Belle II Software development
PXDClusterCheckModule.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 <pxd/modules/pxdReconstruction/PXDClusterCheckModule.h>
10
11#include <framework/datastore/StoreArray.h>
12#include <framework/datastore/RelationArray.h>
13#include <framework/datastore/RelationIndex.h>
14#include <framework/logging/Logger.h>
15
16#include <mdst/dataobjects/MCParticle.h>
17#include <pxd/dataobjects/PXDDigit.h>
18#include <pxd/dataobjects/PXDCluster.h>
19#include <pxd/dataobjects/PXDTrueHit.h>
20
21using namespace std;
22using namespace Belle2;
23using namespace Belle2::PXD;
24
25
26#define assert_float(A,B) if(!isClose((A),(B)))\
27 B2FATAL("Assertion failed: " << #A << " (" << (A) << ") != " << #B << " (" << (B) << ")");
28#define assert_eq(A,B) if((A)!=(B))\
29 B2FATAL("Assertion failed: " << #A << " (" << (A) << ") != " << #B << " (" << (B) << ")");
30
31namespace {
33 bool isClose(double a, double b, double epsilon = 1e-6)
34 {
35 return a == b || fabs(a - b) < epsilon || (fabs(a / b) - 1.0) < epsilon;
36 }
37
39 template<class range> void checkRelation(range a, range b)
40 {
41 //They should have the same number of elements
42 assert_eq(std::distance(begin(a), end(a)), std::distance(begin(b), end(b)));
43 //Loop over both ranges and compare index and weights
44 for (decltype(begin(a)) ita = begin(a), itb = begin(b); ita != end(a) && itb != end(b); ++ita, ++itb) {
45 assert_eq(ita->indexTo, itb->indexTo);
46 assert_float(ita->weight, itb->weight);
47 }
48 }
49}
50
51//-----------------------------------------------------------------
52// Register the Module
53//-----------------------------------------------------------------
54REG_MODULE(PXDClusterCheck);
55
56//-----------------------------------------------------------------
57// Implementation
58//-----------------------------------------------------------------
59
61{
62 //Set module properties
63 setDescription("This Modules compares to sets of clusters and their relations "
64 "to make sure they are identical. Intended to cross check Clusterizer. "
65 "Default Collection names are assumed for MCParticles, PXDTrueHits and "
66 "PXDDigits");
68 addParam("clustersOld", m_clustersOld, "Digits collection name", string(""));
69 addParam("clustersNew", m_clustersNew, "Digits collection name", string(""));
70}
71
73{
74 //Mark all StoreArrays as required
75 StoreArray<MCParticle> storeMCParticles;
76 StoreArray<PXDDigit> storeDigits;
77 StoreArray<PXDTrueHit> storeTrueHits;
78 StoreArray<PXDCluster> storeClustersOld(m_clustersOld);
79 StoreArray<PXDCluster> storeClustersNew(m_clustersNew);
80 storeMCParticles.isRequired();
81 storeDigits.isRequired();
82 storeTrueHits.isRequired();
83 storeClustersOld.isRequired();
84 storeClustersNew.isRequired();
85
86 //And also all relations
87 RelationArray relClustersMCParticlesOld(storeClustersOld, storeMCParticles);
88 RelationArray relClustersTrueHitsOld(storeClustersOld, storeTrueHits);
89 RelationArray relClustersDigitsOld(storeClustersOld, storeDigits);
90 relClustersMCParticlesOld.isRequired();
91 relClustersTrueHitsOld.isRequired();
92 relClustersDigitsOld.isRequired();
93
94 RelationArray relClustersMCParticlesNew(storeClustersNew, storeMCParticles);
95 RelationArray relClustersTrueHitsNew(storeClustersNew, storeTrueHits);
96 RelationArray relClustersDigitsNew(storeClustersNew, storeDigits);
97 relClustersMCParticlesNew.isRequired();
98 relClustersTrueHitsNew.isRequired();
99 relClustersDigitsNew.isRequired();
100}
101
103{
104 //Obtain all StoreArrays
105 const StoreArray<MCParticle> storeMCParticles;
106 const StoreArray<PXDDigit> storeDigits;
107 const StoreArray<PXDTrueHit> storeTrueHits;
108 const StoreArray<PXDCluster> storeClustersOld(m_clustersOld);
109 const StoreArray<PXDCluster> storeClustersNew(m_clustersNew);
110 //Obtain all relations
111 RelationArray relCDOld(storeClustersOld, storeDigits);
112 RelationArray relCDNew(storeClustersNew, storeDigits);
113 //There might be differences in the order of the pixels so we sort the cluster relation
114 if (relCDOld) relCDOld.consolidate();
115 if (relCDNew) relCDNew.consolidate();
116 //The rest should be sorted anyway so let's just assume they are
117 const RelationIndex<PXDCluster, MCParticle> relClustersMCParticlesOld(storeClustersOld, storeMCParticles);
118 const RelationIndex<PXDCluster, PXDTrueHit> relClustersTrueHitsOld(storeClustersOld, storeTrueHits);
119 const RelationIndex<PXDCluster, MCParticle> relClustersMCParticlesNew(storeClustersNew, storeMCParticles);
120 const RelationIndex<PXDCluster, PXDTrueHit> relClustersTrueHitsNew(storeClustersNew, storeTrueHits);
121
122 //We want the same number of Clusters
123 assert_eq(storeClustersOld.getEntries(), storeClustersNew.getEntries());
124 const unsigned int nCls = storeClustersOld.getEntries();
125 //And for each cluster we want one relation to digits, so size should be equal
126 assert_eq(relCDOld.getEntries(), (int)nCls);
127 assert_eq(relCDNew.getEntries(), (int)nCls);
128 for (unsigned int i = 0; i < nCls; ++i) {
129 //Loop through clusters and compare all members. Since we want to allow for
130 //small deviations we do not use == on the whole cluster but compare the
131 //members individually
132 const PXDCluster& clsOld = *storeClustersOld[i];
133 const PXDCluster& clsNew = *storeClustersNew[i];
134 assert_eq(clsOld.getSensorID(), clsNew.getSensorID());
135 assert_float(clsOld.getU(), clsNew.getU());
136 assert_float(clsOld.getV(), clsNew.getV());
137 assert_float(clsOld.getUSigma(), clsNew.getUSigma());
138 assert_float(clsOld.getVSigma(), clsNew.getVSigma());
139 assert_float(clsOld.getCharge(), clsNew.getCharge());
140 assert_float(clsOld.getSeedCharge(), clsNew.getSeedCharge());
141 assert_eq(clsOld.getSize(), clsNew.getSize());
142 assert_eq(clsOld.getUSize(), clsNew.getUSize());
143 assert_eq(clsOld.getVSize(), clsNew.getVSize());
144 assert_eq(clsOld.getUStart(), clsNew.getUStart());
145 assert_eq(clsOld.getVStart(), clsNew.getVStart());
146 assert_float(clsOld.getRho(), clsNew.getRho());
147
148 //Get the corresponding relation element
149 const RelationElement reOld = relCDOld[i];
150 const RelationElement reNew = relCDNew[i];
151 //The relation is sorted so the index should be correct
152 assert_eq(reOld.getFromIndex(), i);
153 assert_eq(reNew.getFromIndex(), i);
154 //And the number of relations should be equal to the cluster size
155 assert_eq(reOld.getSize(), clsOld.getSize());
156 assert_eq(reNew.getSize(), clsNew.getSize());
157 //And the entries should be identical
158 for (unsigned int j = 0; j < reOld.getSize(); ++j) {
159 assert_eq(reOld.getToIndex(j), reNew.getToIndex(j));
160 assert_eq(reOld.getWeight(j), reNew.getWeight(j));
161 }
162 //Now let's compare the MCParticle and TrueHit relations
163 checkRelation(relClustersMCParticlesOld.getElementsFrom(clsOld), relClustersMCParticlesNew.getElementsFrom(clsNew));
164 checkRelation(relClustersTrueHitsOld.getElementsFrom(clsOld), relClustersTrueHitsNew.getElementsFrom(clsNew));
165 }
166}
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:30
float getV() const
Get v coordinate of hit position.
Definition: PXDCluster.h:136
float getUSigma() const
Get error of u coordinate of hit position.
Definition: PXDCluster.h:141
unsigned short getSeedCharge() const
Get seed charge.
Definition: PXDCluster.h:161
float getVSigma() const
Get error in v coordinate of hit position.
Definition: PXDCluster.h:146
unsigned short getVSize() const
Get cluster size in v direction.
Definition: PXDCluster.h:176
unsigned short getSize() const
Get cluster size.
Definition: PXDCluster.h:166
unsigned short getCharge() const
Get collected charge.
Definition: PXDCluster.h:156
float getRho() const
Get hit position error covariance coefficient.
Definition: PXDCluster.h:151
unsigned short getUSize() const
Get cluster size in u direction.
Definition: PXDCluster.h:171
VxdID getSensorID() const
Get the sensor ID.
Definition: PXDCluster.h:126
unsigned short getVStart() const
Get cluster start cell in v direction.
Definition: PXDCluster.h:186
float getU() const
Get u coordinate of hit position.
Definition: PXDCluster.h:131
unsigned short getUStart() const
Get cluster start cell in u direction.
Definition: PXDCluster.h:181
std::string m_clustersNew
Name of the second PXDCluster StoreArray.
virtual void initialize() override
Initialize the module.
virtual void event() override
do the clustering
std::string m_clustersOld
Name of the first PXDCluster StoreArray.
PXDClusterCheckModule()
Constructor defining the parameters.
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:62
void consolidate()
Consolidate Relation Elements.
int getEntries() const
Get the number of elements.
Class to store a single element of a relation.
index_type getFromIndex() const
Get index we point from.
index_type getToIndex(size_t n=0) const
Get nth index we point to.
size_t getSize() const
Get number of indices we points to.
weight_type getWeight(size_t n=0) const
Get nth weight we point to.
Provides access to fast ( O(log n) ) bi-directional lookups on a specified relation.
Definition: RelationIndex.h:76
range_from getElementsFrom(const FROM *from) const
Return a range of all elements pointing from the given object.
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
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
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
Namespace to encapsulate code needed for simulation and reconstrucion of the PXD.
Abstract base class for different kinds of events.
STL namespace.