CMS 3D CMS Logo

FBaseSimEvent.cc
Go to the documentation of this file.
1 //HepMC Headers
2 #include "HepMC/GenEvent.h"
3 #include "HepMC/GenVertex.h"
4 #include "HepMC/GenParticle.h"
5 
6 //Framework Headers
8 
9 //CMSSW Data Formats
12 
13 //FAMOS Headers
21 
23 
24 using namespace HepPDT;
25 
26 // system include
27 #include <iostream>
28 #include <iomanip>
29 #include <map>
30 #include <string>
31 
33  : nSimTracks(0), nSimVertices(0), nGenParticles(0), nChargedParticleTracks(0), initialSize(5000) {
34  // Initialize the vectors of particles and vertices
35  theGenParticles = new std::vector<HepMC::GenParticle*>();
36  theSimTracks = new std::vector<FSimTrack>;
37  theSimVertices = new std::vector<FSimVertex>;
38  theChargedTracks = new std::vector<unsigned>();
40 
41  // Reserve some size to avoid mutiple copies
42  /* */
43  theSimTracks->resize(initialSize);
44  theSimVertices->resize(initialSize);
52  /* */
53 
54  // Initialize the Particle filter
55  myFilter = new KineParticleFilter(kine);
56 
57  // Initialize the distance from (0,0,0) after which *generated* particles are
58  // no longer considered - because the mother could have interacted before.
59  // unit : cm x cm
60  lateVertexPosition = 2.5 * 2.5;
61 }
62 
64  // Clear the vectors
65  theGenParticles->clear();
66  theSimTracks->clear();
67  theSimVertices->clear();
68  theChargedTracks->clear();
69  theFSimVerticesType->clear();
70 
71  // Delete
72  delete theGenParticles;
73  delete theSimTracks;
74  delete theSimVertices;
75  delete theChargedTracks;
76  delete theFSimVerticesType;
77  delete myFilter;
78 }
79 
81 
82 void FBaseSimEvent::fill(const HepMC::GenEvent& myGenEvent) {
83  // Clear old vectors
84  clear();
85 
86  // Add the particles in the FSimEvent
87  addParticles(myGenEvent);
88 }
89 
90 void FBaseSimEvent::fill(const std::vector<SimTrack>& simTracks, const std::vector<SimVertex>& simVertices) {
91  // Watch out there ! A SimVertex is in mm (stupid),
92  // while a FSimVertex is in cm (clever).
93 
94  clear();
95 
96  unsigned nVtx = simVertices.size();
97  unsigned nTks = simTracks.size();
98 
99  // Empty event, do nothin'
100  if (nVtx == 0)
101  return;
102 
103  // Two arrays for internal use.
104  std::vector<int> myVertices(nVtx, -1);
105  std::vector<int> myTracks(nTks, -1);
106 
107  // create a map associating geant particle id and position in the
108  // event SimTrack vector
109 
110  std::map<unsigned, unsigned> geantToIndex;
111  for (unsigned it = 0; it < simTracks.size(); ++it) {
112  geantToIndex[simTracks[it].trackId()] = it;
113  }
114 
115  // Create also a map associating a SimTrack with its endVertex
116  /*
117  std::map<unsigned, unsigned> endVertex;
118  for ( unsigned iv=0; iv<simVertices.size(); ++iv ) {
119  endVertex[ simVertices[iv].parentIndex() ] = iv;
120  }
121  */
122 
123  // Set the main vertex for the kine particle filter
124  // SimVertices were in mm until 110_pre2
125  // HepLorentzVector primaryVertex = simVertices[0].position()/10.;
126  // SImVertices are now in cm
127  // Also : position is copied until SimVertex switches to Mathcore.
128  // XYZTLorentzVector primaryVertex = simVertices[0].position();
129  // The next 5 lines to be then replaced by the previous line
130  XYZTLorentzVector primaryVertex(simVertices[0].position().x(),
131  simVertices[0].position().y(),
132  simVertices[0].position().z(),
133  simVertices[0].position().t());
134  //
135  //myFilter->setMainVertex(primaryVertex);
136  // Add the main vertex to the list.
137  addSimVertex(/*myFilter->vertex()*/ primaryVertex, -1, FSimVertexType::PRIMARY_VERTEX);
138  myVertices[0] = 0;
139 
140  for (unsigned trackId = 0; trackId < nTks; ++trackId) {
141  // The track
142  const SimTrack& track = simTracks[trackId];
143  // std::cout << std::endl << "SimTrack " << trackId << " " << track << std::endl;
144 
145  // The origin vertex
146  int vertexId = track.vertIndex();
147  const SimVertex& vertex = simVertices[vertexId];
148  //std::cout << "Origin vertex " << vertexId << " " << vertex << std::endl;
149 
150  // The mother track
151  int motherId = -1;
152  if (!vertex.noParent()) { // there is a parent to this vertex
153  // geant id of the mother
154  unsigned motherGeantId = vertex.parentIndex();
155  std::map<unsigned, unsigned>::iterator association = geantToIndex.find(motherGeantId);
156  if (association != geantToIndex.end())
157  motherId = association->second;
158  }
159  int originId = motherId == -1 ? -1 : myTracks[motherId];
160  //std::cout << "Origin id " << originId << std::endl;
161 
162  /*
163  if ( endVertex.find(trackId) != endVertex.end() )
164  std::cout << "End vertex id = " << endVertex[trackId] << std::endl;
165  else
166  std::cout << "No endVertex !!! " << std::endl;
167  std::cout << "Tracker surface position " << track.trackerSurfacePosition() << std::endl;
168  */
169 
170  // Add the vertex (if it does not already exist!)
172  vertex.position().px(), vertex.position().py(), vertex.position().pz(), vertex.position().e());
173  if (myVertices[vertexId] == -1)
174  // Momentum and position are copied until SimTrack and SimVertex
175  // switch to Mathcore.
176  // myVertices[vertexId] = addSimVertex(vertex.position(),originId);
177  // The next line to be then replaced by the previous line
178  myVertices[vertexId] = addSimVertex(position, originId);
179 
180  // Add the track (with protection for brem'ing electrons and muons)
181  int motherType = motherId == -1 ? 0 : simTracks[motherId].type();
182 
183  bool notBremInDetector = (abs(motherType) != 11 && std::abs(motherType) != 13) || motherType != track.type() ||
184  position.Perp2() < lateVertexPosition;
185 
186  if (notBremInDetector) {
187  // Momentum and position are copied until SimTrack and SimVertex
188  // switch to Mathcore.
189  // RawParticle part(track.momentum(), vertex.position());
190  // The next 3 lines to be then replaced by the previous line
191  XYZTLorentzVector momentum(
192  track.momentum().px(), track.momentum().py(), track.momentum().pz(), track.momentum().e());
194  //
195  //std::cout << "Ctau = " << part.PDGcTau() << std::endl;
196  // Don't save tracks that have decayed immediately but for which no daughters
197  // were saved (probably due to cuts on E, pT and eta)
198  // if ( part.PDGcTau() > 0.1 || endVertex.find(trackId) != endVertex.end() )
199  myTracks[trackId] = addSimTrack(&part, myVertices[vertexId], track.genpartIndex());
200  if (myTracks[trackId] >= 0) {
201  (*theSimTracks)[myTracks[trackId]].setTkPosition(track.trackerSurfacePosition());
202  (*theSimTracks)[myTracks[trackId]].setTkMomentum(track.trackerSurfaceMomentum());
203  }
204  } else {
205  myTracks[trackId] = myTracks[motherId];
206  if (myTracks[trackId] >= 0) {
207  (*theSimTracks)[myTracks[trackId]].setTkPosition(track.trackerSurfacePosition());
208  (*theSimTracks)[myTracks[trackId]].setTkMomentum(track.trackerSurfaceMomentum());
209  }
210  }
211  }
212 
213  // Now loop over the remaining end vertices !
214  for (unsigned vertexId = 0; vertexId < nVtx; ++vertexId) {
215  // if the vertex is already saved, just ignore.
216  if (myVertices[vertexId] != -1)
217  continue;
218 
219  // The yet unused vertex
220  const SimVertex& vertex = simVertices[vertexId];
221 
222  // The mother track
223  int motherId = -1;
224  if (!vertex.noParent()) { // there is a parent to this vertex
225 
226  // geant id of the mother
227  unsigned motherGeantId = vertex.parentIndex();
228  std::map<unsigned, unsigned>::iterator association = geantToIndex.find(motherGeantId);
229  if (association != geantToIndex.end())
230  motherId = association->second;
231  }
232  int originId = motherId == -1 ? -1 : myTracks[motherId];
233 
234  // Add the vertex
235  // Momentum and position are copied until SimTrack and SimVertex
236  // switch to Mathcore.
237  // myVertices[vertexId] = addSimVertex(vertex.position(),originId);
238  // The next 3 lines to be then replaced by the previous line
240  vertex.position().px(), vertex.position().py(), vertex.position().pz(), vertex.position().e());
241  myVertices[vertexId] = addSimVertex(position, originId);
242  }
243 
244  // Finally, propagate all particles to the calorimeters
245  BaseParticlePropagator myPart;
246  XYZTLorentzVector mom;
248 
249  // Loop over the tracks
250  for (int fsimi = 0; fsimi < (int)nTracks(); ++fsimi) {
251  FSimTrack& myTrack = track(fsimi);
252  double trackerSurfaceTime =
253  myTrack.vertex().position().t() + myTrack.momentum().e() / myTrack.momentum().pz() *
254  (myTrack.trackerSurfacePosition().z() - myTrack.vertex().position().z());
256  myTrack.trackerSurfacePosition().y(),
257  myTrack.trackerSurfacePosition().z(),
258  trackerSurfaceTime);
259  mom = XYZTLorentzVector(myTrack.trackerSurfaceMomentum().x(),
260  myTrack.trackerSurfaceMomentum().y(),
261  myTrack.trackerSurfaceMomentum().z(),
262  myTrack.trackerSurfaceMomentum().t());
263 
264  if (mom.T() > 0.) {
265  // The particle to be propagated
266  myPart = BaseParticlePropagator(RawParticle(mom, pos, myTrack.charge()), 0., 0., 4.);
267 
268  // Propagate to Preshower layer 1
269  myPart.propagateToPreshowerLayer1(false);
270  if (myTrack.notYetToEndVertex(myPart.particle().vertex()) && myPart.getSuccess() > 0)
271  myTrack.setLayer1(myPart.particle(), myPart.getSuccess());
272 
273  // Propagate to Preshower Layer 2
274  myPart.propagateToPreshowerLayer2(false);
275  if (myTrack.notYetToEndVertex(myPart.particle().vertex()) && myPart.getSuccess() > 0)
276  myTrack.setLayer2(myPart.particle(), myPart.getSuccess());
277 
278  // Propagate to Ecal Endcap
279  myPart.propagateToEcalEntrance(false);
280  if (myTrack.notYetToEndVertex(myPart.particle().vertex()))
281  myTrack.setEcal(myPart.particle(), myPart.getSuccess());
282 
283  // Propagate to HCAL entrance
284  myPart.propagateToHcalEntrance(false);
285  if (myTrack.notYetToEndVertex(myPart.particle().vertex()))
286  myTrack.setHcal(myPart.particle(), myPart.getSuccess());
287 
288  // Attempt propagation to HF for low pt and high eta
289  if (myPart.particle().cos2ThetaV() > 0.8 || mom.T() < 3.) {
290  // Propagate to VFCAL entrance
291  myPart.propagateToVFcalEntrance(false);
292  if (myTrack.notYetToEndVertex(myPart.particle().vertex()))
293  myTrack.setVFcal(myPart.particle(), myPart.getSuccess());
294 
295  // Otherwise propagate to the HCAL exit and HO.
296  } else {
297  // Propagate to HCAL exit
298  myPart.propagateToHcalExit(false);
299  if (myTrack.notYetToEndVertex(myPart.particle().vertex()))
300  myTrack.setHcalExit(myPart.particle(), myPart.getSuccess());
301  // Propagate to HOLayer entrance
302  myPart.setMagneticField(0);
303  myPart.propagateToHOLayer(false);
304  if (myTrack.notYetToEndVertex(myPart.particle().vertex()))
305  myTrack.setHO(myPart.particle(), myPart.getSuccess());
306  }
307  }
308  }
309 }
310 
313  int genEventSize = myGenEvent.particles_size();
314  std::vector<int> myGenVertices(genEventSize, static_cast<int>(0));
315 
316  // If no particles, no work to be done !
317  if (myGenEvent.particles_empty())
318  return;
319 
320  // Are there particles in the FSimEvent already ?
321  int offset = nGenParts();
322 
323  // Primary vertex
324  HepMC::GenVertex* primaryVertex = *(myGenEvent.vertices_begin());
325 
326  // unit transformation (needs review)
327  XYZTLorentzVector primaryVertexPosition(primaryVertex->position().x() / 10.,
328  primaryVertex->position().y() / 10.,
329  primaryVertex->position().z() / 10.,
330  primaryVertex->position().t() / 10.);
331 
332  // This is the main vertex index
333  int mainVertex = addSimVertex(primaryVertexPosition, -1, FSimVertexType::PRIMARY_VERTEX);
334 
335  int initialBarcode = 0;
336  if (myGenEvent.particles_begin() != myGenEvent.particles_end()) {
337  initialBarcode = (*myGenEvent.particles_begin())->barcode();
338  }
339 
340  // Loop on the particles of the generated event
341  for (auto piter = myGenEvent.particles_begin(); piter != myGenEvent.particles_end(); ++piter) {
342  // This is the generated particle pointer - for the signal event only
343  HepMC::GenParticle* p = *piter;
344 
345  if (!offset) {
346  (*theGenParticles)[nGenParticles++] = p;
348  theGenSize *= 2;
349  theGenParticles->resize(theGenSize);
350  }
351  }
352 
353  // Reject particles with late origin vertex (i.e., coming from late decays)
354  // This should not happen, but one never knows what users may be up to!
355  // For example exotic particles might decay late - keep the decay products in the case.
356  XYZTLorentzVector productionVertexPosition(0., 0., 0., 0.);
357  HepMC::GenVertex* productionVertex = p->production_vertex();
358  if (productionVertex) {
359  unsigned productionMother = productionVertex->particles_in_size();
360  if (productionMother) {
361  unsigned motherId = (*(productionVertex->particles_in_const_begin()))->pdg_id();
362  if (motherId < 1000000)
363  productionVertexPosition = XYZTLorentzVector(productionVertex->position().x() / 10.,
364  productionVertex->position().y() / 10.,
365  productionVertex->position().z() / 10.,
366  productionVertex->position().t() / 10.);
367  }
368  }
369  if (!myFilter->acceptVertex(productionVertexPosition))
370  continue;
371 
372  int abspdgId = std::abs(p->pdg_id());
373  HepMC::GenVertex* endVertex = p->end_vertex();
374 
375  // Keep only:
376  // 1) Stable particles (watch out! New status code = 1001!)
377  bool testStable = p->status() % 1000 == 1;
378  // Declare stable standard particles that decay after a macroscopic path length
379  // (except if exotic)
380  if (p->status() == 2 && abspdgId < 1000000) {
381  if (endVertex) {
382  XYZTLorentzVector decayPosition = XYZTLorentzVector(endVertex->position().x() / 10.,
383  endVertex->position().y() / 10.,
384  endVertex->position().z() / 10.,
385  endVertex->position().t() / 10.);
386  // If the particle flew enough to be beyond the beam pipe enveloppe, just declare it stable
387  if (decayPosition.Perp2() > lateVertexPosition)
388  testStable = true;
389  }
390  }
391 
392  // 2) or particles with stable daughters (watch out! New status code = 1001!)
393  bool testDaugh = false;
394  if (!testStable && p->status() == 2 && endVertex && endVertex->particles_out_size()) {
395  HepMC::GenVertex::particles_out_const_iterator firstDaughterIt = endVertex->particles_out_const_begin();
396  HepMC::GenVertex::particles_out_const_iterator lastDaughterIt = endVertex->particles_out_const_end();
397  for (; firstDaughterIt != lastDaughterIt; ++firstDaughterIt) {
398  HepMC::GenParticle* daugh = *firstDaughterIt;
399  if (daugh->status() % 1000 == 1) {
400  // Check that it is not a "prompt electron or muon brem":
401  if (abspdgId == 11 || abspdgId == 13) {
402  if (endVertex) {
403  XYZTLorentzVector endVertexPosition = XYZTLorentzVector(endVertex->position().x() / 10.,
404  endVertex->position().y() / 10.,
405  endVertex->position().z() / 10.,
406  endVertex->position().t() / 10.);
407  // If the particle flew enough to be beyond the beam pipe enveloppe, just declare it stable
408  if (endVertexPosition.Perp2() < lateVertexPosition) {
409  break;
410  }
411  }
412  }
413  testDaugh = true;
414  break;
415  }
416  }
417  }
418 
419  // 3) or particles that fly more than one micron.
420  double dist = 0.;
421  if (!testStable && !testDaugh && p->production_vertex()) {
422  XYZTLorentzVector productionVertexPosition(p->production_vertex()->position().x() / 10.,
423  p->production_vertex()->position().y() / 10.,
424  p->production_vertex()->position().z() / 10.,
425  p->production_vertex()->position().t() / 10.);
426  dist = (primaryVertexPosition - productionVertexPosition).Vect().Mag2();
427  }
428  bool testDecay = (dist > 1e-8) ? true : false;
429 
430  // Save the corresponding particle and vertices
431  if (testStable || testDaugh || testDecay) {
432  /*
433  const HepMC::GenParticle* mother = p->production_vertex() ?
434  *(p->production_vertex()->particles_in_const_begin()) : 0;
435  */
436 
437  int motherBarcode = p->production_vertex() && p->production_vertex()->particles_in_const_begin() !=
438  p->production_vertex()->particles_in_const_end()
439  ? (*(p->production_vertex()->particles_in_const_begin()))->barcode()
440  : 0;
441 
442  int originVertex = motherBarcode && myGenVertices[motherBarcode - initialBarcode]
443  ? myGenVertices[motherBarcode - initialBarcode]
444  : mainVertex;
445 
446  XYZTLorentzVector momentum(p->momentum().px(), p->momentum().py(), p->momentum().pz(), p->momentum().e());
447  RawParticle part = makeParticle(theTable(), p->pdg_id(), momentum, vertex(originVertex).position());
448 
449  // Add the particle to the event and to the various lists
450 
451  int theTrack = testStable && p->end_vertex() ?
452  // The particle is scheduled to decay
453  addSimTrack(&part, originVertex, nGenParts() - offset, p->end_vertex())
454  :
455  // The particle is not scheduled to decay
456  addSimTrack(&part, originVertex, nGenParts() - offset);
457 
458  if (
459  // This one deals with particles with no end vertex
460  !p->end_vertex() ||
461  // This one deals with particles that have a pre-defined
462  // decay proper time, but have not decayed yet
463  (testStable && p->end_vertex() && !p->end_vertex()->particles_out_size())
464  // In both case, just don't add a end vertex in the FSimEvent
465  )
466  continue;
467 
468  // Add the vertex to the event and to the various lists
469  XYZTLorentzVector decayVertex = XYZTLorentzVector(p->end_vertex()->position().x() / 10.,
470  p->end_vertex()->position().y() / 10.,
471  p->end_vertex()->position().z() / 10.,
472  p->end_vertex()->position().t() / 10.);
473  // vertex(mainVertex).position();
474  int theVertex = addSimVertex(decayVertex, theTrack, FSimVertexType::DECAY_VERTEX);
475 
476  if (theVertex != -1)
477  myGenVertices[p->barcode() - initialBarcode] = theVertex;
478 
479  // There we are !
480  }
481  }
482 }
483 
484 int FBaseSimEvent::addSimTrack(const RawParticle* p, int iv, int ig, const HepMC::GenVertex* ev) {
485  // Check that the particle is in the Famos "acceptance"
486  // Keep all primaries of pile-up events, though
487  if (!myFilter->acceptParticle(*p) && ig >= -1)
488  return -1;
489 
490  // The new track index
491  int trackId = nSimTracks++;
493  theTrackSize *= 2;
494  theSimTracks->resize(theTrackSize);
495  }
496 
497  // Attach the particle to the origin vertex, and to the mother
498  vertex(iv).addDaughter(trackId);
499  if (!vertex(iv).noParent()) {
500  track(vertex(iv).parent().id()).addDaughter(trackId);
501 
502  if (ig == -1) {
503  int motherId = track(vertex(iv).parent().id()).genpartIndex();
504  if (motherId < -1)
505  ig = motherId;
506  }
507  }
508 
509  // Some transient information for FAMOS internal use
510  (*theSimTracks)[trackId] =
511  ev ?
512  // A proper decay time is scheduled
513  FSimTrack(p,
514  iv,
515  ig,
516  trackId,
517  this,
518  ev->position().t() / 10. * pdg::mass(p->pid(), theTable()) / std::sqrt(p->momentum().Vect().Mag2()))
519  :
520  // No proper decay time is scheduled
521  FSimTrack(p, iv, ig, trackId, this);
522 
523  return trackId;
524 }
525 
527  // Check that the vertex is in the Famos "acceptance"
528  if (!myFilter->acceptVertex(v))
529  return -1;
530 
531  // The number of vertices
532  int vertexId = nSimVertices++;
534  theVertexSize *= 2;
535  theSimVertices->resize(theVertexSize);
537  }
538 
539  // Attach the end vertex to the particle (if accepted)
540  if (im != -1)
541  track(im).setEndVertex(vertexId);
542 
543  // Some transient information for FAMOS internal use
544  (*theSimVertices)[vertexId] = FSimVertex(v, im, vertexId, this);
545 
546  (*theFSimVerticesType)[vertexId] = FSimVertexType(type);
547 
548  return vertexId;
549 }
550 
552  std::cout << "Id Gen Name eta phi pT E Vtx1 "
553  << " x y z "
554  << "Moth Vtx2 eta phi R Z Da1 Da2 Ecal?" << std::endl;
555 
556  for (HepMC::GenEvent::particle_const_iterator piter = myGenEvent.particles_begin();
557  piter != myGenEvent.particles_end();
558  ++piter) {
559  HepMC::GenParticle* p = *piter;
560  /* */
561  int partId = p->pdg_id();
563 
564  if (pdt->particle(ParticleID(partId)) != nullptr) {
565  name = (pdt->particle(ParticleID(partId)))->name();
566  } else {
567  name = "none";
568  }
569 
570  XYZTLorentzVector momentum1(p->momentum().px(), p->momentum().py(), p->momentum().pz(), p->momentum().e());
571 
572  int vertexId1 = 0;
573 
574  if (!p->production_vertex())
575  continue;
576 
577  XYZVector vertex1(p->production_vertex()->position().x() / 10.,
578  p->production_vertex()->position().y() / 10.,
579  p->production_vertex()->position().z() / 10.);
580  vertexId1 = p->production_vertex()->barcode();
581 
582  std::cout.setf(std::ios::fixed, std::ios::floatfield);
583  std::cout.setf(std::ios::right, std::ios::adjustfield);
584 
585  std::cout << std::setw(4) << p->barcode() << " " << name;
586 
587  for (unsigned int k = 0; k < 11 - name.length() && k < 12; k++)
588  std::cout << " ";
589 
590  double eta = momentum1.eta();
591  if (eta > +10.)
592  eta = +10.;
593  if (eta < -10.)
594  eta = -10.;
595  std::cout << std::setw(6) << std::setprecision(2) << eta << " " << std::setw(6) << std::setprecision(2)
596  << momentum1.phi() << " " << std::setw(7) << std::setprecision(2) << momentum1.pt() << " " << std::setw(7)
597  << std::setprecision(2) << momentum1.e() << " " << std::setw(4) << vertexId1 << " " << std::setw(6)
598  << std::setprecision(1) << vertex1.x() << " " << std::setw(6) << std::setprecision(1) << vertex1.y()
599  << " " << std::setw(6) << std::setprecision(1) << vertex1.z() << " ";
600 
601  const HepMC::GenParticle* mother = *(p->production_vertex()->particles_in_const_begin());
602 
603  if (mother)
604  std::cout << std::setw(4) << mother->barcode() << " ";
605  else
606  std::cout << " ";
607 
608  if (p->end_vertex()) {
609  XYZTLorentzVector vertex2(p->end_vertex()->position().x() / 10.,
610  p->end_vertex()->position().y() / 10.,
611  p->end_vertex()->position().z() / 10.,
612  p->end_vertex()->position().t() / 10.);
613  int vertexId2 = p->end_vertex()->barcode();
614 
615  std::vector<const HepMC::GenParticle*> children;
616  HepMC::GenVertex::particles_out_const_iterator firstDaughterIt = p->end_vertex()->particles_out_const_begin();
617  HepMC::GenVertex::particles_out_const_iterator lastDaughterIt = p->end_vertex()->particles_out_const_end();
618  for (; firstDaughterIt != lastDaughterIt; ++firstDaughterIt) {
619  children.push_back(*firstDaughterIt);
620  }
621 
622  std::cout << std::setw(4) << vertexId2 << " " << std::setw(6) << std::setprecision(2) << vertex2.eta() << " "
623  << std::setw(6) << std::setprecision(2) << vertex2.phi() << " " << std::setw(5) << std::setprecision(1)
624  << vertex2.pt() << " " << std::setw(6) << std::setprecision(1) << vertex2.z() << " ";
625  for (unsigned id = 0; id < children.size(); ++id)
626  std::cout << std::setw(4) << children[id]->barcode() << " ";
627  }
628  std::cout << std::endl;
629  }
630 }
631 
632 void FBaseSimEvent::print() const {
633  std::cout << " Id Gen Name eta phi pT E Vtx1 "
634  << " x y z "
635  << "Moth Vtx2 eta phi R Z Daughters Ecal?" << std::endl;
636 
637  for (int i = 0; i < (int)nTracks(); i++)
638  std::cout << track(i) << std::endl;
639 
640  for (int i = 0; i < (int)nVertices(); i++)
641  std::cout << "i = " << i << " " << vertexType(i) << std::endl;
642 }
643 
645  nSimTracks = 0;
646  nSimVertices = 0;
647  nGenParticles = 0;
649 }
650 
652  (*theChargedTracks)[nChargedParticleTracks++] = id;
654  theChargedSize *= 2;
656  }
657 }
658 
659 int FBaseSimEvent::chargedTrack(int id) const {
660  if (id >= 0 && id < (int)nChargedParticleTracks)
661  return (*theChargedTracks)[id];
662  else
663  return -1;
664 }
665 
const ParticleDataTable * pdt
double lateVertexPosition
int addSimVertex(const XYZTLorentzVector &decayVertex, int im=-1, FSimVertexType::VertexType type=FSimVertexType::ANY)
Add a new vertex to the Event and to the various lists.
const HepMC::GenParticle * embdGenpart(int i) const
return MC track with a given id
FSimTrack & track(int id) const
Return track with given Id.
bool propagateToPreshowerLayer1(bool first=true)
const math::XYZVectorD & trackerSurfacePosition() const
Definition: SimTrack.h:40
HepPDT::ParticleDataTable ParticleDataTable
std::vector< FSimTrack > * theSimTracks
std::vector< unsigned > * theChargedTracks
FBaseSimEvent(const edm::ParameterSet &kine)
Default constructor.
unsigned int theTrackSize
unsigned int theVertexSize
KineParticleFilter * myFilter
The particle filter.
int addSimTrack(const RawParticle *p, int iv, int ig=-1, const HepMC::GenVertex *ev=nullptr)
Add a new track to the Event and to the various lists.
void setEcal(const RawParticle &pp, int success)
Set the ecal variables.
Definition: FSimTrack.cc:118
bool acceptParticle(const RawParticle &p) const
void addParticles(const HepMC::GenEvent &hev)
Add the particles and their vertices to the list.
void setLayer2(const RawParticle &pp, int success)
Set the preshower layer2 variables.
Definition: FSimTrack.cc:112
void clear()
clear the FBaseSimEvent content before the next event
void setMagneticField(double b)
Set the magnetic field.
unsigned int nGenParts() const
Number of generator particles.
Definition: FBaseSimEvent.h:84
unsigned int nSimTracks
const FSimVertex vertex() const
Origin vertex.
unsigned int theGenSize
unsigned int nVertices() const
Number of vertices.
Definition: FBaseSimEvent.h:81
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
unsigned int nTracks() const
Number of tracks.
Definition: FBaseSimEvent.h:78
const HepPDT::ParticleDataTable * theTable() const
Get the pointer to the particle data table.
Definition: FBaseSimEvent.h:54
RawParticle makeParticle(HepPDT::ParticleDataTable const *, int id, const math::XYZTLorentzVector &p)
Definition: makeParticle.cc:28
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:22
bool propagateToVFcalEntrance(bool first=true)
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
Definition: SimTrack.h:33
void setLayer1(const RawParticle &pp, int success)
Set the preshower layer1 variables.
Definition: FSimTrack.cc:106
void print() const
print the FBaseSimEvent in an intelligible way
const XYZTLorentzVector & momentum() const
Temporary (until move of SimTrack to Mathcore) - No! Actually very useful.
Definition: FSimTrack.h:209
double cos2ThetaV() const
Definition: RawParticle.h:281
~FBaseSimEvent()
usual virtual destructor
T sqrt(T t)
Definition: SSEVec.h:23
bool propagateToHcalExit(bool first=true)
unsigned int nSimVertices
float charge() const
charge
Definition: FSimTrack.h:56
A FSimVertexType hold the information on the vertex origine.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
RawParticle const & particle() const
The particle being propagated.
std::vector< FSimVertexType > FSimVertexTypeCollection
collection of FSimVertexType objects
bool notYetToEndVertex(const XYZTLorentzVector &pos) const
Compare the end vertex position with another position.
Definition: FSimTrack.cc:85
unsigned int nGenParticles
unsigned int initialSize
std::vector< FSimVertex > * theSimVertices
bool propagateToEcalEntrance(bool first=true)
bool acceptVertex(const math::XYZTLorentzVector &p) const
void fill(const HepMC::GenEvent &hev)
fill the FBaseSimEvent from the current HepMC::GenEvent
int getSuccess() const
Has propagation been performed and was barrel or endcap reached ?
unsigned int theChargedSize
part
Definition: HCALResponse.h:20
const math::XYZTLorentzVector & position() const
Temporary (until CMSSW moves to Mathcore) - No ! Actually very useful.
Definition: FSimVertex.h:48
void addChargedTrack(int id)
Add an id in the vector of charged tracks id&#39;s.
void setHcalExit(const RawParticle &pp, int success)
Set the hcal exit variables.
Definition: FSimTrack.cc:136
unsigned int nChargedParticleTracks
bool propagateToHcalEntrance(bool first=true)
void initializePdt(const HepPDT::ParticleDataTable *aPdt)
Initialize the particle data table.
void setEndVertex(int endv)
Set the end vertex.
Definition: FSimTrack.h:167
FSimVertex & vertex(int id) const
Return vertex with given Id.
static int position[264][3]
Definition: ReadPGInfo.cc:289
double mass(int pdgID, const HepPDT::ParticleDataTable *pdt)
void addDaughter(int i)
Add a RecHit for a track on a layer.
Definition: FSimTrack.h:200
void setHO(const RawParticle &pp, int success)
Set the ho variables.
Definition: FSimTrack.cc:141
void setVFcal(const RawParticle &pp, int success)
Set the hcal variables.
Definition: FSimTrack.cc:130
const math::XYZTLorentzVectorD & trackerSurfaceMomentum() const
Definition: SimTrack.h:42
void addDaughter(int i)
Definition: FSimVertex.h:45
void setHcal(const RawParticle &pp, int success)
Set the hcal variables.
Definition: FSimTrack.cc:124
void printMCTruth(const HepMC::GenEvent &hev)
print the original MCTruth event
std::vector< HepMC::GenParticle * > * theGenParticles
math::XYZVector XYZVector
Definition: RawParticle.h:26
bool noParent() const
Definition: SimVertex.h:30
int chargedTrack(int id) const
return "reconstructed" charged tracks index.
bool propagateToHOLayer(bool first=true)
primaryVertex
hltOfflineBeamSpot for HLTMON
int parentIndex() const
Definition: SimVertex.h:29
bool propagateToPreshowerLayer2(bool first=true)
FSimVertexType & vertexType(int id) const
Return vertex with given Id.
math::XYZTLorentzVector XYZTLorentzVector
Definition: RawParticle.h:25
const XYZTLorentzVector & vertex() const
the vertex fourvector
Definition: RawParticle.h:320
FSimVertexTypeCollection * theFSimVerticesType
int genpartIndex() const
index of the corresponding Generator particle in the Event container (-1 if no Genpart) ...
Definition: SimTrack.h:37