13 #include <tracking/spacePointCreation/MCVXDPurityInfo.h>
15 #include <framework/datastore/RelationVector.h>
16 #include <mdst/dataobjects/MCParticle.h>
18 #include <tracking/spacePointCreation/SpacePoint.h>
20 #include <pxd/dataobjects/PXDTrueHit.h>
21 #include <svd/dataobjects/SVDTrueHit.h>
23 #include <tracking/spacePointCreation/MapHelperFunctions.h>
27 #include <unordered_map>
41 static bool findWeightInVector(std::vector<std::pair<int, double> >& vec,
double weight)
43 const double epsilon = 1
e-4;
44 return (std::find_if(vec.begin(), vec.end(),
45 [&epsilon, &weight](
const std::pair<int, double>& p)
46 { return fabs(p.second - weight) <= epsilon; })
56 template<
typename TrueHitType>
61 std::vector<std::pair<int, double> > mcParticles;
62 B2DEBUG(4999,
"Found " << trueHits.
size() <<
" TrueHits related to SpacePoint " << spacePoint->
getArrayIndex());
64 for (
size_t iTH = 0; iTH < trueHits.
size(); ++iTH) {
65 B2DEBUG(4999,
"Trying to get MCParticles from TrueHit " << trueHits[iTH]->getArrayIndex() <<
66 " from Array " << trueHits[iTH]->getArrayName());
67 Belle2::MCParticle* mcPart = trueHits[iTH]->template getRelatedFrom<Belle2::MCParticle>(
"ALL");
72 B2DEBUG(4999,
"TrueHit is related to MCParticle " << mcPartId);
74 B2DEBUG(1,
"Found no MCParticle related to TrueHit " << trueHits[iTH]->getArrayIndex() <<
75 " from Array " << trueHits[iTH]->getArrayName());
77 mcParticles.push_back(std::make_pair(mcPartId, trueHits.
weight(iTH)));
81 std::sort(mcParticles.begin(), mcParticles.end());
82 auto newEnd = std::unique(mcParticles.begin(), mcParticles.end(),
83 [](
const std::pair<int, double>& a,
const std::pair<int, double>& b) { return a.first == b.first; }
85 if (newEnd != mcParticles.end()) B2DEBUG(1,
86 "More than one TrueHits (related to one SpacePoint) are related to the same MCParticle!");
87 mcParticles.resize(std::distance(mcParticles.begin(), newEnd));
92 if (mcParticles.empty()) mcParticles.push_back(std::make_pair(-2, 1));
99 if (!uGood && !vGood) mcParticles.push_back(std::make_pair(-2, 2));
100 else if (uGood && !vGood) mcParticles.push_back(std::make_pair(-2, 21));
101 else if (!uGood && vGood) mcParticles.push_back(std::make_pair(-2, 11));
104 B2ERROR(
"Unknown DetectorType in getMCParticles! This is just a notification! Needs to be handled!");
117 B2DEBUG(4999,
"SpacePoint contains PXDCluster");
120 if (setClusters.first) {
122 B2DEBUG(4999,
"SpacePoint contains U SVDCluster");
124 if (setClusters.second) {
126 B2DEBUG(4999,
"SpacePoint contains V SVDCluster");
136 if (weight < 1.5 && weight > 0)
return {0};
137 if (weight < 2.5 && weight > 0)
return { 1, 2 };
138 if (weight < 20 && weight > 0)
return {1};
139 if (weight > 20 && weight < 30)
return {2};
141 return std::vector<size_t>();
151 static std::vector<Belle2::MCVXDPurityInfo>
createPurityInfosVec(
const std::vector<const Belle2::SpacePoint*>& spacePoints)
153 std::array<unsigned, 3> totalClusters = { {0, 0, 0 } };
155 std::unordered_map<int, std::array<unsigned, 3> > mcClusters;
157 unsigned nClusters = 0;
160 B2DEBUG(4999,
"Now processing SpacePoint " << spacePoint->
getArrayIndex() <<
" from Array " << spacePoint->
getArrayName());
165 std::vector<std::pair<int, double> > mcParticles;
169 else B2FATAL(
"Unknown DetectorType (" << spacePoint->
getType() <<
") in createPurityInfos! Skipping this SpacePoint " <<
172 for (
const std::pair<int, double>& particle : mcParticles) {
174 for (
size_t acc : accessors) {
175 mcClusters[particle.first][acc]++;
179 B2DEBUG(4999,
"container contained " << spacePoints.size() <<
" SpacePoint with " << nClusters <<
" Clusters");
182 std::vector<Belle2::MCVXDPurityInfo> purityInfos;
185 purityInfos.push_back(MCVXDPurityInfo(mcId, totalClusters, mcClusters[mcId]));
189 std::sort(purityInfos.begin(), purityInfos.end(),
190 [](
const MCVXDPurityInfo & left,
const MCVXDPurityInfo & right) { return left > right; }
203 template<
typename SPContainer>
204 static std::vector<Belle2::MCVXDPurityInfo>
createPurityInfos(
const SPContainer* container)
219 template<
typename SPContainer>
220 static std::vector<Belle2::MCVXDPurityInfo>
createPurityInfos(
const SPContainer& container)