ATLAS Offline Software
Loading...
Searching...
No Matches
MCTruthClassifierGen.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5/*
6 * Implementation file that mainly contains the code logic
7 * dealing with Truth - record classification
8 * Contributors: Pierre-Antoine Delsart
9 * Andrii Verbytskyi <andrii.verbytskyi@mpp.mpg.de>
10 */
11
13#include "xAODTruth/TruthVertex.h" // must precede DecayProducts.h (its TruthVertex overload is guarded by this header)
15#include "TruthUtils/Loops.h"
20
21// Helpers used only in this file (internal linkage).
22static ParticleOrigin defOrigOfElectron(const xAOD::TruthParticleContainer& xTruthParticleContainer, const xAOD::TruthParticle* thePart, bool& isPrompt, ParticleOutCome& outCome);
23static ParticleOrigin defOrigOfMuon(const xAOD::TruthParticleContainer& xTruthParticleContainer, const xAOD::TruthParticle* thePart, bool& isPrompt, ParticleOutCome& outCome);
24static ParticleOrigin defOrigOfTau(const xAOD::TruthParticleContainer& xTruthParticleContainer, const xAOD::TruthParticle* thePart, int ancestorPDGin, ParticleOutCome& outCome);
25static ParticleOrigin defOrigOfPhoton(const xAOD::TruthParticleContainer& xTruthParticleContainer, const xAOD::TruthParticle* thePart, bool& isPrompt, ParticleOutCome& outCome);
26static ParticleOrigin defOrigOfNeutrino(const xAOD::TruthParticleContainer& xTruthParticleContainer, const xAOD::TruthParticle* thePart, bool& isPrompt, ParticleOutCome& outCome);
27
28std::pair<ParticleType, ParticleOrigin>
30 const xAOD::TruthParticle* const thePart,
31 ParticleOutCome& outCome) {
32 ParticleType partType = Unknown;
33 ParticleOrigin partOrig = NonDefined;
34
35 if (!MC::isStable(thePart) && !MC::isDecayed(thePart)) {
36 return std::make_pair(GenParticle, partOrig);
37 }
38 const bool isPartHadr = MC::isHadron(thePart) && !MC::isBeam(thePart);
39 if (MC::isDecayed(thePart) && (!MC::isTau(thePart) && !isPartHadr)) return std::make_pair(GenParticle, partOrig);
40
41 // SUSY datasets: tau(status==2)->tau(status==2)
42 if (MC::isDecayed(thePart) && MC::isTau(thePart)) {
43 const xAOD::TruthVertex* endVert = thePart->decayVtx();
44 if (endVert) {
45 if (endVert->nOutgoingParticles() == 1 && MC::isTau(endVert->outgoingParticle(0))) {
46 return std::make_pair(GenParticle, partOrig);
47 }
48 }
49 }
50
51 if (MC::isStable(thePart) && MC::isSUSY(thePart)) return std::make_pair(SUSYParticle, partOrig);
52
53 if (MC::isStable(thePart) && MC::isBSM(thePart)) return std::make_pair(OtherBSMParticle, partOrig);
54
55 if (MC::isDecayed(thePart) &&
56 (!MC::isElectron(thePart) && !MC::isMuon(thePart) &&
57 !MC::isTau(thePart) && !MC::isPhoton(thePart)) &&
58 !isPartHadr)
59 return std::make_pair(GenParticle, partOrig);
60
61 // FIXME vetoing protons here to preserve previous behaviour
62 if (MC::isNucleus(thePart) && std::abs(thePart->pdgId()) != MC::PROTON) return std::make_pair(NuclFrag, partOrig);
63
64 if ( !MC::isSMLepton(thePart) && !MC::isPhoton(thePart) && !isPartHadr) return std::make_pair(partType, partOrig);
65 // don't consider generator particles
66
67 const xAOD::TruthVertex* partProdVtx = thePart->hasProdVtx() ? thePart->prodVtx() : nullptr;
68
69 const xAOD::TruthParticle* parent{};
70 if (partProdVtx) {
71 for (const auto& temp: partProdVtx->particles_in()) {if (temp) parent = temp;}
72 }
73 const int parentPDG = parent?parent->pdg_id():0;
74
75 if (!partProdVtx && HepMC::is_simulation_particle(thePart)) {
76 return std::make_pair(NonPrimary, partOrig);
77 }
78 if (!partProdVtx && MC::isElectron(thePart)) {
79 // to define electron outcome status
80 bool isPrompt = false; // updated by defOrigOfElectron
81 partOrig = defOrigOfElectron(truthParticleContainer, thePart, isPrompt, outCome);
82 return std::make_pair(UnknownElectron, partOrig);
83 }
84 if (!partProdVtx && MC::isMuon(thePart)) {
85 // to define electron outcome status
86 bool isPrompt = false; // updated by defOrigOfMuon
87 partOrig = defOrigOfMuon(truthParticleContainer, thePart, isPrompt, outCome);
88 return std::make_pair(UnknownMuon, partOrig);
89 }
90 if (!partProdVtx && MC::isTau(thePart)) {
91 // to define electron outcome status
92 partOrig = defOrigOfTau(truthParticleContainer, thePart, parentPDG, outCome);
93 return std::make_pair(UnknownTau, partOrig);
94 }
95 if (!partProdVtx && MC::isPhoton(thePart)) {
96 // to define photon outcome
97 bool isPrompt = false; // updated by defOrigOfPhoton
98 partOrig = defOrigOfPhoton(truthParticleContainer, thePart, isPrompt, outCome);
99 return std::make_pair(UnknownPhoton, partOrig);
100 }
101 if (!partProdVtx && MC::isNeutrino(thePart)) {
102 // to define neutrino outcome
103 outCome = NonInteract;
104 return std::make_pair(Neutrino, partOrig);
105 }
106
107 if (parent && HepMC::is_same_generator_particle(thePart, parent))
108 return std::make_pair(NonPrimary, partOrig);
109
110 if (isPartHadr) return std::make_pair(Hadron, partOrig);
111
112 if (partProdVtx && parentPDG == 0 && partProdVtx->nOutgoingParticles() == 1 &&
113 partProdVtx->nIncomingParticles() == 0) {
114 if (MC::isElectron(thePart)) {
115 outCome = defOutComeOfElectron(thePart);
116 return std::make_pair(IsoElectron, SingleElec);
117 }
118 if (MC::isMuon(thePart)) {
119 outCome = defOutComeOfMuon(thePart);
120 return std::make_pair(IsoMuon, SingleMuon);
121 }
122 if (MC::isTau(thePart)) {
123 outCome = defOutComeOfTau(thePart);
124 return std::make_pair(IsoTau, SingleTau);
125 }
126 if (MC::isPhoton(thePart)) {
127 outCome = defOutComeOfPhoton(thePart);
128 return std::make_pair(IsoPhoton, SinglePhot);
129 }
130 }
131
132 if (parentPDG == thePart->pdg_id() && parent && parent->status() == 3 && MC::isDecayed(thePart)) return std::make_pair(GenParticle, partOrig);
133
134 if (MC::isElectron(thePart)) {
135 bool isPrompt = false; // updated by defOrigOfElectron
136 partOrig = defOrigOfElectron(truthParticleContainer, thePart, isPrompt, outCome);
137 partType = defTypeOfElectron(partOrig, isPrompt);
138 } else if (MC::isMuon(thePart)) {
139 bool isPrompt = false; // updated by defOrigOfMuon
140 partOrig = defOrigOfMuon(truthParticleContainer, thePart, isPrompt, outCome);
141 partType = defTypeOfMuon(partOrig, isPrompt);
142 } else if (MC::isTau(thePart)) {
143 partOrig = defOrigOfTau(truthParticleContainer, thePart, parentPDG, outCome);
144 partType = defTypeOfTau(partOrig);
145 } else if (MC::isPhoton(thePart)) {
146 bool isPrompt = false; // updated by defOrigOfPhoton
147 partOrig = defOrigOfPhoton(truthParticleContainer, thePart, isPrompt, outCome);
148 partType = defTypeOfPhoton(partOrig);
149 } else if (MC::isNeutrino(thePart)) {
150 bool isPrompt = false; // updated by defOrigOfNeutrino
151 partOrig = defOrigOfNeutrino(truthParticleContainer, thePart, isPrompt, outCome);
152 partType = Neutrino;
153 }
154
155 // particleTruthClassifier succeeded
156 return std::make_pair(partType, partOrig);
157}
158
160 const xAOD::TruthParticle* thePart,
161 bool& isPrompt,
162 ParticleOutCome& outCome)
163{
164 // Executing DefOrigOfElectron
165
166 // Find the first copy of this particle stored in the xAOD::TruthParticleContainer (i.e. the particle prior to any interactions)
167 const xAOD::TruthParticle* thePriPart = MC::findMatching(xTruthParticleContainer, thePart);
168 if (!thePriPart) return NonDefined;
169 if (!MC::isElectron(thePriPart)) return NonDefined;
170
171 //-- to define electron outcome status
172 outCome = defOutComeOfElectron(thePriPart);
173
174 const xAOD::TruthVertex* partProdVtx = thePriPart->hasProdVtx() ? thePriPart->prodVtx() : nullptr;
175 if (!partProdVtx) return NonDefined;
176
177
178 const xAOD::TruthParticle* ancestor = MC::findMother(thePriPart);
179 if (!ancestor) { return NonDefined; } // After this point "ancestor" cannot be nullptr
180
181 // Start of method 1 of protecting against loops
182 bool samePart = MC::TruthLoopDetectionMethod1(partProdVtx, ancestor);
183 // to resolve Sherpa loop
184 // End of method 1 of protecting against loops
185
186 if ((MC::isMuon(ancestor) || MC::isTau(ancestor) || MC::isW(ancestor)) && ancestor->hasProdVtx() && !samePart) {
187 int pPDG(0);
188 const xAOD::TruthParticle* ancestorParent{};
189 do {
190 pPDG = 0; // reset pPDG
191 ancestorParent = MC::findMother(ancestor);
192 // Start of method 2 of protecting against loops
193 // to prevent Sherpa loop
194 if (ancestor == ancestorParent) { break; }
195 if (MC::TruthLoopDetectionMethod2(ancestor,ancestorParent)) {
196 ancestorParent = ancestor;
197 break;
198 }
199 // End of method 2 of protecting against loops
200 // FIXME why are slightly different criteria used in method 1 and method 2???
201 if (ancestorParent) {
202 pPDG = ancestorParent->pdgId(); // Only set pPDG in the case that we aren't in a loop.
203 if (MC::isMuon(pPDG) || MC::isTau(pPDG) || MC::isW(pPDG)) { // There will be another iteration so set ancestor to ancestorParent
204 ancestor = ancestorParent; // ancestorParent is not nullptr here
205 }
206 }
207 } while ((MC::isMuon(pPDG) || MC::isTau(pPDG) || MC::isW(pPDG)));
208
209 if (MC::isMuon(pPDG) || MC::isTau(pPDG) || MC::isW(pPDG) || MC::isZ(pPDG) || MC::isHiggs(pPDG) ||
210 MC::isMSSMHiggs(pPDG) || MC::isHeavyBoson(pPDG) || MC::isTop(pPDG) || // MSSM Higgs bosons, Heavy bosons( Z', Z'', W'+)
211 std::abs(pPDG) == MC::WBOSON_LRSM || MC::isNeutrinoRH(pPDG) || // Left-right symmetric model WBoson || Right-handed neutrino (Pythia-specific)
212 MC::isSUSY(pPDG)) {
213 ancestor = ancestorParent; // ancestorParent is not nullptr here
214 }
215 }
216
217 const int ancestorPDG = ancestor->pdgId();
218 const xAOD::TruthVertex* ancestorProdVtx = ancestor->hasProdVtx() ? ancestor->prodVtx() : nullptr;
219 partProdVtx = ancestor->decayVtx();
220 const int numOfParents = partProdVtx->nIncomingParticles();
221 const int numberOfChildren = partProdVtx->nOutgoingParticles();
222
223 // Determine decay products
224 auto DP = DecayProducts(partProdVtx);
225 const int NumOfPhot = DP.pd(MC::PHOTON);
226 const int NumOfEl = DP.pd(MC::ELECTRON);
227 const int NumOfPos = DP.pd(MC::POSITRON);
228 const int NumOfquark = DP.apd({MC::DQUARK,MC::UQUARK,MC::SQUARK,MC::CQUARK,MC::BQUARK,MC::TQUARK});
229 const int NumOfgluon = DP.apd(MC::GLUON);
230 const int NumOfElNeut = DP.apd(MC::NU_E);
231 const int NumOfLQ = DP.apd(MC::LEPTOQUARK);
232 const int NumOfMuPl = DP.pd(-MC::MUON);
233 const int NumOfMuMin = DP.pd(MC::MUON);
234 const int NumOfMuNeut = DP.apd(MC::NU_MU);
235 const int NumOfTau = DP.apd(MC::TAU);
236 const int NumOfTauNeut = DP.apd(MC::NU_TAU);
237
238 samePart = false;
239 int NumOfNucFr(0);
240 const bool possibleNuclearFragment = (numOfParents == 1 && (MC::isPhoton(ancestorPDG) || MC::isElectron(ancestorPDG) || MC::isMuon(ancestorPDG) || std::abs(ancestorPDG) == MC::PIPLUS));
241 for (const auto& aChild: partProdVtx->particles_out()) {
242 if (!aChild) continue;
243 const int childPDG = aChild->pdgId();
244 if (std::abs(childPDG) == std::abs(ancestorPDG) && HepMC::is_same_generator_particle(aChild, ancestor )) samePart = true;
245 if (possibleNuclearFragment &&
246 (MC::isNucleus(childPDG) || childPDG == 0 || childPDG == MC::PROTON || childPDG == MC::NEUTRON || // FIXME Do we really expect particles with PDG_ID = 0 in the truth record?
247 std::abs(childPDG) == MC::PIPLUS || std::abs(childPDG) == MC::PI0))
248 NumOfNucFr++;
249 }
250 // End of section determining decay products
251
252 if ((MC::isPhoton(ancestorPDG) && numberOfChildren == 2 && NumOfEl == 1 && NumOfPos == 1) || (MC::isPhoton(ancestorPDG) && numberOfChildren == 1 && (NumOfEl == 1 || NumOfPos == 1))) return PhotonConv;
253
254 // e,gamma,pi+Nuclear->NuclearFragments+nuclons+e
255 if ((numOfParents == 1 && (MC::isPhoton(ancestorPDG) || MC::isElectron(ancestorPDG) || MC::isTau(ancestorPDG))) && numberOfChildren > 1 && NumOfNucFr != 0) return ElMagProc;
256
257 if (numOfParents == 1 && std::abs(ancestorPDG) == MC::PIPLUS && numberOfChildren > 2 && NumOfNucFr != 0) return ElMagProc;
258
259 // nuclear photo fission
260 if (MC::isPhoton(ancestorPDG) && numberOfChildren > 4 && NumOfNucFr != 0) return ElMagProc;
261
262 // unknown process el(pos)->el+pos??
263 if (MC::isElectron(ancestorPDG) && numberOfChildren == 2 && NumOfEl == 1 && NumOfPos == 1) return ElMagProc;
264
265 // unknown process el->el+el??
266 if (ancestorPDG == MC::ELECTRON && numberOfChildren == 2 && NumOfEl == 2 && NumOfPos == 0) return ElMagProc;
267
268 // unknown process pos->pos+pos??
269 if (ancestorPDG == MC::POSITRON && numberOfChildren == 2 && NumOfEl == 0 && NumOfPos == 2) return ElMagProc;
270
271 // unknown process pos/el->pos/el??
272 if (MC::isElectron(ancestorPDG) && !MC::isDecayed(ancestor) && ancestorPDG == thePriPart->pdgId() && numberOfChildren == 1 && !samePart) return ElMagProc;
273
274 // pi->pi+e+/e-; mu->mu+e+/e- ;
275 // gamma+ atom->gamma(the same) + e (compton scattering)
276 if (numberOfChildren == 2 && (NumOfEl == 1 || NumOfPos == 1) && !MC::isElectron(ancestorPDG) && samePart) return ElMagProc;
277
278 if ((ancestorPDG == MC::PI0 && numberOfChildren == 3 && NumOfPhot == 1 && NumOfEl == 1 && NumOfPos == 1) ||
279 (ancestorPDG == MC::PI0 && numberOfChildren == 4 && NumOfPhot == 0 && NumOfEl == 2 && NumOfPos == 2))
280 return DalitzDec;
281
282 // Quark weak decay
283 if (MC::isSMQuark(ancestorPDG) && numOfParents == 1 && numberOfChildren == 3 && NumOfquark == 1 && NumOfElNeut == 1) return QuarkWeakDec;
284
285 if (MC::isMuon(ancestorPDG) && NumOfNucFr != 0) return ElMagProc;
286
287 if (MC::isTop(ancestorPDG)) return top;
288
289 if (MC::isW(ancestorPDG) && ancestorProdVtx && ancestorProdVtx->nIncomingParticles() != 0) {
290
291 const xAOD::TruthVertex* prodVert = ancestorProdVtx;
292 const xAOD::TruthParticle* ptrPart{};
293 do {
294 ptrPart = prodVert->incomingParticle(0); // FIXME just taking the first one
295 prodVert = ptrPart->hasProdVtx() ? ptrPart->prodVtx() : nullptr;
296 } while (MC::isW(ptrPart) && prodVert);
297
298 if (prodVert && prodVert->nIncomingParticles() == 1) {
299 if (std::abs(ptrPart->pdgId()) == MC::RH_NU_E) return NuREle; // Right-handed NU_E (Pythia-specific)
300 if (std::abs(ptrPart->pdgId()) == MC::RH_NU_MU) return NuRMu; // Right-handed NU_MU (Pythia-specific)
301 if (std::abs(ptrPart->pdgId()) == MC::RH_NU_TAU) return NuRTau; // Right-handed NU_TAU (Pythia-specific)
302 }
303 return WBoson;
304 }
305 if (MC::isW(ancestorPDG)) return WBoson;
306 if (MC::isZ(ancestorPDG)) return ZBoson;
307
308 // MadGraphPythia ZWW*->lllnulnu
309 if (numOfParents == 1 && numberOfChildren > 4 && (MC::isSMQuark(ancestorPDG) || MC::isGluon(ancestorPDG))) {
310
311 const xAOD::TruthParticle* thePartToCheck = thePriPart;
312 const xAOD::TruthParticle* theParent = thePriPart->hasProdVtx() ? thePriPart->prodVtx()->incomingParticle(0) : nullptr; // FIXME just taking the first one
313 if (theParent && MC::isElectron(theParent) && MC::isDecayed(theParent)) { thePartToCheck = theParent; }
314
315 bool isZboson = false;
316 bool isWboson = false;
317 bool skipnext = false;
318
319 for (unsigned int ipOut = 0; ipOut + 1 < partProdVtx->nOutgoingParticles(); ++ipOut) {
320 const xAOD::TruthParticle* aChild = partProdVtx->outgoingParticle(ipOut);
321 if (!aChild) continue;
322 const xAOD::TruthParticle* theNextChild = nullptr;
323 for (unsigned int ipOut1 = ipOut + 1; ipOut1 < partProdVtx->nOutgoingParticles(); ipOut1++) {
324 theNextChild = partProdVtx->outgoingParticle(ipOut1);
325 if (theNextChild) break;
326 }
327 if (!theNextChild) continue;
328 if (skipnext) {
329 skipnext = false;
330 continue;
331 }
332
333 if (MC::isElectron(aChild) && MC::isElectron(theNextChild)) {
334 // Zboson
335 if (thePartToCheck == aChild || thePartToCheck == theNextChild) {
336 isZboson = true;
337 break;
338 }
339 skipnext = true;
340 } else if (MC::isElectron(aChild) && std::abs(theNextChild->pdgId()) == MC::NU_E) {
341 // WBoson
342 if (thePartToCheck == aChild || thePartToCheck == theNextChild) {
343 isWboson = true;
344 break;
345 }
346 skipnext = true;
347 }
348 }
349 if (isWboson) return WBoson;
350 if (isZboson) return ZBoson;
351 }
352 if (numOfParents == 2) {
353 //--Sherpa Z->ee
354 if ((numberOfChildren - NumOfquark - NumOfgluon) == 2 && NumOfEl == 1 && NumOfPos == 1) return ZBoson;
355
356 //--Sherpa W->enu ??
357 if ((numberOfChildren - NumOfquark - NumOfgluon) == 2 && (NumOfEl == 1 || NumOfPos == 1) && NumOfElNeut == 1) return WBoson;
358
359 const int pdg1 = partProdVtx->incomingParticle(0)->pdgId();
360 const int pdg2 = partProdVtx->incomingParticle(1)->pdgId();
361 //--Sherpa ZZ,ZW
362 if ((numberOfChildren - NumOfquark - NumOfgluon) == 4 &&
363 (NumOfEl + NumOfPos + NumOfMuPl + NumOfMuMin + NumOfTau + NumOfElNeut + NumOfMuNeut + NumOfTauNeut == 4) &&
364 (MC::isQuark(pdg1)||MC::isGluon(pdg1)) && (MC::isQuark(pdg2)||MC::isGluon(pdg2))) return DiBoson;
365
366 //--Sherpa VVV -- Note, have to allow for prompt photon radiation or these get lost
367 if ((numberOfChildren - NumOfquark - NumOfgluon - NumOfPhot) == 6 &&
368 (NumOfEl + NumOfPos + NumOfMuPl + NumOfMuMin + NumOfTau + NumOfElNeut + NumOfMuNeut + NumOfTauNeut == 6) &&
369 (MC::isQuark(pdg1)||MC::isGluon(pdg1)) && (MC::isQuark(pdg2)||MC::isGluon(pdg2))) return MultiBoson;
370
371 //--Sherpa tttt with all t->Wb; W->lnu
372 if ((numberOfChildren - NumOfquark - NumOfgluon) == 8 &&
373 (NumOfEl + NumOfPos + NumOfMuPl + NumOfMuMin + NumOfTau + NumOfElNeut + NumOfMuNeut + NumOfTauNeut == 8) &&
374 (MC::isQuark(pdg1)||MC::isGluon(pdg1)) && (MC::isQuark(pdg2)||MC::isGluon(pdg2))) {
375 // MultiBoson for 4topLep
376 return MultiBoson;
377 }
378
379 //--Sherpa Vgamma ( Z->ee+gamma or W->enu+gamma )
380 if ((numberOfChildren - NumOfquark - NumOfgluon) >= 3 && NumOfPhot >= 1 && NumOfEl == 1 && NumOfPos == 1) {
381 // Sherpa ee + gamma
382 return ZBoson;
383 }
384 if ((numberOfChildren - NumOfquark - NumOfgluon) >= 3 && NumOfPhot >= 1 && (NumOfEl == 1 || NumOfPos == 1) && NumOfElNeut == 1) {
385 // Sherpa enu + gamma
386 return WBoson;
387 }
388 }
389
390 // New Sherpa Z->ee
391 if (partProdVtx == ancestorProdVtx) {
392 int NumOfEleLoop = 0;
393 int NumOfLepLoop = 0;
394 int NumOfEleNeuLoop = 0;
395 for (const auto *const pout: partProdVtx->particles_out()) {
396 if (!pout) continue;
397 for (const auto *const pin: partProdVtx->particles_in()) {
398 if (!pin) continue;
399 if (!HepMC::is_same_particle(pout,pin)) continue;
400 if (MC::isElectron(pout)) NumOfEleLoop++;
401 if (std::abs(pout->pdgId()) == MC::NU_E) NumOfEleNeuLoop++;
402 if (MC::isSMLepton(pout)) NumOfLepLoop++;
403 break; // break out of inner loop after having found two matching particles
404 }
405 }
406 if (NumOfEleLoop == 2 && NumOfEleNeuLoop == 0) return ZBoson;
407 if (NumOfEleLoop == 1 && NumOfEleNeuLoop == 1) return WBoson;
408 if ((NumOfEleLoop == 4 && NumOfEleNeuLoop == 0) || (NumOfEleLoop == 3 && NumOfEleNeuLoop == 1) ||
409 (NumOfEleLoop == 2 && NumOfEleNeuLoop == 2)) return DiBoson;
410 if (NumOfLepLoop == 4) return DiBoson;
411 }
412
413 //-- McAtNLo
414
415 if (MC::isHiggs(ancestorPDG)) return Higgs;
416
417 if (MC::isMSSMHiggs(ancestorPDG)) return HiggsMSSM; // MSSM Higgs bosons
418
419 if (MC::isHeavyBoson(ancestorPDG)) return HeavyBoson; // Heavy bosons( Z', Z'', W'+)
420
421 if (MC::isMuon(ancestorPDG)) return Mu;
422 if (MC::isTau(ancestorPDG)) {
423 const ParticleOrigin tauOrig = defOrigOfTau(xTruthParticleContainer, ancestor, ancestorPDG, outCome);
424 const ParticleType tautype = defTypeOfTau(tauOrig);
425 return (tautype == IsoTau)?tauOrig:TauLep;
426 }
427
428 if (std::abs(ancestorPDG) == MC::WBOSON_LRSM) return WBosonLRSM; // Left-right symmetric model WBoson (Pythia-specific)
429 if (std::abs(ancestorPDG) == MC::RH_NU_E) return NuREle; // Right-handed NU_E (Pythia-specific)
430 if (std::abs(ancestorPDG) == MC::RH_NU_MU) return NuRMu; // Right-handed NU_MU (Pythia-specific)
431 if (std::abs(ancestorPDG) == MC::RH_NU_TAU) return NuRTau; // Right-handed NU_TAU (Pythia-specific)
432 if (MC::isLeptoQuark(ancestorPDG) || NumOfLQ != 0) return LQ;
433 if (MC::isSUSY(ancestorPDG)) return SUSY;
434 if (MC::isBSM(ancestorPDG)) return OtherBSM;
435
436 const ParticleType pType = defTypeOfHadron(ancestorPDG);
437 if ((pType == BBbarMesonPart || pType == CCbarMesonPart) && ancestorProdVtx && MC::isHardScatteringVertex(ancestorProdVtx)) isPrompt = true;
438 return convHadronTypeToOrig(pType, ancestorPDG);
439}
440
441
443 const xAOD::TruthParticle* thePart,
444 bool& isPrompt,
445 ParticleOutCome& outCome)
446{
447 // Executing DefOrigOfMuon
448
449 // Find the first copy of this particle stored in the xAOD::TruthParticleContainer (i.e. the particle prior to any interactions)
450 const xAOD::TruthParticle* thePriPart = MC::findMatching(xTruthParticleContainer, thePart);
451 if (!thePriPart) return NonDefined;
452 if (!MC::isMuon(thePriPart)) return NonDefined;
453
454 //-- to define muon outcome status
455 outCome = defOutComeOfMuon(thePriPart);
456
457 const xAOD::TruthVertex* partProdVtx = thePriPart->hasProdVtx() ? thePriPart->prodVtx() : nullptr;
458 if (!partProdVtx) return NonDefined;
459
460
461 const xAOD::TruthParticle* ancestor = MC::findMother(thePriPart);
462 if (!ancestor) { return NonDefined; } // ancestor is not a nullptr beyond this point
463
464 // "method 1" for finding Sherpa loops from defOrigOfElectron not used here. Why?
465
466 if ((MC::isTau(ancestor)|| MC::isW(ancestor)) && ancestor->hasProdVtx()) {
467 int pPDG(0);
468 const xAOD::TruthParticle* ancestorParent{};
469 do {
470 pPDG = 0;
471 ancestorParent = MC::findMother(ancestor);
472 // Start of method 2 of protecting against loops
473 // to prevent Sherpa loop
474 if (ancestor == ancestorParent) { break; }
475 if (MC::TruthLoopDetectionMethod2(ancestor,ancestorParent)) {
476 ancestorParent = ancestor;
477 break;
478 }
479 // End of method 2 of protecting against loops
480
481 if (ancestorParent) {
482 pPDG = ancestorParent->pdgId();// Only set pPDG in the case that we aren't in a loop.
483 if (MC::isMuon(pPDG) || MC::isTau(pPDG) || MC::isW(pPDG)) { // FIXME should this be (MC::isTau(pPDG) || MC::isW(pPDG)) ???
484 // There will be another iteration so set ancestor to ancestorParent
485 ancestor = ancestorParent; // ancestorParent is not nullptr here
486 }
487 }
488 } while ((MC::isMuon(pPDG) || MC::isTau(pPDG) || MC::isW(pPDG))); // FIXME should this be (MC::isTau(pPDG) || MC::isW(pPDG)) ???
489
490 if (MC::isTau(pPDG) || MC::isW(pPDG) || MC::isZ(pPDG) || MC::isHiggs(pPDG) ||
491 MC::isMSSMHiggs(pPDG) || MC::isHeavyBoson(pPDG) || MC::isTop(pPDG) || // MSSM Higgs bosons, Heavy bosons( Z', Z'', W'+)
492 std::abs(pPDG) == MC::WBOSON_LRSM || MC::isNeutrinoRH(pPDG) || // Left-right symmetric model WBoson || Right-handed neutrino (Pythia-specific)
493 MC::isSUSY(pPDG)) {
494 ancestor = ancestorParent; // ancestorParent is not nullptr here
495 }
496 }
497
498 const int ancestorPDG = ancestor->pdgId();
499 const xAOD::TruthVertex* ancestorProdVtx = ancestor->hasProdVtx() ? ancestor->prodVtx() : nullptr;
500 partProdVtx = ancestor->decayVtx();
501 const int numOfParents = partProdVtx->nIncomingParticles();
502 const int numberOfChildren = partProdVtx->nOutgoingParticles();
503
504 // Determine decay products
505 auto DP = DecayProducts(partProdVtx);
506 const int NumOfPhot = DP.pd(MC::PHOTON);
507 const int NumOfEl = DP.pd(MC::ELECTRON);
508 const int NumOfPos = DP.pd(MC::POSITRON);
509 const int NumOfElNeut = DP.apd(MC::NU_E);
510 const int NumOfMuNeut = DP.apd(MC::NU_MU);
511 const int NumOfLQ = DP.apd(MC::LEPTOQUARK);
512 const int NumOfquark = DP.apd({MC::DQUARK,MC::UQUARK,MC::SQUARK,MC::CQUARK,MC::BQUARK,MC::TQUARK});
513 const int NumOfgluon = DP.apd(MC::GLUON);
514 const int NumOfMuPl = DP.pd(-MC::MUON);
515 const int NumOfMuMin = DP.pd(MC::MUON);
516 const int NumOfTau = DP.apd(MC::TAU);
517 const int NumOfTauNeut = DP.apd(MC::NU_TAU);
518 // End of section determining decay products
519
520 if (std::abs(ancestorPDG) == MC::PIPLUS && numberOfChildren == 2 && NumOfMuNeut == 1) return PionDecay;
521 if (std::abs(ancestorPDG) == MC::KPLUS && numberOfChildren == 2 && NumOfMuNeut == 1) return KaonDecay;
522 if (MC::isTau(ancestorPDG)) {
523 const ParticleOrigin tauOrig = defOrigOfTau(xTruthParticleContainer, ancestor, ancestorPDG, outCome);
524 const ParticleType tautype = defTypeOfTau(tauOrig);
525 return (tautype == IsoTau)?tauOrig:TauLep;
526 }
527
528 if (MC::isTop(ancestorPDG)) return top;
529 // Quark weak decay
530 if (MC::isSMQuark(ancestorPDG) && numOfParents == 1 && numberOfChildren == 3 && NumOfquark == 1 && NumOfMuNeut == 1) return QuarkWeakDec;
531
532 if (MC::isW(ancestorPDG) && ancestorProdVtx && ancestorProdVtx->nIncomingParticles() != 0) {
533 const xAOD::TruthVertex* prodVert = ancestorProdVtx;
534 const xAOD::TruthParticle* itrP;
535 do {
536 itrP = prodVert->incomingParticle(0); // FIXME just taking the first one
537 prodVert = itrP->hasProdVtx() ? itrP->prodVtx() : nullptr;
538 } while (MC::isW(itrP) && prodVert);
539
540 if (prodVert && prodVert->nIncomingParticles() == 1) {
541 if (std::abs(itrP->pdgId()) == MC::RH_NU_E) return NuREle; // Right-handed NU_E (Pythia-specific)
542 if (std::abs(itrP->pdgId()) == MC::RH_NU_MU) return NuRMu; // Right-handed NU_MU (Pythia-specific)
543 if (std::abs(itrP->pdgId()) == MC::RH_NU_TAU) return NuRTau; // Right-handed NU_TAU (Pythia-specific)
544 }
545 return WBoson;
546 }
547 if (MC::isW(ancestorPDG)) return WBoson;
548 if (MC::isZ(ancestorPDG)) return ZBoson;
549 if (MC::isPhoton(ancestorPDG) && numberOfChildren == 2 && NumOfMuMin == 1 && NumOfMuPl == 1) return PhotonConv;
550 //-- Exotics
551
552 // MadGraphPythia ZWW*->lllnulnu
553 if (numOfParents == 1 && numberOfChildren > 4 && (MC::isSMQuark(ancestorPDG) || MC::isGluon(ancestorPDG))) {
554 bool isZboson = false;
555 bool isWboson = false;
556 bool skipnext = false;
557 for (unsigned int ipOut = 0; ipOut + 1 < partProdVtx->nOutgoingParticles(); ipOut++) {
558 if (skipnext) {
559 skipnext = false;
560 continue;
561 }
562 const xAOD::TruthParticle* aChild = partProdVtx->outgoingParticle(ipOut);
563 if (!aChild) continue;
564 const xAOD::TruthParticle* theNextChild{};
565 for (unsigned int ipOut1 = ipOut + 1; ipOut1 < partProdVtx->nOutgoingParticles(); ipOut1++) {
566 theNextChild = partProdVtx->outgoingParticle(ipOut1);
567 if (theNextChild) break;
568 }
569 if (!theNextChild) continue;
570 if (MC::isMuon(aChild) && MC::isMuon(theNextChild)) {
571 // Zboson
572 if (thePriPart == aChild || thePriPart == theNextChild) {
573 isZboson = true;
574 break;
575 }
576 skipnext = true;
577 } else if (MC::isMuon(aChild) && std::abs(theNextChild->pdgId()) == MC::NU_MU) {
578 // WBoson
579 if (thePriPart == aChild || thePriPart == theNextChild) {
580 isWboson = true;
581 break;
582 }
583 skipnext = true;
584 }
585 }
586 if (isWboson) return WBoson;
587 if (isZboson) return ZBoson;
588 }
589 if (numOfParents == 2 ) {
590 //--Sherpa Z->mumu
591 if ((numberOfChildren - NumOfquark - NumOfgluon) == 2 && NumOfMuPl == 1 && NumOfMuMin == 1) return ZBoson;
592
593 //--Sherpa W->munu ??
594 // if(numOfParents==2&&(numberOfChildren-NumOfquark-NumOfgluon)==2&&(NumOfEl==1||NumOfPos==1)&&NumOfElNeut==1) return WBoson;
595 if ((numberOfChildren - NumOfquark - NumOfgluon) == 2 && (NumOfMuPl == 1 || NumOfMuMin == 1) && NumOfMuNeut == 1) return WBoson;
596
597 const int pdg1 = partProdVtx->incomingParticle(0)->pdgId();
598 const int pdg2 = partProdVtx->incomingParticle(1)->pdgId();
599 //--Sherpa ZZ,ZW
600 if ((numberOfChildren - NumOfquark - NumOfgluon) == 4 &&
601 (NumOfEl + NumOfPos + NumOfMuPl + NumOfMuMin + NumOfTau + NumOfElNeut + NumOfMuNeut + NumOfTauNeut == 4) &&
602 (MC::isQuark(pdg1)||MC::isGluon(pdg1)) && (MC::isQuark(pdg2)||MC::isGluon(pdg2))) return DiBoson;
603
604 //--Sherpa VVV -- Note, have to allow for prompt photon radiation or these get lost
605 if ((numberOfChildren - NumOfquark - NumOfgluon - NumOfPhot) == 6 &&
606 (NumOfEl + NumOfPos + NumOfMuPl + NumOfMuMin + NumOfTau + NumOfElNeut + NumOfMuNeut + NumOfTauNeut == 6) &&
607 (MC::isQuark(pdg1)||MC::isGluon(pdg1)) && (MC::isQuark(pdg2)||MC::isGluon(pdg2))) return MultiBoson;
608
609 //--Sherpa tttt with all t->Wb; W->lnu
610 if ((numberOfChildren - NumOfquark - NumOfgluon) == 8 &&
611 (NumOfEl + NumOfPos + NumOfMuPl + NumOfMuMin + NumOfTau + NumOfElNeut + NumOfMuNeut + NumOfTauNeut == 8) &&
612 (MC::isQuark(pdg1)||MC::isGluon(pdg1)) && (MC::isQuark(pdg2)||MC::isGluon(pdg2))) {
613 // MultiBoson for 4topLep
614 return MultiBoson;
615 }
616
617 //--Sherpa Vgamma ( Z->ee+gamma or W->enu+gamma )
618 if ((numberOfChildren - NumOfquark - NumOfgluon) >= 3 && NumOfPhot >= 1 && NumOfMuPl == 1 && NumOfMuMin == 1) {
619 // Sherpa mumu + gamma
620 return ZBoson;
621 }
622 if ((numberOfChildren - NumOfquark - NumOfgluon) >= 3 && NumOfPhot >= 1 && (NumOfMuPl == 1 || NumOfMuMin == 1) && NumOfMuNeut == 1) {
623 // Sherpa munu + gamma
624 return WBoson;
625 }
626
627 }
628
629 //--New Sherpa Z->mumu
630 if (partProdVtx == ancestorProdVtx) {
631 int NumOfMuLoop = 0;
632 int NumOfMuNeuLoop = 0;
633 int NumOfLepLoop = 0;
634 for (const auto & pout: partProdVtx->particles_out()) {
635 if (!pout) continue;
636 for (const auto & pin: partProdVtx->particles_in()) {
637 if (!pin) continue;
638 if (HepMC::is_same_particle(pout,pin)) {
639 if (MC::isMuon(pout)) NumOfMuLoop++;
640 if (std::abs(pout->pdg_id()) == MC::NU_MU) NumOfMuNeuLoop++;
641 if (MC::isSMLepton(pout)) NumOfLepLoop++;
642 break; // break out of inner loop after having found two matching particles
643 }
644 }
645 }
646 if (NumOfMuLoop == 2 && NumOfMuNeuLoop == 0) return ZBoson;
647 if (NumOfMuLoop == 1 && NumOfMuNeuLoop == 1) return WBoson;
648 if ((NumOfMuLoop == 4 && NumOfMuNeuLoop == 0) || (NumOfMuLoop == 3 && NumOfMuNeuLoop == 1) ||
649 (NumOfMuLoop == 2 && NumOfMuNeuLoop == 2)) return DiBoson;
650 if (NumOfLepLoop == 4) return DiBoson;
651 }
652
653 //-- McAtNLo
654
655 if (MC::isHiggs(ancestorPDG)) return Higgs;
656
657 if (MC::isMSSMHiggs(ancestorPDG)) return HiggsMSSM; // MSSM Higgs bosons
658
659 if (MC::isHeavyBoson(ancestorPDG)) return HeavyBoson; // Heavy bosons( Z', Z'', W'+)
660
661 if (std::abs(ancestorPDG) == MC::WBOSON_LRSM) return WBosonLRSM; // Left-right symmetric model WBoson (Pythia-specific)
662 if (std::abs(ancestorPDG) == MC::RH_NU_E) return NuREle; // Right-handed NU_E (Pythia-specific)
663 if (std::abs(ancestorPDG) == MC::RH_NU_MU) return NuRMu; // Right-handed NU_MU (Pythia-specific)
664 if (std::abs(ancestorPDG) == MC::RH_NU_TAU) return NuRTau; // Right-handed NU_TAU (Pythia-specific)
665 if (MC::isLeptoQuark(ancestorPDG) || NumOfLQ != 0) return LQ;
666 if (MC::isSUSY(ancestorPDG)) return SUSY;
667 if (MC::isBSM(ancestorPDG)) return OtherBSM;
668
669 const ParticleType pType = defTypeOfHadron(ancestorPDG);
670 if ((pType == BBbarMesonPart || pType == CCbarMesonPart) && ancestorProdVtx && MC::isHardScatteringVertex(ancestorProdVtx)) isPrompt = true;
671
672 return convHadronTypeToOrig(pType, ancestorPDG);
673}
674
675
677 const xAOD::TruthParticle* thePart,
678 int ancestorPDGin,
679 ParticleOutCome& outCome)
680{
681 // Executing DefOrigOfTau
682
683 // Find the first copy of this particle stored in the xAOD::TruthParticleContainer (i.e. the particle prior to any interactions)
684 const xAOD::TruthParticle* thePriPart = MC::findMatching(xTruthParticleContainer, thePart);
685 if (!thePriPart) return NonDefined;
686 if (!MC::isTau(thePriPart)) return NonDefined;
687
688 //-- to define tau outcome status
689 if (MC::isPhysical(thePriPart)) outCome = defOutComeOfTau(thePriPart); // FIXME why do we need the additional check on MC::isPhysical here c.f. defOrigOfElectron and defOrigOfMuon?
690
691 const xAOD::TruthVertex* partProdVtx = thePriPart->hasProdVtx() ? thePriPart->prodVtx() : nullptr;
692 if (!partProdVtx) return NonDefined;
693
694
695 const xAOD::TruthParticle* ancestor = MC::findMother(thePriPart);
696 if (!ancestor) { return NonDefined; } // ancestor is not a nullptr beyond this point
697
698 // "method 1" for finding Sherpa loops from defOrigOfElectron not used here. Why?
699
700 // Difference from defOrigOfElectron and defOrigOfMuon - no loop through ancestor particles
701
702 if (MC::isW(ancestorPDGin) && ancestor->hasProdVtx()) { // FIXME ancestorPDGin here could in principle be inconsistent with ancestorProdVtx
703 const xAOD::TruthParticle* ancestorParent = MC::findMother(ancestor);
704 if (ancestorParent && MC::isTop(ancestorParent->pdgId())) {
705 ancestor = ancestorParent; //...so ancestor cannot be nullptr
706 }
707 }
708
709 const int ancestorPDG = ancestor->pdgId();
710 const xAOD::TruthVertex* ancestorProdVtx = ancestor->hasProdVtx() ? ancestor->prodVtx() : nullptr;
711 partProdVtx = ancestor->decayVtx();
712 if (!partProdVtx) return NonDefined; // FIXME not sure this could ever be true?
713 const int numOfParents = partProdVtx->nIncomingParticles();
714
715 // Determine decay products
716 auto DP = DecayProducts(partProdVtx);
717 const int numberOfChildren = DP.size();
718 const int NumOfPhot = DP.pd(MC::PHOTON);
719 const int NumOfEl = DP.pd(MC::ELECTRON);
720 const int NumOfPos = DP.pd(MC::POSITRON);
721 const int NumOfElNeut = DP.apd(MC::NU_E);
722 const int NumOfMuNeut = DP.apd(MC::NU_MU);
723 /* const int NumOfLQ = DP.apd(MC::LEPTOQUARK); */ // FIXME Leptoquarks not an option?
724 const int NumOfquark = DP.apd({MC::DQUARK,MC::UQUARK,MC::SQUARK,MC::CQUARK,MC::BQUARK,MC::TQUARK});
725 const int NumOfgluon = DP.apd(MC::GLUON);
726 const int NumOfMuPl = DP.pd(-MC::MUON);
727 const int NumOfMuMin = DP.pd(MC::MUON);
728 const int NumOfTau = DP.apd(MC::TAU);
729 const int NumOfTauNeut = DP.apd(MC::NU_TAU);
730 // End of section determining decay products
731
732 if (MC::isTop(ancestorPDG)) return top;
733 if (MC::isW(ancestorPDG) && ancestorProdVtx && ancestorProdVtx->nIncomingParticles() != 0) {
734 const xAOD::TruthVertex* prodVert = ancestorProdVtx;
735 const xAOD::TruthParticle* itrP;
736 do {
737 itrP = prodVert->incomingParticle(0); // FIXME just taking the first one
738 prodVert = itrP->hasProdVtx() ? itrP->prodVtx() : nullptr;
739 } while (MC::isW(itrP) && prodVert);
740
741 if (prodVert && prodVert->nIncomingParticles() == 1 ) {
742 if (std::abs(itrP->pdgId()) == MC::RH_NU_E) return NuREle; // Right-handed NU_E (Pythia-specific)
743 if (std::abs(itrP->pdgId()) == MC::RH_NU_MU) return NuRMu; // Right-handed NU_MU (Pythia-specific)
744 if (std::abs(itrP->pdgId()) == MC::RH_NU_TAU) return NuRTau; // Right-handed NU_TAU (Pythia-specific)
745 }
746 return WBoson;
747 }
748 if (MC::isW(ancestorPDG)) { return WBoson;}
749 if (MC::isZ(ancestorPDG)) { return ZBoson;}
750 if (numOfParents == 1 && numberOfChildren > 4 && (MC::isSMQuark(ancestorPDG) || MC::isGluon(ancestorPDG))) {
751 bool isZboson = false;
752 bool isWboson = false;
753 bool skipnext = false;
754 for (unsigned int ipOut = 0; ipOut + 1 < partProdVtx->nOutgoingParticles(); ipOut++) {
755 if (skipnext) {
756 skipnext = false;
757 continue;
758 }
759 const xAOD::TruthParticle* aChild = partProdVtx->outgoingParticle(ipOut);
760 if (!aChild) continue;
761 const xAOD::TruthParticle* theNextChild{};
762 for (unsigned int ipOut1 = ipOut + 1; ipOut1 < partProdVtx->nOutgoingParticles(); ipOut1++) {
763 theNextChild = partProdVtx->outgoingParticle(ipOut1);
764 if (theNextChild) break;
765 }
766 if (!theNextChild) {
767 continue;
768 }
769 if (MC::isTau(aChild) && MC::isTau(theNextChild)) {
770 // Zboson
771 if (thePriPart == aChild || thePriPart == theNextChild) {
772 isZboson = true;
773 break;
774 }
775 skipnext = true;
776 } else if (MC::isTau(aChild) && std::abs(theNextChild->pdgId()) == MC::NU_TAU) {
777 // WBoson
778 if (thePriPart == aChild || thePriPart == theNextChild) {
779 isWboson = true;
780 break;
781 }
782 skipnext = true;
783 }
784 }
785 if (isWboson) return WBoson;
786 if (isZboson) return ZBoson;
787 }
788 if (numOfParents == 2 ) {
789 const int pdg1 = partProdVtx->incomingParticle(0)->pdgId();
790 const int pdg2 = partProdVtx->incomingParticle(1)->pdgId();
791 //--Sherpa Z->tautau
792 if ((numberOfChildren - NumOfquark - NumOfgluon) == 2 && NumOfTau == 2 && (MC::isQuark(pdg1)||MC::isGluon(pdg1)) && (MC::isQuark(pdg2)||MC::isGluon(pdg2))) return ZBoson; // FIXME Why the extra checks on incoming particles compared to Z->ee, Z->mumu and Z->nunu?
793
794 //--Sherpa W->taunu new
795 if ((numberOfChildren - NumOfquark - NumOfgluon) == 2 && NumOfTau == 1 && NumOfTauNeut == 1) return WBoson;
796
797 //--Sherpa ZZ,ZW
798 if ((numberOfChildren - NumOfquark - NumOfgluon) == 4 &&
799 (NumOfEl + NumOfPos + NumOfMuPl + NumOfMuMin + NumOfTau + NumOfElNeut + NumOfMuNeut + NumOfTauNeut == 4) &&
800 (MC::isQuark(pdg1)||MC::isGluon(pdg1)) && (MC::isQuark(pdg2)||MC::isGluon(pdg2))) return DiBoson;
801
802 //--Sherpa VVV -- Note, have to allow for prompt photon radiation or these get lost
803 if ((numberOfChildren - NumOfquark - NumOfgluon - NumOfPhot) == 6 &&
804 (NumOfEl + NumOfPos + NumOfMuPl + NumOfMuMin + NumOfTau + NumOfElNeut + NumOfMuNeut + NumOfTauNeut == 6) &&
805 (MC::isQuark(pdg1)||MC::isGluon(pdg1)) && (MC::isQuark(pdg2)||MC::isGluon(pdg2))) return MultiBoson;
806
807 //--Sherpa tttt with all t->Wb; W->lnu
808 if ((numberOfChildren - NumOfquark - NumOfgluon) == 8 &&
809 (NumOfEl + NumOfPos + NumOfMuPl + NumOfMuMin + NumOfTau + NumOfElNeut + NumOfMuNeut + NumOfTauNeut == 8) &&
810 (MC::isQuark(pdg1)||MC::isGluon(pdg1)) && (MC::isQuark(pdg2)||MC::isGluon(pdg2))) {
811 // MultiBoson for 4topLep
812 return MultiBoson;
813 }
814
815 //--Sherpa Vgamma ( Z->tautau+gamma or W->taunu+gamma )
816 if ((numberOfChildren - NumOfquark - NumOfgluon) >= 3 && NumOfPhot >= 1 && NumOfTau == 2) {
817 // Sherpa tautau + gamma
818 return ZBoson;
819 }
820 if ((numberOfChildren - NumOfquark - NumOfgluon) >= 3 && NumOfPhot >= 1 && NumOfTau == 1 && NumOfTauNeut == 1) {
821 // Sherpa taunu + gamma
822 return WBoson;
823 }
824 }
825
826 // New Sherpa Z->tautau
827 if (partProdVtx == ancestorProdVtx) {
828 int NumOfTauLoop = 0;
829 int NumOfTauNeuLoop = 0;
830 int NumOfLepLoop = 0;
831 for ( const auto *const pout: partProdVtx->particles_out()) {
832 if (!pout) continue;
833 for (const auto *const pin: partProdVtx->particles_in()) {
834 if (!pin) continue;
835 if (!HepMC::is_same_particle(pout,pin)) continue;
836 if (MC::isTau(pout)) NumOfTauLoop++;
837 if (std::abs(pout->pdgId()) == MC::NU_TAU) NumOfTauNeuLoop++;
838 if (MC::isSMLepton(pout)) NumOfLepLoop++;
839 break; // break out of inner loop after having found two matching particles
840 }
841 }
842 if (NumOfTauLoop == 2 && NumOfTauNeuLoop == 0) return ZBoson;
843 if (NumOfTauLoop == 1 && NumOfTauNeuLoop == 1) return WBoson;
844 if ((NumOfTauLoop == 4 && NumOfTauNeuLoop == 0) || (NumOfTauLoop == 3 && NumOfTauNeuLoop == 1) || (NumOfTauLoop == 2 && NumOfTauNeuLoop == 2)) return DiBoson;
845 if (NumOfLepLoop == 4) return DiBoson;
846 }
847
848 //-- McAtNLo
849
850 if (MC::isHiggs(ancestorPDG)) return Higgs;
851 if (MC::isMSSMHiggs(ancestorPDG)) return HiggsMSSM; // MSSM Higgs bosons
852 if (MC::isHeavyBoson(ancestorPDG)) return HeavyBoson; // Heavy bosons( Z', Z'', W'+)
853 if (std::abs(ancestorPDG) == MC::WBOSON_LRSM) return WBosonLRSM; // Left-right symmetric model WBoson (Pythia-specific)
854 if (std::abs(ancestorPDG) == MC::RH_NU_TAU) return NuRTau; // Right-handed NU_TAU (Pythia-specific)
855 if (MC::isSUSY(ancestorPDG)) return SUSY;
856 if (MC::isBSM(ancestorPDG)) return OtherBSM;
857 if (std::abs(ancestorPDG) == MC::JPSI) return JPsi;
858
859 const ParticleType pType = defTypeOfHadron(ancestorPDG);
860 return convHadronTypeToOrig(pType, ancestorPDG);
861}
862
863
865 const xAOD::TruthParticle* thePart,
866 bool& isPrompt,
867 ParticleOutCome& outCome)
868{
869 if (!thePart) return NonDefined; // FIXME Why is this extra protection needed for this function and not the others?
870 // Executing DefOrigOfPhoton
871
872
873 // Find the first copy of this particle stored in the xAOD::TruthParticleContainer (i.e. the particle prior to any interactions)
874 const xAOD::TruthParticle* thePriPart = MC::findMatching(xTruthParticleContainer, thePart);
875 if (!thePriPart) return NonDefined;
876 if (!MC::isPhoton(thePriPart)) return NonDefined;
877
878 const xAOD::TruthVertex* partProdVtx = thePriPart->hasProdVtx() ? thePriPart->prodVtx() : nullptr;
879
880 //-- to define photon outcome status
881 outCome = defOutComeOfPhoton(thePriPart);
882
883 if (!partProdVtx) return NonDefined;
884
885 int numOfParents = partProdVtx->nIncomingParticles();
886
887 const xAOD::TruthParticle* ancestor = MC::findMother(thePriPart);
888 if (!ancestor) { return NonDefined; } // ancestor is not a nullptr beyond this point
889
890 int ancestorPDG = ancestor->pdgId();
891 // "method 1" for finding Sherpa loops from defOrigOfElectron not used here. Why?
892 const xAOD::TruthVertex* ancestorProdVtx = ancestor->hasProdVtx() ? ancestor->prodVtx() : nullptr;
893
894 partProdVtx = ancestor->decayVtx(); // FIXME how often does this line actually change the pointer???
895 numOfParents = partProdVtx->nIncomingParticles();
896
897 const int numberOfChildren = partProdVtx->nOutgoingParticles();
898
899 // Determine decay products
900 auto DP = DecayProducts(partProdVtx);
901 const int NumOfEl = DP.pd(MC::ELECTRON);
902 const int NumOfPos = DP.pd(MC::POSITRON);
903 const int NumOfMu = DP.apd(MC::MUON);
904 const int NumOfTau = DP.apd(MC::TAU);
905 const int NumOfLQ = DP.apd(MC::LEPTOQUARK);
906 const int NumOfLep = NumOfEl + NumOfPos + NumOfMu + NumOfTau;
907 const int NumOfNeut = DP.apd({MC::NU_E,MC::NU_MU,MC::NU_TAU});
908 const int NumOfPht = DP.pd(MC::PHOTON);
909
910 int childPDG(0);
911 int NumOfPartons(0);
912 int NumOfNucFr(0);
913 const bool possibleNuclearFragment = (numOfParents == 1 && (MC::isPhoton(ancestorPDG) || MC::isElectron(ancestorPDG) || std::abs(ancestorPDG) == MC::PIPLUS));
914 const xAOD::TruthParticle* child{};
915 for (const auto& pout: partProdVtx->particles_out()) {
916 if (!pout) continue;
917 childPDG = pout->pdg_id();
918 if (possibleNuclearFragment &&
919 (MC::isNucleus(childPDG) || childPDG == 0 || childPDG == MC::PROTON || childPDG == MC::NEUTRON)) { // FIXME Do we really expect particles with PDG_ID = 0 in the truth record?
920 NumOfNucFr++;
921 }
922 if (std::abs(childPDG) < MC::ELECTRON ||
923 (std::abs(childPDG) > MC::NU_TAU && std::abs(childPDG) < 43 && !MC::isPhoton(childPDG))) {
924 // FIXME Too loose? This definition picks up 4th generation quarks and leptons as well as all gauge bosons and leptoquarks.
925 // Suggest MC::isSMQuark(childPDG) || (MC::isBoson(childPDG) && !MC::isPhoton(childPDG))
926 // or maybe even MC::isSMQuark(childPDG) || MC::isGluon(childPDG)
927 // AKA const int NumOfPartons = DP.apd({MC::DQUARK,MC::UQUARK,MC::SQUARK,MC::CQUARK,MC::BQUARK,MC::TQUARK,MC::GLUON});
928 NumOfPartons++;
929 }
930 if (childPDG == ancestorPDG) {
931 child = pout;
932 }
933 }
934 // End of section determining decay products
935
936 bool foundISR = false;
937 bool foundFSR = false;
938 if (numOfParents == 1 && numberOfChildren == 2 && child && HepMC::is_same_generator_particle(child, ancestor)) return BremPhot;
939 if (numOfParents == 1 && numberOfChildren == 2 && MC::isElectron(ancestorPDG) && NumOfPht == 2) return ElMagProc;
940
941 // decay of W,Z and Higgs to lepton with FSR generated by Pythia
942 if (numOfParents == 1 && numberOfChildren == 2 && (MC::isElectron(ancestorPDG) || MC::isMuon(ancestorPDG) || MC::isTau(ancestorPDG)) &&
943 !(child && HepMC::is_same_generator_particle(child, ancestor)) && ancestorProdVtx &&
944 ancestorProdVtx->nIncomingParticles() == 1) {
945 int itr = 0;
946 int PartPDG = 0;
947 const xAOD::TruthVertex* prodVert = ancestorProdVtx;
948 const xAOD::TruthVertex* Vert{};
949 do {
950 Vert = prodVert;
951 for (const auto & pin: Vert->particles_in()) {
952 if (!pin) continue;
953 PartPDG = std::abs(pin->pdgId());
954 prodVert = pin->prodVtx();
955 if (MC::isZ(PartPDG) || MC::isW(PartPDG) || MC::isHiggs(PartPDG)) foundFSR = true;
956 }
957 itr++;
958 if (itr > 100) { // FIXME Improve loop detection here?
959 // DefOrigOfPhoton:: infinite while
960 break;
961 }
962 } while (prodVert && std::abs(ancestorPDG) == PartPDG);
963
964 if (foundFSR) return FSRPhot;
965 }
966
967 // Nucl reaction
968 // gamma+Nuclear=>gamma+Nucl.Fr+Nuclons+pions
969 // e+Nuclear=>e+gamma+Nucl.Fr+Nuclons+pions
970 // pi+Nuclear=>gamma+Nucl.Fr+Nuclons+pions
971
972 if ((numOfParents == 1 && (MC::isPhoton(ancestorPDG) || MC::isElectron(ancestorPDG)) && numberOfChildren > 2 && NumOfNucFr != 0) ||
973 (numOfParents == 1 && std::abs(ancestorPDG) == MC::PIPLUS && numberOfChildren > 10 && NumOfNucFr != 0) ||
974 (numOfParents == 1 && MC::isPhoton(ancestorPDG) && numberOfChildren > 10 && MC::isStable(ancestor)) ||
975 (numOfParents == 1 && MC::isNucleus(ancestorPDG) && std::abs(ancestorPDG) != MC::PROTON)) // FIXME vetoing protons here to preserve previous behaviour
976 return NucReact;
977
978 if (MC::isMuon(ancestorPDG) && NumOfMu == 0) return Mu;
979 if (MC::isTau(ancestorPDG) && NumOfTau == 0) return TauLep;
980
981 if (numOfParents == 1 && ancestor->status() == 3) return (foundISR)? ISRPhot:UndrPhot; // FIXME foundISR is always false at this point
982
983 //-- to find initial and final state raiation and underline photons
984 //-- SUSY
985 if (numOfParents == 1 && (MC::isSMQuark(ancestorPDG) || MC::isGluon(ancestorPDG)) &&
986 (numberOfChildren != NumOfPht + NumOfPartons || !MC::Pythia8::isConditionA(ancestor))) {
987 for (const auto& pout: partProdVtx->particles_out()) {
988 if (!pout) continue;
989 if (ancestorPDG != pout->pdgId()) continue;
990 const xAOD::TruthVertex* Vrtx = pout->decayVtx();
991 if (!Vrtx) continue;
992 if (Vrtx->nOutgoingParticles() != 1 && Vrtx->nIncomingParticles() == 1) continue;
993 if (!Vrtx->outgoingParticle(0)) continue;
994 if (Vrtx->outgoingParticle(0)->pdgId() == 91) foundISR = true; // Herwig "cluster"
995 }
996 return (foundISR)?ISRPhot:UndrPhot;
997 }
998
999 //-- to find final state radiation
1000 //-- Exotics
1001
1002 // FSR from Photos
1003 //-- Exotics- CompHep
1004 if (numOfParents == 2 && ((MC::isElectron(ancestorPDG) && NumOfEl == 1 && NumOfPos == 1) || (MC::isMuon(ancestorPDG) && NumOfMu == 2) || (MC::isTau(ancestorPDG) && NumOfTau == 2))) {
1005 if (std::abs(partProdVtx->incomingParticle(0)->pdgId()) == std::abs(partProdVtx->incomingParticle(1)->pdgId())) return FSRPhot;
1006 }
1007
1008 if (numOfParents == 2 && NumOfLep == 1 && NumOfNeut == 1 && (MC::isElectron(ancestorPDG) || std::abs(ancestorPDG) == MC::NU_E)) return FSRPhot;
1009
1010 //-- Exotics - CompHep
1011 if (MC::isElectron(ancestorPDG) && numOfParents == 1 && numberOfChildren == 2 && (NumOfEl == 1 || NumOfPos == 1) && NumOfPht == 1 &&
1012 !( child && HepMC::is_same_generator_particle(child, ancestor)) && !HepMC::is_simulation_particle(child) && !HepMC::is_simulation_particle(ancestor))
1013 return FSRPhot;
1014
1015 // FSR from Photos
1016 if (MC::isZ(ancestorPDG) && ((NumOfEl + NumOfPos == 2 || NumOfEl + NumOfPos == 4) || (NumOfMu == 2 || NumOfMu == 4) || (NumOfTau == 2 || NumOfTau == 4)) && NumOfPht > 0) return FSRPhot;
1017
1018 if (NumOfPht > 0 && (std::abs(ancestorPDG) == MC::WBOSON_LRSM || MC::isNeutrinoRH(ancestorPDG))) return FSRPhot; // Left-right symmetric model WBoson || Right-handed neutrinos (Pythia-specific)
1019
1020 if (numOfParents == 2 && NumOfLQ == 1) return FSRPhot;
1021
1022 //--- other process
1023
1024 if (MC::isZ(ancestorPDG)) return ZBoson;
1025 if (MC::isW(ancestorPDG)) {
1026
1027 if (NumOfLep == 1 && NumOfNeut == 1 && numberOfChildren == NumOfLep + NumOfNeut + NumOfPht) return FSRPhot;
1028
1029 if (ancestorProdVtx && ancestorProdVtx->nIncomingParticles() != 0) {
1030 const xAOD::TruthVertex* prodVert = ancestorProdVtx;
1031 const xAOD::TruthParticle* itrP;
1032 do {
1033 itrP = prodVert->incomingParticle(0); // FIXME just taking the first one
1034 prodVert = itrP->hasProdVtx() ? itrP->prodVtx() : nullptr;
1035 } while (MC::isW(itrP) && prodVert);
1036
1037 if (prodVert && prodVert->nIncomingParticles() == 1 ) {
1038 if ( MC::isTau(itrP)) return TauLep;
1039 if ( MC::isMuon(itrP)) return Mu;
1040 if ( std::abs(itrP->pdgId()) == MC::RH_NU_E) return NuREle; // Right-handed NU_E (Pythia-specific)
1041 if ( std::abs(itrP->pdgId()) == MC::RH_NU_MU) return NuRMu; // Right-handed NU_MU (Pythia-specific)
1042 if ( std::abs(itrP->pdgId()) == MC::RH_NU_TAU) return NuRTau; // Right-handed NU_TAU (Pythia-specific)
1043 }
1044 } else
1045 return WBoson;
1046 }
1047
1048 // MadGraphPythia ZWW*->lllnulnu
1049 if (numOfParents == 1 && numberOfChildren > 4 && (MC::isSMQuark(ancestorPDG) || MC::isGluon(ancestorPDG))) {
1050 bool isZboson = false;
1051 bool isWboson = false;
1052 bool skipnext = false;
1053 for (unsigned int ipOut = 0; ipOut + 1 < partProdVtx->nOutgoingParticles(); ipOut++) {
1054 if (skipnext) {
1055 skipnext = false;
1056 continue;
1057 }
1058 const xAOD::TruthParticle* aChild = partProdVtx->outgoingParticle(ipOut);
1059 if (!aChild) continue;
1060 const xAOD::TruthParticle* theNextChild{};
1061 for (unsigned int ipOut1 = ipOut + 1; ipOut1 < partProdVtx->nOutgoingParticles(); ipOut1++) {
1062 theNextChild = partProdVtx->outgoingParticle(ipOut1);
1063 if (theNextChild) break;
1064 }
1065 if (!theNextChild) continue;
1066 if (MC::isTau(aChild) && MC::isTau(theNextChild)) {
1067 // Zboson
1068 if (thePriPart == aChild || thePriPart == theNextChild) {
1069 isZboson = true;
1070 break;
1071 }
1072 skipnext = true;
1073 } else if (MC::isTau(aChild) && std::abs(theNextChild->pdgId()) == MC::NU_TAU) {
1074 // WBoson
1075 if (thePriPart == aChild || thePriPart == theNextChild) {
1076 isWboson = true;
1077 break;
1078 }
1079 skipnext = true;
1080 }
1081 }
1082 if (isWboson) return WBoson;
1083 if (isZboson) return ZBoson;
1084 }
1085
1086 //--Sherpa ZZ,ZW+FSR
1087 if (numOfParents == 4 && (numberOfChildren - NumOfPht) == 4 && (NumOfLep + NumOfNeut == 4)) {
1088 if (MC::isSMLepton(partProdVtx->incomingParticle(0))&&MC::isSMLepton(partProdVtx->incomingParticle(1))
1089 && MC::isSMLepton(partProdVtx->incomingParticle(2))&&MC::isSMLepton(partProdVtx->incomingParticle(3)))
1090 return FSRPhot;
1091 }
1092
1093 //--New Sherpa single photon
1094 if (partProdVtx == ancestorProdVtx) {
1095 for (const auto *const pout: partProdVtx->particles_out()) {
1096 if (!pout) continue;
1097 for (const auto *const pin: partProdVtx->particles_in()) {
1098 if (!pin) continue;
1099 if (!HepMC::is_same_particle(pout,pin)) continue;
1100 if (MC::isPhoton(pout)) return SinglePhot;
1101 break; // break out of inner loop after having found two matching particles
1102 }
1103 }
1104 }
1105
1106 if (MC::isHiggs(ancestorPDG)) return Higgs;
1107 if (std::abs(ancestorPDG) == MC::PI0) return PiZero;
1108 if (MC::isMSSMHiggs(ancestorPDG)) return HiggsMSSM; // MSSM Higgs bosons
1109 if (MC::isHeavyBoson(ancestorPDG) || std::abs(ancestorPDG) == 5100039 ) return HeavyBoson; // Heavy Bosons (Z' Z'' W'+) + KK excited graviton
1110
1111 if (MC::isSUSY(ancestorPDG)) return SUSY;
1112 if (MC::isBSM(ancestorPDG)) return OtherBSM;
1113
1114 // Pythia8 gamma+jet samples
1115 if (MC::Pythia8::isConditionA(ancestor) && MC::isStable(thePriPart) && NumOfPht == 1 && numberOfChildren == (NumOfPht + NumOfPartons)) return PromptPhot;
1116
1117 const ParticleType pType = defTypeOfHadron(ancestorPDG);
1118 if ((pType == BBbarMesonPart || pType == CCbarMesonPart) && ancestorProdVtx && MC::isHardScatteringVertex(ancestorProdVtx)) isPrompt = true;
1119 return convHadronTypeToOrig(pType, ancestorPDG);
1120}
1121
1124 const xAOD::TruthParticle* thePart,
1125 bool& isPrompt,
1126 ParticleOutCome& outCome)
1127{
1128 // Executing DefOrigOfNeutrino
1129
1130 const int nuFlav = std::abs(thePart->pdgId());
1131 // Find the first copy of this particle stored in the xAOD::TruthParticleContainer (i.e. the particle prior to any interactions)
1132 const xAOD::TruthParticle* thePriPart = MC::findMatching(xTruthParticleContainer, thePart);
1133 if (!thePriPart) return NonDefined;
1134 if (std::abs(thePriPart->pdgId()) != nuFlav) return NonDefined; // FIXME should this be if (!MC::isSMNeutrino(thePriPart) || abs(thePriPart->pdgId()) != nuFlav) return NonDefined; // (Use MC::isNeutrino if 4th generation neutrinos OK)
1135
1136 //-- to define neutrino outcome status
1137 outCome = NonInteract;
1138
1139 const xAOD::TruthVertex* partProdVtx = thePriPart->hasProdVtx() ? thePriPart->prodVtx() : nullptr;
1140 if (!partProdVtx) return NonDefined;
1141
1142
1143 const xAOD::TruthParticle* ancestor = MC::findMother(thePriPart);
1144 if (!ancestor) { return NonDefined; } // ancestor is not a nullptr beyond this point
1145
1146 // Start of method 3 of protecting against loops
1147 // to resolve Sherpa loop
1148 bool samePart = MC::TruthLoopDetectionMethod1(partProdVtx, ancestor);
1149 // End of method 3 of protecting against loops
1150
1151 if ((std::abs(ancestor->pdgId()) == nuFlav || MC::isTau(ancestor) || MC::isW(ancestor)) && ancestor->hasProdVtx() && !samePart) {
1152 int pPDG(0);
1153 const xAOD::TruthParticle* ancestorParent{};
1154 do {
1155 pPDG = 0;
1156 ancestorParent = MC::findMother(ancestor);
1157 // Start of method 2 of protecting against loops
1158 // to prevent Sherpa loop
1159 if (MC::TruthLoopDetectionMethod2(ancestor,ancestorParent)) {
1160 ancestorParent = ancestor;
1161 break;
1162 }
1163 //
1164 if (ancestorParent) {
1165 pPDG = ancestorParent->pdgId(); // FIXME difference in behaviour compared to defOrigOfElectron/Muon pPDG set even if we are in a loop
1166 }
1167 // to prevent Sherpa loop
1168 if (ancestor == ancestorParent) { break; }
1169 // End of method 2 of protecting against Sherpa loops
1170 if (std::abs(pPDG) == nuFlav || MC::isTau(pPDG) || MC::isW(pPDG) ) {
1171 // There will be another iteration so set ancestor to ancestorParent
1172 ancestor = ancestorParent; // ancestorParent is not a nullptr
1173 }
1174
1175 } while ((std::abs(pPDG) == nuFlav || MC::isTau(pPDG) || MC::isW(pPDG)));
1176
1177 if (std::abs(pPDG) == nuFlav || MC::isTau(pPDG) || MC::isW(pPDG) || MC::isZ(pPDG) || MC::isHiggs(pPDG) ||
1178 MC::isMSSMHiggs(pPDG) || MC::isHeavyBoson(pPDG) || MC::isTop(pPDG) || // MSSM Higgs bosons, Heavy bosons( Z', Z'', W'+)
1179 std::abs(pPDG) == MC::WBOSON_LRSM || MC::isNeutrinoRH(pPDG) || // Left-right symmetric model WBoson || Right-handed neutrino (Pythia-specific)
1180 MC::isSUSY(pPDG)) {
1181 ancestor = ancestorParent; // ancestorParent is not nullptr here
1182 }
1183 }
1184 //if ancestor is still nullptr, we have a problem
1185 if (!ancestor) return NonDefined; // FIXME it should not be possible for ancestor to be nullptr at this point???
1186
1187 const int ancestorPDG = ancestor->pdgId();
1188 partProdVtx = ancestor->decayVtx();
1189 const xAOD::TruthVertex* ancestorProdVtx = ancestor->hasProdVtx() ? ancestor->prodVtx() : nullptr;
1190 const int numOfParents = partProdVtx->nIncomingParticles();
1191 const int numberOfChildren = partProdVtx->nOutgoingParticles();
1192
1193 // Determine decay products
1194 auto DP = DecayProducts(partProdVtx);
1195 const int NumOfPhot = DP.pd(MC::PHOTON);
1196 const int NumOfquark = DP.apd({MC::DQUARK,MC::UQUARK,MC::SQUARK,MC::CQUARK,MC::BQUARK,MC::TQUARK});
1197 const int NumOfgluon = DP.apd(MC::GLUON);
1198 const int NumOfLQ = DP.apd(MC::LEPTOQUARK);
1199 const int NumOfElNeut = DP.apd(MC::NU_E);
1200 const int NumOfMuNeut = DP.apd(MC::NU_MU);
1201 const int NumOfTauNeut = DP.apd(MC::NU_TAU);
1202 const int NumOfEl = DP.apd(MC::ELECTRON);
1203 const int NumOfMu = DP.apd(MC::MUON);
1204 const int NumOfTau = DP.apd(MC::TAU);
1205
1206 samePart = false;
1207 for (const auto& aChild: partProdVtx->particles_out()) {
1208 if (!aChild) continue;
1209 if (aChild->pdgId() == ancestorPDG && HepMC::is_same_generator_particle(aChild,ancestor)) {
1210 samePart = true;
1211 break;
1212 }
1213 }
1214 // End of section determining decay products
1215
1216 // Quark weak decay
1217 if (MC::isQuark(ancestorPDG) && numOfParents == 1 && numberOfChildren == 3 && NumOfquark == 1 && (NumOfEl == 1 || NumOfMu == 1 || NumOfTau == 1)) return QuarkWeakDec;
1218 if (MC::isTop(ancestorPDG)) return top;
1219
1220 if (MC::isW(ancestorPDG) && ancestorProdVtx && ancestorProdVtx->nIncomingParticles() != 0) {
1221 const xAOD::TruthVertex* prodVert = ancestorProdVtx;
1222 const xAOD::TruthParticle* ptrPart;
1223 do {
1224 ptrPart = prodVert->incomingParticle(0); // FIXME just taking the first one
1225 prodVert = ptrPart->hasProdVtx() ? ptrPart->prodVtx() : nullptr;
1226 } while (MC::isW(ptrPart) && prodVert);
1227
1228 if (prodVert && prodVert->nIncomingParticles() == 1) {
1229 if (std::abs(ptrPart->pdgId()) == MC::RH_NU_E) return NuREle; // Right-handed NU_E (Pythia-specific)
1230 if (std::abs(ptrPart->pdgId()) == MC::RH_NU_MU) return NuRMu; // Right-handed NU_MU (Pythia-specific)
1231 if (std::abs(ptrPart->pdgId()) == MC::RH_NU_TAU) return NuRTau; // Right-handed NU_TAU (Pythia-specific)
1232 }
1233 return WBoson;
1234 }
1235 if (MC::isW(ancestorPDG)) return WBoson;
1236 if (MC::isZ(ancestorPDG)) return ZBoson;
1237
1238 //-- Exotics
1239
1240 // MadGraphPythia ZWW*->lllnulnu or ZWW*->nunulnulnu (don't even know if the latter is generated)
1241 if (numOfParents == 1 && numberOfChildren > 4 && (MC::isSMQuark(ancestorPDG) || MC::isGluon(ancestorPDG))) {
1242
1243 const xAOD::TruthParticle* thePartToCheck = thePriPart;
1244 const xAOD::TruthParticle* theParent = thePriPart->hasProdVtx() ? thePriPart->prodVtx()->incomingParticle(0) : nullptr; // FIXME just taking the first one
1245
1246 if (MC::isElectron(theParent) && MC::isDecayed(theParent)) { thePartToCheck = theParent; }
1247 bool isZboson = false;
1248 bool isWboson = false;
1249 bool skipnext = false;
1250
1251 for (unsigned int ipOut = 0; ipOut + 1 < partProdVtx->nOutgoingParticles(); ++ipOut) {
1252 const xAOD::TruthParticle* aChild = partProdVtx->outgoingParticle(ipOut);
1253 if (!aChild) continue;
1254 const xAOD::TruthParticle* theNextChild{};
1255 for (unsigned int ipOut1 = ipOut + 1; ipOut1 < partProdVtx->nOutgoingParticles(); ipOut1++) {
1256 theNextChild = partProdVtx->outgoingParticle(ipOut1);
1257 if (theNextChild) break;
1258 }
1259 if (!theNextChild) continue;
1260
1261 if (skipnext) {
1262 skipnext = false;
1263 continue;
1264 }
1265
1266 const int apdgID1 = std::abs(aChild->pdgId());
1267 const int apdgID2 = std::abs(theNextChild->pdgId());
1268 if (apdgID1 == apdgID2 && MC::isSMNeutrino(apdgID1)) {
1269 // Zboson
1270 if (thePartToCheck == aChild || thePartToCheck == theNextChild) {
1271 isZboson = true;
1272 break;
1273 }
1274 skipnext = true;
1275 } else if ((apdgID1 == MC::ELECTRON && apdgID2 == MC::NU_E) ||
1276 (apdgID1 == MC::NU_E && apdgID2 == MC::ELECTRON) ||
1277 (apdgID1 == MC::MUON && apdgID2 == MC::NU_MU) ||
1278 (apdgID1 == MC::NU_MU && apdgID2 == MC::MUON) ||
1279 (apdgID1 == MC::TAU && apdgID2 == MC::NU_TAU) ||
1280 (apdgID1 == MC::NU_TAU && apdgID2 == MC::TAU)
1281 ) {
1282 // WBoson
1283 if (thePartToCheck == aChild || thePartToCheck == theNextChild) {
1284 isWboson = true;
1285 break;
1286 }
1287 skipnext = true;
1288 }
1289 }
1290 if (isWboson) return WBoson;
1291 if (isZboson) return ZBoson;
1292 }
1293
1294 if (numOfParents == 2) {
1295 //--Sherpa Z->nunu
1296 if ( (numberOfChildren - NumOfquark - NumOfgluon) == 2 && (NumOfElNeut == 2 || NumOfMuNeut == 2 || NumOfTauNeut == 2)) return ZBoson;
1297
1298 //--Sherpa W->enu ??
1299 if ((numberOfChildren - NumOfquark - NumOfgluon) == 2 && ((NumOfEl == 1 && NumOfElNeut == 1) || (NumOfMu == 1 && NumOfMuNeut == 1) || (NumOfTau == 1 && NumOfTauNeut == 1))) return WBoson;
1300
1301 const int pdg1 = partProdVtx->incomingParticle(0)->pdgId();
1302 const int pdg2 = partProdVtx->incomingParticle(1)->pdgId();
1303 //--Sherpa ZZ,ZW
1304 if ( (numberOfChildren - NumOfquark - NumOfgluon) == 4 && (NumOfEl + NumOfMu + NumOfTau + NumOfElNeut + NumOfMuNeut + NumOfTauNeut == 4) &&
1305 (MC::isQuark(pdg1)||MC::isGluon(pdg1)) && (MC::isQuark(pdg2)||MC::isGluon(pdg2))) return DiBoson;
1306
1307 //--Sherpa VVV -- Note, have to allow for prompt photon radiation or these get lost
1308 if ((numberOfChildren - NumOfquark - NumOfgluon - NumOfPhot) == 6 && (NumOfEl + NumOfMu + NumOfTau + NumOfElNeut + NumOfMuNeut + NumOfTauNeut == 6) &&
1309 (MC::isQuark(pdg1)||MC::isGluon(pdg1)) && (MC::isQuark(pdg2)||MC::isGluon(pdg2))) return MultiBoson;
1310
1311 //--Sherpa Vgamma ( Z->nunu+gamma )
1312 if ((numberOfChildren - NumOfquark - NumOfgluon) >= 3 && NumOfPhot >= 1 && (NumOfElNeut == 2 || NumOfMuNeut == 2 || NumOfTauNeut == 2)) {
1313 // Sherpa nunu + gamma
1314 return ZBoson;
1315 }
1316 }
1317
1318 // New Sherpa Z->nunu
1319 if (partProdVtx == ancestorProdVtx) {
1320 int NumOfLepLoop = 0;
1321 int NumOfNeuLoop = 0;
1322 for (const auto *const pout: partProdVtx->particles_out()) {
1323 if (!pout) continue;
1324 for (const auto *const pin: partProdVtx->particles_in()) {
1325 if (!pin) continue;
1326 if (HepMC::is_same_particle(pin,pout)) continue;
1327 const int apdgid = std::abs(pout->pdgId());
1328 if (MC::isSMLepton(apdgid)) {
1329 if (MC::isSMNeutrino(apdgid)) { NumOfNeuLoop++; }
1330 else { NumOfLepLoop++; }
1331 }
1332 break; // break out of inner loop after having found two matching particles
1333 }
1334 }
1335 if (NumOfNeuLoop == 2 && NumOfLepLoop == 0) return ZBoson;
1336 if (NumOfNeuLoop == 1 && NumOfLepLoop == 1) return WBoson;
1337 if (NumOfNeuLoop + NumOfLepLoop == 4) return DiBoson;
1338 }
1339
1340 //-- McAtNLo
1341
1342 if (MC::isHiggs(ancestorPDG)) return Higgs;
1343 if (MC::isMSSMHiggs(ancestorPDG)) return HiggsMSSM; // MSSM Higgs bosons
1344 if (MC::isHeavyBoson(ancestorPDG)) return HeavyBoson; // Heavy bosons( Z', Z'', W'+)
1345
1346 if (MC::isTau(ancestorPDG)) {
1347 const ParticleOrigin tauOrig = defOrigOfTau(xTruthParticleContainer, ancestor, ancestorPDG, outCome);
1348 const ParticleType tautype = defTypeOfTau(tauOrig);
1349 return (tautype == IsoTau)?tauOrig:TauLep;
1350 }
1351
1352 if (std::abs(ancestorPDG) == MC::WBOSON_LRSM) return WBosonLRSM; // Left-right symmetric model WBoson (Pythia-specific)
1353 if (std::abs(ancestorPDG) == MC::RH_NU_E) return NuREle; // Right-handed NU_E (Pythia-specific)
1354 if (std::abs(ancestorPDG) == MC::RH_NU_MU) return NuRMu; // Right-handed NU_MU (Pythia-specific)
1355 if (std::abs(ancestorPDG) == MC::RH_NU_TAU) return NuRTau; // Right-handed NU_TAU (Pythia-specific)
1356 if (MC::isLeptoQuark(ancestorPDG) || NumOfLQ != 0) return LQ;
1357 if (MC::isSUSY(ancestorPDG)) return SUSY;
1358 if (MC::isBSM(ancestorPDG)) return OtherBSM;
1359
1360 const ParticleType pType = defTypeOfHadron(ancestorPDG);
1361 if ((pType == BBbarMesonPart || pType == CCbarMesonPart) && ancestorProdVtx && MC::isHardScatteringVertex(ancestorProdVtx)) isPrompt = true;
1362
1363 return convHadronTypeToOrig(pType, ancestorPDG);
1364}
1365
1366} // namespace MCTruthPartClassifier
ATLAS-specific HepMC functions.
int status() const
Status code.
int pdgId() const
PDG ID code.
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
int pdg_id() const
PDG ID code.
bool hasProdVtx() const
Check for a production vertex on this particle.
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
const TruthParticle_v1 * outgoingParticle(size_t index) const
Get one of the outgoing particles.
const TruthParticle_v1 * incomingParticle(size_t index) const
Get one of the incoming particles.
std::vector< const TruthParticle * > particles_out() const
Get the outgoing particles.
size_t nOutgoingParticles() const
Get the number of outgoing particles.
size_t nIncomingParticles() const
Get the number of incoming particles.
std::vector< const TruthParticle * > particles_in() const
Get the incoming particles.
bool is_same_generator_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same generated particle.
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
bool is_simulation_particle(const T &p)
Method to establish if a particle was created during the simulation (based on the status value).
ParticleOutCome defOutComeOfElectron(T thePart)
Determine the outcome of a simulated electron from its end vertex (NonInteract, ElectrMagInter,...
ParticleOutCome defOutComeOfPhoton(T thePart)
Determine the outcome of a simulated photon from its end vertex (UnConverted, Converted,...
static ParticleOrigin defOrigOfNeutrino(const xAOD::TruthParticleContainer &xTruthParticleContainer, const xAOD::TruthParticle *thePart, bool &isPrompt, ParticleOutCome &outCome)
ParticleOutCome
Outcome of a (simulated) truth particle: what happened to it after being produced,...
@ NonInteract
Particle without an end vertex (survived the detector) – also used for neutrinos.
ParticleType defTypeOfPhoton(ParticleOrigin PhotOrig)
Classify a photon (Unknown/Iso/NonIso/Bkg) from its origin.
ParticleOrigin convHadronTypeToOrig(ParticleType pType, int motherPDG)
Convert a hadron ParticleType to a ParticleOrigin (JPsi if a c-cbar meson has a J/psi mother).
ParticleOutCome defOutComeOfTau(T thePart)
Determine the outcome of a simulated tau from its decay products (NonInteract, NuclInteraction,...
ParticleType defTypeOfTau(ParticleOrigin TauOrig)
Classify a tau (Unknown/Iso/NonIso/Bkg) from its origin.
static ParticleOrigin defOrigOfTau(const xAOD::TruthParticleContainer &xTruthParticleContainer, const xAOD::TruthParticle *thePart, int ancestorPDGin, ParticleOutCome &outCome)
ParticleType defTypeOfMuon(ParticleOrigin MuOrig, bool isPrompt)
Classify a muon (Unknown/Iso/NonIso/Bkg) from its origin; prompt muons are always Iso.
ParticleOrigin
Origin of a truth particle, as assigned by MCTruthClassifier::particleTruthClassifier (the second mem...
@ ElMagProc
Electromagnetic or nuclear material process: bremsstrahlung/pair production in the detector,...
@ UndrPhot
"Underlying" photon: radiated from a quark or gluon in the parton shower/underlying event
@ WBosonLRSM
Decay of the W_R boson of the left-right symmetric model (Pythia-specific PDG 9900024).
@ JPsi
Decay of a J/psi.
@ ZBoson
Z boson (or Z/gamma*) decay (including Sherpa Z records and Z+gamma).
@ ISRPhot
Initial-state radiation photon (quark/gluon mother whose copy is a Herwig cluster).
@ PromptPhot
Prompt (direct) photon of the hard process, e.g. Pythia8 gamma+jet.
@ BremPhot
Bremsstrahlung photon: the mother continues as a copy of itself plus this photon.
@ DiBoson
Two-boson (WW, WZ, ZZ) production recorded without explicit bosons: four leptons/neutrinos in the har...
@ Higgs
Higgs boson decay (SM Higgs, PDG 25).
@ HiggsMSSM
Decay of an extra (MSSM/2HDM) Higgs boson: H (35), A (36) or H+ (37).
@ LQ
Leptoquark: the ancestor is a leptoquark, or the decay vertex contains one.
@ PhotonConv
Photon conversion (gamma -> e+ e-, or gamma -> mu+ mu- for muons).
@ NuREle
Decay of a right-handed electron neutrino (Pythia-specific PDG 9900012), or of a W_R decaying to it.
@ TauLep
Decay (or radiation) of a tau lepton that is not itself prompt.
@ NuRMu
Decay of a right-handed muon neutrino (Pythia-specific PDG 9900014).
@ KaonDecay
Muon from K -> mu nu in flight.
@ FSRPhot
Final-state radiation photon, e.g. from the leptons of W/Z/H decays or from Photos.
@ WBoson
W boson decay (including Sherpa W records and W+gamma).
@ Mu
Decay (or radiation) of a muon.
@ OtherBSM
Decay of a non-SUSY BSM particle (added later, hence the out-of-order value).
@ NuRTau
Decay of a right-handed tau neutrino (Pythia-specific PDG 9900016).
@ NonDefined
Origin could not be determined (no production vertex, no ancestor, or particle not classified).
@ PiZero
Photon from a pi0 decay.
@ NucReact
Photon from a nuclear reaction in the material.
@ SingleElec
Single-electron particle gun: production vertex with no mother and one outgoing particle.
@ top
Decay of a top quark (including through W).
@ DalitzDec
Dalitz decay of a pi0 (pi0 -> gamma e+ e-, or pi0 -> e+ e- e+ e-).
@ QuarkWeakDec
Weak decay of a quark: q -> q' l nu with a single other quark in the final state.
@ SingleTau
Single-tau particle gun.
@ HeavyBoson
Decay of a heavy gauge boson Z', Z'', W'+ (PDG 32, 33, 34), or a KK graviton (5100039) in the photon ...
@ SingleMuon
Single-muon particle gun.
@ SinglePhot
Single-photon particle gun.
@ PionDecay
Muon from pi -> mu nu in flight.
@ MultiBoson
Three or more bosons (VVV, 4-top with leptonic W decays): six or eight leptons/neutrinos in the hard-...
ParticleType defTypeOfHadron(int pdg)
Classify a hadron by PDG ID into a ParticleType (Unknown if none applies).
static ParticleOrigin defOrigOfMuon(const xAOD::TruthParticleContainer &xTruthParticleContainer, const xAOD::TruthParticle *thePart, bool &isPrompt, ParticleOutCome &outCome)
std::pair< ParticleType, ParticleOrigin > classifyTruthParticle(const xAOD::TruthParticleContainer &truthParticleContainer, const xAOD::TruthParticle *const thePart, ParticleOutCome &outCome)
Classify thePart (not nullptr), using truthParticleContainer to look up its ancestors.
static ParticleOrigin defOrigOfPhoton(const xAOD::TruthParticleContainer &xTruthParticleContainer, const xAOD::TruthParticle *thePart, bool &isPrompt, ParticleOutCome &outCome)
int isPrompt(const unsigned int classify, bool allow_prompt_tau_decays=true)
Tell whether a particle is prompt, from the word returned by defOrigOfParticle().
ParticleOutCome defOutComeOfMuon(T thePart)
Determine the outcome of a simulated muon from its end vertex (NonInteract, DecaytoElectron,...
ParticleType defTypeOfElectron(ParticleOrigin EleOrig, bool isPrompt)
Classify an electron (Unknown/Iso/NonIso/Bkg) from its origin; prompt electrons are always Iso.
ParticleType
Type of a truth particle, as assigned by MCTruthClassifier::particleTruthClassifier (the first member...
@ BBbarMesonPart
Hidden-bottom meson (e.g. Upsilon, chi_b).
@ Unknown
Not classified: not a lepton, photon, neutrino or hadron (e.g. a quark, a gluon, a boson),...
@ Neutrino
Neutrino (an origin is determined for it, see ParticleOrigin).
@ NonPrimary
Not a primary particle: a copy produced by the simulation (e.g. Geant4) with no production vertex,...
@ IsoPhoton
Isolated (prompt) photon: from W/Z/H/BSM decay, a hard-process prompt photon, or a single-photon gun.
@ IsoTau
Isolated (prompt) tau.
@ UnknownMuon
Muon with undefined origin.
@ NuclFrag
Nuclear fragment: a nucleus other than a proton, produced in a material interaction.
@ CCbarMesonPart
Hidden-charm meson (e.g. J/psi, chi_c).
@ OtherBSMParticle
Stable non-SUSY BSM particle (added later, hence the out-of-order value).
@ IsoElectron
Isolated (prompt) electron, e.g. from W/Z/H/top/BSM decay, or a single-electron particle gun.
@ IsoMuon
Isolated (prompt) muon.
@ GenParticle
Generator-level intermediate particle (decayed, or otherwise not a final-state candidate) that is not...
@ UnknownPhoton
Photon with undefined origin.
@ SUSYParticle
Stable SUSY particle (e.g. the LSP).
@ UnknownElectron
Electron with undefined origin (no production vertex, or origin could not be traced).
@ Hadron
Any hadron (neither the beam nor a nuclear fragment); the origin is not studied further.
@ UnknownTau
Tau with undefined origin.
static ParticleOrigin defOrigOfElectron(const xAOD::TruthParticleContainer &xTruthParticleContainer, const xAOD::TruthParticle *thePart, bool &isPrompt, ParticleOutCome &outCome)
bool isConditionA(const T &p)
Match selected Pythia status codes for hardest-subprocess and later-stage particles: 21: incoming par...
static const int PI0
static const int UQUARK
static const int KPLUS
T findMatching(C TruthContainer, T p)
Function to find in the container the particle that p descends from in the simulation (see HepMC::is_...
bool isNeutrinoRH(const T &p)
PDG rule 12: Occasionally program authors add their own states.
bool isZ(const T &p)
static const int SQUARK
static const int NEUTRON
static const int DQUARK
PDG Rule 1: Particles are given positive numbers, antiparticles negative numbers.
static const int MUON
bool TruthLoopDetectionMethod1(const V &childOrigVtx, const T &parent)
Method 1: true if the parent is among the children produced at the child's production vertex,...
Definition Loops.h:32
bool isHardScatteringVertex(T pVert)
Function to classify the vertex as hard scattering vertex.
bool isSMLepton(const T &p)
APID: the fourth generation leptons are not standard model leptons.
static const int CQUARK
bool isPhoton(const T &p)
bool isW(const T &p)
static const int PHOTON
static const int RH_NU_TAU
bool isSMNeutrino(const T &p)
static const int WBOSON_LRSM
static const int TQUARK
static const int TAU
static const int GLUON
bool isNeutrino(const T &p)
APID: the fourth generation neutrinos are neutrinos.
bool isElectron(const T &p)
static const int ELECTRON
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
static const int PIPLUS
bool isSMQuark(const T &p)
bool TruthLoopDetectionMethod2(const T1 &child, const T2 &parent)
Method 2: true if the parent's production vertex is the child's decay vertex and the child's producti...
Definition Loops.h:47
bool isTop(const T &p)
static const int POSITRON
bool isMuon(const T &p)
bool isSUSY(const T &p)
static const int NU_MU
bool isMSSMHiggs(const T &p)
APID: Additional Higgs bosons for MSSM (Used in MCTruthClassifier).
bool isDecayed(const T &p)
Identify if the particle decayed.
bool isQuark(const T &p)
PDG rule 2: Quarks and leptons are numbered consecutively starting from 1 and 11 respectively; to do ...
static const int JPSI
T findMother(T thePart)
Function to get a mother of particle. MCTruthClassifier legacy.
static const int NU_E
static const int BQUARK
bool isHiggs(const T &p)
APID: HIGGS boson is only one particle.
static const int LEPTOQUARK
bool isBeam(const T &p)
Identify if the particle is beam particle.
static const int NU_TAU
bool isHadron(const T &p)
bool isNucleus(const T &p)
PDG rule 16 Nuclear codes are given as 10-digit numbers ±10LZZZAAAI.
static const int RH_NU_MU
bool isGluon(const T &p)
bool isHeavyBoson(const T &p)
APID: Additional "Heavy"/"prime" versions of W and Z bosons (Used in MCTruthClassifier).
bool isLeptoQuark(const T &p)
PDG rule 11c: “One-of-a-kind” exotic particles are assigned numbers in the range 41–80.
static const int RH_NU_E
PDG Rule 12: Occasionally program authors add their own states.
bool isTau(const T &p)
static const int PROTON
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
bool isBSM(const T &p)
APID: graviton and all Higgs extensions are BSM.
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15
TruthParticle_v1 TruthParticle
Typedef to implementation.
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.