CMS 3D CMS Logo

Typedefs | Functions

GenParticlesHelper Namespace Reference

Typedefs

typedef
reco::GenParticleCollection::const_iterator 
IG
typedef
reco::GenParticleRefVector::const_iterator 
IGR

Functions

void findDescendents (const reco::GenParticleRef &base, reco::GenParticleRefVector &descendents, int status, int pdgId=0)
 find all descendents of a given status and pdgId (recursive)
void findParticles (const reco::GenParticleCollection &sourceParticles, reco::GenParticleRefVector &particleRefs, int pdgId, int status)
 find all particles of a given pdgId and status
void findSisters (const reco::GenParticleRef &baseSister, reco::GenParticleRefVector &sisterRefs)
 find the particles having the same daughter as baseSister
bool hasAncestor (const reco::GenParticle *particle, int pdgId, int status)
 does the particle have an ancestor with this pdgId and this status?
bool isDirect (const reco::GenParticleRef &particle)
 check if particle is direct (has status 3 or is a daughter of particle with status 3)
std::ostream & operator<< (std::ostream &out, const reco::GenParticleRef &genRef)

Typedef Documentation

typedef reco::GenParticleCollection::const_iterator GenParticlesHelper::IG

Definition at line 10 of file GenParticlesHelper.h.

Definition at line 11 of file GenParticlesHelper.h.


Function Documentation

void GenParticlesHelper::findDescendents ( const reco::GenParticleRef base,
reco::GenParticleRefVector descendents,
int  status,
int  pdgId = 0 
)

find all descendents of a given status and pdgId (recursive)

Definition at line 31 of file GenParticlesHelper.cc.

References abs, edm::RefVector< C, T, F >::begin(), edm::RefVector< C, T, F >::end(), and edm::RefVector< C, T, F >::push_back().

Referenced by TauGenJetProducer::produce().

                                          {


    const GenParticleRefVector& daughterRefs = base->daughterRefVector();
  
    for(IGR idr = daughterRefs.begin(); 
        idr!= daughterRefs.end(); ++idr ) {
    
      if( (*idr)->status() == status && 
          (!pdgId || std::abs((*idr)->pdgId()) == pdgId) ) {
      
        // cout<<"adding "<<(*idr)<<endl;
        descendents.push_back(*idr);
      }
      else 
        findDescendents( *idr, descendents, status, pdgId );
    }
  }
void GenParticlesHelper::findParticles ( const reco::GenParticleCollection sourceParticles,
reco::GenParticleRefVector particleRefs,
int  pdgId,
int  status 
)

find all particles of a given pdgId and status

Definition at line 10 of file GenParticlesHelper.cc.

References abs, cmsDownloadME::gen, getHLTprescales::index, reco::LeafCandidate::pdgId(), edm::RefVector< C, T, F >::push_back(), ntuplemaker::status, and reco::LeafCandidate::status().

Referenced by TauGenJetProducer::produce().

                                                                                                                                  {

    unsigned index = 0;
    for(IG ig = sourceParticles.begin(); 
        ig!= sourceParticles.end(); ++ig, ++index) {
 
      const GenParticle& gen = *ig;
    
      // status has been specified, and this one does not have the correct
      // status
      if(status && gen.status()!=status ) continue;
    
      if( std::abs(gen.pdgId()) == pdgId ) {
        GenParticleRef genref( &sourceParticles, index );
        particleRefs.push_back( genref );
      }
    }
  }
void GenParticlesHelper::findSisters ( const reco::GenParticleRef baseSister,
reco::GenParticleRefVector sisterRefs 
)

find the particles having the same daughter as baseSister

Definition at line 55 of file GenParticlesHelper.cc.

References edm::RefVector< C, T, F >::begin(), edm::RefVector< C, T, F >::end(), and edm::RefVector< C, T, F >::push_back().

                                                {
  
    assert( baseSister->numberOfMothers() > 0 );
  
    // get first mother 
    const GenParticleRefVector& mothers = baseSister->motherRefVector();
  
    // get sisters 
    const GenParticleRefVector allRefs 
      = mothers[0]->daughterRefVector();
  
    typedef GenParticleRefVector::const_iterator IT;
    for(IT id = allRefs.begin();
        id != allRefs.end();
        ++id ) {
    
      if( *id == baseSister ) { 
        continue; // this is myself
      }
      else 
        sisterRefs.push_back( *id );
    }
  }
bool GenParticlesHelper::hasAncestor ( const reco::GenParticle particle,
int  pdgId,
int  status 
)

does the particle have an ancestor with this pdgId and this status?

Definition at line 98 of file GenParticlesHelper.cc.

References edm::RefVector< C, T, F >::begin(), edm::RefVector< C, T, F >::end(), reco::CompositeRefCandidateT< D >::motherRefVector(), reco::LeafCandidate::pdgId(), ntuplemaker::status, and reco::LeafCandidate::status().

                                             {    
 
    if( particle->pdgId() == pdgId && 
        particle->status() == status )
      return true;

    const GenParticleRefVector& mothers = particle->motherRefVector();
    
    for( IGR im = mothers.begin(); im!=mothers.end(); ++im) {
      const GenParticle& part = **im;
      if( hasAncestor( &part, pdgId, status) )
        return true;
    } 

    return false;
  }
bool GenParticlesHelper::isDirect ( const reco::GenParticleRef particle)

check if particle is direct (has status 3 or is a daughter of particle with status 3)

Definition at line 81 of file GenParticlesHelper.cc.

References ntuplemaker::status.

                                               {
    assert( (particle->status() != 0) && (particle->status() < 4 ) );
    if( particle->status() == 3 )
      return true;
    else {
      assert( particle->numberOfMothers() > 0 );
  
      // get first mother 
      const GenParticleRefVector& mothers = particle->motherRefVector();
      if( mothers[0]->status() == 3 )
        return true;
      else
        return false;
    }
  }
std::ostream & GenParticlesHelper::operator<< ( std::ostream &  out,
const reco::GenParticleRef genRef 
)

Definition at line 117 of file GenParticlesHelper.cc.

References edm::Ref< C, T, F >::key(), and dbtoconf::out.

                                                               {
    
    if(!out) return out;
    
    out<<genRef.key()<<" "<<genRef->pt();
    
    return out;
  }