Belle II Software development
SpacePoint2TrueHitConnectorModule.h
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#pragma once
10
11#include <framework/core/FrameworkExceptions.h>
12#include <framework/core/Module.h>
13
14#include <framework/datastore/StoreArray.h>
15#include <framework/datastore/RelationArray.h>
16
17#include <tracking/spacePointCreation/SpacePoint.h>
18#include <pxd/dataobjects/PXDTrueHit.h>
19#include <svd/dataobjects/SVDTrueHit.h>
20
21#include <string>
22#include <vector>
23#include <array>
24#include <tuple>
25
26#include <unordered_map> // needed for typedef of defaultMap
27
28// root output
29#include <TFile.h>
30#include <TTree.h>
31
32namespace Belle2 {
41 struct TrueHitInfo {
42
43 int m_Id;
44 double m_wU;
45 double m_wV;
46 bool m_U;
47 bool m_V;
50 TrueHitInfo() : m_Id(-1), m_wU(0.), m_wV(0.), m_U(false), m_V(false) { }
51
53 explicit TrueHitInfo(int Id) : m_Id(Id), m_wU(0.), m_wV(0.), m_U(false), m_V(false) { }
54
55 // /** ctor with full information */
56 // TrueHitInfo(int Id, double wU, double wV, bool U, bool V) :
57 // m_Id(Id), m_wU(wU), m_wV(wV), m_U(U), m_V(V) { }
58
59 // /** ctor for single Cluster SpacePoints (SVD) or PXD SpacePoints. The information which Cluster is set can be
60 // * retrieved from the SpacePoint directlly for SVD in this case!
61 // */
62 // TrueHitInfo(int Id, double weight) : m_Id(Id), m_wU(weight), m_wV(0.), m_U(true), m_V(false) { }
63
69 bool operator<(const TrueHitInfo& b) const
70 {
71 return (std::tuple<int, double>(b.m_U + b.m_V, b.m_wU + b.m_wV) < std::tuple<int, double>(m_U + m_V, m_wU + m_wV));
72 }
73
75 short getNClusters() const { return m_U + m_V; }
76
78 void setUWeight(double weight) { m_wU = weight; m_U = true; }
79
81 void setVWeight(double weight) { m_wV = weight; m_V = true; }
82
84 double getWeightSum() const { return m_wU + m_wV; }
85 }; // end of struct TrueHitInfo
86
88 std::ostream& operator<<(std::ostream& os, const TrueHitInfo& thInfo)
89 {
90 os << "Id " << thInfo.m_Id << ": wU = " << thInfo.m_wU << ", setU = " << thInfo.m_U << ". wV = " <<
91 thInfo.m_wV << ", setV = " << thInfo.m_V;
92 return os;
93 }
94
118
119 public:
120
123 void initialize() override;
125 void event() override;
127 void terminate() override;
129 BELLE2_DEFINE_EXCEPTION(NoClusterToSpacePoint,
130 "Found no related Cluster for a SpacePoint!");
134 std::vector<double> SpacePointULocal;
135 std::vector<double> SpacePointVLocal;
136 std::vector<double> SpacePointXGlobal;
137 std::vector<double> SpacePointYGlobal;
138 std::vector<double> SpacePointZGlobal;
140 std::vector<double> TrueHitULocal;
141 std::vector<double> TrueHitVLocal;
142 std::vector<double> TrueHitXGlobal;
143 std::vector<double> TrueHitYGlobal;
144 std::vector<double> TrueHitZGlobal;
146 std::vector<double> WeightU;
147 std::vector<double> WeightV;
149 std::vector<unsigned short int> HitVxdID;
150 std::vector<unsigned short int> RelationStatus;
151 std::vector<unsigned int> NRelations;
153 // TODO TODO TODO TODO TODO TODO TODO: remove if not needed, only for tessting at the moment (i.e. do not commit)
154 std::vector<unsigned int> ClusterSizeU;
155 std::vector<unsigned int> ClusterSizeV;
157 std::vector<double> SpacePointErrorU;
158 std::vector<double> SpacePointErrorV;
160 std::vector<double> SpacePointErrorX;
161 std::vector<double> SpacePointErrorY;
162 std::vector<double> SpacePointErrorZ;
163 // TODO TODO TODO TODO TODO TODO TODO: remove if not needed, only for tessting at the moment (i.e. do not commit)
164 }; // end RootVariables
165
166 protected:
167
168 typedef std::unordered_map<int, TrueHitInfo> baseMapT;
176 };
177
180 c_clearHit = 1, //< bit 0: Only one TrueHit to SpacePoint
181 c_ghostHit = 2, //< bit 1: ghost hit as described in this module
182 c_SpacePointU = 4, //< bit 2: SpacePoint U-coordinate is set
183 c_SpacePointV = 8, //< bit 3: SpacePoint V-coordinate is set
184 c_primaryParticle = 16, //< bit 4: Particle related to TrueHit is primary
185 c_bgParticle = 32, //< bit 5: particle related to TrueHit is background
186 c_nonUniqueRelation = 64, //< bit 6: more than one TrueHit related to SpacePoint
187 c_registeredRelation = 128, //< bit 7: this relation got registered
188 c_noiseCluster = 256, //< bit 8: one of the Clusters has no relation to a TrueHit (i.e. is noise) -> only for twoCluster SPs!
189 }; // end e_relationStatus
190
191 // ================================================== PARAMETERS ==============================================================
194 std::vector<std::string> m_PARAMtrueHitNames;
196 std::vector<std::string> m_PARAMspacePointNames;
199 std::vector<std::string> m_PARAMdetectorTypes;
200
201 std::vector<std::string> m_PARAMclusterNames;
203 std::vector<std::string> m_PARAMrootFileName;
207
210
219// double m_PARAMmaxLocalDiff; /**< maximum difference of local position coordinates for each direction between TrueHit and SpacePoint */
220
225 // ================================================= INTERMALLY USED MEMBERS ==================================================
227 unsigned int m_nContainers;
228
229 std::vector<e_detTypes> m_detectorTypes;
240 std::vector<std::pair<Belle2::StoreArray<Belle2::SpacePoint>, e_detTypes> > m_inputSpacePoints;
241
242 std::vector<Belle2::StoreArray<Belle2::SpacePoint> > m_outputSpacePoints;
247 unsigned int m_iCont;
248
253 TTree* m_treePtr;
255 // ================================================= COUNTERS =================================================================
256 std::vector<unsigned int> m_SpacePointsCtr;
259 std::vector<std::array<unsigned int, 5> > m_nRelTrueHitsCtr;
260
262 std::vector<unsigned int> m_noClusterCtr;
263
264 std::vector<unsigned int> m_regRelationsCtr;
266 std::vector<unsigned int> m_ghostHitCtr;
269 std::vector<unsigned int> m_noTrueHitCtr;
270
272 std::vector<unsigned int> m_rejectedRelsCtr;
273
274 unsigned int m_weightTooSmallCtr;
278 // TODO: make these counters for every container not only for all together!
279// unsigned int m_negWeightCtr; /**< number of negative weights */
280
281// unsigned int m_totWeightsCtr; /**< total number of weights */
282
283// unsigned int m_single2WTHCtr; /**< counter for SpacePoints with more than two possible TrueHits, but only one of them has two weights */
284//
285// unsigned int m_nonSingle2WTHCtr; /**< counter for SpacePoints with more than two possible TrueHits, with more than one of them having two weights */
286//
287// unsigned int m_all2WTHCtr; /**< Counter for SpacePoints where alle possible TrueHits have two weights */
288//
289// unsigned int m_accSingle2WTHCtr; /**< counter for SpacePoints with more than two possible TrueHits, but only one of them has two weights, where a relation was registered to a TrueHit */
290//
291// unsigned int m_accNonSingle2WTHCtr; /**< counter for SpacePoints with more than two possible TrueHits, with more than one of them having two weights where a relation was registered to a TrueHit */
292//
293// unsigned int m_accAll2WTHCtr; /**< Counter for SpacePoints where alle possible TrueHits have two weights, where a relation was registered to a TrueHit */
294//
295// unsigned int m_oneCluster2THCtr; /**< Counter for SpacePoints with only one Cluster but two possible TrueHits (in these cases, the one with the bigger weight gets automatically accepted) */
296//
297// unsigned int m_moreThan2Weights; /**< Count the cases whith more than two weights */
298//
299
303 void initializeCounters();
304
314 template <typename MapType, typename TrueHitType>
315 std::pair<TrueHitType*, double> getTHwithWeight(const MapType& aMap, Belle2::StoreArray<TrueHitType> trueHits,
316 Belle2::SpacePoint* spacePoint, e_detTypes detType);
317
322 template <typename TrueHitType>
323 bool compatibleCombination(Belle2::SpacePoint* spacePoint, TrueHitType* trueHit);
324
334 template<typename MapType, typename ClusterType, typename TrueHitType>
335 MapType getRelatedTrueHits(Belle2::SpacePoint* spacePoint, std::string clusterName = "ALL", std::string trueHitName = "ALL");
336
342 template<typename MapType>
343 MapType processSpacePoint(Belle2::SpacePoint* spacePoint, e_detTypes detType);
344
348 template<typename MapType>
349 void registerAllRelations(Belle2::SpacePoint* spacePoint, MapType trueHitMap, e_detTypes detType);
350
354 template<typename TrueHitType>
355 void registerOneRelation(Belle2::SpacePoint* spacePoint, std::pair<TrueHitType*, double> trueHitwWeight, e_detTypes);
356
360 template<typename ClusterType>
361 void
362 reRegisterClusterRelations(Belle2::SpacePoint* origSpacePoint, Belle2::SpacePoint* newSpacePoint, std::string clusterName = "ALL");
363
367 template<typename ClusterType>
368 std::vector<std::pair<ClusterType*, double> >
369 getRelatedClusters(Belle2::SpacePoint* spacePoint, std::string clusterName = "ALL");
370
376 template<typename TrueHitType>
377 void registerTrueHitRelation(Belle2::SpacePoint* spacePoint, int index, double weight, Belle2::StoreArray<TrueHitType> trueHits);
378
388 template<typename MapType>
389 void positionAnalysis(Belle2::SpacePoint* spacePoint, const MapType& trueHitMap, const int& index, e_detTypes detType);
390
392 std::pair<double, double> getLocalPos(Belle2::SpacePoint* spacePoint);
393
395 template<typename TrueHitType>
396 std::pair<ROOT::Math::XYZVector, ROOT::Math::XYZVector> getTrueHitPositions(TrueHitType* trueHit);
397
399 void initializeRootFile();
400
402 void closeRootFile();
403
404 // TODO TODO TODO TODO TODO TODO TODO: remove if not needed, only for tessting at the moment (i.e. do not commit)
408 std::pair<unsigned short int, unsigned short int> getClusterSizes(Belle2::SpacePoint* spacePoint, e_detTypes detType);
409
413 std::pair<double, double> getLocalError(Belle2::SpacePoint* spacePoint);
414
421 double calculateRelationWeight(const TrueHitInfo& trueHitInfo, Belle2::SpacePoint* spacePoint);
422
423 }; // end module
424
428 template<typename T>
430
431 public:
434 simpleBitfield(const simpleBitfield<T>& __otherBitfield) = delete;
438 const T hasStatus(T __statusBits) const { return (__bits & __statusBits) == __statusBits; }
440 const T getStatus() const { return __bits; }
442 void setStatus(T __statusBits) { __bits = __statusBits; }
444 void addStatus(T __statusBits) { __bits |= __statusBits; }
446 void removeStatus(T __statusBits) { __bits &= __statusBits; }
448 void clear() { __bits = T(); }
449
450 private:
452 }; // end class bitfield
454} // end namespace Belle2
Base class for Modules.
Definition: Module.h:72
Module that tries to register a relation between SpacePoints and TrueHits, hence making some MC Infor...
BELLE2_DEFINE_EXCEPTION(NoClusterToSpacePoint, "Found no related Cluster for a SpacePoint!")
Exception for when no related Cluster can be found for a SpacePoint.
std::vector< std::string > m_PARAMclusterNames
names of containers of Clusters
std::pair< TrueHitType *, double > getTHwithWeight(const MapType &aMap, Belle2::StoreArray< TrueHitType > trueHits, Belle2::SpacePoint *spacePoint, e_detTypes detType)
get the TrueHit from information that is stored in the map (conditions are checked in the following o...
std::vector< std::string > m_PARAMtrueHitNames
names of containers of TrueHits
std::vector< unsigned int > m_SpacePointsCtr
Number of SpacePoints presented to the module.
std::vector< std::string > m_PARAMdetectorTypes
detector type names as strings to determine which name belongs to which detector type
void initialize() override
initialize: initialize counters, check StoreArrays, register StoreArrays, ...
unsigned int m_nContainers
number of passed containers -> storing the size of an input vector for not having to obtain it every ...
void reRegisterClusterRelations(Belle2::SpacePoint *origSpacePoint, Belle2::SpacePoint *newSpacePoint, std::string clusterName="ALL")
register all the relations to Clusters that origSpacePoint had for newSpacePoint
RootVariables m_rootVariables
Root variables used for collecting data eventwise.
std::vector< unsigned int > m_rejectedRelsCtr
Number of SpacePoints that were not related to a TrueHit (i.e.
void event() override
event: try to find the appropriate TrueHit to all SpacePoints
MapType getRelatedTrueHits(Belle2::SpacePoint *spacePoint, std::string clusterName="ALL", std::string trueHitName="ALL")
get all the related TrueHits to the SpacePoint, including their weights in a map (multimap!...
std::pair< double, double > getLocalError(Belle2::SpacePoint *spacePoint)
get the position error of SpacePoints in local coordinates
void registerAllRelations(Belle2::SpacePoint *spacePoint, MapType trueHitMap, e_detTypes detType)
register a Relation to all the TrueHits in the trueHitMap for the passed SpacePoint
std::vector< unsigned int > m_noClusterCtr
Number of SpacePoints without relation to a Cluster (i.e.
std::vector< std::pair< Belle2::StoreArray< Belle2::SpacePoint >, e_detTypes > > m_inputSpacePoints
StoreArray of all input SpacePoints.
double m_PARAMmaxGlobalDiff
maximum difference of global position coordinates for each direction between TrueHit and SpacePoint
void initializeRootFile()
initialize the root file that is used for output
std::unordered_map< int, TrueHitInfo > baseMapT
typedef for shorter notation throughout the module
std::vector< unsigned int > m_regRelationsCtr
Number of registered relations.
unsigned int m_weightTooSmallCtr
Count the omitted relations because of a too small weight.
void terminate() override
terminate: print some summary information
unsigned int m_iCont
'helper variable' needed to not have to pass one integer down to processSpacePoint only to have a han...
std::vector< std::pair< ClusterType *, double > > getRelatedClusters(Belle2::SpacePoint *spacePoint, std::string clusterName="ALL")
get the pointers to the related Clusters and the weight of the original Relations between the spacePo...
std::vector< std::array< unsigned int, 5 > > m_nRelTrueHitsCtr
counting different numbers of related TrueHits (to a SpacePoint) with one variable
void positionAnalysis(Belle2::SpacePoint *spacePoint, const MapType &trueHitMap, const int &index, e_detTypes detType)
Analyze the position of SpacePoints and corresponding TrueHits.
bool m_PARAMstoreSeparate
switch for storing the SpacePoints that can be related to a TrueHit into separate StoreArrays,...
unsigned int m_rejectedNoPrimaryCtr
Count how many times a relation was rejected because TrueHit was not related to primary.
std::vector< Belle2::StoreArray< Belle2::SpacePoint > > m_outputSpacePoints
StoreArray of all output SpacePoints.
std::pair< unsigned short int, unsigned short int > getClusterSizes(Belle2::SpacePoint *spacePoint, e_detTypes detType)
get the sizes of the related Clusters of a SpacePoint
MapType processSpacePoint(Belle2::SpacePoint *spacePoint, e_detTypes detType)
process a SpacePoint.
std::vector< e_detTypes > m_detectorTypes
storing the detector types for each container in vector, needed in initialize
std::vector< std::string > m_PARAMrootFileName
name and update status of root file
double m_maxGlobalDiff
storing the squared value of m_PARAMmaxGlobalDiff here to not alter the parameter input
void registerTrueHitRelation(Belle2::SpacePoint *spacePoint, int index, double weight, Belle2::StoreArray< TrueHitType > trueHits)
register the relation between a SpacePoint and the TrueHit (passed by index in the correspoinding Tru...
std::vector< unsigned int > m_noTrueHitCtr
Number of SpacePoints that contained a Cluster to which no TrueHit could be found (i....
std::string m_PARAMoutputSuffix
suffix that will be appended to the StoreArray names of the output StoreArrays
Belle2::StoreArray< Belle2::SVDTrueHit > m_SVDTrueHits
SVDTrueHits StoreArray used throughout the module.
bool m_PARAMrequirePrimary
require the TrueHit to be related to a primary particle in order for the relation to get registered!
double m_PARAMmaxPosSigma
defining th maximum difference of local coordinates in units of PitchSize / sqrt(12)
Belle2::StoreArray< Belle2::PXDTrueHit > m_PXDTrueHits
PXDTrueHits StoreArray used throughout the module.
Belle2::StoreArray< Belle2::PXDCluster > m_PXDClusters
PXDTClusters StoreArray used throughout the module.
bool m_PARAMregisterAll
switch for registereing all relations for all TrueHits for all SpacePoints (there can be more than 1 ...
Belle2::StoreArray< Belle2::SVDCluster > m_SVDClusters
PXDClusters StoreArray used throughout the module.
void registerOneRelation(Belle2::SpacePoint *spacePoint, std::pair< TrueHitType *, double > trueHitwWeight, e_detTypes)
register Relation between SpacePoint and TrueHit (and if neccessary also between SpacePoint and Clust...
double calculateRelationWeight(const TrueHitInfo &trueHitInfo, Belle2::SpacePoint *spacePoint)
calculate the Relation weight to be used (for SVD only, although method works with PXD as well!...
std::pair< ROOT::Math::XYZVector, ROOT::Math::XYZVector > getTrueHitPositions(TrueHitType *trueHit)
get the local (.first) and global (.second) position of a TrueHit (passed by index)
bool m_PARAMrequireProximity
require the TrueHit to be close to the SpacePoint.
std::vector< std::string > m_PARAMspacePointNames
names of containers of SpacePoints
std::pair< double, double > getLocalPos(Belle2::SpacePoint *spacePoint)
get the local position of a SpacePoint
void initializeCounters()
initialize all counters to 0 WARNING: only call in constructor of module!
bool compatibleCombination(Belle2::SpacePoint *spacePoint, TrueHitType *trueHit)
compares the TrueHit and the SpacePoint positions (global) to decide whether they are compatible NOTE...
bool m_PARAMpositionAnalysis
switch for doing the analysis of positions of SpacePoints and TrueHits
double m_PARAMminWeight
define a minimal weight a relation between Cluster and TrueHit.
std::vector< unsigned int > m_ghostHitCtr
Number of SpacePoints that are considered ghost hits.
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:42
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
helper class for setting up a bitfield that can be used to store several flags in one variable TODO: ...
void removeStatus(T __statusBits)
remove a status from the bitfield
void setStatus(T __statusBits)
set the status of the bitfield (CAUTION: overwrites any previously defined status!...
T __bits
member holding the bits that are maniuplated
const T hasStatus(T __statusBits) const
check if a certain status has been set to the bitfield
void addStatus(T __statusBits)
add a status to the bitfield (if it has not already been added)
simpleBitfield< T > & operator=(simpleBitfield< T > &)=delete
not needed
const T getStatus() const
get the status of the bitfield
simpleBitfield(const simpleBitfield< T > &__otherBitfield)=delete
not needed
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
Abstract base class for different kinds of events.
helper struct to access root variables inside the module
std::vector< unsigned int > ClusterSizeV
size of the v-cluster (resp.
std::vector< double > WeightV
weight of the relation between the V-Cluster of the SpacePoint and the TrueHit
std::vector< double > SpacePointErrorZ
positiion error of SpacePoint in Z direction (global)
std::vector< double > TrueHitXGlobal
TrueHit global X-position.
std::vector< double > SpacePointErrorX
positiion error of SpacePoint in X direction (global)
std::vector< double > SpacePointVLocal
SpacePoint local V-position.
std::vector< unsigned int > ClusterSizeU
size of the u-cluster (resp.
std::vector< double > SpacePointErrorY
positiion error of SpacePoint in Y direction (global)
std::vector< unsigned int > NRelations
Number of related TrueHits to a SpacePoint.
std::vector< double > SpacePointXGlobal
SpacePoint global X-position.
std::vector< unsigned short int > HitVxdID
VxdID of the SpacePoint/TrueHit.
std::vector< double > SpacePointErrorU
position error of SpacePoint in U direction
std::vector< unsigned short int > RelationStatus
different flags of the relation stored in here (see c_relationStatus)
std::vector< double > SpacePointYGlobal
SpacePoint global Y-position.
std::vector< double > SpacePointULocal
SpacePoint local U-position.
std::vector< double > SpacePointZGlobal
SpacePoint global Z-position.
std::vector< double > TrueHitYGlobal
TrueHit global Y-position.
std::vector< double > SpacePointErrorV
position error of SpacePoint in V direction
std::vector< double > WeightU
weight of the relation between the U-Cluster of the SpacePoint and the TrueHit
std::vector< double > TrueHitZGlobal
TrueHit global Z-position.
helper struct that holds information that is needed for the registration of the relation between Spac...
double m_wU
weight of relation between U-Cluster and TrueHit
bool m_U
if true, U-Cluster is used by SpacePoint
void setVWeight(double weight)
set the weight for the V-Cluster
short getNClusters() const
get the number of Clusters that point to this TrueHit
TrueHitInfo()
default ctor, initializing Id to -1, weights to 0, and bools to false
bool operator<(const TrueHitInfo &b) const
comparison operator ensuring strict weak ordering sorts by the number of Clusters first,...
void setUWeight(double weight)
set the weight for the U-Cluster
TrueHitInfo(int Id)
ctor using Id-only
double m_wV
weight of relation between V-Cluster and TrueHit
bool m_V
if true, V-Cluster is used by SpacePoint
double getWeightSum() const
get sum of relation weights
int m_Id
TrueHit ID (StoreArray Index)