ATLAS Offline Software
Loading...
Searching...
No Matches
MCTruthClassifier.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef MCTRUTHCLASSIFIER_MCTRUTHCLASSIFIER_H
6#define MCTRUTHCLASSIFIER_MCTRUTHCLASSIFIER_H
7/********************************************************************
8NAME: MCTruthClassifier.h
9PACKAGE: atlasoff/PhysicsAnalysis/MCTruthClassifier
10AUTHORS: O. Fedin
11CREATED: Sep 2007
12 ********************************************************************/
13
16#include "AsgTools/AsgTool.h"
19// EDM includes
23// For making PID selections easier
28
29#ifndef XAOD_ANALYSIS
30#include "GaudiKernel/ToolHandle.h"
33#endif
34
35#ifndef GENERATIONBASE
36//EDM includes
40#include "xAODEgamma/Electron.h"
41#include "xAODEgamma/Photon.h"
42#include "xAODMuon/Muon.h"
43#endif
44
45#if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
51#include "AthenaKernel/Units.h"
52#endif
53
54#include <cmath>
55#include <utility>
56class MCTruthClassifier : virtual public IMCTruthClassifier , public asg::AsgTool
57{
59public:
60 // constructor
61 MCTruthClassifier(const std::string& type) : asg::AsgTool(type) {
62#if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
63 // Properties used by egammaClusMatch (calorimeter cluster -> truth particle matching).
64 // Angular sizes are in eta/phi units, transverse momentum cuts in GeV.
65 declareProperty("FwdElectronUseG4Sel", m_FwdElectronUseG4Sel = true,
66 "Use Geant4 selection for forward electrons calo clusters. "
67 "Geant4 particles are always skipped for non-forward candidates; "
68 "if true they are skipped for forward electrons as well, if false they are considered for them");
69 declareProperty("FwdElectronTruthExtrEtaCut",
71 "Cut on the eta of the truth Particles to be extrapolated "
72 "for Fwd electrons: particles with |eta| below it are not extrapolated");
74 "FwdElectronTruthExtrEtaWindowCut",
76 "Cut on the delta eta of the truth Particles to be extrapolated for "
77 "Fwd electrons and the current FwdElectron: particles further away in eta are not extrapolated. "
78 "Truth particles in the opposite eta hemisphere are never extrapolated");
79 declareProperty("partExtrConePhi", m_partExtrConePhi = 0.4,
80 "Half-width in phi of the elliptical cone around the cluster in which truth particles are "
81 "extrapolated to the calorimeter (used if ROICone is true, and for the Geant4 particles of inclG4part)");
82 declareProperty("partExtrConeEta", m_partExtrConeEta = 0.2,
83 "Half-width in eta of the elliptical cone around the cluster in which truth particles are "
84 "extrapolated to the calorimeter (used if ROICone is true, and for the Geant4 particles of inclG4part)");
85 declareProperty("phtClasConePhi", m_phtClasConePhi = 0.05,
86 "Half-width in phi of the narrow elliptical cone around the cluster, "
87 "applied to the extrapolated truth particle positions; not used for forward electrons");
88 declareProperty("phtClasConeEta", m_phtClasConeEta = 0.025,
89 "Half-width in eta of the narrow elliptical cone around the cluster, "
90 "applied to the extrapolated truth particle positions; not used for forward electrons");
91 declareProperty("phtdRtoTrCut", m_phtdRtoTrCut = 0.1,
92 "Maximum distance dR between the cluster and the extrapolated truth particle for "
93 "a match (not forward electrons)");
94 declareProperty("fwrdEledRtoTrCut", m_fwrdEledRtoTrCut = 0.15,
95 "Maximum distance dR between the cluster and the extrapolated truth particle for "
96 "a match (forward electrons)");
97 declareProperty("ROICone", m_ROICone = false,
98 "Before the extrapolation, keep only truth particles inside the elliptical cone "
99 "partExtrConePhi x partExtrConeEta around the cluster (not forward electrons). "
100 "The truth particles are always taken from a fixed dR = 0.5 cone around the cluster");
101 //AV: those below are needed in egammaClusMatch
102 declareProperty("pTChargePartCut", m_pTChargePartCut = 1.0,
103 "Minimum pT in GeV of the charged truth particles considered for the cluster matching");
104 declareProperty("pTNeutralPartCut", m_pTNeutralPartCut = 0.,
105 "Minimum pT in GeV of the neutral truth particles considered for the cluster matching");
106 declareProperty("inclG4part", m_inclG4part = false,
107 "If no generator particle was matched to the cluster (not forward electrons), "
108 "also try stable Geant4 particles without a decay vertex");
109#endif
110#ifndef GENERATIONBASE
111 // Properties used to match a track to a truth particle (getGenPart).
112 declareProperty("deltaRMatchCut", m_deltaRMatchCut = 0.2,
113 "Maximum dR between a track and its truth particle for tracks with more than "
114 "NumOfSiHitsCut silicon (pixel + SCT) hits; otherwise the match is dropped");
115 declareProperty("deltaPhiMatchCut", m_deltaPhiMatchCut = 0.2,
116 "Maximum delta phi between a track and its truth particle for tracks with at most "
117 "NumOfSiHitsCut silicon (pixel + SCT) hits; otherwise the match is dropped");
118 declareProperty("NumOfSiHitsCut", m_NumOfSiHitsCut = 3,
119 "Number of silicon (pixel + SCT) hits on a track that decides whether deltaRMatchCut "
120 "(more hits than this) or deltaPhiMatchCut (this many or fewer) is applied");
121#endif
122 }
123 virtual ~MCTruthClassifier() = default ;
124
125 // Gaudi algorithm hooks
126 virtual StatusCode initialize() override {
127 ATH_MSG_INFO(" Initializing MCTruthClassifier");
128#ifndef XAOD_ANALYSIS
129 // Only needed for GenParticle interface
131#endif
133
134#if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
135 if (!m_caloExtensionTool.empty()) {
136 ATH_CHECK(m_caloExtensionTool.retrieve());
137 } else {
138 m_caloExtensionTool.disable();
139 }
140
142
143 if (!m_truthInConeTool.empty()) {
144 ATH_CHECK(m_truthInConeTool.retrieve());
145 } else {
146 m_truthInConeTool.disable();
147 }
148#endif
149 return StatusCode::SUCCESS;
150 }
151
153
154protected:
155 virtual Result particleTruthClassifier(const EventContext& ctx, const xAOD::TruthParticle* thePart) const override final {
156 using namespace MCTruthPartClassifier;
157 if (!thePart) {
158 return {Unknown, NonDefined, nullptr, UnknownOutCome};
159 }
160
161 // retrieve collection and get a pointer
163 if (!truthParticleContainerReadHandle.isValid()) {
164 ATH_MSG_WARNING(" Invalid ReadHandle for xAOD::TruthParticleContainer with key: " << truthParticleContainerReadHandle.key());
165 return {Unknown, NonDefined, thePart, UnknownOutCome};
166 }
167
169 const auto [type, origin] = classifyTruthParticle(*truthParticleContainerReadHandle, thePart, outCome);
170 return {type, origin, thePart, outCome};
171 }
172
173public:
174#ifndef GENERATIONBASE /*These can not run in Generation only release*/
175 //Main method for Track to Truth association
177#ifndef XAOD_ANALYSIS
178 //Main method for egamma clusters to Truth Particle association
179 const xAOD::TruthParticle* egammaClusMatch(const EventContext& ctx, const xAOD::CaloCluster*, bool isFwrdEle) const;
180#endif
181
182protected:
183 virtual Result particleTruthClassifier(const EventContext& ctx, const xAOD::TrackParticle*) const override final;
184
185 virtual Result particleTruthClassifier(const EventContext& ctx, const xAOD::Electron*) const override final;
186
187 virtual Result particleTruthClassifier(const EventContext& ctx, const xAOD::Photon*) const override final;
188
189 virtual Result particleTruthClassifier(const EventContext& ctx, const xAOD::Muon*) const override final;
190
191 virtual Result particleTruthClassifier(const EventContext& ctx, const xAOD::CaloCluster*) const override final;
192
193#endif
194
195private:
196
197#if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
198 bool genPartToCalo(const EventContext& ctx,
199 const xAOD::CaloCluster* clus,
200 const xAOD::TruthParticle* thePart,
201 bool isFwrdEle,
202 double& dRmatch,
203 bool& isNarrowCone,
204 const CaloDetDescrManager& caloDDMgr) const;
205#endif
206
207 /* Data members */
208
211 m_truthParticleContainerKey{this,"xAODTruthParticleContainerName","TruthParticles","ReadHandleKey for xAOD::TruthParticleContainer"};
212
213#if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
215 ToolHandle<Trk::IParticleCaloExtensionTool> m_caloExtensionTool{this,"ParticleCaloExtensionTool",""};
219 ToolHandle<xAOD::ITruthParticlesInConeTool>
220 m_truthInConeTool{this,"TruthInConeTool","xAOD::TruthParticlesInConeTool/TruthParticlesInConeTool"};
221
222 // Properties for the calorimeter cluster -> truth particle matching (egammaClusMatch).
223 // Angular sizes are in eta/phi units, pT cuts in GeV; see the declareProperty descriptions for details.
234
238#endif
239
240#ifndef XAOD_ANALYSIS
242 m_truthLinkVecReadHandleKey{this,"xAODTruthLinkVector","xAODTruthLinks", "ReadHandleKey for xAODTruthParticleLinkVector"};
243#endif
244#ifndef GENERATIONBASE
245 // Properties for the track -> truth particle matching (getGenPart).
249#endif
250};
251#endif // MCTRUTHCLASSIFIER_MCTRUTHCLASSIFIER_H
#define ASG_TOOL_CLASS(CLASSNAME, INT1)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
Property holding a SG store/key/clid from which a ReadHandle is made.
Handle class for reading from StoreGate.
Definition of CaloDetDescrManager.
ATLAS-specific HepMC functions.
struct TBPatternUnitContext Unknown
Wrapper to avoid constant divisions when using units.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
This class provides the client interface for accessing the detector description information common to...
virtual Result particleTruthClassifier(const EventContext &ctx, const xAOD::TruthParticle *) const =0
std::tuple< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin, const xAOD::TruthParticle *, MCTruthPartClassifier::ParticleOutCome > Result
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
int m_NumOfSiHitsCut
Si (pixel + SCT) hit count selecting between deltaRMatchCut and deltaPhiMatchCut.
float m_partExtrConePhi
phi half-width of the cone in which truth particles are extrapolated
bool m_ROICone
only extrapolate truth particles inside the partExtrCone ellipse
float m_pTNeutralPartCut
minimum pT of neutral truth particles considered
SG::ReadHandleKey< xAODTruthParticleLinkVector > m_truthLinkVecReadHandleKey
const xAOD::TruthParticle * getGenPart(const xAOD::TrackParticle *) const
float m_phtdRtoTrCut
max dR cluster - extrapolated truth particle (not forward electrons)
ToolHandle< xAOD::ITruthParticlesInConeTool > m_truthInConeTool
Finds the truth particles in a cone around a cluster (egammaClusMatch); optional, disabled if empty.
float m_phtClasConeEta
eta half-width of the narrow cone around the cluster (not forward electrons)
virtual Result particleTruthClassifier(const EventContext &ctx, const xAOD::Muon *) const override final
float m_partExtrConeEta
eta half-width of the cone in which truth particles are extrapolated
virtual Result particleTruthClassifier(const EventContext &ctx, const xAOD::CaloCluster *) const override final
float m_deltaPhiMatchCut
max delta phi track - truth particle if the track has at most NumOfSiHitsCut Si hits
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Calorimeter detector description, needed together with the extension tool; optional,...
bool genPartToCalo(const EventContext &ctx, const xAOD::CaloCluster *clus, const xAOD::TruthParticle *thePart, bool isFwrdEle, double &dRmatch, bool &isNarrowCone, const CaloDetDescrManager &caloDDMgr) const
float m_deltaRMatchCut
max dR track - truth particle if the track has more than NumOfSiHitsCut Si hits
virtual ~MCTruthClassifier()=default
float m_FwdElectronTruthExtrEtaWindowCut
forward electrons: max |delta eta| to the cluster for a truth particle to be extrapolated
bool m_FwdElectronUseG4Sel
skip Geant4 particles also for forward electrons
MCTruthClassifier(const std::string &type)
virtual Result particleTruthClassifier(const EventContext &ctx, const xAOD::TruthParticle *thePart) const override final
ToolHandle< Trk::IParticleCaloExtensionTool > m_caloExtensionTool
Extrapolates truth particles to the calorimeter (egammaClusMatch); optional, disabled if empty.
float m_fwrdEledRtoTrCut
max dR cluster - extrapolated truth particle (forward electrons)
float m_pTChargePartCut
minimum pT of charged truth particles considered
const xAOD::TruthParticle * egammaClusMatch(const EventContext &ctx, const xAOD::CaloCluster *, bool isFwrdEle) const
float m_phtClasConePhi
phi half-width of the narrow cone around the cluster (not forward electrons)
float m_FwdElectronTruthExtrEtaCut
forward electrons: truth particles with |eta| below this are not extrapolated
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleContainerKey
Key of the xAOD truth particle container that is searched when classifying (ancestors,...
bool m_inclG4part
also try Geant4 particles if no generator particle matched
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Base class for the dual-use tool implementation classes.
Definition AsgTool.h:47
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
ParticleOutCome
Outcome of a (simulated) truth particle: what happened to it after being produced,...
@ UnknownOutCome
End vertex exists, but its content matches none of the patterns below.
@ NonDefined
Origin could not be determined (no production vertex, no ancestor, or particle not classified).
std::pair< ParticleType, ParticleOrigin > classifyTruthParticle(const xAOD::TruthParticleContainer &truthParticleContainer, const xAOD::TruthParticle *const thePart, ParticleOutCome &outCome)
Classify thePart (not nullptr), using truthParticleContainer to look up its ancestors.
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:
Definition Muon.h:13
Photon_v1 Photon
Definition of the current "egamma version".
Definition Photon.h:17
Electron_v1 Electron
Definition of the current "egamma version".
Definition Electron.h:17