1 #ifndef PhysicsTools_HepMCCandAlgos_GenParticlesHelper_h
2 #define PhysicsTools_HepMCCandAlgos_GenParticlesHelper_h
5 #include "HepPDT/ParticleID.hh"
11 #include <unordered_set>
198 return findDecayedMother(p) == 0;
204 return p.status()==1 && isPrompt(p);
209 return p.status()==2 && (isHadron(p) || absPdgId(p)==13 || absPdgId(p)==15) && isLastCopy(p);
214 return isDecayedLeptonHadron(p) && isPrompt(p);
220 return findDecayedMother(p,15) != 0;
226 const P *
tau = findDecayedMother(p,15);
227 return tau && isPrompt(*tau);
233 const P *
tau = findDecayedMother(p,15);
234 const P *dm = findDecayedMother(p);
235 return tau && tau==dm;
241 const P *
tau = findDecayedMother(p,15);
242 const P *dm = findDecayedMother(p);
243 return tau && tau==dm && isPrompt(*tau);
249 return findDecayedMother(p,13) != 0;
255 const P *
mu = findDecayedMother(p,13);
256 return mu && isPrompt(*mu);
262 const P *um = uniqueMother(p);
263 return um && isHadron(*um) && isDecayedLeptonHadron(*um);
270 return heppdtid.isHadron();
278 if (p.status()==3)
return true;
281 if (p.status()>20 && p.status()<30)
return true;
287 if (p.status()==1 || p.status()==2) {
288 const P *um = mother(p);
290 const P *firstcopy = firstCopy(*um);
291 bool fromResonance = firstcopy && firstcopy->status()==22;
293 const P *umNext = nextCopy(*um);
294 bool fsrBranching = umNext && umNext->status()>50 && umNext->status()<60;
296 if (fromResonance && !fsrBranching)
return true;
307 return hardProcessMotherCopy(p) != 0;
313 return p.status()==1 && fromHardProcess(p);
319 return isDecayedLeptonHadron(p) && fromHardProcess(p);
325 const P *
tau = findDecayedMother(p,15);
326 return tau && fromHardProcessDecayed(*tau);
332 const P *
tau = findDecayedMother(p,15);
333 const P *dm = findDecayedMother(p);
334 return tau && tau==dm && fromHardProcess(*tau);
340 if (p.status()==3)
return true;
343 const P *hpc = hardProcessMotherCopy(p);
344 if (!hpc)
return false;
348 if (hpc->status()==21 && (&
p)==hpc)
return true;
351 if (hpc->status()==22 && isLastCopy(p))
return true;
356 if ( (hpc->status()==23 || hpc->status()==1) && (&p)==lastDaughterCopyBeforeFSR(*hpc) )
return true;
367 return &p == firstCopy(p);
373 return &p == lastCopy(p);
379 return &p == lastCopyBeforeFSR(p);
388 dupCheck_.insert(mo);
390 if (dupCheck_.count(mo))
return 0;
400 while (previousCopy(*pcopy)) {
401 dupCheck_.insert(pcopy);
402 pcopy = previousCopy(*pcopy);
403 if (dupCheck_.count(pcopy))
return 0;
413 while (nextCopy(*pcopy)) {
414 dupCheck_.insert(pcopy);
415 pcopy = nextCopy(*pcopy);
416 if (dupCheck_.count(pcopy))
return 0;
425 const P *pcopy = firstCopy(p);
426 if (!pcopy)
return 0;
427 bool hasDaughterCopy =
true;
429 while (hasDaughterCopy) {
430 dupCheck_.insert(pcopy);
431 hasDaughterCopy =
false;
432 const unsigned int ndau = numberOfDaughters(*pcopy);
434 for (
unsigned int idau = 0; idau<ndau; ++idau) {
435 const P *dau = daughter(*pcopy,idau);
442 for (
unsigned int idau = 0; idau<ndau; ++idau) {
443 const P *dau = daughter(*pcopy,idau);
446 hasDaughterCopy =
true;
450 if (dupCheck_.count(pcopy))
return 0;
460 bool hasDaughterCopy =
true;
462 while (hasDaughterCopy) {
463 dupCheck_.insert(pcopy);
464 hasDaughterCopy =
false;
465 const unsigned int ndau = numberOfDaughters(*pcopy);
467 for (
unsigned int idau = 0; idau<ndau; ++idau) {
468 const P *dau = daughter(*pcopy,idau);
475 for (
unsigned int idau = 0; idau<ndau; ++idau) {
476 const P *dau = daughter(*pcopy,idau);
479 hasDaughterCopy =
true;
483 if (dupCheck_.count(pcopy))
return 0;
492 if (isHardProcess(p))
return &
p;
497 while (previousCopy(*pcopy)) {
498 dupCheck_.insert(pcopy);
499 pcopy = previousCopy(*pcopy);
500 if (isHardProcess(*pcopy))
return pcopy;
501 if (dupCheck_.count(pcopy))
break;
510 const unsigned int nmoth = numberOfMothers(p);
511 for (
unsigned int imoth = 0; imoth<nmoth; ++imoth) {
512 const P *moth = mother(p,imoth);
525 const unsigned int ndau = numberOfDaughters(p);
526 for (
unsigned int idau = 0; idau<ndau; ++idau) {
527 const P *dau = daughter(p,idau);
539 const P *mo = mother(p);
541 while (mo && !isDecayedLeptonHadron(*mo)) {
542 dupCheck_.insert(mo);
544 if (dupCheck_.count(mo))
return 0;
552 const P *mo = mother(p);
554 while (mo && (absPdgId(*mo)!=abspdgid || !isDecayedLeptonHadron(*mo)) ) {
555 dupCheck_.insert(mo);
557 if (dupCheck_.count(mo))
return 0;
595 return p.production_vertex() ? p.production_vertex()->particles_in_size() : 0;
607 return p.production_vertex() && p.production_vertex()->particles_in_size() ? *(p.production_vertex()->particles_in_const_begin() + imoth) : 0;
619 return p.end_vertex() ? p.end_vertex()->particles_out_size() : 0;
631 return *(p.end_vertex()->particles_out_const_begin() + idau);
const P * lastDaughterCopyBeforeFSR(const P &p)
bool isTauDecayProduct(const P &p)
void fillGenStatusFlags(const P &p, reco::GenStatusFlags &statusFlags)
virtual int pdgId() const
PDG identifier.
bool fromHardProcess(const P &p)
bool isDirectHadronDecayProduct(const P &p)
const P * hardProcessMotherCopy(const P &p)
bool isPromptMuonDecayProduct(const P &p)
bool fromHardProcessFinalState(const P &p)
unsigned int numberOfMothers(const reco::GenParticle &p)
bool isDirectPromptTauDecayProduct(const P &p)
const reco::GenParticle * daughter(const reco::GenParticle &p, unsigned int idau)
void setIsLastCopyBeforeFSR(bool b)
void setIsTauDecayProduct(bool b)
void setIsDirectPromptTauDecayProduct(bool b)
bool isPromptFinalState(const P &p)
bool isHardProcess(const P &p)
void setIsDirectHadronDecayProduct(bool b)
bool isPrompt(const P &p)
void setIsDirectHardProcessTauDecayProduct(bool b)
void setIsHardProcess(bool b)
bool isLastCopyBeforeFSR(const P &p)
unsigned int numberOfDaughters(const reco::GenParticle &p)
bool isPromptDecayed(const P &p)
bool isDirectHardProcessTauDecayProduct(const P &p)
const P * uniqueMother(const P &p)
const P * firstCopy(const P &p)
const P * findDecayedMother(const P &p)
const P * previousCopy(const P &p)
virtual size_t numberOfMothers() const
number of mothers
bool isFirstCopy(const P &p)
virtual size_t numberOfDaughters() const
number of daughters
virtual const Candidate * daughter(size_type) const
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
Abs< T >::type abs(const T &t)
void setIsHardProcessTauDecayProduct(bool b)
bool isHardProcessTauDecayProduct(const P &p)
void setFromHardProcess(bool b)
bool isDirectTauDecayProduct(const P &p)
const P * nextCopy(const P &p)
bool isHadron(const P &p)
bool fromHardProcessDecayed(const P &p)
void setIsPromptTauDecayProduct(bool b)
int absPdgId(const reco::GenParticle &p)
bool isPromptTauDecayProduct(const P &p)
void setIsDecayedLeptonHadron(bool b)
void setIsFirstCopy(bool b)
std::unordered_set< const P * > dupCheck_
bool isDecayedLeptonHadron(const P &p)
bool fromHardProcessBeforeFSR(const P &p)
bool isMuonDecayProduct(const P &p)
void setIsDirectTauDecayProduct(bool b)
void setFromHardProcessBeforeFSR(bool b)
bool isLastCopy(const P &p)
const P * lastCopy(const P &p)
void setIsLastCopy(bool b)
const P * lastCopyBeforeFSR(const P &p)
int pdgId(const reco::GenParticle &p)
virtual const Candidate * mother(size_type=0) const
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...
const reco::GenParticle * mother(const reco::GenParticle &p, unsigned int imoth=0)