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  std::cout << "The MC truth! " << std::endl;
101  printMCTruth(myGenEvent);
102 
103  std::cout << std::endl << "The FAMOS event! " << std::endl;
104  print();
105  */
106 
107 }
108 
109 void
111 
112  // Clear old vectors
113  clear();
114 
115  // Add the particles in the FSimEvent
116  addParticles(myGenParticles);
117 
118 }
119 
120 void
121 FBaseSimEvent::fill(const std::vector<SimTrack>& simTracks,
122  const std::vector<SimVertex>& simVertices) {
123 
124  // Watch out there ! A SimVertex is in mm (stupid),
125  // while a FSimVertex is in cm (clever).
126 
127  clear();
128 
129  unsigned nVtx = simVertices.size();
130  unsigned nTks = simTracks.size();
131 
132  // Empty event, do nothin'
133  if ( nVtx == 0 ) return;
134 
135  // Two arrays for internal use.
136  std::vector<int> myVertices(nVtx,-1);
137  std::vector<int> myTracks(nTks,-1);
138 
139  // create a map associating geant particle id and position in the
140  // event SimTrack vector
141 
142  std::map<unsigned, unsigned> geantToIndex;
143  for( unsigned it=0; it<simTracks.size(); ++it ) {
144  geantToIndex[ simTracks[it].trackId() ] = it;
145  }
146 
147  // Create also a map associating a SimTrack with its endVertex
148  /*
149  std::map<unsigned, unsigned> endVertex;
150  for ( unsigned iv=0; iv<simVertices.size(); ++iv ) {
151  endVertex[ simVertices[iv].parentIndex() ] = iv;
152  }
153  */
154 
155  // Set the main vertex for the kine particle filter
156  // SimVertices were in mm until 110_pre2
157  // HepLorentzVector primaryVertex = simVertices[0].position()/10.;
158  // SImVertices are now in cm
159  // Also : position is copied until SimVertex switches to Mathcore.
160  // XYZTLorentzVector primaryVertex = simVertices[0].position();
161  // The next 5 lines to be then replaced by the previous line
162  XYZTLorentzVector primaryVertex(simVertices[0].position().x(),
163  simVertices[0].position().y(),
164  simVertices[0].position().z(),
165  simVertices[0].position().t());
166  //
167  myFilter->setMainVertex(primaryVertex);
168  // Add the main vertex to the list.
170  myVertices[0] = 0;
171 
172  for( unsigned trackId=0; trackId<nTks; ++trackId ) {
173 
174  // The track
175  const SimTrack& track = simTracks[trackId];
176  // std::cout << std::endl << "SimTrack " << trackId << " " << track << std::endl;
177 
178  // The origin vertex
179  int vertexId = track.vertIndex();
180  const SimVertex& vertex = simVertices[vertexId];
181  //std::cout << "Origin vertex " << vertexId << " " << vertex << std::endl;
182 
183  // The mother track
184  int motherId = -1;
185  if( !vertex.noParent() ) { // there is a parent to this vertex
186  // geant id of the mother
187  unsigned motherGeantId = vertex.parentIndex();
188  std::map<unsigned, unsigned >::iterator association
189  = geantToIndex.find( motherGeantId );
190  if(association != geantToIndex.end() )
191  motherId = association->second;
192  }
193  int originId = motherId == - 1 ? -1 : myTracks[motherId];
194  //std::cout << "Origin id " << originId << std::endl;
195 
196  /*
197  if ( endVertex.find(trackId) != endVertex.end() )
198  std::cout << "End vertex id = " << endVertex[trackId] << std::endl;
199  else
200  std::cout << "No endVertex !!! " << std::endl;
201  std::cout << "Tracker surface position " << track.trackerSurfacePosition() << std::endl;
202  */
203 
204  // Add the vertex (if it does not already exist!)
205  XYZTLorentzVector position(vertex.position().px(),vertex.position().py(),
206  vertex.position().pz(),vertex.position().e());
207  if ( myVertices[vertexId] == -1 )
208  // Momentum and position are copied until SimTrack and SimVertex
209  // switch to Mathcore.
210  // myVertices[vertexId] = addSimVertex(vertex.position(),originId);
211  // The next line to be then replaced by the previous line
212  myVertices[vertexId] = addSimVertex(position,originId);
213 
214  // Add the track (with protection for brem'ing electrons and muons)
215  int motherType = motherId == -1 ? 0 : simTracks[motherId].type();
216 
217  bool notBremInDetector =
218  (abs(motherType) != 11 && abs(motherType) != 13) ||
219  motherType != track.type() ||
220  position.Perp2() < lateVertexPosition ;
221 
222  if ( notBremInDetector ) {
223  // Momentum and position are copied until SimTrack and SimVertex
224  // switch to Mathcore.
225  // RawParticle part(track.momentum(), vertex.position());
226  // The next 3 lines to be then replaced by the previous line
227  XYZTLorentzVector momentum(track.momentum().px(),track.momentum().py(),
228  track.momentum().pz(),track.momentum().e());
229  RawParticle part(momentum,position);
230  //
231  part.setID(track.type());
232  //std::cout << "Ctau = " << part.PDGcTau() << std::endl;
233  // Don't save tracks that have decayed immediately but for which no daughters
234  // were saved (probably due to cuts on E, pT and eta)
235  // if ( part.PDGcTau() > 0.1 || endVertex.find(trackId) != endVertex.end() )
236  myTracks[trackId] = addSimTrack(&part,myVertices[vertexId],track.genpartIndex());
237  if ( myTracks[trackId] >= 0 ) {
238  (*theSimTracks)[ myTracks[trackId] ].setTkPosition(track.trackerSurfacePosition());
239  (*theSimTracks)[ myTracks[trackId] ].setTkMomentum(track.trackerSurfaceMomentum());
240  }
241  } else {
242 
243  myTracks[trackId] = myTracks[motherId];
244  if ( myTracks[trackId] >= 0 ) {
245  (*theSimTracks)[ myTracks[trackId] ].setTkPosition(track.trackerSurfacePosition());
246  (*theSimTracks)[ myTracks[trackId] ].setTkMomentum(track.trackerSurfaceMomentum());
247  }
248  }
249 
250  }
251 
252  // Now loop over the remaining end vertices !
253  for( unsigned vertexId=0; vertexId<nVtx; ++vertexId ) {
254 
255  // if the vertex is already saved, just ignore.
256  if ( myVertices[vertexId] != -1 ) continue;
257 
258  // The yet unused vertex
259  const SimVertex& vertex = simVertices[vertexId];
260 
261  // The mother track
262  int motherId = -1;
263  if( !vertex.noParent() ) { // there is a parent to this vertex
264 
265  // geant id of the mother
266  unsigned motherGeantId = vertex.parentIndex();
267  std::map<unsigned, unsigned >::iterator association
268  = geantToIndex.find( motherGeantId );
269  if(association != geantToIndex.end() )
270  motherId = association->second;
271  }
272  int originId = motherId == - 1 ? -1 : myTracks[motherId];
273 
274  // Add the vertex
275  // Momentum and position are copied until SimTrack and SimVertex
276  // switch to Mathcore.
277  // myVertices[vertexId] = addSimVertex(vertex.position(),originId);
278  // The next 3 lines to be then replaced by the previous line
279  XYZTLorentzVector position(vertex.position().px(),vertex.position().py(),
280  vertex.position().pz(),vertex.position().e());
281  myVertices[vertexId] = addSimVertex(position,originId);
282  }
283 
284  // Finally, propagate all particles to the calorimeters
285  BaseParticlePropagator myPart;
286  XYZTLorentzVector mom;
287  XYZTLorentzVector pos;
288 
289 
290  // Loop over the tracks
291  for( int fsimi=0; fsimi < (int)nTracks() ; ++fsimi) {
292 
293 
294  FSimTrack& myTrack = track(fsimi);
295  double trackerSurfaceTime = myTrack.vertex().position().t()
296  + myTrack.momentum().e()/myTrack.momentum().pz()
297  * ( myTrack.trackerSurfacePosition().z()
298  - myTrack.vertex().position().z() );
299  pos = XYZTLorentzVector(myTrack.trackerSurfacePosition().x(),
300  myTrack.trackerSurfacePosition().y(),
301  myTrack.trackerSurfacePosition().z(),
302  trackerSurfaceTime);
303  mom = XYZTLorentzVector(myTrack.trackerSurfaceMomentum().x(),
304  myTrack.trackerSurfaceMomentum().y(),
305  myTrack.trackerSurfaceMomentum().z(),
306  myTrack.trackerSurfaceMomentum().t());
307 
308  if ( mom.T() > 0. ) {
309  // The particle to be propagated
310  myPart = BaseParticlePropagator(RawParticle(mom,pos),0.,0.,4.);
311  myPart.setCharge(myTrack.charge());
312 
313  // Propagate to Preshower layer 1
314  myPart.propagateToPreshowerLayer1(false);
315  if ( myTrack.notYetToEndVertex(myPart.vertex()) && myPart.getSuccess()>0 )
316  myTrack.setLayer1(myPart,myPart.getSuccess());
317 
318  // Propagate to Preshower Layer 2
319  myPart.propagateToPreshowerLayer2(false);
320  if ( myTrack.notYetToEndVertex(myPart.vertex()) && myPart.getSuccess()>0 )
321  myTrack.setLayer2(myPart,myPart.getSuccess());
322 
323  // Propagate to Ecal Endcap
324  myPart.propagateToEcalEntrance(false);
325  if ( myTrack.notYetToEndVertex(myPart.vertex()) )
326  myTrack.setEcal(myPart,myPart.getSuccess());
327 
328  // Propagate to HCAL entrance
329  myPart.propagateToHcalEntrance(false);
330  if ( myTrack.notYetToEndVertex(myPart.vertex()) )
331  myTrack.setHcal(myPart,myPart.getSuccess());
332 
333  // Attempt propagation to HF for low pt and high eta
334  if ( myPart.cos2ThetaV()>0.8 || mom.T() < 3. ) {
335  // Propagate to VFCAL entrance
336  myPart.propagateToVFcalEntrance(false);
337  if ( myTrack.notYetToEndVertex(myPart.vertex()) )
338  myTrack.setVFcal(myPart,myPart.getSuccess());
339 
340  // Otherwise propagate to the HCAL exit and HO.
341  } else {
342  // Propagate to HCAL exit
343  myPart.propagateToHcalExit(false);
344  if ( myTrack.notYetToEndVertex(myPart.vertex()) )
345  myTrack.setHcalExit(myPart,myPart.getSuccess());
346  // Propagate to HOLayer entrance
347  myPart.setMagneticField(0);
348  myPart.propagateToHOLayer(false);
349  if ( myTrack.notYetToEndVertex(myPart.vertex()) )
350  myTrack.setHO(myPart,myPart.getSuccess());
351  }
352  }
353  }
354 }
355 
356 
357 void
358 FBaseSimEvent::addParticles(const HepMC::GenEvent& myGenEvent) {
359 
361  int genEventSize = myGenEvent.particles_size();
362  std::vector<int> myGenVertices(genEventSize, static_cast<int>(0));
363 
364  // If no particles, no work to be done !
365  if ( myGenEvent.particles_empty() ) return;
366 
367  // Are there particles in the FSimEvent already ?
368  int offset = nGenParts();
369 
370  // Primary vertex
371  HepMC::GenVertex* primaryVertex = *(myGenEvent.vertices_begin());
372 
373  // unit transformation (needs review)
374  XYZTLorentzVector primaryVertexPosition(primaryVertex->position().x()/10.,
375  primaryVertex->position().y()/10.,
376  primaryVertex->position().z()/10.,
377  primaryVertex->position().t()/10.);
378 
379  // Set the main vertex
380  myFilter->setMainVertex(primaryVertexPosition);
381 
382  // This is the main vertex index
383  int mainVertex = addSimVertex(myFilter->vertex(), -1, FSimVertexType::PRIMARY_VERTEX);
384 
385  HepMC::GenEvent::particle_const_iterator piter;
386  HepMC::GenEvent::particle_const_iterator pbegin = myGenEvent.particles_begin();
387  HepMC::GenEvent::particle_const_iterator pend = myGenEvent.particles_end();
388 
389  int initialBarcode = 0;
390  if ( pbegin != pend ) initialBarcode = (*pbegin)->barcode();
391  // Loop on the particles of the generated event
392  for ( piter = pbegin; piter != pend; ++piter ) {
393 
394  // This is the generated particle pointer - for the signal event only
395  HepMC::GenParticle* p = *piter;
396 
397  if ( !offset ) {
398  (*theGenParticles)[nGenParticles++] = p;
400  theGenSize *= 2;
401  theGenParticles->resize(theGenSize);
402  }
403 
404  }
405 
406  // Reject particles with late origin vertex (i.e., coming from late decays)
407  // This should not happen, but one never knows what users may be up to!
408  // For example exotic particles might decay late - keep the decay products in the case.
409  XYZTLorentzVector productionVertexPosition(0.,0.,0.,0.);
410  HepMC::GenVertex* productionVertex = p->production_vertex();
411  if ( productionVertex ) {
412  unsigned productionMother = productionVertex->particles_in_size();
413  if ( productionMother ) {
414  unsigned motherId = (*(productionVertex->particles_in_const_begin()))->pdg_id();
415  if ( abs(motherId) < 1000000 )
416  productionVertexPosition =
417  XYZTLorentzVector(productionVertex->position().x()/10.,
418  productionVertex->position().y()/10.,
419  productionVertex->position().z()/10.,
420  productionVertex->position().t()/10.);
421  }
422  }
423  if ( !myFilter->accept(productionVertexPosition) ) continue;
424 
425  int abspdgId = abs(p->pdg_id());
426  HepMC::GenVertex* endVertex = p->end_vertex();
427 
428  // Keep only:
429  // 1) Stable particles (watch out! New status code = 1001!)
430  bool testStable = p->status()%1000==1;
431  // Declare stable standard particles that decay after a macroscopic path length
432  // (except if exotic)
433  if ( p->status() == 2 && abspdgId < 1000000) {
434  if ( endVertex ) {
435  XYZTLorentzVector decayPosition =
436  XYZTLorentzVector(endVertex->position().x()/10.,
437  endVertex->position().y()/10.,
438  endVertex->position().z()/10.,
439  endVertex->position().t()/10.);
440  // If the particle flew enough to be beyond the beam pipe enveloppe, just declare it stable
441  if ( decayPosition.Perp2() > lateVertexPosition ) testStable = true;
442  }
443  }
444 
445  // 2) or particles with stable daughters (watch out! New status code = 1001!)
446  bool testDaugh = false;
447  if ( !testStable &&
448  p->status() == 2 &&
449  endVertex &&
450  endVertex->particles_out_size() ) {
451  HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
452  endVertex->particles_out_const_begin();
453  HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
454  endVertex->particles_out_const_end();
455  for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
456  HepMC::GenParticle* daugh = *firstDaughterIt;
457  if ( daugh->status()%1000==1 ) {
458  // Check that it is not a "prompt electron or muon brem":
459  if (abspdgId == 11 || abspdgId == 13) {
460  if ( endVertex ) {
461  XYZTLorentzVector endVertexPosition = XYZTLorentzVector(endVertex->position().x()/10.,
462  endVertex->position().y()/10.,
463  endVertex->position().z()/10.,
464  endVertex->position().t()/10.);
465  // If the particle flew enough to be beyond the beam pipe enveloppe, just declare it stable
466  if ( endVertexPosition.Perp2() < lateVertexPosition ) {
467  break;
468  }
469  }
470  }
471  testDaugh=true;
472  break;
473  }
474  }
475  }
476 
477  // 3) or particles that fly more than one micron.
478  double dist = 0.;
479  if ( !testStable && !testDaugh && p->production_vertex() ) {
481  productionVertexPosition(p->production_vertex()->position().x()/10.,
482  p->production_vertex()->position().y()/10.,
483  p->production_vertex()->position().z()/10.,
484  p->production_vertex()->position().t()/10.);
485  dist = (primaryVertexPosition-productionVertexPosition).Vect().Mag2();
486  }
487  bool testDecay = ( dist > 1e-8 ) ? true : false;
488 
489  // Save the corresponding particle and vertices
490  if ( testStable || testDaugh || testDecay ) {
491 
492  /*
493  const HepMC::GenParticle* mother = p->production_vertex() ?
494  *(p->production_vertex()->particles_in_const_begin()) : 0;
495  */
496 
497  int motherBarcode = p->production_vertex() &&
498  p->production_vertex()->particles_in_const_begin() !=
499  p->production_vertex()->particles_in_const_end() ?
500  (*(p->production_vertex()->particles_in_const_begin()))->barcode() : 0;
501 
502  int originVertex =
503  motherBarcode && myGenVertices[motherBarcode-initialBarcode] ?
504  myGenVertices[motherBarcode-initialBarcode] : mainVertex;
505 
506  XYZTLorentzVector momentum(p->momentum().px(),
507  p->momentum().py(),
508  p->momentum().pz(),
509  p->momentum().e());
510  RawParticle part(momentum, vertex(originVertex).position());
511  part.setID(p->pdg_id());
512 
513  // Add the particle to the event and to the various lists
514 
515  int theTrack = testStable && p->end_vertex() ?
516  // The particle is scheduled to decay
517  addSimTrack(&part,originVertex, nGenParts()-offset,p->end_vertex()) :
518  // The particle is not scheduled to decay
519  addSimTrack(&part,originVertex, nGenParts()-offset);
520 
521  if (
522  // This one deals with particles with no end vertex
523  !p->end_vertex() ||
524  // This one deals with particles that have a pre-defined
525  // decay proper time, but have not decayed yet
526  ( testStable && p->end_vertex() && !p->end_vertex()->particles_out_size() )
527  // In both case, just don't add a end vertex in the FSimEvent
528  ) continue;
529 
530  // Add the vertex to the event and to the various lists
531  XYZTLorentzVector decayVertex =
532  XYZTLorentzVector(p->end_vertex()->position().x()/10.,
533  p->end_vertex()->position().y()/10.,
534  p->end_vertex()->position().z()/10.,
535  p->end_vertex()->position().t()/10.);
536  // vertex(mainVertex).position();
537  int theVertex = addSimVertex(decayVertex,theTrack, FSimVertexType::DECAY_VERTEX);
538 
539  if ( theVertex != -1 ) myGenVertices[p->barcode()-initialBarcode] = theVertex;
540 
541  // There we are !
542  }
543  }
544 
545 }
546 
547 void
549 
550  // If no particles, no work to be done !
551  unsigned int nParticles = myGenParticles.size();
552  nGenParticles = nParticles;
553 
554  if ( !nParticles ) return;
555 
557  std::map<const reco::Candidate*,int> myGenVertices;
558 
559  // Are there particles in the FSimEvent already ?
560  int offset = nTracks();
561 
562  // Skip the incoming protons
563  nGenParticles = 0;
564  unsigned int ip = 0;
565  if ( nParticles > 1 &&
566  myGenParticles[0].pdgId() == 2212 &&
567  myGenParticles[1].pdgId() == 2212 ) {
568  ip = 2;
569  nGenParticles = 2;
570  }
571 
572  // Primary vertex
573  XYZTLorentzVector primaryVertex (myGenParticles[ip].vx(),
574  myGenParticles[ip].vy(),
575  myGenParticles[ip].vz(),
576  0.);
577 
578  // Set the main vertex
579  myFilter->setMainVertex(primaryVertex);
580 
581  // This is the main vertex index
582  int mainVertex = addSimVertex(myFilter->vertex(), -1, FSimVertexType::PRIMARY_VERTEX);
583 
584  // Loop on the particles of the generated event
585  for ( ; ip<nParticles; ++ip ) {
586 
587  // nGenParticles = ip;
588 
589  nGenParticles++;
590  const reco::GenParticle& p = myGenParticles[ip];
591 
592  // Reject particles with late origin vertex (i.e., coming from late decays)
593  // This should not happen, but one never knows what users may be up to!
594  // For example exotic particles might decay late - keep the decay products in the case.
595  XYZTLorentzVector productionVertexPosition(0.,0.,0.,0.);
596  const reco::Candidate* productionMother = p.numberOfMothers() ? p.mother(0) : 0;
597  if ( productionMother ) {
598  unsigned motherId = productionMother->pdgId();
599  if ( abs(motherId) < 1000000 )
600  productionVertexPosition = XYZTLorentzVector(p.vx(), p.vy(), p.vz(), 0.);
601  }
602  if ( !myFilter->accept(productionVertexPosition) ) continue;
603 
604  // Keep only:
605  // 1) Stable particles
606  bool testStable = p.status()%1000==1;
607  // Declare stable standard particles that decay after a macroscopic path length
608  // (except if exotic particle)
609  if ( p.status() == 2 && abs(p.pdgId()) < 1000000 ) {
610  unsigned int nDaughters = p.numberOfDaughters();
611  if ( nDaughters ) {
612  const reco::Candidate* daughter = p.daughter(0);
613  XYZTLorentzVector decayPosition =
614  XYZTLorentzVector(daughter->vx(), daughter->vy(), daughter->vz(), 0.);
615  // If the particle flew enough to be beyond the beam pipe enveloppe, just declare it stable
616  if ( decayPosition.Perp2() > lateVertexPosition ) testStable = true;
617  }
618  }
619 
620  // 2) or particles with stable daughters
621  bool testDaugh = false;
622  unsigned int nDaughters = p.numberOfDaughters();
623  if ( !testStable &&
624  // p.status() == 2 &&
625  nDaughters ) {
626  for ( unsigned iDaughter=0; iDaughter<nDaughters; ++iDaughter ) {
627  const reco::Candidate* daughter = p.daughter(iDaughter);
628  if ( daughter->status()%1000==1 ) {
629  testDaugh=true;
630  break;
631  }
632  }
633  }
634 
635  // 3) or particles that fly more than one micron.
636  double dist = 0.;
637  if ( !testStable && !testDaugh ) {
638  XYZTLorentzVector productionVertex(p.vx(),p.vy(),p.vz(),0.);
639  dist = (primaryVertex-productionVertex).Vect().Mag2();
640  }
641  bool testDecay = ( dist > 1e-8 ) ? true : false;
642 
643  // Save the corresponding particle and vertices
644  if ( testStable || testDaugh || testDecay ) {
645 
646  const reco::Candidate* mother = p.numberOfMothers() ? p.mother(0) : 0;
647 
648  int originVertex =
649  mother &&
650  myGenVertices.find(mother) != myGenVertices.end() ?
651  myGenVertices[mother] : mainVertex;
652 
653  XYZTLorentzVector momentum(p.px(),p.py(),p.pz(),p.energy());
654  RawParticle part(momentum, vertex(originVertex).position());
655  part.setID(p.pdgId());
656 
657  // Add the particle to the event and to the various lists
658  int theTrack = addSimTrack(&part,originVertex, nGenParts()-offset);
659 
660  // It there an end vertex ?
661  if ( !nDaughters ) continue;
662  const reco::Candidate* daughter = p.daughter(0);
663 
664  // Add the vertex to the event and to the various lists
665  XYZTLorentzVector decayVertex =
666  XYZTLorentzVector(daughter->vx(), daughter->vy(),
667  daughter->vz(), 0.);
668  int theVertex = addSimVertex(decayVertex,theTrack, FSimVertexType::DECAY_VERTEX);
669 
670  if ( theVertex != -1 ) myGenVertices[&p] = theVertex;
671 
672  // There we are !
673  }
674  }
675 
676  // There is no GenParticle's in that case...
677  // nGenParticles=0;
678 
679 }
680 
681 int
682 FBaseSimEvent::addSimTrack(const RawParticle* p, int iv, int ig,
683  const HepMC::GenVertex* ev) {
684 
685  // Check that the particle is in the Famos "acceptance"
686  // Keep all primaries of pile-up events, though
687  if ( !myFilter->accept(p) && ig >= -1 ) return -1;
688 
689  // The new track index
690  int trackId = nSimTracks++;
692  theTrackSize *= 2;
693  theSimTracks->resize(theTrackSize);
694  }
695 
696  // Attach the particle to the origin vertex, and to the mother
697  vertex(iv).addDaughter(trackId);
698  if ( !vertex(iv).noParent() ) {
699  track(vertex(iv).parent().id()).addDaughter(trackId);
700 
701  if ( ig == -1 ) {
702  int motherId = track(vertex(iv).parent().id()).genpartIndex();
703  if ( motherId < -1 ) ig = motherId;
704  }
705  }
706 
707  // Some transient information for FAMOS internal use
708  (*theSimTracks)[trackId] = ev ?
709  // A proper decay time is scheduled
710  FSimTrack(p,iv,ig,trackId,this,
711  ev->position().t()/10.
712  * p->PDGmass()
713  / std::sqrt(p->momentum().Vect().Mag2())) :
714  // No proper decay time is scheduled
715  FSimTrack(p,iv,ig,trackId,this);
716 
717  return trackId;
718 
719 }
720 
721 int
723 
724  // Check that the vertex is in the Famos "acceptance"
725  if ( !myFilter->accept(v) ) return -1;
726 
727  // The number of vertices
728  int vertexId = nSimVertices++;
730  theVertexSize *= 2;
731  theSimVertices->resize(theVertexSize);
733  }
734 
735  // Attach the end vertex to the particle (if accepted)
736  if ( im !=-1 ) track(im).setEndVertex(vertexId);
737 
738  // Some transient information for FAMOS internal use
739  (*theSimVertices)[vertexId] = FSimVertex(v,im,vertexId,this);
740 
741  (*theFSimVerticesType)[vertexId] = FSimVertexType(type);
742 
743  return vertexId;
744 
745 }
746 
747 void
748 FBaseSimEvent::printMCTruth(const HepMC::GenEvent& myGenEvent) {
749 
750  std::cout << "Id Gen Name eta phi pT E Vtx1 "
751  << " x y z "
752  << "Moth Vtx2 eta phi R Z Da1 Da2 Ecal?" << std::endl;
753 
754  for ( HepMC::GenEvent::particle_const_iterator
755  piter = myGenEvent.particles_begin();
756  piter != myGenEvent.particles_end();
757  ++piter ) {
758 
759  HepMC::GenParticle* p = *piter;
760  /* */
761  int partId = p->pdg_id();
763 
764  if ( pdt->particle(ParticleID(partId)) !=0 ) {
765  name = (pdt->particle(ParticleID(partId)))->name();
766  } else {
767  name = "none";
768  }
769 
770  XYZTLorentzVector momentum1(p->momentum().px(),
771  p->momentum().py(),
772  p->momentum().pz(),
773  p->momentum().e());
774 
775  int vertexId1 = 0;
776 
777  if ( !p->production_vertex() ) continue;
778 
779  XYZVector vertex1 (p->production_vertex()->position().x()/10.,
780  p->production_vertex()->position().y()/10.,
781  p->production_vertex()->position().z()/10.);
782  vertexId1 = p->production_vertex()->barcode();
783 
784  std::cout.setf(std::ios::fixed, std::ios::floatfield);
785  std::cout.setf(std::ios::right, std::ios::adjustfield);
786 
787  std::cout << std::setw(4) << p->barcode() << " "
788  << name;
789 
790  for(unsigned int k=0;k<11-name.length() && k<12; k++) std::cout << " ";
791 
792  double eta = momentum1.eta();
793  if ( eta > +10. ) eta = +10.;
794  if ( eta < -10. ) eta = -10.;
795  std::cout << std::setw(6) << std::setprecision(2) << eta << " "
796  << std::setw(6) << std::setprecision(2) << momentum1.phi() << " "
797  << std::setw(7) << std::setprecision(2) << momentum1.pt() << " "
798  << std::setw(7) << std::setprecision(2) << momentum1.e() << " "
799  << std::setw(4) << vertexId1 << " "
800  << std::setw(6) << std::setprecision(1) << vertex1.x() << " "
801  << std::setw(6) << std::setprecision(1) << vertex1.y() << " "
802  << std::setw(6) << std::setprecision(1) << vertex1.z() << " ";
803 
804  const HepMC::GenParticle* mother =
805  *(p->production_vertex()->particles_in_const_begin());
806 
807  if ( mother )
808  std::cout << std::setw(4) << mother->barcode() << " ";
809  else
810  std::cout << " " ;
811 
812  if ( p->end_vertex() ) {
813  XYZTLorentzVector vertex2(p->end_vertex()->position().x()/10.,
814  p->end_vertex()->position().y()/10.,
815  p->end_vertex()->position().z()/10.,
816  p->end_vertex()->position().t()/10.);
817  int vertexId2 = p->end_vertex()->barcode();
818 
819  std::vector<const HepMC::GenParticle*> children;
820  HepMC::GenVertex::particles_out_const_iterator firstDaughterIt =
821  p->end_vertex()->particles_out_const_begin();
822  HepMC::GenVertex::particles_out_const_iterator lastDaughterIt =
823  p->end_vertex()->particles_out_const_end();
824  for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
825  children.push_back(*firstDaughterIt);
826  }
827 
828  std::cout << std::setw(4) << vertexId2 << " "
829  << std::setw(6) << std::setprecision(2) << vertex2.eta() << " "
830  << std::setw(6) << std::setprecision(2) << vertex2.phi() << " "
831  << std::setw(5) << std::setprecision(1) << vertex2.pt() << " "
832  << std::setw(6) << std::setprecision(1) << vertex2.z() << " ";
833  for ( unsigned id=0; id<children.size(); ++id )
834  std::cout << std::setw(4) << children[id]->barcode() << " ";
835  }
836  std::cout << std::endl;
837 
838  }
839 
840 }
841 
842 void
844 
845  std::cout << " Id Gen Name eta phi pT E Vtx1 "
846  << " x y z "
847  << "Moth Vtx2 eta phi R Z Daughters Ecal?" << std::endl;
848 
849  for( int i=0; i<(int)nTracks(); i++ )
850  std::cout << track(i) << std::endl;
851 
852  for( int i=0; i<(int)nVertices(); i++ )
853  std::cout << "i = " << i << " " << vertexType(i) << std::endl;
854 
855 
856 
857 }
858 
859 void
861 
862  nSimTracks = 0;
863  nSimVertices = 0;
864  nGenParticles = 0;
866 
867 }
868 
869 void
871  (*theChargedTracks)[nChargedParticleTracks++] = id;
874  theChargedSize *= 2;
876  }
877 }
878 
879 int
881  if (id>=0 && id<(int)nChargedParticleTracks)
882  return (*theChargedTracks)[id];
883  else
884  return -1;
885 }
886 
887 /*
888 const SimTrack &
889 FBaseSimEvent::embdTrack(int i) const {
890  return (*theSimTracks)[i].simTrack();
891 }
892 
893 const SimVertex &
894 FBaseSimEvent::embdVertex(int i) const {
895  return (*theSimVertices)[i].simVertex();
896 }
897 */
898 
899 const HepMC::GenParticle*
901  return (*theGenParticles)[i];
902 }
903 
904 /*
905 FSimTrack&
906 FBaseSimEvent::track(int id) const {
907  return (*theSimTracks)[id];
908 }
909 
910 
911 FSimVertex&
912 FBaseSimEvent::vertex(int id) const {
913  return (*theSimVertices)[id];
914 }
915 */
const ParticleDataTable * pdt
double lateVertexPosition
type
Definition: HCALResponse.h:21
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
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.
int i
Definition: DBlmapReader.cc:9
virtual int pdgId() const
PDG identifier.
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
virtual int status() const
status word
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
virtual int status() const =0
status word
KineParticleFilter * myFilter
The particle filter.
virtual double vx() const =0
x coordinate of vertex position
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
T eta() const
virtual double vy() const
y coordinate of vertex position
unsigned int theGenSize
float float float z
bool notYetToEndVertex(const XYZTLorentzVector &pos) const
Compare the end vertex position with another position.
Definition: FSimTrack.cc:33
virtual double vy() const =0
y coordinate of vertex position
FSimVertex & vertex(int id) const
Return vertex with given Id.
unsigned int nVertices() const
Number of vertices.
Definition: FBaseSimEvent.h:93
FSimVertexType & vertexType(int id) const
Return vertex with given Id.
bool propagateToVFcalEntrance(bool first=true)
virtual double energy() const
energy
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
virtual size_t numberOfMothers() const
number of mothers
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:88
bool propagateToHcalExit(bool first=true)
const_iterator end() const
last daughter const_iterator
Definition: Candidate.h:146
virtual size_t numberOfDaughters() const
number of daughters
unsigned int nSimVertices
int genpartIndex() const
index of the corresponding Generator particle in the Event container (-1 if no Genpart) ...
Definition: SimTrack.h:33
virtual const Candidate * daughter(size_type) const
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
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
virtual double vz() const
z coordinate of vertex position
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
virtual int pdgId() const =0
PDG identifier.
const XYZTLorentzVector & vertex() const
the vertex fourvector
Definition: RawParticle.h:285
virtual double px() const
x coordinate of momentum vector
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
virtual double pz() const
z coordinate of momentum vector
virtual double vz() const =0
z coordinate of vertex position
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:98
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.
virtual double vx() const
x coordinate of vertex position
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
Definition: DDAxes.h:10
std::vector< HepMC::GenParticle * > * theGenParticles
bool propagateToHOLayer(bool first=true)
bool propagateToPreshowerLayer2(bool first=true)
virtual const Candidate * mother(size_type=0) const
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...
virtual double py() const
y coordinate of momentum vector
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