CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BaseFlatGunSource.cc
Go to the documentation of this file.
1 /*
2  * $Date: 2010/01/19 16:17:26 $
3  * $Revision: 1.21 $
4  * \author Julia Yarba
5  */
6 
7 #include <ostream>
8 
10 
12 
14 
17 
18 // #include "FWCore/Framework/intercface/ESHandle.h"
19 // #include "FWCore/Framework/interface/EventSetup.h"
21 
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  const InputSourceDescription& desc ) :
49  GeneratedInputSource (pset, desc),
50  fEvt(0),
51  fRandomEngine(getEngineReference()),
52  fRandomGenerator(0)
53  // fPDGTable( new DefaultConfig::ParticleDataTable("PDG Table") )
54 {
55 
56  ParameterSet defpset ;
57  //ParameterSet pgun_params = pset.getParameter<ParameterSet>("PGunParameters") ;
58  ParameterSet pgun_params =
59  pset.getUntrackedParameter<ParameterSet>("PGunParameters", defpset ) ;
60 
61  // although there's the method ParameterSet::empty(),
62  // it looks like it's NOT even necessary to check if it is,
63  // before trying to extract parameters - if it is empty,
64  // the default values seem to be taken
65  vector<int> defids ;
66  defids.push_back(13) ;
67  fPartIDs = pgun_params.getUntrackedParameter< vector<int> >("PartID",defids);
68  fMinEta = pgun_params.getUntrackedParameter<double>("MinEta",-5.5);
69  fMaxEta = pgun_params.getUntrackedParameter<double>("MaxEta",5.5);
70  fMinPhi = pgun_params.getUntrackedParameter<double>("MinPhi",-3.14159265358979323846);
71  fMaxPhi = pgun_params.getUntrackedParameter<double>("MaxPhi", 3.14159265358979323846);
72 
73  //
74  //fPDGTablePath = "/afs/cern.ch/sw/lcg/external/clhep/1.9.2.1/slc3_ia32_gcc323/data/HepPDT/" ;
75 /*
76  string HepPDTBase( getenv("HEPPDT_PARAM_PATH") ) ;
77  fPDGTablePath = HepPDTBase + "/data/" ;
78  fPDGTableName = "PDG_mass_width_2004.mc"; // should it be 2004 table ?
79 
80  string TableFullName = fPDGTablePath + fPDGTableName ;
81  ifstream PDFile( TableFullName.c_str() ) ;
82  if( !PDFile )
83  {
84  throw cms::Exception("FileNotFound", "BaseFlatGunSource::BaseFlatGunSource()")
85  << "File " << TableFullName << " cannot be opened.\n";
86  }
87 
88  HepPDT::TableBuilder tb(*fPDGTable) ;
89  if ( !addPDGParticles( PDFile, tb ) ) { cout << " Error reading PDG !" << endl; }
90  // the tb dtor fills fPDGTable
91 */
92 
93  fVerbosity = pset.getUntrackedParameter<int>( "Verbosity",0 ) ;
94 
95 // The Service has already instantiated an engine. Use it.
96  fRandomGenerator = new CLHEP::RandFlat(fRandomEngine) ;
97  fAddAntiParticle = pset.getUntrackedParameter<bool>("AddAntiParticle",false);
98 
99 }
100 
102 {
103 
104  if ( fRandomGenerator != NULL ) delete fRandomGenerator;
105 
106  // no need to cleanup GenEvent memory - done in HepMCProduct
107  // if (fEvt != NULL) delete fEvt ; // double check
108  // delete fPDGTable;
109 
110 }
111 
112 
114 {
115 
116  es.getData( fPDGTable ) ;
117 
118  return ;
119 
120 }
std::vector< int > fPartIDs
T getUntrackedParameter(std::string const &, T const &) const
BaseFlatGunSource(const ParameterSet &, const InputSourceDescription &)
#define NULL
Definition: scimark2.h:8
CLHEP::RandFlat * fRandomGenerator
void getData(T &iHolder) const
Definition: EventSetup.h:67
CLHEP::HepRandomEngine & getEngineReference()
void beginRun(edm::Run &r, const edm::EventSetup &)
bool isAvailable() const
Definition: Service.h:47
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
ESHandle< HepPDT::ParticleDataTable > fPDGTable
CLHEP::HepRandomEngine & fRandomEngine
Definition: Run.h:33