22 #ifndef Pythia8_GeneratorInput_H
23 #define Pythia8_GeneratorInput_H
26 #include "Pythia8/Pythia.h"
43 bool parse(
const string paramStr);
46 void extractRunParam(
string line);
49 bool haveParam(
const string ¶mIn) {
50 return (
params.find(paramIn) ==
params.end()) ?
false :
true; }
54 double getParam(
const string ¶mIn) {
55 return (haveParam(paramIn)) ?
params[paramIn] : 0.; }
56 int getParamAsInt(
const string ¶mIn) {
57 return (haveParam(paramIn)) ? int(
params[paramIn]) : 0.; }
65 void warnParamOverwrite(
const string ¶mIn,
double val);
68 static string trim(
string s);
77 static const double ZEROTHRESHOLD;
95 bool fileFound() {
return (isUnw != NULL); }
102 void printParticles();
107 bool addResonances();
110 bool rescaleMomenta();
113 string baseFN, parFN, unwFN;
116 double ebmupA, ebmupB;
121 vector<LHAParticle> myParticles;
124 static const bool LHADEBUG, LHADEBUGRESCALE;
125 static const double ZEROTHRESHOLD, EWARNTHRESHOLD, PTWARNTHRESHOLD,
145 bool initAfterBeams();
167 bool parse(
const string paramStr);
170 void extractRunParam(
string line);
173 bool haveParam(
const string ¶mIn) {
174 return (
params.find(paramIn) ==
params.end()) ?
false :
true; }
178 double getParam(
const string ¶mIn) {
179 return (haveParam(paramIn)) ?
params[paramIn] : 0.; }
180 int getParamAsInt(
const string ¶mIn) {
181 return (haveParam(paramIn)) ? int(
params[paramIn]) : 0.; }
189 void warnParamOverwrite(
const string ¶mIn,
double val);
192 static string trim(
string s);
195 map<string,double>
params;
201 static const double ZEROTHRESHOLD;
217 const double AlpgenPar::ZEROTHRESHOLD = 1e-10;
224 inline bool AlpgenPar::parse(
const string paramStr) {
233 stringstream paramStream(paramStr);
235 while (getline(paramStream, line)) {
238 if (line.find(
"run parameters") != string::npos) {
242 }
else if (line.find(
"end parameters") != string::npos) {
246 }
else if (block == 0) {
250 extractRunParam(line);
262 inline void AlpgenPar::extractRunParam(
string line) {
265 size_t idx = line.rfind(
"!");
266 if (idx == string::npos)
return;
267 string paramName = trim(line.substr(idx + 1));
268 string paramVal = trim(line.substr(0, idx));
269 istringstream iss(paramVal);
273 if (paramName ==
"hard process code") {
275 warnParamOverwrite(
"hpc", val);
279 }
else if (paramName.find(
"Crosssection") == 0) {
281 iss >> val >> xerrup;
282 warnParamOverwrite(
"xsecup", val);
283 warnParamOverwrite(
"xerrup", val);
285 params[
"xerrup"] = xerrup;
288 }
else if (paramName.find(
"unwtd events") == 0) {
290 iss >> nevent >> val;
291 warnParamOverwrite(
"nevent", val);
292 warnParamOverwrite(
"lum", val);
293 params[
"nevent"] = nevent;
297 }
else if (paramName.find(
",") != string::npos) {
301 istringstream issName(paramName);
302 while (getline(issName, paramNameNow,
',')) {
304 warnParamOverwrite(paramNameNow, val);
305 params[paramNameNow] = val;
311 iss >> paramIdx >> val;
312 warnParamOverwrite(paramName, val);
321 inline void AlpgenPar::printParams() {
324 cout << fixed << setprecision(3) << endl
325 <<
" *------- Alpgen parameters -------*" << endl;
326 for (map < string, double >::iterator it =
params.begin();
328 cout <<
" | " << left << setw(13) << it->first
329 <<
" | " << right << setw(13) << it->second
331 cout <<
" *-----------------------------------*" << endl;
338 inline void AlpgenPar::warnParamOverwrite(
const string ¶mIn,
double val) {
341 if (haveParam(paramIn) &&
342 abs(getParam(paramIn) - val) > ZEROTHRESHOLD) {
343 if (infoPtr) infoPtr->errorMsg(
"Warning in LHAupAlpgen::"
344 "warnParamOverwrite: overwriting existing parameter", paramIn);
352 inline string AlpgenPar::trim(
string s) {
356 if ((i = s.find_last_not_of(
" \t\r\n")) != string::npos)
357 s = s.substr(0, i + 1);
358 if ((i = s.find_first_not_of(
" \t\r\n")) != string::npos)
375 const bool LHAupAlpgen::LHADEBUG =
false;
378 const bool LHAupAlpgen::LHADEBUGRESCALE =
false;
381 const double LHAupAlpgen::ZEROTHRESHOLD = 1e-10;
384 const double LHAupAlpgen::EWARNTHRESHOLD = 3e-3;
385 const double LHAupAlpgen::PTWARNTHRESHOLD = 1e-3;
388 const double LHAupAlpgen::INCOMINGMIN = 1e-3;
394 LHAupAlpgen::LHAupAlpgen(
const char* baseFNin, Info* infoPtrIn)
395 : baseFN(baseFNin), alpgenPar(infoPtrIn), isUnw(NULL) {
398 if (infoPtrIn) setPtr(infoPtrIn);
402 istream* isPar = NULL;
406 parFN = baseFN +
"_unw.par.gz";
407 isPar = openFile(parFN.c_str(), ifsPar);
408 if (!ifsPar.is_open()) closeFile(isPar, ifsPar);
411 parFN = baseFN +
"_unw.par";
412 isPar = openFile(parFN.c_str(), ifsPar);
413 if (!ifsPar.is_open()) {
414 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::LHAupAlpgen: "
415 "cannot open parameter file", parFN);
416 closeFile(isPar, ifsPar);
422 string paramStr((std::istreambuf_iterator<char>(isPar->rdbuf())),
423 std::istreambuf_iterator<char>());
427 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::LHAupAlpgen: "
428 "cannot read parameter file", parFN);
431 closeFile(isPar, ifsPar);
434 alpgenPar.parse(paramStr);
435 if (infoPtr) setInfoHeader(
"AlpgenPar", paramStr);
439 unwFN = baseFN +
".unw.gz";
440 isUnw = openFile(unwFN.c_str(), ifsUnw);
441 if (!ifsUnw.is_open()) closeFile(isUnw, ifsUnw);
444 unwFN = baseFN +
".unw";
445 isUnw = openFile(unwFN.c_str(), ifsUnw);
446 if (!ifsUnw.is_open()) {
447 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::LHAupAlpgen: "
448 "cannot open event file", unwFN);
449 closeFile(isUnw, ifsUnw);
459 inline bool LHAupAlpgen::setInit() {
462 if (!alpgenPar.haveParam(
"ih2") || !alpgenPar.haveParam(
"ebeam") ||
463 !alpgenPar.haveParam(
"hpc") || !alpgenPar.haveParam(
"xsecup") ||
464 !alpgenPar.haveParam(
"xerrup")) {
465 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setInit: "
466 "missing input parameters");
471 int ih2 = alpgenPar.getParamAsInt(
"ih2");
473 int idbmupB = (ih2 == 1) ? 2212 : -2212;
476 double ebeam = alpgenPar.getParam(
"ebeam");
481 int pdfgupA = 0, pdfsupA = 0;
482 int pdfgupB = 0, pdfsupB = 0;
489 lprup = alpgenPar.getParamAsInt(
"hpc");
492 if (lprup == 7 || lprup == 8 || lprup == 13) {
493 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setInit: "
494 "process not implemented");
503 if (lprup == 6 || lprup == 7 || lprup == 8 || lprup == 16) {
504 if (!alpgenPar.haveParam(
"ihvy")) {
505 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setInit: "
506 "heavy flavour information not present");
509 ihvy1 = alpgenPar.getParamAsInt(
"ihvy");
513 if (!alpgenPar.haveParam(
"ihvy2")) {
514 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setInit: "
515 "heavy flavour information not present");
518 ihvy2 = alpgenPar.getParamAsInt(
"ihvy2");
523 if (!alpgenPar.haveParam(
"mb")) {
524 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setInit: "
525 "heavy flavour information not present");
528 mb = alpgenPar.getParam(
"mb");
532 setBeamA(idbmupA, ebmupA, pdfgupA, pdfsupA);
533 setBeamB(idbmupB, ebmupB, pdfgupB, pdfsupB);
537 double xsecup = alpgenPar.getParam(
"xsecup");
538 double xerrup = alpgenPar.getParam(
"xerrup");
539 addProcess(lprup, xsecup, xerrup, xmaxup);
540 xSecSumSave = xsecup;
541 xErrSumSave = xerrup;
552 inline bool LHAupAlpgen::setEvent(
int) {
555 int nEvent, iProc, nParton;
558 if (!getline(*isUnw, line)) {
561 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setEvent: "
562 "could not read events from file");
566 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setEvent: "
567 "end of file reached");
570 istringstream iss1(line);
571 iss1 >> nEvent >> iProc >> nParton >> Swgt >> Sq;
574 double wgtT = Swgt, scaleT = Sq;
575 setProcess(lprup, wgtT, scaleT);
581 int idT, statusT, mother1T, mother2T, col1T, col2T;
582 double pxT, pyT, pzT, eT, mT;
584 double tauT = 0., spinT = 9.;
590 for (
int i = 0; i < nParton; i++) {
592 if (!getline(*isUnw, line)) {
593 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setEvent: "
594 "could not read events from file");
597 istringstream iss2(line);
603 iss2 >> idT >> col1T >> col2T >> pzT;
605 mother1T = mother2T = 0;
611 pzT = (i == 0) ? INCOMINGMIN : -INCOMINGMIN;
619 iss2 >> idT >> col1T >> col2T >> pxT >> pyT >> pzT >> mT;
623 eT = sqrt(max(0., pxT*pxT + pyT*pyT + pzT*pzT + mT*mT));
627 myParticles.push_back(LHAParticle(
628 idT, statusT, mother1T, mother2T, col1T, col2T,
629 pxT, pyT, pzT, eT, mT, tauT, spinT,-1.));
633 if (!addResonances())
return false;
637 if (!rescaleMomenta())
return false;
640 for (
size_t i = 0; i < myParticles.size(); i++)
641 addParticle(myParticles[i]);
644 id1T = myParticles[0].idPart;
645 x1T = myParticles[0].ePart / ebmupA;
646 id2T = myParticles[1].idPart;
647 x2T = myParticles[1].ePart / ebmupA;
648 setIdX(id1T, id2T, x1T, x2T);
649 setPdf(id1T, id2T, x1T, x2T, 0., 0., 0.,
false);
657 inline void LHAupAlpgen::printParticles() {
659 cout << endl <<
"---- LHAupAlpgen particle listing begin ----" << endl;
660 cout << scientific << setprecision(6);
661 for (
int i = 0; i < int(myParticles.size()); i++) {
663 << setw(5) << myParticles[i].idPart
664 << setw(5) << myParticles[i].statusPart
665 << setw(15) << myParticles[i].pxPart
666 << setw(15) << myParticles[i].pyPart
667 << setw(15) << myParticles[i].pzPart
668 << setw(15) << myParticles[i].ePart
669 << setw(15) << myParticles[i].mPart
670 << setw(5) << myParticles[i].mother1Part - 1
671 << setw(5) << myParticles[i].mother2Part - 1
672 << setw(5) << myParticles[i].col1Part
673 << setw(5) << myParticles[i].col2Part
676 cout <<
"---- LHAupAlpgen particle listing end ----" << endl;
684 inline bool LHAupAlpgen::addResonances() {
687 int idT, statusT, mother1T, mother2T, col1T, col2T;
688 double pxT, pyT, pzT, eT, mT;
690 double tauT = 0., spinT = 9.;
703 if (lprup <= 4 || lprup == 10 || lprup == 14 || lprup == 15) {
705 int i1 = myParticles.size() - 1, i2 = i1 - 1;
708 if (myParticles[i1].idPart + myParticles[i2].idPart == 0)
711 idT = - (myParticles[i1].idPart % 2) - (myParticles[i2].idPart % 2);
712 idT = (idT > 0) ? 24 : (idT < 0) ? -24 : 23;
715 if (lprup == 2 || lprup == 4) {
717 if (infoPtr) infoPtr->errorMsg(
"Error in "
718 "LHAupAlpgen::addResonances: wrong resonance type in event");
724 if (abs(idT) != 24) {
725 if (infoPtr) infoPtr->errorMsg(
"Error in "
726 "LHAupAlpgen::addResonances: wrong resonance type in event");
736 pxT = myParticles[i1].pxPart + myParticles[i2].pxPart;
737 pyT = myParticles[i1].pyPart + myParticles[i2].pyPart;
738 pzT = myParticles[i1].pzPart + myParticles[i2].pzPart;
739 eT = myParticles[i1].ePart + myParticles[i2].ePart;
740 mT = sqrt(eT*eT - pxT*pxT - pyT*pyT - pzT*pzT);
741 myParticles.push_back(LHAParticle(
742 idT, statusT, mother1T, mother2T, col1T, col2T,
743 pxT, pyT, pzT, eT, mT, tauT, spinT, -1.));
746 myParticles[i1].mother1Part = myParticles[i2].mother1Part =
748 myParticles[i1].mother2Part = myParticles[i2].mother2Part = 0;
774 }
else if ( ((lprup == 6 || lprup == 8 || lprup == 16) && ihvy1 == 6) ||
775 lprup == 5 || lprup == 13) {
778 int idx = myParticles.size() - 1;
779 for (
int i = myParticles.size() - 1; i > -1; i--) {
782 if (myParticles[i].idPart == 23 ||
783 abs(myParticles[i].idPart) == 24) {
787 if (myParticles[idx].idPart + myParticles[idx - 1].idPart == 0)
790 flav = - (myParticles[idx].idPart % 2)
791 - (myParticles[idx - 1].idPart % 2);
792 flav = (flav > 0) ? 24 : (flav < 0) ? -24 : 23;
793 if (flav != myParticles[i].idPart) {
795 infoPtr->errorMsg(
"Error in LHAupAlpgen::addResonance: "
796 "resonance does not match decay products");
801 myParticles[i].statusPart = 2;
802 myParticles[idx ].mother1Part = i + 1;
803 myParticles[idx--].mother2Part = 0;
804 myParticles[idx ].mother1Part = i + 1;
805 myParticles[idx--].mother2Part = 0;
808 }
else if (abs(myParticles[i].idPart) == 6) {
812 if (myParticles[idx].idPart + myParticles[idx - 1].idPart == 0)
815 flav = - (myParticles[idx].idPart % 2)
816 - (myParticles[idx - 1].idPart % 2);
817 flav = (flav > 0) ? 24 : (flav < 0) ? -24 : 23;
819 bool outOfOrder =
false, wrongFlavour =
false;;
820 if ( abs(flav) != 24 ||
821 (flav == 24 && myParticles[i].idPart != 6) ||
822 (flav == -24 && myParticles[i].idPart != -6) ) {
825 if (lprup == 5 || lprup == 13) {
833 if (myParticles[idx].idPart + myParticles[idx - 1].idPart == 0)
836 flav = - (myParticles[idx].idPart % 2)
837 - (myParticles[idx - 1].idPart % 2);
838 flav = (flav > 0) ? 24 : (flav < 0) ? -24 : 23;
841 if ( abs(flav) != 24 ||
842 (flav == 24 && myParticles[i].idPart != 6) ||
843 (flav == -24 && myParticles[i].idPart != -6) )
845 else outOfOrder =
true;
851 infoPtr->errorMsg(
"Error in LHAupAlpgen::addResonance: "
852 "resonance does not match decay products");
858 myParticles[i].statusPart = 2;
866 pxT = myParticles[idx].pxPart + myParticles[idx - 1].pxPart;
867 pyT = myParticles[idx].pyPart + myParticles[idx - 1].pyPart;
868 pzT = myParticles[idx].pzPart + myParticles[idx - 1].pzPart;
869 eT = myParticles[idx].ePart + myParticles[idx - 1].ePart;
870 mT = sqrt(eT*eT - pxT*pxT - pyT*pyT - pzT*pzT);
871 myParticles.push_back(LHAParticle(
872 idT, statusT, mother1T, mother2T, col1T, col2T,
873 pxT, pyT, pzT, eT, mT, tauT, spinT, -1.));
876 myParticles[idx ].mother1Part = myParticles.size();
877 myParticles[idx--].mother2Part = 0;
878 myParticles[idx ].mother1Part = myParticles.size();
879 myParticles[idx--].mother2Part = 0;
882 idT = (flav == 24) ? 5 : -5;
885 col1T = myParticles[i].col1Part;
886 col2T = myParticles[i].col2Part;
888 pxT = myParticles[i].pxPart - myParticles.back().pxPart;
889 pyT = myParticles[i].pyPart - myParticles.back().pyPart;
890 pzT = myParticles[i].pzPart - myParticles.back().pzPart;
891 eT = myParticles[i].ePart - myParticles.back().ePart;
892 mT = sqrt(eT*eT - pxT*pxT - pyT*pyT - pzT*pzT);
893 myParticles.push_back(LHAParticle(
894 idT, statusT, mother1T, mother2T, col1T, col2T,
895 pxT, pyT, pzT, eT, mT, tauT, spinT, -1.));
899 if (outOfOrder) idx += 4;
910 }
else if (lprup == 7 || lprup == 9 || lprup == 11 || lprup == 12) {
915 if (lprup == 13)
for (
int i = 0; i < 2; i++)
916 if (abs(myParticles[i].idPart) == 5) {
917 myParticles[i].mPart = mb;
918 myParticles[i].ePart = sqrt(pow2(myParticles[i].pzPart) + pow2(mb));
922 if (LHADEBUG) printParticles();
941 inline bool LHAupAlpgen::rescaleMomenta() {
946 for (
int i = 0; i < int(myParticles.size()); i++) {
947 Vec4 pNow = Vec4(myParticles[i].pxPart, myParticles[i].pyPart,
948 myParticles[i].pzPart, myParticles[i].ePart);
949 if (i < 2) pIn += pNow;
950 else if (myParticles[i].statusPart == 1) {
958 if (abs(pOut.pT() - pIn.pT()) > ZEROTHRESHOLD) {
960 double pxDiff = (pOut.px() - pIn.px()) / nOut,
961 pyDiff = (pOut.py() - pIn.py()) / nOut;
964 if (pxDiff > PTWARNTHRESHOLD || pyDiff > PTWARNTHRESHOLD) {
965 if (infoPtr) infoPtr->errorMsg(
"Warning in LHAupAlpgen::setEvent: "
966 "large pT imbalance in incoming event");
969 if (LHADEBUGRESCALE) {
971 cout <<
"pxDiff = " << pxDiff <<
", pyDiff = " << pyDiff << endl;
977 for (
int i = 2; i < int(myParticles.size()); i++) {
978 if (myParticles[i].statusPart != 1)
continue;
979 myParticles[i].pxPart -= pxDiff;
980 myParticles[i].pyPart -= pyDiff;
981 myParticles[i].ePart = sqrt(max(0., pow2(myParticles[i].pxPart) +
982 pow2(myParticles[i].pyPart) + pow2(myParticles[i].pzPart) +
983 pow2(myParticles[i].mPart)));
984 pOut += Vec4(myParticles[i].pxPart, myParticles[i].pyPart,
985 myParticles[i].pzPart, myParticles[i].ePart);
990 double de = (pOut.e() - pIn.e());
991 double dp = (pOut.pz() - pIn.pz());
992 double a = 1 + (de + dp) / 2. / myParticles[0].ePart;
993 double b = 1 + (de - dp) / 2. / myParticles[1].ePart;
1000 if (abs(a - 1.) * myParticles[0].ePart > EWARNTHRESHOLD ||
1001 abs(b - 1.) * myParticles[1].ePart > EWARNTHRESHOLD) {
1002 if (infoPtr) infoPtr->errorMsg(
"Warning in LHAupAlpgen::setEvent: "
1003 "large rescaling factor");
1006 if (LHADEBUGRESCALE) {
1008 cout <<
"de = " << de <<
", dp = " << dp
1009 <<
", a = " << a <<
", b = " << b << endl
1010 <<
"Absolute energy change for incoming 0 = "
1011 << abs(a - 1.) * myParticles[0].ePart << endl
1012 <<
"Absolute energy change for incoming 1 = "
1013 << abs(b - 1.) * myParticles[1].ePart << endl;
1016 myParticles[0].ePart *= a;
1017 myParticles[0].pzPart *= a;
1018 myParticles[1].ePart *= b;
1019 myParticles[1].pzPart *= b;
1022 for (
int i = 0; i < int(myParticles.size()); i++) {
1023 if (myParticles[i].statusPart != 2)
continue;
1027 for (
int j = 0; j < int(myParticles.size()); j++) {
1028 if (myParticles[j].mother1Part - 1 != i)
continue;
1029 resVec += Vec4(myParticles[j].pxPart, myParticles[j].pyPart,
1030 myParticles[j].pzPart, myParticles[j].ePart);
1033 myParticles[i].pxPart = resVec.px();
1034 myParticles[i].pyPart = resVec.py();
1035 myParticles[i].pzPart = resVec.pz();
1036 myParticles[i].ePart = resVec.e();
1053 AlpgenHooks::AlpgenHooks(Pythia &pythia) : LHAagPtr(NULL) {
1056 string agFile = pythia.settings.word(
"Alpgen:file");
1057 if (agFile !=
"void") {
1058 LHAagPtr =
new LHAupAlpgen(agFile.c_str(), &pythia.info);
1059 pythia.settings.mode(
"Beams:frameType", 5);
1060 pythia.setLHAupPtr(LHAagPtr);
1072 inline bool AlpgenHooks::initAfterBeams() {
1075 bool setLightMasses = settingsPtr->flag(
"Alpgen:setLightMasses");
1076 bool setHeavyMasses = settingsPtr->flag(
"Alpgen:setHeavyMasses");
1077 bool setNjet = settingsPtr->flag(
"Alpgen:setNjet");
1078 bool setMLM = settingsPtr->flag(
"Alpgen:setMLM");
1082 string parStr = infoPtr->header(
"AlpgenPar");
1083 if (!parStr.empty()) {
1089 if (setLightMasses) {
1090 if (par.haveParam(
"mc")) particleDataPtr->m0(4, par.getParam(
"mc"));
1091 if (par.haveParam(
"mb")) particleDataPtr->m0(5, par.getParam(
"mb"));
1093 if (setHeavyMasses) {
1094 if (par.haveParam(
"mt")) particleDataPtr->m0(6, par.getParam(
"mt"));
1095 if (par.haveParam(
"mz")) particleDataPtr->m0(23, par.getParam(
"mz"));
1096 if (par.haveParam(
"mw")) particleDataPtr->m0(24, par.getParam(
"mw"));
1097 if (par.haveParam(
"mh")) particleDataPtr->m0(25, par.getParam(
"mh"));
1102 if (par.haveParam(
"njets"))
1103 settingsPtr->mode(
"JetMatching:nJet", par.getParamAsInt(
"njets"));
1105 infoPtr->errorMsg(
"Warning in AlpgenHooks:init: "
1106 "no ALPGEN nJet parameter found");
1111 if (par.haveParam(
"ptjmin") && par.haveParam(
"drjmin") &&
1112 par.haveParam(
"etajmax")) {
1113 double ptjmin = par.getParam(
"ptjmin");
1114 ptjmin = max(ptjmin + 5., 1.2 * ptjmin);
1115 settingsPtr->parm(
"JetMatching:eTjetMin", ptjmin);
1116 settingsPtr->parm(
"JetMatching:coneRadius", par.getParam(
"drjmin"));
1117 settingsPtr->parm(
"JetMatching:etaJetMax", par.getParam(
"etajmax"));
1121 infoPtr->errorMsg(
"Warning in AlpgenHooks:init: "
1122 "no ALPGEN merging parameters found");
1142 const double MadgraphPar::ZEROTHRESHOLD = 1e-10;
1148 inline bool MadgraphPar::parse(
const string paramStr) {
1151 stringstream paramStream(paramStr);
1153 while ( getline(paramStream, line) ) extractRunParam(line);
1162 inline void MadgraphPar::extractRunParam(
string line) {
1165 size_t idz = line.find(
"#");
1166 if ( !(idz == string::npos) )
return;
1167 size_t idx = line.find(
"=");
1168 size_t idy = line.find(
"!");
1169 if (idy == string::npos) idy = line.size();
1170 if (idx == string::npos)
return;
1171 string paramName = trim( line.substr( idx + 1, idy - idx - 1) );
1172 string paramVal = trim( line.substr( 0, idx) );
1173 replace( paramVal.begin(), paramVal.end(),
'd',
'e');
1176 istringstream iss(paramVal);
1178 if (paramName.find(
",") != string::npos) {
1179 string paramNameNow;
1180 istringstream issName( paramName);
1181 while ( getline(issName, paramNameNow,
',') ) {
1183 warnParamOverwrite( paramNameNow, val);
1184 params[paramNameNow] = val;
1190 warnParamOverwrite( paramName, val);
1199 inline void MadgraphPar::printParams() {
1203 <<
" *-------- Madgraph parameters --------*" << endl;
1204 for (map<string,double>::iterator it =
params.begin();
1205 it !=
params.end(); ++it)
1206 cout <<
" | " << left << setw(15) << it->first
1207 <<
" | " << right << setw(15) << it->second
1209 cout <<
" *---------------------------------------*" << endl;
1216 inline void MadgraphPar::warnParamOverwrite(
const string ¶mIn,
1220 if (haveParam(paramIn) &&
1221 abs(getParam(paramIn) - val) > ZEROTHRESHOLD) {
1222 if (infoPtr) infoPtr->errorMsg(
"Warning in LHAupAlpgen::"
1223 "warnParamOverwrite: overwriting existing parameter", paramIn);
1231 inline string MadgraphPar::trim(
string s) {
1235 if ( (i = s.find_last_not_of(
" \t\r\n")) != string::npos)
1236 s = s.substr(0, i + 1);
1237 if ( (i = s.find_first_not_of(
" \t\r\n")) != string::npos)
1246 #endif // Pythia8_GeneratorInput_H