Belle II Software  release-05-02-19
PXDclusterFilterModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: bjoern.spruck@belle2.org *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <tracking/modules/pxdDataReduction/PXDclusterFilterModule.h>
12 #include <map>
13 
14 using namespace Belle2;
15 using namespace std;
16 
17 //-----------------------------------------------------------------
18 // Register the Module
19 //-----------------------------------------------------------------
20 REG_MODULE(PXDclusterFilter)
21 
22 //-----------------------------------------------------------------
23 // Implementation
24 //-----------------------------------------------------------------
25 
27 {
28  // Set module properties
29  setDescription("The module produce a StoreArray of PXDClusters inside/overlapping any of the ROIs.");
30 
31  // Parameter definitions
32  addParam("PXDClustersName", m_PXDClustersName, "The name of the StoreArray of PXDClusters to be filtered", std::string(""));
33  addParam("PXDClustersInsideROIName", m_PXDClustersInsideROIName, "The name of the StoreArray of Filtered PXDClusters",
34  std::string("PXDClustersIN"));
35  addParam("PXDClustersOutsideROIName", m_PXDClustersOutsideROIName, "The name of the StoreArray of Filtered PXDClusters",
36  std::string("PXDClustersOUT"));
37  addParam("ROIidsName", m_ROIidsName, "The name of the StoreArray of ROIs", std::string(""));
38  addParam("CreateOutside", m_CreateOutside, "Create the StoreArray of PXD clusters outside the ROIs", false);
39 
40  addParam("overrideDB", m_overrideDB, "If set, ROI-finding settings in DB are overwritten", false);
41  addParam("enableFiltering", m_enableFiltering, "enables/disables ROI-finding if overrideDB=True", false);
42 
43 }
44 
46 {
47 
48  StoreArray<ROIid> roiIDs;
49  roiIDs.isRequired(m_ROIidsName);
50 
51  // We have to change it once the hardware type clusters are well defined
52  StoreArray<PXDCluster> PXDClusters(m_PXDClustersName);
53  PXDClusters.isRequired();
54 
55  m_selectorIN.registerSubset(PXDClusters, m_PXDClustersInsideROIName);
56  m_selectorIN.inheritAllRelations();
57 
58  if (m_CreateOutside) {
59  m_selectorOUT.registerSubset(PXDClusters, m_PXDClustersOutsideROIName);
60  m_selectorOUT.inheritAllRelations();
61  }
62 }
63 
65 {
66  // reset variables used to enable/disable ROI-finding
67  m_skipEveryNth = -1;
68  if (m_roiParameters) {
69  m_skipEveryNth = m_roiParameters->getDisableROIforEveryNth();
70  } else {
71  B2ERROR("No configuration for the current run found");
72  }
73  m_countNthEvent = 0;
74 }
75 
76 bool PXDclusterFilterModule::Overlaps(const ROIid& theROI, const PXDCluster& thePXDCluster)
77 {
78  // Not so easy, we have to check every pixel which is time consuming
79  // maybe optimze: we can first check the cluster as rectangular but that only helps if we have that property before
80  // PXDClusters do not have them ...
81 
82  if (theROI.getSensorID() != thePXDCluster.getSensorID()) return false; // anyway checked before?
83 
84  // Loop over all Pixel related to this CLuster
85  for (auto thePixel : thePXDCluster.getRelationsTo<PXDDigit>()) {
86  // if any pixel inside
87  if (theROI.getMinUid() <= thePixel.getUCellID() &&
88  theROI.getMaxUid() >= thePixel.getUCellID() &&
89  theROI.getMinVid() <= thePixel.getVCellID() &&
90  theROI.getMaxVid() >= thePixel.getVCellID()) return true;
91  }
92  // no pixel inside
93  return false;
94 }
95 
97 {
98  // parameters might also change on a per-event basis
99  if (m_roiParameters.hasChanged()) {
100  if (m_roiParameters) {
101  m_skipEveryNth = m_roiParameters->getDisableROIforEveryNth();
102  } else {
103  B2ERROR("No configuration for the current run found");
104  }
105  // and reset counter
106  m_countNthEvent = 0;
107  }
108 
109  if (m_overrideDB) {
110  if (m_enableFiltering) {
111  filterClusters();
112  } else {
113  copyClusters();
114  }
115  return;
116  }
117 
118  m_countNthEvent++;
119 
120  // Data reduction disabled -> simply copy everything
121  if (m_skipEveryNth > 0 and m_countNthEvent % m_skipEveryNth == 0) {
122  copyClusters();
123  m_countNthEvent = 0;
124 
125  return;
126  }
127 
128  // Perform data reduction
129  filterClusters();
130 }
131 
133 {
134  // We have to change it once the hardware type clusters are well defined
135  StoreArray<PXDCluster> PXDClusters(m_PXDClustersName);
136  StoreArray<ROIid> ROIids_store_array(m_ROIidsName);
138  multimap< VxdID, ROIid > ROIids;
139 
140  for (auto ROI : ROIids_store_array)
141  ROIids.insert(pair<VxdID, ROIid> (ROI.getSensorID() , ROI));
142 
143  m_selectorIN.select([ROIids, this](const PXDCluster * thePxdCluster) {
144  auto ROIidsRange = ROIids.equal_range(thePxdCluster->getSensorID()) ;
145  for (auto theROI = ROIidsRange.first ; theROI != ROIidsRange.second; theROI ++)
146  if (Overlaps(theROI->second, *thePxdCluster)) // *or* Cluster has intersting Properties. TODO
147  return true;
148 
149  return false;
150  });
151 
152  if (m_CreateOutside) {
153  m_selectorOUT.select([ROIids, this](const PXDCluster * thePxdCluster) {
154  auto ROIidsRange = ROIids.equal_range(thePxdCluster->getSensorID()) ;
155  for (auto theROI = ROIidsRange.first ; theROI != ROIidsRange.second; theROI ++)
156  if (Overlaps(theROI->second, *thePxdCluster)) // *and* Cluster has NO intersting Properties. TODO
157  return false;
158 
159  return true;
160  });
161  }
162 }
163 
165 {
166  // omitting the variable name; otherwise a warning is produced (un-used variable)
167  m_selectorIN.select([](const PXDCluster* /* thePxdCluster */) {return true;});
168 }
169 
170 
Belle2::PXDclusterFilterModule::event
void event() override
This method is the core of the module.
Definition: PXDclusterFilterModule.cc:96
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::PXDclusterFilterModule::initialize
void initialize() override
Initialize the Module.
Definition: PXDclusterFilterModule.cc:45
Belle2::PXDDigit
The PXD digit class.
Definition: PXDDigit.h:38
Belle2::RelationsInterface::getRelationsTo
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
Definition: RelationsObject.h:199
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::PXDclusterFilterModule::beginRun
void beginRun() override final
Called when entering a new run.
Definition: PXDclusterFilterModule.cc:64
Belle2::PXDclusterFilterModule::filterClusters
void filterClusters()
all the actual work is done here
Definition: PXDclusterFilterModule.cc:132
Belle2::ROIid
ROIid stores the U and V ids and the sensor id of the Region Of Interest.
Definition: ROIid.h:35
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PXDCluster
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:41
Belle2::PXDclusterFilterModule
The module produce a StoreArray of PXDCluster inside the ROIs.
Definition: PXDclusterFilterModule.h:42
Belle2::PXDCluster::getSensorID
VxdID getSensorID() const
Get the sensor ID.
Definition: PXDCluster.h:131
Belle2::PXDclusterFilterModule::Overlaps
bool Overlaps(const ROIid &theROI, const PXDCluster &thePXDCluster)
Check for cluster overlaps - a pixel shared with two or more clusters.
Definition: PXDclusterFilterModule.cc:76
Belle2::PXDclusterFilterModule::copyClusters
void copyClusters()
all the actual work is done here
Definition: PXDclusterFilterModule.cc:164
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33