CMS 3D CMS Logo

Py8PtGun.cc
Go to the documentation of this file.
3 
5 
6 namespace gen {
7 
8 class Py8PtGun : public Py8GunBase {
9 
10  public:
11 
12  Py8PtGun( edm::ParameterSet const& );
13  ~Py8PtGun() override {}
14 
15  bool generatePartonsAndHadronize() override;
16  const char* classname() const override;
17 
18  private:
19 
20  // PtGun particle(s) characteristics
21  double fMinEta;
22  double fMaxEta;
23  double fMinPt ;
24  double fMaxPt ;
26 
27 };
28 
29 // implementation
30 //
32  : Py8GunBase(ps) {
33 
34  // ParameterSet defpset ;
35  edm::ParameterSet pgun_params =
36  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  fMinPt = pgun_params.getParameter<double>("MinPt"); // , 0.);
40  fMaxPt = pgun_params.getParameter<double>("MaxPt"); // , 0.);
41  fAddAntiParticle = pgun_params.getParameter<bool>("AddAntiParticle"); //, false) ;
42 
43 }
44 
46 {
47 
48  fMasterGen->event.reset();
49 
50  for ( size_t i=0; i<fPartIDs.size(); i++ ){
51 
52  int particleID = fPartIDs[i]; // this is PDG - need to convert to Py8 ???
53 
54  double phi = (fMaxPhi-fMinPhi) * randomEngine().flat() + fMinPhi;
55  double eta = (fMaxEta-fMinEta) * randomEngine().flat() + fMinEta;
56  double the = 2.*atan(exp(-eta));
57 
58  double pt = (fMaxPt-fMinPt) * randomEngine().flat() + fMinPt;
59 
60  double mass = (fMasterGen->particleData).m0( particleID );
61 
62  double pp = pt / sin(the); // sqrt( ee*ee - mass*mass );
63  double ee = sqrt( pp*pp + mass*mass );
64 
65  double px = pt * cos(phi);
66  double py = pt * sin(phi);
67  double pz = pp * cos(the);
68 
69  if ( !((fMasterGen->particleData).isParticle( particleID )) ){
70  particleID = std::abs(particleID) ;
71  }
72  if( 1<= std::abs(particleID) && std::abs(particleID) <= 6) // quarks
73  (fMasterGen->event).append( particleID, 23, 101, 0, px, py, pz, ee, mass );
74  else if (std::abs(particleID) == 21) // gluons
75  (fMasterGen->event).append( 21, 23, 101, 102, px, py, pz, ee, mass );
76  // other
77  else {
78  (fMasterGen->event).append( particleID, 1, 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 
85 // Here also need to add anti-particle (if any)
86 // otherwise just add a 2nd particle of the same type
87 // (for example, gamma)
88 //
89  if ( fAddAntiParticle ) {
90  if( 1 <= std::abs(particleID) && std::abs(particleID) <= 6){ // quarks
91  (fMasterGen->event).append( -particleID, 23, 0, 101, -px, -py, -pz, ee, mass );
92  } else if (std::abs(particleID) == 21){ // gluons
93  (fMasterGen->event).append( 21, 23, 102, 101, -px, -py, -pz, ee, mass );
94  } else {
95  if ( (fMasterGen->particleData).isParticle( -particleID ) ) {
96  (fMasterGen->event).append( -particleID, 1, 0, 0, -px, -py, -pz, ee, mass );
97  } else {
98  (fMasterGen->event).append( particleID, 1, 0, 0, -px, -py, -pz, ee, mass );
99  }
100  int eventSize = (fMasterGen->event).size()-1;
101  // -log(flat) = exponential distribution
102  double tauTmp = -(fMasterGen->event)[eventSize].tau0() * log(randomEngine().flat());
103  (fMasterGen->event)[eventSize].tau( tauTmp );
104  }
105  }
106  }
107 
108  if ( !fMasterGen->next() ) return false;
109  evtGenDecay();
110 
111  event().reset(new HepMC::GenEvent);
112  return toHepMC.fill_next_event( fMasterGen->event, event().get() );
113 
114 }
115 
116 const char* Py8PtGun::classname() const
117 {
118  return "Py8PtGun";
119 }
120 
122 
123 } // end namespace
124 
125 using gen::Pythia8PtGun;
size
Write out results.
edm::GeneratorFilter< gen::Py8PtGun, gen::ExternalDecayDriver > Pythia8PtGun
Definition: Py8PtGun.cc:121
T getParameter(std::string const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
double fMinPhi
Definition: Py8GunBase.h:60
double flat() override
Definition: P8RndmEngine.cc:7
const char * classname() const override
Definition: Py8PtGun.cc:116
bool fAddAntiParticle
Definition: Py8PtGun.cc:25
void evtGenDecay()
Definition: Py8GunBase.cc:159
T sqrt(T t)
Definition: SSEVec.h:18
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::unique_ptr< HepMC::GenEvent > & event()
std::vector< int > fPartIDs
Definition: Py8GunBase.h:59
P8RndmEngine & randomEngine()
double fMinPt
Definition: Py8PtGun.cc:23
double fMinEta
Definition: Py8PtGun.cc:21
~Py8PtGun() override
Definition: Py8PtGun.cc:13
bool generatePartonsAndHadronize() override
Definition: Py8PtGun.cc:45
double fMaxPhi
Definition: Py8GunBase.h:61
Py8PtGun(edm::ParameterSet const &)
Definition: Py8PtGun.cc:31
HepMC::Pythia8ToHepMC toHepMC
std::unique_ptr< Pythia8::Pythia > fMasterGen
double fMaxPt
Definition: Py8PtGun.cc:24
double fMaxEta
Definition: Py8PtGun.cc:22
Definition: event.py:1