CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/FastSimulation/PileUpProducer/src/PileUpSimulator.cc

Go to the documentation of this file.
00001 #include "FastSimulation/PileUpProducer/interface/PileUpSimulator.h"
00002 #include "FastSimulation/Event/interface/FSimEvent.h"
00003 #include "FastSimulation/Particle/interface/RawParticle.h"
00004 
00005 #include "HepMC/GenEvent.h"
00006 
00007 //#include <iostream>
00008 
00009 PileUpSimulator::PileUpSimulator(FSimEvent* aSimEvent) 
00010   : 
00011   mySimEvent(aSimEvent)  
00012 {}
00013                
00014 PileUpSimulator::~PileUpSimulator() {}
00015 
00016 void PileUpSimulator::produce(const HepMC::GenEvent* myGenEvent)
00017 {
00018 
00019   // There might be no pile-up event to process (Poisson and/or flag)
00020   if ( !myGenEvent ) return;
00021 
00022   // Pile-up event iterator
00023   HepMC::GenEvent::vertex_const_iterator viter;
00024   HepMC::GenEvent::vertex_const_iterator vbegin = myGenEvent->vertices_begin();
00025   HepMC::GenEvent::vertex_const_iterator vend = myGenEvent->vertices_end();
00026   
00027   int ievt = 0;
00028   // Loop on all pile-up events
00029   for ( viter=vbegin; viter!=vend; ++viter ) { 
00030 
00031     // The origin vertex (turn it to cm's from GenEvent mm's)
00032     HepMC::GenVertex* v = *viter;    
00033     XYZTLorentzVector smearedVertex =  
00034       XYZTLorentzVector(v->position().x()/10.,v->position().y()/10.,
00035                         v->position().z()/10.,v->position().t()/10.);
00036 
00037     //std::cout << "Vertex position " << smearedVertex << std::endl;
00038 
00039     // Add it to the FBaseSimEvent
00040     int mainVertex = mySimEvent->addSimVertex(smearedVertex, -1, FSimVertexType::PILEUP_VERTEX);
00041 
00042     // Particles iterator
00043     HepMC::GenVertex::particles_out_const_iterator firstDaughterIt = v->particles_out_const_begin();
00044     HepMC::GenVertex::particles_out_const_iterator lastDaughterIt = v->particles_out_const_end();
00045 
00046     // Loop on particles
00047     for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
00048 
00049       // A particle
00050       HepMC::GenParticle* daugh = *firstDaughterIt;
00051       RawParticle myPart(XYZTLorentzVector(daugh->momentum().px(),
00052                                            daugh->momentum().py(),
00053                                            daugh->momentum().pz(),
00054                                            daugh->momentum().e()),
00055                          smearedVertex);
00056       
00057       // Add it to the FBaseSimEvent
00058       myPart.setID(daugh->pdg_id());
00059       // myPart.print();
00060 
00061       // Add the particle to the event (with a genpartIndex 
00062       // indicating the pileup event index)
00063       mySimEvent->addSimTrack(&myPart,mainVertex,-ievt-2);
00064 
00065       // End particle loop  
00066     }
00067 
00068     // Increment the number of pile-up events
00069     ++ievt;
00070     // End vertex loop
00071   }
00072   // Pile-up events now inserted
00073 
00074 }