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