ATLAS Offline Software
Loading...
Searching...
No Matches
IMCTruthClassifier.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef MCTRUTHCLASSIFIER_IMCTRUTHCLASSIFIER_H
5#define MCTRUTHCLASSIFIER_IMCTRUTHCLASSIFIER_H
6
12
14#include "AsgTools/IAsgTool.h"
19
20#include <memory>
21#include <unordered_map>
22#include <vector>
23#include <optional>
24
25#ifndef GENERATIONBASE
29#include "xAODJet/Jet.h"
30#include "xAODMuon/Muon.h"
32#endif
33
34#ifndef XAOD_ANALYSIS
37#endif
38
39#if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
41#endif
42
43class IMCTruthClassifier : virtual public asg::IAsgTool
44{
46protected:
47 // Additional information that can be returned by the classifier.
48 // Originally, these were all held in member variables in the classifier,
49 // but that prevents the classifier methods from being made const.
50 // Not all of these are filled by all classifier calls; it would probably
51 // be better to split this up into a hierarchy of structures.
52 class Info
53 {
54 public:
55 Info() : eventContext(Gaudi::Hive::currentContext()) {}
56 Info(const EventContext& ctx) : eventContext(ctx) {}
57
58 ~Info() = default;
59
60 const EventContext& eventContext;
61 const xAOD::TruthParticle* genPart = nullptr;
62
64
65 const xAOD::TruthParticle* mother = nullptr;
66 const xAOD::TruthParticle* Mother() const { return mother;}
67 inline void setMotherProperties(const xAOD::TruthParticle* from) {
68 mother = from;
69 if (!from) return;
70 }
71 inline void resetMotherProperties() { mother = nullptr; }
72
75
76#ifndef GENERATIONBASE /*Disable when no reconstruction packages are expected*/
77 float deltaRMatch = -999;
78 float deltaPhi = -999;
79 float probTrkToTruth = 0;
80 uint8_t numOfSiHits = 0;
81
82 std::vector<const xAOD::TruthParticle*> egPartPtr;
83 std::vector<float> egPartdR;
84 std::vector<std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>> egPartClas;
85
86 std::vector<const xAOD::TrackParticle*> cnvPhotTrkPtr;
87 std::vector<const xAOD::TruthParticle*> cnvPhotTrkToTruthPart;
88 std::vector<MCTruthPartClassifier::ParticleType> cnvPhotPartType;
89 std::vector<MCTruthPartClassifier::ParticleOrigin> cnvPhotPartOrig;
90#endif
91 };
92public:
94 virtual ~IMCTruthClassifier() = default;
95
96 // Methods for Reco object to Truth association
97#ifndef GENERATIONBASE
98 // Method for Track to Truth association
100 const xAOD::TrackParticle*,
101 IMCTruthClassifier::Info* info = nullptr) const = 0;
102#ifndef XAOD_ANALYSIS
103 // Method for egamma clusters to Truth Particle association
105 const xAOD::CaloCluster*, bool,
106 IMCTruthClassifier::Info* info = nullptr) const = 0;
107#endif
108#endif
109
110// Methods for Truth Particle classification
111protected:
112 virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
114
115#ifndef XAOD_ANALYSIS /*These can not run in Analysis Base*/
116 virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
118public:
119 std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
120 particleHepMCTruthClassifier(const HepMcParticleLink& theLink) const {return particleHepMCTruthClassifier(theLink, nullptr); }
121#endif
122protected:
123
124#ifndef GENERATIONBASE
125 // Methods for Reco Particle classification
126 // Rely on the Reco to Truth association and then the Truth classification
127 virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
129
130 virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
132
133 virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
135
136 virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
138
139 virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
141
142 virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
144
145public:
146 std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
147 particleTruthClassifier(const xAOD::Jet* p, bool DR) const {return particleTruthClassifier(p, DR, nullptr); }
148#endif
149public:
151 template <typename T> std::tuple<MCTruthPartClassifier::ParticleType,
153 const xAOD::TruthParticle*,
155 particleTruthClassifier_full(const T* p, std::optional<std::reference_wrapper<const EventContext>> ctx = std::nullopt) const {
157 auto classification = particleTruthClassifier(p, &info);
158 return {classification.first,classification.second,info.genPart,info.particleOutCome};
159 }
160
161 template <typename T> std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
162 particleTruthClassifier(const T* p, std::optional<std::reference_wrapper<const EventContext>> ctx = std::nullopt) const
163 {
164 if (!ctx) return particleTruthClassifier(p, nullptr);
165 IMCTruthClassifier::Info info(ctx->get());
166 return particleTruthClassifier(p, &info);
167 }
168
169};
170
171#endif // MCTRUTHCLASSIFIER_IMCTRUTHCLASSIFIER_H
#define ASG_TOOL_INTERFACE(CLASSNAME)
std::vector< MCTruthPartClassifier::ParticleOrigin > cnvPhotPartOrig
std::vector< const xAOD::TruthParticle * > egPartPtr
void setMotherProperties(const xAOD::TruthParticle *from)
std::vector< float > egPartdR
std::vector< const xAOD::TruthParticle * > cnvPhotTrkToTruthPart
const xAOD::TruthParticle * PhotonMother() const
MCTruthPartClassifier::ParticleOutCome particleOutCome
Info(const EventContext &ctx)
std::vector< MCTruthPartClassifier::ParticleType > cnvPhotPartType
const xAOD::TruthParticle * photonMother
std::vector< const xAOD::TrackParticle * > cnvPhotTrkPtr
const xAOD::TruthParticle * Mother() const
const EventContext & eventContext
std::vector< std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > > egPartClas
const xAOD::TruthParticle * genPart
const xAOD::TruthParticle * mother
virtual ~IMCTruthClassifier()=default
Virtual destructor.
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::Muon *, IMCTruthClassifier::Info *info) const =0
std::tuple< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin, const xAOD::TruthParticle *, MCTruthPartClassifier::ParticleOutCome > particleTruthClassifier_full(const T *p, std::optional< std::reference_wrapper< const EventContext > > ctx=std::nullopt) const
Returns more info than the particleTruthClassifier.
std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const T *p, std::optional< std::reference_wrapper< const EventContext > > ctx=std::nullopt) const
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::Jet *, bool DR, IMCTruthClassifier::Info *info) const =0
virtual const xAOD::TruthParticle * getGenPart(const xAOD::TrackParticle *, IMCTruthClassifier::Info *info=nullptr) const =0
virtual const xAOD::TruthParticle * egammaClusMatch(const xAOD::CaloCluster *, bool, IMCTruthClassifier::Info *info=nullptr) const =0
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::CaloCluster *, IMCTruthClassifier::Info *info) const =0
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::Electron *, IMCTruthClassifier::Info *info) const =0
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::Photon *, IMCTruthClassifier::Info *info) const =0
std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleHepMCTruthClassifier(const HepMcParticleLink &theLink) const
std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::Jet *p, bool DR) const
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::TruthParticle *, IMCTruthClassifier::Info *info) const =0
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::TrackParticle *, IMCTruthClassifier::Info *info) const =0
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleHepMCTruthClassifier(const HepMcParticleLink &theLink, IMCTruthClassifier::Info *info) const =0
Base class for the dual-use tool interface classes.
Definition IAsgTool.h:41
=============================================================================
Jet_v1 Jet
Definition of the current "jet version".
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.
Muon_v1 Muon
Reference the current persistent version:
Photon_v1 Photon
Definition of the current "egamma version".
Electron_v1 Electron
Definition of the current "egamma version".