Belle II Software  release-08-01-10
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/pxdDataReduction/PXDdigiFilterModule.h>
10 #include <map>
11 
12 using namespace Belle2;
13 
14 //-----------------------------------------------------------------
15 // Register the Module
16 //-----------------------------------------------------------------
17 REG_MODULE(PXDdigiFilter);
18 
19 //-----------------------------------------------------------------
20 // Implementation
21 //-----------------------------------------------------------------
22 
24 {
25  // Set module properties
26  setDescription("The module produce a StoreArray of PXDDigit inside the ROIs. A second StoreArray with PXDDigits outside the ROI can be created on demand.");
28 
29  // Parameter definitions
30  addParam("PXDDigitsName", m_PXDDigitsName, "The name of the StoreArray of PXDDigits to be filtered", std::string(""));
31  addParam("PXDDigitsInsideROIName", m_PXDDigitsInsideROIName, "The name of the StoreArray of Filtered PXDDigits",
32  std::string("PXDDigitsIN"));
33  addParam("PXDDigitsOutsideROIName", m_PXDDigitsOutsideROIName, "The name of the StoreArray of Filtered PXDDigits",
34  std::string("PXDDigitsOUT"));
35  addParam("ROIidsName", m_ROIidsName, "The name of the StoreArray of ROIs", std::string(""));
36  addParam("CreateOutside", m_CreateOutside, "Create the StoreArray of PXD pixel outside the ROIs", false);
37 
38  addParam("overrideDB", m_overrideDB, "If set, ROI-filtering settings in DB are overwritten", false);
39  addParam("usePXDDataReduction", m_usePXDDataReduction, "enables/disables ROI-filtering if overrideDB=True", false);
40 }
41 
43 {
44  m_ROIs.isRequired(m_ROIidsName);
45  m_PXDDigits.isRequired(m_PXDDigitsName);
48  m_selectorIN.registerSubset(m_PXDDigits);
49  } else {
51  m_selectorIN.inheritAllRelations();
52  }
53 
54  if (m_CreateOutside) {
56  m_selectorOUT.registerSubset(m_PXDDigits);
57  } else {
59  m_selectorOUT.inheritAllRelations();
60  }
61  }
62 }
63 
65 {
66  // reset variables used to enable/disable ROI-filtering
67  m_skipEveryNth = -1;
69  m_skipEveryNth = m_ROISimulationParameters->getDisableROIforEveryNth();
70  } else {
71  B2ERROR("No configuration for the current run found");
72  }
73  m_countNthEvent = 0;
74 }
75 
77 {
78  // parameters might also change on a per-event basis
79  if (m_ROISimulationParameters.hasChanged()) {
81  m_skipEveryNth = m_ROISimulationParameters->getDisableROIforEveryNth();
82  } else {
83  B2ERROR("No configuration for the current run found");
84  }
85  // and reset counter
86  m_countNthEvent = 0;
87  }
88 
89  if (m_overrideDB) {
91  filterDigits();
92  } else {
93  copyDigits();
94  }
95  return;
96  }
97 
99 
100  // Data reduction disabled -> simply copy everything
101  if (m_skipEveryNth > 0 and m_countNthEvent % m_skipEveryNth == 0) {
102  copyDigits();
103  m_countNthEvent = 0;
104 
105  return;
106  }
107 
108  // Perform data reduction
109  filterDigits();
110 }
111 
113 {
114  std::multimap< VxdID, ROIid > ROIids;
115 
116  for (auto ROI : m_ROIs)
117  ROIids.insert(std::pair<VxdID, ROIid> (ROI.getSensorID(), ROI));
118 
119  m_selectorIN.select([ROIids](const PXDDigit * thePxdDigit) {
120  auto ROIidsRange = ROIids.equal_range(thePxdDigit->getSensorID()) ;
121  for (auto theROI = ROIidsRange.first ; theROI != ROIidsRange.second; theROI ++)
122  if (theROI->second.Contains(*thePxdDigit))
123  return true;
124 
125  return false;
126  });
127 
128  if (m_CreateOutside) {
129  m_selectorOUT.select([ROIids](const PXDDigit * thePxdDigit) {
130  auto ROIidsRange = ROIids.equal_range(thePxdDigit->getSensorID()) ;
131  for (auto theROI = ROIidsRange.first ; theROI != ROIidsRange.second; theROI ++)
132  if (theROI->second.Contains(*thePxdDigit))
133  return false;
134 
135  return true;
136  });
137  }
138 }
139 
141 {
142  // omitting the variable name; otherwise a warning is produced (un-used variable)
143  m_selectorIN.select([](const PXDDigit* /* thePxdDigit */) {return true;});
144 }
145 
146 
@ 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.
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.