ATLAS Offline Software
Loading...
Searching...
No Matches
ElasticTruthTrajectoryBuilder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Andrei Gaponenko, 2008
6
8
10
14
17
18#include <stack>
19
20namespace Trk {
21
22//================================================================
24ElasticTruthTrajectoryBuilder(const std::string& type,
25const std::string& name,
26const IInterface* parent)
27 : AthAlgTool(type,name,parent)
28{
29 declareInterface<Trk::ITruthTrajectoryBuilder>(this);
30}
31
32
33//================================================================
35 return StatusCode::SUCCESS;
36}
37
38//================================================================
41{
42 result->clear();
43 if (input) {
45 HepMC::ConstGenParticlePtr current = input;
46
47 // Extend trajectory outwards. The last particle should go at [0]
48 // in the TruthTrajectory, so we need to use a tmp storage while
49 // traversing the structure.
50 std::stack<HepMC::ConstGenParticlePtr> tmp;
51 while ( (next = getDaughter(current)) ) {
52 tmp.push(current = next);
53 }
54
55 // All particles in the TruthTrajectory will be from the same GenEvent
56 const int eventNumber = input->parent_event()->event_number();
57
58 // copy the outer half to result
59 while (!tmp.empty()) {
60 result->emplace_back(tmp.top(), eventNumber, HepMcParticleLink::IS_EVENTNUM);
61 tmp.pop();
62 }
63
64 // The input particle itself
65 result->emplace_back(input, eventNumber, HepMcParticleLink::IS_EVENTNUM);
66
67 // Now continue towards the interaction point
68 while ( (next = getMother(current)) ) {
69 result->emplace_back(current = next, eventNumber, HepMcParticleLink::IS_EVENTNUM);
70 }
71 }
72}
73
74//================================================================
77{
78 HepMC::ConstGenParticlePtr mother{nullptr};
79 HepMC::ConstGenParticlePtr daughter{nullptr};
80 // only truth vertices with 1 incoming particle
81 if(vtx && (vtx->particles_in_size() == 1)) {
82#ifdef HEPMC3
83 mother = vtx->particles_in().front();
84#else
85 mother = *vtx->particles_in_const_begin();
86#endif
87 // Allow status code 1 and 2. E.g. a pion that produced a long track can decay outside of InDet and have status==2.
88 if( mother && MC::isPhysical(mother) ) {
89
90 // Restrict to quasi-elastic processes (e.g. brems, delta-rays, pi->pi+Delta).
91 //
92 // Require not more than 2 outgoing particles. Note that
93 // delta-rays for primary==electron is a special case, because we have two
94 // outgoing particles with the same PDG id. The "correct" one
95 // is that with the higher energy (NOT pt).
96 //
97 // allow 1 outgoing to cover possible vertexes from interaction in detector material
98 if (vtx->particles_out_size() <= 2) {
99 int num_passed_cuts = 0;
100 HepMC::ConstGenParticlePtr passed_cuts{nullptr};
101 for(const auto& candidate: *vtx) {
102 if(candidate->pdg_id() == mother->pdg_id()) {
103
104 if(passed_cuts && MC::isElectron(mother)) { // second negative electron is a special case
105 if(candidate->momentum().e() > passed_cuts->momentum().e()) {
106 passed_cuts = candidate; // don't increment num_passed_cuts, we are replacing chosen particle
107 }
108 } else {
109 passed_cuts = candidate;
110 ++num_passed_cuts;
111 }
112 }
113 }
114
115 if(num_passed_cuts==1) { // disallow hadronic pi->N*pi etc.
116 daughter = std::move(passed_cuts);
117 }
118
119 }
120 }
121 }
122
123 return std::make_pair(mother, daughter);
124}
125
126//================================================================
128 if(mother) {
129 MotherDaughter res = truthTrajectoryCuts(mother->end_vertex());
130 if(res.first == mother) return res.second;
131 }
132 return {nullptr};
133}
134
135//================================================================
137 if(daughter) {
138 MotherDaughter res = truthTrajectoryCuts(daughter->production_vertex());
139 if(res.second == daughter) return res.first;
140 }
141 return {nullptr};
142}
143
144 //================================================================
145
146} // namespace Trk
An STL vector of pointers that by default owns its pointed-to elements.
ATLAS-specific HepMC functions.
std::pair< std::vector< unsigned int >, bool > res
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
ElasticTruthTrajectoryBuilder(const std::string &type, const std::string &name, const IInterface *parent)
static MotherDaughter truthTrajectoryCuts(const HepMC::ConstGenVertexPtr &vtx)
Decides if the vertex connects two particles on the same TruthTrajectory.
HepMC::ConstGenParticlePtr getMother(const HepMC::ConstGenParticlePtr &particle) const
Returns an umambiguous mother of the truth particle on a TruthTrajectory, or 0.
void buildTruthTrajectory(TruthTrajectory *result, const HepMC::ConstGenParticlePtr &input) const
Build a TruthTrajectory this particle belongs to.
std::pair< HepMC::ConstGenParticlePtr, HepMC::ConstGenParticlePtr > MotherDaughter
Return type for the next method.
HepMC::ConstGenParticlePtr getDaughter(const HepMC::ConstGenParticlePtr &particle) const
Returns an umambiguous daughter of the truth particle on a TruthTrajectory, or 0.
A TruthTrajectory is a chain of charged MC particles connected through the mother-daughter relationsh...
const GenParticle * ConstGenParticlePtr
Definition GenParticle.h:38
const HepMC::GenVertex * ConstGenVertexPtr
Definition GenVertex.h:60
bool isElectron(const T &p)
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
Ensure that the ATLAS eigen extensions are properly loaded.
@ next
Definition BinningData.h:33