CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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) More...
 
void findParticles (const reco::GenParticleCollection &sourceParticles, reco::GenParticleRefVector &particleRefs, int pdgId, int status)
 find all particles of a given pdgId and status More...
 
void findSisters (const reco::GenParticleRef &baseSister, reco::GenParticleRefVector &sisterRefs)
 find the particles having the same daughter as baseSister More...
 
bool hasAncestor (const reco::GenParticle *particle, int pdgId, int status)
 does the particle have an ancestor with this pdgId and this status? More...
 
bool isDirect (const reco::GenParticleRef &particle)
 check if particle is direct (has status 3 or is a daughter of particle with status 3) More...
 
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().

33  {
34 
35 
36  const GenParticleRefVector& daughterRefs = base->daughterRefVector();
37 
38  for(IGR idr = daughterRefs.begin();
39  idr!= daughterRefs.end(); ++idr ) {
40 
41  if( (*idr)->status() == status &&
42  (!pdgId || std::abs((*idr)->pdgId()) == pdgId) ) {
43 
44  // cout<<"adding "<<(*idr)<<endl;
45  descendents.push_back(*idr);
46  }
47  else
48  findDescendents( *idr, descendents, status, pdgId );
49  }
50  }
reco::GenParticleRefVector::const_iterator IGR
#define abs(x)
Definition: mlp_lapack.h:159
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
tuple status
Definition: ntuplemaker.py:245
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 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, relval_steps::gen(), getHLTprescales::index, reco::LeafCandidate::pdgId(), edm::RefVector< C, T, F >::push_back(), reco::LeafCandidate::status(), and ntuplemaker::status.

Referenced by TauGenJetProducer::produce().

10  {
11 
12  unsigned index = 0;
13  for(IG ig = sourceParticles.begin();
14  ig!= sourceParticles.end(); ++ig, ++index) {
15 
16  const GenParticle& gen = *ig;
17 
18  // status has been specified, and this one does not have the correct
19  // status
20  if(status && gen.status()!=status ) continue;
21 
22  if( std::abs(gen.pdgId()) == pdgId ) {
23  GenParticleRef genref( &sourceParticles, index );
24  particleRefs.push_back( genref );
25  }
26  }
27  }
virtual int pdgId() const
PDG identifier.
virtual int status() const
status word
#define abs(x)
Definition: mlp_lapack.h:159
reco::GenParticleCollection::const_iterator IG
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
tuple status
Definition: ntuplemaker.py:245
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(), errorMatrix2Lands_multiChannel::id, and edm::RefVector< C, T, F >::push_back().

56  {
57 
58  assert( baseSister->numberOfMothers() > 0 );
59 
60  // get first mother
61  const GenParticleRefVector& mothers = baseSister->motherRefVector();
62 
63  // get sisters
64  const GenParticleRefVector allRefs
65  = mothers[0]->daughterRefVector();
66 
68  for(IT id = allRefs.begin();
69  id != allRefs.end();
70  ++id ) {
71 
72  if( *id == baseSister ) {
73  continue; // this is myself
74  }
75  else
76  sisterRefs.push_back( *id );
77  }
78  }
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
std::vector< LinkConnSpec >::const_iterator IT
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
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(), reco::LeafCandidate::status(), and ntuplemaker::status.

99  {
100 
101  if( particle->pdgId() == pdgId &&
102  particle->status() == status )
103  return true;
104 
105  const GenParticleRefVector& mothers = particle->motherRefVector();
106 
107  for( IGR im = mothers.begin(); im!=mothers.end(); ++im) {
108  const GenParticle& part = **im;
109  if( hasAncestor( &part, pdgId, status) )
110  return true;
111  }
112 
113  return false;
114  }
virtual int pdgId() const
PDG identifier.
reco::GenParticleRefVector::const_iterator IGR
virtual int status() const
status word
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
const mothers & motherRefVector() const
references to mothers
part
Definition: HCALResponse.h:21
bool hasAncestor(const reco::GenParticle *particle, int pdgId, int status)
does the particle have an ancestor with this pdgId and this status?
tuple status
Definition: ntuplemaker.py:245
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.

81  {
82  assert( (particle->status() != 0) && (particle->status() < 4 ) );
83  if( particle->status() == 3 )
84  return true;
85  else {
86  assert( particle->numberOfMothers() > 0 );
87 
88  // get first mother
89  const GenParticleRefVector& mothers = particle->motherRefVector();
90  if( mothers[0]->status() == 3 )
91  return true;
92  else
93  return false;
94  }
95  }
tuple status
Definition: ntuplemaker.py:245
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.

118  {
119 
120  if(!out) return out;
121 
122  out<<genRef.key()<<" "<<genRef->pt();
123 
124  return out;
125  }
tuple out
Definition: dbtoconf.py:99
key_type key() const
Accessor for product key.
Definition: Ref.h:266