ATLAS Offline Software
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 /********************************************************************
8 NAME: MCTruthClassifier.h
9 PACKAGE: atlasoff/PhysicsAnalysis/MCTruthClassifier
10 AUTHORS: O. Fedin
11 CREATED: Sep 2007
12  ********************************************************************/
13 
15 #include "AsgTools/AsgTool.h"
18 // EDM includes
20 #include "xAODTruth/TruthVertex.h"
22 // For making PID selections easier
26 
27 #ifndef XAOD_ANALYSIS
28 #include "GaudiKernel/ToolHandle.h"
30 #include "AtlasHepMC/GenParticle.h"
31 #endif
32 
33 #ifndef GENERATIONBASE
34 //EDM includes
38 #include "xAODEgamma/Electron.h"
39 #include "xAODEgamma/Photon.h"
40 #include "xAODMuon/Muon.h"
41 #include "xAODJet/Jet.h"
42 #endif
43 
44 #if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
50 #include "AthenaKernel/Units.h"
51 #endif
52 
53 #include <cmath>
54 #include <utility>
55 class MCTruthClassifier : virtual public IMCTruthClassifier , public asg::AsgTool
56 {
58 public:
59  // constructor
60  MCTruthClassifier(const std::string& type) : asg::AsgTool(type) {
61 #if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
62  declareProperty("FwdElectronUseG4Sel", m_FwdElectronUseG4Sel = true,
63  "Use Geant4 selection for forward electrons calo clusters");
64  declareProperty("FwdElectronTruthExtrEtaCut",
66  "Cut on the eta of the truth Particles to be extrapolated "
67  "for Fwd electrons");
69  "FwdElectronTruthExtrEtaWindowCut",
71  "Cut on the delta eta of the truth Particles to be extrapolated for "
72  "Fwd electrons and the current FwdElectron");
73  declareProperty("partExtrConePhi", m_partExtrConePhi = 0.4);
74  declareProperty("partExtrConeEta", m_partExtrConeEta = 0.2);
75  declareProperty("phtClasConePhi", m_phtClasConePhi = 0.05);
76  declareProperty("phtClasConeEta", m_phtClasConeEta = 0.025);
77  declareProperty("useCaching", m_useCaching = true);
78  declareProperty("phtdRtoTrCut", m_phtdRtoTrCut = 0.1);
79  declareProperty("fwrdEledRtoTrCut", m_fwrdEledRtoTrCut = 0.15);
80  declareProperty("ROICone", m_ROICone = false);
81  //AV: those below are needed in egammaClusMatch
82  declareProperty("pTChargePartCut", m_pTChargePartCut = 1.0);
83  declareProperty("pTNeutralPartCut", m_pTNeutralPartCut = 0.);
84  declareProperty("inclG4part", m_inclG4part = false);
85 #endif
86 #ifndef GENERATIONBASE
87  declareProperty("deltaRMatchCut", m_deltaRMatchCut = 0.2);
88  declareProperty("deltaPhiMatchCut", m_deltaPhiMatchCut = 0.2);
89  declareProperty("NumOfSiHitsCut", m_NumOfSiHitsCut = 3);
90  declareProperty("jetPartDRMatch", m_jetPartDRMatch = 0.4);
91 #endif
92  }
93  virtual ~MCTruthClassifier() = default ;
94 
95  // Gaudi algorithm hooks
96  virtual StatusCode initialize() override {
97  ATH_MSG_INFO(" Initializing MCTruthClassifier");
98 #ifndef XAOD_ANALYSIS
99  // Only needed for GenParticle interface
101 #endif
103 
104 #if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
105  if (!m_caloExtensionTool.empty()) {
106  ATH_CHECK(m_caloExtensionTool.retrieve());
107  } else {
108  m_caloExtensionTool.disable();
109  }
110 
112 
113  if (!m_truthInConeTool.empty()) {
114  ATH_CHECK(m_truthInConeTool.retrieve());
115  } else {
116  m_truthInConeTool.disable();
117  }
118 #endif
119  return StatusCode::SUCCESS;
120  }
121  virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
123 
124 #ifndef XAOD_ANALYSIS /*These can not run in Analysis Base*/
125  virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
127 
128 #endif
129 
130 #ifndef GENERATIONBASE /*These can not run in Generation only release*/
131  //Main method for Track to Truth association
133 
134 #ifndef XAOD_ANALYSIS
135  //Main method for egamma clusters to Truth Particle association
136  virtual const xAOD::TruthParticle* egammaClusMatch(const xAOD::CaloCluster*,bool,MCTruthPartClassifier::Info* info) const override final;
137 #endif
138 
139  virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
141 
144 
147 
150 
153 
155  particleTruthClassifier(const xAOD::Jet*, bool DR, MCTruthPartClassifier::Info* info = nullptr) const override final;
156 #endif
157 
158 private:
159  inline double detEta(double x, double y) const { return std::abs(x - y); }
160  inline double detPhi(double x, double y) const {
161  double det = x - y;
162  if (det > M_PI) det = det - 2. * M_PI;
163  if (det < -M_PI) det = det + 2. * M_PI;
164  return std::abs(det);
165  }
166 
167  // Temporary helper methods for detecting loops in the truth record
168  // Method1: Returns true if the parent particle is in the list of
169  // children of its decay vertex. Otherwise, returns the result of
170  // Method3.
171  bool TruthLoopDetectionMethod1(const xAOD::TruthVertex* childOrigVtx, const xAOD::TruthParticle* parent) const;
172  // Method2: Returns true if the parent production vertex is the
173  // child decay vertex and the child production vertex is the parent
174  // decay vertex.
176  // Method3: Returns true if the parent and child production vertices
177  // are the same.
178  bool TruthLoopDetectionMethod3(const xAOD::TruthVertex* childOrigVtx, const xAOD::TruthParticle* parent) const;
179 
181  const xAOD::TruthParticle*,
182  bool& isPrompt,
184 
186  const xAOD::TruthParticle*,
187  bool& isPrompt,
189 
191  const xAOD::TruthParticle*,
192  int motherPDG,
194 
196  const xAOD::TruthParticle*,
197  bool& isPrompt,
199 
201  const xAOD::TruthParticle*,
202  bool& isPrompt,
204 
205 #if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
206  bool genPartToCalo(const EventContext& ctx,
207  const xAOD::CaloCluster* clus,
208  const xAOD::TruthParticle* thePart,
209  bool isFwrdEle,
210  double& dRmatch,
211  bool& isNarrowCone,
212  const CaloDetDescrManager& caloDDMgr) const;
213 
214 #endif
215 
216 #ifndef GENERATIONBASE
217  double fracParticleInJet(const xAOD::TruthParticle*, const xAOD::Jet*, bool DR, bool nparts) const;
218  void findJetConstituents(const xAOD::Jet*, std::set<const xAOD::TruthParticle*>& constituents, bool DR) const;
219 #endif
220 
221  /* Data members*/
223  m_truthParticleContainerKey{this,"xAODTruthParticleContainerName","TruthParticles","ReadHandleKey for xAOD::TruthParticleContainer"};
224 
225 #if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
226  ToolHandle<Trk::IParticleCaloExtensionTool> m_caloExtensionTool{this,"ParticleCaloExtensionTool",""};
227  SG::ReadCondHandleKey<CaloDetDescrManager> m_caloMgrKey{this,"CaloDetDescrManager",""};
228  ToolHandle<xAOD::ITruthParticlesInConeTool>
229  m_truthInConeTool{this,"TruthInConeTool","xAOD::TruthParticlesInConeTool/TruthParticlesInConeTool"};
230 
235  float m_partExtrConePhi;
241  bool m_ROICone;
242 
246 #endif
247 
248 #ifndef XAOD_ANALYSIS
250  m_truthLinkVecReadHandleKey{this,"xAODTruthLinkVector","xAODTruthLinks", "ReadHandleKey for xAODTruthParticleLinkVector"};
251 #endif
252 #ifndef GENERATIONBASE
253  float m_deltaRMatchCut;
254  float m_deltaPhiMatchCut;
256  float m_jetPartDRMatch;
257 #endif
258 };
259 #endif // MCTRUTHCLASSIFIER_MCTRUTHCLASSIFIER_H
Jet.h
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
MCTruthClassifier::m_FwdElectronTruthExtrEtaWindowCut
float m_FwdElectronTruthExtrEtaWindowCut
Definition: MCTruthClassifier.h:238
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Jet
Basic data class defines behavior for all Jet objects The Jet class is the principal data class for...
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:47
MCTruthClassifier::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: MCTruthClassifier.h:101
TRTCalib_Extractor.det
det
Definition: TRTCalib_Extractor.py:36
Muon.h
MCTruthClassifier::findJetConstituents
void findJetConstituents(const xAOD::Jet *, std::set< const xAOD::TruthParticle * > &constituents, bool DR) const
Definition: MCRecoToTruth.cxx:278
MCTruthClassifier::defOrigOfElectron
MCTruthPartClassifier::ParticleOrigin defOrigOfElectron(const xAOD::TruthParticleContainer &xTruthParticleContainer, const xAOD::TruthParticle *, bool &isPrompt, MCTruthPartClassifier::Info &info) const
Definition: MCTruthClassifierGen.cxx:247
TruthParticleContainer.h
MCTruthClassifier::m_phtClasConeEta
float m_phtClasConeEta
Definition: MCTruthClassifier.h:243
MCTruthClassifier::particleHepMCTruthClassifier
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleHepMCTruthClassifier(const HepMcParticleLink &theLink, MCTruthPartClassifier::Info *info=nullptr) const override final
Definition: MCTruthClassifierGen.cxx:25
MCTruthClassifier::m_useCaching
bool m_useCaching
Definition: MCTruthClassifier.h:241
MCTruthClassifier::m_partExtrConeEta
float m_partExtrConeEta
Definition: MCTruthClassifier.h:239
M_PI
#define M_PI
Definition: ActiveFraction.h:11
MCTruthClassifier::TruthLoopDetectionMethod1
bool TruthLoopDetectionMethod1(const xAOD::TruthVertex *childOrigVtx, const xAOD::TruthParticle *parent) const
Definition: MCTruthClassifierGen.cxx:190
MCTruthClassifier::m_caloExtensionTool
ToolHandle< Trk::IParticleCaloExtensionTool > m_caloExtensionTool
Definition: MCTruthClassifier.h:231
PropDirection.h
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
MCTruthClassifier::m_pTNeutralPartCut
float m_pTNeutralPartCut
Definition: MCTruthClassifier.h:249
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
SG::ReadHandleKey< xAOD::TruthParticleContainer >
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition: TrackSystemController.h:45
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
x
#define x
GenParticle.h
MCTruthClassifier::m_truthParticleContainerKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleContainerKey
Definition: MCTruthClassifier.h:228
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
Photon
Class describing an photon
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
MCTruthClassifier::m_NumOfSiHitsCut
int m_NumOfSiHitsCut
Definition: MCTruthClassifier.h:260
MCTruthClassifier::m_jetPartDRMatch
float m_jetPartDRMatch
Definition: MCTruthClassifier.h:261
MCTruthClassifierDefs.h
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
EgammaxAODHelpers.h
MCTruthClassifier::m_FwdElectronTruthExtrEtaCut
float m_FwdElectronTruthExtrEtaCut
Definition: MCTruthClassifier.h:237
IMCTruthClassifier.h
TrackParametersIdHelper.h
CaloCluster.h
Photon.h
MCTruthClassifier::defOrigOfMuon
MCTruthPartClassifier::ParticleOrigin defOrigOfMuon(const xAOD::TruthParticleContainer &xTruthParticleContainer, const xAOD::TruthParticle *, bool &isPrompt, MCTruthPartClassifier::Info &info) const
Definition: MCTruthClassifierGen.cxx:523
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ParticleOrigin
ParticleOrigin
Definition: TruthClasses.h:51
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition: AthCommonDataStore.h:145
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
MCTruthClassifier::defOrigOfNeutrino
MCTruthPartClassifier::ParticleOrigin defOrigOfNeutrino(const xAOD::TruthParticleContainer &xTruthParticleContainer, const xAOD::TruthParticle *, bool &isPrompt, MCTruthPartClassifier::Info &info) const
Definition: MCTruthClassifierGen.cxx:1177
test_pyathena.parent
parent
Definition: test_pyathena.py:15
MCTruthClassifier::egammaClusMatch
virtual const xAOD::TruthParticle * egammaClusMatch(const xAOD::CaloCluster *, bool, MCTruthPartClassifier::Info *info) const override final
Definition: MCTruthClassifierAthena.cxx:44
CaloCluster
Principal data class for CaloCell clusters.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:79
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ITruthParticlesInConeTool.h
MCTruthClassifier::m_truthLinkVecReadHandleKey
SG::ReadHandleKey< xAODTruthParticleLinkVector > m_truthLinkVecReadHandleKey
Definition: MCTruthClassifier.h:255
MCTruthClassifier::TruthLoopDetectionMethod2
bool TruthLoopDetectionMethod2(const xAOD::TruthParticle *child, const xAOD::TruthParticle *parent) const
Definition: MCTruthClassifierGen.cxx:211
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
MCTruthClassifier::m_phtClasConePhi
float m_phtClasConePhi
Definition: MCTruthClassifier.h:242
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
MCTruthClassifier::m_partExtrConePhi
float m_partExtrConePhi
Definition: MCTruthClassifier.h:240
columnar::final
CM final
Definition: ColumnAccessor.h:106
MCTruthClassifier::defOrigOfPhoton
MCTruthPartClassifier::ParticleOrigin defOrigOfPhoton(const xAOD::TruthParticleContainer &xTruthParticleContainer, const xAOD::TruthParticle *, bool &isPrompt, MCTruthPartClassifier::Info &info) const
Definition: MCTruthClassifierGen.cxx:914
MCTruthClassifier::genPartToCalo
bool genPartToCalo(const EventContext &ctx, const xAOD::CaloCluster *clus, const xAOD::TruthParticle *thePart, bool isFwrdEle, double &dRmatch, bool &isNarrowCone, const CaloDetDescrManager &caloDDMgr) const
Definition: MCTruthClassifierAthena.cxx:237
MCTruthClassifier::TruthLoopDetectionMethod3
bool TruthLoopDetectionMethod3(const xAOD::TruthVertex *childOrigVtx, const xAOD::TruthParticle *parent) const
Definition: MCTruthClassifierGen.cxx:233
TruthVertex.h
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:37
MagicNumbers.h
MCTruthClassifier::m_inclG4part
bool m_inclG4part
Definition: MCTruthClassifier.h:250
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
Units.h
Wrapper to avoid constant divisions when using units.
IMCTruthClassifier
Definition: IMCTruthClassifier.h:92
MCTruthClassifier
Definition: MCTruthClassifier.h:56
MCTruthClassifier::MCTruthClassifier
MCTruthClassifier(const std::string &type)
Definition: MCTruthClassifier.h:65
SG::ReadCondHandleKey< CaloDetDescrManager >
TrackParticle.h
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
IParticleCaloExtensionTool.h
MCTruthClassifier::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: MCTruthClassifier.h:232
python.CaloAddPedShiftConfig.default
default
Definition: CaloAddPedShiftConfig.py:43
y
#define y
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:469
MCTruthPartClassifier::isPrompt
int isPrompt(const unsigned int classify, bool allow_prompt_tau_decays=true)
Definition: TruthClassifiers.h:180
MCTruthPartClassifier
Definition: TruthClassifiers.h:12
ASG_TOOL_CLASS
#define ASG_TOOL_CLASS(CLASSNAME, INT1)
Definition: AsgToolMacros.h:68
MCTruthClassifier::m_deltaRMatchCut
float m_deltaRMatchCut
Definition: MCTruthClassifier.h:258
Electron
Class describing an electron.
MCTruthClassifier::m_deltaPhiMatchCut
float m_deltaPhiMatchCut
Definition: MCTruthClassifier.h:259
DecayProducts.h
MCTruthClassifier::m_pTChargePartCut
float m_pTChargePartCut
Definition: MCTruthClassifier.h:248
MCTruthClassifier::m_truthInConeTool
ToolHandle< xAOD::ITruthParticlesInConeTool > m_truthInConeTool
Definition: MCTruthClassifier.h:234
Electron.h
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:44
AsgTool.h
TruthParticle.h
MCTruthClassifier::~MCTruthClassifier
virtual ~MCTruthClassifier()=default
MCTruthClassifier::defOrigOfTau
MCTruthPartClassifier::ParticleOrigin defOrigOfTau(const xAOD::TruthParticleContainer &xTruthParticleContainer, const xAOD::TruthParticle *, int motherPDG, MCTruthPartClassifier::Info &info) const
Definition: MCTruthClassifierGen.cxx:741
MCTruthClassifier::particleTruthClassifier
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::TruthParticle *, MCTruthPartClassifier::Info *info=nullptr) const override final
Definition: MCTruthClassifierGen.cxx:42
MCTruthClassifier::m_FwdElectronUseG4Sel
bool m_FwdElectronUseG4Sel
Definition: MCTruthClassifier.h:236
ParticleType
ParticleType
Definition: TruthClasses.h:8
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:27
MCTruthClassifier::m_fwrdEledRtoTrCut
float m_fwrdEledRtoTrCut
Definition: MCTruthClassifier.h:245
MCTruthPartClassifier::Info
Definition: IMCTruthClassifier.h:49
python.ParticleTypeUtil.info
def info
Definition: ParticleTypeUtil.py:87
MCTruthClassifier::detEta
double detEta(double x, double y) const
Definition: MCTruthClassifier.h:164
MCTruthClassifier::fracParticleInJet
double fracParticleInJet(const xAOD::TruthParticle *, const xAOD::Jet *, bool DR, bool nparts) const
Definition: MCRecoToTruth.cxx:310
MCTruthClassifier::m_ROICone
bool m_ROICone
Definition: MCTruthClassifier.h:246
HepMCHelpers.h
MCTruthClassifier::m_phtdRtoTrCut
float m_phtdRtoTrCut
Definition: MCTruthClassifier.h:244
MCTruthClassifier::detPhi
double detPhi(double x, double y) const
Definition: MCTruthClassifier.h:165
MCTruthClassifier::getGenPart
virtual const xAOD::TruthParticle * getGenPart(const xAOD::TrackParticle *, MCTruthPartClassifier::Info *info=nullptr) const override final
Definition: MCRecoToTruth.cxx:181