CMS 3D CMS Logo

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     // std::cout << "Vertex n0 " << ievt << std::endl;
00032 
00033     // The origin vertex (turn it to cm's from GenEvent mm's)
00034     HepMC::GenVertex* v = *viter;    
00035     XYZTLorentzVector smearedVertex =  
00036       XYZTLorentzVector(v->position().x()/10.,v->position().y()/10.,
00037                         v->position().z()/10.,v->position().t()/10.);
00038 
00039     // std::cout << "Vertex position " << smearedVertex << std::endl;
00040 
00041     // Add it to the FBaseSimEvent
00042     int mainVertex = mySimEvent->addSimVertex(smearedVertex);
00043 
00044     // Particles iterator
00045     HepMC::GenVertex::particles_out_const_iterator firstDaughterIt = v->particles_out_const_begin();
00046     HepMC::GenVertex::particles_out_const_iterator lastDaughterIt = v->particles_out_const_end();
00047 
00048     // Loop on particles
00049     for ( ; firstDaughterIt != lastDaughterIt ; ++firstDaughterIt ) {
00050 
00051       // A particle
00052       HepMC::GenParticle* daugh = *firstDaughterIt;
00053       RawParticle myPart(XYZTLorentzVector(daugh->momentum().px(),
00054                                            daugh->momentum().py(),
00055                                            daugh->momentum().pz(),
00056                                            daugh->momentum().e()),
00057                          smearedVertex);
00058       
00059       // Add it to the FBaseSimEvent
00060       myPart.setID(daugh->pdg_id());
00061       // myPart.print();
00062 
00063       // Add the particle to the event (with a genpartIndex 
00064       // indicating the pileup event index)
00065       mySimEvent->addSimTrack(&myPart,mainVertex,-ievt-2);
00066 
00067       // End particle loop  
00068     }
00069 
00070     // Increment the number of pile-up events
00071     ++ievt;
00072     // End vertex loop
00073   }
00074   // Pile-up events now inserted
00075 
00076 }

Generated on Tue Jun 9 17:35:13 2009 for CMSSW by  doxygen 1.5.4