File indexing completed on 2024-04-06 12:13:54
0001
0002 #include <iostream>
0003
0004 #include "Pythia6JetGun.h"
0005
0006 #include "FWCore/Utilities/interface/Exception.h"
0007
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009
0010 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0011
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013
0014 using namespace edm;
0015 using namespace gen;
0016
0017 Pythia6JetGun::Pythia6JetGun(const ParameterSet& pset)
0018 : Pythia6ParticleGun(pset), fMinEta(0.), fMaxEta(0.), fMinE(0.), fMaxE(0.), fMinP(0.), fMaxP(0.) {
0019 ParameterSet pgun_params = pset.getParameter<ParameterSet>("PGunParameters");
0020 fMinEta = pgun_params.getParameter<double>("MinEta");
0021 fMaxEta = pgun_params.getParameter<double>("MaxEta");
0022 fMinE = pgun_params.getParameter<double>("MinE");
0023 fMaxE = pgun_params.getParameter<double>("MaxE");
0024 fMinP = pgun_params.getParameter<double>("MinP");
0025 fMaxP = pgun_params.getParameter<double>("MaxP");
0026 }
0027
0028 Pythia6JetGun::~Pythia6JetGun() {}
0029
0030 void Pythia6JetGun::generateEvent(CLHEP::HepRandomEngine*) {
0031 Pythia6Service::InstanceWrapper guard(fPy6Service);
0032
0033
0034
0035
0036
0037
0038 HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(0., 0., 0.));
0039
0040
0041
0042 fEvt = new HepMC::GenEvent();
0043
0044 int ip = 1;
0045 double totPx = 0.;
0046 double totPy = 0.;
0047 double totPz = 0.;
0048 double totE = 0.;
0049 double totM = 0.;
0050 double phi, eta, the, ee, pp;
0051 int dum = 0;
0052 for (size_t i = 0; i < fPartIDs.size(); i++) {
0053 int particleID = fPartIDs[i];
0054 int py6PID = HepPID::translatePDTtoPythia(particleID);
0055
0056
0057
0058 phi = 2. * M_PI * pyr_(&dum);
0059 the = std::acos(-1. + 2. * pyr_(&dum));
0060
0061
0062
0063 ee = (fMaxE - fMinE) * pyr_(&dum) + fMinE;
0064
0065
0066
0067
0068 double mass = pymass_(py6PID);
0069 pyjets.p[4][ip - 1] = mass;
0070
0071
0072
0073 py1ent_(ip, py6PID, ee, the, phi);
0074
0075
0076
0077 totPx += pyjets.p[0][ip - 1];
0078 totPy += pyjets.p[1][ip - 1];
0079 totPz += pyjets.p[2][ip - 1];
0080 totE += pyjets.p[3][ip - 1];
0081
0082 ip++;
0083
0084 }
0085
0086
0087
0088 totM = std::sqrt(totE * totE - (totPx * totPx + totPy * totPy + totPz * totPz));
0089
0090
0091
0092 pp = (fMaxP - fMinP) * pyr_(&dum) + fMinP;
0093 ee = std::sqrt(totM * totM + pp * pp);
0094
0095
0096
0097 phi = (fMaxPhi - fMinPhi) * pyr_(&dum) + fMinPhi;
0098 eta = (fMaxEta - fMinEta) * pyr_(&dum) + fMinEta;
0099 the = 2. * atan(exp(-eta));
0100
0101 double betaX = pp / ee * std::sin(the) * std::cos(phi);
0102 double betaY = pp / ee * std::sin(the) * std::sin(phi);
0103 double betaZ = pp / ee * std::cos(the);
0104
0105
0106
0107
0108
0109 int first = -1, last = -1;
0110 double rothe = 0, rophi = 0.;
0111
0112 pyrobo_(first, last, rothe, rophi, betaX, betaY, betaZ);
0113
0114
0115
0116
0117 for (int i = 0; i < pyjets.n; i++) {
0118 HepMC::FourVector p(pyjets.p[0][i], pyjets.p[1][i], pyjets.p[2][i], pyjets.p[3][i]);
0119 HepMC::GenParticle* Part = new HepMC::GenParticle(p, HepPID::translatePythiatoPDT(pyjets.k[1][i]), 1);
0120 Part->suggest_barcode(i + 1);
0121 Vtx->add_particle_out(Part);
0122 }
0123 fEvt->add_vertex(Vtx);
0124
0125
0126 pyexec_();
0127
0128 return;
0129 }
0130
0131 DEFINE_FWK_MODULE(Pythia6JetGun);