CMS 3D CMS Logo

Py8MassGun.cc
Go to the documentation of this file.
1 
2 #include <memory>
3 
6 
8 
9 namespace gen {
10 
11  class Py8MassGun : public Py8GunBase {
12  public:
14  ~Py8MassGun() 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 fMinPt;
26  double fMaxPt;
27  double fMinM;
28  double fMaxM;
29  int fMomMode;
30  };
31 
32  // implementation
33  //
35  // ParameterSet defpset ;
36  edm::ParameterSet pgun_params = ps.getParameter<edm::ParameterSet>("PGunParameters"); // , defpset ) ;
37  fMinEta = pgun_params.getParameter<double>("MinEta"); // ,-2.2);
38  fMaxEta = pgun_params.getParameter<double>("MaxEta"); // , 2.2);
39  fMinP = pgun_params.getParameter<double>("MinP"); // , 0.);
40  fMaxP = pgun_params.getParameter<double>("MaxP"); // , 0.);
41  fMinPt = pgun_params.getParameter<double>("MinPt"); // , 0.);
42  fMaxPt = pgun_params.getParameter<double>("MaxPt"); // , 0.);
43  fMinM = pgun_params.getParameter<double>("MinM"); // , 0.);
44  fMaxM = pgun_params.getParameter<double>("MaxM"); // , 0.);
45  fMomMode = pgun_params.getParameter<int>("MomMode"); // , 1);
46  }
47 
49  fMasterGen->event.reset();
50  size_t pSize = fPartIDs.size();
51  if (pSize > 2)
52  return false;
53 
54  int NTotParticles = fPartIDs.size();
55 
56  // energy below is dummy, it is not used
57  (fMasterGen->event).append(990, -11, 0, 0, 2, 1 + NTotParticles, 0, 0, 0., 0., 0., 15000., 15000.);
58 
59  // Pick a flat mass range
60  double phi, eta, the, ee, pp;
61  double m0 = (fMaxM - fMinM) * randomEngine().flat() + fMinM;
62  // Global eta
64 
65  if (pSize == 2) {
66  // Masses.
67  double m1 = fMasterGen->particleData.m0(fPartIDs[0]);
68  double m2 = fMasterGen->particleData.m0(fPartIDs[1]);
69 
70  // Energies and absolute momentum in the rest frame.
71  if (m1 + m2 > m0)
72  return false;
73  double e1 = 0.5 * (m0 * m0 + m1 * m1 - m2 * m2) / m0;
74  double e2 = 0.5 * (m0 * m0 + m2 * m2 - m1 * m1) / m0;
75  double pAbs = 0.5 * sqrt((m0 - m1 - m2) * (m0 + m1 + m2) * (m0 + m1 - m2) * (m0 - m1 + m2)) / m0;
76  // Isotropic angles in rest frame give three-momentum.
77  double cosTheta = 2. * randomEngine().flat() - 1.;
78  double sinTheta = sqrt(1. - cosTheta * cosTheta);
79  phi = 2. * M_PI * randomEngine().flat();
80 
81  double pX = pAbs * sinTheta * cos(phi);
82  double pY = pAbs * sinTheta * sin(phi);
83  double pZ = pAbs * cosTheta;
84 
85  (fMasterGen->event).append(fPartIDs[0], 1, 1, 0, 0, 0, 0, 0, pX, pY, pZ, e1, m1);
86  (fMasterGen->event).append(fPartIDs[1], 1, 1, 0, 0, 0, 0, 0, -pX, -pY, -pZ, e2, m2);
87  } else {
88  (fMasterGen->event).append(fPartIDs[0], 1, 1, 0, 0, 0, 0, 0, 0.0, 0.0, 0.0, m0, m0);
89  }
90 
91  //now the boost (from input params)
92  if (fMomMode == 0) {
93  pp = (fMaxP - fMinP) * randomEngine().flat() + fMinP;
94  } else {
95  double pT = (fMaxPt - fMinPt) * randomEngine().flat() + fMinPt;
96  pp = pT * cosh(eta);
97  }
98  ee = sqrt(m0 * m0 + pp * pp);
99 
100  //the boost direction (from input params)
101  //
102  phi = (fMaxPhi - fMinPhi) * randomEngine().flat() + fMinPhi;
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* Py8MassGun::classname() const { return "Py8MassGun"; }
121 
123 
124 } // namespace gen
125 
126 using gen::Pythia8MassGun;
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const char * classname() const override
Definition: Py8MassGun.cc:120
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
bool generatePartonsAndHadronize() override
Definition: Py8MassGun.cc:48
double fMinPhi
Definition: Py8GunBase.h:58
double flat() override
Definition: P8RndmEngine.cc:7
Py8MassGun(edm::ParameterSet const &)
Definition: Py8MassGun.cc:34
~Py8MassGun() override
Definition: Py8MassGun.cc:14
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< HepMC::GenEvent > & event()
std::vector< int > fPartIDs
Definition: Py8GunBase.h:57
#define M_PI
edm::GeneratorFilter< gen::Py8MassGun, gen::ExternalDecayDriver > Pythia8MassGun
Definition: Py8MassGun.cc:122
P8RndmEngine & randomEngine()
double fMaxPhi
Definition: Py8GunBase.h:59
HepMC::Pythia8ToHepMC toHepMC
std::unique_ptr< Pythia8::Pythia > fMasterGen
Definition: event.py:1