Belle II Software  release-05-02-19
AnalyzingAlgorithmClusterBased.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jakob Lettenbichler *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 // svd:
12 #include <svd/dataobjects/SVDCluster.h>
13 
14 
15 // tracking:
16 #include <tracking/spacePointCreation/SpacePoint.h>
17 #include <tracking/trackFindingVXD/analyzingTools/algorithms/AnalyzingAlgorithmBase.h>
18 
19 namespace Belle2 {
29  namespace AnalyzingAlgorithmHelper {
30 
31 // /** non-memberfunction Comparison for equality two clusters */
32 // template <class ClusterType>
33 // inline bool operator == (const ClusterType& a, const ClusterType& b)
34 // { return (a.getSensorID() == b.getSensorID()
35 // and a.isUCluster() == b.isUCluster()
36 // and a.getPosition() == b.getSensorID()); }
37 //
38 
39 
41  template <class TrackCandType>
42  std::vector<const Belle2::SVDCluster*> getSVDClusters(const TrackCandType* aTC, bool wantUCluster)
43  {
44  std::vector<const Belle2::SVDCluster*> clusters;
45  for (const Belle2::SpacePoint* aHit : aTC->getHits()) {
46  auto relatedClusters = aHit->getRelationsTo<SVDCluster>("ALL");
47  for (const Belle2::SVDCluster& aCluster : relatedClusters) {
48  if (aCluster.isUCluster() == wantUCluster) { clusters.push_back(&aCluster); }
49  }
50  }
51  return clusters;
52  }
53 
54 
60  template <class ClusterType>
61  std::vector<const ClusterType*> getUniqueClusters(std::vector<const ClusterType*>& firstTC,
62  std::vector<const ClusterType*>& secondTC)
63  {
64  auto compareClusters = [](const ClusterType * a, const ClusterType * b) -> bool {
65  return (a->getSensorID() == b->getSensorID()
66  and a->isUCluster() == b->isUCluster()
67  and a->getPosition() == b->getPosition()); };
68 
69  std::vector<const ClusterType*> uniqueClusters;
70  for (const auto* firstCluster : firstTC) {
71  for (const auto* secondCluster : secondTC) {
72  if (compareClusters(firstCluster, secondCluster)) { uniqueClusters.push_back(firstCluster); break; }
73  }
74  }
75  return uniqueClusters;
76  }
77  }
78 
79 
80 
81 // residual type algorithms: (uses difference between test- and refTC):
82 
84  template <class DataType, class TCInfoType, class VectorType>
85  class AnalyzingAlgorithmLostUClusters : public AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType> {
86  public:
88  AnalyzingAlgorithmLostUClusters() : AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType>
89  (AlgoritmType::AnalyzingAlgorithmLostUClusters) {}
90 
92  DataType calcData(const TCInfoType& aTC) override
93  {
95  std::vector<const SVDCluster*> uClustersRef = AnalyzingAlgorithmHelper::getSVDClusters(tcs.refTC->tC, true);
96  std::vector<const SVDCluster*> uClustersTest = AnalyzingAlgorithmHelper::getSVDClusters(tcs.testTC->tC, true);
97 
98  return AnalyzingAlgorithmHelper::getUniqueClusters(uClustersRef, uClustersTest).size();
99  }
100  };
101 
102 
103 
105  template <class DataType, class TCInfoType, class VectorType>
106  class AnalyzingAlgorithmLostVClusters : public AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType> {
107  public:
110  (AlgoritmType::AnalyzingAlgorithmLostVClusters) {}
111 
113  DataType calcData(const TCInfoType& aTC) override
114  {
116  std::vector<const SVDCluster*> vClustersRef = AnalyzingAlgorithmHelper::getSVDClusters(tcs.refTC->tC, false);
117  std::vector<const SVDCluster*> vClustersTest = AnalyzingAlgorithmHelper::getSVDClusters(tcs.testTC->tC, false);
118 
119  return AnalyzingAlgorithmHelper::getUniqueClusters(vClustersRef, vClustersTest).size();
120  }
121  };
122 
123 
124 
126  template <class DataType, class TCInfoType, class VectorType>
127  class AnalyzingAlgorithmLostUEDep : public AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType> {
128  public:
132 
134  virtual DataType calcData(const TCInfoType& aTC)
135  {
136  DataType lostEdep;
138  std::vector<const SVDCluster*> uClustersRef = AnalyzingAlgorithmHelper::getSVDClusters(tcs.refTC->tC, true);
139  std::vector<const SVDCluster*> uClustersTest = AnalyzingAlgorithmHelper::getSVDClusters(tcs.testTC->tC, true);
140 
141  std::vector<const SVDCluster*> lostuClusters = AnalyzingAlgorithmHelper::getUniqueClusters(uClustersRef, uClustersTest);
142 
143  for (const SVDCluster* aCluster : lostuClusters) {
144  lostEdep.push_back(double(aCluster->getCharge()));
145  }
146  return lostEdep;
147  }
148  };
149 
150 
151 
153  template <class DataType, class TCInfoType, class VectorType>
154  class AnalyzingAlgorithmLostVEDep : public AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType> {
155  public:
157  AnalyzingAlgorithmLostVEDep() : AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType>
158  (AlgoritmType::AnalyzingAlgorithmLostVEDep) {}
159 
161  virtual DataType calcData(const TCInfoType& aTC)
162  {
163  DataType lostEdep;
165  std::vector<const SVDCluster*> vClustersRef = AnalyzingAlgorithmHelper::getSVDClusters(tcs.refTC->tC, false);
166  std::vector<const SVDCluster*> vClustersTest = AnalyzingAlgorithmHelper::getSVDClusters(tcs.testTC->tC, false);
167 
168  std::vector<const SVDCluster*> lostvClusters = AnalyzingAlgorithmHelper::getUniqueClusters(vClustersRef, vClustersTest);
169 
170  for (const SVDCluster* aCluster : lostvClusters) {
171  lostEdep.push_back(double(aCluster->getCharge()));
172  }
173  return lostEdep;
174  }
175  };
176 
177 
178 
179 // value type algorithms: (uses info of a single TC):
180 
181 
182 
184  template <class DataType, class TCInfoType, class VectorType>
185  class AnalyzingAlgorithmTotalUClusters : public AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType> {
186  public:
188  AnalyzingAlgorithmTotalUClusters() : AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType>
189  (AlgoritmType::AnalyzingAlgorithmTotalUClusters) {}
190 
192  DataType calcData(const TCInfoType& aTC) override
193  {
195  std::vector<const SVDCluster*> uClusters = AnalyzingAlgorithmHelper::getSVDClusters(thisTC.tC, true);
196 
197  return uClusters.size();
198  }
199  };
200 
201 
202 
204  template <class DataType, class TCInfoType, class VectorType>
205  class AnalyzingAlgorithmTotalVClusters : public AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType> {
206  public:
209  (AlgoritmType::AnalyzingAlgorithmTotalVClusters) {}
210 
212  DataType calcData(const TCInfoType& aTC) override
213  {
215  std::vector<const SVDCluster*> vClusters = AnalyzingAlgorithmHelper::getSVDClusters(thisTC.tC, false);
216 
217  return vClusters.size();
218  }
219  };
220 
221 
222 
224  template <class DataType, class TCInfoType, class VectorType>
225  class AnalyzingAlgorithmTotalUEDep : public AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType> {
226  public:
229  (AlgoritmType::AnalyzingAlgorithmTotalUEDep) {}
230 
232  virtual DataType calcData(const TCInfoType& aTC)
233  {
234  DataType totalEDep;
236  std::vector<const SVDCluster*> uClusters = AnalyzingAlgorithmHelper::getSVDClusters(thisTC.tC, true);
237 
238  for (const SVDCluster* aCluster : uClusters) {
239  totalEDep.push_back(double(aCluster->getCharge()));
240  }
241  return totalEDep;
242  }
243  };
244 
245 
246 
248  template <class DataType, class TCInfoType, class VectorType>
249  class AnalyzingAlgorithmTotalVEDep : public AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType> {
250  public:
252  AnalyzingAlgorithmTotalVEDep() : AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType>
253  (AlgoritmType::AnalyzingAlgorithmTotalVEDep) {}
254 
256  virtual DataType calcData(const TCInfoType& aTC)
257  {
258  DataType totalEDep;
260  std::vector<const SVDCluster*> vClusters = AnalyzingAlgorithmHelper::getSVDClusters(thisTC.tC, false);
261 
262  for (const SVDCluster* aCluster : vClusters) {
263  totalEDep.push_back(double(aCluster->getCharge()));
264  }
265  return totalEDep;
266  }
267  };
269 }
Belle2::AnalyzingAlgorithmHelper::getSVDClusters
std::vector< const Belle2::SVDCluster * > getSVDClusters(const TrackCandType *aTC, bool wantUCluster)
helper function to retrieve SVDClusters from a given TC
Definition: AnalyzingAlgorithmClusterBased.h:50
Belle2::AnalyzingAlgorithmBase::AnalyzingAlgorithmBase
AnalyzingAlgorithmBase()
constructor
Definition: AnalyzingAlgorithmBase.h:129
Belle2::AnalyzingAlgorithmTotalVEDep::AnalyzingAlgorithmTotalVEDep
AnalyzingAlgorithmTotalVEDep()
constructor
Definition: AnalyzingAlgorithmClusterBased.h:260
Belle2::AnalyzingAlgorithmLostVClusters::calcData
DataType calcData(const TCInfoType &aTC) override
returns how many v-type-clusters the testTC lost compared to the refTC
Definition: AnalyzingAlgorithmClusterBased.h:121
Belle2::AnalyzingAlgorithmLostUClusters::calcData
DataType calcData(const TCInfoType &aTC) override
returns how many u-type-clusters the testTC lost compared to the refTC
Definition: AnalyzingAlgorithmClusterBased.h:100
Belle2::AnalyzingAlgorithmTotalVClusters
Class for storing an algorithm to find out how many v-type-clusters the given TC had.
Definition: AnalyzingAlgorithmClusterBased.h:213
Belle2::AnalyzingAlgorithmHelper::getUniqueClusters
std::vector< const ClusterType * > getUniqueClusters(std::vector< const ClusterType * > &firstTC, std::vector< const ClusterType * > &secondTC)
helper function to retrieve the number of unique Clusters of first tc given, compared with second tc
Definition: AnalyzingAlgorithmClusterBased.h:69
Belle2::AnalyzingAlgorithmTotalUEDep::calcData
virtual DataType calcData(const TCInfoType &aTC)
returns the energy deposit of u-type-clusters the given TC had
Definition: AnalyzingAlgorithmClusterBased.h:240
Belle2::AnalyzingAlgorithmTotalVEDep::calcData
virtual DataType calcData(const TCInfoType &aTC)
returns the energy deposit of v-type-clusters the given TC had
Definition: AnalyzingAlgorithmClusterBased.h:264
Belle2::AnalyzingAlgorithmTotalVClusters::AnalyzingAlgorithmTotalVClusters
AnalyzingAlgorithmTotalVClusters()
constructor
Definition: AnalyzingAlgorithmClusterBased.h:216
Belle2::AnalyzingAlgorithmLostUEDep
Class for storing an algorithm to find out the energy deposit of u-type-clusters the testTC lost comp...
Definition: AnalyzingAlgorithmClusterBased.h:135
Belle2::AnalyzingAlgorithmTotalUEDep::AnalyzingAlgorithmTotalUEDep
AnalyzingAlgorithmTotalUEDep()
constructor
Definition: AnalyzingAlgorithmClusterBased.h:236
Belle2::SpacePoint
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:52
Belle2::AnalyzingAlgorithmLostUClusters::AnalyzingAlgorithmLostUClusters
AnalyzingAlgorithmLostUClusters()
constructor
Definition: AnalyzingAlgorithmClusterBased.h:96
Belle2::AnalyzingAlgorithmTotalUClusters::calcData
DataType calcData(const TCInfoType &aTC) override
returns how many u-type-clusters the given TC had
Definition: AnalyzingAlgorithmClusterBased.h:200
Belle2::AnalyzingAlgorithmBase::chooseCorrectTC
virtual const TCInfoType & chooseCorrectTC(const TCInfoType &aTC) const
virtual class to determine the correct TC to be used for algorithm calculation.
Definition: AnalyzingAlgorithmBase.h:94
Belle2::AnalyzingAlgorithmLostUEDep::calcData
virtual DataType calcData(const TCInfoType &aTC)
returns the energy deposit of u-type-clusters the testTC lost compared to the refTC
Definition: AnalyzingAlgorithmClusterBased.h:142
Belle2::AnalyzingAlgorithmBase::chooseCorrectPairOfTCs
virtual const TcPair chooseCorrectPairOfTCs(const TCInfoType &aTC) const
makes sure that TcPair.refTC and .testTC are correctly set - throws exeption if there are problems
Definition: AnalyzingAlgorithmBase.h:110
Belle2::AnalyzingAlgorithmLostVEDep::calcData
virtual DataType calcData(const TCInfoType &aTC)
returns the energy deposit of v-type-clusters the testTC lost compared to the refTC
Definition: AnalyzingAlgorithmClusterBased.h:169
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::AnalyzingAlgorithmLostUEDep::AnalyzingAlgorithmLostUEDep
AnalyzingAlgorithmLostUEDep()
constructor
Definition: AnalyzingAlgorithmClusterBased.h:138
Belle2::AlgoritmType::AnalyzingAlgorithmLostUEDep
@ AnalyzingAlgorithmLostUEDep
value type hit (with access to clusters via relations), stores vector< double >. defined in ....
Definition: AlgoritmType.h:73
Belle2::AnalyzingAlgorithmTotalUEDep
Class for storing an algorithm to find out the energy deposit of u-type-clusters the given TC had.
Definition: AnalyzingAlgorithmClusterBased.h:233
Belle2::AnalyzingAlgorithmLostVClusters
Class for storing an algorithm to find out how many v-type-clusters the testTC lost compared to the r...
Definition: AnalyzingAlgorithmClusterBased.h:114
Belle2::SVDCluster
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:38
Belle2::AnalyzingAlgorithmTotalVClusters::calcData
DataType calcData(const TCInfoType &aTC) override
returns how many v-type-clusters the given TC had
Definition: AnalyzingAlgorithmClusterBased.h:220
Belle2::AnalyzingAlgorithmLostVEDep::AnalyzingAlgorithmLostVEDep
AnalyzingAlgorithmLostVEDep()
constructor
Definition: AnalyzingAlgorithmClusterBased.h:165
Belle2::AnalyzingAlgorithmBase
Base class for storing an algorithm determining the data one wants to have.
Definition: AnalyzingAlgorithmBase.h:41
Belle2::AnalyzingAlgorithmTotalUClusters::AnalyzingAlgorithmTotalUClusters
AnalyzingAlgorithmTotalUClusters()
constructor
Definition: AnalyzingAlgorithmClusterBased.h:196
Belle2::AnalyzingAlgorithmLostVClusters::AnalyzingAlgorithmLostVClusters
AnalyzingAlgorithmLostVClusters()
constructor
Definition: AnalyzingAlgorithmClusterBased.h:117