Belle II Software  release-06-02-00
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 <tracking/dataobjects/ROIid.h>
11 #include <map>
12 
13 using namespace Belle2;
14 using namespace std;
15 
16 //-----------------------------------------------------------------
17 // Register the Module
18 //-----------------------------------------------------------------
19 REG_MODULE(PXDdigiFilter)
20 
21 //-----------------------------------------------------------------
22 // Implementation
23 //-----------------------------------------------------------------
24 
26 {
27  // Set module properties
28  setDescription("The module produce a StoreArray of PXDDigit inside the ROIs.");
29  setPropertyFlags(c_ParallelProcessingCertified);
30 
31  // Parameter definitions
32  addParam("PXDDigitsName", m_PXDDigitsName, "The name of the StoreArray of PXDDigits to be filtered", std::string(""));
33  addParam("PXDDigitsInsideROIName", m_PXDDigitsInsideROIName, "The name of the StoreArray of Filtered PXDDigits",
34  std::string("PXDDigitsIN"));
35  addParam("PXDDigitsOutsideROIName", m_PXDDigitsOutsideROIName, "The name of the StoreArray of Filtered PXDDigits",
36  std::string("PXDDigitsOUT"));
37  addParam("ROIidsName", m_ROIidsName, "The name of the StoreArray of ROIs", std::string(""));
38  addParam("CreateOutside", m_CreateOutside, "Create the StoreArray of PXD pixel outside the ROIs", false);
39 
40  addParam("overrideDB", m_overrideDB, "If set, ROI-filtering settings in DB are overwritten", false);
41  addParam("usePXDDataReduction", m_usePXDDataReduction, "enables/disables ROI-filtering if overrideDB=True", false);
42 }
43 
45 {
46 
47  StoreArray<ROIid> roiIDs;
48  roiIDs.isRequired(m_ROIidsName);
49 
50  StoreArray<PXDDigit> PXDDigits(m_PXDDigitsName);
51  PXDDigits.isRequired();
52  if (m_PXDDigitsName == m_PXDDigitsInsideROIName) {
53  m_selectorIN.registerSubset(PXDDigits);
54  } else {
55  m_selectorIN.registerSubset(PXDDigits, m_PXDDigitsInsideROIName, DataStore::c_WriteOut);
56  m_selectorIN.inheritAllRelations();
57  }
58 
59  if (m_CreateOutside) {
60  if (m_PXDDigitsName == m_PXDDigitsOutsideROIName) {
61  m_selectorOUT.registerSubset(PXDDigits);
62  } else {
63  m_selectorOUT.registerSubset(PXDDigits, m_PXDDigitsOutsideROIName);
64  m_selectorOUT.inheritAllRelations();
65  }
66  }
67 }
68 
70 {
71  // reset variables used to enable/disable ROI-filtering
72  m_skipEveryNth = -1;
73  if (m_roiParameters) {
74  m_skipEveryNth = m_roiParameters->getDisableROIforEveryNth();
75  } else {
76  B2ERROR("No configuration for the current run found");
77  }
78  m_countNthEvent = 0;
79 }
80 
82 {
83  // parameters might also change on a per-event basis
84  if (m_roiParameters.hasChanged()) {
85  if (m_roiParameters) {
86  m_skipEveryNth = m_roiParameters->getDisableROIforEveryNth();
87  } else {
88  B2ERROR("No configuration for the current run found");
89  }
90  // and reset counter
91  m_countNthEvent = 0;
92  }
93 
94  if (m_overrideDB) {
95  if (m_usePXDDataReduction) {
96  filterDigits();
97  } else {
98  copyDigits();
99  }
100  return;
101  }
102 
103  m_countNthEvent++;
104 
105  // Data reduction disabled -> simply copy everything
106  if (m_skipEveryNth > 0 and m_countNthEvent % m_skipEveryNth == 0) {
107  copyDigits();
108  m_countNthEvent = 0;
109 
110  return;
111  }
112 
113  // Perform data reduction
114  filterDigits();
115 }
116 
118 {
119  StoreArray<PXDDigit> PXDDigits(m_PXDDigitsName);
120  StoreArray<ROIid> ROIids_store_array(m_ROIidsName);
122  multimap< VxdID, ROIid > ROIids;
123 
124  for (auto ROI : ROIids_store_array)
125  ROIids.insert(pair<VxdID, ROIid> (ROI.getSensorID() , ROI));
126 
127  m_selectorIN.select([ROIids](const PXDDigit * thePxdDigit) {
128  auto ROIidsRange = ROIids.equal_range(thePxdDigit->getSensorID()) ;
129  for (auto theROI = ROIidsRange.first ; theROI != ROIidsRange.second; theROI ++)
130  if (theROI->second.Contains(*thePxdDigit))
131  return true;
132 
133  return false;
134  });
135 
136  if (m_CreateOutside) {
137  m_selectorOUT.select([ROIids](const PXDDigit * thePxdDigit) {
138  auto ROIidsRange = ROIids.equal_range(thePxdDigit->getSensorID()) ;
139  for (auto theROI = ROIidsRange.first ; theROI != ROIidsRange.second; theROI ++)
140  if (theROI->second.Contains(*thePxdDigit))
141  return false;
142 
143  return true;
144  });
145  }
146 }
147 
149 {
150  // omitting the variable name; otherwise a warning is produced (un-used variable)
151  m_selectorIN.select([](const PXDDigit* /* thePxdDigit */) {return true;});
152 }
153 
154 
@ c_WriteOut
Object/array should be saved by output modules.
Definition: DataStore.h:70
Base class for Modules.
Definition: Module.h:72
The PXD digit class.
Definition: PXDDigit.h:27
VxdID getSensorID() const
Get the sensor ID.
Definition: PXDDigit.h:64
The module produce a StoreArray of PXDDigit inside the ROIs.
void initialize() override final
Initializer.
void copyDigits()
all the actual work is done here
void event() override final
This method is called for each event.
void beginRun() override final
Called when entering a new run.
void filterDigits()
all the actual work is done here
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
#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.