1 #ifndef PhysicsTools_HepMCCandAlgos_GenParticlesHelper_h
2 #define PhysicsTools_HepMCCandAlgos_GenParticlesHelper_h
5 #include "HepPDT/ParticleID.hh"
197 return findDecayedMother(p) == 0;
203 return p.status()==1 && isPrompt(p);
208 return p.status()==2 && (isHadron(p) || absPdgId(p)==13 || absPdgId(p)==15) && isLastCopy(p);
213 return isDecayedLeptonHadron(p) && isPrompt(p);
219 return findDecayedMother(p,15) != 0;
225 const P *
tau = findDecayedMother(p,15);
226 return tau && isPrompt(*tau);
232 const P *
tau = findDecayedMother(p,15);
233 const P *dm = findDecayedMother(p);
234 return tau && tau==dm;
240 const P *
tau = findDecayedMother(p,15);
241 const P *dm = findDecayedMother(p);
242 return tau && tau==dm && isPrompt(*tau);
248 return findDecayedMother(p,13) != 0;
254 const P *
mu = findDecayedMother(p,13);
255 return mu && isPrompt(*mu);
261 const P *um = uniqueMother(p);
262 return um && isHadron(*um) && isDecayedLeptonHadron(*um);
269 return heppdtid.isHadron();
277 if (p.status()==3)
return true;
280 if (p.status()>20 && p.status()<30)
return true;
286 if (p.status()==1 || p.status()==2) {
287 const P *um = mother(p);
289 const P *firstcopy = firstCopy(*um);
290 bool fromResonance = firstcopy && firstcopy->status()==22;
292 const P *umNext = nextCopy(*um);
293 bool fsrBranching = umNext && umNext->status()>50 && umNext->status()<60;
295 if (fromResonance && !fsrBranching)
return true;
306 return hardProcessMotherCopy(p) != 0;
312 return p.status()==1 && fromHardProcess(p);
318 return isDecayedLeptonHadron(p) && fromHardProcess(p);
324 const P *
tau = findDecayedMother(p,15);
325 return tau && fromHardProcessDecayed(*tau);
331 const P *
tau = findDecayedMother(p,15);
332 const P *dm = findDecayedMother(p);
333 return tau && tau==dm && fromHardProcess(*tau);
339 if (p.status()==3)
return true;
342 const P *hpc = hardProcessMotherCopy(p);
343 if (!hpc)
return false;
347 if (hpc->status()==21 && (&
p)==hpc)
return true;
350 if (hpc->status()==22 && isLastCopy(p))
return true;
355 if ( (hpc->status()==23 || hpc->status()==1) && (&p)==lastDaughterCopyBeforeFSR(*hpc) )
return true;
366 return &p == firstCopy(p);
372 return &p == lastCopy(p);
378 return &p == lastCopyBeforeFSR(p);
387 dupCheck_.insert(mo);
389 if (dupCheck_.count(mo))
return 0;
399 while (previousCopy(*pcopy)) {
400 dupCheck_.insert(pcopy);
401 pcopy = previousCopy(*pcopy);
402 if (dupCheck_.count(pcopy))
return 0;
412 while (nextCopy(*pcopy)) {
413 dupCheck_.insert(pcopy);
414 pcopy = nextCopy(*pcopy);
415 if (dupCheck_.count(pcopy))
return 0;
424 const P *pcopy = firstCopy(p);
425 if (!pcopy)
return 0;
426 bool hasDaughterCopy =
true;
428 while (hasDaughterCopy) {
429 dupCheck_.insert(pcopy);
430 hasDaughterCopy =
false;
431 const unsigned int ndau = numberOfDaughters(*pcopy);
433 for (
unsigned int idau = 0; idau<ndau; ++idau) {
434 const P *dau = daughter(*pcopy,idau);
441 for (
unsigned int idau = 0; idau<ndau; ++idau) {
442 const P *dau = daughter(*pcopy,idau);
445 hasDaughterCopy =
true;
449 if (dupCheck_.count(pcopy))
return 0;
459 bool hasDaughterCopy =
true;
461 while (hasDaughterCopy) {
462 dupCheck_.insert(pcopy);
463 hasDaughterCopy =
false;
464 const unsigned int ndau = numberOfDaughters(*pcopy);
466 for (
unsigned int idau = 0; idau<ndau; ++idau) {
467 const P *dau = daughter(*pcopy,idau);
474 for (
unsigned int idau = 0; idau<ndau; ++idau) {
475 const P *dau = daughter(*pcopy,idau);
478 hasDaughterCopy =
true;
482 if (dupCheck_.count(pcopy))
return 0;
491 if (isHardProcess(p))
return &
p;
496 while (previousCopy(*pcopy)) {
497 dupCheck_.insert(pcopy);
498 pcopy = previousCopy(*pcopy);
499 if (isHardProcess(*pcopy))
return pcopy;
500 if (dupCheck_.count(pcopy))
break;
509 const unsigned int nmoth = numberOfMothers(p);
510 for (
unsigned int imoth = 0; imoth<nmoth; ++imoth) {
511 const P *moth = mother(p,imoth);
524 const unsigned int ndau = numberOfDaughters(p);
525 for (
unsigned int idau = 0; idau<ndau; ++idau) {
526 const P *dau = daughter(p,idau);
538 const P *mo = mother(p);
540 while (mo && !isDecayedLeptonHadron(*mo)) {
541 dupCheck_.insert(mo);
543 if (dupCheck_.count(mo))
return 0;
551 const P *mo = mother(p);
553 while (mo && (absPdgId(*mo)!=abspdgid || !isDecayedLeptonHadron(*mo)) ) {
554 dupCheck_.insert(mo);
556 if (dupCheck_.count(mo))
return 0;
594 return p.production_vertex() ? p.production_vertex()->particles_in_size() : 0;
606 return p.production_vertex() && p.production_vertex()->particles_in_size() ? *(p.production_vertex()->particles_in_const_begin() + imoth) : 0;
618 return p.end_vertex() ? p.end_vertex()->particles_out_size() : 0;
630 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)