CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
19  ParameterSet defpset;
20  ParameterSet pgun_params = pset.getParameter<ParameterSet>("PGunParameters");
21 
22  fMinPt = pgun_params.getParameter<double>("MinPt");
23  fMaxPt = pgun_params.getParameter<double>("MaxPt");
24  dxyMin_ = pgun_params.getParameter<double>("dxyMin");
25  dxyMax_ = pgun_params.getParameter<double>("dxyMax");
26  lxyMax_ = pgun_params.getParameter<double>("LxyMax");
27  lzMax_ = pgun_params.getParameter<double>("LzMax");
28  ConeRadius_ = pgun_params.getParameter<double>("ConeRadius");
29  ConeH_ = pgun_params.getParameter<double>("ConeH");
30  DistanceToAPEX_ = pgun_params.getParameter<double>("DistanceToAPEX");
31 
32  produces<HepMCProduct>("unsmeared");
33  produces<GenEventInfoProduct>();
34 }
35 
37  // no need to cleanup GenEvent memory - done in HepMCProduct
38 }
39 
42  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
43 
44  if (fVerbosity > 0) {
45  cout << " FlatRandomPtAndDxyGunProducer : Begin New Event Generation" << endl;
46  }
47  // event loop (well, another step in it...)
48 
49  // no need to clean up GenEvent memory - done in HepMCProduct
50  //
51 
52  // here re-create fEvt (memory)
53  //
54  fEvt = new HepMC::GenEvent();
55 
56  // now actualy, cook up the event from PDGTable and gun parameters
57  int barcode = 1;
58  for (unsigned int ip = 0; ip < fPartIDs.size(); ++ip) {
59  double phi_vtx = 0;
60  double dxy = 0;
61  double pt = 0;
62  double eta = 0;
63  double px = 0;
64  double py = 0;
65  double pz = 0;
66  double vx = 0;
67  double vy = 0;
68  double vz = 0;
69  double lxy = 0;
70 
71  bool passLoop = false;
72  while (not passLoop) {
73  bool passLxy = false;
74  bool passLz = false;
75  phi_vtx = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi);
76  dxy = CLHEP::RandFlat::shoot(engine, dxyMin_, dxyMax_);
77  float dxysign = CLHEP::RandFlat::shoot(engine, -1, 1);
78  if (dxysign < 0)
79  dxy = -dxy;
80  pt = CLHEP::RandFlat::shoot(engine, fMinPt, fMaxPt);
81  px = pt * cos(phi_vtx);
82  py = pt * sin(phi_vtx);
83  for (int i = 0; i < 10000; i++) {
84  vx = CLHEP::RandFlat::shoot(engine, -lxyMax_, lxyMax_);
85  vy = (pt * dxy + vx * py) / px;
86  lxy = sqrt(vx * vx + vy * vy);
87  if (lxy < abs(lxyMax_) and (vx * px + vy * py) > 0) {
88  passLxy = true;
89  break;
90  }
91  }
92  eta = CLHEP::RandFlat::shoot(engine, fMinEta, fMaxEta);
93  pz = pt * sinh(eta);
94  //vz = fabs(fRandomGaussGenerator->fire(0.0, LzWidth_/2.0));
95  float ConeTheta = ConeRadius_ / ConeH_;
96  for (int j = 0; j < 100; j++) {
97  vz = CLHEP::RandFlat::shoot(engine, 0.0, lzMax_); // this is abs(vz)
98  float v0 = vz - DistanceToAPEX_;
99  if (v0 <= 0 or lxy * lxy / (ConeTheta * ConeTheta) > v0 * v0) {
100  passLz = true;
101  break;
102  }
103  }
104  if (pz < 0)
105  vz = -vz;
106  passLoop = (passLxy and passLz);
107 
108  if (passLoop)
109  break;
110  }
111 
112  float time = sqrt(vx * vx + vy * vy + vz * vz);
113 
114  HepMC::GenVertex* Vtx1 = new HepMC::GenVertex(HepMC::FourVector(vx, vy, vz, time));
115 
116  int PartID = fPartIDs[ip];
117  const HepPDT::ParticleData* PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID)));
118  double mass = PData->mass().value();
119  double energy2 = px * px + py * py + pz * pz + mass * mass;
120  double energy = sqrt(energy2);
121  HepMC::FourVector p(px, py, pz, energy);
122  HepMC::GenParticle* Part = new HepMC::GenParticle(p, PartID, 1);
123  Part->suggest_barcode(barcode);
124  barcode++;
125  Vtx1->add_particle_out(Part);
126  fEvt->add_vertex(Vtx1);
127 
128  if (fAddAntiParticle) {
129  HepMC::GenVertex* Vtx2 = new HepMC::GenVertex(HepMC::FourVector(-vx, -vy, -vz, time));
130  HepMC::FourVector ap(-px, -py, -pz, energy);
131  int APartID = -PartID;
132  if (PartID == 22 || PartID == 23) {
133  APartID = PartID;
134  }
135  HepMC::GenParticle* APart = new HepMC::GenParticle(ap, APartID, 1);
136  APart->suggest_barcode(barcode);
137  barcode++;
138  Vtx2->add_particle_out(APart);
139  fEvt->add_vertex(Vtx2);
140  }
141  }
142  fEvt->set_event_number(e.id().event());
143  fEvt->set_signal_process_id(20);
144 
145  if (fVerbosity > 0) {
146  fEvt->print();
147  }
148 
149  unique_ptr<HepMCProduct> BProduct(new HepMCProduct());
150  BProduct->addHepMCData(fEvt);
151  e.put(std::move(BProduct), "unsmeared");
152 
153  unique_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
154  e.put(std::move(genEventInfo));
155 
156  if (fVerbosity > 0) {
157  cout << " FlatRandomPtAndDxyGunProducer : End New Event Generation" << endl;
158  fEvt->print();
159  }
160 }
EventNumber_t event() const
Definition: EventID.h:40
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
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:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< int > fPartIDs
HepPDT::ParticleData ParticleData
FlatRandomPtAndDxyGunProducer(const ParameterSet &pset)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EventID id() const
Definition: EventBase.h:59
StreamID streamID() const
Definition: Event.h:98
tuple cout
Definition: gather_cfg.py:144