CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
read_particles_from_HepMC.cc
Go to the documentation of this file.
2 using namespace TauSpinner;
3 /*******************************************************************************
4  Get daughters of HepMC::GenParticle
5 
6  Recursively searches for final-state daughters of 'x'
7 *******************************************************************************/
8 inline std::vector<SimpleParticle> *getDaughters(HepMC::GenParticle *x)
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 }
38 
39 
40 /*******************************************************************************
41  Find last self
42 
43  Recursively finds the last particle with the same PDG ID
44  on the list of its decay products
45 *******************************************************************************/
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 }
57 
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 }
64 
65 /*******************************************************************************
66  Read HepMC::GenEvent.
67 
68  Read HepMC event from data file
69  and return particles filtered out from the event.
70 
71  This routine is prepared for use with files generated by Pythia8.
72  Fills:
73 
74  'X' - Heavy particle (W+/-, H+/-, H, Z)
75  'tau' - first tau
76  'tau2' - second tau or nu_tau, if 'X' decays to one tau only
77  'tau_daughters' - daughters of 'tau'
78  'tau2_daughters' - daughters of 'tau2' or empty list, if 'tau2' is nu_tau.
79 
80  Returns:
81  0 - no more events to read (finished processing the file)
82  1 - no decay found in the event (finished processing current event)
83  2 - decay found and processed correctly.
84  Event will continue to be processed
85  with next function call.
86 *******************************************************************************/
87 int readParticlesFromHepMC(const HepMC::GenEvent *event, SimpleParticle &X, SimpleParticle &tau, SimpleParticle &tau2, std::vector<SimpleParticle> &tau_daughters, std::vector<SimpleParticle> &tau2_daughters)
88 {
89  if(event==NULL) return 1;
90 
91  // Exctract particles from event
92  HepMC::GenParticle *hX=NULL, *hTau=NULL, *hTau2=NULL;
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 = NULL;
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 }
HepMC::GenParticle * findLastSelf(HepMC::GenParticle *x)
TPRegexp parents
Definition: eve_filter.cc:21
tuple pp
Definition: createTree.py:15
isFirst
Definition: cuy.py:417
#define X(str)
Definition: MuonsGrabber.cc:48
#define NULL
Definition: scimark2.h:8
std::vector< TauSpinner::SimpleParticle > * getDaughters(HepMC::GenParticle *x)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
int readParticlesFromHepMC(const HepMC::GenEvent *event, TauSpinner::SimpleParticle &X, TauSpinner::SimpleParticle &tau, TauSpinner::SimpleParticle &tau2, std::vector< TauSpinner::SimpleParticle > &tau_daughters, std::vector< TauSpinner::SimpleParticle > &tau2_daughters)
tuple cout
Definition: gather_cfg.py:121