CMS 3D CMS Logo

Functions
read_particles_from_HepMC.cc File Reference
#include "GeneratorInterface/TauolaInterface/interface/read_particles_from_HepMC.h"

Go to the source code of this file.

Functions

HepMC::GenParticle * findLastSelf (HepMC::GenParticle *x)
 
std::vector< SimpleParticle > * getDaughters (HepMC::GenParticle *x)
 
bool isFirst (HepMC::GenParticle *x)
 
int readParticlesFromHepMC (const HepMC::GenEvent *event, SimpleParticle &X, SimpleParticle &tau, SimpleParticle &tau2, std::vector< SimpleParticle > &tau_daughters, std::vector< SimpleParticle > &tau2_daughters)
 

Function Documentation

HepMC::GenParticle* findLastSelf ( HepMC::GenParticle *  x)
inline

Definition at line 46 of file read_particles_from_HepMC.cc.

References class-composition::children, AlCaHLTBitMon_ParallelJobs::p, and x.

Referenced by readParticlesFromHepMC().

47 {
48  if(!x->end_vertex()) return x;
49 
50  for(HepMC::GenVertex::particle_iterator p = x->end_vertex()->particles_begin(HepMC::children); p!=x->end_vertex()->particles_end(HepMC::children); ++p)
51  {
52  if( (*p)->pdg_id()==x->pdg_id() ) return findLastSelf( *p );
53  }
54 
55  return x;
56 }
HepMC::GenParticle * findLastSelf(HepMC::GenParticle *x)
std::vector<SimpleParticle>* getDaughters ( HepMC::GenParticle *  x)
inline

Definition at line 8 of file read_particles_from_HepMC.cc.

References BPhysicsValidation_cfi::daughters, GenParticle::GenParticle, AlCaHLTBitMon_ParallelJobs::p, and createTree::pp.

Referenced by readParticlesFromHepMC().

9 {
10  std::vector<SimpleParticle> *daughters = new std::vector<SimpleParticle>();
11  if(!x->end_vertex()) return daughters;
12 
13  // Check decay products of 'x'
14  for(HepMC::GenVertex::particles_out_const_iterator p = x->end_vertex()->particles_out_const_begin(); p!=x->end_vertex()->particles_out_const_end(); ++p)
15  {
17  HepMC::FourVector mm = pp->momentum();
18 
19  // If the daughter of 'x' has its end vertex - recursively read
20  // all of its daughters.
21  if( pp->end_vertex() && pp->pdg_id()!=111)
22  {
23  std::vector<SimpleParticle> *sub_daughters = getDaughters(pp);
24  daughters->insert(daughters->end(),sub_daughters->begin(),sub_daughters->end());
25 
26  delete sub_daughters;
27  }
28  // Otherwise - add this particle to the list of daughters.
29  else if(pp->pdg_id()!=x->pdg_id())
30  {
31  SimpleParticle tp( mm.px(), mm.py(), mm.pz(), mm.e(), pp->pdg_id() );
32  daughters->push_back(tp);
33  }
34  }
35 
36  return daughters;
37 }
std::vector< SimpleParticle > * getDaughters(HepMC::GenParticle *x)
bool isFirst ( HepMC::GenParticle *  x)
inline

Definition at line 58 of file read_particles_from_HepMC.cc.

References AlCaHLTBitMon_ParallelJobs::p, and parents.

Referenced by readParticlesFromHepMC().

58  {
59  for(HepMC::GenVertex::particle_iterator p = x->production_vertex()->particles_begin(HepMC::parents); p!=x->production_vertex()->particles_end(HepMC::parents); ++p){
60  if(x->pdg_id()==(*p)->pdg_id()) return false;
61  }
62  return true;
63 }
TPRegexp parents
Definition: eve_filter.cc:21
int readParticlesFromHepMC ( const HepMC::GenEvent event,
SimpleParticle &  X,
SimpleParticle &  tau,
SimpleParticle &  tau2,
std::vector< SimpleParticle > &  tau_daughters,
std::vector< SimpleParticle > &  tau2_daughters 
)

Definition at line 87 of file read_particles_from_HepMC.cc.

