CMS 3D CMS Logo

Py8EGun.cc
Go to the documentation of this file.
1 
4 
6 
7 namespace gen {
8 
9  class Py8EGun : public Py8GunBase {
10  public:
11  Py8EGun(edm::ParameterSet const&);
12  ~Py8EGun() override {}
13 
14  bool generatePartonsAndHadronize() override;
15  const char* classname() const override;
16 
17  private:
18  // EGun particle(s) characteristics
19  double fMinEta;
20  double fMaxEta;
21  double fMinE;
22  double fMaxE;
24  };
25 
26  // implementation
27  //
29  // ParameterSet defpset ;
30  edm::ParameterSet pgun_params = ps.getParameter<edm::ParameterSet>("PGunParameters"); // , defpset ) ;
31  fMinEta = pgun_params.getParameter<double>("MinEta"); // ,-2.2);
32  fMaxEta = pgun_params.getParameter<double>("MaxEta"); // , 2.2);
33  fMinE = pgun_params.getParameter<double>("MinE"); // , 0.);
34  fMaxE = pgun_params.getParameter<double>("MaxE"); // , 0.);
35  fAddAntiParticle = pgun_params.getParameter<bool>("AddAntiParticle"); //, false) ;
36  }
37 
39  fMasterGen->event.reset();
40 
41  int colorindex = 101;
42 
43  for (size_t i = 0; i < fPartIDs.size(); i++) {
44  int particleID = fPartIDs[i]; // this is PDG - need to convert to Py8 ???
45  if ((std::abs(particleID) <= 6 || particleID == 21) && !(fAddAntiParticle)) {
46  throw cms::Exception("PythiaError") << "Attempting to generate quarks or gluons without setting "
47  "AddAntiParticle to true. This will not handle color properly."
48  << std::endl;
49  }
50 
51  double phi = (fMaxPhi - fMinPhi) * randomEngine().flat() + fMinPhi;
52  double ee = (fMaxE - fMinE) * randomEngine().flat() + fMinE;
53  double eta = (fMaxEta - fMinEta) * randomEngine().flat() + fMinEta;
54  double the = 2. * atan(exp(-eta));
55 
56  double mass = (fMasterGen->particleData).m0(particleID);
57 
58  double pp = sqrt(ee * ee - mass * mass);
59  double px = pp * sin(the) * cos(phi);
60  double py = pp * sin(the) * sin(phi);
61  double pz = pp * cos(the);
62 
63  if (!((fMasterGen->particleData).isParticle(particleID))) {
64  particleID = std::fabs(particleID);
65  }
66  if (1 <= std::abs(particleID) && std::abs(particleID) <= 6) { // quarks
67  (fMasterGen->event).append(particleID, 23, colorindex, 0, px, py, pz, ee, mass);
68  if (!fAddAntiParticle)
69  colorindex += 1;
70  } else if (std::abs(particleID) == 21) { // gluons
71  (fMasterGen->event).append(21, 23, colorindex, colorindex + 1, px, py, pz, ee, mass);
72  if (!fAddAntiParticle) {
73  colorindex += 2;
74  }
75  }
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, colorindex, -px, -py, -pz, ee, mass);
92  colorindex += 1;
93  } else if (std::abs(particleID) == 21) { // gluons
94  (fMasterGen->event).append(21, 23, colorindex + 1, colorindex, -px, -py, -pz, ee, mass);
95  colorindex += 2;
96  } else {
97  if ((fMasterGen->particleData).isParticle(-particleID)) {
98  (fMasterGen->event).append(-particleID, 1, 0, 0, -px, -py, -pz, ee, mass);
99  } else {
100  (fMasterGen->event).append(particleID, 1, 0, 0, -px, -py, -pz, ee, mass);
101  }
102  int eventSize = (fMasterGen->event).size() - 1;
103  // -log(flat) = exponential distribution
104  double tauTmp = -(fMasterGen->event)[eventSize].tau0() * log(randomEngine().flat());
105  (fMasterGen->event)[eventSize].tau(tauTmp);
106  }
107  }
108  }
109 
110  if (!fMasterGen->next())
111  return false;
112  evtGenDecay();
113 
114  event().reset(new HepMC::GenEvent);
115  return toHepMC.fill_next_event(fMasterGen->event, event().get());
116  }
117 
118  const char* Py8EGun::classname() const { return "Py8EGun"; }
119 
121 
122 } // namespace gen
123 
124 using gen::Pythia8EGun;
gen::Py8InterfaceBase::fMasterGen
std::unique_ptr< Pythia8::Pythia > fMasterGen
Definition: Py8InterfaceBase.h:44
gen::Py8EGun::generatePartonsAndHadronize
bool generatePartonsAndHadronize() override
Definition: Py8EGun.cc:38
mps_fire.i
i
Definition: mps_fire.py:355
gen::Py8GunBase::fMinPhi
double fMinPhi
Definition: Py8GunBase.h:58
gen::Py8EGun::fMinEta
double fMinEta
Definition: Py8EGun.cc:19
metsig::tau
Definition: SignAlgoResolutions.h:49
gen::P8RndmEngine::flat
double flat() override
Definition: P8RndmEngine.cc:7
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
ExternalDecayDriver.h
gen::Py8EGun::classname
const char * classname() const override
Definition: Py8EGun.cc:118
gen::Pythia8EGun
edm::GeneratorFilter< gen::Py8EGun, gen::ExternalDecayDriver > Pythia8EGun
Definition: Py8EGun.cc:120
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
EgammaObjectsElectrons_cfi.particleID
particleID
Definition: EgammaObjectsElectrons_cfi.py:4
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
gen::Py8EGun::~Py8EGun
~Py8EGun() override
Definition: Py8EGun.cc:12
edm::GeneratorFilter
Definition: GeneratorFilter.h:40
gen::Py8GunBase::evtGenDecay
void evtGenDecay()
Definition: Py8GunBase.cc:144
PVValHelper::eta
Definition: PVValidationHelpers.h:69
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
gen::Py8EGun::Py8EGun
Py8EGun(edm::ParameterSet const &)
Definition: Py8EGun.cc:28
gen
Definition: PythiaDecays.h:13
gen::Py8InterfaceBase::randomEngine
P8RndmEngine & randomEngine()
Definition: Py8InterfaceBase.h:41
edm::ParameterSet
Definition: ParameterSet.h:36
GeneratorFilter.h
mps_setup.append
append
Definition: mps_setup.py:85
gen::Py8GunBase::fPartIDs
std::vector< int > fPartIDs
Definition: Py8GunBase.h:57
gen::Py8EGun::fMinE
double fMinE
Definition: Py8EGun.cc:21
get
#define get
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
gen::Py8EGun::fAddAntiParticle
bool fAddAntiParticle
Definition: Py8EGun.cc:23
gen::BaseHadronizer::event
std::unique_ptr< HepMC::GenEvent > & event()
Definition: BaseHadronizer.h:86
gen::Py8GunBase
Definition: Py8GunBase.h:40
Exception
Definition: hltDiff.cc:246
gen::Py8InterfaceBase::toHepMC
HepMC::Pythia8ToHepMC toHepMC
Definition: Py8InterfaceBase.h:46
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
createTree.pp
pp
Definition: createTree.py:17
gen::Py8EGun::fMaxEta
double fMaxEta
Definition: Py8EGun.cc:20
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
gen::Py8GunBase::fMaxPhi
double fMaxPhi
Definition: Py8GunBase.h:59
Py8GunBase.h
event
Definition: event.py:1
gen::Py8EGun::fMaxE
double fMaxE
Definition: Py8EGun.cc:22
gen::Py8EGun
Definition: Py8EGun.cc:9
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443