ATLAS Offline Software
ElasticTruthTrajectoryBuilder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Andrei Gaponenko, 2008
6 
8 
10 
11 #include "AtlasHepMC/GenParticle.h"
12 #include "AtlasHepMC/GenVertex.h"
14 
17 
18 #include <stack>
19 
20 namespace Trk {
21 
22 //================================================================
24 ElasticTruthTrajectoryBuilder(const std::string& type,
25 const std::string& name,
26 const IInterface* 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) {
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()) {
61  tmp.pop();
62  }
63 
64  // The input particle itself
66 
67  // Now continue towards the interaction point
68  while ( (next = getMother(current)) ) {
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 = 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
fillPileUpNoiseLumi.current
current
Definition: fillPileUpNoiseLumi.py:52
get_generator_info.result
result
Definition: get_generator_info.py:21
Trk::ElasticTruthTrajectoryBuilder::buildTruthTrajectory
void buildTruthTrajectory(TruthTrajectory *result, const HepMC::ConstGenParticlePtr &input) const
Build a TruthTrajectory this particle belongs to.
Definition: ElasticTruthTrajectoryBuilder.cxx:40
Trk::next
@ next
Definition: BinningData.h:33
GenVertex.h
Trk::ElasticTruthTrajectoryBuilder::MotherDaughter
std::pair< HepMC::ConstGenParticlePtr, HepMC::ConstGenParticlePtr > MotherDaughter
Return type for the next method.
Definition: ElasticTruthTrajectoryBuilder.h:39
Trk::ElasticTruthTrajectoryBuilder::getDaughter
HepMC::ConstGenParticlePtr getDaughter(const HepMC::ConstGenParticlePtr &particle) const
Returns an umambiguous daughter of the truth particle on a TruthTrajectory, or 0.
Definition: ElasticTruthTrajectoryBuilder.cxx:127
GenParticle.h
Trk::ElasticTruthTrajectoryBuilder::initialize
virtual StatusCode initialize()
Definition: ElasticTruthTrajectoryBuilder.cxx:34
MC::isPhysical
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
Definition: HepMCHelpers.h:51
ElasticTruthTrajectoryBuilder.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:12
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Trk::ElasticTruthTrajectoryBuilder::truthTrajectoryCuts
static MotherDaughter truthTrajectoryCuts(const HepMC::ConstGenVertexPtr &vtx)
Decides if the vertex connects two particles on the same TruthTrajectory.
Definition: ElasticTruthTrajectoryBuilder.cxx:76
Trk::ElasticTruthTrajectoryBuilder::getMother
HepMC::ConstGenParticlePtr getMother(const HepMC::ConstGenParticlePtr &particle) const
Returns an umambiguous mother of the truth particle on a TruthTrajectory, or 0.
Definition: ElasticTruthTrajectoryBuilder.cxx:136
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
TruthTrajectory
Definition: TruthTrajectory.h:26
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Trk::ElasticTruthTrajectoryBuilder::ElasticTruthTrajectoryBuilder
ElasticTruthTrajectoryBuilder(const std::string &type, const std::string &name, const IInterface *parent)
Definition: ElasticTruthTrajectoryBuilder.cxx:24
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TruthTrajectory.h
HepMC::ConstGenVertexPtr
const HepMC::GenVertex * ConstGenVertexPtr
Definition: GenVertex.h:60
AthAlgTool
Definition: AthAlgTool.h:26
HepMCHelpers.h