9 #include "Pythia8/LesHouches.h"
18 #if (defined GZIPSUPPORT && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406)
19 #pragma GCC diagnostic ignored "-Wshadow"
23 #include "boost/iostreams/filtering_stream.hpp"
24 #include "boost/iostreams/filter/gzip.hpp"
27 #if (defined GZIPSUPPORT && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406)
28 #pragma GCC diagnostic warning "-Wshadow"
45 const double LHAup::CONVERTMB2PB = 1e9;
51 void LHAup::listInit(ostream& os) {
54 os <<
"\n -------- LHA initialization information ------------ \n";
57 os << fixed << setprecision(3)
58 <<
"\n beam kind energy pdfgrp pdfset \n"
59 <<
" A " << setw(6) << idBeamASave
60 << setw(12) << eBeamASave
61 << setw(8) << pdfGroupBeamASave
62 << setw(8) << pdfSetBeamASave <<
"\n"
63 <<
" B " << setw(6) << idBeamBSave
64 << setw(12) << eBeamBSave
65 << setw(8) << pdfGroupBeamBSave
66 << setw(8) << pdfSetBeamBSave <<
"\n";
69 os <<
"\n Event weighting strategy = " << setw(2)
70 << strategySave <<
"\n" ;
73 os << scientific << setprecision(4)
74 <<
"\n Processes, with strategy-dependent cross section info \n"
75 <<
" number xsec (pb) xerr (pb) xmax (pb) \n" ;
76 for (
int ip = 0; ip < int(processes.size()); ++ip) {
77 os << setw(8) << processes[ip].idProc
78 << setw(15) << processes[ip].xSecProc
79 << setw(15) << processes[ip].xErrProc
80 << setw(15) << processes[ip].xMaxProc <<
"\n";
84 os <<
"\n -------- End LHA initialization information -------- \n";
92 void LHAup::listEvent(ostream& os) {
95 os <<
"\n -------- LHA event information and listing -------------"
96 <<
"--------------------------------------------------------- \n";
99 os << scientific << setprecision(4)
100 <<
"\n process = " << setw(8) << idProc
101 <<
" weight = " << setw(12) << weightProc
102 <<
" scale = " << setw(12) << scaleProc <<
" (GeV) \n"
104 <<
" alpha_em = " << setw(12) << alphaQEDProc
105 <<
" alpha_strong = " << setw(12) << alphaQCDProc <<
"\n";
108 os << fixed << setprecision(3)
109 <<
"\n Participating Particles \n"
110 <<
" no id stat mothers colours p_x "
111 <<
"p_y p_z e m tau spin \n" ;
112 for (
int ip = 1; ip < int(particles.size()); ++ip) {
114 << setw(10) << particles[ip].idPart
115 << setw(5) << particles[ip].statusPart
116 << setw(6) << particles[ip].mother1Part
117 << setw(6) << particles[ip].mother2Part
118 << setw(6) << particles[ip].col1Part
119 << setw(6) << particles[ip].col2Part
120 << setw(11) << particles[ip].pxPart
121 << setw(11) << particles[ip].pyPart
122 << setw(11) << particles[ip].pzPart
123 << setw(11) << particles[ip].ePart
124 << setw(11) << particles[ip].mPart
125 << setw(8) << particles[ip].tauPart
126 << setw(8) << particles[ip].spinPart <<
"\n";
130 if (pdfIsSetSave) os <<
"\n pdf: id1 =" << setw(5) << id1pdfSave
131 <<
" id2 =" << setw(5) << id2pdfSave
132 <<
" x1 =" << scientific << setw(10) << x1pdfSave
133 <<
" x2 =" << setw(10) << x2pdfSave
134 <<
" scalePDF =" << setw(10) << scalePDFSave
135 <<
" pdf1 =" << setw(10) << pdf1Save
136 <<
" pdf2 =" << setw(10) << pdf2Save <<
"\n";
139 os <<
"\n -------- End LHA event information and listing ---------"
140 <<
"--------------------------------------------------------- \n";
148 bool LHAup::openLHEF(
string fileNameIn) {
151 fileName = fileNameIn;
152 const char* cstring = fileName.c_str();
153 osLHEF.open(cstring, ios::out | ios::trunc);
155 infoPtr->errorMsg(
"Error in LHAup::openLHEF:"
156 " could not open file", fileName);
162 strftime(dateNow,12,
"%d %b %Y",localtime(&t));
163 strftime(timeNow,9,
"%H:%M:%S",localtime(&t));
166 osLHEF <<
"<LesHouchesEvents version=\"1.0\">\n"
168 <<
" File written by Pythia8::LHAup on "
169 << dateNow <<
" at " << timeNow <<
"\n"
181 bool LHAup::initLHEF() {
184 osLHEF <<
"<init>\n" << scientific << setprecision(6)
185 <<
" " << idBeamASave <<
" " << idBeamBSave
186 <<
" " << eBeamASave <<
" " << eBeamBSave
187 <<
" " << pdfGroupBeamASave <<
" " << pdfGroupBeamBSave
188 <<
" " << pdfSetBeamASave <<
" " << pdfSetBeamBSave
189 <<
" " << strategySave <<
" " << processes.size() <<
"\n";
192 for (
int ip = 0; ip < int(processes.size()); ++ip)
193 osLHEF <<
" " << setw(13) << processes[ip].xSecProc
194 <<
" " << setw(13) << processes[ip].xErrProc
195 <<
" " << setw(13) << processes[ip].xMaxProc
196 <<
" " << setw(6) << processes[ip].idProc <<
"\n";
199 osLHEF <<
"</init>" << endl;
210 bool LHAup::eventLHEF(
bool verbose) {
216 osLHEF <<
"<event>\n" << scientific << setprecision(6)
217 <<
" " << setw(5) << particles.size() - 1
218 <<
" " << setw(5) << idProc
219 <<
" " << setw(13) << weightProc
220 <<
" " << setw(13) << scaleProc
221 <<
" " << setw(13) << alphaQEDProc
222 <<
" " << setw(13) << alphaQCDProc <<
"\n";
225 for (
int ip = 1; ip < int(particles.size()); ++ip) {
226 LHAParticle& ptNow = particles[ip];
227 osLHEF <<
" " << setw(8) << ptNow.idPart
228 <<
" " << setw(5) << ptNow.statusPart
229 <<
" " << setw(5) << ptNow.mother1Part
230 <<
" " << setw(5) << ptNow.mother2Part
231 <<
" " << setw(5) << ptNow.col1Part
232 <<
" " << setw(5) << ptNow.col2Part << setprecision(10)
233 <<
" " << setw(17) << ptNow.pxPart
234 <<
" " << setw(17) << ptNow.pyPart
235 <<
" " << setw(17) << ptNow.pzPart
236 <<
" " << setw(17) << ptNow.ePart
237 <<
" " << setw(17) << ptNow.mPart << setprecision(6);
238 if (ptNow.tauPart == 0.) osLHEF <<
" 0.";
239 else osLHEF <<
" " << setw(13) << ptNow.tauPart;
240 if (ptNow.spinPart == 9.) osLHEF <<
" 9.";
241 else osLHEF <<
" " << setw(13) << ptNow.spinPart;
246 if (pdfIsSetSave) osLHEF <<
"#pdf"
247 <<
" " << setw(4) << id1pdfSave
248 <<
" " << setw(4) << id2pdfSave
249 <<
" " << setw(13) << x1pdfSave
250 <<
" " << setw(13) << x2pdfSave
251 <<
" " << setw(13) << scalePDFSave
252 <<
" " << setw(13) << pdf1Save
253 <<
" " << setw(13) << pdf2Save <<
"\n";
259 osLHEF <<
"<event>\n" << scientific << setprecision(6)
260 << particles.size() - 1 <<
" " << idProc <<
" "
261 << weightProc <<
" " << scaleProc <<
" "
262 << alphaQEDProc <<
" " << alphaQCDProc <<
"\n";
265 for (
int ip = 1; ip < int(particles.size()); ++ip) {
266 LHAParticle& ptNow = particles[ip];
267 osLHEF << ptNow.idPart <<
" " << ptNow.statusPart
268 <<
" " << ptNow.mother1Part <<
" " << ptNow.mother2Part
269 <<
" " << ptNow.col1Part <<
" " << ptNow.col2Part
270 << setprecision(10) <<
" " << ptNow.pxPart
271 <<
" " << ptNow.pyPart <<
" " << ptNow.pzPart
272 <<
" " << ptNow.ePart <<
" " << ptNow.mPart
274 if (ptNow.tauPart == 0.) osLHEF <<
" 0.";
275 else osLHEF <<
" " << setw(13) << ptNow.tauPart;
276 if (ptNow.spinPart == 9.) osLHEF <<
" 9.";
277 else osLHEF <<
" " << setw(13) << ptNow.spinPart;
282 if (pdfIsSetSave) osLHEF <<
"#pdf" <<
" " << id1pdfSave
283 <<
" " << id2pdfSave <<
" " << x1pdfSave <<
" " << x2pdfSave
284 <<
" " << scalePDFSave <<
" " << pdf1Save <<
" " << pdf2Save
289 osLHEF <<
"</event>" << endl;
298 bool LHAup::closeLHEF(
bool updateInit) {
301 osLHEF <<
"</LesHouchesEvents>" << endl;
306 const char* cstring = fileName.c_str();
307 osLHEF.open(cstring, ios::in | ios::out);
310 osLHEF <<
"<LesHouchesEvents version=\"1.0\">\n"
312 <<
" File written by Pythia8::LHAup on "
313 << dateNow <<
" at " << timeNow <<
"\n"
330 bool LHAup::setInitLHEF(istream& is,
bool readHeaders) {
334 if (!getline(is, line))
return false;
335 if (line.find(
"<LesHouchesEvents") == string::npos)
return false;
336 if (line.find(
"version=\"1.0\"" ) == string::npos )
return false;
340 string headerTag = (readHeaders) ?
"<header>" :
"<init";
346 if (!getline(is, line))
return false;
347 if (line.find_first_not_of(
" \n\t\v\b\r\f\a") != string::npos) {
348 istringstream getfirst(line);
350 if (!getfirst)
return false;
352 }
while (tag !=
"<init>" && tag !=
"<init" && tag != headerTag);
355 if (readHeaders ==
true && tag == headerTag) {
357 map < string, string > headerMap;
360 bool read =
true, newKey =
false;
362 vector < string > keyVec;
364 if (!getline(is, line))
return false;
368 size_t pos1 = line.find_first_not_of(
" \n\t\v\b\r\f\a");
369 size_t pos2 = line.find_last_not_of(
" \n\t\v\b\r\f\a");
370 if (pos1 != string::npos && line[pos1] ==
'<' &&
371 pos2 != string::npos && line[pos2] ==
'>' &&
375 tag = line.substr(pos1 + 1, pos2 - pos1 - 1);
376 istringstream getfirst(tag);
383 if (tag ==
"init")
break;
387 else if (tag ==
"/header") {
392 }
else if (tag[0] !=
'/') {
393 keyVec.push_back(tag);
398 }
else if (tag ==
"/" + keyVec.back()) {
413 if (keyVec.empty()) key =
"base";
414 else key = keyVec[0];
415 for (
size_t i = 1; i < keyVec.size(); i++)
416 key +=
"." + keyVec[i];
421 headerMap[key] += line +
"\n";
426 for (map < string, string >::iterator it = headerMap.begin();
427 it != headerMap.end(); it++)
428 setInfoHeader(it->first, it->second);
433 if (!getline(is, line))
return false;
434 if (line.find(
"</init") != string::npos)
return true;
437 int idbmupA, idbmupB;
438 double ebmupA, ebmupB;
439 int pdfgupA, pdfgupB, pdfsupA, pdfsupB, idwtup, nprup;
440 istringstream getbms(line);
441 getbms >> idbmupA >> idbmupB >> ebmupA >> ebmupB >> pdfgupA
442 >> pdfgupB >> pdfsupA >> pdfsupB >> idwtup >> nprup;
443 if (!getbms)
return false;
444 setBeamA(idbmupA, ebmupA, pdfgupA, pdfsupA);
445 setBeamB(idbmupB, ebmupB, pdfgupB, pdfsupB);
449 double xsecup, xerrup, xmaxup;
453 for (
int ip = 0; ip < nprup; ++ip) {
454 if (!getline(is, line))
return false;
455 istringstream getpro(line);
456 getpro >> xsecup >> xerrup >> xmaxup >> lprup ;
457 if (!getpro)
return false;
458 addProcess(lprup, xsecup, xerrup, xmaxup);
459 xSecSumSave += xsecup;
460 xErrSumSave += pow2(xerrup);
462 xErrSumSave = sqrt(xErrSumSave);
474 bool LHAup::setNewEventLHEF(istream& is,
double mRecalculate ) {
479 if (!getline(is, line))
return false;
480 if (line.find_first_not_of(
" \n\t\v\b\r\f\a") != string::npos) {
481 istringstream getfirst(line);
483 if (!getfirst)
return false;
485 }
while (tag !=
"<event>" && tag !=
"<event");
488 if (!getline(is, line))
return false;
489 istringstream getpro(line);
490 getpro >> nupSave >> idprupSave >> xwgtupSave >> scalupSave
491 >> aqedupSave >> aqcdupSave;
492 if (!getpro)
return false;
495 particlesSave.clear();
496 particlesSave.push_back( LHAParticle() );
501 int idup, istup, mothup1, mothup2, icolup1, icolup2;
502 double pup1, pup2, pup3, pup4, pup5, vtimup, spinup;
503 bool doRecalculate = (mRecalculate > 0.);
504 for (
int ip = 1; ip <= nupSave; ++ip) {
505 if (!getline(is, line))
return false;
506 istringstream getall(line);
507 getall >> idup >> istup >> mothup1 >> mothup2 >> icolup1 >> icolup2
508 >> pup1 >> pup2 >> pup3 >> pup4 >> pup5 >> vtimup >> spinup;
509 if (!getall)
return false;
511 if (doRecalculate && pup5 > mRecalculate)
512 pup5 = sqrtpos( pup4*pup4 - pup1*pup1 - pup2*pup2 - pup3*pup3);
513 particlesSave.push_back( LHAParticle( idup, istup, mothup1, mothup2,
514 icolup1, icolup2, pup1, pup2, pup3, pup4, pup5, vtimup, spinup, -1.) );
518 id1InSave = particlesSave[1].idPart;
519 id2InSave = particlesSave[2].idPart;
520 x1InSave = (eBeamASave > 0.) ? particlesSave[1].ePart / eBeamASave : 0.;
521 x2InSave = (eBeamBSave > 0.) ? particlesSave[2].ePart / eBeamBSave : 0.;
527 if (!getline(is, line))
return false;
528 istringstream getinfo(line);
530 if (!getinfo)
return false;
533 if (tag ==
"#pdf" && !getPDFSave) {
534 getinfo >> id1pdfInSave >> id2pdfInSave >> x1pdfInSave >> x2pdfInSave
535 >> scalePDFInSave >> pdf1InSave >> pdf2InSave;
536 if (!getinfo)
return false;
540 }
else if (tag ==
"#" && !getScale) {
542 for (
int i = 3; i < int(particlesSave.size()); ++i)
543 if (particlesSave[i].statusPart == 1) {
544 if ( !(getinfo >> scaleIn) )
return false;
545 particlesSave[i].scalePart = scaleIn;
547 if (!getinfo)
return false;
550 }
while (tag !=
"</event>" && tag !=
"</event");
554 id1pdfInSave = id1InSave;
555 id2pdfInSave = id2InSave;
556 x1pdfInSave = x1InSave;
557 x2pdfInSave = x2InSave;
572 bool LHAup::setOldEventLHEF() {
575 setProcess( idprupSave, xwgtupSave, scalupSave, aqedupSave, aqcdupSave);
576 for (
int ip = 1; ip <= nupSave; ++ip) addParticle( particlesSave[ip] );
577 setIdX( id1InSave, id2InSave, x1InSave, x2InSave);
578 setPdf( id1pdfInSave, id2pdfInSave, x1pdfInSave, x2pdfInSave,
579 scalePDFInSave, pdf1InSave, pdf2InSave, getPDFSave);
598 istream* LHAup::openFile(
const char *fn, ifstream &ifs) {
604 return (istream *) &ifs;
609 boost::iostreams::filtering_istream *fis =
610 new boost::iostreams::filtering_istream();
613 if (!ifs.good()) fis->setstate(std::ios_base::badbit);
617 const char *last = strrchr(fn,
'.');
618 if (last && strncmp(last,
".gz", 3) == 0)
619 fis->push(boost::iostreams::gzip_decompressor());
622 return (istream *) fis;
624 #endif // GZIPSUPPORT
632 void LHAup::closeFile(istream *&is, ifstream &ifs) {
635 if (is && is != &ifs)
delete is;
639 if (ifs.is_open()) ifs.close();
651 LHAupLHEF::LHAupLHEF(
const char* fileIn,
const char* headerIn,
653 : is(NULL), isHead(NULL), readHeaders(readHeadersIn) {
658 is = openFile(fileIn, ifs);
659 isHead = (headerIn == NULL) ? is : openFile(headerIn, ifsHead);
666 LHAupLHEF::~LHAupLHEF() {
679 bool LHAupFromPYTHIA8::setInit() {
682 int idbmupA = infoPtr->idA();
683 int idbmupB = infoPtr->idB();
684 double ebmupA = infoPtr->eA();
685 double ebmupB = infoPtr->eB();
690 setBeamA(idbmupA, ebmupA, pdfgupA, pdfsupA);
691 setBeamB(idbmupB, ebmupB, pdfgupB, pdfsupB);
702 addProcess(lprup, xsecup, xerrup, xmaxup);
713 bool LHAupFromPYTHIA8::setEvent(
int,
double ) {
719 double xwgtup = infoPtr->weight();
720 double scalup = infoPtr->QRen();
721 double aqedup = infoPtr->alphaEM();
722 double aqcdup = infoPtr->alphaS();
723 setProcess(idprup, xwgtup, scalup, aqedup, aqcdup);
727 int nup = processPtr->size() - 3;
728 int idup, statusup, istup, mothup1, mothup2, icolup1, icolup2;
729 double pup1, pup2, pup3, pup4, pup5, vtimup, spinup;
730 for (
int ip = 1; ip <= nup; ++ip) {
731 Particle& particle = (*processPtr)[ip + 2];
732 idup = particle.id();
734 statusup = particle.status();
735 if (ip < 3) istup = -1;
736 else if (statusup < 0) istup = 2;
738 mothup1 = max(0, particle.mother1() - 2);
739 mothup2 = max(0, particle.mother2() - 2);
740 icolup1 = particle.col();
741 icolup2 = particle.acol();
742 pup1 = particle.px();
743 pup2 = particle.py();
744 pup3 = particle.pz();
747 vtimup = particle.tau();
748 spinup = particle.pol();
749 addParticle(idup, istup, mothup1, mothup2, icolup1, icolup2,
750 pup1, pup2, pup3, pup4, pup5, vtimup, spinup, -1.) ;
754 int id1up = infoPtr->id1();
755 int id2up = infoPtr->id2();
756 double x1up = infoPtr->x1();
757 double x2up = infoPtr->x2();
758 setIdX( id1up, id2up, x1up, x2up);
761 int id1pdfup = infoPtr->id1pdf();
762 int id2pdfup = infoPtr->id2pdf();
763 double x1pdfup = infoPtr->x1pdf();
764 double x2pdfup = infoPtr->x2pdf();
765 double scalePDFup = infoPtr->QFac();
766 double pdf1up = infoPtr->pdf1();
767 double pdf2up = infoPtr->pdf2();
768 setPdf(id1pdfup, id2pdfup, x1pdfup, x2pdfup, scalePDFup, pdf1up,
780 bool LHAupFromPYTHIA8::updateSigma() {
783 double sigGen = CONVERTMB2PB * infoPtr->sigmaGen();
784 double sigErr = CONVERTMB2PB * infoPtr->sigmaErr();