Belle II Software development
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/roiFinding/pxd/MCSlowPionPXDROICreatorModule.h>
10#include <vxd/geometry/GeoCache.h>
11#include <vxd/geometry/SensorInfoBase.h>
12#include <pxd/dataobjects/PXDDigit.h>
13#include <mdst/dataobjects/MCParticle.h>
14#include <tracking/dataobjects/ROIid.h>
15
16using namespace Belle2;
17
18//-----------------------------------------------------------------
19// Register the Module
20//-----------------------------------------------------------------
21REG_MODULE(MCSlowPionPXDROICreator);
22
23//-----------------------------------------------------------------
24// Implementation
25//-----------------------------------------------------------------
26
28{
29 // Set module properties
30 setDescription("Create artificial ROI just for PXDDigits from slow pions from D* decays based on MC information.");
32
33 // Parameter definitions
34 addParam("PXDDigitsName", m_pxdDigitsName, "StoreArray name of the input PXD clusters", std::string(""));
35 addParam("MCParticlesName", m_MCParticlesName, "StoreArray name of the input tracks", std::string(""));
36 addParam("ROIsName", m_ROIsName, "StoreArray name of the ROIs", std::string(""));
37 addParam("ROISize", m_ROISize,
38 "Size of the ROIs. Set to a rather large value to only create on ROI per sensor instead of one ROI per PXDDigit.",
39 m_ROISize);
40}
41
42
44{
45 m_PXDDigits.isRequired(m_pxdDigitsName);
47 m_ROIs.isRequired(m_ROIsName);
48
49 B2DEBUG(29, "StoreArray names in use: \n"
50 " MCParticles: " << m_MCParticlesName << "\n"
51 " PXDDigits: " << m_pxdDigitsName << "\n"
52 " ROIs: " << m_ROIsName);
53}
54
55
57{
58 // Just skip if there are no MCParticles by accident in simulation,
59 // or because the module is added to the path for data reconstruction
60 if (m_MCParticles.getEntries() == 0) {
61 return;
62 }
63
64 for (const MCParticle& mcParticle : m_MCParticles) {
65 // Nothing to do if the particle is not a slow pion from a D* -> D pi^{\pm} decay
66 // or if there is no mother particle e.g. when using particle gun.
67 if (not mcParticle.getMother() or
68 not(std::abs(mcParticle.getPDG()) == 211 and
69 std::abs(mcParticle.getMother()->getPDG()) == 413)) {
70 continue;
71 }
72 const RelationVector<PXDDigit>& relatedPXDDigits = mcParticle.getRelationsFrom<PXDDigit>(m_pxdDigitsName);
73 // Don't try to create ROIs if there are no PXDDigits for this slow pion
74 if (relatedPXDDigits.size() == 0) {
75 continue;
76 }
77
78 // Only count slow pions with related PXDDigits
80 VxdID lastSensor(0);
81 for (const PXDDigit& digit : relatedPXDDigits) {
82 const VxdID& sensor = digit.getSensorID();
83 // Only create one ROI per sensor instead of one per PXDDigit.
84 // So if there already is a ROI on this sensor from a previous PXDDigit of this MCParticle, just skip this PXDDigit.
85 if (sensor == lastSensor) {
86 continue;
87 }
88 lastSensor = sensor;
89 const short uCell = digit.getUCellID();
90 const short vCell = digit.getVCellID();
91
92 // Check consistency of cells to only create ROIs that are fully contained on a sensor
93 const short minU = uCell - m_ROISize / 2 >= 0 ? uCell - m_ROISize / 2 : 0;
94 const short maxU = uCell + m_ROISize / 2 <= 249 ? uCell + m_ROISize / 2 : 249;
95 const short minV = vCell - m_ROISize / 2 >= 0 ? vCell - m_ROISize / 2 : 0;
96 const short maxV = vCell + m_ROISize / 2 <= 767 ? vCell + m_ROISize / 2 : 767;
97
98 m_ROIs.appendNew(ROIid(minU, maxU, minV, maxV, sensor));
100 }
101 }
102}
103
105{
106 B2DEBUG(29, "Created " << m_ROICounter << " ROIs for " << m_slowPiCounter << " slow Pions, that's " <<
107 (double)m_ROICounter / (double)m_slowPiCounter << " per slow pion.");
108}
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
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
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.