6 #include "HepMC/GenEvent.h"
7 #include "HepMC/PdfInfo.h"
8 #include "HepMC/PythiaWrapper6_4.h"
9 #include "HepMC/HEPEVT_Wrapper.h"
10 #include "HepMC/IO_HEPEVT.h"
26 #include "HepPID/ParticleIDTranslations.hh"
58 class Pythia6ServiceWithCallback :
public Pythia6Service {
87 int n,
npad,
k[5][pyjets_maxn];
88 double p[5][pyjets_maxn],
v[5][pyjets_maxn];
100 fCOMEnergy(ps.getParameter<double>(
"comEnergy")),
101 fHepMCVerbosity(ps.getUntrackedParameter<
bool>(
"pythiaHepMCVerbosity",
false)),
102 fMaxEventsToPrint(ps.getUntrackedParameter<
int>(
"maxEventsToPrint", 0)),
103 fPythiaListVerbosity(ps.getUntrackedParameter<
int>(
"pythiaPylistVerbosity", 0)),
104 fDisplayPythiaBanner(ps.getUntrackedParameter<
bool>(
"displayPythiaBanner",
false)),
105 fDisplayPythiaCards(ps.getUntrackedParameter<
bool>(
"displayPythiaCards",
false)) {
108 if (ps.
exists(
"PPbarInitialState")) {
112 <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
113 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
114 std::cout <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE." << std::endl;
115 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
119 }
else if (ps.
exists(
"ElectronPositronInitialState")) {
123 <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
124 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
125 std::cout <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE." << std::endl;
126 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
130 }
else if (ps.
exists(
"ElectronProtonInitialState")) {
138 <<
"Pythia6 will be initialized for ELECTRON-PROTON INITIAL STATE. "
139 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
140 std::cout <<
"Pythia6 will be initialized for ELECTRON-PROTON INITIAL STATE." << std::endl;
141 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
145 }
else if (ps.
exists(
"PositronProtonInitialState")) {
153 <<
"Pythia6 will be initialized for POSITRON-PROTON INITIAL STATE. "
154 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
155 std::cout <<
"Pythia6 will be initialized for POSITRON-PROTON INITIAL STATE." << std::endl;
156 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
160 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron, "
161 "ElectronProton, and PositronProton \n";
171 if (ps.
exists(
"stopHadrons"))
175 if (ps.
exists(
"gluinoHadrons"))
179 if (ps.
exists(
"imposeProperTime")) {
184 if (ps.
exists(
"doPDGConvert"))
187 if (ps.
exists(
"jetMatching")) {
226 for (
int ip = 0; ip < pyjets_maxn; ip++) {
227 for (
int i = 0;
i < 5;
i++) {
239 for (
int ip = 0; ip < pyjets_maxn; ip++) {
240 for (
int i = 0;
i < 5;
i++) {
264 if (
event()->signal_process_id() <= 0)
266 if (
event()->event_scale() <= 0)
268 if (
event()->alphaQED() <= 0)
270 if (
event()->alphaQCD() <= 0)
277 pdf.set_id1(
pyint1.mint[14] == 21 ? 0 :
pyint1.mint[14]);
279 pdf.set_id2(
pyint1.mint[15] == 21 ? 0 :
pyint1.mint[15]);
281 pdf.set_x1(
pyint1.vint[40]);
283 pdf.set_x2(
pyint1.vint[41]);
288 if (pdf.scalePDF() <= 0)
289 pdf.set_scalePDF(
pyint1.vint[50]);
318 event()->set_pdf_info(pdf);
320 HepMC::GenCrossSection xsec;
324 xsec.set_cross_section(
cs, cserr);
325 event()->set_cross_section(xsec);
331 event()->weights().push_back(
pyint1.vint[96] * 1.0e9);
337 event()->weights().push_back(1. / (
pyint1.vint[98]));
348 eventInfo()->setBinningValues(std::vector<double>(1,
pypars.pari[16]));
358 for (HepMC::GenEvent::particle_iterator
part =
event()->particles_begin();
part !=
event()->particles_end();
360 (*part)->set_pdg_id(HepPID::translatePythiatoPDT((*part)->pdg_id()));
371 std::cout <<
"Event process = " <<
pypars.msti[0] << std::endl <<
"----------------------" << std::endl;
381 std::cout <<
"\n PYPARS \n" << std::endl;
384 <<
"PARI(I)" << std::endl;
385 for (
unsigned int ind = 0; ind < 200; ind++) {
518 int NPartsAfterDecays =
event().get()->particles_size();
519 int barcode = NPartsAfterDecays;
529 for (
int ipart = NPartsAfterDecays; ipart > NPartsBeforeDecays; ipart--) {
537 if (pydat3.mdcy[0][py6ptr - 1] != 1)
539 int py6id = HepPID::translatePDTtoPythia(
pdgid);
545 if (
part->momentum().t() <=
part->generated_mass()) {
549 for (
int i = 0;
i < 5;
i++) {
555 pyjets.k[1][0] = py6id;
556 pyjets.p[4][0] =
part->generated_mass();
557 pyjets.p[3][0] =
part->momentum().t();
558 pyjets.p[0][0] =
part->momentum().x();
559 pyjets.p[1][0] =
part->momentum().y();
560 pyjets.p[2][0] =
part->momentum().z();
561 HepMC::GenVertex* prod_vtx =
part->production_vertex();
564 pyjets.v[0][0] = prod_vtx->position().x();
565 pyjets.v[1][0] = prod_vtx->position().y();
566 pyjets.v[2][0] = prod_vtx->position().z();
567 pyjets.v[3][0] = prod_vtx->position().t();
580 for (
int iprt1 = 1; iprt1 < pyjets.n; iprt1++) {
583 HepMC::GenVertex* DecVtx =
new HepMC::GenVertex(
584 HepMC::FourVector(pyjets.v[0][iprt1], pyjets.v[1][iprt1], pyjets.v[2][iprt1], pyjets.v[3][iprt1]));
585 DecVtx->add_particle_in(
part);
588 HepMC::FourVector pmom(pyjets.p[0][iprt1], pyjets.p[1][iprt1], pyjets.p[2][iprt1], pyjets.p[3][iprt1]);
591 if (pyjets.k[0][iprt1] >= 1 && pyjets.k[0][iprt1] <= 10) {
593 }
else if (pyjets.k[0][iprt1] >= 11 && pyjets.k[0][iprt1] <= 20) {
595 }
else if (pyjets.k[0][iprt1] >= 21 && pyjets.k[0][iprt1] <= 30) {
597 }
else if (pyjets.k[0][iprt1] >= 31 && pyjets.k[0][iprt1] <= 100) {
598 dstatus = pyjets.k[0][iprt1];
601 new HepMC::GenParticle(pmom, HepPID::translatePythiatoPDT(pyjets.k[1][iprt1]), dstatus);
603 daughter->suggest_barcode(barcode);
604 DecVtx->add_particle_out(daughter);
607 for (iprt2 = iprt1 + 1; iprt2 < pyjets.n; iprt2++)
609 if (pyjets.k[2][iprt2] !=
parent) {
610 parent = pyjets.k[2][iprt2];
614 HepMC::FourVector pmomN(pyjets.p[0][iprt2], pyjets.p[1][iprt2], pyjets.p[2][iprt2], pyjets.p[3][iprt2]);
617 if (pyjets.k[0][iprt2] >= 1 && pyjets.k[0][iprt2] <= 10) {
619 }
else if (pyjets.k[0][iprt2] >= 11 && pyjets.k[0][iprt2] <= 20) {
621 }
else if (pyjets.k[0][iprt2] >= 21 && pyjets.k[0][iprt2] <= 30) {
623 }
else if (pyjets.k[0][iprt2] >= 31 && pyjets.k[0][iprt2] <= 100) {
624 dstatus = pyjets.k[0][iprt2];
627 new HepMC::GenParticle(pmomN, HepPID::translatePythiatoPDT(pyjets.k[1][iprt2]), dstatus);
629 daughterN->suggest_barcode(barcode);
630 DecVtx->add_particle_out(daughterN);
636 event().get()->add_vertex(DecVtx);
648 for (
int i = 0;
i < 5;
i++) {
698 call_pyinit(
"USER",
"",
"", 0.0);
704 edm::LogInfo(
"Generator|LHEInterface") <<
"Pythia6 hadronisation found an SLHA header, "
705 <<
"will be passed on to Pythia." << std::endl;
752 call_pyinit(
"3mom",
"e-",
"p", 0.0);
762 call_pyinit(
"3mom",
"e+",
"p", 0.0);
766 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron, ElectronProton, "
767 "and PositronProton \n";
778 for (
unsigned int i = 0;
i <
pdg.size();
i++) {
779 int PyID = HepPID::translatePDTtoPythia(
pdg[
i]);
783 std::ostringstream pyCard;
784 pyCard <<
"MDCY(" << pyCode <<
",1)=0";
796 for (
unsigned int iss = 0; iss < settings.size(); iss++) {
797 if (settings[iss].
find(
"QED-brem-off") == std::string::npos)
799 size_t fnd1 = settings[iss].find(
":");
800 if (fnd1 == std::string::npos)
805 if (
value ==
"all") {
809 int PyID = HepPID::translatePDTtoPythia(
number);
817 <<
" Fatal conflict: \n mandatory internal directive to set MSTJ(39)=" << pyCode
818 <<
" overrides user setting MSTJ(39)=" <<
pydat1_.mstj[38]
819 <<
" - user will not get expected behaviour \n";
821 std::ostringstream pyCard;
822 pyCard <<
"MSTJ(39)=" << pyCode;
836 HepMC::GenEvent::vertex_const_iterator
vbegin =
event()->vertices_begin();
837 HepMC::GenEvent::vertex_const_iterator
vend =
event()->vertices_end();
838 HepMC::GenEvent::vertex_const_iterator vitr =
vbegin;
839 for (; vitr !=
vend; ++vitr) {
840 HepMC::GenVertex::particle_iterator pbegin = (*vitr)->particles_begin(
HepMC::children);
841 HepMC::GenVertex::particle_iterator pend = (*vitr)->particles_end(
HepMC::children);
842 HepMC::GenVertex::particle_iterator pitr = pbegin;
843 for (; pitr != pend; ++pitr) {
844 if ((*pitr)->end_vertex())
846 if ((*pitr)->status() != 1)
849 int pdgcode =
abs((*pitr)->pdg_id());
851 if (pydat3.mdcy[0][
pycomp_(pdgcode) - 1] != 1)
854 double ctau = pydat2.pmas[3][
pycomp_(pdgcode) - 1];
855 HepMC::FourVector mom = (*pitr)->momentum();
856 HepMC::FourVector vin = (*vitr)->position();
861 bool decayInRange =
false;
862 while (!decayInRange) {
865 double proper_length = -ctau *
log(unif_rand);
866 double factor = proper_length / mom.m();
867 x = vin.x() +
factor * mom.px();
868 y = vin.y() +
factor * mom.py();
869 z = vin.z() +
factor * mom.pz();
870 t = vin.t() +
factor * mom.e();
872 if (
pydat1.mstj[21] == 4) {
876 }
else if (
pydat1.mstj[21] == 3) {
886 HepMC::GenVertex* vdec =
new HepMC::GenVertex(HepMC::FourVector(x, y, z,
t));
887 event()->add_vertex(vdec);
888 vdec->add_particle_in((*pitr));
896 if (!
runInfo().internalXSec()) {