CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Py8JetGun.cc
Go to the documentation of this file.
1 
2 #include <memory>
3 
6 
8 
9 namespace gen {
10 
11  class Py8JetGun : public Py8GunBase {
12  public:
14  ~Py8JetGun() override {}
15 
16  bool generatePartonsAndHadronize() override;
17  const char* classname() const override;
18 
19  private:
20  // PtGun particle(s) characteristics
21  double fMinEta;
22  double fMaxEta;
23  double fMinP;
24  double fMaxP;
25  double fMinE;
26  double fMaxE;
27  };
28 
29  // implementation
30  //
32  // ParameterSet defpset ;
33  edm::ParameterSet pgun_params = ps.getParameter<edm::ParameterSet>("PGunParameters"); // , defpset ) ;
34  fMinEta = pgun_params.getParameter<double>("MinEta"); // ,-2.2);
35  fMaxEta = pgun_params.getParameter<double>("MaxEta"); // , 2.2);
36  fMinP = pgun_params.getParameter<double>("MinP"); // , 0.);
37  fMaxP = pgun_params.getParameter<double>("MaxP"); // , 0.);
38  fMinE = pgun_params.getParameter<double>("MinE"); // , 0.);
39  fMaxE = pgun_params.getParameter<double>("MaxE"); // , 0.);
40  }
41 
43  fMasterGen->event.reset();
44 
45  int NTotParticles = fPartIDs.size();
46 
47  // energy below is dummy, it is not used
48  (fMasterGen->event).append(990, -11, 0, 0, 2, 1 + NTotParticles, 0, 0, 0., 0., 0., 15000., 15000.);
49 
50  double totPx = 0.;
51  double totPy = 0.;
52  double totPz = 0.;
53  double totE = 0.;
54  double totM = 0.;
55  double phi, eta, the, ee, pp;
56 
57  for (size_t i = 0; i < fPartIDs.size(); i++) {
58  int particleID = fPartIDs[i]; // this is PDG
59 
60  phi = 2. * M_PI * randomEngine().flat();
61  the = acos(-1. + 2. * randomEngine().flat());
62 
63  // from input
64  //
65  ee = (fMaxE - fMinE) * randomEngine().flat() + fMinE;
66 
67  double mass = (fMasterGen->particleData).m0(particleID);
68 
69  pp = sqrt(ee * ee - mass * mass);
70 
71  double px = pp * sin(the) * cos(phi);
72  double py = pp * sin(the) * sin(phi);
73  double pz = pp * cos(the);
74 
75  if (!((fMasterGen->particleData).isParticle(particleID))) {
76  particleID = std::fabs(particleID);
77  }
78  (fMasterGen->event).append(particleID, 1, 1, 0, 0, 0, 0, 0, px, py, pz, ee, mass);
79  int eventSize = (fMasterGen->event).size() - 1;
80  // -log(flat) = exponential distribution
81  double tauTmp = -(fMasterGen->event)[eventSize].tau0() * log(randomEngine().flat());
82  (fMasterGen->event)[eventSize].tau(tauTmp);
83 
84  // values for computing total mass
85  //
86  totPx += px;
87  totPy += py;
88  totPz += pz;
89  totE += ee;
90  }
91 
92  totM = sqrt(totE * totE - (totPx * totPx + totPy * totPy + totPz * totPz));
93 
94  //now the boost (from input params)
95  //
96  pp = (fMaxP - fMinP) * randomEngine().flat() + fMinP;
97  ee = sqrt(totM * totM + pp * pp);
98 
99  //the boost direction (from input params)
100  //
101  phi = (fMaxPhi - fMinPhi) * randomEngine().flat() + fMinPhi;
102  eta = (fMaxEta - fMinEta) * randomEngine().flat() + fMinEta;
103  the = 2. * atan(exp(-eta));
104 
105  double betaX = pp / ee * std::sin(the) * std::cos(phi);
106  double betaY = pp / ee * std::sin(the) * std::sin(phi);
107  double betaZ = pp / ee * std::cos(the);
108 
109  // boost all particles
110  //
111  (fMasterGen->event).bst(betaX, betaY, betaZ);
112 
113  if (!fMasterGen->next())
114  return false;
115 
116  event() = std::make_unique<HepMC::GenEvent>();
117  return toHepMC.fill_next_event(fMasterGen->event, event().get());
118  }
119 
120  const char* Py8JetGun::classname() const { return "Py8JetGun"; }
121 
123 
124 } // namespace gen
125 
126 using gen::Pythia8JetGun;
static std::vector< std::string > checklist log
double fMinEta
Definition: Py8JetGun.cc:21
double fMinE
Definition: Py8JetGun.cc:25
tuple pp
Definition: createTree.py:17
const char * classname() const override
Definition: Py8JetGun.cc:120
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
double fMinPhi
Definition: Py8GunBase.h:58
double fMaxP
Definition: Py8JetGun.cc:24
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
double flat() override
Definition: P8RndmEngine.cc:7
double fMaxE
Definition: Py8JetGun.cc:26
Py8JetGun(edm::ParameterSet const &)
Definition: Py8JetGun.cc:31
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
~Py8JetGun() override
Definition: Py8JetGun.cc:14
std::unique_ptr< HepMC::GenEvent > & event()
std::vector< int > fPartIDs
Definition: Py8GunBase.h:57
#define M_PI
P8RndmEngine & randomEngine()
edm::GeneratorFilter< gen::Py8JetGun, gen::ExternalDecayDriver > Pythia8JetGun
Definition: Py8JetGun.cc:122
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double fMaxPhi
Definition: Py8GunBase.h:59
HepMC::Pythia8ToHepMC toHepMC
std::unique_ptr< Pythia8::Pythia > fMasterGen
double fMinP
Definition: Py8JetGun.cc:23
tuple size
Write out results.
bool generatePartonsAndHadronize() override
Definition: Py8JetGun.cc:42
double fMaxEta
Definition: Py8JetGun.cc:22