ATLAS Offline Software
Loading...
Searching...
No Matches
TruthVariables.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
9namespace MuonPRDTest {
10 TruthVariables::TruthVariables(MuonTesterTree& tree, const std::string& container_name, MSG::Level msglvl) :
11 PrdTesterModule(tree, "TruthTestModule", msglvl), m_key{container_name} {}
13
14 bool TruthVariables::fill(const EventContext& ctx) {
15 SG::ReadHandle<McEventCollection> truthContainer{m_key, ctx};
16 if (!truthContainer.isValid()) {
17 ATH_MSG_FATAL("Failed to retrieve container " << m_key.fullKey());
18 return false;
19 }
20 unsigned int truth_vertices{0}, truth_parts{0};
21 for (auto it : *truthContainer) {
22 const HepMC::GenEvent* subEvent = it;
23 for (const auto& vertex : subEvent->vertices()) {
24 m_Truth_vertex.push_back(vertex->position());
25 m_Truth_vertexId.push_back(vertex->status());
26 ++truth_vertices;
27 }
28 for (const auto& particle : subEvent->particles()) {
29 m_truthParticleP4.push_back(particle->momentum());
30 m_Truth_particlePdg_id.push_back(particle->pdg_id());
31 m_Truth_particleStatus.push_back(particle->status());
32 m_Truth_particleBarcode.push_back(HepMC::barcode(particle));
33 auto production_vertex = particle->production_vertex();
34 m_Truth_particleProduction_vertex_id.push_back(production_vertex ? production_vertex->status() : -1);
35 auto end_vertex = particle->end_vertex();
36 m_Truth_particleEnd_vertex_id.push_back(end_vertex ? end_vertex->status() : -1);
37 ++truth_parts;
38 }
39
40 }
41 m_Truth_nVertices = truth_vertices;
42 m_Truth_nParticles = truth_parts;
43 return true;
44 }
45} // namespace MuonPRDTest
#define ATH_MSG_FATAL(x)
PrdTesterModule(MuonTesterTree &tree, const std::string &grp_name, MSG::Level msglvl)
VectorBranch< int > & m_Truth_vertexId
VectorBranch< int > & m_Truth_particleStatus
VectorBranch< int > & m_Truth_particleEnd_vertex_id
ScalarBranch< unsigned int > & m_Truth_nVertices
VectorBranch< int > & m_Truth_particleProduction_vertex_id
SG::ReadHandleKey< McEventCollection > m_key
bool declare_keys() override final
VectorBranch< int > & m_Truth_particleBarcode
TruthVariables(MuonTesterTree &tree, const std::string &container_name, MSG::Level msglvl)
PtEtaPhiEBranch m_truthParticleP4
CartesFourVecBranch m_Truth_vertex
ScalarBranch< unsigned int > & m_Truth_nParticles
bool fill(const EventContext &ctx) override final
The fill method checks if enough information is provided such that the branch is cleared from the inf...
VectorBranch< int > & m_Truth_particlePdg_id
bool declare_dependency(Key &key)
Declares the ReadHandle/ ReadCondHandleKey as data dependency of the algorithm.
TTree * tree() override final
Returns the underlying TTree object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
int barcode(const T *p)
Definition Barcode.h:15
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39