Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MuonTruthClassificationAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 
11 namespace Muon {
12 
13  // Initialize method:
19  ATH_CHECK(m_idHelperSvc.retrieve());
20  ATH_CHECK(m_truthClassifier.retrieve());
21  return StatusCode::SUCCESS;
22  }
23 
24  // Execute method:
25  StatusCode MuonTruthClassificationAlg::execute(const EventContext& ctx) const {
26  // skip if no input data found
27  SG::ReadHandle truthContainer(m_truthRecordKey, ctx);
28  ATH_CHECK(truthContainer.isValid());
29 
30  // create output container
31  SG::WriteHandle muonTruthContainer(m_outTruthMuonKey, ctx);
32  ATH_CHECK(muonTruthContainer.record(std::make_unique<xAOD::TruthParticleContainer>(),
33  std::make_unique<xAOD::TruthParticleAuxContainer>()));
34  ATH_MSG_DEBUG("Recorded TruthParticleContainer with key: " << m_outTruthMuonKey);
35 
36  // loop over truth coll
37  for (const xAOD::TruthParticle* truth : *truthContainer) {
38  if (!MC::isStable(truth) || !m_pdgIds.value().count(truth->absPdgId()) || truth->pt() < m_pt) continue;
39  xAOD::TruthParticle* truthParticle = muonTruthContainer->push_back(std::make_unique<xAOD::TruthParticle>());
40  truthParticle->setPdgId(truth->pdgId());
41  truthParticle->setBarcode(HepMC::barcode(truth)); // FIXME barcode-based
42  truthParticle->setStatus(truth->status());
43  truthParticle->setPx(truth->px());
44  truthParticle->setPy(truth->py());
45  truthParticle->setPz(truth->pz());
46  truthParticle->setE(truth->e());
47  truthParticle->setM(truth->m());
48  if (truth->hasProdVtx()) truthParticle->setProdVtxLink(truth->prodVtxLink());
49  ElementLink<xAOD::TruthParticleContainer> truthLink(*muonTruthContainer, muonTruthContainer->size() - 1);
50  truthLink.toPersistent();
51  ATH_MSG_DEBUG("Found stable muon: " << truth->pt() << " eta " << truth->eta() << " phi " << truth->phi() << " mass "
52  << truth->m() << " barcode " << HepMC::barcode(truth) << " truthParticle->barcode "
53  << HepMC::barcode(truthParticle) << " (*truthLink)->barcode " << HepMC::barcode(*truthLink) << " "
54  << truthLink); // FIXME barcode-based
55  int iType = 0;
56  int iOrigin = 0;
57 
58  // if configured look up truth classification
59  if (!m_truthClassifier.empty()) {
60  // if configured also get truth classification
61  std::pair<MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin> truthClass =
62  m_truthClassifier->particleTruthClassifier(truth);
63  iType = truthClass.first;
64  iOrigin = truthClass.second;
65  ATH_MSG_VERBOSE("Got truth type " << iType << " origin " << iOrigin);
67  truthOrigin(*truthParticle) = iOrigin;
69  truthType(*truthParticle) = iType;
70  }
71 
72  ATH_MSG_DEBUG("good muon with type " << iType << " and origin" << iOrigin);
73  }
74 
75  ATH_MSG_DEBUG("Registered " << muonTruthContainer->size() << " truth muons ");
76 
77  return StatusCode::SUCCESS;
78  }
79 
80 } // namespace Muon
81 
xAOD::TruthParticle_v1::setStatus
void setStatus(int value)
Set status code.
Muon::MuonTruthClassificationAlg::m_pt
Gaudi::Property< float > m_pt
Definition: MuonTruthClassificationAlg.h:42
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::TruthParticle_v1::setE
void setE(float value)
Set the energy of the particle.
Definition: TruthParticle_v1.cxx:235
xAOD::TruthParticle_v1::setBarcode
void setBarcode(int value)
Set barcode.
TruthParticleContainer.h
xAOD::TruthParticle_v1::setPx
void setPx(float value)
Set the x component of the particle's momentum.
Muon::MuonTruthClassificationAlg::m_truthRecordKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthRecordKey
Definition: MuonTruthClassificationAlg.h:37
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition: TrackSystemController.h:45
IDTPM::truthType
int truthType(const U &p)
Definition: TrackParametersHelper.h:274
Muon::MuonTruthClassificationAlg::m_truthOriginKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_truthOriginKey
Definition: MuonTruthClassificationAlg.h:39
Muon::MuonTruthClassificationAlg::m_truthClassifier
ToolHandle< IMCTruthClassifier > m_truthClassifier
Definition: MuonTruthClassificationAlg.h:50
TruthParticleAuxContainer.h
Muon::MuonTruthClassificationAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: MuonTruthClassificationAlg.cxx:25
IDTPM::truthOrigin
int truthOrigin(const U &p)
Definition: TrackParametersHelper.h:283
xAOD::TruthParticle_v1::setM
void setM(float value)
Also store the mass.
Definition: TruthParticle_v1.cxx:241
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
xAOD::TruthParticle_v1::setPy
void setPy(float value)
Set the y component of the particle's momentum.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::TruthParticle_v1::setPdgId
void setPdgId(int pid)
Set PDG ID code.
Muon::MuonTruthClassificationAlg::m_outTruthMuonKey
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_outTruthMuonKey
Definition: MuonTruthClassificationAlg.h:38
Muon::MuonTruthClassificationAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonTruthClassificationAlg.h:47
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
MC::isStable
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
Definition: HepMCHelpers.h:45
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Muon::MuonTruthClassificationAlg::m_pdgIds
Gaudi::Property< std::set< int > > m_pdgIds
Definition: MuonTruthClassificationAlg.h:44
xAOD::TruthParticle_v1::setPz
void setPz(float value)
Set the z component of the particle's momentum.
MuonTruthClassificationAlg.h
Muon::MuonTruthClassificationAlg::initialize
virtual StatusCode initialize() override
Definition: MuonTruthClassificationAlg.cxx:14
Muon::MuonTruthClassificationAlg::m_truthTypeKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_truthTypeKey
Definition: MuonTruthClassificationAlg.h:40
xAOD::TruthParticle_v1::setProdVtxLink
void setProdVtxLink(const ElementLink< TruthVertexContainer > &link)
Set the production vertex of the particle.
HepMCHelpers.h