CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ExpoRandomPtGunSource.cc
Go to the documentation of this file.
1 /*
2  * $Date: 2009/05/25 13:00:58 $
3  * $Revision: 1.4 $
4  * \author Jean-Roch Vlimant
5  */
6 
7 #include <ostream>
8 
10 
12 
15 
16 // #include "FWCore/Utilities/interface/Exception.h"
17 
18 // #include "CLHEP/Random/RandExpo.h"
19 
20 using namespace edm;
21 using namespace std;
22 
24  const InputSourceDescription& desc) :
25  BaseFlatGunSource(pset, desc)
26 {
27 
28 
29  ParameterSet defpset ;
30  ParameterSet pgun_params =
31  pset.getUntrackedParameter<ParameterSet>("PGunParameters",defpset) ;
32 
33  fMinPt = pgun_params.getUntrackedParameter<double>("MinPt",0.99);
34  fMaxPt = pgun_params.getUntrackedParameter<double>("MaxPt",1.01);
35 
36  fMeanPt = pgun_params.getUntrackedParameter<double>("MeanPt",-1.);
37 
38  produces<HepMCProduct>();
39 
40  //the explonential generator
41  fRandomExpoGenerator = new CLHEP::RandExponential(fRandomEngine,fMeanPt);
42 
43 }
44 
46 {
47  // no need to cleanup GenEvent memory - done in HepMCProduct
48 }
49 
51 {
52 
53  if ( fVerbosity > 0 )
54  {
55  cout << " ExpoRandomPtGunSource : Begin New Event Generation" << endl ;
56  }
57  // event loop (well, another step in it...)
58 
59  // no need to clean up GenEvent memory - done in HepMCProduct
60  //
61 
62  // here re-create fEvt (memory)
63  //
64  fEvt = new HepMC::GenEvent() ;
65 
66  // now actualy, cook up the event from PDGTable and gun parameters
67  //
68  // 1st, primary vertex
69  //
70  //HepMC::GenVertex* Vtx = new HepMC::GenVertex(CLHEP::HepLorentzVector(0.,0.,0.));
71  HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(0.,0.,0.));
72 
73  // loop over particles
74  //
75  int barcode = 1 ;
76  for (unsigned int ip=0; ip<fPartIDs.size(); ++ip)
77  {
78 
79  //the max is to ensure you don't generate at 0
80  //the 90% is to get rid of edge effect
81 
82  double pt = std::max(0.00001,0.90*fMinPt)+fRandomExpoGenerator->fire(fMeanPt);
83  //shoot until in the designated range
84  while (pt<fMinPt || pt>fMaxPt)
85  {pt = std::max(0.00001,0.90*fMinPt) + fRandomExpoGenerator->fire(fMeanPt);}
86 
87  double eta = fRandomGenerator->fire(fMinEta, fMaxEta) ;
88  double phi = fRandomGenerator->fire(fMinPhi, fMaxPhi) ;
89  int PartID = fPartIDs[ip] ;
90  const HepPDT::ParticleData*
91  PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID))) ;
92  double mass = PData->mass().value() ;
93  double theta = 2.*atan(exp(-eta)) ;
94  double mom = pt/sin(theta) ;
95  double px = pt*cos(phi) ;
96  double py = pt*sin(phi) ;
97  double pz = mom*cos(theta) ;
98  double energy2= mom*mom + mass*mass ;
99  double energy = sqrt(energy2) ;
100  //CLHEP::Hep3Vector p(px,py,pz) ;
101  //HepMC::GenParticle* Part =
102  // new HepMC::GenParticle(CLHEP::HepLorentzVector(p,energy),PartID,1);
103  HepMC::FourVector p(px,py,pz,energy) ;
104  HepMC::GenParticle* Part =
105  new HepMC::GenParticle(p,PartID,1);
106  Part->suggest_barcode( barcode ) ;
107  barcode++ ;
108  Vtx->add_particle_out(Part);
109 
110  if ( fAddAntiParticle )
111  {
112  //CLHEP::Hep3Vector ap(-px,-py,-pz) ;
113  HepMC::FourVector ap(-px,-py,-pz,energy) ;
114  int APartID = -PartID ;
115  if ( PartID == 22 || PartID == 23 )
116  {
117  APartID = PartID ;
118  }
119  //HepMC::GenParticle* APart =
120  // new HepMC::GenParticle(CLHEP::HepLorentzVector(ap,energy),APartID,1);
121  HepMC::GenParticle* APart =
122  new HepMC::GenParticle(ap,APartID,1);
123  APart->suggest_barcode( barcode ) ;
124  barcode++ ;
125  Vtx->add_particle_out(APart) ;
126  }
127 
128  }
129 
130  fEvt->add_vertex(Vtx) ;
131  fEvt->set_event_number(event()) ;
132  fEvt->set_signal_process_id(20) ;
133 
134  if ( fVerbosity > 0 )
135  {
136  fEvt->print() ;
137  }
138 
139  auto_ptr<HepMCProduct> BProduct(new HepMCProduct()) ;
140  BProduct->addHepMCData( fEvt );
141  e.put(BProduct);
142 
143  if ( fVerbosity > 0 )
144  {
145  // for testing purpose only
146  // fEvt->print() ; // prints empty info after it's made into edm::Event
147  cout << " FlatRandomPtGunSource : Event Generation Done " << endl;
148  }
149 
150  return true;
151 }
152 
std::vector< int > fPartIDs
T getUntrackedParameter(std::string const &, T const &) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
ExpoRandomPtGunSource(const ParameterSet &, const InputSourceDescription &)
#define abs(x)
Definition: mlp_lapack.h:159
CLHEP::RandFlat * fRandomGenerator
T eta() const
virtual bool produce(Event &e)
const T & max(const T &a, const T &b)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
T sqrt(T t)
Definition: SSEVec.h:46
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
HepPDT::ParticleData ParticleData
ESHandle< HepPDT::ParticleDataTable > fPDGTable
CLHEP::RandExponential * fRandomExpoGenerator
HepMC::GenEvent * fEvt
CLHEP::HepRandomEngine & fRandomEngine
tuple mass
Definition: scaleCards.py:27
tuple cout
Definition: gather_cfg.py:121
Definition: DDAxes.h:10