Belle II Software  release-06-02-00
GFTC2SPTCConverterModule.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/Module.h>
12 #include <framework/datastore/StoreArray.h>
13 #include <tracking/spacePointCreation/SpacePoint.h>
14 
15 #include <tracking/spacePointCreation/SpacePointTrackCand.h>
16 
17 #include <genfit/TrackCand.h>
18 #include <genfit/TrackCandHit.h>
19 
20 #include <string>
21 #include <utility>
22 #include <boost/tuple/tuple.hpp>
23 
24 namespace Belle2 {
66 
67  public:
68 
71  void initialize()
72  override;
74  void event() override;
76  void terminate() override;
78  protected:
79 
86  c_noFail = 0,
90  c_unusedHits = -4,
92  c_noValidSP = -6,
93  c_lowNDF = -7,
94  };
95 
97  conversionStatus getFailEnum(int intToConvert)
98  {
99  switch (intToConvert) {
100  case 1: return c_singleClusterSP;
101  case 0: return c_noFail;
102  case -1: return c_foundNoSpacePoint;
103  case -2: return c_foundNoTrueHit;
104  case -3: return c_unsuitableGFTC;
105  case -4: return c_unusedHits;
106  case -5: return c_nonSingleSP;
107  case -6: return c_noValidSP;
108  case -7: return c_lowNDF;
109  default: return c_foundNoSpacePoint;
110  }
111  }
112 
113  // ========================================================== PARAMETERS ============================================================================
114  std::string m_PXDClusterName;
116  std::string m_SVDClusterName;
122  std::string m_PXDClusterSPName;
124  std::string m_genfitTCName;
126  std::string m_SPTCName;
138  // ============================================================= COUNTER VARIABLES ====================================================================
139  unsigned int
142  unsigned int m_genfitTCCtr;
144  unsigned int m_abortedTrueHitCtr;
148  unsigned int m_abortedNoSPCtr;
150  unsigned int
153  unsigned int
156  unsigned int m_skippedPXDnoSPCtr;
158  unsigned int m_skippedPXDnoTHCtr;
160  unsigned int m_skippedSVDnoSPCtr;
162  unsigned int m_skippedSVDnoTHCtr;
164  unsigned int m_singleClusterSPCtr;
166  unsigned int
169  unsigned int m_skippedCluster;
171  unsigned int
176  unsigned int
181  unsigned int m_nonSingleSPCtr;
183  unsigned int
188  {
189  m_SpacePointTCCtr = 0;
190  m_genfitTCCtr = 0;
193  m_abortedNoSPCtr = 0;
194  m_abortedMiscCtr = 0;
195  m_abortedLowNDFCtr = 0;
197 
199  m_nonSingleSPCtr = 0;
200 
206 
207  m_skippedCluster = 0;
210 
213 
214  m_NDF = 0; // (cppcheck complaining about not being initialized in constructor)
215  }
216 
219  {
220  switch (status) {
221  case c_foundNoSpacePoint: m_abortedNoSPCtr++; break;
222  case c_foundNoTrueHit: m_abortedTrueHitCtr++; break;
224  case c_lowNDF: m_abortedLowNDFCtr++; break;
225  case c_noValidSP: m_abortedNoValidSPCtr++; break;
226  default: m_abortedMiscCtr++; break;
227  }
228  return;
229  }
230 
235  template<typename ClusterType>
236  void increaseSkippedCounter(conversionStatus status, ClusterType* cluster)
237  {
238  short unsigned int layerNumber = cluster->getSensorID().getLayerNumber();
239  if (layerNumber > 6) throw SpacePointTrackCand::UnsupportedDetType();
240  switch (status) {
241  case c_noFail:
242  break;
243  case c_singleClusterSP:
244  break;
245  case c_foundNoSpacePoint:
246  if (layerNumber < 3) m_skippedPXDnoSPCtr++;
247  else m_skippedSVDnoSPCtr++;
248  break;
249  case c_foundNoTrueHit:
250  if (layerNumber < 3) m_skippedPXDnoTHCtr++;
251  else m_skippedSVDnoTHCtr++;
252  break;
253  case c_unsuitableGFTC:
254  if (layerNumber < 3) m_skippedPXDunsuitableCtr++;
256  break;
257  case c_noValidSP:
258  if (layerNumber < 3) m_skippedPXDnoValidSPCtr++;
260  break;
261  default:
262  m_skippedCluster++; break;
263  }
264  return;
265  }
266  // ================================================================ INTERNALLY USED VARIABLES ===========================================================
267  std::string svdMainArrayName;
269  int m_NDF;
271  // ================================================= TYPEDEFS ============================================================================================================
272 
273 // #ifndef __CINT__ // was once needed, when it was defined in SpacePointTrackCand.h
274  template<typename HitType> using HitInfo =
275  std::pair<double, const HitType*>;
276 // #endif
277 
278  template<typename T> using flaggedPair =
279  boost::tuple<bool, T, T>;
281  // ============================================================================ MODULE METHODS ==============================================================================
282 
283 
284  void markHitAsUsed(std::vector<flaggedPair<int> >& flaggedHitIDs,
285  int hitToMark);
291  std::pair<const Belle2::SpacePointTrackCand, conversionStatus>
292  createSpacePointTC(const genfit::TrackCand* genfitTC, const StoreArray<PXDCluster>& pxdClusters,
293  const StoreArray<SVDCluster>& svdClusters);
294 
298  std::pair<Belle2::SpacePoint*, conversionStatus>
299  processTrackCandHit(genfit::TrackCandHit* hit, const StoreArray<PXDCluster>& pxdClusters, const StoreArray<SVDCluster>& svdClusters,
300  std::vector<flaggedPair<int> >& flaggedHitIDs, int iHit);
301 
312  template<typename ClusterType, typename TrueHitType>
313  std::pair<Belle2::SpacePoint*, conversionStatus>
314  getSpacePoint(const ClusterType* cluster, std::vector<flaggedPair<int> >& flaggedHitIDs, int iHit, bool singleCluster,
315  std::string arrayName = "");
324  template<typename ClusterType>
325  std::pair<Belle2::SpacePoint*, conversionStatus>
327  std::vector<flaggedPair<int> >& flaggedHitIDs);
328 
336  std::pair<int, int> checkExistAndValid(int clusterInd, int detID, std::vector<flaggedPair<int> >& flaggedHitIDs);
337 
342  int getAppropriateSpacePointIndex(const std::vector<std::pair<bool, bool> >& existAndValidSPs,
343  const std::vector<std::pair<int, int> >& clusterPositions);
344 
349  template<typename ClusterType>
350  std::vector<int> getClusterIndices(const Belle2::SpacePoint* spacePoint, std::string storeArrayName);
351 
355  int getNDF(Belle2::SpacePoint* spacePoint);
356 
360  bool checkUsedAllHits(std::vector<flaggedPair<int> >& flaggedHitIDs);
361 
363  template <typename TrueHitType>
364  bool foundRelatedTrueHit(const Belle2::SpacePoint* spacePoint, unsigned int allowedRelations = 1);
365 
370  "Not all hits of the genfit::TrackCand have been marked as used. This indicates that not all hits have been used to create a SpacePointTrackCand.");
371  };
373 }
Module for converting genfit::TrackCands to SpacePointTrackCands.
unsigned int m_abortedNoSPCtr
Counter for aborted conversions because no SpacePoint has been found.
int getNDF(Belle2::SpacePoint *spacePoint)
get the NDF of a SpacePoint
int m_PARAMminNDF
parameter for specifying a minimal number of degrees of freedom a SpacePointTrackCand has to have in ...
unsigned int m_skippedPXDunsuitableCtr
Counter for skipped PXD Clusters due to unsuitable GFTC.
bool m_PARAMskipCluster
Switch for controlling the behavior of the converter, when for one or more Clusters no appropriate Sp...
conversionStatus
enum for differentiating different reasons why a conversion failed negative values mean fail!
@ c_nonSingleSP
conversion failed because there were more than one single Cluster SpacePoints related to a Cluster
@ c_foundNoSpacePoint
conversion failed because no related SpacePoint was found to a Cluster/Hit of the GFTC
@ c_singleClusterSP
had to use a singleCluster SpacePoint (also returned if PXD is passed!
@ c_lowNDF
conversion failed because the created SpacePointTrackCand had not enough degrees of freedom
@ c_unusedHits
conversion failed because there were unused Hits
@ c_noValidSP
conversion failed because there was no valid SpacePoint (only possible for double Cluster SpacePoints...
@ c_foundNoTrueHit
conversion failed because there was no related SpacePoint to a TrueHit
@ c_unsuitableGFTC
conversion failed because the GFTC is considered not suitable for conversion
@ c_noFail
conversion without any problems
unsigned int m_skippedSVDnoValidSPCtr
Counter for skipped SVD Clusters due to no found valid SpacePoint.
std::string m_SingleClusterSVDSPName
Single Cluster SVD SpacePoints collection name.
unsigned int m_abortedUnsuitableTCCtr
Counter for aborted conversions due to unsuitable genfit::TrackCand.
std::pair< const Belle2::SpacePointTrackCand, conversionStatus > createSpacePointTC(const genfit::TrackCand *genfitTC, const StoreArray< PXDCluster > &pxdClusters, const StoreArray< SVDCluster > &svdClusters)
create a SpacePointTrackCand from the genfit::TrackCand
std::pair< double, const HitType * > HitInfo
container used for storing information, that is then put into the SpacePointTrackCand
std::string m_NoSingleClusterSVDSPName
Non SingleCluster SVD SpacePoints collection name.
void initialize() override
initialize module (e.g.
void event() override
event: convert genfit::TrackCands to SpacePointTrackCands
std::string m_PXDClusterName
PXDCluster collection name.
unsigned int m_skippedSVDunsuitableCtr
Counter for skipped SVD Clusters due to unsuitable GFTC.
void terminate() override
terminate: print some summary information on the processed events
bool foundRelatedTrueHit(const Belle2::SpacePoint *spacePoint, unsigned int allowedRelations=1)
check if there is a related TrueHit for a given SpacePoint.
unsigned int m_skippedSVDnoSPCtr
Counter for skipped SVD Clusters, due to no found SpacePoint.
unsigned int m_genfitTCCtr
Counter for genfit::TrackCands which were presented to the module.
std::string m_genfitTCName
Name of collection of genfit::TrackCand StoreArray.
void increaseSkippedCounter(conversionStatus status, ClusterType *cluster)
increase the appropriate counter variable if a Cluster is skipped (i.e.
bool m_PARAMcheckTrueHits
Parameter Indicating if the TrueHits related from the Clusters forming a SpacePoint should be checked...
unsigned int m_skippedSVDnoTHCtr
Counter for skipped SVD Clusters, due to no related TrueHit to a SpacePoint.
bool m_PARAMuseSingleClusterSP
Parameter Indicating if SingleCluster SVD SpacePoints should be used if no double Cluster SVD SpacePo...
unsigned int m_nonSingleSPCtr
Counter for cases where there is more than one single Cluster SpacePoint related to a Cluster.
unsigned int m_noTwoClusterSPCtr
Counter for cases where no related two Cluster could be found for a Cluster.
std::pair< Belle2::SpacePoint *, conversionStatus > processTrackCandHit(genfit::TrackCandHit *hit, const StoreArray< PXDCluster > &pxdClusters, const StoreArray< SVDCluster > &svdClusters, std::vector< flaggedPair< int > > &flaggedHitIDs, int iHit)
process a TrackCandHit (i.e.
unsigned int m_abortedNoValidSPCtr
Counter for aborted conversions due to no found valid SpacePoint to any Cluster of the GFTC.
boost::tuple< bool, T, T > flaggedPair
typdef, for avoiding having a vector<bool> and a vector<pair<T,T>>
std::string m_SPTCName
Name of collection under which SpacePointTrackCands will be stored in the StoreArray.
conversionStatus getFailEnum(int intToConvert)
get the enum representation of an integer
void increaseFailCounter(conversionStatus status)
increase the counter that 'belongs' to the conversionStatus
void markHitAsUsed(std::vector< flaggedPair< int > > &flaggedHitIDs, int hitToMark)
mark a hit as used, i.e.
unsigned int m_skippedPXDnoSPCtr
Counter for skipped PXD Clusters, due to no found SpacePoint.
std::pair< Belle2::SpacePoint *, conversionStatus > findAppropriateSpacePoint(const Belle2::RelationVector< Belle2::SpacePoint > &spacePoints, std::vector< flaggedPair< int > > &flaggedHitIDs)
given a RelationVector with SpacePoints in it, it tries to get the appropriate one (see main document...
unsigned int m_skippedPXDnoValidSPCtr
Counter for skipped PXD Clusters due to no found valid SpacePoint.
std::string m_SVDClusterName
SVDCluster collection name.
std::string m_PXDClusterSPName
PXDCluster SpacePoints collection name.
unsigned int m_skippedPXDnoTHCtr
Counter for skipped PXD Clusters, due to no related TrueHit to a SpacePoint.
std::pair< int, int > checkExistAndValid(int clusterInd, int detID, std::vector< flaggedPair< int > > &flaggedHitIDs)
check if the Cluster (of a SpacePoint) is valid and/or exists in a genfit::TrackCand
unsigned int m_skippedCluster
Counter for skipped Cluster.
std::pair< Belle2::SpacePoint *, conversionStatus > getSpacePoint(const ClusterType *cluster, std::vector< flaggedPair< int > > &flaggedHitIDs, int iHit, bool singleCluster, std::string arrayName="")
templated version to get a SpacePoint from a Cluster
bool m_PARAMcheckNoSingleSVDSP
Switch for checking the StoreArray of non-single cluster SVD SpacePoints in initialize.
unsigned int m_SpacePointTCCtr
Counter for SpacePointTrackCands which were converted (if a curling track is split up,...
unsigned int m_abortedLowNDFCtr
Counter for SpacePointTrackCands that were not stored due to a too small number of degrees of freedom...
bool checkUsedAllHits(std::vector< flaggedPair< int > > &flaggedHitIDs)
check if all hits have been used (i.e.
std::vector< int > getClusterIndices(const Belle2::SpacePoint *spacePoint, std::string storeArrayName)
get the indices of the Clusters related to the SpacePoint.
void initializeCounters()
reset counters to 0 to avoid indeterministic behaviour
unsigned int m_abortedMiscCtr
temporary counter used for counting all failed conversions for which the reason cannot be deduced at ...
int m_NDF
number of degrees of freedom.
unsigned int m_singleClusterSPCtr
Counter for single cluster SVD SpacePoints.
int getAppropriateSpacePointIndex(const std::vector< std::pair< bool, bool > > &existAndValidSPs, const std::vector< std::pair< int, int > > &clusterPositions)
get the position of the appropriate SpacePoint inside the RelationVector NOTE: returns negative index...
std::string svdMainArrayName
Name of the Array of SVD SpacePoints that shall be searched first.
unsigned int m_abortedTrueHitCtr
Counting discarded conversions due to check for TrueHits not good.
BELLE2_DEFINE_EXCEPTION(UnusedHits, "Not all hits of the genfit::TrackCand have been marked as used. This indicates that not all hits have been used to create a SpacePointTrackCand.")
Exception thrown, when not all hits of a genfit::TrackCand have been used for conversion.
Base class for Modules.
Definition: Module.h:72
Class for type safe access to objects that are referred to in relations.
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:42
Hit object for use in TrackCand.
Definition: TrackCandHit.h:34
Track candidate – seed values and indices.
Definition: TrackCand.h:69
Abstract base class for different kinds of events.