CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PileUpSimulator.cc
Go to the documentation of this file.
4 
5 #include "HepMC/GenEvent.h"
6 
7 //#include <iostream>
8 
10  :
11  mySimEvent(aSimEvent)
12 {}
13 
15 
16 void PileUpSimulator::produce(const HepMC::GenEvent* myGenEvent)
17 {
18 
19  // There might be no pile-up event to process (Poisson and/or flag)
20  if ( !myGenEvent ) return;
21 
22  // Pile-up event iterator
23  HepMC::GenEvent::vertex_const_iterator viter;
24  HepMC::GenEvent::vertex_const_iterator vbegin = myGenEvent->vertices_begin();
25  HepMC::GenEvent::vertex_const_iterator vend = myGenEvent->vertices_end();
26 
27  int ievt = 0;
28  // Loop on all pile-up events
29  for ( viter=vbegin; viter!=vend; ++viter ) {
30 
31  // The origin vertex (turn it to cm's from GenEvent mm's)
32  HepMC::GenVertex* v = *viter;
33  XYZTLorentzVector smearedVertex =
34  XYZTLorentzVector(v->position().x()/10.,v->position().y()/10.,
35  v->position().z()/10.,v->position().t()/10.);
36 
37  //std::cout << "Vertex position " << smearedVertex << std::endl;
38 
39  // Add it to the FBaseSimEvent
40  int mainVertex = mySimEvent->addSimVertex(smearedVertex, -1, FSimVertexType::PILEUP_VERTEX);
41 
42  // Particles iterator
43  HepMC::GenVertex::particles_out_const_iterator firstDaughterIt = v->particles_out_const_begin();
44  HepMC::GenVertex::particles_out_const_iterator lastDaughterIt = v->particles_out_const_end();
45 
46  // Loop on particles
47  for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
48 
49  // A particle
50  HepMC::GenParticle* daugh = *firstDaughterIt;
51  RawParticle myPart(XYZTLorentzVector(daugh->momentum().px(),
52  daugh->momentum().py(),
53  daugh->momentum().pz(),
54  daugh->momentum().e()),
55  smearedVertex);
56 
57  // Add it to the FBaseSimEvent
58  myPart.setID(daugh->pdg_id());
59  // myPart.print();
60 
61  // Add the particle to the event (with a genpartIndex
62  // indicating the pileup event index)
63  mySimEvent->addSimTrack(&myPart,mainVertex,-ievt-2);
64 
65  // End particle loop
66  }
67 
68  // Increment the number of pile-up events
69  ++ievt;
70  // End vertex loop
71  }
72  // Pile-up events now inserted
73 
74 }
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 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.
PileUpSimulator(FSimEvent *aSimEvent)
Constructor.
FSimEvent * mySimEvent
#define vend()
Definition: vmac.h:41
void setID(const int id)
Definition: RawParticle.cc:101
#define vbegin()
Definition: vmac.h:34
void produce(const HepMC::GenEvent *pu)
Produce N minimum bias events, and add them to the FSimEvent.
~PileUpSimulator()
Default Destructor.
math::XYZTLorentzVector XYZTLorentzVector
Definition: RawParticle.h:15