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