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