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
100  if (!m_truthLinkVecReadHandleKey.key().empty()) {
102  }
103 #endif
105 
106 #if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
107  if (!m_caloExtensionTool.empty()) {
108  ATH_CHECK(m_caloExtensionTool.retrieve());
109  } else {
110  m_caloExtensionTool.disable();
111  }
112 
114 
115  if (!m_truthInConeTool.empty()) {
116  ATH_CHECK(m_truthInConeTool.retrieve());
117  } else {
118  m_truthInConeTool.disable();
119  }
120 #endif
121  return StatusCode::SUCCESS;
122  }
123  virtual StatusCode finalize()
124 #ifndef XAOD_STANDALONE
125  override
126 #endif
127  { return StatusCode::SUCCESS;}
128 
129  /* All get to see these*/
130  virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
132 
133  virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
134  checkOrigOfBkgElec(const xAOD::TruthParticle* thePart,MCTruthPartClassifier::Info* info = nullptr) const override;
135 
136 
137 #ifndef XAOD_ANALYSIS /*These can not run in Analysis Base*/
138  virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
139  particleTruthClassifier(const HepMcParticleLink& theLink,MCTruthPartClassifier::Info* info = nullptr) const override;
140 
141  virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
143 
144 #endif
145 
146 #ifndef GENERATIONBASE /*These can not run in Generation only release*/
147  virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
149 
150  virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
152 
153  virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
154  particleTruthClassifier(const xAOD::Photon*,MCTruthPartClassifier::Info* info = nullptr) const override;
155 
156  virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
157  particleTruthClassifier(const xAOD::Muon*,MCTruthPartClassifier::Info* info = nullptr) const override;
158 
159  virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
161 
162  virtual std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin>
163  particleTruthClassifier(const xAOD::Jet*, bool DR, MCTruthPartClassifier::Info* info = nullptr) const override;
164 
165  virtual const xAOD::TruthParticle* getGenPart(const xAOD::TrackParticle*, MCTruthPartClassifier::Info* info = nullptr) const override;
166 
167 #endif
168 
169 private:
170  inline double detEta(double x, double y) const { return std::abs(x - y); }
171  inline double detPhi(double x, double y) const {
172  double det = x - y;
173  if (det > M_PI) det = det - 2. * M_PI;
174  if (det < -M_PI) det = det + 2. * M_PI;
175  return std::abs(det);
176  }
177 
178 
180  const xAOD::TruthParticle*,
181  bool& isPrompt,
183 
185  const xAOD::TruthParticle*,
186  bool& isPrompt,
188 
190  const xAOD::TruthParticle*,
191  int motherPDG,
193 
195  const xAOD::TruthParticle*,
196  bool& isPrompt,
198 
200  const xAOD::TruthParticle*,
201  bool& isPrompt,
203 
204 #if !defined(XAOD_ANALYSIS) && !defined(GENERATIONBASE)
205  bool genPartToCalo(const EventContext& ctx,
206  const xAOD::CaloCluster* clus,
207  const xAOD::TruthParticle* thePart,
208  bool isFwrdEle,
209  double& dRmatch,
210  bool& isNarrowCone,
211  const CaloDetDescrManager& caloDDMgr) const;
212 
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
grepfile.info
info
Definition: grepfile.py:38
MCTruthClassifier::defOrigOfNeutrino
MCTruthPartClassifier::ParticleOrigin defOrigOfNeutrino(const xAOD::TruthParticleContainer *m_xTruthParticleContainer, const xAOD::TruthParticle *, bool &isPrompt, MCTruthPartClassifier::Info *info) const
Definition: MCTruthClassifierGen.cxx:1216
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
MCTruthClassifier::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: MCTruthClassifier.h:101
Muon.h
MCTruthClassifier::findJetConstituents
void findJetConstituents(const xAOD::Jet *, std::set< const xAOD::TruthParticle * > &constituents, bool DR) const
Definition: MCRecoToTruth.cxx:273
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TruthParticleContainer.h
MCTruthClassifier::m_phtClasConeEta
float m_phtClasConeEta
Definition: MCTruthClassifier.h:243
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::m_caloExtensionTool
ToolHandle< Trk::IParticleCaloExtensionTool > m_caloExtensionTool
Definition: MCTruthClassifier.h:231
PropDirection.h
MCTruthClassifier::defOrigOfElectron
MCTruthPartClassifier::ParticleOrigin defOrigOfElectron(const xAOD::TruthParticleContainer *xTruthParticleContainer, const xAOD::TruthParticle *, bool &isPrompt, MCTruthPartClassifier::Info *info) const
Definition: MCTruthClassifierGen.cxx:230
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
SG::ReadHandleKey< xAOD::TruthParticleContainer >
x
#define x
MCTruthClassifier::finalize
virtual StatusCode finalize() override
Definition: MCTruthClassifier.h:128
GenParticle.h
MCTruthClassifier::m_truthParticleContainerKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleContainerKey
Definition: MCTruthClassifier.h:228
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
MCTruthClassifier::checkOrigOfBkgElec
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > checkOrigOfBkgElec(const xAOD::TruthParticle *thePart, MCTruthPartClassifier::Info *info=nullptr) const override
Definition: MCTruthClassifierGen.cxx:1476
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:59
EgammaxAODHelpers.h
MCTruthClassifier::m_FwdElectronTruthExtrEtaCut
float m_FwdElectronTruthExtrEtaCut
Definition: MCTruthClassifier.h:237
IMCTruthClassifier.h
TrackParametersIdHelper.h
CaloCluster.h
Photon.h
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.
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
WritePulseShapeToCool.det
det
Definition: WritePulseShapeToCool.py:204
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ITruthParticlesInConeTool.h
MCTruthClassifier::m_truthLinkVecReadHandleKey
SG::ReadHandleKey< xAODTruthParticleLinkVector > m_truthLinkVecReadHandleKey
Definition: MCTruthClassifier.h:255
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:581
MCTruthClassifier::m_partExtrConePhi
float m_partExtrConePhi
Definition: MCTruthClassifier.h:240
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
TruthVertex.h
MCTruthClassifier::getGenPart
virtual const xAOD::TruthParticle * getGenPart(const xAOD::TrackParticle *, MCTruthPartClassifier::Info *info=nullptr) const override
Definition: MCRecoToTruth.cxx:181
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
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.
MCTruthClassifier::egammaClusMatch
const xAOD::TruthParticle * egammaClusMatch(const xAOD::CaloCluster *, bool, MCTruthPartClassifier::Info *info) const
Definition: MCTruthClassifierAthena.cxx:44
xAOD::Electron_v1
Definition: Electron_v1.h:34
IMCTruthClassifier
Definition: IMCTruthClassifier.h:103
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
MCTruthClassifier::defOrigOfMuon
MCTruthPartClassifier::ParticleOrigin defOrigOfMuon(const xAOD::TruthParticleContainer *m_xTruthParticleContainer, const xAOD::TruthParticle *, bool &isPrompt, MCTruthPartClassifier::Info *info) const
Definition: MCTruthClassifierGen.cxx:539
IParticleCaloExtensionTool.h
MCTruthClassifier::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: MCTruthClassifier.h:232
y
#define y
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
xAOD::Photon_v1
Definition: Photon_v1.h:37
MCTruthPartClassifier::isPrompt
int isPrompt(const unsigned int classify, bool allow_prompt_tau_decays=true)
Definition: TruthClassifiers.h:180
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
ASG_TOOL_CLASS
#define ASG_TOOL_CLASS(CLASSNAME, INT1)
Definition: AsgToolMacros.h:68
MCTruthClassifier::m_deltaRMatchCut
float m_deltaRMatchCut
Definition: MCTruthClassifier.h:258
MCTruthClassifier::m_deltaPhiMatchCut
float m_deltaPhiMatchCut
Definition: MCTruthClassifier.h:259
MCTruthClassifier::defOrigOfTau
MCTruthPartClassifier::ParticleOrigin defOrigOfTau(const xAOD::TruthParticleContainer *m_xTruthParticleContainer, const xAOD::TruthParticle *, int motherPDG, MCTruthPartClassifier::Info *info) const
Definition: MCTruthClassifierGen.cxx:775
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:43
python.CaloScaleNoiseConfig.default
default
Definition: CaloScaleNoiseConfig.py:79
AsgTool.h
TruthParticle.h
MCTruthClassifier::~MCTruthClassifier
virtual ~MCTruthClassifier()=default
MCTruthClassifier::particleTruthClassifier
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::TruthParticle *, MCTruthPartClassifier::Info *info=nullptr) const override
Definition: MCTruthClassifierGen.cxx:77
MCTruthClassifier::m_FwdElectronUseG4Sel
bool m_FwdElectronUseG4Sel
Definition: MCTruthClassifier.h:236
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
MCTruthClassifier::m_fwrdEledRtoTrCut
float m_fwrdEledRtoTrCut
Definition: MCTruthClassifier.h:245
MCTruthPartClassifier::Info
Definition: IMCTruthClassifier.h:49
MCTruthClassifier::detEta
double detEta(double x, double y) const
Definition: MCTruthClassifier.h:175
MCTruthClassifier::fracParticleInJet
double fracParticleInJet(const xAOD::TruthParticle *, const xAOD::Jet *, bool DR, bool nparts) const
Definition: MCRecoToTruth.cxx:305
MCTruthClassifier::m_ROICone
bool m_ROICone
Definition: MCTruthClassifier.h:246
HepMCHelpers.h
MCTruthClassifier::defOrigOfPhoton
MCTruthPartClassifier::ParticleOrigin defOrigOfPhoton(const xAOD::TruthParticleContainer *m_xTruthParticleContainer, const xAOD::TruthParticle *, bool &isPrompt, MCTruthPartClassifier::Info *info) const
Definition: MCTruthClassifierGen.cxx:952
MCTruthClassifier::m_phtdRtoTrCut
float m_phtdRtoTrCut
Definition: MCTruthClassifier.h:244
MCTruthClassifier::detPhi
double detPhi(double x, double y) const
Definition: MCTruthClassifier.h:176