CMS 3D CMS Logo

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