Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes for GenParticle status flags #8006

Merged
merged 2 commits into from Mar 2, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
88 changes: 58 additions & 30 deletions PhysicsTools/HepMCCandAlgos/interface/MCTruthHelper.h
Expand Up @@ -148,6 +148,10 @@ namespace MCTruthHelper {
template<typename P>
const P *hardProcessMotherCopy(const P &p);

//return previous copy of particle in chain (0 in case this is already the first copy)
template<typename P>
const P *previousCopy(const P &p);

//return next copy of particle in chain (0 in case this is already the last copy)
template<typename P>
const P *nextCopy(const P &p);
Expand Down Expand Up @@ -175,12 +179,18 @@ namespace MCTruthHelper {

//abs(pdgid)
int absPdgId(const HepMC::GenParticle &p);

//number of mothers
unsigned int numberOfMothers(const reco::GenParticle &p);

//number of mothers
unsigned int numberOfMothers(const HepMC::GenParticle &p);

//mother
const reco::GenParticle *mother(const reco::GenParticle &p);
const reco::GenParticle *mother(const reco::GenParticle &p, unsigned int imoth=0);

//mother
const HepMC::GenParticle *mother(const HepMC::GenParticle &p);
const HepMC::GenParticle *mother(const HepMC::GenParticle &p, unsigned int imoth=0);

//number of daughters
unsigned int numberOfDaughters(const reco::GenParticle &p);
Expand Down Expand Up @@ -247,15 +257,17 @@ namespace MCTruthHelper {
/////////////////////////////////////////////////////////////////////////////
template<typename P>
bool isDirectTauDecayProduct(const P &p) {
const P *um = uniqueMother(p);
return um && absPdgId(*um)==15 && isDecayedLeptonHadron(*um);
const P *tau = findDecayedMother(p,15);
const P *dm = findDecayedMother(p);
return tau && tau==dm;
}

/////////////////////////////////////////////////////////////////////////////
template<typename P>
bool isDirectPromptTauDecayProduct(const P &p) {
const P *um = uniqueMother(p);
return um && absPdgId(*um)==15 && isDecayedLeptonHadron(*um) && isPrompt(*um);
const P *tau = findDecayedMother(p,15);
const P *dm = findDecayedMother(p);
return tau && tau==dm && isPrompt(*tau);
}

/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -343,8 +355,9 @@ namespace MCTruthHelper {
/////////////////////////////////////////////////////////////////////////////
template<typename P>
bool isDirectHardProcessTauDecayProduct(const P &p) {
const P *um = uniqueMother(p);
return um && absPdgId(*um)==15 && isDecayedLeptonHadron(*um) && fromHardProcess(*um);
const P *tau = findDecayedMother(p,15);
const P *dm = findDecayedMother(p);
return tau && tau==dm && fromHardProcess(*tau);
}

template<typename P>
Expand Down Expand Up @@ -406,8 +419,8 @@ namespace MCTruthHelper {
template<typename P>
const P *firstCopy(const P &p) {
const P *pcopy = &p;
while (mother(*pcopy) && pdgId(*mother(*pcopy))==pdgId(p)) {
pcopy = mother(*pcopy);
while (previousCopy(*pcopy)) {
pcopy = previousCopy(*pcopy);
}
return pcopy;
}
Expand All @@ -416,22 +429,12 @@ namespace MCTruthHelper {
template<typename P>
const P *lastCopy(const P &p) {
const P *pcopy = &p;
bool hasDaughterCopy = true;
while (hasDaughterCopy) {
hasDaughterCopy = false;
const unsigned int ndau = numberOfDaughters(*pcopy);
for (unsigned int idau = 0; idau<ndau; ++idau) {
const P *dau = daughter(*pcopy,idau);
if (pdgId(*dau)==pdgId(p)) {
pcopy = dau;
hasDaughterCopy = true;
break;
}
}
while (nextCopy(*pcopy)) {
pcopy = nextCopy(*pcopy);
}
return pcopy;
return pcopy;
}

/////////////////////////////////////////////////////////////////////////////
template<typename P>
const P *lastCopyBeforeFSR(const P &p) {
Expand Down Expand Up @@ -500,13 +503,28 @@ namespace MCTruthHelper {

//check if any other copies are hard process particles
const P *pcopy = &p;
while (mother(*pcopy) && pdgId(*mother(*pcopy))==pdgId(p)) {
pcopy = mother(*pcopy);
while (previousCopy(*pcopy)) {
pcopy = previousCopy(*pcopy);
if (isHardProcess(*pcopy)) return pcopy;
}
return 0;
}

/////////////////////////////////////////////////////////////////////////////
template<typename P>
const P *previousCopy(const P &p) {

const unsigned int nmoth = numberOfMothers(p);
for (unsigned int imoth = 0; imoth<nmoth; ++imoth) {
const P *moth = mother(p,imoth);
if (pdgId(*moth)==pdgId(p)) {
return moth;
}
}

return 0;
}

/////////////////////////////////////////////////////////////////////////////
template<typename P>
const P *nextCopy(const P &p) {
Expand Down Expand Up @@ -563,13 +581,23 @@ namespace MCTruthHelper {
}

/////////////////////////////////////////////////////////////////////////////
const reco::GenParticle *mother(const reco::GenParticle &p) {
return static_cast<const reco::GenParticle*>(p.mother());
unsigned int numberOfMothers(const reco::GenParticle &p) {
return p.numberOfMothers();
}

/////////////////////////////////////////////////////////////////////////////
unsigned int numberOfMothers(const HepMC::GenParticle &p) {
return p.production_vertex() ? p.production_vertex()->particles_in_size() : 0;
}

/////////////////////////////////////////////////////////////////////////////
const reco::GenParticle *mother(const reco::GenParticle &p, unsigned int imoth) {
return static_cast<const reco::GenParticle*>(p.mother(imoth));
}

/////////////////////////////////////////////////////////////////////////////
const HepMC::GenParticle *mother(const HepMC::GenParticle &p) {
return p.production_vertex() && p.production_vertex()->particles_in_size() ? *p.production_vertex()->particles_in_const_begin() : 0;
const HepMC::GenParticle *mother(const HepMC::GenParticle &p, unsigned int imoth) {
return p.production_vertex() && p.production_vertex()->particles_in_size() ? *(p.production_vertex()->particles_in_const_begin() + imoth) : 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bendavid - i'm not following this last line - the meaning o imoth seems to be the pdgId?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, imoth is the index of the mother in the list of mothers. (Yes, genparticles can have more than one mother)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this really is supposed to be pointer arithmetic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so why “15”, which I had assumed was the pdgId of a tau?

On Mar 2, 2015, at 6:07 PM, Josh Bendavid notifications@github.com wrote:

In PhysicsTools/HepMCCandAlgos/interface/MCTruthHelper.h:

}

/////////////////////////////////////////////////////////////////////////////

  • const HepMC::GenParticle *mother(const HepMC::GenParticle &p) {
  • return p.production_vertex() && p.production_vertex()->particles_in_size() ? *p.production_vertex()->particles_in_const_begin() : 0;
  • const HepMC::GenParticle *mother(const HepMC::GenParticle &p, unsigned int imoth) {
  • return p.production_vertex() && p.production_vertex()->particles_in_size() ? *(p.production_vertex()->particles_in_const_begin() + imoth) : 0;
    }

No, imoth is the index of the mother in the list of mothers. (Yes, genparticles can have more than one mother)


Reply to this email directly or view it on GitHub.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, where is this function called with 15?
There is "findDecayedMother" which is a different function, and there the input parameter is indeed a pdg id.


/////////////////////////////////////////////////////////////////////////////
Expand Down