CMS 3D CMS Logo

FlatRandomPtAndDxyGunProducer.cc
Go to the documentation of this file.
1 #include <ostream>
2 
4 
7 
12 
13 #include "CLHEP/Random/RandFlat.h"
14 
15 using namespace edm;
16 using namespace std;
17 
20 {
21  ParameterSet defpset ;
22  ParameterSet pgun_params =
23  pset.getParameter<ParameterSet>("PGunParameters") ;
24 
25  fMinPt = pgun_params.getParameter<double>("MinPt");
26  fMaxPt = pgun_params.getParameter<double>("MaxPt");
27  dxyMin_ = pgun_params.getParameter<double>("dxyMin");
28  dxyMax_ = pgun_params.getParameter<double>("dxyMax");
29  lxyMax_ = pgun_params.getParameter<double>("LxyMax");
30  lzMax_ = pgun_params.getParameter<double>("LzMax");
31  ConeRadius_ = pgun_params.getParameter<double>("ConeRadius");
32  ConeH_ = pgun_params.getParameter<double>("ConeH");
33  DistanceToAPEX_ = pgun_params.getParameter<double>("DistanceToAPEX");
34 
35  produces<HepMCProduct>("unsmeared");
36  produces<GenEventInfoProduct>();
37 }
38 
40 {
41  // no need to cleanup GenEvent memory - done in HepMCProduct
42 }
43 
45 {
47  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
48 
49  if ( fVerbosity > 0 ){
50  cout << " FlatRandomPtAndDxyGunProducer : Begin New Event Generation" << endl ;
51  }
52  // event loop (well, another step in it...)
53 
54  // no need to clean up GenEvent memory - done in HepMCProduct
55  //
56 
57  // here re-create fEvt (memory)
58  //
59  fEvt = new HepMC::GenEvent() ;
60 
61  // now actualy, cook up the event from PDGTable and gun parameters
62  int barcode = 1 ;
63  for (unsigned int ip=0; ip<fPartIDs.size(); ++ip){
64 
65  double phi_vtx = 0;
66  double dxy = 0;
67  double pt = 0;
68  double eta = 0;
69  double px = 0;
70  double py = 0;
71  double pz = 0;
72  double vx = 0;
73  double vy = 0;
74  double vz = 0;
75  double lxy = 0;
76 
77  bool passLoop = false;
78  while (not passLoop) {
79 
80  bool passLxy = false;
81  bool passLz = false;
82  phi_vtx = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi);
83  dxy = CLHEP::RandFlat::shoot(engine, dxyMin_, dxyMax_);
84  float dxysign = CLHEP::RandFlat::shoot(engine, -1, 1);
85  if (dxysign < 0)
86  dxy = -dxy;
87  pt = CLHEP::RandFlat::shoot(engine, fMinPt, fMaxPt);
88  px = pt*cos(phi_vtx);
89  py = pt*sin(phi_vtx);
90  for (int i=0; i<10000; i++){
91  vx = CLHEP::RandFlat::shoot(engine, -lxyMax_, lxyMax_);
92  vy = (pt*dxy + vx * py)/px;
93  lxy = sqrt(vx*vx + vy*vy);
94  if (lxy<abs(lxyMax_) and (vx*px + vy*py)>0){
95  passLxy = true;
96  break;
97  }
98  }
99  eta = CLHEP::RandFlat::shoot(engine, fMinEta, fMaxEta);
100  pz = pt * sinh(eta);
101  //vz = fabs(fRandomGaussGenerator->fire(0.0, LzWidth_/2.0));
102  float ConeTheta = ConeRadius_/ConeH_;
103  for (int j=0; j<100; j++){
104  vz = CLHEP::RandFlat::shoot(engine, 0.0, lzMax_);// this is abs(vz)
105  float v0 = vz - DistanceToAPEX_;
106  if ( v0<=0 or lxy*lxy/(ConeTheta*ConeTheta) > v0*v0 ) {
107  passLz=true;
108  break;
109  }
110  }
111  if (pz<0)
112  vz = -vz;
113  passLoop = (passLxy and passLz);
114 
115  if (passLoop)
116  break;
117  }
118 
119  HepMC::GenVertex* Vtx1 = new HepMC::GenVertex(HepMC::FourVector(vx,vy,vz));
120 
121  int PartID = fPartIDs[ip] ;
122  const HepPDT::ParticleData* PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID))) ;
123  double mass = PData->mass().value() ;
124  double energy2= px*px + py*py + pz*pz + mass*mass ;
125  double energy = sqrt(energy2) ;
126  HepMC::FourVector p(px,py,pz,energy) ;
127  HepMC::GenParticle* Part = new HepMC::GenParticle(p,PartID,1);
128  Part->suggest_barcode( barcode ) ;
129  barcode++;
130  Vtx1->add_particle_out(Part);
131  fEvt->add_vertex(Vtx1) ;
132 
133  if ( fAddAntiParticle ) {
134  HepMC::GenVertex* Vtx2 = new HepMC::GenVertex(HepMC::FourVector(-vx,-vy,-vz));
135  HepMC::FourVector ap(-px,-py,-pz,energy) ;
136  int APartID = -PartID ;
137  if ( PartID == 22 || PartID == 23 )
138  {
139  APartID = PartID ;
140  }
141  HepMC::GenParticle* APart = new HepMC::GenParticle(ap,APartID,1);
142  APart->suggest_barcode( barcode ) ;
143  barcode++ ;
144  Vtx2->add_particle_out(APart) ;
145  fEvt->add_vertex(Vtx2) ;
146  }
147  }
148  fEvt->set_event_number(e.id().event()) ;
149  fEvt->set_signal_process_id(20) ;
150 
151  if ( fVerbosity > 0 ){
152  fEvt->print() ;
153  }
154 
155  unique_ptr<HepMCProduct> BProduct(new HepMCProduct()) ;
156  BProduct->addHepMCData( fEvt );
157  e.put(std::move(BProduct), "unsmeared");
158 
159  unique_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
160  e.put(std::move(genEventInfo));
161 
162  if ( fVerbosity > 0 ){
163  cout << " FlatRandomPtAndDxyGunProducer : End New Event Generation" << endl ;
164  fEvt->print();
165  }
166 }
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
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
void produce(Event &e, const EventSetup &es) override
ESHandle< HepPDT::ParticleDataTable > fPDGTable
T sqrt(T t)
Definition: SSEVec.h:18
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
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
FlatRandomPtAndDxyGunProducer(const ParameterSet &pset)
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
StreamID streamID() const
Definition: Event.h:86
def move(src, dest)
Definition: eostools.py:510