References funct::abs(), class-composition::children, gather_cfg::cout, findLastSelf(), GenParticle::GenParticle, getDaughters(), isFirst(), and BPhysicsValidation_cfi::pdgid.

88 {
89  if(event==nullptr) return 1;
90 
91  // Exctract particles from event
92  HepMC::GenParticle *hX=nullptr, *hTau=nullptr, *hTau2=nullptr;
93 
94  for(HepMC::GenEvent::particle_const_iterator it = event->particles_begin(); it!=event->particles_end(); ++it)
95  {
96  int pdgid = (*it)->pdg_id();
97  if(
98  (
99  abs(pdgid)==37 ||
100  pdgid ==25 ||
101  abs(pdgid)==24 ||
102  pdgid ==23
103  ) &&
104  (*it)->end_vertex() &&
105  (*it)->end_vertex()->particles_out_size()>=2
106  )
107  {
108  hX = *it;
109  HepMC::GenParticle *LhX=hX;
110  if(!isFirst(hX)) continue;
111  findLastSelf(LhX);
112  hTau = hTau2 = nullptr;
113 
114  for(HepMC::GenVertex::particle_iterator it2 = LhX->end_vertex()->particles_begin(HepMC::children); it2!=LhX->end_vertex()->particles_end(HepMC::children); ++it2)
115  {
116  if (abs( (*it2)->pdg_id() )==15 && (*it2)->end_vertex() ){
117  if(!hTau) hTau = *it2;
118  else if(!hTau2) hTau2 = *it2;
119  else
120  {
121  std::cout<<"TauSpiner: three taus in one decay"<<std::endl;
122  return 1;
123  }
124  }
125  if (abs( (*it2)->pdg_id() )==16 )
126  {
127  if(!hTau2) hTau2 = *it2;
128  else
129  {
130  std::cout<<"TauSpiner: two neutrinos or two taus and neutrino in one decay"<<std::endl;
131  return 1;
132  }
133  }
134  }
135  if(hTau && hTau2) break;
136 
137  }
138  }
139 
140  if(!hX) return 1;
141 
142  if(!hTau || !hTau2)
143  {
144  //std::cout<<"TauSpiner: boson found but no proper tau pair or tau + neutrino found."<<std::endl;
145  return 1;
146  }
147 
148  // Check for self-decaying taus
149  hTau = findLastSelf(hTau);
150  hTau2 = findLastSelf(hTau2);
151 
152  // Fill SimpleParticles from HepMC particles
153  X.setPx(hX->momentum().px());
154  X.setPy(hX->momentum().py());
155  X.setPz(hX->momentum().pz());
156  X.setE (hX->momentum().e ());
157  X.setPdgid(hX->pdg_id());
158 
159  tau.setPx(hTau->momentum().px());
160  tau.setPy(hTau->momentum().py());
161  tau.setPz(hTau->momentum().pz());
162  tau.setE (hTau->momentum().e ());
163  tau.setPdgid(hTau->pdg_id());
164 
165  tau2.setPx(hTau2->momentum().px());
166  tau2.setPy(hTau2->momentum().py());
167  tau2.setPz(hTau2->momentum().pz());
168  tau2.setE (hTau2->momentum().e ());
169  tau2.setPdgid(hTau2->pdg_id());
170 
171  // Create list of tau daughters
172  std::vector<SimpleParticle> *buf = getDaughters(hTau);
173  tau_daughters.clear();
174  tau_daughters.insert(tau_daughters.end(),buf->begin(),buf->end());
175 
176  delete buf;
177 
178  // Second particle can be 2nd tau. In that case - read its daughters.
179  // Otherwise it is nu_tau~
180  buf = getDaughters(hTau2);
181  tau2_daughters.clear();
182  tau2_daughters.insert(tau2_daughters.end(),buf->begin(),buf->end());
183 
184  delete buf;
185 
186  return 0;
187 }
std::vector< SimpleParticle > * getDaughters(HepMC::GenParticle *x)
#define X(str)
Definition: MuonsGrabber.cc:48
bool isFirst(HepMC::GenParticle *x)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HepMC::GenParticle * findLastSelf(HepMC::GenParticle *x)