CMS 3D CMS Logo

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