ATLAS Offline Software
PartonHistoryUtils.cxx
Go to the documentation of this file.
3 #include <array>
4 
5 namespace top {
6 namespace PartonHistoryUtils {
7 
9  bool isAfterFSR(false);
10  const int particle_ID = particle->pdgId();
11  int forLoop = 0;
12 
13  while (!isAfterFSR) {
14  forLoop = 0;
15  for (size_t j = 0; j < particle->nChildren(); j++) {
16  const xAOD::TruthParticle* tmp_children = particle->child(j);
17  if (tmp_children && tmp_children->pdgId() == particle_ID) {
18  particle = particle->child(j);
19  forLoop++;
20  break;
21  }//if
22  }//for
23  if (forLoop == 0) isAfterFSR = true;
24  }//while
25  return particle;
26  }
27 
29  bool skipit(false);
30 
31  for (size_t i = 0; i < particle->nParents(); i++) {
32  const xAOD::TruthParticle* parent = particle->parent(i);
33  if (parent && parent->pdgId() == particle->pdgId()) {
34  skipit = true;
35  break;
36  }//if
37  }//for
38  return skipit;
39  }
40 
42 
44 
45  if (higgs->pdgId() != 25) return result;
46 
48  const xAOD::TruthParticle* higgs_fsr = findAfterFSR(higgs);
49  if (higgs_fsr->nChildren() != 2) return result;
50 
52  result.decay1_vector = higgs_fsr->child(0)->p4();
53  result.decay2_vector = higgs_fsr->child(1)->p4();
54  result.decay1_pdgId = higgs_fsr->child(0)->pdgId();
55  result.decay2_pdgId = higgs_fsr->child(1)->pdgId();
56 
58  const bool isZ = (result.decay1_pdgId == 23 || result.decay2_pdgId == 23) ? true : false;
59  const bool isW = (std::abs(result.decay1_pdgId) == 24 || std::abs(result.decay2_pdgId) == 24) ? true : false;
60 
65  // commented out variables are unused. experts please check and remove
66  auto tauHadronicIndex = [/*&result*/](const xAOD::TruthParticle* particle) {
67  bool isOk(false);
68  const bool isHadronic = TauIsHadronic(particle, isOk);
69  if (!isOk) {
70  return -1;
71  }
72 
73  if (isHadronic) return 1;
74 
75  return 0;
76  };
77 
78  if (std::abs(result.decay1_pdgId) == 15) {
79  result.tau_decay1_isHadronic = tauHadronicIndex(higgs_fsr->child(0));
80  }
81  if (std::abs(result.decay2_pdgId) == 15) {
82  result.tau_decay2_isHadronic = tauHadronicIndex(higgs_fsr->child(1));
83  }
84 
85  if (!isZ && !isW) return result;
86 
87  const xAOD::TruthParticle* decay1 = findAfterFSR(higgs->child(0));
88  if (decay1->nChildren() != 2) return result;
89  const xAOD::TruthParticle* decay2 = findAfterFSR(higgs->child(1));
90  if (decay2->nChildren() != 2) return result;
91 
93  result.decay1_from_decay1_vector = decay1->child(0)->p4();
94  result.decay2_from_decay1_vector = decay1->child(1)->p4();
95  result.decay1_from_decay1_pdgId = decay1->child(0)->pdgId();
96  result.decay2_from_decay1_pdgId = decay1->child(1)->pdgId();
97 
98  result.decay1_from_decay2_vector = decay2->child(0)->p4();
99  result.decay2_from_decay2_vector = decay2->child(1)->p4();
100  result.decay1_from_decay2_pdgId = decay2->child(0)->pdgId();
101  result.decay2_from_decay2_pdgId = decay2->child(1)->pdgId();
102 
103  if (std::abs(result.decay1_from_decay1_pdgId) == 15) {
104  result.tau_decay1_from_decay1_isHadronic = tauHadronicIndex(decay1->child(0));
105  }
106  if (std::abs(result.decay2_from_decay1_pdgId) == 15) {
107  result.tau_decay2_from_decay1_isHadronic = tauHadronicIndex(decay1->child(1));
108  }
109  if (std::abs(result.decay1_from_decay2_pdgId) == 15) {
110  result.tau_decay1_from_decay2_isHadronic = tauHadronicIndex(decay2->child(0));
111  }
112  if (std::abs(result.decay2_from_decay2_pdgId) == 15) {
113  result.tau_decay2_from_decay2_isHadronic = tauHadronicIndex(decay2->child(1));
114  }
115 
116  return result;
117  }
118 
119  bool TauIsHadronic(const xAOD::TruthParticle* tau, bool &isOk) {
120 
121  if (!tau) {
122  isOk = false;
123  return false;
124  }
125 
126  if (std::abs(tau->pdgId()) != 15) {
127  isOk = false;
128  return false;
129  }
130 
131  const xAOD::TruthParticle* afterFsr = findAfterFSR(tau);
132 
133  if (afterFsr->nChildren() != 2) {
134  isOk = false;
135  return false;
136  }
137 
138  const xAOD::TruthParticle* child1 = findAfterFSR(afterFsr->child(0));
139  const xAOD::TruthParticle* child2 = findAfterFSR(afterFsr->child(1));
140 
141  if (std::abs(child1->pdgId()) == 16) {
142  // it means the other particle ahs to be W
143  if (std::abs(child2->pdgId()) != 24) {
144  isOk = false;
145  return false;
146  }
147 
148  // child2 is W
149  if (child2->nChildren() != 2) {
150  isOk = false;
151  return false;
152  }
153 
154  isOk = true;
155 
156  // everything is fine, check if the W decays hadronically or leptonically
157  if (std::abs(child2->child(0)->pdgId()) < 16) {
158  return true;
159  } else {
160  return false;
161  }
162  } else {
163  // it means the other particle has to be nu
164  if (std::abs(child2->pdgId()) != 16) {
165  isOk = false;
166  return false;
167  }
168 
169  // child1 is W
170  if (child1->nChildren() != 2) {
171  isOk = false;
172  return false;
173  }
174 
175  isOk = true;
176 
177  // everything is fine, check if the W decays hadronically or leptonically
178  if (std::abs(child1->child(0)->pdgId()) < 16) {
179  return true;
180  } else {
181  return false;
182  }
183  }
184  }
185 
186  void
187  decorateWithMPtPhi(xAOD::PartonHistory* pHistory, const std::string & prefix, const TLorentzVector & vec ){
188  constexpr size_t nItems=3;
189  const std::array<std::string, nItems> suffix{"_m", "_pt", "_phi"};
190  const std::array<double, nItems> values{vec.M(), vec.Pt(), vec.Phi()};
191  for(size_t i(0);i<nItems;++i){
192  pHistory->auxdecor< float >(prefix+suffix[i]) = values[i];
193  }
194  return;
195  }
196 }
197 }
xAOD::PartonHistory
Interface class.
Definition: PartonHistory.h:48
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
get_generator_info.result
result
Definition: get_generator_info.py:21
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
hotSpotInTAG.suffix
string suffix
Definition: hotSpotInTAG.py:186
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
SG::AuxElement::auxdecor
Decorator< T, ALLOC >::reference_type auxdecor(const std::string &name) const
Fetch an aux decoration, as a non-const reference.
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:797
top::PartonHistoryUtils::findAfterFSR
const xAOD::TruthParticle * findAfterFSR(const xAOD::TruthParticle *particle)
Return particle after FSR (before the decay vertex)
Definition: PartonHistoryUtils.cxx:8
PartonHistory.h
top::PartonHistoryUtils::TauIsHadronic
bool TauIsHadronic(const xAOD::TruthParticle *tau, bool &isOk)
Check if tau decays hadronically or not.
Definition: PartonHistoryUtils.cxx:119
lumiFormat.i
int i
Definition: lumiFormat.py:92
isZ
bool isZ(const T &p)
Definition: AtlasPID.h:164
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
PartonHistoryUtils.h
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
test_pyathena.parent
parent
Definition: test_pyathena.py:15
top::PartonHistoryUtils::AnalyzeHiggsDecay
HiggsDecay AnalyzeHiggsDecay(const xAOD::TruthParticle *higgs)
Store higgs decay information.
Definition: PartonHistoryUtils.cxx:41
xAOD::TruthParticle_v1::nChildren
size_t nChildren() const
Number of children of this particle.
Definition: TruthParticle_v1.cxx:140
top::PartonHistoryUtils::HiggsDecay
Definition: PartonHistoryUtils.h:20
isW
bool isW(const T &p)
Definition: AtlasPID.h:167
xAOD::TruthParticle_v1::child
const TruthParticle_v1 * child(size_t i=0) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
Definition: TruthParticle_v1.cxx:149
xAOD::TruthParticle_v1::p4
virtual FourMom_t p4() const override final
The full 4-momentum of the particle.
Definition: TruthParticle_v1.cxx:196
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
top::PartonHistoryUtils::hasParticleIdenticalParent
bool hasParticleIdenticalParent(const xAOD::TruthParticle *particle)
Return true when particle is a top before FSR.
Definition: PartonHistoryUtils.cxx:28
top::PartonHistoryUtils::decorateWithMPtPhi
void decorateWithMPtPhi(xAOD::PartonHistory *pHistory, const std::string &prefix, const TLorentzVector &vec)
Perform decoration M, Pt, Phi of the history from a TLorentzVector.
Definition: PartonHistoryUtils.cxx:187