test
CMS 3D CMS Logo

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