CMS 3D CMS Logo

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