Belle II Software  release-08-01-10
PXDclusterFilterModule.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/PXDclusterFilterModule.h>
10 #include <map>
11 
12 using namespace Belle2;
13 
14 //-----------------------------------------------------------------
15 // Register the Module
16 //-----------------------------------------------------------------
17 REG_MODULE(PXDclusterFilter);
18 
19 //-----------------------------------------------------------------
20 // Implementation
21 //-----------------------------------------------------------------
22 
24 {
25  // Set module properties
26  setDescription("The module produce a StoreArray of PXDClusters inside/overlapping any of the ROIs.");
27 
28  // Parameter definitions
29  addParam("PXDClustersName", m_PXDClustersName, "The name of the StoreArray of PXDClusters to be filtered", std::string(""));
30  addParam("PXDClustersInsideROIName", m_PXDClustersInsideROIName, "The name of the StoreArray of Filtered PXDClusters",
31  std::string("PXDClustersIN"));
32  addParam("PXDClustersOutsideROIName", m_PXDClustersOutsideROIName, "The name of the StoreArray of Filtered PXDClusters",
33  std::string("PXDClustersOUT"));
34  addParam("ROIidsName", m_ROIidsName, "The name of the StoreArray of ROIs", std::string(""));
35  addParam("CreateOutside", m_CreateOutside, "Create the StoreArray of PXD clusters outside the ROIs", false);
36 
37  addParam("overrideDB", m_overrideDB, "If set, ROI-finding settings in DB are overwritten", false);
38  addParam("enableFiltering", m_enableFiltering, "enables/disables ROI-finding if overrideDB=True", false);
39 
40 }
41 
43 {
44  m_ROIs.isRequired(m_ROIidsName);
45  // We have to change it once the hardware type clusters are well defined
49  m_selectorIN.inheritAllRelations();
50 
51  if (m_CreateOutside) {
53  m_selectorOUT.inheritAllRelations();
54  }
55 }
56 
58 {
59  // reset variables used to enable/disable ROI-finding
60  m_skipEveryNth = -1;
62  m_skipEveryNth = m_ROISimulationParameters->getDisableROIforEveryNth();
63  } else {
64  B2ERROR("No configuration for the current run found");
65  }
66  m_countNthEvent = 0;
67 }
68 
69 bool PXDclusterFilterModule::Overlaps(const ROIid& theROI, const PXDCluster& thePXDCluster)
70 {
71  // Not so easy, we have to check every pixel which is time consuming
72  // maybe optimze: we can first check the cluster as rectangular but that only helps if we have that property before
73  // PXDClusters do not have them ...
74 
75  if (theROI.getSensorID() != thePXDCluster.getSensorID()) return false; // anyway checked before?
76 
77  // Loop over all Pixel related to this CLuster
78  for (auto thePixel : thePXDCluster.getRelationsTo<PXDDigit>()) {
79  // if any pixel inside
80  if (theROI.getMinUid() <= thePixel.getUCellID() &&
81  theROI.getMaxUid() >= thePixel.getUCellID() &&
82  theROI.getMinVid() <= thePixel.getVCellID() &&
83  theROI.getMaxVid() >= thePixel.getVCellID()) return true;
84  }
85  // no pixel inside
86  return false;
87 }
88 
90 {
91  // parameters might also change on a per-event basis
92  if (m_ROISimulationParameters.hasChanged()) {
94  m_skipEveryNth = m_ROISimulationParameters->getDisableROIforEveryNth();
95  } else {
96  B2ERROR("No configuration for the current run found");
97  }
98  // and reset counter
99  m_countNthEvent = 0;
100  }
101 
102  if (m_overrideDB) {
103  if (m_enableFiltering) {
104  filterClusters();
105  } else {
106  copyClusters();
107  }
108  return;
109  }
110 
111  m_countNthEvent++;
112 
113  // Data reduction disabled -> simply copy everything
114  if (m_skipEveryNth > 0 and m_countNthEvent % m_skipEveryNth == 0) {
115  copyClusters();
116  m_countNthEvent = 0;
117 
118  return;
119  }
120 
121  // Perform data reduction
122  filterClusters();
123 }
124 
126 {
127  std::multimap< VxdID, ROIid > ROIids;
128 
129  for (auto ROI : m_ROIs)
130  ROIids.insert(std::pair<VxdID, ROIid> (ROI.getSensorID(), ROI));
131 
132  m_selectorIN.select([ROIids, this](const PXDCluster * thePxdCluster) {
133  auto ROIidsRange = ROIids.equal_range(thePxdCluster->getSensorID()) ;
134  for (auto theROI = ROIidsRange.first ; theROI != ROIidsRange.second; theROI ++)
135  if (Overlaps(theROI->second, *thePxdCluster)) // *or* Cluster has intersting Properties. TODO
136  return true;
137 
138  return false;
139  });
140 
141  if (m_CreateOutside) {
142  m_selectorOUT.select([ROIids, this](const PXDCluster * thePxdCluster) {
143  auto ROIidsRange = ROIids.equal_range(thePxdCluster->getSensorID()) ;
144  for (auto theROI = ROIidsRange.first ; theROI != ROIidsRange.second; theROI ++)
145  if (Overlaps(theROI->second, *thePxdCluster)) // *and* Cluster has NO intersting Properties. TODO
146  return false;
147 
148  return true;
149  });
150  }
151 }
152 
154 {
155  // omitting the variable name; otherwise a warning is produced (un-used variable)
156  m_selectorIN.select([](const PXDCluster* /* thePxdCluster */) {return true;});
157 }
158 
159 
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:30
VxdID getSensorID() const
Get the sensor ID.
Definition: PXDCluster.h:126
The PXD digit class.
Definition: PXDDigit.h:27
SelectSubset< PXDCluster > m_selectorOUT
selector of the subset of PXDClusters NOT contained in the ROIs
bool Overlaps(const ROIid &theROI, const PXDCluster &thePXDCluster)
Check for cluster overlaps - a pixel shared with two or more clusters.
bool m_overrideDB
if set, overwrites ROI-finding settings in DB
void initialize() override
Initializer.
std::string m_PXDClustersOutsideROIName
The name of the StoreArray of Filtered PXDClusters.
void event() override
This method is called for each event.
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.
DBObjPtr< ROISimulationParameters > m_ROISimulationParameters
Configuration parameters for ROIs.
void filterClusters()
all the actual work is done here
std::string m_PXDClustersName
The name of the StoreArray of PXDClusters to be filtered.
StoreArray< PXDCluster > m_PXDClusters
StoreArray containing the input PXDClusters.
std::string m_PXDClustersInsideROIName
The name of the StoreArray of Filtered PXDClusters.
void copyClusters()
all the actual work is done here
std::string m_ROIidsName
The name of the StoreArray of ROIs.
void beginRun() override final
Called when entering a new run.
PXDclusterFilterModule()
Constructor: Sets the description, the properties and the parameters of the module.
bool m_enableFiltering
enables/disables ROI-finding if overwriteDB=True
bool m_CreateOutside
if set, create list of outside pixels, too
SelectSubset< PXDCluster > m_selectorIN
selector of the subset of PXDClusters contained in the ROIs
StoreArray< ROIid > m_ROIs
StoreArray containing the ROIs.
ROIid stores the U and V ids and the sensor id of the Region Of Interest.
Definition: ROIid.h:25
int getMaxVid() const
return the maximum V id of the ROI
Definition: ROIid.h:47
int getMinVid() const
return the minimum V id of the ROI
Definition: ROIid.h:46
VxdID getSensorID() const
return the sensor ID of the ROI
Definition: ROIid.h:48
int getMinUid() const
return the minimum U id of the ROI
Definition: ROIid.h:44
int getMaxUid() const
return the maximum U id of the ROI
Definition: ROIid.h:45
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
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.