CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BaseFlatGunProducer.cc
Go to the documentation of this file.
1 /*
2  * $Date: 2013/05/17 20:09:07 $
3  * $Revision: 1.9 $
4  * \author Julia Yarba
5  */
6 
7 #include <ostream>
8 #include <memory>
9 
17 
20 
22 
24 
25 
26 #include <iostream>
27 
28 using namespace edm;
29 using namespace std;
30 using namespace CLHEP;
31 
32 namespace {
33  CLHEP::HepRandomEngine& getEngineReference()
34  {
35 
37  if(!rng.isAvailable()) {
38  throw cms::Exception("Configuration")
39  << "The RandomNumberProducer module requires the RandomNumberGeneratorService\n"
40  "which appears to be absent. Please add that service to your configuration\n"
41  "or remove the modules that require it.";
42  }
43 
44 // The Service has already instantiated an engine. Make contact with it.
45  return (rng->getEngine());
46  }
47 }
48 
50  fEvt(0),
51  fRandomEngine(getEngineReference()),
52  fRandomGenerator(0)
53  // fPDGTable( new DefaultConfig::ParticleDataTable("PDG Table") )
54 {
55 
56  ParameterSet pgun_params = pset.getParameter<ParameterSet>("PGunParameters") ;
57 
58  // although there's the method ParameterSet::empty(),
59  // it looks like it's NOT even necessary to check if it is,
60  // before trying to extract parameters - if it is empty,
61  // the default values seem to be taken
62  fPartIDs = pgun_params.getParameter< vector<int> >("PartID");
63  fMinEta = pgun_params.getParameter<double>("MinEta");
64  fMaxEta = pgun_params.getParameter<double>("MaxEta");
65  fMinPhi = pgun_params.getParameter<double>("MinPhi");
66  fMaxPhi = pgun_params.getParameter<double>("MaxPhi");
67 
68  //
69  //fPDGTablePath = "/afs/cern.ch/sw/lcg/external/clhep/1.9.2.1/slc3_ia32_gcc323/data/HepPDT/" ;
70 /*
71  string HepPDTBase( getenv("HEPPDT_PARAM_PATH") ) ;
72  fPDGTablePath = HepPDTBase + "/data/" ;
73  fPDGTableName = "PDG_mass_width_2004.mc"; // should it be 2004 table ?
74 
75  string TableFullName = fPDGTablePath + fPDGTableName ;
76  ifstream PDFile( TableFullName.c_str() ) ;
77  if( !PDFile )
78  {
79  throw cms::Exception("FileNotFound", "BaseFlatGunProducer::BaseFlatGunProducer()")
80  << "File " << TableFullName << " cannot be opened.\n";
81  }
82 
83  HepPDT::TableBuilder tb(*fPDGTable) ;
84  if ( !addPDGParticles( PDFile, tb ) ) { cout << " Error reading PDG !" << endl; }
85  // the tb dtor fills fPDGTable
86 */
87 
88  fVerbosity = pset.getUntrackedParameter<int>( "Verbosity",0 ) ;
89 
90 // The Service has already instantiated an engine. Use it.
91  fRandomGenerator = new CLHEP::RandFlat(fRandomEngine) ;
92  fAddAntiParticle = pset.getParameter<bool>("AddAntiParticle") ;
93 
94  produces<GenRunInfoProduct, InRun>();
95 }
96 
98 {
99 
100 //if ( fRandomGenerator != NULL ) delete fRandomGenerator;
101  // do I need to delete the Engine, too ?
102 
103  // no need to cleanup GenEvent memory - done in HepMCProduct
104  // if (fEvt != NULL) delete fEvt ; // double check
105  // delete fPDGTable;
106 
107 }
108 
109 
111 {
112  es.getData( fPDGTable ) ;
113  return ;
114 
115 }
116 void BaseFlatGunProducer::endRun(const Run &run, const EventSetup& es ) {
117 }
118 
119 
121 {
122  // just create an empty product
123  // to keep the EventContent definitions happy
124  // later on we might put the info into the run info that this is a PGun
125  auto_ptr<GenRunInfoProduct> genRunInfo( new GenRunInfoProduct() );
126  run.put( genRunInfo );
127 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void endRun(edm::Run const &r, const edm::EventSetup &) override
CLHEP::HepRandomEngine & fRandomEngine
BaseFlatGunProducer(const ParameterSet &)
void getData(T &iHolder) const
Definition: EventSetup.h:67
void endRunProduce(edm::Run &r, const edm::EventSetup &) override
CLHEP::HepRandomEngine & getEngineReference()
ESHandle< HepPDT::ParticleDataTable > fPDGTable
CLHEP::RandFlat * fRandomGenerator
bool isAvailable() const
Definition: Service.h:47
void beginRun(const edm::Run &r, const edm::EventSetup &) override
std::vector< int > fPartIDs
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
void put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Run.h:86
Definition: Run.h:36