Belle II Software  release-08-01-10
MCSlowPionPXDROICreatorModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <tracking/modules/pxdDataReduction/MCSlowPionPXDROICreatorModule.h>
10 #include <vxd/geometry/GeoCache.h>
11 #include <vxd/geometry/SensorInfoBase.h>
12 
13 #include <pxd/dataobjects/PXDDigit.h>
14 #include <mdst/dataobjects/MCParticle.h>
15 #include <tracking/dataobjects/ROIid.h>
16 
17 
18 using namespace Belle2;
19 
20 //-----------------------------------------------------------------
21 // Register the Module
22 //-----------------------------------------------------------------
23 REG_MODULE(MCSlowPionPXDROICreator);
24 
25 //-----------------------------------------------------------------
26 // Implementation
27 //-----------------------------------------------------------------
28 
30 {
31  // Set module properties
32  setDescription("Create artificial ROI just for PXDDigits from slow pions from D* decays based on MC information.");
34 
35  // Parameter definitions
36  addParam("PXDDigitsName", m_pxdDigitsName, "StoreArray name of the input PXD clusters", std::string(""));
37  addParam("MCParticlesName", m_MCParticlesName, "StoreArray name of the input tracks", std::string(""));
38  addParam("ROIsName", m_ROIsName, "StoreArray name of the ROIs", std::string(""));
39  addParam("ROISize", m_ROISize,
40  "Size of the ROIs. Set to a rather large value to only create on ROI per sensor instead of one ROI per PXDDigit.",
41  m_ROISize);
42 }
43 
44 
46 {
47  m_PXDDigits.isRequired(m_pxdDigitsName);
49  m_ROIs.isRequired(m_ROIsName);
50 
51  B2DEBUG(29, "StoreArray names in use: \n"
52  " MCParticles: " << m_MCParticlesName << "\n"
53  " PXDDigits: " << m_pxdDigitsName << "\n"
54  " ROIs: " << m_ROIsName);
55 }
56 
57 
59 {
60  // Just skip if there are no MCParticles by accident in simulation,
61  // or because the module is added to the path for data reconstruction
62  if (m_MCParticles.getEntries() == 0) {
63  return;
64  }
65 
66  for (const MCParticle& mcParticle : m_MCParticles) {
67  // Nothing to do if the particle is not a slow pion from a D* -> D pi^{\pm} decay
68  // or if there is no mother particle e.g. when using particle gun.
69  if (not mcParticle.getMother() or
70  not(std::abs(mcParticle.getPDG()) == 211 and
71  std::abs(mcParticle.getMother()->getPDG()) == 413)) {
72  continue;
73  }
74  const RelationVector<PXDDigit>& relatedPXDDigits = mcParticle.getRelationsFrom<PXDDigit>(m_pxdDigitsName);
75  // Don't try to create ROIs if there are no PXDDigits for this slow pion
76  if (relatedPXDDigits.size() == 0) {
77  continue;
78  }
79 
80  // Only count slow pions with related PXDDigits
82  VxdID lastSensor(0);
83  for (const PXDDigit& digit : relatedPXDDigits) {
84  const VxdID& sensor = digit.getSensorID();
85  // Only create one ROI per sensor instead of one per PXDDigit.
86  // So if there already is a ROI on this sensor from a previous PXDDigit of this MCParticle, just skip this PXDDigit.
87  if (sensor == lastSensor) {
88  continue;
89  }
90  lastSensor = sensor;
91  const short uCell = digit.getUCellID();
92  const short vCell = digit.getVCellID();
93 
94  // Check consistency of cells to only create ROIs that are fully contained on a sensor
95  const short minU = uCell - m_ROISize / 2 >= 0 ? uCell - m_ROISize / 2 : 0;
96  const short maxU = uCell + m_ROISize / 2 <= 249 ? uCell + m_ROISize / 2 : 249;
97  const short minV = vCell - m_ROISize / 2 >= 0 ? vCell - m_ROISize / 2 : 0;
98  const short maxV = vCell + m_ROISize / 2 <= 767 ? vCell + m_ROISize / 2 : 767;
99 
100  m_ROIs.appendNew(ROIid(minU, maxU, minV, maxV, sensor));
101  m_ROICounter++;
102  }
103  }
104 }
105 
107 {
108  B2DEBUG(29, "Created " << m_ROICounter << " ROIs for " << m_slowPiCounter << " slow Pions, that's " <<
109  (double)m_ROICounter / (double)m_slowPiCounter << " per slow pion.");
110 }
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
virtual void initialize() override
init the module
virtual void event() override
processes the event
uint m_ROICounter
Count the ROI that are created for debugging.
std::string m_pxdDigitsName
PXDDigits StoreArray name.
std::string m_MCParticlesName
MCParticles StoreArray name.
StoreArray< PXDDigit > m_PXDDigits
StoreArray for the PXDDigits.
MCSlowPionPXDROICreatorModule()
Constructor: Sets the description, the properties and the parameters of the module.
StoreArray< MCParticle > m_MCParticles
StoreArray for the MCParticles.
uint m_slowPiCounter
Count the slow pions in MC for debugging.
StoreArray< ROIid > m_ROIs
StoreArray for the ROIs.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
The PXD digit class.
Definition: PXDDigit.h:27
ROIid stores the U and V ids and the sensor id of the Region Of Interest.
Definition: ROIid.h:25
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
Abstract base class for different kinds of events.