CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/IOMC/ParticleGuns/src/BaseFlatGunProducer.cc

Go to the documentation of this file.
00001 /*
00002  *  $Date: 2010/01/19 16:17:26 $
00003  *  $Revision: 1.7 $
00004  *  \author Julia Yarba
00005  */
00006 
00007 #include <ostream>
00008 #include <memory>
00009 
00010 #include "FWCore/Framework/interface/EDProducer.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "FWCore/Framework/interface/Run.h"
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "FWCore/Utilities/interface/Exception.h"
00015 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 
00018 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00019 #include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
00020 
00021 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00022 
00023 #include "IOMC/ParticleGuns/interface/BaseFlatGunProducer.h"
00024 
00025 
00026 #include <iostream>
00027 
00028 using namespace edm;
00029 using namespace std;
00030 using namespace CLHEP;
00031 
00032 namespace {
00033   CLHEP::HepRandomEngine& getEngineReference()
00034   {
00035 
00036    Service<RandomNumberGenerator> rng;
00037    if(!rng.isAvailable()) {
00038     throw cms::Exception("Configuration")
00039        << "The RandomNumberProducer module requires the RandomNumberGeneratorService\n"
00040           "which appears to be absent.  Please add that service to your configuration\n"
00041           "or remove the modules that require it.";
00042    }
00043 
00044 // The Service has already instantiated an engine.  Make contact with it.
00045    return (rng->getEngine());
00046   }
00047 }
00048 
00049 BaseFlatGunProducer::BaseFlatGunProducer( const ParameterSet& pset ) :
00050    fEvt(0),
00051    fRandomEngine(getEngineReference()),
00052    fRandomGenerator(0)
00053    // fPDGTable( new DefaultConfig::ParticleDataTable("PDG Table") )
00054 {
00055 
00056    ParameterSet pgun_params = pset.getParameter<ParameterSet>("PGunParameters") ;
00057   
00058    // although there's the method ParameterSet::empty(),  
00059    // it looks like it's NOT even necessary to check if it is,
00060    // before trying to extract parameters - if it is empty,
00061    // the default values seem to be taken
00062    fPartIDs    = pgun_params.getParameter< vector<int> >("PartID");  
00063    fMinEta     = pgun_params.getParameter<double>("MinEta");
00064    fMaxEta     = pgun_params.getParameter<double>("MaxEta");
00065    fMinPhi     = pgun_params.getParameter<double>("MinPhi");
00066    fMaxPhi     = pgun_params.getParameter<double>("MaxPhi");
00067 
00068   //
00069   //fPDGTablePath = "/afs/cern.ch/sw/lcg/external/clhep/1.9.2.1/slc3_ia32_gcc323/data/HepPDT/" ;
00070 /*
00071   string HepPDTBase( getenv("HEPPDT_PARAM_PATH") ) ; 
00072   fPDGTablePath = HepPDTBase + "/data/" ;
00073   fPDGTableName = "PDG_mass_width_2004.mc"; // should it be 2004 table ?
00074 
00075   string TableFullName = fPDGTablePath + fPDGTableName ;
00076   ifstream PDFile( TableFullName.c_str() ) ;
00077   if( !PDFile ) 
00078   {
00079       throw cms::Exception("FileNotFound", "BaseFlatGunProducer::BaseFlatGunProducer()")
00080         << "File " << TableFullName << " cannot be opened.\n";
00081   }
00082 
00083   HepPDT::TableBuilder tb(*fPDGTable) ;
00084   if ( !addPDGParticles( PDFile, tb ) ) { cout << " Error reading PDG !" << endl; }
00085   // the tb dtor fills fPDGTable
00086 */
00087 
00088   fVerbosity = pset.getUntrackedParameter<int>( "Verbosity",0 ) ;
00089 
00090 // The Service has already instantiated an engine.  Use it.
00091    fRandomGenerator = new CLHEP::RandFlat(fRandomEngine) ;
00092    fAddAntiParticle = pset.getParameter<bool>("AddAntiParticle") ;
00093 
00094    produces<GenRunInfoProduct, InRun>();
00095 }
00096 
00097 BaseFlatGunProducer::~BaseFlatGunProducer()
00098 {
00099   
00100 //if ( fRandomGenerator != NULL ) delete fRandomGenerator;
00101   // do I need to delete the Engine, too ?
00102   
00103   // no need to cleanup GenEvent memory - done in HepMCProduct
00104   // if (fEvt != NULL) delete fEvt ; // double check
00105   // delete fPDGTable;
00106   
00107 }
00108 
00109 
00110 void BaseFlatGunProducer::beginRun( edm::Run & r, const EventSetup& es )
00111 {
00112    es.getData( fPDGTable ) ;
00113    return ;
00114 
00115 }
00116 
00117 
00118 void BaseFlatGunProducer::endRun( Run &run, const EventSetup& es )
00119 {
00120    // just create an empty product
00121    // to keep the EventContent definitions happy
00122    // later on we might put the info into the run info that this is a PGun
00123    auto_ptr<GenRunInfoProduct> genRunInfo( new GenRunInfoProduct() );
00124    run.put( genRunInfo );
00125 }