CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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() {}
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 
110  event().reset(new HepMC::GenEvent);
111  return toHepMC.fill_next_event( fMasterGen->event, event().get() );
112 
113 }
114 
115 const char* Py8PtGun::classname() const
116 {
117  return "Py8PtGun";
118 }
119 
121 
122 } // end namespace
123 
124 using gen::Pythia8PtGun;
edm::GeneratorFilter< gen::Py8PtGun, gen::ExternalDecayDriver > Pythia8PtGun
Definition: Py8PtGun.cc:120
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::auto_ptr< Pythia8::Pythia > fMasterGen
tuple pp
Definition: createTree.py:15
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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:59
virtual double flat() override
Definition: P8RndmEngine.cc:7
std::auto_ptr< HepMC::GenEvent > & event()
def gen
run2 Cosmic #### Run 256259 @ 0T 2015C### Run 272133 @ 3.8T 2016B###
bool fAddAntiParticle
Definition: Py8PtGun.cc:25
const char * classname() const override
Definition: Py8PtGun.cc:115
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::vector< int > fPartIDs
Definition: Py8GunBase.h:58
P8RndmEngine & randomEngine()
double fMinPt
Definition: Py8PtGun.cc:23
double fMinEta
Definition: Py8PtGun.cc:21
Geom::Phi< T > phi() const
bool generatePartonsAndHadronize() override
Definition: Py8PtGun.cc:45
double fMaxPhi
Definition: Py8GunBase.h:60
Py8PtGun(edm::ParameterSet const &)
Definition: Py8PtGun.cc:31
HepMC::Pythia8ToHepMC toHepMC
double fMaxPt
Definition: Py8PtGun.cc:24
double fMaxEta
Definition: Py8PtGun.cc:22
tuple size
Write out results.