9 #include "Pythia8/Pythia.h"
10 #include "Pythia8/LesHouches.h"
27 const double LHAup::CONVERTMB2PB = 1e9;
33 void LHAup::listInit() {
36 cout <<
"\n -------- LHA initialization information ------------ \n";
39 cout << fixed << setprecision(3)
40 <<
"\n beam kind energy pdfgrp pdfset \n"
41 <<
" A " << setw(6) << idBeamASave
42 << setw(12) << eBeamASave
43 << setw(8) << pdfGroupBeamASave
44 << setw(8) << pdfSetBeamASave <<
"\n"
45 <<
" B " << setw(6) << idBeamBSave
46 << setw(12) << eBeamBSave
47 << setw(8) << pdfGroupBeamBSave
48 << setw(8) << pdfSetBeamBSave <<
"\n";
51 cout <<
"\n Event weighting strategy = " << setw(2)
52 << strategySave <<
"\n" ;
55 cout << scientific << setprecision(4)
56 <<
"\n Processes, with strategy-dependent cross section info \n"
57 <<
" number xsec (pb) xerr (pb) xmax (pb) \n" ;
58 for (
int ip = 0; ip < int(processes.size()); ++ip) {
59 cout << setw(8) << processes[ip].idProc
60 << setw(15) << processes[ip].xSecProc
61 << setw(15) << processes[ip].xErrProc
62 << setw(15) << processes[ip].xMaxProc <<
"\n";
66 cout <<
"\n -------- End LHA initialization information -------- \n";
74 void LHAup::listEvent() {
77 cout <<
"\n -------- LHA event information and listing -------------"
78 <<
"--------------------------------------------------------- \n";
81 cout << scientific << setprecision(4)
82 <<
"\n process = " << setw(8) << idProc
83 <<
" weight = " << setw(12) << weightProc
84 <<
" scale = " << setw(12) << scaleProc <<
" (GeV) \n"
86 <<
" alpha_em = " << setw(12) << alphaQEDProc
87 <<
" alpha_strong = " << setw(12) << alphaQCDProc <<
"\n";
90 cout << fixed << setprecision(3)
91 <<
"\n Participating Particles \n"
92 <<
" no id stat mothers colours p_x "
93 <<
"p_y p_z e m tau spin \n" ;
94 for (
int ip = 1; ip < int(particles.size()); ++ip) {
96 << setw(10) << particles[ip].idPart
97 << setw(5) << particles[ip].statusPart
98 << setw(6) << particles[ip].mother1Part
99 << setw(6) << particles[ip].mother2Part
100 << setw(6) << particles[ip].col1Part
101 << setw(6) << particles[ip].col2Part
102 << setw(11) << particles[ip].pxPart
103 << setw(11) << particles[ip].pyPart
104 << setw(11) << particles[ip].pzPart
105 << setw(11) << particles[ip].ePart
106 << setw(11) << particles[ip].mPart
107 << setw(8) << particles[ip].tauPart
108 << setw(8) << particles[ip].spinPart <<
"\n";
112 if (pdfIsSetSave) cout <<
"\n pdf: id1 =" << setw(5) << id1pdfSave
113 <<
" id2 =" << setw(5) << id2pdfSave
114 <<
" x1 =" << scientific << setw(10) << x1pdfSave
115 <<
" x2 =" << setw(10) << x2pdfSave
116 <<
" scalePDF =" << setw(10) << scalePDFSave
117 <<
" pdf1 =" << setw(10) << pdf1Save
118 <<
" pdf2 =" << setw(10) << pdf2Save <<
"\n";
121 cout <<
"\n -------- End LHA event information and listing ---------"
122 <<
"--------------------------------------------------------- \n";
130 bool LHAup::openLHEF(
string fileNameIn) {
133 fileName = fileNameIn;
134 const char* cstring = fileName.c_str();
135 osLHEF.open(cstring, ios::out | ios::trunc);
137 infoPtr->errorMsg(
"Error in LHAup::openLHEF:"
138 " could not open file", fileName);
144 strftime(dateNow,12,
"%d %b %Y",localtime(&t));
145 strftime(timeNow,9,
"%H:%M:%S",localtime(&t));
148 osLHEF <<
"<LesHouchesEvents version=\"1.0\">\n"
150 <<
" File written by Pythia8::LHAup on "
151 << dateNow <<
" at " << timeNow <<
"\n"
163 bool LHAup::initLHEF() {
166 osLHEF <<
"<init>\n" << scientific << setprecision(6)
167 <<
" " << idBeamASave <<
" " << idBeamBSave
168 <<
" " << eBeamASave <<
" " << eBeamBSave
169 <<
" " << pdfGroupBeamASave <<
" " << pdfGroupBeamBSave
170 <<
" " << pdfSetBeamASave <<
" " << pdfSetBeamBSave
171 <<
" " << strategySave <<
" " << processes.size() <<
"\n";
174 for (
int ip = 0; ip < int(processes.size()); ++ip)
175 osLHEF <<
" " << setw(13) << processes[ip].xSecProc
176 <<
" " << setw(13) << processes[ip].xErrProc
177 <<
" " << setw(13) << processes[ip].xMaxProc
178 <<
" " << setw(6) << processes[ip].idProc <<
"\n";
181 osLHEF <<
"</init>" << endl;
192 bool LHAup::eventLHEF(
bool verbose) {
198 osLHEF <<
"<event>\n" << scientific << setprecision(6)
199 <<
" " << setw(5) << particles.size() - 1
200 <<
" " << setw(5) << idProc
201 <<
" " << setw(13) << weightProc
202 <<
" " << setw(13) << scaleProc
203 <<
" " << setw(13) << alphaQEDProc
204 <<
" " << setw(13) << alphaQCDProc <<
"\n";
207 for (
int ip = 1; ip < int(particles.size()); ++ip) {
208 LHAParticle& ptNow = particles[ip];
209 osLHEF <<
" " << setw(8) << ptNow.idPart
210 <<
" " << setw(5) << ptNow.statusPart
211 <<
" " << setw(5) << ptNow.mother1Part
212 <<
" " << setw(5) << ptNow.mother2Part
213 <<
" " << setw(5) << ptNow.col1Part
214 <<
" " << setw(5) << ptNow.col2Part << setprecision(10)
215 <<
" " << setw(17) << ptNow.pxPart
216 <<
" " << setw(17) << ptNow.pyPart
217 <<
" " << setw(17) << ptNow.pzPart
218 <<
" " << setw(17) << ptNow.ePart
219 <<
" " << setw(17) << ptNow.mPart << setprecision(6);
220 if (ptNow.tauPart == 0.) osLHEF <<
" 0.";
221 else osLHEF <<
" " << setw(13) << ptNow.tauPart;
222 if (ptNow.spinPart == 9.) osLHEF <<
" 9.";
223 else osLHEF <<
" " << setw(13) << ptNow.spinPart;
228 if (pdfIsSetSave) osLHEF <<
"#pdf"
229 <<
" " << setw(4) << id1pdfSave
230 <<
" " << setw(4) << id2pdfSave
231 <<
" " << setw(13) << x1pdfSave
232 <<
" " << setw(13) << x2pdfSave
233 <<
" " << setw(13) << scalePDFSave
234 <<
" " << setw(13) << pdf1Save
235 <<
" " << setw(13) << pdf2Save <<
"\n";
238 if (scaleShowersIsSetSave) osLHEF <<
"#scaleShowers"
239 <<
" " << setw(13) << scaleShowersSave[0]
240 <<
" " << setw(13) << scaleShowersSave[1] <<
"\n";
246 osLHEF <<
"<event>\n" << scientific << setprecision(6)
247 << particles.size() - 1 <<
" " << idProc <<
" "
248 << weightProc <<
" " << scaleProc <<
" "
249 << alphaQEDProc <<
" " << alphaQCDProc <<
"\n";
252 for (
int ip = 1; ip < int(particles.size()); ++ip) {
253 LHAParticle& ptNow = particles[ip];
254 osLHEF << ptNow.idPart <<
" " << ptNow.statusPart
255 <<
" " << ptNow.mother1Part <<
" " << ptNow.mother2Part
256 <<
" " << ptNow.col1Part <<
" " << ptNow.col2Part
257 << setprecision(10) <<
" " << ptNow.pxPart
258 <<
" " << ptNow.pyPart <<
" " << ptNow.pzPart
259 <<
" " << ptNow.ePart <<
" " << ptNow.mPart
261 if (ptNow.tauPart == 0.) osLHEF <<
" 0.";
262 else osLHEF <<
" " << setw(13) << ptNow.tauPart;
263 if (ptNow.spinPart == 9.) osLHEF <<
" 9.";
264 else osLHEF <<
" " << setw(13) << ptNow.spinPart;
269 if (pdfIsSetSave) osLHEF <<
"#pdf" <<
" " << id1pdfSave
270 <<
" " << id2pdfSave <<
" " << x1pdfSave <<
" " << x2pdfSave
271 <<
" " << scalePDFSave <<
" " << pdf1Save <<
" " << pdf2Save
275 if (scaleShowersIsSetSave) osLHEF <<
"#scaleShowers" <<
" "
276 << scaleShowersSave[0] <<
" " << scaleShowersSave[1] <<
"\n";
280 osLHEF <<
"</event>" << endl;
289 bool LHAup::closeLHEF(
bool updateInit) {
292 osLHEF <<
"</LesHouchesEvents>" << endl;
297 const char* cstring = fileName.c_str();
298 osLHEF.open(cstring, ios::in | ios::out);
301 osLHEF <<
"<LesHouchesEvents version=\"1.0\">\n"
303 <<
" File written by Pythia8::LHAup on "
304 << dateNow <<
" at " << timeNow <<
"\n"
321 bool LHAup::setInitLHEF(istream& is,
bool readHeaders) {
325 if (!getline(is, line))
return false;
326 if (line.find(
"<LesHouchesEvents") == string::npos)
return false;
327 if (line.find(
"version=\"1.0\"" ) == string::npos )
return false;
331 string headerTag = (readHeaders) ?
"<header>" :
"<init";
337 if (!getline(is, line))
return false;
338 if (line.find_first_not_of(
" \n\t\v\b\r\f\a") != string::npos) {
339 istringstream getfirst(line);
341 if (!getfirst)
return false;
343 }
while (tag !=
"<init>" && tag !=
"<init" && tag != headerTag);
346 if (readHeaders ==
true && tag == headerTag) {
348 map < string, string > headerMap;
351 bool read =
true, newKey =
false;
353 vector < string > keyVec;
356 if (!getline(is, line))
return false;
361 size_t firstTagEnd = line.find_first_of(
">");
362 size_t secondTagBegin = line.find_first_of(
"<",firstTagEnd);
363 vector<string> lineVec;
364 if (firstTagEnd != string::npos && secondTagBegin != string::npos) {
365 lineVec.push_back(line.substr(0,secondTagBegin));
366 lineVec.push_back(line.substr(secondTagBegin,
367 line.size()-secondTagBegin));
370 lineVec.push_back(line);
374 for (
int iVec=0; iVec<int(lineVec.size()); ++iVec) {
375 line = lineVec[iVec];
378 size_t posBeg = line.find_first_not_of(
" \n\t\v\b\r\f\a");
379 size_t posEnd = line.find_last_not_of(
" \n\t\v\b\r\f\a");
380 string lineClean =
" ";
381 if (posBeg != string::npos && posEnd != string::npos && posBeg
383 lineClean = line.substr(posBeg, posEnd - posBeg + 1);
385 posEnd = lineClean.size();
389 if (lineClean ==
" " || posBeg >= posEnd)
continue;
392 size_t tagBeg = lineClean.find_first_of(
"<");
393 size_t tagEnd = lineClean.find_first_of(
">");
395 while (tagBeg != string::npos && tagBeg < tagEnd) {
401 tag = lineClean.substr(tagBeg + 1, tagEnd - tagBeg - 1);
402 istringstream getfirst(tag);
407 tagBeg = lineClean.find_first_of(
"<",tagEnd);
408 tagEnd = lineClean.find_first_of(
">",tagBeg+1);
414 if (tag ==
"init")
break;
418 else if (tag ==
"/header") {
423 }
else if (tag[0] !=
'/') {
424 keyVec.push_back(tag);
429 }
else if (tag ==
"/" + keyVec.back()) {
435 }
else if (keyVec.size() >= 2
436 && tag ==
"/" + keyVec[keyVec.size()-2]) {
437 infoPtr->errorMsg(
"Warning in LHAup::setInitLHEF:"
438 " corrupt LHEF end tag",keyVec.back());
450 if (tag ==
"init")
break;
458 if (keyVec.empty()) key =
"base";
459 else key = keyVec[0];
460 for (
size_t i = 1; i < keyVec.size(); i++)
461 key +=
"." + keyVec[i];
466 posBeg = line.find_first_not_of(
" \n\t\v\b\r\f\a",posBeg);
467 if (posBeg == string::npos || posBeg > posEnd)
continue;
470 headerMap[key] += line.substr(posBeg,posEnd - posBeg + 1) +
"\n";
475 if (tag ==
"init")
break;
480 for (map < string, string >::iterator it = headerMap.begin();
481 it != headerMap.end(); it++)
482 setInfoHeader(it->first, it->second);
487 if (!getline(is, line))
return false;
488 if (line.find(
"</init") != string::npos)
return true;
491 int idbmupA, idbmupB;
492 double ebmupA, ebmupB;
493 int pdfgupA, pdfgupB, pdfsupA, pdfsupB, idwtup, nprup;
494 istringstream getbms(line);
495 getbms >> idbmupA >> idbmupB >> ebmupA >> ebmupB >> pdfgupA
496 >> pdfgupB >> pdfsupA >> pdfsupB >> idwtup >> nprup;
497 if (!getbms)
return false;
498 setBeamA(idbmupA, ebmupA, pdfgupA, pdfsupA);
499 setBeamB(idbmupB, ebmupB, pdfgupB, pdfsupB);
503 double xsecup, xerrup, xmaxup;
507 for (
int ip = 0; ip < nprup; ++ip) {
508 if (!getline(is, line))
return false;
509 istringstream getpro(line);
510 getpro >> xsecup >> xerrup >> xmaxup >> lprup ;
511 if (!getpro)
return false;
512 addProcess(lprup, xsecup, xerrup, xmaxup);
513 xSecSumSave += xsecup;
514 xErrSumSave += pow2(xerrup);
516 xErrSumSave = sqrt(xErrSumSave);
528 bool LHAup::setNewEventLHEF(istream& is) {
533 if (!getline(is, line))
return false;
534 if (line.find_first_not_of(
" \n\t\v\b\r\f\a") != string::npos) {
535 istringstream getfirst(line);
537 if (!getfirst)
return false;
539 }
while (tag !=
"<event>" && tag !=
"<event");
542 if (!getline(is, line))
return false;
543 istringstream getpro(line);
544 getpro >> nupSave >> idprupSave >> xwgtupSave >> scalupSave
545 >> aqedupSave >> aqcdupSave;
546 if (!getpro)
return false;
549 particlesSave.clear();
550 particlesSave.push_back( LHAParticle() );
555 int idup, istup, mothup1, mothup2, icolup1, icolup2;
556 double pup1, pup2, pup3, pup4, pup5, vtimup, spinup;
557 for (
int ip = 1; ip <= nupSave; ++ip) {
558 if (!getline(is, line))
return false;
559 istringstream getall(line);
560 getall >> idup >> istup >> mothup1 >> mothup2 >> icolup1 >> icolup2
561 >> pup1 >> pup2 >> pup3 >> pup4 >> pup5 >> vtimup >> spinup;
562 if (!getall)
return false;
563 particlesSave.push_back( LHAParticle( idup, istup, mothup1, mothup2,
564 icolup1, icolup2, pup1, pup2, pup3, pup4, pup5, vtimup, spinup, -1.) );
568 id1InSave = particlesSave[1].idPart;
569 id2InSave = particlesSave[2].idPart;
570 x1InSave = (eBeamASave > 0.) ? particlesSave[1].ePart / eBeamASave : 0.;
571 x2InSave = (eBeamBSave > 0.) ? particlesSave[2].ePart / eBeamBSave : 0.;
576 getScaleShowers =
false;
578 if (!getline(is, line))
return false;
579 istringstream getinfo(line);
581 if (!getinfo)
return false;
584 if (tag ==
"#pdf" && !getPDFSave) {
585 getinfo >> id1pdfInSave >> id2pdfInSave >> x1pdfInSave >> x2pdfInSave
586 >> scalePDFInSave >> pdf1InSave >> pdf2InSave;
587 if (!getinfo)
return false;
591 }
else if (tag ==
"#scaleShowers") {
592 getinfo >> scaleShowersInSave[0] >> scaleShowersInSave[1];
593 if (!getinfo)
return false;
594 getScaleShowers =
true;
597 }
else if (tag ==
"#" && !getScale) {
599 for (
int i = 3; i < int(particlesSave.size()); ++i)
600 if (particlesSave[i].statusPart == 1) {
601 if ( !(getinfo >> scaleIn) )
return false;
602 particlesSave[i].scalePart = scaleIn;
604 if (!getinfo)
return false;
607 }
while (tag !=
"</event>" && tag !=
"</event");
611 id1pdfInSave = id1InSave;
612 id2pdfInSave = id2InSave;
613 x1pdfInSave = x1InSave;
614 x2pdfInSave = x2InSave;
629 bool LHAup::setOldEventLHEF() {
632 setProcess( idprupSave, xwgtupSave, scalupSave, aqedupSave, aqcdupSave);
633 for (
int ip = 1; ip <= nupSave; ++ip) addParticle( particlesSave[ip] );
634 setIdX( id1InSave, id2InSave, x1InSave, x2InSave);
635 setPdf( id1pdfInSave, id2pdfInSave, x1pdfInSave, x2pdfInSave,
636 scalePDFInSave, pdf1InSave, pdf2InSave, getPDFSave);
638 setScaleShowers( scaleShowersInSave[0], scaleShowersInSave[1]);
650 istream* LHAup::openFile(
const char *fn, ifstream &ifs) {
653 return (istream *) &ifs;
661 void LHAup::closeFile(istream *&is, ifstream &ifs) {
664 if (is && is != &ifs)
delete is;
668 if (ifs.is_open()) ifs.close();
679 bool LHAupLHEF::setInitLHEF( istream & isIn,
bool readHead ) {
682 if (!reader.isGood)
return false;
687 comments+=
"<LesHouchesEvents version =\"3.0\">\n";
688 comments+=
"<header>\n";
689 comments+=reader.headerComments;
690 comments+=
"</header>\n";
691 comments+=
"<init>\n";
692 comments+=reader.initComments;
693 comments+=
"</init>\n";
694 istringstream is1(comments);
695 bool useComments = (headerfile == NULL);
696 istream & iss((useComments ? is1 : isIn));
700 if ( useComments && !getline(iss,line))
return false;
701 if (!useComments && !getLine(line))
return false;
705 string headerTag = (readHead) ?
"<header>" :
"<init";
711 if ( useComments && !getline(iss,line))
return false;
712 if (!useComments && !getLine(line))
return false;
713 if (line.find_first_not_of(
" \n\t\v\b\r\f\a") != string::npos) {
714 istringstream getfirst(line);
716 if (!getfirst)
return false;
718 }
while (tag !=
"<init>" && tag !=
"<init" && tag != headerTag);
721 if (readHead ==
true && tag == headerTag) {
723 map < string, string > headerMap;
726 bool read =
true, newKey =
false;
727 int commentDepth = 0;
729 vector < string > keyVec;
731 if ( useComments && !getline(iss,line))
return false;
732 if (!useComments && !getLine(line))
return false;
736 if (commentDepth >= 1 && line.find(
"-->") != string::npos) {
738 size_t comBeg = line.find(
"-->")+2;
739 size_t comEnd = line.find_last_not_of(
"\n\t\v\b\r\f\a ");
740 if( comEnd == comBeg )
continue;
741 line = line.substr(comBeg,comEnd-comBeg+1);
743 if (commentDepth >= 1 && line.find(
"]]>") != string::npos)
746 if (commentDepth >= 1)
continue;
748 if (line.find(
"<!--") != string::npos) {
749 if (line.find(
"-->") == string::npos) commentDepth++;
750 int comBeg = line.find(
"<!--");
751 line = line.substr(0,comBeg);
754 if (line.find(
"<![cdata[") != string::npos
755 || line.find(
"<![CDATA[") != string::npos) {
756 if (line.find(
"]]>") == string::npos) commentDepth++;
757 int comBeg = line.find(
"<![");
758 line = line.substr(0,comBeg);
764 size_t firstTagEnd = line.find_first_of(
">");
765 size_t secondTagBegin = line.find_first_of(
"<",firstTagEnd);
766 vector<string> lineVec;
767 if (firstTagEnd != string::npos && secondTagBegin != string::npos) {
768 lineVec.push_back(line.substr(0,secondTagBegin));
769 lineVec.push_back(line.substr(secondTagBegin,
770 line.size()-secondTagBegin));
773 lineVec.push_back(line);
777 for (
int iVec=0; iVec<int(lineVec.size()); ++iVec) {
778 line = lineVec[iVec];
781 size_t posBeg = line.find_first_not_of(
" \n\t\v\b\r\f\a");
782 size_t posEnd = line.find_last_not_of(
" \n\t\v\b\r\f\a");
783 string lineClean =
" ";
784 if (posBeg != string::npos && posEnd != string::npos && posBeg
786 lineClean = line.substr(posBeg, posEnd - posBeg + 1);
788 posEnd = lineClean.size();
793 if (lineClean ==
" " || posBeg >= posEnd)
continue;
796 size_t tagBeg = lineClean.find_first_of(
"<");
797 size_t tagEnd = lineClean.find_first_of(
">");
799 while (tagBeg != string::npos && tagBeg < tagEnd) {
805 tag = lineClean.substr(tagBeg + 1, tagEnd - tagBeg - 1);
806 istringstream getfirst(tag);
811 tagBeg = lineClean.find_first_of(
"<",tagEnd);
812 tagEnd = lineClean.find_first_of(
">",tagBeg+1);
818 if (tag ==
"init")
break;
822 else if (tag ==
"/header") {
827 }
else if (tag[0] !=
'/') {
828 keyVec.push_back(tag);
833 }
else if (tag ==
"/" + keyVec.back()) {
839 }
else if (keyVec.size() >= 2
840 && tag ==
"/" + keyVec[keyVec.size()-2]) {
841 infoPtr->errorMsg(
"Warning in LHAupLHEF::setInitLHEF:"
842 " corrupt LHEF end tag",keyVec.back());
854 if (tag ==
"init")
break;
862 if (keyVec.empty()) key =
"base";
863 else key = keyVec[0];
864 for (
size_t i = 1; i < keyVec.size(); i++)
865 key +=
"." + keyVec[i];
870 posBeg = line.find_first_not_of(
" \n\t\v\b\r\f\a",posBeg);
871 if (posBeg == string::npos || posBeg > posEnd)
continue;
874 headerMap[key] += line.substr(posBeg,posEnd - posBeg + 1) +
"\n";
879 if (tag ==
"init")
break;
884 for (map < string, string >::iterator it = headerMap.begin();
885 it != headerMap.end(); it++)
886 setInfoHeader(it->first, it->second);
891 int idbmupA, idbmupB;
892 double ebmupA, ebmupB;
893 int pdfgupA, pdfgupB, pdfsupA, pdfsupB, idwtup, nprup;
895 idbmupA = reader.heprup.IDBMUP.first;
896 idbmupB = reader.heprup.IDBMUP.second;
897 ebmupA = reader.heprup.EBMUP.first;
898 ebmupB = reader.heprup.EBMUP.second;
899 pdfgupA = reader.heprup.PDFGUP.first;
900 pdfgupB = reader.heprup.PDFGUP.first;
901 pdfsupA = reader.heprup.PDFSUP.first;
902 pdfsupB = reader.heprup.PDFSUP.second;
903 idwtup = reader.heprup.IDWTUP;
904 nprup = reader.heprup.NPRUP;
906 setBeamA(idbmupA, ebmupA, pdfgupA, pdfsupA);
907 setBeamB(idbmupB, ebmupB, pdfgupB, pdfsupB);
911 double xsecup, xerrup, xmaxup;
915 infoPtr->sigmaLHEFSave.resize(0);
916 for (
int ip = 0; ip < nprup; ++ip) {
917 xsecup = reader.heprup.XSECUP[ip];
918 xerrup = reader.heprup.XERRUP[ip];
919 xmaxup = reader.heprup.XMAXUP[ip];
920 lprup = reader.heprup.LPRUP[ip];
921 addProcess(lprup, xsecup, xerrup, xmaxup);
922 xSecSumSave += xsecup;
923 xErrSumSave += pow(xerrup,2);
924 infoPtr->sigmaLHEFSave.push_back(xsecup);
926 xErrSumSave = sqrt(xErrSumSave);
929 infoPtr->setLHEF3InitInfo();
930 if (reader.version > 1) {
931 infoPtr->setLHEF3InitInfo( reader.version,
932 &reader.heprup.initrwgt, &(reader.heprup.generators),
933 &(reader.heprup.weightgroups), &(reader.heprup.weights),
945 bool LHAupLHEF::setNewEventLHEF() {
948 if(!reader.readEvent())
return false;
951 nupSave = reader.hepeup.NUP;
952 idprupSave = reader.hepeup.IDPRUP;
953 xwgtupSave = reader.hepeup.XWGTUP;
954 scalupSave = reader.hepeup.SCALUP;
955 aqedupSave = reader.hepeup.AQEDUP;
956 aqcdupSave = reader.hepeup.AQCDUP;
959 particlesSave.clear();
965 int idup, istup, mothup1, mothup2, icolup1, icolup2;
966 double pup1, pup2, pup3, pup4, pup5, vtimup, spinup;
967 for (
int i = 0; i < reader.hepeup.NUP; ++i ) {
969 idup = reader.hepeup.IDUP[i];
970 istup = reader.hepeup.ISTUP[i];
971 mothup1 = reader.hepeup.MOTHUP[i].first;
972 mothup2 = reader.hepeup.MOTHUP[i].second;
973 icolup1 = reader.hepeup.ICOLUP[i].first;
974 icolup2 = reader.hepeup.ICOLUP[i].second;
975 pup1 = reader.hepeup.PUP[i][0];
976 pup2 = reader.hepeup.PUP[i][1];
977 pup3 = reader.hepeup.PUP[i][2];
978 pup4 = reader.hepeup.PUP[i][3];
979 pup5 = reader.hepeup.PUP[i][4];
980 vtimup = reader.hepeup.VTIMUP[i];
981 spinup = reader.hepeup.SPINUP[i];
983 icolup1, icolup2, pup1, pup2, pup3, pup4, pup5, vtimup, spinup, -1.) );
987 id1InSave = particlesSave[1].idPart;
988 id2InSave = particlesSave[2].idPart;
989 x1InSave = (eBeamA() > 0.) ? particlesSave[1].ePart / eBeamA() : 0.;
990 x2InSave = (eBeamB() > 0.) ? particlesSave[2].ePart / eBeamB() : 0.;
993 std::string line, tag;
994 std::stringstream ss(reader.eventComments);
996 getScale = (setScalesFromLHEF && reader.version == 1) ?
false :
true;
997 getScaleShowers =
false;
998 while (getline(ss, line)) {
999 istringstream getinfo(line);
1001 if (!getinfo)
break;
1003 if (tag ==
"#pdf" && !getPDFSave) {
1004 getinfo >> id1pdfInSave >> id2pdfInSave >> x1pdfInSave >> x2pdfInSave
1005 >> scalePDFInSave >> pdf1InSave >> pdf2InSave;
1006 if (!getinfo)
return false;
1009 }
else if (tag ==
"#scaleShowers") {
1010 getinfo >> scaleShowersInSave[0] >> scaleShowersInSave[1];
1011 if (!getinfo)
return false;
1012 getScaleShowers =
true;
1014 }
else if (tag ==
"#" && !getScale) {
1016 for (
int i = 3; i < int(particlesSave.size()); ++i)
1017 if (particlesSave[i].statusPart == 1) {
1018 if ( !(getinfo >> scaleIn) )
return false;
1019 particlesSave[i].scalePart = scaleIn;
1021 if (!getinfo)
return false;
1027 if ( setScalesFromLHEF && reader.version > 1 ){
1028 for ( map<string,double>::const_iterator
1029 it = reader.hepeup.scalesSave.attributes.begin();
1030 it != reader.hepeup.scalesSave.attributes.end(); ++it ) {
1031 if ( it->first.find_last_of(
"_") != string::npos) {
1032 unsigned iFound = it->first.find_last_of(
"_") + 1;
1033 int iPos = atoi(it->first.substr(iFound).c_str());
1035 if ( iPos <
int(particlesSave.size())
1036 && particlesSave[iPos].statusPart == 1)
1037 particlesSave[iPos].scalePart = it->second;
1044 id1pdfInSave = id1InSave;
1045 id2pdfInSave = id2InSave;
1046 x1pdfInSave = x1InSave;
1047 x2pdfInSave = x2InSave;
1048 scalePDFInSave = 0.;
1054 infoPtr->setLHEF3EventInfo();
1056 if (reader.version > 1) {
1057 infoPtr->setLHEF3EventInfo( &reader.hepeup.attributes,
1058 &reader.hepeup.weights_detailed, &reader.hepeup.weights_compressed,
1059 &reader.hepeup.scalesSave, &reader.hepeup.weightsSave,
1060 &reader.hepeup.rwgtSave, reader.weights_detailed_vector(),
1061 reader.weightnames_detailed_vector(),
1062 reader.eventComments, reader.hepeup.XWGTUP);
1065 infoPtr->setLHEF3EventInfo( &reader.hepeup.attributes, 0, 0, 0, 0, 0,
1066 vector<double>(), vector<string>(),
"", reader.hepeup.XWGTUP);
1082 LHAupPlugin::LHAupPlugin(
string nameIn, Pythia *pythiaPtr) :
1083 LHAup(), lhaPtr(nullptr), libPtr(nullptr), name(nameIn) {
1086 if (infoPtr !=
nullptr)
1087 libPtr =
const_cast<Info&
>(pythiaPtr->info).plugin(name);
1088 else libPtr = make_shared<Plugin>(name);
1089 if (!libPtr->isLoaded())
return;
1092 NewLHAup* newLHAup = (NewLHAup*)libPtr->symbol(
"newLHAup");
1093 if (!newLHAup)
return;
1094 lhaPtr = newLHAup(pythiaPtr);
1102 LHAupPlugin::~LHAupPlugin() {
1105 if (lhaPtr ==
nullptr || !libPtr->isLoaded())
return;
1106 DeleteLHAup* deleteLHAup =
1107 (DeleteLHAup*)libPtr->symbol(
"deleteLHAup");
1108 if (deleteLHAup) deleteLHAup(lhaPtr);
1120 bool LHAupFromPYTHIA8::setInit() {
1123 int idbmupA = infoPtr->idA();
1124 int idbmupB = infoPtr->idB();
1125 double ebmupA = infoPtr->eA();
1126 double ebmupB = infoPtr->eB();
1131 setBeamA(idbmupA, ebmupA, pdfgupA, pdfsupA);
1132 setBeamB(idbmupB, ebmupB, pdfgupB, pdfsupB);
1136 setStrategy(idwtup);
1143 addProcess(lprup, xsecup, xerrup, xmaxup);
1154 bool LHAupFromPYTHIA8::setEvent(
int) {
1160 double xwgtup = infoPtr->weight();
1161 double scalup = infoPtr->QRen();
1162 double aqedup = infoPtr->alphaEM();
1163 double aqcdup = infoPtr->alphaS();
1164 setProcess(idprup, xwgtup, scalup, aqedup, aqcdup);
1168 int nup = processPtr->size() - 3;
1170 int idup, statusup, istup, mothup1, mothup2, icolup1, icolup2;
1171 double pup1, pup2, pup3, pup4, pup5, vtimup, spinup;
1172 for (
int ip = 1; ip <= nup; ++ip) {
1173 Particle& particle = (*processPtr)[ip + 2];
1174 idup = particle.id();
1176 statusup = particle.status();
1177 if (statusup == -21) istup = -1;
1178 else if (statusup < 0) istup = 2;
1180 mothup1 = max(0, particle.mother1() - 2);
1181 mothup2 = max(0, particle.mother2() - 2);
1182 icolup1 = particle.col();
1183 icolup2 = particle.acol();
1184 pup1 = particle.px();
1185 pup2 = particle.py();
1186 pup3 = particle.pz();
1187 pup4 = particle.e();
1188 pup5 = particle.m();
1189 vtimup = particle.tau();
1190 spinup = particle.pol();
1191 addParticle(idup, istup, mothup1, mothup2, icolup1, icolup2,
1192 pup1, pup2, pup3, pup4, pup5, vtimup, spinup, -1.) ;
1193 if (statusup == -21) ++n21;
1197 int id1up = infoPtr->id1();
1198 int id2up = infoPtr->id2();
1199 double x1up = infoPtr->x1();
1200 double x2up = infoPtr->x2();
1201 setIdX( id1up, id2up, x1up, x2up);
1204 int id1pdfup = infoPtr->id1pdf();
1205 int id2pdfup = infoPtr->id2pdf();
1206 double x1pdfup = infoPtr->x1pdf();
1207 double x2pdfup = infoPtr->x2pdf();
1208 double scalePDFup = infoPtr->QFac();
1209 double pdf1up = infoPtr->pdf1();
1210 double pdf2up = infoPtr->pdf2();
1211 setPdf(id1pdfup, id2pdfup, x1pdfup, x2pdfup, scalePDFup, pdf1up,
1215 if (n21 == 4) setScaleShowers( processPtr->scale(),
1216 processPtr->scaleSecond() );
1227 bool LHAupFromPYTHIA8::updateSigma() {
1230 double sigGen = CONVERTMB2PB * infoPtr->sigmaGen();
1231 double sigErr = CONVERTMB2PB * infoPtr->sigmaErr();
1248 bool LHEF3FromPythia8::openLHEF(
string fileNameIn) {
1251 fileName = fileNameIn;
1252 const char* cstring = fileName.c_str();
1253 osLHEF.open(cstring, ios::out | ios::trunc);
1255 cout <<
"Error in LHAup::openLHEF: could not open file "
1256 << fileName << endl;
1268 bool LHEF3FromPythia8::setInit() {
1271 writer.headerStream.str(
"");
1272 writer.initStream.str(
"");
1273 writer.headerStream.clear();
1274 writer.initStream.clear();
1277 heprup.IDBMUP = make_pair(infoPtr->idA(), infoPtr->idB());
1280 heprup.EBMUP = make_pair(infoPtr->eA(),infoPtr->eB());
1284 heprup.PDFGUP = make_pair(0,0);
1288 heprup.PDFSUP = make_pair(0,0);
1299 vector<double> XSECUP;
1300 for (
int i=0; i < heprup.NPRUP; ++i)
1301 XSECUP.push_back(CONVERTMB2PB * (infoPtr->sigmaGen()));
1302 heprup.XSECUP = XSECUP;
1306 vector<double> XERRUP;
1307 for (
int i=0; i < heprup.NPRUP; ++i)
1308 XERRUP.push_back(CONVERTMB2PB * infoPtr->sigmaErr());
1309 heprup.XERRUP = XERRUP;
1312 vector<double> XMAXUP;
1313 for (
int i=0; i < heprup.NPRUP; ++i) XMAXUP.push_back(0.0);
1314 heprup.XMAXUP = XMAXUP;
1318 for (
int i=0; i < heprup.NPRUP; ++i) LPRUP.push_back(9999+i);
1319 heprup.LPRUP = LPRUP;
1322 if (infoPtr->initrwgt )
1323 heprup.initrwgt = *(infoPtr->initrwgt);
1326 if (infoPtr->generators)
1327 heprup.generators = *(infoPtr->generators);
1330 if (infoPtr->weightgroups)
1331 heprup.weightgroups = *(infoPtr->weightgroups);
1334 if (infoPtr->init_weights)
1335 heprup.weights = *(infoPtr->init_weights);
1347 stringstream setout;
1348 settingsPtr->writeFile(setout,
true);
1349 while ( getline(setout,line) )
1350 writer.headerBlock() << line <<
"\n";
1355 writer.heprup = heprup;
1366 bool LHEF3FromPythia8::setEvent(
int) {
1368 Event event = *eventPtr;
1376 for (
int i = 0; i < int(event.size()); ++i) {
1377 if ( event[i].status() == -22) ++hepeup.NUP;
1378 if ( event[i].isFinal()) ++hepeup.NUP;
1382 hepeup.IDPRUP = 9999;
1385 hepeup.XWGTUP = infoPtr->weight();
1391 hepeup.XPDWUP = make_pair(0,0);
1395 hepeup.SCALUP = eventPtr->scale();
1398 hepeup.AQEDUP = infoPtr->alphaEM();
1401 hepeup.AQCDUP = infoPtr->alphaS();
1406 for (
int i = 0; i < int( event.size()); ++i) {
1407 if ( event[i].mother1() == 1 && in1 == 0) in1 = i;
1408 if ( event[i].mother1() == 2 && in2 == 0) in2 = i;
1412 vector<int> hardResonances;
1413 for (
int i = 0; i < int(event.size()); ++i) {
1414 if ( event[i].status() != -22)
continue;
1415 if ( event[i].mother1() != 3)
continue;
1416 if ( event[i].mother2() != 4)
continue;
1417 hardResonances.push_back(i);
1421 vector<int> evolvedResonances;
1422 vector<pair<int,int> > evolvedDecayProducts;
1423 for (
int j = 0; j < int(hardResonances.size()); ++j) {
1424 for (
int i =
int(event.size())-1; i > 0; --i) {
1425 if ( i == hardResonances[j]
1426 || (event[i].mother1() ==
event[i].mother2()
1427 &&
event[i].isAncestor(hardResonances[j])) ) {
1428 evolvedResonances.push_back(i);
1429 evolvedDecayProducts.push_back(
1430 make_pair(event[i].daughter1(), event[i].daughter2()) );
1438 now.init(
"(dummy event)", particleDataPtr);
1454 hepeup.IDUP.push_back(event[in1].
id());
1455 hepeup.IDUP.push_back(event[in2].
id());
1456 hepeup.ISTUP.push_back(-1);
1457 hepeup.ISTUP.push_back(-1);
1458 hepeup.MOTHUP.push_back(make_pair(0,0));
1459 hepeup.MOTHUP.push_back(make_pair(0,0));
1460 hepeup.ICOLUP.push_back(make_pair(event[in1].col(),event[in1].acol()));
1461 hepeup.ICOLUP.push_back(make_pair(event[in2].col(),event[in2].acol()));
1465 p.push_back(event[in1].pz());
1466 p.push_back(event[in1].e());
1467 p.push_back(event[in1].m());
1468 hepeup.PUP.push_back(p);
1472 p.push_back(event[in2].pz());
1473 p.push_back(event[in2].e());
1474 p.push_back(event[in2].m());
1475 hepeup.PUP.push_back(p);
1477 hepeup.VTIMUP.push_back(event[in1].tau());
1478 hepeup.VTIMUP.push_back(event[in2].tau());
1479 hepeup.SPINUP.push_back(event[in1].pol());
1480 hepeup.SPINUP.push_back(event[in2].pol());
1482 now.append(event[in1]);
1483 now.append(event[in2]);
1486 for (
int j = 0; j < int(evolvedResonances.size()); ++j) {
1487 int i = evolvedResonances[j];
1488 hepeup.IDUP.push_back(event[i].
id());
1489 hepeup.ISTUP.push_back(2);
1490 hepeup.MOTHUP.push_back(make_pair(1,2));
1491 hepeup.ICOLUP.push_back(make_pair(event[i].col(),event[i].acol()));
1492 p.push_back(event[i].px());
1493 p.push_back(event[i].py());
1494 p.push_back(event[i].pz());
1495 p.push_back(event[i].e());
1496 p.push_back(event[i].m());
1497 hepeup.PUP.push_back(p);
1499 hepeup.VTIMUP.push_back(event[i].tau());
1500 hepeup.SPINUP.push_back(event[i].pol());
1501 now.append(event[i]);
1502 now.back().statusPos();
1510 if ( now[iDec].isFinal() && now[iDec].canDecay()
1511 && now[iDec].mayDecay() && now[iDec].isResonance() ) {
1513 int iD1 = now[iDec].daughter1();
1514 int iD2 = now[iDec].daughter2();
1517 if ( iD1 == 0 || iD2 == 0 )
continue;
1520 for (
int k = iD1; k <= iD2; ++k ) {
1521 Particle partNow =
event[k];
1522 hepeup.IDUP.push_back(partNow.id());
1523 hepeup.MOTHUP.push_back(make_pair(iDec,iDec));
1524 hepeup.ICOLUP.push_back(make_pair(partNow.col(),partNow.acol()));
1525 p.push_back(partNow.px());
1526 p.push_back(partNow.py());
1527 p.push_back(partNow.pz());
1528 p.push_back(partNow.e());
1529 p.push_back(partNow.m());
1530 hepeup.PUP.push_back(p);
1532 hepeup.VTIMUP.push_back(partNow.tau());
1533 hepeup.SPINUP.push_back(partNow.pol());
1534 now.append(partNow);
1535 if ( partNow.canDecay() && partNow.mayDecay() && partNow.isResonance()){
1536 now.back().statusPos();
1537 hepeup.ISTUP.push_back(2);
1539 hepeup.ISTUP.push_back(1);
1546 }
while (++iDec < now.size());
1549 for (
int i = 0; i < int(event.size()); ++i) {
1550 if (!event[i].isFinal())
continue;
1553 for (
int j = 0; j < int(evolvedDecayProducts.size()); ++j) {
1554 skip = ( i >= evolvedDecayProducts[j].first
1555 && i <= evolvedDecayProducts[j].second);
1558 for (
int j = 0; j < int(iSkip.size()); ++j) {
1559 skip = ( i == iSkip[j] );
1563 hepeup.IDUP.push_back(event[i].
id());
1564 hepeup.ISTUP.push_back(1);
1565 hepeup.MOTHUP.push_back(make_pair(1,2));
1566 hepeup.ICOLUP.push_back(make_pair(event[i].col(),event[i].acol()));
1567 p.push_back(event[i].px());
1568 p.push_back(event[i].py());
1569 p.push_back(event[i].pz());
1570 p.push_back(event[i].e());
1571 p.push_back(event[i].m());
1572 hepeup.PUP.push_back(p);
1574 hepeup.VTIMUP.push_back(event[i].tau());
1575 hepeup.SPINUP.push_back(event[i].pol());
1576 now.append(event[i]);
1580 hepeup.heprup = &heprup;
1583 if (infoPtr->weights_detailed)
1584 hepeup.weights_detailed = *(infoPtr->weights_detailed);
1587 if (infoPtr->weights_compressed)
1588 hepeup.weights_compressed = *(infoPtr->weights_compressed);
1591 if (infoPtr->scales)
1592 hepeup.scalesSave = *(infoPtr->scales);
1595 if (infoPtr->weights)
1596 hepeup.weightsSave = *(infoPtr->weights);
1600 hepeup.rwgtSave = *(infoPtr->rwgt);
1603 if (infoPtr->eventAttributes)
1604 hepeup.attributes = *(infoPtr->eventAttributes);
1609 writer.hepeup = hepeup;
1610 if (writeToFile) writer.writeEvent(&hepeup,pDigits);
1620 bool LHEF3FromPythia8::closeLHEF(
bool updateInit) {
1623 osLHEF <<
"</LesHouchesEvents>" << endl;
1628 const char* cstring = fileName.c_str();
1629 osLHEF.open(cstring, ios::in | ios::out);