Belle II Software development
PXDdigiFilterModule.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/PXDdigiFilterModule.h>
10#include <simulation/dbobjects/ROISimulationParameters.h>
11#include <tracking/dataobjects/ROIid.h>
12
13#include <map>
14
15using namespace Belle2;
16
17//-----------------------------------------------------------------
18// Register the Module
19//-----------------------------------------------------------------
20REG_MODULE(PXDdigiFilter);
21
22//-----------------------------------------------------------------
23// Implementation
24//-----------------------------------------------------------------
25
27{
28 // Set module properties
29 setDescription("The module produce a StoreArray of PXDDigit inside the ROIs. A second StoreArray with PXDDigits outside the ROI can be created on demand.");
31
32 // Parameter definitions
33 addParam("PXDDigitsName", m_PXDDigitsName, "The name of the StoreArray of PXDDigits to be filtered", std::string(""));
34 addParam("PXDDigitsInsideROIName", m_PXDDigitsInsideROIName, "The name of the StoreArray of Filtered PXDDigits",
35 std::string("PXDDigitsIN"));
36 addParam("PXDDigitsOutsideROIName", m_PXDDigitsOutsideROIName, "The name of the StoreArray of Filtered PXDDigits",
37 std::string("PXDDigitsOUT"));
38 addParam("ROIidsName", m_ROIidsName, "The name of the StoreArray of ROIs", std::string(""));
39 addParam("CreateOutside", m_CreateOutside, "Create the StoreArray of PXD pixel outside the ROIs", false);
40
41 addParam("overrideDB", m_overrideDB, "If set, ROI-filtering settings in DB are overwritten", false);
42 addParam("usePXDDataReduction", m_usePXDDataReduction, "enables/disables ROI-filtering if overrideDB=True", false);
43}
44
46{
47 m_ROIs.isRequired(m_ROIidsName);
48 m_PXDDigits.isRequired(m_PXDDigitsName);
51 m_selectorIN.registerSubset(m_PXDDigits);
52 } else {
54 m_selectorIN.inheritAllRelations();
55 }
56
57 if (m_CreateOutside) {
59 m_selectorOUT.registerSubset(m_PXDDigits);
60 } else {
62 m_selectorOUT.inheritAllRelations();
63 }
64 }
65}
66
68{
69 // reset variables used to enable/disable ROI-filtering
70 m_skipEveryNth = -1;
72 m_skipEveryNth = m_ROISimulationParameters->getDisableROIforEveryNth();
73 } else {
74 B2ERROR("No configuration for the current run found");
75 }
77}
78
80{
81 // parameters might also change on a per-event basis
82 if (m_ROISimulationParameters.hasChanged()) {
84 m_skipEveryNth = m_ROISimulationParameters->getDisableROIforEveryNth();
85 } else {
86 B2ERROR("No configuration for the current run found");
87 }
88 // and reset counter
90 }
91
92 if (m_overrideDB) {
95 } else {
96 copyDigits();
97 }
98 return;
99 }
100
102
103 // Data reduction disabled -> simply copy everything
104 if (m_skipEveryNth > 0 and m_countNthEvent % m_skipEveryNth == 0) {
105 copyDigits();
106 m_countNthEvent = 0;
107
108 return;
109 }
110
111 // Perform data reduction
112 filterDigits();
113}
114
116{
117 std::multimap< VxdID, ROIid > ROIids;
118
119 for (auto ROI : m_ROIs)
120 ROIids.insert(std::pair<VxdID, ROIid> (ROI.getSensorID(), ROI));
121
122 m_selectorIN.select([ROIids](const PXDDigit * thePxdDigit) {
123 auto ROIidsRange = ROIids.equal_range(thePxdDigit->getSensorID()) ;
124 for (auto theROI = ROIidsRange.first ; theROI != ROIidsRange.second; theROI ++)
125 if (theROI->second.Contains(*thePxdDigit))
126 return true;
127
128 return false;
129 });
130
131 if (m_CreateOutside) {
132 m_selectorOUT.select([ROIids](const PXDDigit * thePxdDigit) {
133 auto ROIidsRange = ROIids.equal_range(thePxdDigit->getSensorID()) ;
134 for (auto theROI = ROIidsRange.first ; theROI != ROIidsRange.second; theROI ++)
135 if (theROI->second.Contains(*thePxdDigit))
136 return false;
137
138 return true;
139 });
140 }
141}
142
144{
145 // omitting the variable name; otherwise a warning is produced (un-used variable)
146 m_selectorIN.select([](const PXDDigit* /* thePxdDigit */) {return true;});
147}
148
149
@ c_WriteOut
Object/array should be saved by output modules.
Definition: DataStore.h:70
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
VxdID getSensorID() const
Get the sensor ID.
Definition: PXDDigit.h:64
void initialize() override final
Initializer.
bool m_overrideDB
if set, overwrites ROI-finding settings in DB
int m_countNthEvent
Event counter to be able to disable data reduction for every Nth event.
int m_skipEveryNth
Parameter from DB for how many events to skip data reduction.
void copyDigits()
all the actual work is done here
DBObjPtr< ROISimulationParameters > m_ROISimulationParameters
Configuration parameters for ROIs.
SelectSubset< PXDDigit > m_selectorIN
selector of the subset of PXDDigits contained in the ROIs
bool m_usePXDDataReduction
enables/disables ROI-finding if overwriteDB=True
void event() override final
This method is called for each event.
std::string m_PXDDigitsOutsideROIName
The name of the StoreArray of Filtered PXDDigits.
std::string m_ROIidsName
The name of the StoreArray of ROIs.
StoreArray< PXDDigit > m_PXDDigits
StoreArray containing the input PXDDigits.
void beginRun() override final
Called when entering a new run.
std::string m_PXDDigitsName
The name of the StoreArray of PXDDigits to be filtered.
void filterDigits()
all the actual work is done here
PXDdigiFilterModule()
Constructor: Sets the description, the properties and the parameters of the module.
bool m_CreateOutside
if set, create list of outside pixels, too
std::string m_PXDDigitsInsideROIName
The name of the StoreArray of Filtered PXDDigits.
SelectSubset< PXDDigit > m_selectorOUT
selector of the subset of PXDDigits NOT contained in the ROIs
StoreArray< ROIid > m_ROIs
StoreArray containing the ROIs.
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.