CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Pythia6Gun.cc
Go to the documentation of this file.
1 /*
2  * \author Julia Yarba
3  */
4 
5 #include <iostream>
6 
7 #include "Pythia6Gun.h"
8 
9 //#include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
13 
18 
20 
21 using namespace edm;
22 using namespace gen;
23 
24 Pythia6Gun::Pythia6Gun(const ParameterSet& pset)
25  : fPy6Service(new Pythia6Service(pset)),
26  fEvt(nullptr)
27 // fPDGTable( new DefaultConfig::ParticleDataTable("PDG Table") )
28 {
29  ParameterSet pgun_params = pset.getParameter<ParameterSet>("PGunParameters");
30 
31  // although there's the method ParameterSet::empty(),
32  // it looks like it's NOT even necessary to check if it is,
33  // before trying to extract parameters - if it is empty,
34  // the default values seem to be taken
35  //
36  fMinPhi = pgun_params.getParameter<double>("MinPhi"); // ,-3.14159265358979323846);
37  fMaxPhi = pgun_params.getParameter<double>("MaxPhi"); // , 3.14159265358979323846);
38 
39  fHepMCVerbosity = pset.getUntrackedParameter<bool>("pythiaHepMCVerbosity", false);
40  fPylistVerbosity = pset.getUntrackedParameter<int>("pythiaPylistVerbosity", 0);
41  fMaxEventsToPrint = pset.getUntrackedParameter<int>("maxEventsToPrint", 0);
42 
43  // Turn off banner printout
44  if (!call_pygive("MSTU(12)=12345")) {
45  throw edm::Exception(edm::errors::Configuration, "PythiaError") << " pythia did not accept MSTU(12)=12345";
46  }
47 
49  produces<HepMCProduct>("unsmeared");
50 }
51 
53  if (fPy6Service)
54  delete fPy6Service;
55  //
56  // note that GenEvent or any undelaying (GenVertex, GenParticle) do NOT
57  // need to be cleaned, as it'll be done automatically by HepMCProduct
58  //
59 }
60 
62  // es.getData( fPDGTable ) ;
63  return;
64 }
65 
66 void Pythia6Gun::beginRun(Run const&, EventSetup const& es) {
67  std::cout << " FYI: MSTU(10)=1 is ENFORCED in Py6-PGuns, for technical reasons" << std::endl;
68  return;
69 }
70 
73 
75 
76  Pythia6Service::InstanceWrapper guard(fPy6Service); // grab Py6 instance
77 
81 
82  call_pygive("MSTU(10)=1");
83 
84  call_pyinit("NONE", "", "", 0.0);
85 }
86 
88 void Pythia6Gun::endRun(Run const&, EventSetup const& es) {
89  // here put in GenRunInfoProduct
90 
91  call_pystat(1);
92 
93  return;
94 }
95 
97  for (int iprt = fPartIDs.size(); iprt < pyjets.n; iprt++) // the pointer is shifted by -1, c++ style
98  {
99  int parent = pyjets.k[2][iprt];
100  if (parent != 0) {
101  // pull up parent particle
102  //
103  HepMC::GenParticle* parentPart = fEvt->barcode_to_particle(parent);
104  parentPart->set_status(2); // reset status, to mark that it's decayed
105 
106  HepMC::GenVertex* DecVtx = new HepMC::GenVertex(
107  HepMC::FourVector(pyjets.v[0][iprt], pyjets.v[1][iprt], pyjets.v[2][iprt], pyjets.v[3][iprt]));
108  DecVtx->add_particle_in(parentPart); // this will cleanup end_vertex if exists,
109  // and replace with the new one
110  // I presume barcode will be given automatically
111 
112  HepMC::FourVector pmom(pyjets.p[0][iprt], pyjets.p[1][iprt], pyjets.p[2][iprt], pyjets.p[3][iprt]);
113 
114  int dstatus = 0;
115  if (pyjets.k[0][iprt] >= 1 && pyjets.k[0][iprt] <= 10) {
116  dstatus = 1;
117  } else if (pyjets.k[0][iprt] >= 11 && pyjets.k[0][iprt] <= 20) {
118  dstatus = 2;
119  } else if (pyjets.k[0][iprt] >= 21 && pyjets.k[0][iprt] <= 30) {
120  dstatus = 3;
121  } else if (pyjets.k[0][iprt] >= 31 && pyjets.k[0][iprt] <= 100) {
122  dstatus = pyjets.k[0][iprt];
123  }
124  HepMC::GenParticle* daughter =
125  new HepMC::GenParticle(pmom, HepPID::translatePythiatoPDT(pyjets.k[1][iprt]), dstatus);
126  daughter->suggest_barcode(iprt + 1);
127  DecVtx->add_particle_out(daughter);
128  // give particle barcode as well !
129 
130  int iprt1;
131  for (iprt1 = iprt + 1; iprt1 < pyjets.n; iprt1++) // the pointer is shifted by -1, c++ style
132  {
133  if (pyjets.k[2][iprt1] != parent)
134  break; // another parent particle, break the loop
135 
136  HepMC::FourVector pmomN(pyjets.p[0][iprt1], pyjets.p[1][iprt1], pyjets.p[2][iprt1], pyjets.p[3][iprt1]);
137 
138  dstatus = 0;
139  if (pyjets.k[0][iprt1] >= 1 && pyjets.k[0][iprt1] <= 10) {
140  dstatus = 1;
141  } else if (pyjets.k[0][iprt1] >= 11 && pyjets.k[0][iprt1] <= 20) {
142  dstatus = 2;
143  } else if (pyjets.k[0][iprt1] >= 21 && pyjets.k[0][iprt1] <= 30) {
144  dstatus = 3;
145  } else if (pyjets.k[0][iprt1] >= 31 && pyjets.k[0][iprt1] <= 100) {
146  dstatus = pyjets.k[0][iprt1];
147  }
148  HepMC::GenParticle* daughterN =
149  new HepMC::GenParticle(pmomN, HepPID::translatePythiatoPDT(pyjets.k[1][iprt1]), dstatus);
150  daughterN->suggest_barcode(iprt1 + 1);
151  DecVtx->add_particle_out(daughterN);
152  }
153 
154  iprt = iprt1 - 1; // reset counter such that it doesn't go over the same child more than once
155  // don't forget to offset back into c++ counting, as it's already +1 forward
156 
157  fEvt->add_vertex(DecVtx);
158  }
159  }
160 
161  return;
162 }
163 
166 
168 
169  fEvt->set_beam_particles(nullptr, nullptr);
170  fEvt->set_event_number(evt.id().event());
171  fEvt->set_signal_process_id(pypars.msti[0]);
172 
174 
175  int evtN = evt.id().event();
176  if (evtN <= fMaxEventsToPrint) {
177  if (fPylistVerbosity) {
179  }
180  if (fHepMCVerbosity) {
181  if (fEvt)
182  fEvt->print();
183  }
184  }
185 
186  loadEvent(evt);
187 }
188 
190  std::unique_ptr<HepMCProduct> bare_product(new HepMCProduct());
191 
192  if (fEvt)
193  bare_product->addHepMCData(fEvt);
194 
195  evt.put(std::move(bare_product), "unsmeared");
196 
197  return;
198 }
199 
200 HepMC::GenParticle* Pythia6Gun::addAntiParticle(int& ip, int& particleID, double& ee, double& eta, double& phi) {
201  if (ip < 2)
202  return nullptr;
203 
204  // translate PDG to Py6
205  int py6PID = HepPID::translatePDTtoPythia(particleID);
206  // Check if particle is its own anti-particle.
207  int pythiaCode = pycomp_(py6PID); // this is py6 internal validity check, it takes Pythia6 pid
208  // so actually I'll need to convert
209  int has_antipart = pydat2.kchg[3 - 1][pythiaCode - 1];
210  int particleID2 = has_antipart ? -1 * particleID : particleID; // this is PDG, for HepMC::GenEvent
211  int py6PID2 = has_antipart ? -1 * py6PID : py6PID; // this py6 id, for py1ent
212  double the = 2. * atan(exp(eta));
213  phi = phi + M_PI;
214  if (phi > 2. * M_PI) {
215  phi = phi - 2. * M_PI;
216  }
217 
218  // copy over mass of the previous one, because then py6 will pick it up
219  pyjets.p[4][ip - 1] = pyjets.p[4][ip - 2];
220 
221  py1ent_(ip, py6PID2, ee, the, phi);
222 
223  double px = pyjets.p[0][ip - 1]; // pt*cos(phi) ;
224  double py = pyjets.p[1][ip - 1]; // pt*sin(phi) ;
225  double pz = pyjets.p[2][ip - 1]; // mom*cos(the) ;
226  HepMC::FourVector ap(px, py, pz, ee);
227  HepMC::GenParticle* APart = new HepMC::GenParticle(ap, particleID2, 1);
228  APart->suggest_barcode(ip);
229 
230  return APart;
231 }
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void beginJob() override
Definition: Pythia6Gun.cc:61
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: Pythia6Gun.cc:88
CLHEP::HepRandomEngine * randomEngine() const
LuminosityBlockIndex index() const
void produce(edm::Event &, const edm::EventSetup &) override
Definition: Pythia6Gun.cc:164
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: Pythia6Gun.cc:66
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: Pythia6Gun.cc:71
bool call_pygive(const std::string &line)
HepMC::GenParticle * addAntiParticle(int &, int &, double &, double &, double &)
Definition: Pythia6Gun.cc:200
HepMC::GenEvent * fEvt
Definition: Pythia6Gun.h:68
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) final
Definition: Pythia6Gun.cc:87
bool fHepMCVerbosity
Definition: Pythia6Gun.h:75
int fPylistVerbosity
Definition: Pythia6Gun.h:76
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
assert(be >=bs)
virtual void generateEvent(CLHEP::HepRandomEngine *)=0
static const std::string kPythia6
void call_pylist(int mode)
void attachPy6DecaysToGenEvent()
Definition: Pythia6Gun.cc:96
double fMinPhi
Definition: Pythia6Gun.h:63
int fMaxEventsToPrint
Definition: Pythia6Gun.h:77
def move
Definition: eostools.py:511
~Pythia6Gun() override
Definition: Pythia6Gun.cc:52
list lumi
Definition: dqmdumpme.py:53
void loadEvent(edm::Event &)
Definition: Pythia6Gun.cc:189
#define M_PI
int pycomp_(int &)
#define pypars
double fMaxPhi
Definition: Pythia6Gun.h:64
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void py1ent_(int &ip, int &kf, double &pe, double &the, double &phi)
edm::EventID id() const
Definition: EventBase.h:59
Pythia6Service * fPy6Service
Definition: Pythia6Gun.h:58
StreamID streamID() const
Definition: Event.h:98
tuple cout
Definition: gather_cfg.py:144
std::vector< int > fPartIDs
Definition: Pythia6Gun.h:62
Definition: Run.h:45