9 #include "Pythia8/LesHouches.h"
26 const double LHAup::CONVERTMB2PB = 1e9;
32 void LHAup::listInit() {
35 cout <<
"\n -------- LHA initialization information ------------ \n";
38 cout << fixed << setprecision(3)
39 <<
"\n beam kind energy pdfgrp pdfset \n"
40 <<
" A " << setw(6) << idBeamASave
41 << setw(12) << eBeamASave
42 << setw(8) << pdfGroupBeamASave
43 << setw(8) << pdfSetBeamASave <<
"\n"
44 <<
" B " << setw(6) << idBeamBSave
45 << setw(12) << eBeamBSave
46 << setw(8) << pdfGroupBeamBSave
47 << setw(8) << pdfSetBeamBSave <<
"\n";
50 cout <<
"\n Event weighting strategy = " << setw(2)
51 << strategySave <<
"\n" ;
54 cout << scientific << setprecision(4)
55 <<
"\n Processes, with strategy-dependent cross section info \n"
56 <<
" number xsec (pb) xerr (pb) xmax (pb) \n" ;
57 for (
int ip = 0; ip < int(processes.size()); ++ip) {
58 cout << setw(8) << processes[ip].idProc
59 << setw(15) << processes[ip].xSecProc
60 << setw(15) << processes[ip].xErrProc
61 << setw(15) << processes[ip].xMaxProc <<
"\n";
65 cout <<
"\n -------- End LHA initialization information -------- \n";
73 void LHAup::listEvent() {
76 cout <<
"\n -------- LHA event information and listing -------------"
77 <<
"--------------------------------------------------------- \n";
80 cout << scientific << setprecision(4)
81 <<
"\n process = " << setw(8) << idProc
82 <<
" weight = " << setw(12) << weightProc
83 <<
" scale = " << setw(12) << scaleProc <<
" (GeV) \n"
85 <<
" alpha_em = " << setw(12) << alphaQEDProc
86 <<
" alpha_strong = " << setw(12) << alphaQCDProc <<
"\n";
89 cout << fixed << setprecision(3)
90 <<
"\n Participating Particles \n"
91 <<
" no id stat mothers colours p_x "
92 <<
"p_y p_z e m tau spin \n" ;
93 for (
int ip = 1; ip < int(particles.size()); ++ip) {
95 << setw(10) << particles[ip].idPart
96 << setw(5) << particles[ip].statusPart
97 << setw(6) << particles[ip].mother1Part
98 << setw(6) << particles[ip].mother2Part
99 << setw(6) << particles[ip].col1Part
100 << setw(6) << particles[ip].col2Part
101 << setw(11) << particles[ip].pxPart
102 << setw(11) << particles[ip].pyPart
103 << setw(11) << particles[ip].pzPart
104 << setw(11) << particles[ip].ePart
105 << setw(11) << particles[ip].mPart
106 << setw(8) << particles[ip].tauPart
107 << setw(8) << particles[ip].spinPart <<
"\n";
111 if (pdfIsSetSave) cout <<
"\n pdf: id1 =" << setw(5) << id1pdfSave
112 <<
" id2 =" << setw(5) << id2pdfSave
113 <<
" x1 =" << scientific << setw(10) << x1pdfSave
114 <<
" x2 =" << setw(10) << x2pdfSave
115 <<
" scalePDF =" << setw(10) << scalePDFSave
116 <<
" pdf1 =" << setw(10) << pdf1Save
117 <<
" pdf2 =" << setw(10) << pdf2Save <<
"\n";
120 cout <<
"\n -------- End LHA event information and listing ---------"
121 <<
"--------------------------------------------------------- \n";
129 bool LHAup::openLHEF(
string fileNameIn) {
132 fileName = fileNameIn;
133 const char* cstring = fileName.c_str();
134 osLHEF.open(cstring, ios::out | ios::trunc);
136 infoPtr->errorMsg(
"Error in LHAup::openLHEF:"
137 " could not open file", fileName);
143 strftime(dateNow,12,
"%d %b %Y",localtime(&t));
144 strftime(timeNow,9,
"%H:%M:%S",localtime(&t));
147 osLHEF <<
"<LesHouchesEvents version=\"1.0\">\n"
149 <<
" File written by Pythia8::LHAup on "
150 << dateNow <<
" at " << timeNow <<
"\n"
162 bool LHAup::initLHEF() {
165 osLHEF <<
"<init>\n" << scientific << setprecision(6)
166 <<
" " << idBeamASave <<
" " << idBeamBSave
167 <<
" " << eBeamASave <<
" " << eBeamBSave
168 <<
" " << pdfGroupBeamASave <<
" " << pdfGroupBeamBSave
169 <<
" " << pdfSetBeamASave <<
" " << pdfSetBeamBSave
170 <<
" " << strategySave <<
" " << processes.size() <<
"\n";
173 for (
int ip = 0; ip < int(processes.size()); ++ip)
174 osLHEF <<
" " << setw(13) << processes[ip].xSecProc
175 <<
" " << setw(13) << processes[ip].xErrProc
176 <<
" " << setw(13) << processes[ip].xMaxProc
177 <<
" " << setw(6) << processes[ip].idProc <<
"\n";
180 osLHEF <<
"</init>" << endl;
191 bool LHAup::eventLHEF(
bool verbose) {
197 osLHEF <<
"<event>\n" << scientific << setprecision(6)
198 <<
" " << setw(5) << particles.size() - 1
199 <<
" " << setw(5) << idProc
200 <<
" " << setw(13) << weightProc
201 <<
" " << setw(13) << scaleProc
202 <<
" " << setw(13) << alphaQEDProc
203 <<
" " << setw(13) << alphaQCDProc <<
"\n";
206 for (
int ip = 1; ip < int(particles.size()); ++ip) {
207 LHAParticle& ptNow = particles[ip];
208 osLHEF <<
" " << setw(8) << ptNow.idPart
209 <<
" " << setw(5) << ptNow.statusPart
210 <<
" " << setw(5) << ptNow.mother1Part
211 <<
" " << setw(5) << ptNow.mother2Part
212 <<
" " << setw(5) << ptNow.col1Part
213 <<
" " << setw(5) << ptNow.col2Part << setprecision(10)
214 <<
" " << setw(17) << ptNow.pxPart
215 <<
" " << setw(17) << ptNow.pyPart
216 <<
" " << setw(17) << ptNow.pzPart
217 <<
" " << setw(17) << ptNow.ePart
218 <<
" " << setw(17) << ptNow.mPart << setprecision(6);
219 if (ptNow.tauPart == 0.) osLHEF <<
" 0.";
220 else osLHEF <<
" " << setw(13) << ptNow.tauPart;
221 if (ptNow.spinPart == 9.) osLHEF <<
" 9.";
222 else osLHEF <<
" " << setw(13) << ptNow.spinPart;
227 if (pdfIsSetSave) osLHEF <<
"#pdf"
228 <<
" " << setw(4) << id1pdfSave
229 <<
" " << setw(4) << id2pdfSave
230 <<
" " << setw(13) << x1pdfSave
231 <<
" " << setw(13) << x2pdfSave
232 <<
" " << setw(13) << scalePDFSave
233 <<
" " << setw(13) << pdf1Save
234 <<
" " << setw(13) << pdf2Save <<
"\n";
240 osLHEF <<
"<event>\n" << scientific << setprecision(6)
241 << particles.size() - 1 <<
" " << idProc <<
" "
242 << weightProc <<
" " << scaleProc <<
" "
243 << alphaQEDProc <<
" " << alphaQCDProc <<
"\n";
246 for (
int ip = 1; ip < int(particles.size()); ++ip) {
247 LHAParticle& ptNow = particles[ip];
248 osLHEF << ptNow.idPart <<
" " << ptNow.statusPart
249 <<
" " << ptNow.mother1Part <<
" " << ptNow.mother2Part
250 <<
" " << ptNow.col1Part <<
" " << ptNow.col2Part
251 << setprecision(10) <<
" " << ptNow.pxPart
252 <<
" " << ptNow.pyPart <<
" " << ptNow.pzPart
253 <<
" " << ptNow.ePart <<
" " << ptNow.mPart
255 if (ptNow.tauPart == 0.) osLHEF <<
" 0.";
256 else osLHEF <<
" " << setw(13) << ptNow.tauPart;
257 if (ptNow.spinPart == 9.) osLHEF <<
" 9.";
258 else osLHEF <<
" " << setw(13) << ptNow.spinPart;
263 if (pdfIsSetSave) osLHEF <<
"#pdf" <<
" " << id1pdfSave
264 <<
" " << id2pdfSave <<
" " << x1pdfSave <<
" " << x2pdfSave
265 <<
" " << scalePDFSave <<
" " << pdf1Save <<
" " << pdf2Save
270 osLHEF <<
"</event>" << endl;
279 bool LHAup::closeLHEF(
bool updateInit) {
282 osLHEF <<
"</LesHouchesEvents>" << endl;
287 const char* cstring = fileName.c_str();
288 osLHEF.open(cstring, ios::in | ios::out);
291 osLHEF <<
"<LesHouchesEvents version=\"1.0\">\n"
293 <<
" File written by Pythia8::LHAup on "
294 << dateNow <<
" at " << timeNow <<
"\n"
311 bool LHAup::setInitLHEF(istream& is,
bool readHeaders) {
315 if (!getline(is, line))
return false;
316 if (line.find(
"<LesHouchesEvents") == string::npos)
return false;
317 if (line.find(
"version=\"1.0\"" ) == string::npos )
return false;
321 string headerTag = (readHeaders) ?
"<header>" :
"<init";
327 if (!getline(is, line))
return false;
328 if (line.find_first_not_of(
" \n\t\v\b\r\f\a") != string::npos) {
329 istringstream getfirst(line);
331 if (!getfirst)
return false;
333 }
while (tag !=
"<init>" && tag !=
"<init" && tag != headerTag);
336 if (readHeaders ==
true && tag == headerTag) {
338 map < string, string > headerMap;
341 bool read =
true, newKey =
false;
343 vector < string > keyVec;
346 if (!getline(is, line))
return false;
351 size_t firstTagEnd = line.find_first_of(
">");
352 size_t secondTagBegin = line.find_first_of(
"<",firstTagEnd);
353 vector<string> lineVec;
354 if (firstTagEnd != string::npos && secondTagBegin != string::npos) {
355 lineVec.push_back(line.substr(0,secondTagBegin));
356 lineVec.push_back(line.substr(secondTagBegin,
357 line.size()-secondTagBegin));
360 lineVec.push_back(line);
364 for (
int iVec=0; iVec<int(lineVec.size()); ++iVec) {
365 line = lineVec[iVec];
368 size_t posBeg = line.find_first_not_of(
" \n\t\v\b\r\f\a");
369 size_t posEnd = line.find_last_not_of(
" \n\t\v\b\r\f\a");
370 string lineClean =
" ";
371 if (posBeg != string::npos && posEnd != string::npos && posBeg
373 lineClean = line.substr(posBeg, posEnd - posBeg + 1);
375 posEnd = lineClean.size();
379 if (lineClean ==
" " || posBeg >= posEnd)
continue;
382 size_t tagBeg = lineClean.find_first_of(
"<");
383 size_t tagEnd = lineClean.find_first_of(
">");
385 while (tagBeg != string::npos && tagBeg < tagEnd) {
391 tag = lineClean.substr(tagBeg + 1, tagEnd - tagBeg - 1);
392 istringstream getfirst(tag);
397 tagBeg = lineClean.find_first_of(
"<",tagEnd);
398 tagEnd = lineClean.find_first_of(
">",tagBeg+1);
404 if (tag ==
"init")
break;
408 else if (tag ==
"/header") {
413 }
else if (tag[0] !=
'/') {
414 keyVec.push_back(tag);
419 }
else if (tag ==
"/" + keyVec.back()) {
425 }
else if (keyVec.size() >= 2
426 && tag ==
"/" + keyVec[keyVec.size()-2]) {
427 infoPtr->errorMsg(
"Warning in LHAup::setInitLHEF:"
428 " corrupt LHEF end tag",keyVec.back());
440 if (tag ==
"init")
break;
448 if (keyVec.empty()) key =
"base";
449 else key = keyVec[0];
450 for (
size_t i = 1; i < keyVec.size(); i++)
451 key +=
"." + keyVec[i];
456 posBeg = line.find_first_not_of(
" \n\t\v\b\r\f\a",posBeg);
457 if (posBeg == string::npos || posBeg > posEnd)
continue;
460 headerMap[key] += line.substr(posBeg,posEnd - posBeg + 1) +
"\n";
465 if (tag ==
"init")
break;
470 for (map < string, string >::iterator it = headerMap.begin();
471 it != headerMap.end(); it++)
472 setInfoHeader(it->first, it->second);
477 if (!getline(is, line))
return false;
478 if (line.find(
"</init") != string::npos)
return true;
481 int idbmupA, idbmupB;
482 double ebmupA, ebmupB;
483 int pdfgupA, pdfgupB, pdfsupA, pdfsupB, idwtup, nprup;
484 istringstream getbms(line);
485 getbms >> idbmupA >> idbmupB >> ebmupA >> ebmupB >> pdfgupA
486 >> pdfgupB >> pdfsupA >> pdfsupB >> idwtup >> nprup;
487 if (!getbms)
return false;
488 setBeamA(idbmupA, ebmupA, pdfgupA, pdfsupA);
489 setBeamB(idbmupB, ebmupB, pdfgupB, pdfsupB);
493 double xsecup, xerrup, xmaxup;
497 for (
int ip = 0; ip < nprup; ++ip) {
498 if (!getline(is, line))
return false;
499 istringstream getpro(line);
500 getpro >> xsecup >> xerrup >> xmaxup >> lprup ;
501 if (!getpro)
return false;
502 addProcess(lprup, xsecup, xerrup, xmaxup);
503 xSecSumSave += xsecup;
504 xErrSumSave += pow2(xerrup);
506 xErrSumSave = sqrt(xErrSumSave);
518 bool LHAup::setNewEventLHEF(istream& is) {
523 if (!getline(is, line))
return false;
524 if (line.find_first_not_of(
" \n\t\v\b\r\f\a") != string::npos) {
525 istringstream getfirst(line);
527 if (!getfirst)
return false;
529 }
while (tag !=
"<event>" && tag !=
"<event");
532 if (!getline(is, line))
return false;
533 istringstream getpro(line);
534 getpro >> nupSave >> idprupSave >> xwgtupSave >> scalupSave
535 >> aqedupSave >> aqcdupSave;
536 if (!getpro)
return false;
539 particlesSave.clear();
540 particlesSave.push_back( LHAParticle() );
545 int idup, istup, mothup1, mothup2, icolup1, icolup2;
546 double pup1, pup2, pup3, pup4, pup5, vtimup, spinup;
547 for (
int ip = 1; ip <= nupSave; ++ip) {
548 if (!getline(is, line))
return false;
549 istringstream getall(line);
550 getall >> idup >> istup >> mothup1 >> mothup2 >> icolup1 >> icolup2
551 >> pup1 >> pup2 >> pup3 >> pup4 >> pup5 >> vtimup >> spinup;
552 if (!getall)
return false;
553 particlesSave.push_back( LHAParticle( idup, istup, mothup1, mothup2,
554 icolup1, icolup2, pup1, pup2, pup3, pup4, pup5, vtimup, spinup, -1.) );
558 id1InSave = particlesSave[1].idPart;
559 id2InSave = particlesSave[2].idPart;
560 x1InSave = (eBeamASave > 0.) ? particlesSave[1].ePart / eBeamASave : 0.;
561 x2InSave = (eBeamBSave > 0.) ? particlesSave[2].ePart / eBeamBSave : 0.;
567 if (!getline(is, line))
return false;
568 istringstream getinfo(line);
570 if (!getinfo)
return false;
573 if (tag ==
"#pdf" && !getPDFSave) {
574 getinfo >> id1pdfInSave >> id2pdfInSave >> x1pdfInSave >> x2pdfInSave
575 >> scalePDFInSave >> pdf1InSave >> pdf2InSave;
576 if (!getinfo)
return false;
580 }
else if (tag ==
"#" && !getScale) {
582 for (
int i = 3; i < int(particlesSave.size()); ++i)
583 if (particlesSave[i].statusPart == 1) {
584 if ( !(getinfo >> scaleIn) )
return false;
585 particlesSave[i].scalePart = scaleIn;
587 if (!getinfo)
return false;
590 }
while (tag !=
"</event>" && tag !=
"</event");
594 id1pdfInSave = id1InSave;
595 id2pdfInSave = id2InSave;
596 x1pdfInSave = x1InSave;
597 x2pdfInSave = x2InSave;
612 bool LHAup::setOldEventLHEF() {
615 setProcess( idprupSave, xwgtupSave, scalupSave, aqedupSave, aqcdupSave);
616 for (
int ip = 1; ip <= nupSave; ++ip) addParticle( particlesSave[ip] );
617 setIdX( id1InSave, id2InSave, x1InSave, x2InSave);
618 setPdf( id1pdfInSave, id2pdfInSave, x1pdfInSave, x2pdfInSave,
619 scalePDFInSave, pdf1InSave, pdf2InSave, getPDFSave);
631 istream* LHAup::openFile(
const char *fn, ifstream &ifs) {
634 return (istream *) &ifs;
642 void LHAup::closeFile(istream *&is, ifstream &ifs) {
645 if (is && is != &ifs)
delete is;
649 if (ifs.is_open()) ifs.close();
660 bool LHAupLHEF::setInitLHEF( istream & isIn,
bool readHead ) {
663 if (!reader.isGood)
return false;
668 comments+=
"<LesHouchesEvents version =\"3.0\">\n";
669 comments+=
"<header>\n";
670 comments+=reader.headerComments;
671 comments+=
"</header>\n";
672 comments+=
"<init>\n";
673 comments+=reader.initComments;
674 comments+=
"</init>\n";
675 istringstream is1(comments);
676 bool useComments = (headerfile == NULL);
677 istream & iss((useComments ? is1 : isIn));
681 if ( useComments && !getline(iss,line))
return false;
682 if (!useComments && !getLine(line))
return false;
686 string headerTag = (readHead) ?
"<header>" :
"<init";
692 if ( useComments && !getline(iss,line))
return false;
693 if (!useComments && !getLine(line))
return false;
694 if (line.find_first_not_of(
" \n\t\v\b\r\f\a") != string::npos) {
695 istringstream getfirst(line);
697 if (!getfirst)
return false;
699 }
while (tag !=
"<init>" && tag !=
"<init" && tag != headerTag);
702 if (readHead ==
true && tag == headerTag) {
704 map < string, string > headerMap;
707 bool read =
true, newKey =
false;
708 int commentDepth = 0;
710 vector < string > keyVec;
712 if ( useComments && !getline(iss,line))
return false;
713 if (!useComments && !getLine(line))
return false;
717 if (commentDepth >= 1 && line.find(
"-->") != string::npos) {
719 size_t comBeg = line.find(
"-->")+2;
720 size_t comEnd = line.find_last_not_of(
"\n\t\v\b\r\f\a ");
721 if( comEnd == comBeg )
continue;
722 line = line.substr(comBeg,comEnd-comBeg+1);
724 if (commentDepth >= 1 && line.find(
"]]>") != string::npos)
727 if (commentDepth >= 1)
continue;
729 if (line.find(
"<!--") != string::npos) {
730 if (line.find(
"-->") == string::npos) commentDepth++;
731 int comBeg = line.find(
"<!--");
732 line = line.substr(0,comBeg);
735 if (line.find(
"<![cdata[") != string::npos
736 || line.find(
"<![CDATA[") != string::npos) {
737 if (line.find(
"]]>") == string::npos) commentDepth++;
738 int comBeg = line.find(
"<![");
739 line = line.substr(0,comBeg);
745 size_t firstTagEnd = line.find_first_of(
">");
746 size_t secondTagBegin = line.find_first_of(
"<",firstTagEnd);
747 vector<string> lineVec;
748 if (firstTagEnd != string::npos && secondTagBegin != string::npos) {
749 lineVec.push_back(line.substr(0,secondTagBegin));
750 lineVec.push_back(line.substr(secondTagBegin,
751 line.size()-secondTagBegin));
754 lineVec.push_back(line);
758 for (
int iVec=0; iVec<int(lineVec.size()); ++iVec) {
759 line = lineVec[iVec];
762 size_t posBeg = line.find_first_not_of(
" \n\t\v\b\r\f\a");
763 size_t posEnd = line.find_last_not_of(
" \n\t\v\b\r\f\a");
764 string lineClean =
" ";
765 if (posBeg != string::npos && posEnd != string::npos && posBeg
767 lineClean = line.substr(posBeg, posEnd - posBeg + 1);
769 posEnd = lineClean.size();
774 if (lineClean ==
" " || posBeg >= posEnd)
continue;
777 size_t tagBeg = lineClean.find_first_of(
"<");
778 size_t tagEnd = lineClean.find_first_of(
">");
780 while (tagBeg != string::npos && tagBeg < tagEnd) {
786 tag = lineClean.substr(tagBeg + 1, tagEnd - tagBeg - 1);
787 istringstream getfirst(tag);
792 tagBeg = lineClean.find_first_of(
"<",tagEnd);
793 tagEnd = lineClean.find_first_of(
">",tagBeg+1);
799 if (tag ==
"init")
break;
803 else if (tag ==
"/header") {
808 }
else if (tag[0] !=
'/') {
809 keyVec.push_back(tag);
814 }
else if (tag ==
"/" + keyVec.back()) {
820 }
else if (keyVec.size() >= 2
821 && tag ==
"/" + keyVec[keyVec.size()-2]) {
822 infoPtr->errorMsg(
"Warning in LHAupLHEF::setInitLHEF:"
823 " corrupt LHEF end tag",keyVec.back());
835 if (tag ==
"init")
break;
843 if (keyVec.empty()) key =
"base";
844 else key = keyVec[0];
845 for (
size_t i = 1; i < keyVec.size(); i++)
846 key +=
"." + keyVec[i];
851 posBeg = line.find_first_not_of(
" \n\t\v\b\r\f\a",posBeg);
852 if (posBeg == string::npos || posBeg > posEnd)
continue;
855 headerMap[key] += line.substr(posBeg,posEnd - posBeg + 1) +
"\n";
860 if (tag ==
"init")
break;
865 for (map < string, string >::iterator it = headerMap.begin();
866 it != headerMap.end(); it++)
867 setInfoHeader(it->first, it->second);
872 int idbmupA, idbmupB;
873 double ebmupA, ebmupB;
874 int pdfgupA, pdfgupB, pdfsupA, pdfsupB, idwtup, nprup;
876 idbmupA = reader.heprup.IDBMUP.first;
877 idbmupB = reader.heprup.IDBMUP.second;
878 ebmupA = reader.heprup.EBMUP.first;
879 ebmupB = reader.heprup.EBMUP.second;
880 pdfgupA = reader.heprup.PDFGUP.first;
881 pdfgupB = reader.heprup.PDFGUP.first;
882 pdfsupA = reader.heprup.PDFSUP.first;
883 pdfsupB = reader.heprup.PDFSUP.second;
884 idwtup = reader.heprup.IDWTUP;
885 nprup = reader.heprup.NPRUP;
887 setBeamA(idbmupA, ebmupA, pdfgupA, pdfsupA);
888 setBeamB(idbmupB, ebmupB, pdfgupB, pdfsupB);
892 double xsecup, xerrup, xmaxup;
896 infoPtr->sigmaLHEFSave.resize(0);
897 for (
int ip = 0; ip < nprup; ++ip) {
898 xsecup = reader.heprup.XSECUP[ip];
899 xerrup = reader.heprup.XERRUP[ip];
900 xmaxup = reader.heprup.XMAXUP[ip];
901 lprup = reader.heprup.LPRUP[ip];
902 addProcess(lprup, xsecup, xerrup, xmaxup);
903 xSecSumSave += xsecup;
904 xErrSumSave += pow(xerrup,2);
905 infoPtr->sigmaLHEFSave.push_back(xsecup);
907 xErrSumSave = sqrt(xErrSumSave);
910 infoPtr->setLHEF3InitInfo();
911 if (reader.version > 1) {
912 infoPtr->setLHEF3InitInfo( reader.version,
913 &reader.heprup.initrwgt, &(reader.heprup.generators),
914 &(reader.heprup.weightgroups), &(reader.heprup.weights),
926 bool LHAupLHEF::setNewEventLHEF() {
929 if(!reader.readEvent())
return false;
932 nupSave = reader.hepeup.NUP;
933 idprupSave = reader.hepeup.IDPRUP;
934 xwgtupSave = reader.hepeup.XWGTUP;
935 scalupSave = reader.hepeup.SCALUP;
936 aqedupSave = reader.hepeup.AQEDUP;
937 aqcdupSave = reader.hepeup.AQCDUP;
940 particlesSave.clear();
946 int idup, istup, mothup1, mothup2, icolup1, icolup2;
947 double pup1, pup2, pup3, pup4, pup5, vtimup, spinup;
948 for (
int i = 0; i < reader.hepeup.NUP; ++i ) {
950 idup = reader.hepeup.IDUP[i];
951 istup = reader.hepeup.ISTUP[i];
952 mothup1 = reader.hepeup.MOTHUP[i].first;
953 mothup2 = reader.hepeup.MOTHUP[i].second;
954 icolup1 = reader.hepeup.ICOLUP[i].first;
955 icolup2 = reader.hepeup.ICOLUP[i].second;
956 pup1 = reader.hepeup.PUP[i][0];
957 pup2 = reader.hepeup.PUP[i][1];
958 pup3 = reader.hepeup.PUP[i][2];
959 pup4 = reader.hepeup.PUP[i][3];
960 pup5 = reader.hepeup.PUP[i][4];
961 vtimup = reader.hepeup.VTIMUP[i];
962 spinup = reader.hepeup.SPINUP[i];
964 icolup1, icolup2, pup1, pup2, pup3, pup4, pup5, vtimup, spinup, -1.) );
968 id1InSave = particlesSave[1].idPart;
969 id2InSave = particlesSave[2].idPart;
970 x1InSave = (eBeamA() > 0.) ? particlesSave[1].ePart / eBeamA() : 0.;
971 x2InSave = (eBeamB() > 0.) ? particlesSave[2].ePart / eBeamB() : 0.;
974 std::string line, tag;
975 std::stringstream ss(reader.eventComments);
978 getScale = (setScalesFromLHEF && reader.version == 1) ?
false :
true;
979 while (getline(ss, line)) {
980 istringstream getinfo(line);
984 if (tag ==
"#pdf" && !getPDFSave) {
985 getinfo >> id1pdfInSave >> id2pdfInSave >> x1pdfInSave >> x2pdfInSave
986 >> scalePDFInSave >> pdf1InSave >> pdf2InSave;
987 if (!getinfo)
return false;
990 }
else if (tag ==
"#" && !getScale) {
992 for (
int i = 3; i < int(particlesSave.size()); ++i)
993 if (particlesSave[i].statusPart == 1) {
994 if ( !(getinfo >> scaleIn) )
return false;
995 particlesSave[i].scalePart = scaleIn;
997 if (!getinfo)
return false;
1003 if ( setScalesFromLHEF && reader.version > 1 ){
1004 for ( map<string,double>::const_iterator
1005 it = reader.hepeup.scalesSave.attributes.begin();
1006 it != reader.hepeup.scalesSave.attributes.end(); ++it ) {
1007 if ( it->first.find_last_of(
"_") != string::npos) {
1008 unsigned iFound = it->first.find_last_of(
"_") + 1;
1009 int iPos = atoi(it->first.substr(iFound).c_str());
1011 if ( iPos <
int(particlesSave.size())
1012 && particlesSave[iPos].statusPart == 1)
1013 particlesSave[iPos].scalePart = it->second;
1020 id1pdfInSave = id1InSave;
1021 id2pdfInSave = id2InSave;
1022 x1pdfInSave = x1InSave;
1023 x2pdfInSave = x2InSave;
1024 scalePDFInSave = 0.;
1030 infoPtr->setLHEF3EventInfo();
1032 if (reader.version > 1) {
1033 infoPtr->setLHEF3EventInfo( &reader.hepeup.attributes,
1034 &reader.hepeup.weights_detailed, &reader.hepeup.weights_compressed,
1035 &reader.hepeup.scalesSave, &reader.hepeup.weightsSave,
1036 &reader.hepeup.rwgtSave, reader.weights_detailed_vector(),
1037 reader.eventComments, reader.hepeup.XWGTUP);
1040 infoPtr->setLHEF3EventInfo( &reader.hepeup.attributes, 0, 0, 0, 0, 0,
1041 vector<double>(),
"", 1.0);
1057 bool LHAupFromPYTHIA8::setInit() {
1060 int idbmupA = infoPtr->idA();
1061 int idbmupB = infoPtr->idB();
1062 double ebmupA = infoPtr->eA();
1063 double ebmupB = infoPtr->eB();
1068 setBeamA(idbmupA, ebmupA, pdfgupA, pdfsupA);
1069 setBeamB(idbmupB, ebmupB, pdfgupB, pdfsupB);
1073 setStrategy(idwtup);
1080 addProcess(lprup, xsecup, xerrup, xmaxup);
1091 bool LHAupFromPYTHIA8::setEvent(
int) {
1097 double xwgtup = infoPtr->weight();
1098 double scalup = infoPtr->QRen();
1099 double aqedup = infoPtr->alphaEM();
1100 double aqcdup = infoPtr->alphaS();
1101 setProcess(idprup, xwgtup, scalup, aqedup, aqcdup);
1105 int nup = processPtr->size() - 3;
1106 int idup, statusup, istup, mothup1, mothup2, icolup1, icolup2;
1107 double pup1, pup2, pup3, pup4, pup5, vtimup, spinup;
1108 for (
int ip = 1; ip <= nup; ++ip) {
1109 Particle& particle = (*processPtr)[ip + 2];
1110 idup = particle.id();
1112 statusup = particle.status();
1113 if (ip < 3) istup = -1;
1114 else if (statusup < 0) istup = 2;
1116 mothup1 = max(0, particle.mother1() - 2);
1117 mothup2 = max(0, particle.mother2() - 2);
1118 icolup1 = particle.col();
1119 icolup2 = particle.acol();
1120 pup1 = particle.px();
1121 pup2 = particle.py();
1122 pup3 = particle.pz();
1123 pup4 = particle.e();
1124 pup5 = particle.m();
1125 vtimup = particle.tau();
1126 spinup = particle.pol();
1127 addParticle(idup, istup, mothup1, mothup2, icolup1, icolup2,
1128 pup1, pup2, pup3, pup4, pup5, vtimup, spinup, -1.) ;
1132 int id1up = infoPtr->id1();
1133 int id2up = infoPtr->id2();
1134 double x1up = infoPtr->x1();
1135 double x2up = infoPtr->x2();
1136 setIdX( id1up, id2up, x1up, x2up);
1139 int id1pdfup = infoPtr->id1pdf();
1140 int id2pdfup = infoPtr->id2pdf();
1141 double x1pdfup = infoPtr->x1pdf();
1142 double x2pdfup = infoPtr->x2pdf();
1143 double scalePDFup = infoPtr->QFac();
1144 double pdf1up = infoPtr->pdf1();
1145 double pdf2up = infoPtr->pdf2();
1146 setPdf(id1pdfup, id2pdfup, x1pdfup, x2pdfup, scalePDFup, pdf1up,
1158 bool LHAupFromPYTHIA8::updateSigma() {
1161 double sigGen = CONVERTMB2PB * infoPtr->sigmaGen();
1162 double sigErr = CONVERTMB2PB * infoPtr->sigmaErr();
1179 bool LHEF3FromPythia8::openLHEF(
string fileNameIn) {
1182 fileName = fileNameIn;
1183 const char* cstring = fileName.c_str();
1184 osLHEF.open(cstring, ios::out | ios::trunc);
1186 infoPtr->errorMsg(
"Error in LHAup::openLHEF:"
1187 " could not open file", fileName);
1199 bool LHEF3FromPythia8::setInit() {
1202 writer.headerStream.str(
"");
1203 writer.initStream.str(
"");
1204 writer.headerStream.clear();
1205 writer.initStream.clear();
1208 heprup.IDBMUP = make_pair(infoPtr->idA(), infoPtr->idB());
1211 heprup.EBMUP = make_pair(infoPtr->eA(),infoPtr->eB());
1215 heprup.PDFGUP = make_pair(0,0);
1219 heprup.PDFSUP = make_pair(0,0);
1230 vector<double> XSECUP;
1231 for (
int i=0; i < heprup.NPRUP; ++i)
1232 XSECUP.push_back(CONVERTMB2PB * infoPtr->sigmaGen());
1233 heprup.XSECUP = XSECUP;
1237 vector<double> XERRUP;
1238 for (
int i=0; i < heprup.NPRUP; ++i)
1239 XERRUP.push_back(CONVERTMB2PB * infoPtr->sigmaErr());
1240 heprup.XERRUP = XERRUP;
1243 vector<double> XMAXUP;
1244 for (
int i=0; i < heprup.NPRUP; ++i) XMAXUP.push_back(0.0);
1245 heprup.XMAXUP = XMAXUP;
1249 for (
int i=0; i < heprup.NPRUP; ++i) LPRUP.push_back(9999+i);
1250 heprup.LPRUP = LPRUP;
1253 if (infoPtr->initrwgt) heprup.initrwgt = *(infoPtr->initrwgt);
1256 if (infoPtr->generators) heprup.generators = *(infoPtr->generators);
1259 if (infoPtr->weightgroups) heprup.weightgroups = *(infoPtr->weightgroups);
1262 if (infoPtr->init_weights) heprup.weights = *(infoPtr->init_weights);
1274 stringstream setout;
1275 settingsPtr->writeFile(setout,
true);
1276 while ( getline(setout,line) )
1277 writer.headerBlock() << line <<
"\n";
1282 writer.heprup = heprup;
1293 bool LHEF3FromPythia8::setEvent(
int) {
1295 Event event = *eventPtr;
1303 for (
int i = 0; i < int(event.size()); ++i) {
1304 if ( event[i].status() == -22) ++hepeup.NUP;
1305 if ( event[i].isFinal()) ++hepeup.NUP;
1309 hepeup.IDPRUP = 9999;
1312 hepeup.XWGTUP = infoPtr->weight();
1318 hepeup.XPDWUP = make_pair(0,0);
1322 hepeup.SCALUP = eventPtr->scale();
1325 hepeup.AQEDUP = infoPtr->alphaEM();
1328 hepeup.AQCDUP = infoPtr->alphaS();
1333 for (
int i = 0; i < int( event.size()); ++i) {
1334 if ( event[i].mother1() == 1 && in1 == 0) in1 = i;
1335 if ( event[i].mother1() == 2 && in2 == 0) in2 = i;
1339 vector<int> hardResonances;
1340 for (
int i = 0; i < int(event.size()); ++i) {
1341 if ( event[i].status() != -22)
continue;
1342 if ( event[i].mother1() != 3)
continue;
1343 if ( event[i].mother2() != 4)
continue;
1344 hardResonances.push_back(i);
1348 vector<int> evolvedResonances;
1349 vector<pair<int,int> > evolvedDecayProducts;
1350 for (
int j = 0; j < int(hardResonances.size()); ++j) {
1351 for (
int i =
int(event.size())-1; i > 0; --i) {
1352 if ( i == hardResonances[j]
1353 || (event[i].mother1() ==
event[i].mother2()
1354 &&
event[i].isAncestor(hardResonances[j])) ) {
1355 evolvedResonances.push_back(i);
1356 evolvedDecayProducts.push_back(
1357 make_pair(event[i].daughter1(), event[i].daughter2()) );
1365 now.init(
"(dummy event)", particleDataPtr);
1381 hepeup.IDUP.push_back(event[in1].
id());
1382 hepeup.IDUP.push_back(event[in2].
id());
1383 hepeup.ISTUP.push_back(-1);
1384 hepeup.ISTUP.push_back(-1);
1385 hepeup.MOTHUP.push_back(make_pair(0,0));
1386 hepeup.MOTHUP.push_back(make_pair(0,0));
1387 hepeup.ICOLUP.push_back(make_pair(event[in1].col(),event[in1].acol()));
1388 hepeup.ICOLUP.push_back(make_pair(event[in2].col(),event[in2].acol()));
1392 p.push_back(event[in1].pz());
1393 p.push_back(event[in1].e());
1394 p.push_back(event[in1].m());
1395 hepeup.PUP.push_back(p);
1399 p.push_back(event[in2].pz());
1400 p.push_back(event[in2].e());
1401 p.push_back(event[in2].m());
1402 hepeup.PUP.push_back(p);
1404 hepeup.VTIMUP.push_back(event[in1].tau());
1405 hepeup.VTIMUP.push_back(event[in2].tau());
1406 hepeup.SPINUP.push_back(event[in1].pol());
1407 hepeup.SPINUP.push_back(event[in2].pol());
1409 now.append(event[in1]);
1410 now.append(event[in2]);
1413 for (
int j = 0; j < int(evolvedResonances.size()); ++j) {
1414 int i = evolvedResonances[j];
1415 hepeup.IDUP.push_back(event[i].
id());
1416 hepeup.ISTUP.push_back(2);
1417 hepeup.MOTHUP.push_back(make_pair(1,2));
1418 hepeup.ICOLUP.push_back(make_pair(event[i].col(),event[i].acol()));
1419 p.push_back(event[i].px());
1420 p.push_back(event[i].py());
1421 p.push_back(event[i].pz());
1422 p.push_back(event[i].e());
1423 p.push_back(event[i].m());
1424 hepeup.PUP.push_back(p);
1426 hepeup.VTIMUP.push_back(event[i].tau());
1427 hepeup.SPINUP.push_back(event[i].pol());
1428 now.append(event[i]);
1429 now.back().statusPos();
1437 if ( now[iDec].isFinal() && now[iDec].canDecay()
1438 && now[iDec].mayDecay() && now[iDec].isResonance() ) {
1440 int iD1 = now[iDec].daughter1();
1441 int iD2 = now[iDec].daughter2();
1444 if ( iD1 == 0 || iD2 == 0 )
continue;
1447 for (
int k = iD1; k <= iD2; ++k ) {
1448 Particle partNow =
event[k];
1449 hepeup.IDUP.push_back(partNow.id());
1450 hepeup.MOTHUP.push_back(make_pair(iDec,iDec));
1451 hepeup.ICOLUP.push_back(make_pair(partNow.col(),partNow.acol()));
1452 p.push_back(partNow.px());
1453 p.push_back(partNow.py());
1454 p.push_back(partNow.pz());
1455 p.push_back(partNow.e());
1456 p.push_back(partNow.m());
1457 hepeup.PUP.push_back(p);
1459 hepeup.VTIMUP.push_back(partNow.tau());
1460 hepeup.SPINUP.push_back(partNow.pol());
1461 now.append(partNow);
1462 if ( partNow.canDecay() && partNow.mayDecay() && partNow.isResonance()){
1463 now.back().statusPos();
1464 hepeup.ISTUP.push_back(2);
1466 hepeup.ISTUP.push_back(1);
1473 }
while (++iDec < now.size());
1476 for (
int i = 0; i < int(event.size()); ++i) {
1477 if (!event[i].isFinal())
continue;
1480 for (
int j = 0; j < int(evolvedDecayProducts.size()); ++j) {
1481 skip = ( i >= evolvedDecayProducts[j].first
1482 && i <= evolvedDecayProducts[j].second);
1485 for (
int j = 0; j < int(iSkip.size()); ++j) {
1486 skip = ( i == iSkip[j] );
1490 hepeup.IDUP.push_back(event[i].
id());
1491 hepeup.ISTUP.push_back(1);
1492 hepeup.MOTHUP.push_back(make_pair(1,2));
1493 hepeup.ICOLUP.push_back(make_pair(event[i].col(),event[i].acol()));
1494 p.push_back(event[i].px());
1495 p.push_back(event[i].py());
1496 p.push_back(event[i].pz());
1497 p.push_back(event[i].e());
1498 p.push_back(event[i].m());
1499 hepeup.PUP.push_back(p);
1501 hepeup.VTIMUP.push_back(event[i].tau());
1502 hepeup.SPINUP.push_back(event[i].pol());
1503 now.append(event[i]);
1507 hepeup.heprup = &heprup;
1510 if (infoPtr->weights_detailed)
1511 hepeup.weights_detailed = *(infoPtr->weights_detailed);
1514 if (infoPtr->weights_compressed)
1515 hepeup.weights_compressed = *(infoPtr->weights_compressed);
1518 if (infoPtr->scales) hepeup.scalesSave = *(infoPtr->scales);
1521 if (infoPtr->weights) hepeup.weightsSave = *(infoPtr->weights);
1524 if (infoPtr->rwgt) hepeup.rwgtSave = *(infoPtr->rwgt);
1527 if (infoPtr->eventAttributes)
1528 hepeup.attributes = *(infoPtr->eventAttributes);
1533 writer.hepeup = hepeup;
1534 if (writeToFile) writer.writeEvent(&hepeup,pDigits);
1544 bool LHEF3FromPythia8::closeLHEF(
bool updateInit) {
1547 osLHEF <<
"</LesHouchesEvents>" << endl;
1552 const char* cstring = fileName.c_str();
1553 osLHEF.open(cstring, ios::in | ios::out);