Belle II Software development
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/roiFinding/pxd/PXDclusterFilterModule.h>
10#include <tracking/dataobjects/ROIid.h>
11#include <simulation/dbobjects/ROISimulationParameters.h>
12
13#include <map>
14
15using namespace Belle2;
16
17//-----------------------------------------------------------------
18// Register the Module
19//-----------------------------------------------------------------
20REG_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 m_ROIs.isRequired(m_ROIidsName);
48 // We have to change it once the hardware type clusters are well defined
52 m_selectorIN.inheritAllRelations();
53
54 if (m_CreateOutside) {
56 m_selectorOUT.inheritAllRelations();
57 }
58}
59
61{
62 // reset variables used to enable/disable ROI-finding
63 m_skipEveryNth = -1;
65 m_skipEveryNth = m_ROISimulationParameters->getDisableROIforEveryNth();
66 } else {
67 B2ERROR("No configuration for the current run found");
68 }
70}
71
72bool PXDclusterFilterModule::Overlaps(const ROIid& theROI, const PXDCluster& thePXDCluster)
73{
74 // Not so easy, we have to check every pixel which is time consuming
75 // maybe optimze: we can first check the cluster as rectangular but that only helps if we have that property before
76 // PXDClusters do not have them ...
77
78 if (theROI.getSensorID() != thePXDCluster.getSensorID()) return false; // anyway checked before?
79
80 // Loop over all Pixel related to this CLuster
81 for (auto thePixel : thePXDCluster.getRelationsTo<PXDDigit>()) {
82 // if any pixel inside
83 if (theROI.getMinUid() <= thePixel.getUCellID() &&
84 theROI.getMaxUid() >= thePixel.getUCellID() &&
85 theROI.getMinVid() <= thePixel.getVCellID() &&
86 theROI.getMaxVid() >= thePixel.getVCellID()) return true;
87 }
88 // no pixel inside
89 return false;
90}
91
93{
94 // parameters might also change on a per-event basis
95 if (m_ROISimulationParameters.hasChanged()) {
97 m_skipEveryNth = m_ROISimulationParameters->getDisableROIforEveryNth();
98 } else {
99 B2ERROR("No configuration for the current run found");
100 }
101 // and reset counter
102 m_countNthEvent = 0;
103 }
104
105 if (m_overrideDB) {
106 if (m_enableFiltering) {
108 } else {
109 copyClusters();
110 }
111 return;
112 }
113
115
116 // Data reduction disabled -> simply copy everything
117 if (m_skipEveryNth > 0 and m_countNthEvent % m_skipEveryNth == 0) {
118 copyClusters();
119 m_countNthEvent = 0;
120
121 return;
122 }
123
124 // Perform data reduction
126}
127
129{
130 std::multimap< VxdID, ROIid > ROIids;
131
132 for (auto ROI : m_ROIs)
133 ROIids.insert(std::pair<VxdID, ROIid> (ROI.getSensorID(), ROI));
134
135 m_selectorIN.select([ROIids, this](const PXDCluster * thePxdCluster) {
136 auto ROIidsRange = ROIids.equal_range(thePxdCluster->getSensorID()) ;
137 for (auto theROI = ROIidsRange.first ; theROI != ROIidsRange.second; theROI ++)
138 if (Overlaps(theROI->second, *thePxdCluster)) // *or* Cluster has intersting Properties. TODO
139 return true;
140
141 return false;
142 });
143
144 if (m_CreateOutside) {
145 m_selectorOUT.select([ROIids, this](const PXDCluster * thePxdCluster) {
146 auto ROIidsRange = ROIids.equal_range(thePxdCluster->getSensorID()) ;
147 for (auto theROI = ROIidsRange.first ; theROI != ROIidsRange.second; theROI ++)
148 if (Overlaps(theROI->second, *thePxdCluster)) // *and* Cluster has NO intersting Properties. TODO
149 return false;
150
151 return true;
152 });
153 }
154}
155
157{
158 // omitting the variable name; otherwise a warning is produced (un-used variable)
159 m_selectorIN.select([](const PXDCluster* /* thePxdCluster */) {return true;});
160}
161
162
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.
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
#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.