CMS 3D CMS Logo

FlatRandomEGunProducer.cc
Go to the documentation of this file.
1 /*
2  * \author Julia Yarba
3  */
4 
5 #include <ostream>
6 
8 
11 
16 
17 #include "CLHEP/Random/RandFlat.h"
18 
19 using namespace edm;
20 using namespace std;
21 
24 {
25 
26  ParameterSet defpset ;
27  // ParameterSet pgun_params = pset.getParameter<ParameterSet>("PGunParameters") ;
28  ParameterSet pgun_params =
29  pset.getParameter<ParameterSet>("PGunParameters") ;
30 
31  // doesn't seem necessary to check if pset is empty - if this
32  // is the case, default values will be taken for params
33  fMinE = pgun_params.getParameter<double>("MinE");
34  fMaxE = pgun_params.getParameter<double>("MaxE");
35 
36  produces<HepMCProduct>("unsmeared");
37  produces<GenEventInfoProduct>();
38 
39  cout << "Internal FlatRandomEGun is initialzed" << endl ;
40 // cout << "It is going to generate " << remainingEvents() << "events" << endl ;
41 
42 }
43 
45 {
46  // no need to cleanup fEvt since it's done in HepMCProduct
47 }
48 
50 {
52  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
53 
54  if ( fVerbosity > 0 )
55  {
56  cout << " FlatRandomEGunProducer : Begin New Event Generation" << endl ;
57  }
58 
59  // event loop (well, another step in it...)
60 
61  // no need to clean up GenEvent memory - done in HepMCProduct
62 
63  // here re-create fEvt (memory)
64  //
65  fEvt = new HepMC::GenEvent() ;
66 
67  // now actualy, cook up the event from PDGTable and gun parameters
68  //
69 
70  // 1st, primary vertex
71  //
72  HepMC::GenVertex* Vtx = new HepMC::GenVertex( HepMC::FourVector(0.,0.,0.));
73 
74  // loop over particles
75  //
76  int barcode = 1;
77  for (unsigned int ip=0; ip<fPartIDs.size(); ip++)
78  {
79  double energy = CLHEP::RandFlat::shoot(engine, fMinE, fMaxE) ;
80  double eta = CLHEP::RandFlat::shoot(engine, fMinEta, fMaxEta) ;
81  double phi = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi) ;
82  int PartID = fPartIDs[ip] ;
83  const HepPDT::ParticleData*
84  PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID))) ;
85  double mass = PData->mass().value() ;
86  double mom2 = energy*energy - mass*mass ;
87  double mom = 0. ;
88  if (mom2 > 0.)
89  {
90  mom = sqrt(mom2) ;
91  }
92  else
93  {
94  mom = 0. ;
95  }
96  double theta = 2.*atan(exp(-eta)) ;
97  double px = mom*sin(theta)*cos(phi) ;
98  double py = mom*sin(theta)*sin(phi) ;
99  double pz = mom*cos(theta) ;
100 
101  HepMC::FourVector p(px,py,pz,energy) ;
102  HepMC::GenParticle* Part =
103  new HepMC::GenParticle(p,PartID,1);
104  Part->suggest_barcode( barcode ) ;
105  barcode++ ;
106  Vtx->add_particle_out(Part);
107 
108  if ( fAddAntiParticle )
109  {
110  HepMC::FourVector ap(-px,-py,-pz,energy) ;
111  int APartID = -PartID ;
112  if ( PartID == 22 || PartID == 23 )
113  {
114  APartID = PartID ;
115  }
116  HepMC::GenParticle* APart =
117  new HepMC::GenParticle(ap,APartID,1);
118  APart->suggest_barcode( barcode ) ;
119  barcode++ ;
120  Vtx->add_particle_out(APart) ;
121  }
122 
123  }
124  fEvt->add_vertex(Vtx) ;
125  fEvt->set_event_number(e.id().event()) ;
126  fEvt->set_signal_process_id(20) ;
127 
128 
129  if ( fVerbosity > 0 )
130  {
131  fEvt->print() ;
132  }
133 
134  unique_ptr<HepMCProduct> BProduct(new HepMCProduct()) ;
135  BProduct->addHepMCData( fEvt );
136  e.put(std::move(BProduct), "unsmeared");
137 
138  unique_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
139  e.put(std::move(genEventInfo));
140 
141  if ( fVerbosity > 0 )
142  {
143  // for testing purpose only
144  //fEvt->print() ; // for some strange reason, it prints NO event info
145  // after it's been put into edm::Event...
146  cout << " FlatRandomEGunProducer : Event Generation Done " << endl;
147  }
148 }
FlatRandomEGunProducer(const ParameterSet &pset)
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
ESHandle< HepPDT::ParticleDataTable > fPDGTable
T sqrt(T t)
Definition: SSEVec.h:18
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< int > fPartIDs
HepPDT::ParticleData ParticleData
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
StreamID streamID() const
Definition: Event.h:86
void produce(Event &e, const EventSetup &es) override
def move(src, dest)
Definition: eostools.py:510