CMS 3D CMS Logo

Public Member Functions | Private Attributes

edm::FlatRandomEGunProducer Class Reference

#include <FlatRandomEGunProducer.h>

Inheritance diagram for edm::FlatRandomEGunProducer:
edm::BaseFlatGunProducer edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 FlatRandomEGunProducer (const ParameterSet &pset)
virtual void produce (Event &e, const EventSetup &es)
virtual ~FlatRandomEGunProducer ()

Private Attributes

double fMaxE
double fMinE

Detailed Description

Definition at line 15 of file FlatRandomEGunProducer.h.


Constructor & Destructor Documentation

FlatRandomEGunProducer::FlatRandomEGunProducer ( const ParameterSet pset)

Definition at line 20 of file FlatRandomEGunProducer.cc.

References gather_cfg::cout, fMaxE, fMinE, and edm::ParameterSet::getParameter().

                                                                       :
   BaseFlatGunProducer(pset)
{

   ParameterSet defpset ;
   // ParameterSet pgun_params = pset.getParameter<ParameterSet>("PGunParameters") ;
   ParameterSet pgun_params = 
      pset.getParameter<ParameterSet>("PGunParameters") ;
  
   // doesn't seem necessary to check if pset is empty - if this
   // is the case, default values will be taken for params
   fMinE = pgun_params.getParameter<double>("MinE");
   fMaxE = pgun_params.getParameter<double>("MaxE"); 
  
   produces<HepMCProduct>();
   produces<GenEventInfoProduct>();

   cout << "Internal FlatRandomEGun is initialzed" << endl ;
// cout << "It is going to generate " << remainingEvents() << "events" << endl ;
   
}
FlatRandomEGunProducer::~FlatRandomEGunProducer ( ) [virtual]

Definition at line 42 of file FlatRandomEGunProducer.cc.

{
   // no need to cleanup fEvt since it's done in HepMCProduct
}

Member Function Documentation

void FlatRandomEGunProducer::produce ( Event e,
const EventSetup es 
) [virtual]

Implements edm::EDProducer.

Definition at line 47 of file FlatRandomEGunProducer.cc.

References abs, funct::cos(), gather_cfg::cout, relval_parameters_module::energy, eta(), edm::EventID::event(), create_public_lumi_plots::exp, edm::BaseFlatGunProducer::fAddAntiParticle, edm::BaseFlatGunProducer::fEvt, fMaxE, edm::BaseFlatGunProducer::fMaxEta, edm::BaseFlatGunProducer::fMaxPhi, fMinE, edm::BaseFlatGunProducer::fMinEta, edm::BaseFlatGunProducer::fMinPhi, edm::BaseFlatGunProducer::fPartIDs, edm::BaseFlatGunProducer::fPDGTable, edm::BaseFlatGunProducer::fRandomGenerator, edm::BaseFlatGunProducer::fVerbosity, configurableAnalysis::GenParticle, edm::EventBase::id(), scaleCards::mass, AlCaHLTBitMon_ParallelJobs::p, RecoTau_DiTaus_pt_20-420_cfg::ParticleID, phi, edm::Event::put(), funct::sin(), mathSSE::sqrt(), and theta().

{

   if ( fVerbosity > 0 )
   {
      cout << " FlatRandomEGunProducer : Begin New Event Generation" << endl ; 
   }
   
   // event loop (well, another step in it...)
          
   // no need to clean up GenEvent memory - done in HepMCProduct

   // here re-create fEvt (memory)
   //
   fEvt = new HepMC::GenEvent() ;
   
   // now actualy, cook up the event from PDGTable and gun parameters
   //

   // 1st, primary vertex
   //
   HepMC::GenVertex* Vtx = new HepMC::GenVertex( HepMC::FourVector(0.,0.,0.));
   
   // loop over particles
   //
   int barcode = 1;
   for (unsigned int ip=0; ip<fPartIDs.size(); ip++)
   {
       double energy = fRandomGenerator->fire(fMinE, fMaxE) ;
       double eta    = fRandomGenerator->fire(fMinEta, fMaxEta) ;
       double phi    = fRandomGenerator->fire(fMinPhi, fMaxPhi) ;
       int PartID = fPartIDs[ip] ;
       const HepPDT::ParticleData* 
          PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID))) ;
       double mass   = PData->mass().value() ;
       double mom2   = energy*energy - mass*mass ;
       double mom    = 0. ;
       if (mom2 > 0.) 
       {
          mom = sqrt(mom2) ;
       }
       else
       {
          mom = 0. ;
       }
       double theta  = 2.*atan(exp(-eta)) ;
       double px     = mom*sin(theta)*cos(phi) ;
       double py     = mom*sin(theta)*sin(phi) ;
       double pz     = mom*cos(theta) ;

       HepMC::FourVector p(px,py,pz,energy) ;
       HepMC::GenParticle* Part = 
           new HepMC::GenParticle(p,PartID,1);
       Part->suggest_barcode( barcode ) ;
       barcode++ ;
       Vtx->add_particle_out(Part);
       
       if ( fAddAntiParticle )
       {
          HepMC::FourVector ap(-px,-py,-pz,energy) ;
          int APartID = -PartID ;
          if ( PartID == 22 || PartID == 23 )
          {
             APartID = PartID ;
          }
          HepMC::GenParticle* APart =
             new HepMC::GenParticle(ap,APartID,1);
          APart->suggest_barcode( barcode ) ;
          barcode++ ;
          Vtx->add_particle_out(APart) ;
       }
       
   }
   fEvt->add_vertex(Vtx) ;
   fEvt->set_event_number(e.id().event()) ;
   fEvt->set_signal_process_id(20) ;  
   
   
   if ( fVerbosity > 0 )
   {
      fEvt->print() ;  
   }  

   auto_ptr<HepMCProduct> BProduct(new HepMCProduct()) ;
   BProduct->addHepMCData( fEvt );
   e.put(BProduct);

   auto_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
   e.put(genEventInfo);
    
   if ( fVerbosity > 0 )
   {
      // for testing purpose only
      //fEvt->print() ;  // for some strange reason, it prints NO event info
      // after it's been put into edm::Event...
      cout << " FlatRandomEGunProducer : Event Generation Done " << endl;
   }
}

Member Data Documentation

Definition at line 29 of file FlatRandomEGunProducer.h.

Referenced by FlatRandomEGunProducer(), and produce().

Definition at line 28 of file FlatRandomEGunProducer.h.

Referenced by FlatRandomEGunProducer(), and produce().