ATLAS Offline Software
TruthVariables.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "AtlasHepMC/GenEvent.h"
8 #include "AtlasHepMC/GenVertex.h"
9 namespace MuonPRDTest {
10  TruthVariables::TruthVariables(MuonTesterTree& tree, const std::string& container_name, MSG::Level msglvl) :
11  PrdTesterModule(tree, "TruthTestModule", false, 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 #ifdef HEPMC3
24  for (const auto& vertex : subEvent->vertices()) {
25  m_Truth_vertex.push_back(vertex->position());
27  ++truth_vertices;
28  }
29  for (const auto& particle : subEvent->particles()) {
34  auto production_vertex = particle->production_vertex();
35  m_Truth_particleProduction_vertex_id.push_back(production_vertex ? production_vertex->status() : -1);
36  auto end_vertex = particle->end_vertex();
37  m_Truth_particleEnd_vertex_id.push_back(end_vertex ? end_vertex->status() : -1);
38  ++truth_parts;
39  }
40 #else
41  // Vertex
42  HepMC::ConstGenEventVertexRange vertex_range = subEvent->vertex_range();
43  for (auto vit : vertex_range) {
44  const HepMC::GenVertex* vertex = vit;
45  m_Truth_vertex.push_back(vertex->position());
47  ++truth_vertices;
48  }
49  // Particle
50  HepMC::ConstGenEventParticleRange particle_range = subEvent->particle_range();
51  for (auto pit : particle_range) {
52  const HepMC::GenParticle* particle = pit;
57  auto production_vertex = particle->production_vertex();
58  m_Truth_particleProduction_vertex_id.push_back(production_vertex ? production_vertex->id() : -1);
59  auto end_vertex = particle->end_vertex();
60  m_Truth_particleEnd_vertex_id.push_back(end_vertex ? end_vertex->id() : -1);
61  ++truth_parts;
62  }
63 #endif
64 
65  }
66  m_Truth_nVertices = truth_vertices;
67  m_Truth_nParticles = truth_parts;
68  return true;
69  }
70 } // namespace MuonPRDTest
MuonPRDTest::TruthVariables::m_Truth_particleBarcode
VectorBranch< int > & m_Truth_particleBarcode
Definition: TruthVariables.h:29
MuonPRDTest::TruthVariables::TruthVariables
TruthVariables(MuonTesterTree &tree, const std::string &container_name, MSG::Level msglvl)
Definition: TruthVariables.cxx:10
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
GenEvent.h
MuonPRDTest::TruthVariables::fill
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...
Definition: TruthVariables.cxx:14
MuonPRDTest::TruthVariables::m_truthParticleP4
PtEtaPhiEBranch m_truthParticleP4
Definition: TruthVariables.h:26
SG::ReadHandle< McEventCollection >
GenVertex.h
tree
TChain * tree
Definition: tile_monitor.h:30
skel.it
it
Definition: skel.GENtoEVGEN.py:423
MuonPRDTest::TruthVariables::m_Truth_vertexId
VectorBranch< int > & m_Truth_vertexId
Definition: TruthVariables.h:23
MuonVal::MuonTesterBranch::declare_dependency
bool declare_dependency(Key &key)
Declares the ReadHandle/ ReadCondHandleKey as data dependency of the algorithm.
MuonVal::CartesFourVecBranch::push_back
void push_back(const TLorentzVector &vec)
Definition: FourVectorBranch.cxx:34
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
MuonVal::MuonTesterTree
Definition: MuonTesterTree.h:30
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
MuonPRDTest::PrdTesterModule
Definition: PrdTesterModule.h:15
MuonPRDTest::TruthVariables::declare_keys
bool declare_keys() override final
Definition: TruthVariables.cxx:12
MuonPRDTest::TruthVariables::m_Truth_particleEnd_vertex_id
VectorBranch< int > & m_Truth_particleEnd_vertex_id
Definition: TruthVariables.h:31
MuonPRDTest::TruthVariables::m_Truth_nParticles
ScalarBranch< unsigned int > & m_Truth_nParticles
Definition: TruthVariables.h:25
MuonVal::VectorBranch::push_back
void push_back(const T &value)
Adds a new element at the end of the vector.
TruthVariables.h
MuonPRDTest::TruthVariables::m_Truth_particleProduction_vertex_id
VectorBranch< int > & m_Truth_particleProduction_vertex_id
Definition: TruthVariables.h:30
MuonVal::PtEtaPhiEBranch::push_back
void push_back(const TLorentzVector &vec)
Definition: FourVectorBranch.cxx:20
MuonPRDTest::TruthVariables::m_Truth_nVertices
ScalarBranch< unsigned int > & m_Truth_nVertices
Definition: TruthVariables.h:20
MuonPRDTest::TruthVariables::m_key
SG::ReadHandleKey< McEventCollection > m_key
Definition: TruthVariables.h:19
MuonPRDTest::TruthVariables::m_Truth_particleStatus
VectorBranch< int > & m_Truth_particleStatus
Definition: TruthVariables.h:28
MuonPRDTest::TruthVariables::m_Truth_vertex
CartesFourVecBranch m_Truth_vertex
Definition: TruthVariables.h:22
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
MuonPRDTest
Definition: CSCDigitVariables.h:10
MuonPRDTest::TruthVariables::m_Truth_particlePdg_id
VectorBranch< int > & m_Truth_particlePdg_id
Definition: TruthVariables.h:27
GenParticle
@ GenParticle
Definition: TruthClasses.h:30