CMS 3D CMS Logo

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