11#include <tracking/spacePointCreation/MCVXDPurityInfo.h>
13#include <framework/datastore/RelationVector.h>
14#include <mdst/dataobjects/MCParticle.h>
16#include <tracking/spacePointCreation/SpacePoint.h>
18#include <pxd/dataobjects/PXDTrueHit.h>
19#include <svd/dataobjects/SVDTrueHit.h>
21#include <tracking/spacePointCreation/MapHelperFunctions.h>
25#include <unordered_map>
41 const double epsilon = 1e-4;
42 return (std::find_if(vec.begin(), vec.end(),
43 [&epsilon, &weight](
const std::pair<int, double>& p)
44 { return fabs(p.second - weight) <= epsilon; })
54 template<
typename TrueHitType>
59 std::vector<std::pair<int, double> > mcParticles;
60 B2DEBUG(29,
"Found " << trueHits.
size() <<
" TrueHits related to SpacePoint " << spacePoint->
getArrayIndex());
62 for (
size_t iTH = 0; iTH < trueHits.
size(); ++iTH) {
63 B2DEBUG(29,
"Trying to get MCParticles from TrueHit " << trueHits[iTH]->getArrayIndex() <<
64 " from Array " << trueHits[iTH]->getArrayName());
65 Belle2::MCParticle* mcPart = trueHits[iTH]->template getRelatedFrom<Belle2::MCParticle>(
"ALL");
68 if (mcPart !=
nullptr) {
70 B2DEBUG(29,
"TrueHit is related to MCParticle " << mcPartId);
72 B2DEBUG(20,
"Found no MCParticle related to TrueHit " << trueHits[iTH]->getArrayIndex() <<
73 " from Array " << trueHits[iTH]->getArrayName());
75 mcParticles.push_back(std::make_pair(mcPartId, trueHits.
weight(iTH)));
79 std::sort(mcParticles.begin(), mcParticles.end());
80 auto newEnd = std::unique(mcParticles.begin(), mcParticles.end(),
81 [](
const std::pair<int, double>& a,
const std::pair<int, double>& b) { return a.first == b.first; }
83 if (newEnd != mcParticles.end()) B2DEBUG(20,
84 "More than one TrueHits (related to one SpacePoint) are related to the same MCParticle!");
85 mcParticles.resize(std::distance(mcParticles.begin(), newEnd));
90 if (mcParticles.empty()) mcParticles.push_back(std::make_pair(-2, 1));
97 if (!uGood && !vGood) mcParticles.push_back(std::make_pair(-2, 2));
98 else if (uGood && !vGood) mcParticles.push_back(std::make_pair(-2, 21));
99 else if (!uGood && vGood) mcParticles.push_back(std::make_pair(-2, 11));
102 B2ERROR(
"Unknown DetectorType in getMCParticles! This is just a notification! Needs to be handled!");
115 B2DEBUG(29,
"SpacePoint contains PXDCluster");
118 if (setClusters.first) {
120 B2DEBUG(29,
"SpacePoint contains U SVDCluster");
122 if (setClusters.second) {
124 B2DEBUG(29,
"SpacePoint contains V SVDCluster");
134 if (weight < 1.5 && weight > 0)
return {0};
135 if (weight < 2.5 && weight > 0)
return { 1, 2 };
136 if (weight < 20 && weight > 0)
return {1};
137 if (weight > 20 && weight < 30)
return {2};
139 return std::vector<size_t>();
149 static std::vector<Belle2::MCVXDPurityInfo>
createPurityInfosVec(
const std::vector<const Belle2::SpacePoint*>& spacePoints)
151 std::array<unsigned, 3> totalClusters = { {0, 0, 0 } };
153 std::unordered_map<int, std::array<unsigned, 3> > mcClusters;
155 unsigned nClusters = 0;
158 B2DEBUG(29,
"Now processing SpacePoint " << spacePoint->getArrayIndex() <<
" from Array " << spacePoint->getArrayName());
161 nClusters += spacePoint->getNClustersAssigned();
163 std::vector<std::pair<int, double> > mcParticles;
166 else if (spacePoint->getType() ==
VXD::SensorInfoBase::VXD) {B2DEBUG(25,
"found generic spacePoint, treating it as virtualIP");}
167 else B2FATAL(
"Unknown DetectorType (" << spacePoint->getType() <<
") in createPurityInfos! Skipping this SpacePoint " <<
168 spacePoint->getArrayIndex() <<
" from Array " << spacePoint->getArrayName());
170 for (
const std::pair<int, double>& particle : mcParticles) {
172 for (
size_t acc : accessors) {
173 mcClusters[particle.first][acc]++;
177 B2DEBUG(29,
"container contained " << spacePoints.size() <<
" SpacePoint with " << nClusters <<
" Clusters");
180 std::vector<Belle2::MCVXDPurityInfo> purityInfos;
183 purityInfos.push_back(
MCVXDPurityInfo(mcId, totalClusters, mcClusters[mcId]));
187 std::sort(purityInfos.begin(), purityInfos.end(),
201 template<
typename SPContainer>
217 template<
typename SPContainer>
A Class to store the Monte Carlo particle information.
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
The MC VXD Purity info container class.
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
float weight(int index) const
Get weight with index.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
std::pair< bool, bool > getIfClustersAssigned() const
Returns, if u(v)-coordinate is based on cluster information.
Belle2::VXD::SensorInfoBase::SensorType getType() const
Return SensorType (PXD, SVD, ...) on which the SpacePoint lives.
@ VXD
Any type of VXD Sensor.
static std::vector< Belle2::MCVXDPurityInfo > createPurityInfosVec(const std::vector< const Belle2::SpacePoint * > &spacePoints)
create a vector of MCVXDPurityInfos objects for a std::vector<Belle2::SpacePoints>.
std::vector< typename MapType::key_type > getUniqueKeys(const MapType &aMap)
get the unique keys of a map (i.e.
static std::vector< std::pair< int, double > > getMCParticles(const Belle2::SpacePoint *spacePoint)
get the related MCParticles to the TrueHit.
static bool findWeightInVector(std::vector< std::pair< int, double > > &vec, double weight)
find the given weight in the given vector of pair<int,double> NOTE: the criteria for finding are rath...
static std::vector< size_t > getAccessorsFromWeight(double weight)
convert the relation weight (SpacePoint <-> TrueHit) to a type that can be used to access arrays
static void increaseClusterCounters(const Belle2::SpacePoint *spacePoint, std::array< unsigned, 3 > &clusterCtr)
increase the appropriate Cluster counter by asking the SpacePoint which type he has and which Cluster...
static std::vector< Belle2::MCVXDPurityInfo > createPurityInfos(const SPContainer *container)
create a vector of MCVXDPurityInfos objects for any given container holding SpacePoints and providing...
Abstract base class for different kinds of events.