9 #include "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) << id1Save
131 <<
" id2 =" << setw(5) << id2Save
132 <<
" x1 =" << scientific << setw(10) << x1Save
133 <<
" x2 =" << setw(10) << x2Save
134 <<
" scalePDF =" << setw(10) << scalePDFSave
135 <<
" xpdf1 =" << setw(10) << xpdf1Save
136 <<
" xpdf2 =" << setw(10) << xpdf2Save <<
"\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;
208 bool LHAup::eventLHEF() {
211 osLHEF <<
"<event>\n" << scientific << setprecision(6)
212 <<
" " << setw(5) << particles.size() - 1
213 <<
" " << setw(5) << idProc
214 <<
" " << setw(13) << weightProc
215 <<
" " << setw(13) << scaleProc
216 <<
" " << setw(13) << alphaQEDProc
217 <<
" " << setw(13) << alphaQCDProc <<
"\n";
220 for (
int ip = 1; ip < int(particles.size()); ++ip) {
221 osLHEF <<
" " << setw(8) << particles[ip].idPart
222 <<
" " << setw(5) << particles[ip].statusPart
223 <<
" " << setw(5) << particles[ip].mother1Part
224 <<
" " << setw(5) << particles[ip].mother2Part
225 <<
" " << setw(5) << particles[ip].col1Part
226 <<
" " << setw(5) << particles[ip].col2Part << setprecision(10)
227 <<
" " << setw(17) << particles[ip].pxPart
228 <<
" " << setw(17) << particles[ip].pyPart
229 <<
" " << setw(17) << particles[ip].pzPart
230 <<
" " << setw(17) << particles[ip].ePart
231 <<
" " << setw(17) << particles[ip].mPart << setprecision(6);
232 if (particles[ip].tauPart == 0.) osLHEF <<
" 0.";
233 else osLHEF <<
" " << setw(13) << particles[ip].tauPart;
234 if (particles[ip].spinPart == 9.) osLHEF <<
" 9.";
235 else osLHEF <<
" " << setw(13) << particles[ip].spinPart;
240 if (pdfIsSetSave) osLHEF <<
"#pdf"
241 <<
" " << setw(4) << id1Save
242 <<
" " << setw(4) << id2Save
243 <<
" " << setw(13) << x1Save
244 <<
" " << setw(13) << x2Save
245 <<
" " << setw(13) << scalePDFSave
246 <<
" " << setw(13) << xpdf1Save
247 <<
" " << setw(13) << xpdf2Save <<
"\n";
250 osLHEF <<
"</event>" << endl;
259 bool LHAup::closeLHEF(
bool updateInit) {
262 osLHEF <<
"</LesHouchesEvents>" << endl;
267 const char* cstring = fileName.c_str();
268 osLHEF.open(cstring, ios::in | ios::out);
271 osLHEF <<
"<LesHouchesEvents version=\"1.0\">\n"
273 <<
" File written by Pythia8::LHAup on "
274 << dateNow <<
" at " << timeNow <<
"\n"
291 bool LHAup::setInitLHEF(istream& is) {
295 if (!getline(is, line))
return false;
296 if (line.find(
"<LesHouchesEvents") == string::npos)
return false;
297 if (line.find(
"version=\"1.0\"" ) == string::npos )
return false;
302 if (!getline(is, line))
return false;
303 if (line.find_first_not_of(
" \n\t\v\b\r\f\a") != string::npos) {
304 istringstream getfirst(line);
306 if (!getfirst)
return false;
308 }
while (tag !=
"<init>" && tag !=
"<init");
311 int idbmupA, idbmupB;
312 double ebmupA, ebmupB;
313 int pdfgupA, pdfgupB, pdfsupA, pdfsupB, idwtup, nprup;
314 if (!getline(is, line))
return false;
315 istringstream getbms(line);
316 getbms >> idbmupA >> idbmupB >> ebmupA >> ebmupB >> pdfgupA
317 >> pdfgupB >> pdfsupA >> pdfsupB >> idwtup >> nprup;
318 if (!getbms)
return false;
319 setBeamA(idbmupA, ebmupA, pdfgupA, pdfsupA);
320 setBeamB(idbmupB, ebmupB, pdfgupB, pdfsupB);
324 double xsecup, xerrup, xmaxup;
326 for (
int ip = 0; ip < nprup; ++ip) {
327 if (!getline(is, line))
return false;
328 istringstream getpro(line);
329 getpro >> xsecup >> xerrup >> xmaxup >> lprup ;
330 if (!getpro)
return false;
331 addProcess(lprup, xsecup, xerrup, xmaxup);
344 bool LHAup::setNewEventLHEF(istream& is) {
349 if (!getline(is, line))
return false;
350 if (line.find_first_not_of(
" \n\t\v\b\r\f\a") != string::npos) {
351 istringstream getfirst(line);
353 if (!getfirst)
return false;
355 }
while (tag !=
"<event>" && tag !=
"<event");
358 if (!getline(is, line))
return false;
359 istringstream getpro(line);
360 getpro >> nupSave >> idprupSave >> xwgtupSave >> scalupSave
361 >> aqedupSave >> aqcdupSave;
362 if (!getpro)
return false;
365 particlesSave.clear();
366 particlesSave.push_back( LHAParticle() );
371 int idup, istup, mothup1, mothup2, icolup1, icolup2;
372 double pup1, pup2, pup3, pup4, pup5, vtimup, spinup;
373 for (
int ip = 1; ip <= nupSave; ++ip) {
374 if (!getline(is, line))
return false;
375 istringstream getall(line);
376 getall >> idup >> istup >> mothup1 >> mothup2 >> icolup1 >> icolup2
377 >> pup1 >> pup2 >> pup3 >> pup4 >> pup5 >> vtimup >> spinup;
378 if (!getall)
return false;
379 particlesSave.push_back( LHAParticle( idup, istup, mothup1, mothup2,
380 icolup1, icolup2, pup1, pup2, pup3, pup4, pup5, vtimup, spinup) );
386 if (!getline(is, line))
return false;
387 istringstream getpdf(line);
389 if (!getpdf)
return false;
391 getpdf >> id1InSave >> id2InSave >> x1InSave >> x2InSave
392 >> scalePDFInSave >> xpdf1InSave >> xpdf2InSave;
393 if (!getpdf)
return false;
396 }
while (tag !=
"</event>" && tag !=
"</event");
400 id1InSave = particlesSave[1].idPart;
401 id2InSave = particlesSave[2].idPart;
402 x1InSave = particlesSave[1].ePart / eBeamASave;
403 x2InSave = particlesSave[2].ePart / eBeamBSave;
418 bool LHAup::setOldEventLHEF() {
421 setProcess(idprupSave, xwgtupSave, scalupSave, aqedupSave, aqcdupSave);
422 for (
int ip = 1; ip <= nupSave; ++ip) addParticle( particlesSave[ip] );
423 setPdf(id1InSave, id2InSave, x1InSave, x2InSave, scalePDFInSave,
424 xpdf1InSave, xpdf2InSave, getPDFSave);
440 LHAupLHEF::LHAupLHEF(
const char* fileIn) : ifs(fileIn), is(NULL) {
444 is = (istream *) &ifs;
448 boost::iostreams::filtering_istream *fis =
449 new boost::iostreams::filtering_istream();
452 if (!ifs.good()) fis->setstate(ios_base::badbit);
456 const char *last = strrchr(fileIn,
'.');
457 if (last && strncmp(last,
".gz", 3) == 0)
458 fis->push(boost::iostreams::gzip_decompressor());
461 is = (istream *) fis;
470 LHAupLHEF::~LHAupLHEF() {
487 bool LHAupFromPYTHIA8::setInit() {
490 int idbmupA = infoPtr->idA();
491 int idbmupB = infoPtr->idB();
492 double ebmupA = infoPtr->eA();
493 double ebmupB = infoPtr->eB();
498 setBeamA(idbmupA, ebmupA, pdfgupA, pdfsupA);
499 setBeamB(idbmupB, ebmupB, pdfgupB, pdfsupB);
510 addProcess(lprup, xsecup, xerrup, xmaxup);
521 bool LHAupFromPYTHIA8::setEvent(
int ) {
527 double xwgtup = infoPtr->weight();
528 double scalup = infoPtr->QRen();
529 double aqedup = infoPtr->alphaEM();
530 double aqcdup = infoPtr->alphaS();
531 setProcess(idprup, xwgtup, scalup, aqedup, aqcdup);
535 int nup = processPtr->size() - 3;
536 int idup, statusup, istup, mothup1, mothup2, icolup1, icolup2;
537 double pup1, pup2, pup3, pup4, pup5, vtimup, spinup;
538 for (
int ip = 1; ip <= nup; ++ip) {
539 Particle& particle = (*processPtr)[ip + 2];
540 idup = particle.id();
542 statusup = particle.status();
543 if (ip < 3) istup = -1;
544 else if (statusup < 0) istup = 2;
546 mothup1 = max(0, particle.mother1() - 2);
547 mothup2 = max(0, particle.mother2() - 2);
548 icolup1 = particle.col();
549 icolup2 = particle.acol();
550 pup1 = particle.px();
551 pup2 = particle.py();
552 pup3 = particle.pz();
555 vtimup = particle.tau();
556 spinup = particle.pol();
557 addParticle(idup, istup, mothup1, mothup2, icolup1, icolup2,
558 pup1, pup2, pup3, pup4, pup5, vtimup, spinup) ;
562 int id1up = infoPtr->id1();
563 int id2up = infoPtr->id2();
564 double x1up = infoPtr->x1();
565 double x2up = infoPtr->x2();
566 double scalePDFup = infoPtr->QFac();
567 double xpdf1up = infoPtr->pdf1();
568 double xpdf2up = infoPtr->pdf2();
569 setPdf(id1up, id2up, x1up, x2up, scalePDFup, xpdf1up, xpdf2up,
true);
580 bool LHAupFromPYTHIA8::updateSigma() {
583 double sigGen = CONVERTMB2PB * infoPtr->sigmaGen();
584 double sigErr = CONVERTMB2PB * infoPtr->sigmaErr();