CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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

◆ findLastSelf()

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

Definition at line 44 of file read_particles_from_HepMC.cc.

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

Referenced by readParticlesFromHepMC().

44  {
45  if (!x->end_vertex())
46  return x;
47 
48  for (HepMC::GenVertex::particle_iterator p = x->end_vertex()->particles_begin(HepMC::children);
49  p != x->end_vertex()->particles_end(HepMC::children);
50  ++p) {
51  if ((*p)->pdg_id() == x->pdg_id())
52  return findLastSelf(*p);
53  }
54 
55  return x;
56 }
HepMC::GenParticle * findLastSelf(HepMC::GenParticle *x)
float x

◆ getDaughters()

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, createTree::pp, cmsswSequenceInfo::tp, and x.

Referenced by readParticlesFromHepMC().

8  {
9  std::vector<SimpleParticle> *daughters = new std::vector<SimpleParticle>();
10  if (!x->end_vertex())
11  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();
15  p != x->end_vertex()->particles_out_const_end();
16  ++p) {
18  HepMC::FourVector mm = pp->momentum();
19 
20  // If the daughter of 'x' has its end vertex - recursively read
21  // all of its daughters.
22  if (pp->end_vertex() && pp->pdg_id() != 111) {
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  SimpleParticle tp(mm.px(), mm.py(), mm.pz(), mm.e(), pp->pdg_id());
31  daughters->push_back(tp);
32  }
33  }
34 
35  return daughters;
36 }
std::vector< SimpleParticle > * getDaughters(HepMC::GenParticle *x)
float x

◆ isFirst()

bool isFirst ( HepMC::GenParticle *  x)
inline

Definition at line 58 of file read_particles_from_HepMC.cc.

References AlCaHLTBitMon_ParallelJobs::p, parents, and x.

Referenced by readParticlesFromHepMC().

58  {
59  for (HepMC::GenVertex::particle_iterator p = x->production_vertex()->particles_begin(HepMC::parents);
60  p != x->production_vertex()->particles_end(HepMC::parents);
61  ++p) {
62  if (x->pdg_id() == (*p)->pdg_id())
63  return false;
64  }
65  return true;
66 }
TPRegexp parents
Definition: eve_filter.cc:21
float x

◆ readParticlesFromHepMC()

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 90 of file read_particles_from_HepMC.cc.

References funct::abs(), visDQMUpload::buf, class-composition::children, gather_cfg::cout, findLastSelf(), GenParticle::GenParticle, getDaughters(), isFirst(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, EgammaValidation_cff::pdgid, jetsAK8_cff::tau2, and X.

95  {
96  if (event == nullptr)
97  return 1;
98 
99  // Exctract particles from event
100  HepMC::GenParticle *hX = nullptr, *hTau = nullptr, *hTau2 = nullptr;
101 
102  for (HepMC::GenEvent::particle_const_iterator it = event->particles_begin(); it != event->particles_end(); ++it) {
103  int pdgid = (*it)->pdg_id();
104  if ((abs(pdgid) == 37 || pdgid == 25 || abs(pdgid) == 24 || pdgid == 23) && (*it)->end_vertex() &&
105  (*it)->end_vertex()->particles_out_size() >= 2) {
106  hX = *it;
107  HepMC::GenParticle *LhX = hX;
108  if (!isFirst(hX))
109  continue;
110  findLastSelf(LhX);
111  hTau = hTau2 = nullptr;
112 
113  for (HepMC::GenVertex::particle_iterator it2 = LhX->end_vertex()->particles_begin(HepMC::children);
114  it2 != LhX->end_vertex()->particles_end(HepMC::children);
115  ++it2) {
116  if (abs((*it2)->pdg_id()) == 15 && (*it2)->end_vertex()) {
117  if (!hTau)
118  hTau = *it2;
119  else if (!hTau2)
120  hTau2 = *it2;
121  else {
122  std::cout << "TauSpiner: three taus in one decay" << std::endl;
123  return 1;
124  }
125  }
126  if (abs((*it2)->pdg_id()) == 16) {
127  if (!hTau2)
128  hTau2 = *it2;
129  else {
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)
136  break;
137  }
138  }
139 
140  if (!hX)
141  return 1;
142 
143  if (!hTau || !hTau2) {
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:38
bool isFirst(HepMC::GenParticle *x)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HepMC::GenParticle * findLastSelf(HepMC::GenParticle *x)
Definition: event.py:1