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