ATLAS Offline Software
HadronOriginClassifier.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
6 
7 namespace DerivationFramework{
8 
9  HadronOriginClassifier::HadronOriginClassifier(const std::string& t, const std::string& n, const IInterface* p):
10  AthAlgTool(t,n,p),
11  m_mcName("TruthEvents"),
12  m_HadronPtMinCut(0),
13  m_HadronEtaMaxCut(0),
14  m_DSID(0)
15  {
16  declareInterface<DerivationFramework::HadronOriginClassifier>(this);
17 
18  declareProperty("MCCollectionName",m_mcName="TruthEvents");
19  declareProperty("HadronpTMinCut",m_HadronPtMinCut=5000.);
20  declareProperty("HadronetaMaxCut",m_HadronEtaMaxCut=2.5);
21  declareProperty("DSID",m_DSID=410000);
22  }
23 
25 
27  ATH_MSG_INFO("Initialize " );
28  ATH_MSG_INFO("DSID " << m_DSID );
29  // all Herwig++/Herwig7 showered samples
30  if( m_DSID==410003 || m_DSID == 410008 //aMC@NLO+Hpp
31  || m_DSID == 410004 || m_DSID == 410163 //Powheg+Hpp
32  || m_DSID == 410232 //first attempt for Powheg+H7
33  || m_DSID == 410233 //first attempt for aMC@NLO+H7
34  || (m_DSID>=410525 && m_DSID<=410530) //New Powheg+H7 samples
35  || (m_DSID>=407037 && m_DSID<=407040) //Powheg+Hpp MET/HT sliced
36  || m_DSID ==410536 || m_DSID == 410537
37  || m_DSID == 410245 //aMC@NLO+H++ , ttbb
38  || (m_DSID>=410557 && m_DSID<=410559) // new Powheg+H7, mc16
39  || (m_DSID>=411082 && m_DSID<=411090) //Powheg+H7 HF-filtered
40  || (m_DSID>=407354 && m_DSID<=407356) //Powheg+H7 ttbar HT-filtered
41  || m_DSID ==411233 || m_DSID==411234 //Powheg+H7.1.3 ttbar
42  || m_DSID == 411316 //Powheg+H7 allhad ttbar
43  || (m_DSID>=411329 && m_DSID<=411334) //Powheg+H7.1.3 ttbar HF-filtered
44  || (m_DSID>=411335 && m_DSID<=411337) //Powheg+H7.1.3 ttbar HT-filtered
45  || m_DSID ==412116 || m_DSID == 412117 //amc@NLO+H7.1.3 ttbar
46  || m_DSID ==504329 || m_DSID == 504333 || m_DSID == 504341 //amc@NLO+H7.2.1 refined ttZ
47  || (m_DSID >= 601239 && m_DSID <= 601240)
48  ){
50  if (m_DSID==410245 || (m_DSID >= 601239 && m_DSID <= 601240)){
51  m_ttbb=true;
52  }
53  }
54  // all Pythia8 showered samples
55  else if( m_DSID==410006 //Powheg+P8 old main31
56  || m_DSID==410500 //Powheg+P8 new main31, hdamp=mt
57  || (m_DSID>=410501 && m_DSID<=410508) //Powheg+P8 new main31, hdamp=1.5m // Boosted samples are included 410507 410508
58  || (m_DSID>=410511 && m_DSID<=410524) //Powheg+P8 new main31, hdamp=1.5mt, radiation systematics
59  || (m_DSID>=410531 && m_DSID<=410535) //Powheg+P8 allhad samples
60  || (m_DSID>=346343 && m_DSID<=346345) //Powheg+P8 ttH
61  || m_DSID==412123 // MG+P8 ttW
62  || m_DSID==410155 // aMC@NlO+P8 ttW
63  || m_DSID==410159 || m_DSID==410160 //aMC@NLO+P8, old settings
64  || (m_DSID>=410218 && m_DSID<=410220) // aMC@NlO+P8 ttZ
65  || (m_DSID>=410276 && m_DSID<=410278) // aMC@NlO+P8 ttZ_lowMass
66  || (m_DSID>=410225 && m_DSID<=410227) || m_DSID==410274 || m_DSID==410275 //aMC@NLO+P8, new settings
67  || m_DSID==410568 || m_DSID==410569 // nonallhad boosted c-filtered
68  || m_DSID==410244 //aMC@NLO+P8, ttbb (old)
69  || m_DSID==410441 || m_DSID==410442 //new aMC@NLO+P8 mc16, new shower starting scale
70  || (m_DSID>=410464 && m_DSID<=410466) //new aMC@NLO+P8 mc16, new shower starting scale, no shower weights
71  || (m_DSID>=410470 && m_DSID<=410472) || (m_DSID>=410480 && m_DSID<=410482) //new Powheg+P8 mc16
72  || m_DSID==410452 //new aMC@NLO+P8 FxFx mc16
73  || (m_DSID>=411073 && m_DSID<=411081) //Powheg+P8 HF-filtered
74  || (m_DSID>=412066 && m_DSID<=412074) //aMC@NLO+P8 HF-filtered
75  || (m_DSID>=411068 && m_DSID<=411070) //Powheg+P8 ttbb
76  || (m_DSID>=410265 && m_DSID<=410267) //aMC@NLO+P8 ttbb
77  || (m_DSID>=411178 && m_DSID<=411180) || (m_DSID==411275) //Powheg+P8 ttbb OTF production - ATLMCPROD-7240
78  || (m_DSID>=600791 && m_DSID<=600792) //Powheg+P8 ttbb - ATLMCPROD-9179
79  || (m_DSID>=600737 && m_DSID<=600738) //Powheg+P8 ttbb - ATLMCPROD-9179
80  || (m_DSID>=601226 && m_DSID<=601227) // Powheg+P8 ttbb bornzerodamp cut 5, ATLMCPROD-9694
81  || (m_DSID>=407342 && m_DSID<=407344) //Powheg+P8 ttbar HT-filtered
82  || (m_DSID>=407345 && m_DSID<=407347) //Powheg+P8 ttbar MET-filtered
83  || (m_DSID>=407348 && m_DSID<=407350) //aMC@NLO+P8 ttbar HT-filtered
84  || m_DSID==504330 || m_DSID==504331 || m_DSID==504332 || m_DSID==504334 || m_DSID==504335 || m_DSID==504336 || m_DSID==504338 || m_DSID==504342 || m_DSID==504343 || m_DSID==504344 || m_DSID==504346//aMC@NLO+P8 refined ttZ
85  || m_DSID==601491 || m_DSID==601492 //Pow+Py8 ttbar pTHard variations - ATLMCPROD-10168
86  || (m_DSID>=601495 && m_DSID<=601498) //Pow+Py8 ttbar pTHard variations - ATLMCPROD-10168
87  || (m_DSID>=601783 && m_DSID<=601784) // Powheg+P8 ttbb bornzerodamp cut 5 pThard variations - ATLMCPROD-10527
88  ){
90  if ( m_DSID==410244 //aMC@NLO+P8, ttbb (old)
91  || (m_DSID>=411068 && m_DSID<=411070) //Powheg+P8 ttbb
92  || (m_DSID>=410265 && m_DSID<=410267) //aMC@NLO+P8 ttbb
93  || (m_DSID>=411178 && m_DSID<=411180) || (m_DSID==411275) //Powheg+P8 ttbb OTF production - ATLMCPROD-7240
94  || (m_DSID>=600791 && m_DSID<=600792) // Powheg+P8 ttbb
95  || (m_DSID>=600737 && m_DSID<=600738) // Powheg+P8 ttbb dipole recoil
96  || (m_DSID>=601226 && m_DSID<=601227) // Powheg+P8 ttbb bornzerodamp cut 5
97  || (m_DSID>=601783 && m_DSID<=601784) // Powheg+P8 ttbb bornzerodamp cut 5 pThard variations - ATLMCPROD-10527
98  ){
99  m_ttbb=true;
100  }
101  }
102  // all Sherpa showered samples
103  else if( (m_DSID>=410186 && m_DSID<=410189) //Sherpa 2.2.0
104  || (m_DSID>=410249 && m_DSID<=410252) //Sherpa 2.2.1
105  || (m_DSID>=410342 && m_DSID<=410347) //Sherpa 2.2.1 sys
106  || (m_DSID>=410350 && m_DSID<=410355) //Sherpa 2.2.1 sys
107  || (m_DSID>=410357 && m_DSID<=410359) //Sherpa 2.2.1 sys
108  || (m_DSID>=410361 && m_DSID<=410367) //Sherpa 2.2.1 sys
109  || (m_DSID>=410281 && m_DSID<=410283) //Sherpa BFilter
110  || m_DSID==410051 //Sherpa ttbb (ICHEP sample)
111  || (m_DSID>=410323 && m_DSID<=410325) || (m_DSID==410369) //New Sherpa 2.2.1 ttbb
112  || (m_DSID>=364345 && m_DSID<=364348) //Sherpa 2.2.4 (test)
113  || (m_DSID>=410424 && m_DSID<=410427) //Sherpa 2.2.4
114  || (m_DSID>=410661 && m_DSID<=410664) //Sherpa 2.2.4 ttbb
115  || (m_DSID>=421152 && m_DSID<=421158) //Sherpa2.2.8 ttbar
116  || m_DSID==413023 // sherpa 2.2.1 ttZ
117  || m_DSID==700000 // Sherpa 2.2.8 ttW
118  || m_DSID==700168 // Sherpa 2.2.10 ttW
119  || m_DSID==700205 // Sherpa 2.2.10 ttW EWK
120  || m_DSID==700309 // Sherpa 2.2.11 ttZ
121  || (m_DSID>=700051 && m_DSID<=700054) //Sherpa2.2.8 ttbb
122  || (m_DSID>=700121 && m_DSID<=700124) //Sherpa2.2.10 ttbar
123  || (m_DSID>=700164 && m_DSID<=700167) //Sherpa2.2.10 ttbb
124  ){
126  if( m_DSID==410051
127  || (m_DSID>=410323 && m_DSID<=410325) || (m_DSID==410369)
128  || (m_DSID>=410661 && m_DSID<=410664)
129  || (m_DSID>=700051 && m_DSID<=700054)
130  || (m_DSID>=700164 && m_DSID<=700167)
131  ){
132  m_ttbb=true;
133  }
134  }
135  // the default is Pythia6, so no need to list the Pythia6 showered samples
136  // these are:
137  // 410000-410002
138  // 410007, 410009, 410120-410121
139  // 301528-301532
140  // 303722-303726
141  // 407009-407012
142  // 407029-407036
143  // 410120
144  // 426090-426097
145  // 429007
146  else{
148  }
149  return StatusCode::SUCCESS;
150  }
151 
152  /*
153  --------------------------------------------------------------------------------------------------------------------------------------
154  ------------------------------------------------------------- Hadron Map -------------------------------------------------------------
155  --------------------------------------------------------------------------------------------------------------------------------------
156  */
157 
158  // Define the function GetOriginMap that determines the origin of the hadrons.
159  std::map<const xAOD::TruthParticle*, DerivationFramework::HadronOriginClassifier::HF_id> HadronOriginClassifier::GetOriginMap() const {
160  // Create a set of maps to store the information about the hadrons and the partons
161  std::map<const xAOD::TruthParticle*, int> mainHadronMap; // Map with main hadrons and their flavor.
162  std::map<const xAOD::TruthParticle*, HF_id> partonsOrigin; // Map with partons and their category (from top, W, H, MPI, FSR, extra).
163  std::map<const xAOD::TruthParticle*, const xAOD::TruthParticle*> hadronsPartons; // Map with hadrons and their matched parton.
164  std::map<const xAOD::TruthParticle*, HF_id> hadronsOrigin; // Map with hadrons and their category (from top, W, H, MPI, FSR, extra)
165  // Fill the maps mainHadronMap and partonsOrigin
166  buildPartonsHadronsMaps(mainHadronMap, partonsOrigin);
167  // Create two maps to know which partons and hadrons have already been matched.
168  std::vector<const xAOD::TruthParticle*> matched_partons;
169  std::vector<const xAOD::TruthParticle*> matched_hadrons;
170  // Use a while to go through the HF hadrons in mainHadronMap and partons in partonsOrigin.
171  while (matched_partons.size()<partonsOrigin.size() && matched_hadrons.size()<mainHadronMap.size()){
172  // Create a float variable to store the DeltaR between a parton and the closest hadron.
173  float dR=999.;
174  // Create two pointers for TruthParticle type to go through the partons and hadrons.
175  const xAOD::TruthParticle* hadron=nullptr;
176  const xAOD::TruthParticle* parton=nullptr;
177  // Use a for to go through the partonsOrigin.
178  for(std::map<const xAOD::TruthParticle*, HF_id>::iterator itr = partonsOrigin.begin(); itr!=partonsOrigin.end(); ++itr){
179  // Check if the parton has already been matched to an hadron.
180  if(std::find(matched_partons.begin(), matched_partons.end(), (*itr).first) != matched_partons.end()) continue;
181  // Extract the pt of the parton.
182  TVector3 v, vtmp;
183  if ((*itr).first->pt()>0.)
184  v.SetPtEtaPhi((*itr).first->pt(),(*itr).first->eta(),(*itr).first->phi());
185  else // Protection against FPE from eta and phi calculation
186  v.SetXYZ(0.,0.,(*itr).first->pz());
187  // Use a for to go through the HF hadrons in mainHadronMap.
188  for(std::map<const xAOD::TruthParticle*, int>::iterator it = mainHadronMap.begin(); it!=mainHadronMap.end(); ++it){
189  // Check if the hadron has already been matched to a parton.
190  if(std::find(matched_hadrons.begin(), matched_hadrons.end(), (*it).first) != matched_hadrons.end()) continue;
191  // Check if the hadron's flavour mathces the one of the parton.
192  if((*it).second != abs((*itr).first->pdgId()) ) continue;
193  // Extract the pt of the hadron.
194  vtmp.SetPtEtaPhi((*it).first->pt(),(*it).first->eta(),(*it).first->phi());
195  // Compute Delta R between hadron and parton and store in dR if it is smaller than the current value.
196  // Also store the parton and hadron in the pointers that have been previous created.
197  if(vtmp.DeltaR(v) < dR){
198  dR = vtmp.DeltaR(v);
199  hadron = (*it).first;
200  parton = (*itr).first;
201  }
202  }//loop hadrons
203  }//loop partons
204  // Add the matched part-hadron pair in the corresponding maps.
205  matched_partons.push_back(parton);
206  matched_hadrons.push_back(hadron);
207  hadronsPartons[ hadron ] = parton;
208  }
209 
210  // Use a for to go through the HF hadrons in mainHadronMap.
211  for(std::map<const xAOD::TruthParticle*, int>::iterator it = mainHadronMap.begin(); it!=mainHadronMap.end(); ++it){
212  // Extract the current hadron.
213  const xAOD::TruthParticle* hadron = (*it).first;
214  // Check if the hadron has been matched to a parton.
215  // If it has been matched to any hadron, use it to determine the origin.
216  // Otherwise, the hadron is considered extra.
217  if(hadronsPartons.find(hadron)!=hadronsPartons.end()){
218  hadronsOrigin[hadron] = partonsOrigin[ hadronsPartons[hadron] ];
219  } else{
220  hadronsOrigin[hadron] = extrajet;
221  }
222  }
223  return hadronsOrigin;
224  }
225 
226  // Define the function buildPartonsHadronsMaps that determines the flavour of the hadrons and the origin of the partons.
227  void HadronOriginClassifier::buildPartonsHadronsMaps(std::map<const xAOD::TruthParticle*,int>& mainHadronMap, std::map<const xAOD::TruthParticle*,HF_id>& partonsOrigin) const {
228  // Extract the TruthParticles container.
229  const xAOD::TruthEventContainer* xTruthEventContainer = nullptr;
230  if (evtStore()->retrieve(xTruthEventContainer,m_mcName).isFailure()) {
231  ATH_MSG_WARNING("could not retrieve TruthEventContainer " <<m_mcName);
232  }
233  // Create a container with TruthParticles to store the hadrons that has already been saved.
234  std::set<const xAOD::TruthParticle*> usedHadron;
235  for ( const auto* truthevent : *xTruthEventContainer ) {
236  // Use a for to go through the TruthParticles.
237  for(unsigned int i = 0; i < truthevent->nTruthParticles(); i++){
238  // Extract the i-th particle.
239  const xAOD::TruthParticle* part = truthevent->truthParticle(i);
240  if(!part) continue;
241  // Simulated particles are not considered.
243  // Create a set of boolean variables to indicate the type of particle.
244  bool isbquark = false; // The particle is a b-quark.
245  bool iscquark = false; // The particle is a c-quark.
246  bool isHFhadron = false; // The particle is a HF hadron.
247  // Extract the pdgid of the particle and use it to determine the type of particle.
248  int pdgid = abs(part->pdgId());
249  if(pdgid == 5 ){
250  isbquark=true;
251  }
252  else if(pdgid == 4 ){
253  iscquark=true;
254  }
256  isHFhadron=true;
257  }
258  else{
259  continue;
260  }
261  // For HF quarks (b or c), check their category.
262  // The category is determined looking for the parents.
263  if(isbquark){
264  // In this case, the parton is a b-quark.
265  // Create a boolean that indicates when to stop to look for parents.
266  bool islooping = isLooping(part);
267  // Check the category of the b-quark.
268  if(isDirectlyFromWTop(part, islooping)){
269  partonsOrigin[ part ] = b_from_W;
270  }
271  else if(isDirectlyFromTop(part, islooping)){
272  partonsOrigin[ part ] = b_from_top;
273  }
274  else if(!IsTtBb()&&(IsHerwigPP()||IsSherpa())&&isDirectlyFSR(part,islooping)){
275  partonsOrigin[ part ] = b_FSR;
276  }
277  else if(!IsTtBb()&&IsPythia8()&&isDirectlyFSRPythia8(part,islooping)){
278  partonsOrigin[ part ] = b_FSR;
279  }
280  else if(!IsTtBb()&&IsPythia6()&&isDirectlyFSRPythia6(part,islooping)){
281  partonsOrigin[ part ] = b_FSR;
282  }
283  else if(!IsTtBb()&&IsPythia6()&&isDirectlyMPIPythia6(part, islooping)){
284  partonsOrigin[ part ] = b_MPI;
285  }
286  else if(!IsTtBb()&&IsPythia8()&&isDirectlyMPIPythia8(part, islooping)){
287  partonsOrigin[ part ] = b_MPI;
288  }
289  else if(!IsTtBb()&&IsSherpa()&&isDirectlyMPISherpa(part)){
290  partonsOrigin[ part ] = b_MPI;
291  }
292  }
293  if(iscquark){
294  // In this case, the parton is a c-quark.
295  // Create a boolean that indicates when to stop to look for parents.
296  bool islooping = isLooping(part);
297  // Check the category of the b-quark.
298  if(isDirectlyFromWTop(part, islooping)){
299  partonsOrigin[ part ] = c_from_W;
300  }
301  else if(isDirectlyFromTop(part, islooping)){
302  partonsOrigin[ part ] = c_from_top;
303  }
304  else if(!IsTtBb()&&(IsHerwigPP()&&IsSherpa())&&isDirectlyFSR(part,islooping)){
305  partonsOrigin[ part ] = c_FSR;
306  }
307  else if(!IsTtBb()&&IsPythia8()&&isDirectlyFSRPythia8(part,islooping)){
308  partonsOrigin[ part ] = c_FSR;
309  }
310  else if(!IsTtBb()&&IsPythia6()&&isDirectlyFSRPythia6(part,islooping)){
311  partonsOrigin[ part ] = c_FSR;
312  }
313  else if(!IsTtBb()&&IsPythia6()&&isDirectlyMPIPythia6(part, islooping)){
314  partonsOrigin[ part ] = c_MPI;
315  }
316  else if(!IsTtBb()&&IsPythia8()&&isDirectlyMPIPythia8(part, islooping)){
317  partonsOrigin[ part ] = c_MPI;
318  }
319  else if(!IsTtBb()&&IsSherpa()&&isDirectlyMPISherpa(part)){
320  partonsOrigin[ part ] = c_MPI;
321  }
322  }
323  // The HF hadrons are stored in the map mainHadronMap if they are not repeated.
324  if(isHFhadron && !isCHadronFromB(part)){
325  // In this case, the particle is a HF hadron but not a C-Hadron from a B-hadron.
326  // If the hadron is not in usedHadron, then add it in mainHadronMap with fillHadronMap function.
327  if(usedHadron.insert(part).second) {
328  fillHadronMap(usedHadron, mainHadronMap,part,part);
329  }
330  }
331  }//loop on particles
332  }//loop on truthevent container
333  }
334 
335  /*
336  ---------------------------------------------------------------------------------------------------------------------------------------
337  ------------------------------------------------------------ Particle Type ------------------------------------------------------------
338  ---------------------------------------------------------------------------------------------------------------------------------------
339  */
340  bool HadronOriginClassifier::isCHadronFromB(const xAOD::TruthParticle* part, std::shared_ptr<std::set<const xAOD::TruthParticle*>> checked ) const{
341  if(!MC::isCharmHadron(part)) return false;
342  if (!checked) checked = std::make_shared<std::set<const xAOD::TruthParticle*>>();
343  checked ->insert(part);
344 
345  for(unsigned int i=0; i<part->nParents(); ++i){
346  const xAOD::TruthParticle* parent = part->parent(i);
347  if(!parent) continue;
348  if(checked->count(parent)) continue;
349  checked->insert(parent);
350  if( MC::isBottomHadron(parent) ){
351  return true;
352  }
354  if(isCHadronFromB(parent))return true;
355  }
356  }
357 
358  return false;
359  }
360 
361  // Define the function fillHadronMap that fills the map of hadrons with their flavour.
362  void HadronOriginClassifier::fillHadronMap(std::set<const xAOD::TruthParticle*>& usedHadron, std::map<const xAOD::TruthParticle*,int>& mainHadronMap, const xAOD::TruthParticle* mainhad, const xAOD::TruthParticle* ihad, bool decayed) const {
363  // Fist, check that the consdired hadron has a non-null pointer
364  if (!ihad) return;
365  usedHadron.insert(ihad);
366  // Create two variables to indicate the flavour of the parents and childrens particles that will be considered.
367  // Create a boolean to indicate if the particles considered are from the final state.
368  int parent_flav,child_flav;
369  bool isFinal = true;
370  // Check if the considered hadron has children.
371  if(!ihad->nChildren()) return;
372  // Use a for to go through the children.
373  for(unsigned int j=0; j<ihad->nChildren(); ++j){
374  // Extract the j-th children.
375  const xAOD::TruthParticle* child = ihad->child(j);
376  if(!child) continue;
377  if(decayed){
378  fillHadronMap(usedHadron, mainHadronMap,mainhad,child,true);
379  isFinal=false;
380  }
381  else{
382  child_flav = std::abs(MC::leadingQuark(child));
383  if(child_flav!=4 && child_flav!=5) continue;
384  parent_flav = std::abs(MC::leadingQuark(mainhad));
385  if(child_flav!=parent_flav) continue;
386  fillHadronMap(usedHadron, mainHadronMap,mainhad,child);
387  isFinal=false;
388  }
389  }
390 
391  if(isFinal && !decayed){
392  mainHadronMap[mainhad]=std::abs(MC::leadingQuark(mainhad));
393  for(unsigned int j=0; j<ihad->nChildren(); ++j){
394  const xAOD::TruthParticle* child = ihad->child(j);
395  if(!child) continue;
396  fillHadronMap(usedHadron, mainHadronMap,mainhad,child,true);
397  }
398  }
399  }
400 
401  /*
402  ---------------------------------------------------------------------------------------------------------------------------------------
403  ----------------------------------------------------------- Particle Origin -----------------------------------------------------------
404  ---------------------------------------------------------------------------------------------------------------------------------------
405  */
406 
407  // Define the function isFromTop that indicates if a particle comes from top.
408 
410  // Find the first parent of the considered particle that is different from the particle.
411  const xAOD::TruthParticle* initpart = findInitial(part, looping);
412  // Check if this parent comes from the top with function isDirectlyFromTop.
413  return isDirectlyFromTop(initpart, looping);
414  }
415 
416  // Define the function isDirectlyFromTop that indicates if a particle comes from the direct decay of top.
418  // First, make sure the consdired particle has a non-null pointer and it has parents.
419  // Otherwise, return false.
420  if(!part || !part->nParents()) return false;
421  // Go through the parents of the particle.
422  for(unsigned int i=0; i<part->nParents(); ++i){
423  // Extract the i-th parent.
424  const xAOD::TruthParticle* parent = part->parent(i);
425  if(!parent) continue;
426  if(looping) continue;
427  // If the i-th parent is a top, then return true
428  if( abs( parent->pdgId() ) == 6 ) return true;
429  }
430  // If a top is no the parent, then return false.
431  return false;
432  }
433 
434  // Define the function isFromWTop that indicates if a particle comes from the decay chain t->Wb.
435 
437  // Find the first parent of the considered particle that is different from the particle.
438  const xAOD::TruthParticle* initpart = findInitial(part, looping);
439  return isDirectlyFromWTop(initpart, looping);
440  }
441 
442  // Define the function isDirectlyFromWTop that indicates if a particle comes from the direct decay of a W from a top.
444  // First, make sure the consdired particle has a non-null pointer and it has parents.
445  // Otherwise, return false.
446  if(!part || !part->nParents()) return false;
447  // Use a for to go though the parents.
448  for(unsigned int i=0; i<part->nParents(); ++i){
449  // Get the i-th parent.
450  const xAOD::TruthParticle* parent = part->parent(i);
451  if(!parent) continue;
452  if(looping) continue;
453  if( MC::isW(parent)){
454  if( isFromTop(parent, looping) ) return true;
455  }
456  }
457  // In this case, none of the parents of the particle is a W from top.
458  // Hence, return false.
459  return false;
460  }
461 
463  if(!part->nParents()) return false;
464  for(unsigned int i=0; i<part->nParents(); ++i){
465  const xAOD::TruthParticle* parent = part->parent(i);
466  if(!parent) continue;
467  if( looping ) continue;
468  if( MC::isPhoton(parent) || abs(parent->pdgId())<5 ) return true;
469  }
470  return false;
471  }
472 
474  const xAOD::TruthParticle* initpart = findInitial(part, looping);
475  return isDirectlyFromGluonQuark(initpart, looping);
476  }
477 
479  if(!part->nParents()) return false;
480  for(unsigned int i=0; i<part->nParents(); ++i){
481  const xAOD::TruthParticle* parent = part->parent(i);
482  if(!parent) continue;
483  if(looping ) continue;
484  if(!MC::isW(parent)) continue;
485  if(abs(part->pdgId())==4){
486  //trick to get at least 50% of PowhegPythia c from FSR
487  if(part->pdgId()==-(parent->pdgId())/6){
488  if( isFromGluonQuark(parent, looping) ) return true;
489  }
490  }
491  else{
492  if( isFromGluonQuark(parent, looping) ) return true;
493  }
494  }
495  return false;
496  }
497 
499  if(!part->nParents()) return false;
500  for(unsigned int i=0; i<part->nParents(); ++i){
501  const xAOD::TruthParticle* parent = part->parent(i);
502  if(!parent) continue;
503  if( looping ) continue;
505  if( isFromQuarkTop( parent,looping ) ) return true;
506  }
507  }
508  return false;
509  }
510 
512  if(!part->nParents()) return false;
513  for(unsigned int i=0; i<part->nParents(); ++i){
514  const xAOD::TruthParticle* parent = part->parent(i);
515  if(!parent) continue;
516  if( looping ) continue;
517  if( abs(parent->pdgId())<6 ) {
518 
519  if(isFromTop(parent,looping)){
520  return true;
521  }
522  else if(isFromWTop(parent,looping)){
523  return true;
524  }
525  }
526  }
527 
528  return false;
529  }
530 
532  const xAOD::TruthParticle* initpart = findInitial(part, looping);
533  return isDirectlyFromQuarkTop(initpart, looping);
534  }
535 
536  // Define the function isDirectlyFSRPythia8 that indicates if a particle comes from Final State Radiation in samples generated with Pythia8.
537 
539  // First, check if the particle has parents and return false if it does not.
540  if(!part->nParents()) return false;
541  // Use a for to go through the parents.
542  for(unsigned int i=0; i<part->nParents(); ++i){
543 
544  // Extract the i-th parent.
545 
546  const xAOD::TruthParticle* parent = part->parent(i);
547  if(!parent) continue;
548  if( looping ) continue;
550  if( isFromQuarkTopPythia8( parent,looping ) ) return true;
551  }
552  }
553  // In this case, no parent from the particle is a gluon or a photon coming from a top
554  // Hence, the particle is not from FSR and false is not returned.
555  return false;
556  }
557 
558  // Define the function isDirectlyFromQuarkTopPythia8 that indicates if a particle comes from direct decay of the top in samples generated with Pythia8.
560  // First, make sure the consdired particle has a non-null pointer and it has parents.
561  // Otherwise, return false.
562  if(!part->nParents()) return false;
563  // Use a for to go through the parents.
564  for(unsigned int i=0; i<part->nParents(); ++i){
565  // Extract the i-th parent.
566  const xAOD::TruthParticle* parent = part->parent(i);
567  if(!parent) continue;
568  if(looping ) continue;
569  // Check if the parent is a quark different from the top.
570  if( abs(parent->pdgId())<6 ) {
571  // In this case, the parent is a quark different from top.
572  // Check if it comes from the decay chain of the t->Wb.
573  // If it is the case, return true.
574  if(isFromWTop(parent,looping)){
575  return true;
576  }
577  }
578  }
579  // In this case, any of the parents of the particle comes from t->Wb chaing.
580  // Hence, the particle does not come from the top directly and false is returned.
581  return false;
582  }
583 
584  // Define the function isFromQuarkTopPythia8 that indicates if a particle comes from top in samples generated with Pythia8.
586  // Find the first parent of the considered particle that is different from the particle.
587  const xAOD::TruthParticle* initpart = findInitial(part, looping);
588  // Check if this parent comes from the top with function isDirectlyFromQuarkTopPythia8.
589  return isDirectlyFromQuarkTopPythia8(initpart, looping);
590  }
591 
593  if(!part->nParents()) return false;
594  for(unsigned int i=0; i<part->nParents(); ++i){
595  const xAOD::TruthParticle* parent = part->parent(i);
596  if(!parent) continue;
597  if( looping ) continue;
598  if( abs(parent->pdgId())== 2212 && MC::isPhysical(part)) return true;
599  }
600  return false;
601  }
602 
604  const xAOD::TruthParticle* initpart = findInitial(part, looping);
605  return MC::Pythia8::isConditionC(initpart);
606  }
607 
609  if(!part->hasProdVtx()) return false;
610  const xAOD::TruthVertex* vertex = part->prodVtx();
611  return HepMC::status(vertex) == 2;
612  }
613 
614  /*
615  --------------------------------------------------------------------------------------------------------------------------------------
616  ---------------------------------------------------------- Particle Parents ----------------------------------------------------------
617  --------------------------------------------------------------------------------------------------------------------------------------
618  */
619 
620  // Define the function isLooping that determines when to stop to look at the parents of a particle.
621  bool HadronOriginClassifier::isLooping(const xAOD::TruthParticle* part, std::shared_ptr<std::set<const xAOD::TruthParticle*>> init_part) const{
622  // First, check if the particle has parents and return false if it does not.
623  if(!part->nParents()) return false;
624  // In this case, the particle has parents.
625  // Store the particle in the container init_part.
626  if (!init_part) init_part = std::make_shared<std::set<const xAOD::TruthParticle*>>();
627  init_part->insert(part);
628  // Use a for to go through the parents.
629  for(unsigned int i=0; i<part->nParents(); ++i){
630  // Get the i-th parent and check if it is in the container init_part.
631  // If it is not, return true because the parent need to be checked.
632  // Otherwise, check the parent of the parent and keep going until there is a parent to check or all parents are checked.
633  const xAOD::TruthParticle* parent = part->parent(i);
634  if(!parent) continue;
635  if( init_part->count(parent)) return true;
636  if( isLooping(parent, init_part) ) return true;
637  }
638  // If this point is reached, then it means that no parent needs to be checked.
639  // Hence, return false.
640  return false;
641  }
642 
643  // Define the function findInitial which finds the first parent of a particle that is not the particle itself.
644  const xAOD::TruthParticle* HadronOriginClassifier::findInitial(const xAOD::TruthParticle* part, bool looping, std::shared_ptr<std::set<const xAOD::TruthParticle*>> checked ) const{
645  // If the particle has no parent, return the particle.
646  if(!part->nParents()) return part;
647  if (!checked) checked = std::make_shared<std::set<const xAOD::TruthParticle*>>();
648  // Use a for to go through the parents.
649  for(unsigned int i=0; i<part->nParents(); ++i){
650  // Extract the i-th parent.
651  const xAOD::TruthParticle* parent = part->parent(i);
652  if(!parent) continue;
653  if(checked->count(parent) && looping) continue;
654  checked->insert(parent);
655  // If the parent has the same pdgId as the particle, then it means that the parent is the same as the considered particle.
656  // This happens if the particle irradiates for example.
657  // In this case, try to look for the first parent of i-th parent that is being considered.
658  // Repeat the process until you find a particle different from the considred one or that has no parent.
659 
660  if( part->pdgId() == parent->pdgId() ){
661  return findInitial(parent, looping, checked);
662  }
663  }
664  // In this case, no parent different from the considered particle has been found.
665  // Hence, return the particle.
666  return part;
667  }
668 
669 }//namespace
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
DerivationFramework::HadronOriginClassifier::isDirectlyMPIPythia8
bool isDirectlyMPIPythia8(const xAOD::TruthParticle *part, bool looping) const
Definition: HadronOriginClassifier.cxx:603
MCTruthPartClassifier::hadron
@ hadron
Definition: TruthClassifiers.h:148
DerivationFramework::HadronOriginClassifier::isFromTop
bool isFromTop(const xAOD::TruthParticle *part, bool looping) const
Definition: HadronOriginClassifier.cxx:409
DerivationFramework::HadronOriginClassifier::isDirectlyMPISherpa
static bool isDirectlyMPISherpa(const xAOD::TruthParticle *part)
Definition: HadronOriginClassifier.cxx:608
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::HadronOriginClassifier::b_FSR
@ b_FSR
Definition: HadronOriginClassifier.h:45
HadronOriginClassifier.h
MC::Pythia8::isConditionC
bool isConditionC(const T &p)
Definition: HepMCHelpers.h:27
DerivationFramework::HadronOriginClassifier::c_FSR
@ c_FSR
Definition: HadronOriginClassifier.h:45
DerivationFramework::HadronOriginClassifier::IsHerwigPP
bool IsHerwigPP() const
Definition: HadronOriginClassifier.h:93
skel.it
it
Definition: skel.GENtoEVGEN.py:396
DerivationFramework::HadronOriginClassifier::GetOriginMap
std::map< const xAOD::TruthParticle *, HF_id > GetOriginMap() const
Definition: HadronOriginClassifier.cxx:159
DerivationFramework::HadronOriginClassifier::HerwigPP
@ HerwigPP
Definition: HadronOriginClassifier.h:50
DerivationFramework::HadronOriginClassifier::c_MPI
@ c_MPI
Definition: HadronOriginClassifier.h:44
DerivationFramework::HadronOriginClassifier::m_HadronEtaMaxCut
double m_HadronEtaMaxCut
Definition: HadronOriginClassifier.h:101
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::HadronOriginClassifier::c_from_W
@ c_from_W
Definition: HadronOriginClassifier.h:46
DerivationFramework::HadronOriginClassifier::isDirectlyFSR
bool isDirectlyFSR(const xAOD::TruthParticle *part, bool looping) const
Definition: HadronOriginClassifier.cxx:498
isBottomHadron
bool isBottomHadron(const T &p)
Definition: AtlasPID.h:509
DerivationFramework::HadronOriginClassifier::isFromGluonQuark
bool isFromGluonQuark(const xAOD::TruthParticle *part, bool looping) const
Definition: HadronOriginClassifier.cxx:473
DerivationFramework::HadronOriginClassifier::c_from_top
@ c_from_top
Definition: HadronOriginClassifier.h:47
isGluon
bool isGluon(const T &p)
Definition: AtlasPID.h:167
DerivationFramework::HadronOriginClassifier::b_from_W
@ b_from_W
Definition: HadronOriginClassifier.h:46
DerivationFramework::HadronOriginClassifier::isFromQuarkTop
bool isFromQuarkTop(const xAOD::TruthParticle *part, bool looping) const
Definition: HadronOriginClassifier.cxx:531
DerivationFramework::HadronOriginClassifier::fillHadronMap
void fillHadronMap(std::set< const xAOD::TruthParticle * > &usedHadron, std::map< const xAOD::TruthParticle *, int > &mainHadronMap, const xAOD::TruthParticle *mainhad, const xAOD::TruthParticle *ihad, bool decayed=false) const
Definition: HadronOriginClassifier.cxx:362
DerivationFramework::HadronOriginClassifier::~HadronOriginClassifier
virtual ~HadronOriginClassifier()
Definition: HadronOriginClassifier.cxx:24
MC::isPhysical
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
Definition: HepMCHelpers.h:51
DerivationFramework::HadronOriginClassifier::IsSherpa
bool IsSherpa() const
Definition: HadronOriginClassifier.h:96
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
DerivationFramework::HadronOriginClassifier::findInitial
const xAOD::TruthParticle * findInitial(const xAOD::TruthParticle *part, bool looping, std::shared_ptr< std::set< const xAOD::TruthParticle * >> checked=nullptr) const
Definition: HadronOriginClassifier.cxx:644
DerivationFramework::HadronOriginClassifier::m_ttbb
bool m_ttbb
Definition: HadronOriginClassifier.h:104
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
DerivationFramework::HadronOriginClassifier::isDirectlyMPIPythia6
static bool isDirectlyMPIPythia6(const xAOD::TruthParticle *part, bool looping)
Definition: HadronOriginClassifier.cxx:592
HepMC::is_simulation_particle
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
Definition: MagicNumbers.h:342
DerivationFramework::HadronOriginClassifier::b_MPI
@ b_MPI
Definition: HadronOriginClassifier.h:44
lumiFormat.i
int i
Definition: lumiFormat.py:85
leadingQuark
int leadingQuark(const T &p)
Definition: AtlasPID.h:487
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DerivationFramework::HadronOriginClassifier::Pythia8
@ Pythia8
Definition: HadronOriginClassifier.h:50
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
DerivationFramework::HadronOriginClassifier::isFromWTop
bool isFromWTop(const xAOD::TruthParticle *part, bool looping) const
Definition: HadronOriginClassifier.cxx:436
DerivationFramework::HadronOriginClassifier::isDirectlyFSRPythia8
bool isDirectlyFSRPythia8(const xAOD::TruthParticle *part, bool looping) const
Definition: HadronOriginClassifier.cxx:538
DerivationFramework::HadronOriginClassifier::m_GenUsed
GEN_id m_GenUsed
Definition: HadronOriginClassifier.h:103
DerivationFramework::HadronOriginClassifier::m_HadronPtMinCut
double m_HadronPtMinCut
Definition: HadronOriginClassifier.h:100
test_pyathena.parent
parent
Definition: test_pyathena.py:15
DerivationFramework::HadronOriginClassifier::isDirectlyFSRPythia6
bool isDirectlyFSRPythia6(const xAOD::TruthParticle *part, bool looping) const
Definition: HadronOriginClassifier.cxx:478
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DerivationFramework::HadronOriginClassifier::Pythia6
@ Pythia6
Definition: HadronOriginClassifier.h:50
DerivationFramework::HadronOriginClassifier::isDirectlyFromGluonQuark
static bool isDirectlyFromGluonQuark(const xAOD::TruthParticle *part, bool looping)
Definition: HadronOriginClassifier.cxx:462
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DerivationFramework::HadronOriginClassifier::HadronOriginClassifier
HadronOriginClassifier(const std::string &t, const std::string &n, const IInterface *p)
Definition: HadronOriginClassifier.cxx:9
DerivationFramework::HadronOriginClassifier::isDirectlyFromQuarkTopPythia8
bool isDirectlyFromQuarkTopPythia8(const xAOD::TruthParticle *part, bool looping) const
Definition: HadronOriginClassifier.cxx:559
DerivationFramework::HadronOriginClassifier::isDirectlyFromQuarkTop
bool isDirectlyFromQuarkTop(const xAOD::TruthParticle *part, bool looping) const
Definition: HadronOriginClassifier.cxx:511
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:37
xAOD::TruthParticle_v1::nChildren
size_t nChildren() const
Number of children of this particle.
Definition: TruthParticle_v1.cxx:140
DerivationFramework::HadronOriginClassifier::isDirectlyFromTop
static bool isDirectlyFromTop(const xAOD::TruthParticle *part, bool looping)
Definition: HadronOriginClassifier.cxx:417
DerivationFramework::HadronOriginClassifier::IsPythia6
bool IsPythia6() const
Definition: HadronOriginClassifier.h:95
python.PyAthena.v
v
Definition: PyAthena.py:154
DerivationFramework::HadronOriginClassifier::IsPythia8
bool IsPythia8() const
Definition: HadronOriginClassifier.h:94
DerivationFramework::HadronOriginClassifier::m_mcName
std::string m_mcName
Definition: HadronOriginClassifier.h:99
isW
bool isW(const T &p)
Definition: AtlasPID.h:176
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
DerivationFramework::HadronOriginClassifier::isDirectlyFromWTop
bool isDirectlyFromWTop(const xAOD::TruthParticle *part, bool looping) const
Definition: HadronOriginClassifier.cxx:443
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DerivationFramework::HadronOriginClassifier::IsTtBb
bool IsTtBb() const
Definition: HadronOriginClassifier.h:97
DerivationFramework::HadronOriginClassifier::isFromQuarkTopPythia8
bool isFromQuarkTopPythia8(const xAOD::TruthParticle *part, bool looping) const
Definition: HadronOriginClassifier.cxx:585
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:21
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
isCharmHadron
bool isCharmHadron(const T &p)
Definition: AtlasPID.h:508
DerivationFramework::HadronOriginClassifier::m_DSID
int m_DSID
Definition: HadronOriginClassifier.h:102
DerivationFramework::HadronOriginClassifier::extrajet
@ extrajet
Definition: HadronOriginClassifier.h:43
AthAlgTool
Definition: AthAlgTool.h:26
HepMC::status
int status(const T &p)
Definition: MagicNumbers.h:125
DerivationFramework::HadronOriginClassifier::buildPartonsHadronsMaps
void buildPartonsHadronsMaps(std::map< const xAOD::TruthParticle *, int > &mainHadronMap, std::map< const xAOD::TruthParticle *, HF_id > &partonsOrigin) const
Definition: HadronOriginClassifier.cxx:227
HepMCHelpers.h
DerivationFramework::HadronOriginClassifier::b_from_top
@ b_from_top
Definition: HadronOriginClassifier.h:47
DerivationFramework::HadronOriginClassifier::isLooping
bool isLooping(const xAOD::TruthParticle *part, std::shared_ptr< std::set< const xAOD::TruthParticle * >> checked=nullptr) const
init_part needed to detect looping graphs (sherpa) up to know only seen at parton level
Definition: HadronOriginClassifier.cxx:621
DerivationFramework::HadronOriginClassifier::Sherpa
@ Sherpa
Definition: HadronOriginClassifier.h:50
DerivationFramework::HadronOriginClassifier::isCHadronFromB
bool isCHadronFromB(const xAOD::TruthParticle *part, std::shared_ptr< std::set< const xAOD::TruthParticle * >> checked=nullptr) const
Definition: HadronOriginClassifier.cxx:340
DerivationFramework::HadronOriginClassifier::initialize
virtual StatusCode initialize() override
Definition: HadronOriginClassifier.cxx:26