CMS 3D CMS Logo

Pythia6PtYDistGun.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 
4 #include "Pythia6PtYDistGun.h"
6 
8 
10 
12 
14 
15 using namespace edm;
16 using namespace gen;
17 
18 Pythia6PtYDistGun::Pythia6PtYDistGun(const ParameterSet& pset) : Pythia6ParticleGun(pset), fPtYGenerator(nullptr) {
19  ParameterSet pgun_params = pset.getParameter<ParameterSet>("PGunParameters");
20 
21  fPtYGenerator = new PtYDistributor(pgun_params.getParameter<FileInPath>("kinematicsFile"),
22  pgun_params.getParameter<double>("MaxPt"),
23  pgun_params.getParameter<double>("MinPt"),
24  pgun_params.getParameter<double>("MaxY"),
25  pgun_params.getParameter<double>("MinY"),
26  pgun_params.getParameter<int>("PtBinning"),
27  pgun_params.getParameter<int>("YBinning"));
28 }
29 
31  if (fPtYGenerator)
32  delete fPtYGenerator;
33 }
34 
35 void Pythia6PtYDistGun::generateEvent(CLHEP::HepRandomEngine* engine) {
36  Pythia6Service::InstanceWrapper guard(fPy6Service); // grab Py6 instance
37 
38  // now actualy, start cooking up the event gun
39  //
40 
41  // 1st, primary vertex
42  //
43  HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(0., 0., 0.));
44 
45  // here re-create fEvt (memory)
46  //
47  fEvt = new HepMC::GenEvent();
48 
49  int ip = 1;
50 
51  for (size_t i = 0; i < fPartIDs.size(); i++) {
52  int particleID = fPartIDs[i]; // this is PDG - need to convert to Py6 !!!
53  int py6PID = HepPID::translatePDTtoPythia(particleID);
54 
55  int dum = 0;
56  double pt = 0, y = 0, u = 0, ee = 0, the = 0;
57 
58  pt = fPtYGenerator->firePt(engine);
59  y = fPtYGenerator->fireY(engine);
60  u = exp(y);
61 
62  double mass = pymass_(py6PID);
63 
64  // fill p(ip,5) (in PYJETS) with mass value right now,
65  // because the (hardcoded) mstu(10)=1 will make py1ent
66  // pick the mass from there
67  pyjets.p[4][ip - 1] = mass;
68 
69  ee = 0.5 * std::sqrt(mass * mass + pt * pt) * (u * u + 1) / u;
70 
71  double pz = std::sqrt(ee * ee - pt * pt - mass * mass);
72  if (y < 0.)
73  pz *= -1;
74 
75  double phi = (fMaxPhi - fMinPhi) * pyr_(&dum) + fMinPhi;
76 
77  the = atan(pt / pz);
78  if (pz < 0.)
79  the += M_PI;
80 
81  py1ent_(ip, py6PID, ee, the, phi);
82 
83  /*
84  double px = pt*cos(phi) ;
85  double py = pt*sin(phi) ;
86 */
87  double px = pyjets.p[0][ip - 1]; // pt*cos(phi) ;
88  double py = pyjets.p[1][ip - 1]; // pt*sin(phi) ;
89  pz = pyjets.p[2][ip - 1]; // mom*cos(the) ;
90 
91  HepMC::FourVector p(px, py, pz, ee);
93  Part->suggest_barcode(ip);
94  Vtx->add_particle_out(Part);
95 
96  ip++;
97  }
98 
99  fEvt->add_vertex(Vtx);
100 
101  // run pythia
102  pyexec_();
103 
104  return;
105 }
106 
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
double pyr_(int *idummy)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HepMC::GenEvent * fEvt
Definition: Pythia6Gun.h:68
double firePt(CLHEP::HepRandomEngine *)
void generateEvent(CLHEP::HepRandomEngine *) override
double fireY(CLHEP::HepRandomEngine *)
double p[5][pyjets_maxn]
PtYDistributor * fPtYGenerator
double fMinPhi
Definition: Pythia6Gun.h:63
T sqrt(T t)
Definition: SSEVec.h:19
double pymass_(int &)
std::vector< int > fPartIDs
#define M_PI
double fMaxPhi
Definition: Pythia6Gun.h:64
void py1ent_(int &ip, int &kf, double &pe, double &the, double &phi)
HLT enums.
Pythia6Service * fPy6Service
Definition: Pythia6Gun.h:58
void pyexec_()