CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/IOMC/ParticleGuns/src/FlatBaseThetaGunProducer.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <memory>
00003 
00004 #include "FWCore/Framework/interface/Run.h"
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 
00010 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00011 #include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
00012 
00013 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00014 
00015 #include "IOMC/ParticleGuns/interface/FlatBaseThetaGunProducer.h"
00016 
00017 
00018 using namespace edm;
00019 
00020 namespace {
00021 
00022   CLHEP::HepRandomEngine& getEngineReference() {
00023 
00024     edm::Service<edm::RandomNumberGenerator> rng;
00025     if(!rng.isAvailable()) {
00026       throw cms::Exception("Configuration")
00027         << "The RandomNumberProducer module requires the RandomNumberGeneratorService\n"
00028         "which appears to be absent.  Please add that service to your configuration\n"
00029         "or remove the modules that require it.";
00030     }
00031 
00032     // The Service has already instantiated an engine.  Make contact with it.
00033     return (rng->getEngine());
00034   }
00035 }
00036 
00037 FlatBaseThetaGunProducer::FlatBaseThetaGunProducer(const edm::ParameterSet& pset) :
00038    fEvt(0),
00039    fRandomEngine(getEngineReference()),
00040    fRandomGenerator(0) {
00041 
00042   edm::ParameterSet pgun_params = pset.getParameter<edm::ParameterSet>("PGunParameters") ;
00043   
00044   fPartIDs  = pgun_params.getParameter<std::vector<int> >("PartID");  
00045   fMinTheta = pgun_params.getParameter<double>("MinTheta");
00046   fMaxTheta = pgun_params.getParameter<double>("MaxTheta");
00047   fMinPhi   = pgun_params.getParameter<double>("MinPhi");
00048   fMaxPhi   = pgun_params.getParameter<double>("MaxPhi");
00049   fVerbosity = pset.getUntrackedParameter<int>( "Verbosity",0 ) ;
00050 
00051   // The Service has already instantiated an engine.  Use it.
00052    fRandomGenerator = new CLHEP::RandFlat(fRandomEngine) ;
00053    fAddAntiParticle = pset.getParameter<bool>("AddAntiParticle") ;
00054 
00055    produces<GenRunInfoProduct, InRun>();
00056 }
00057 
00058 FlatBaseThetaGunProducer::~FlatBaseThetaGunProducer() {
00059 //  if ( fRandomGenerator != NULL ) delete fRandomGenerator;
00060 }
00061 
00062 
00063 void FlatBaseThetaGunProducer::beginRun( edm::Run &r, const edm::EventSetup& es ) {
00064    es.getData( fPDGTable ) ;
00065 }
00066 
00067 void FlatBaseThetaGunProducer::endRun( Run &run, const EventSetup& es )
00068 {
00069    // just create an empty product
00070    // to keep the EventContent definitions happy
00071    // later on we might put the info into the run info that this is a PGun
00072    std::auto_ptr<GenRunInfoProduct> genRunInfo( new GenRunInfoProduct() );
00073    run.put( genRunInfo );
00074 }