Belle II Software  release-05-01-25
DATCONSpacePointHelperFunctions.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jakob Lettenbichler, Giulia Casarosa, Christian Wessel *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <vector>
14 
15 #include <framework/datastore/StoreArray.h>
16 
17 #include <mdst/dataobjects/MCParticle.h>
18 #include <svd/dataobjects/SVDTrueHit.h>
19 
20 #include <vxd/dataobjects/VxdID.h>
21 
22 #include <tracking/dataobjects/DATCONSVDSpacePoint.h>
23 
24 #include <unordered_map>
25 
26 namespace Belle2 {
36  struct ClustersOnSensor {
37 
38  public:
39 
41  inline void addCluster(const SVDCluster* entry)
42  {
43  vxdID = entry->getSensorID();
44  if (entry->isUCluster() == true) { clustersU.push_back(entry); return; }
45  clustersV.push_back(entry);
46  }
47 
50 
55  std::vector<const SVDCluster*> clustersU;
56 
61  std::vector<const SVDCluster*> clustersV;
62 
63  };
64 
65 
71  void provideDATCONSVDClusterSingles(const StoreArray<SVDCluster>& DATCONSVDClusters,
73  {
74  for (unsigned int i = 0; i < uint(DATCONSVDClusters.getEntries()); ++i) {
75  const SVDCluster* currentCluster = DATCONSVDClusters[i];
76  std::vector<const SVDCluster*> currentClusterCombi = { currentCluster };
77  DATCONSVDSpacePoint* newSP = spacePoints.appendNew(currentClusterCombi);
78  newSP->addRelationTo(currentCluster);
79  }
80  }
81 
82 
83 
92  inline void findPossibleCombinations(const Belle2::ClustersOnSensor& aSensor,
93  std::vector< std::vector<const SVDCluster*> >& foundCombinations)
94  {
95 
96  for (const SVDCluster* uCluster : aSensor.clustersU) {
97  // if (uCluster->getClsTime() < minClusterTime)
98  // continue;
99  for (const SVDCluster* vCluster : aSensor.clustersV) {
100  // if (vCluster->getClsTime() < minClusterTime)
101  // continue;
102  // cppcheck-suppress useStlAlgorithm
103  foundCombinations.push_back({uCluster, vCluster});
104 
105  }
106  }
107  }
108 
116  void provideDATCONSVDClusterCombinations(const StoreArray<SVDCluster>& DATCONSVDClusters,
117  StoreArray<DATCONSVDSpacePoint>& spacePoints)
118  {
119  // collects one entry per sensor, each entry will contain all Clusters on it TODO: better to use a sorted vector/list?
120  std::unordered_map<VxdID::baseType, Belle2::ClustersOnSensor> activatedSensors;
121 
122  // collects all combinations of Clusters which were possible (condition: 1u+1v-Cluster on the same sensor)
123  std::vector<std::vector<const SVDCluster*> > foundCombinations;
124 
125 
126  // sort Clusters by sensor. After the loop, each entry of activatedSensors contains all U and V-type clusters on that sensor
127  for (unsigned int i = 0; i < uint(DATCONSVDClusters.getEntries()); ++i) {
128  SVDCluster* currentCluster = DATCONSVDClusters[i];
129 
130  activatedSensors[currentCluster->getSensorID().getID()].addCluster(currentCluster);
131  }
132 
133  for (auto& aSensor : activatedSensors) {
134 // findPossibleCombinations(aSensor.second, foundCombinations, minClusterTime);
135  findPossibleCombinations(aSensor.second, foundCombinations);
136  }
137 
138  for (auto& clusterCombi : foundCombinations) {
139  DATCONSVDSpacePoint* newSP = spacePoints.appendNew(clusterCombi);
140  for (auto* cluster : clusterCombi) {
141  newSP->addRelationTo(cluster, cluster->isUCluster() ? 1. : -1.);
142 
143  RelationVector<MCParticle> relatedMC = cluster->getRelationsTo<MCParticle>();
144  RelationVector<SVDTrueHit> relatedSVDTrue = cluster->getRelationsTo<SVDTrueHit>();
145 
146  // Register relations to the MCParticles and SVDTrueHits
147  if (relatedMC.size() > 0) {
148  for (unsigned int relmcindex = 0; relmcindex < relatedMC.size(); relmcindex++) {
149  newSP->addRelationTo(relatedMC[relmcindex], relatedMC.weight(relmcindex));
150  }
151  }
152  if (relatedSVDTrue.size() > 0) {
153  for (unsigned int reltruehitindex = 0; reltruehitindex < relatedSVDTrue.size(); reltruehitindex++) {
154  newSP->addRelationTo(relatedSVDTrue[reltruehitindex], relatedSVDTrue.weight(reltruehitindex));
155  }
156  }
157 
158  }
159 
160  }
161  }
162 
164 } //Belle2 namespace
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
Belle2::findPossibleCombinations
void findPossibleCombinations(const Belle2::ClustersOnSensor &aSensor, std::vector< std::vector< const SVDCluster * > > &foundCombinations, SVDClusterCalibrations &clusterCal)
stores all possible 2-Cluster-combinations.
Definition: SpacePointHelperFunctions.h:102
Belle2::DATCONSVDSpacePoint
DATCONSVDSpacePoint typically is build from 1-2 DATCONSimpleSVDClusters.
Definition: DATCONSVDSpacePoint.h:51
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::ClustersOnSensor::clustersU
std::vector< const SVDCluster * > clustersU
stores all SVDclusters of U type.
Definition: SpacePointHelperFunctions.h:66
Belle2::ClustersOnSensor::addCluster
void addCluster(const SVDCluster *entry)
member function to automatically add the cluster to its corresponding entry
Definition: SpacePointHelperFunctions.h:52
Belle2::VxdID::getID
baseType getID() const
Get the unique id.
Definition: VxdID.h:104
Belle2::RelationsInterface::addRelationTo
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
Definition: RelationsObject.h:144
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::provideDATCONSVDClusterCombinations
void provideDATCONSVDClusterCombinations(const StoreArray< SVDCluster > &DATCONSVDClusters, StoreArray< DATCONSVDSpacePoint > &spacePoints)
finds all possible combinations of U and V Clusters for DATCONSVDClusters.
Definition: DATCONSpacePointHelperFunctions.h:124
Belle2::SVDCluster::getSensorID
VxdID getSensorID() const
Get the sensor ID.
Definition: SVDCluster.h:110
Belle2::provideDATCONSVDClusterSingles
void provideDATCONSVDClusterSingles(const StoreArray< SVDCluster > &DATCONSVDClusters, StoreArray< DATCONSVDSpacePoint > &spacePoints)
simply store one spacePoint for each existing DATCONSVDCluster.
Definition: DATCONSpacePointHelperFunctions.h:79
Belle2::SVDCluster
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:38
Belle2::StoreArray< SVDCluster >
Belle2::ClustersOnSensor::vxdID
VxdID vxdID
Id of sensor, TODO can be removed if struct is used in a map.
Definition: SpacePointHelperFunctions.h:60
Belle2::ClustersOnSensor
small struct for storing all clusters of the same sensor in one container.
Definition: SpacePointHelperFunctions.h:47
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226
Belle2::ClustersOnSensor::clustersV
std::vector< const SVDCluster * > clustersV
stores all SVDclusters of V type.
Definition: SpacePointHelperFunctions.h:72