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.
1 
4 
6 
7 namespace gen {
8 
9 class Py8PtGun : public Py8GunBase {
10 
11  public:
12 
13  Py8PtGun( edm::ParameterSet const& );
14  ~Py8PtGun() {}
15 
16  bool generatePartonsAndHadronize() override;
17  const char* classname() const override;
18 
19  private:
20 
21  // PtGun particle(s) characteristics
22  double fMinEta;
23  double fMaxEta;
24  double fMinPt ;
25  double fMaxPt ;
27 
28 };
29 
30 // implementation
31 //
33  : Py8GunBase(ps)
34 {
35 
36  // ParameterSet defpset ;
37  edm::ParameterSet pgun_params =
38  ps.getParameter<edm::ParameterSet>("PGunParameters"); // , defpset ) ;
39  fMinEta = pgun_params.getParameter<double>("MinEta"); // ,-2.2);
40  fMaxEta = pgun_params.getParameter<double>("MaxEta"); // , 2.2);
41  fMinPt = pgun_params.getParameter<double>("MinPt"); // , 0.);
42  fMaxPt = pgun_params.getParameter<double>("MaxPt"); // , 0.);
43  fAddAntiParticle = pgun_params.getParameter<bool>("AddAntiParticle"); //, false) ;
44 
45 }
46 
48 {
49 
50  fMasterGen->event.reset();
51 
52  for ( size_t i=0; i<fPartIDs.size(); i++ )
53  {
54 
55  int particleID = fPartIDs[i]; // this is PDG - need to convert to Py8 ???
56 
57  double phi = (fMaxPhi-fMinPhi) * randomEngine().flat() + fMinPhi;
58  double eta = (fMaxEta-fMinEta) * randomEngine().flat() + fMinEta;
59  double the = 2.*atan(exp(-eta));
60 
61  double pt = (fMaxPt-fMinPt) * randomEngine().flat() + fMinPt;
62 
63  double mass = (fMasterGen->particleData).m0( particleID );
64 
65  double pp = pt / sin(the); // sqrt( ee*ee - mass*mass );
66  double ee = sqrt( pp*pp + mass*mass );
67 
68  double px = pt * cos(phi);
69  double py = pt * sin(phi);
70  double pz = pp * cos(the);
71 
72  if ( !((fMasterGen->particleData).isParticle( particleID )) )
73  {
74  particleID = std::fabs(particleID) ;
75  }
76  if( 1<= fabs(particleID) && fabs(particleID) <= 6) // quarks
77  (fMasterGen->event).append( particleID, 23, 101, 0, px, py, pz, ee, mass );
78  else if (fabs(particleID) == 21) // gluons
79  (fMasterGen->event).append( 21, 23, 101, 102, px, py, pz, ee, mass );
80  else // other
81  (fMasterGen->event).append( particleID, 1, 0, 0, px, py, pz, ee, mass );
82 
83 // Here also need to add anti-particle (if any)
84 // otherwise just add a 2nd particle of the same type
85 // (for example, gamma)
86 //
87  if ( fAddAntiParticle )
88  {
89  if( 1 <= fabs(particleID) && fabs(particleID) <= 6){ // quarks
90  (fMasterGen->event).append( -particleID, 23, 0, 101, -px, -py, -pz, ee, mass );
91  }
92  else if (fabs(particleID) == 21){ // gluons
93  (fMasterGen->event).append( 21, 23, 102, 101, -px, -py, -pz, ee, mass );
94  }
95  else if ( (fMasterGen->particleData).isParticle( -particleID ) )
96  {
97  (fMasterGen->event).append( -particleID, 1, 0, 0, -px, -py, -pz, ee, mass );
98  }
99  else
100  {
101  (fMasterGen->event).append( particleID, 1, 0, 0, -px, -py, -pz, ee, mass );
102  }
103  }
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:26
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
std::vector< int > fPartIDs
Definition: Py8GunBase.h:58
P8RndmEngine & randomEngine()
double fMinPt
Definition: Py8PtGun.cc:24
double fMinEta
Definition: Py8PtGun.cc:22
Geom::Phi< T > phi() const
bool generatePartonsAndHadronize() override
Definition: Py8PtGun.cc:47
double fMaxPhi
Definition: Py8GunBase.h:60
Py8PtGun(edm::ParameterSet const &)
Definition: Py8PtGun.cc:32
HepMC::Pythia8ToHepMC toHepMC
double fMaxPt
Definition: Py8PtGun.cc:25
double fMaxEta
Definition: Py8PtGun.cc:23