ATLAS Offline Software
DecayInFlyTruthTrajectoryBuilder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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 DecayInFlyTruthTrajectoryBuilder(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  // Restrict to quasi-elastic processes (e.g. brems, delta-rays, pi->pi+Delta).
82  //
83  // Require not more than 2 outgoing particles. Note that
84  // delta-rays for primary==electron is a special case, because we have two
85  // outgoing particles with the same PDG id. The "correct" one
86  // is that with the higher energy (NOT pt).
87  //
88  // allow 1 outgoing to cover possible vertexes from interaction in detector material
89  if(vtx && (vtx->particles_in_size() == 1) && (vtx->particles_out_size() <= 2) ) {
90 
91 #ifdef HEPMC3
92  mother = vtx->particles_in().front();
93 #else
94  mother = *vtx->particles_in_const_begin();
95 #endif
96  // Allow status code 1 and 2. E.g. a pion that produced a long track can decay outside of InDet and have status==2.
97  if( mother && MC::isPhysical(mother) ) {
98 
99  int num_passed_cuts = 0;
100  HepMC::ConstGenParticlePtr passed_cuts{nullptr};
101  for(const HepMC::ConstGenParticlePtr& 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  }
109  else {
110  passed_cuts = candidate;
111  ++num_passed_cuts;
112  }
113  }
114  // allow pi/k->mu decay
115  else if(std::abs(candidate->pdg_id()) == 13){
116  passed_cuts = candidate;
117  ++num_passed_cuts;
118  }
119  }
120 
121  if(num_passed_cuts==1) { // disallow hadronic pi->N*pi etc.
122  daughter = passed_cuts;
123  }
124  }
125  }
126 
127  return std::make_pair(mother, daughter);
128 }
129 
130 //================================================================
132  if(mother) {
133  MotherDaughter res = truthTrajectoryCuts(mother->end_vertex());
134  if(res.first == mother) return res.second;
135  }
136  return {nullptr};
137 }
138 
139 //================================================================
141  if(daughter) {
142  MotherDaughter res = truthTrajectoryCuts(daughter->production_vertex());
143  if(res.second == daughter) return res.first;
144  }
145  return {nullptr};
146 }
147 
148 //================================================================
149 
150 } // namespace Trk
Trk::DecayInFlyTruthTrajectoryBuilder::getDaughter
HepMC::ConstGenParticlePtr getDaughter(const HepMC::ConstGenParticlePtr &particle) const
Returns an umambiguous daughter of the truth particle on a TruthTrajectory, or 0.
Definition: DecayInFlyTruthTrajectoryBuilder.cxx:131
fillPileUpNoiseLumi.current
current
Definition: fillPileUpNoiseLumi.py:52
DecayInFlyTruthTrajectoryBuilder.h
get_generator_info.result
result
Definition: get_generator_info.py:21
Trk::DecayInFlyTruthTrajectoryBuilder::DecayInFlyTruthTrajectoryBuilder
DecayInFlyTruthTrajectoryBuilder(const std::string &type, const std::string &name, const IInterface *parent)
Definition: DecayInFlyTruthTrajectoryBuilder.cxx:24
Trk::next
@ next
Definition: BinningData.h:33
Trk::DecayInFlyTruthTrajectoryBuilder::buildTruthTrajectory
void buildTruthTrajectory(TruthTrajectory *result, const HepMC::ConstGenParticlePtr &input) const
Build a TruthTrajectory this particle belongs to.
Definition: DecayInFlyTruthTrajectoryBuilder.cxx:40
GenVertex.h
Trk::DecayInFlyTruthTrajectoryBuilder::initialize
virtual StatusCode initialize()
Definition: DecayInFlyTruthTrajectoryBuilder.cxx:34
GenParticle.h
MC::isPhysical
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
Definition: HepMCHelpers.h:51
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
Trk::DecayInFlyTruthTrajectoryBuilder::truthTrajectoryCuts
static MotherDaughter truthTrajectoryCuts(const HepMC::ConstGenVertexPtr &vtx)
Decides if the vertex connects two particles on the same TruthTrajectory.
Definition: DecayInFlyTruthTrajectoryBuilder.cxx:76
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
test_pyathena.parent
parent
Definition: test_pyathena.py:15
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
Trk::DecayInFlyTruthTrajectoryBuilder::MotherDaughter
std::pair< HepMC::ConstGenParticlePtr, HepMC::ConstGenParticlePtr > MotherDaughter
Return type for the next method.
Definition: DecayInFlyTruthTrajectoryBuilder.h:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Trk::DecayInFlyTruthTrajectoryBuilder::getMother
HepMC::ConstGenParticlePtr getMother(const HepMC::ConstGenParticlePtr &particle) const
Returns an umambiguous mother of the truth particle on a TruthTrajectory, or 0.
Definition: DecayInFlyTruthTrajectoryBuilder.cxx:140
TruthTrajectory.h
HepMC::ConstGenVertexPtr
const HepMC::GenVertex * ConstGenVertexPtr
Definition: GenVertex.h:60
AthAlgTool
Definition: AthAlgTool.h:26
HepMCHelpers.h