CMS 3D CMS Logo

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

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