Belle II Software development
MCPXDROICreatorModule.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/MCPXDROICreatorModule.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(MCPXDROICreator);
22
23//-----------------------------------------------------------------
24// Implementation
25//-----------------------------------------------------------------
26
28{
29 // Set module properties
30 setDescription("Create artificial ROI just for PXDDigits from all charged primary MCParticles or just 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 addParam("createROIForAll", m_createROIForAll, "Create ROI for all chargedstable MCParticles.", m_createROIForAll);
41 addParam("createROIForSlowPionsOnly", m_createROIForSlowPionsOnly, "Create ROI only for slow pions.", m_createROIForSlowPionsOnly);
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 we want to create ROI for all charged primary particles but the particle
68 // is not charged or primary
69 if (m_createROIForAll and
70 not(std::abs(mcParticle.getCharge()) > 0 and mcParticle.isPrimaryParticle())) {
71 continue;
72 }
73 // Nothing to do if only want to create ROI for slow pions but the particle is not a slow pion
74 // from a D* -> D pi^{\pm} decay or if there is no mother particle e.g. when using particle gun.
76 (not mcParticle.getMother() or
77 not(std::abs(mcParticle.getPDG()) == 211 and
78 std::abs(mcParticle.getMother()->getPDG()) == 413))) {
79 continue;
80 }
81 const RelationVector<PXDDigit>& relatedPXDDigits = mcParticle.getRelationsFrom<PXDDigit>(m_pxdDigitsName);
82 // Don't try to create ROIs if there are no PXDDigits for this slow pion
83 if (relatedPXDDigits.size() == 0) {
84 continue;
85 }
86
87 VxdID lastSensor(0);
88 for (const PXDDigit& digit : relatedPXDDigits) {
89 const VxdID& sensor = digit.getSensorID();
90 // Only create one ROI per sensor and MCParticle instead of one per PXDDigit.
91 // So if there already is a ROI on this sensor from a previous PXDDigit of this MCParticle, just skip this PXDDigit.
92 if (sensor == lastSensor) {
93 continue;
94 }
95 lastSensor = sensor;
96 const short uCell = digit.getUCellID();
97 const short vCell = digit.getVCellID();
98
99 // Check consistency of cells to only create ROIs that are fully contained on a sensor
100 const short minU = uCell - m_ROISize / 2 >= 0 ? uCell - m_ROISize / 2 : 0;
101 const short maxU = uCell + m_ROISize / 2 <= 249 ? uCell + m_ROISize / 2 : 249;
102 const short minV = vCell - m_ROISize / 2 >= 0 ? vCell - m_ROISize / 2 : 0;
103 const short maxV = vCell + m_ROISize / 2 <= 767 ? vCell + m_ROISize / 2 : 767;
104
105 m_ROIs.appendNew(ROIid(minU, maxU, minV, maxV, sensor));
106 }
107 }
108}
MCPXDROICreatorModule()
Constructor: Sets the description, the properties and the parameters of the module.
virtual void initialize() override
init the module
bool m_createROIForAll
Create ROI for all chargedstable MCParticles.
virtual void event() override
processes the event
std::string m_pxdDigitsName
PXDDigits StoreArray name.
std::string m_MCParticlesName
MCParticles StoreArray name.
std::string m_ROIsName
ROI StoreArray name.
StoreArray< PXDDigit > m_PXDDigits
StoreArray for the PXDDigits.
bool m_createROIForSlowPionsOnly
Create ROI only for slow pions.
StoreArray< MCParticle > m_MCParticles
StoreArray for the MCParticles.
StoreArray< ROIid > m_ROIs
StoreArray for the ROIs.
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
Abstract base class for different kinds of events.