3 using namespace Pythia8;
33 stringstream paramStream(paramStr);
35 while (getline(paramStream, line)) {
38 if (line.find(
"run parameters") != string::npos) {
42 }
else if (line.find(
"end parameters") != string::npos) {
46 }
else if (block == 0) {
50 extractRunParam(line);
65 size_t idx = line.rfind(
"!");
66 if (idx == string::npos)
return;
67 string paramName = trim(line.substr(idx + 1));
68 string paramVal = trim(line.substr(0, idx));
69 istringstream iss(paramVal);
73 if (paramName ==
"hard process code") {
75 warnParamOverwrite(
"hpc", val);
79 }
else if (paramName.find(
"Crosssection") == 0) {
82 warnParamOverwrite(
"xsecup", val);
83 warnParamOverwrite(
"xerrup", val);
84 params[
"xsecup"] = val;
85 params[
"xerrup"] = xerrup;
88 }
else if (paramName.find(
"unwtd events") == 0) {
91 warnParamOverwrite(
"nevent", val);
92 warnParamOverwrite(
"lum", val);
97 }
else if (paramName.find(
",") != string::npos) {
101 istringstream issName(paramName);
102 while (getline(issName, paramNameNow,
',')) {
104 warnParamOverwrite(paramNameNow, val);
105 params[paramNameNow] = val;
111 iss >> paramIdx >> val;
112 warnParamOverwrite(paramName, val);
113 params[paramName] = val;
124 cout << fixed << setprecision(3) << endl
125 <<
" *------- Alpgen parameters -------*" << endl;
126 for (map < string, double >::iterator it = params.begin();
127 it != params.end(); ++it)
128 cout <<
" | " << left << setw(13) << it->first
129 <<
" | " << right << setw(13) << it->second
131 cout <<
" *-----------------------------------*" << endl;
141 if (haveParam(paramIn) &&
142 abs(getParam(paramIn) - val) > ZEROTHRESHOLD) {
143 if (infoPtr) infoPtr->errorMsg(
"Warning in LHAupAlpgen::"
144 "warnParamOverwrite: overwriting existing parameter", paramIn);
156 if ((i = s.find_last_not_of(
" \t\r\n")) != string::npos)
157 s = s.substr(0, i + 1);
158 if ((i = s.find_first_not_of(
" \t\r\n")) != string::npos)
195 : baseFN(baseFNin), alpgenPar(infoPtrIn), isUnw(
NULL) {
198 if (infoPtrIn)
setPtr(infoPtrIn);
202 istream* isPar =
NULL;
207 isPar = openFile(
parFN.c_str(), ifsPar);
208 if (!ifsPar.is_open()) closeFile(isPar, ifsPar);
212 isPar = openFile(
parFN.c_str(), ifsPar);
213 if (!ifsPar.is_open()) {
214 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::LHAupAlpgen: "
215 "cannot open parameter file",
parFN);
216 closeFile(isPar, ifsPar);
222 string paramStr((istreambuf_iterator<char>(isPar->rdbuf())),
223 istreambuf_iterator<char>());
227 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::LHAupAlpgen: "
228 "cannot read parameter file",
parFN);
231 closeFile(isPar, ifsPar);
235 if (infoPtr) setInfoHeader(
"AlpgenPar", paramStr);
247 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::LHAupAlpgen: "
248 "cannot open event file",
unwFN);
265 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setInit: "
266 "missing input parameters");
273 int idbmupB = (ih2 == 1) ? 2212 : -2212;
281 int pdfgupA = 0, pdfsupA = 0;
282 int pdfgupB = 0, pdfsupB = 0;
293 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setInit: "
294 "process not implemented");
305 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setInit: "
306 "heavy flavour information not present");
314 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setInit: "
315 "heavy flavour information not present");
324 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setInit: "
325 "heavy flavour information not present");
332 setBeamA(idbmupA,
ebmupA, pdfgupA, pdfsupA);
333 setBeamB(idbmupB,
ebmupB, pdfgupB, pdfsupB);
339 addProcess(
lprup, xsecup, xerrup, xmaxup);
340 xSecSumSave = xsecup;
341 xErrSumSave = xerrup;
355 int nEvent, iProc, nParton;
358 if (!getline(*
isUnw, line)) {
361 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setEvent: "
362 "could not read events from file");
366 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setEvent: "
367 "end of file reached");
370 istringstream iss1(line);
371 iss1 >> nEvent >> iProc >> nParton >> Swgt >> Sq;
374 double wgtT = Swgt, scaleT = Sq;
375 setProcess(
lprup, wgtT, scaleT);
381 int idT, statusT, mother1T, mother2T, col1T, col2T;
382 double pxT, pyT, pzT, eT, mT;
384 double tauT = 0., spinT = 9.;
390 for (
int i = 0;
i < nParton;
i++) {
392 if (!getline(*
isUnw, line)) {
393 if (infoPtr) infoPtr->errorMsg(
"Error in LHAupAlpgen::setEvent: "
394 "could not read events from file");
397 istringstream iss2(line);
403 iss2 >> idT >> col1T >> col2T >> pzT;
405 mother1T = mother2T = 0;
419 iss2 >> idT >> col1T >> col2T >> pxT >> pyT >> pzT >> mT;
423 eT =
sqrt(
max(0., pxT*pxT + pyT*pyT + pzT*pzT + mT*mT));
428 idT, statusT, mother1T, mother2T, col1T, col2T,
429 pxT, pyT, pzT, eT, mT, tauT, spinT,-1.));
448 setIdX(id1T, id2T, x1T, x2T);
449 setPdf(id1T, id2T, x1T, x2T, 0., 0., 0.,
false);
459 cout << endl <<
"---- LHAupAlpgen particle listing begin ----" << endl;
460 cout << scientific << setprecision(6);
476 cout <<
"---- LHAupAlpgen particle listing end ----" << endl;
487 int idT, statusT, mother1T, mother2T, col1T, col2T;
488 double pxT, pyT, pzT, eT, mT;
490 double tauT = 0., spinT = 9.;
512 idT = (idT > 0) ? 24 : (idT < 0) ? -24 : 23;
517 if (infoPtr) infoPtr->errorMsg(
"Error in "
518 "LHAupAlpgen::addResonances: wrong resonance type in event");
524 if (
abs(idT) != 24) {
525 if (infoPtr) infoPtr->errorMsg(
"Error in "
526 "LHAupAlpgen::addResonances: wrong resonance type in event");
540 mT =
sqrt(eT*eT - pxT*pxT - pyT*pyT - pzT*pzT);
542 idT, statusT, mother1T, mother2T, col1T, col2T,
543 pxT, pyT, pzT, eT, mT, tauT, spinT, -1.));
592 flav = (flav > 0) ? 24 : (flav < 0) ? -24 : 23;
595 infoPtr->errorMsg(
"Error in LHAupAlpgen::addResonance: "
596 "resonance does not match decay products");
617 flav = (flav > 0) ? 24 : (flav < 0) ? -24 : 23;
619 bool outOfOrder =
false, wrongFlavour =
false;;
620 if (
abs(flav) != 24 ||
638 flav = (flav > 0) ? 24 : (flav < 0) ? -24 : 23;
641 if (
abs(flav) != 24 ||
645 else outOfOrder =
true;
651 infoPtr->errorMsg(
"Error in LHAupAlpgen::addResonance: "
652 "resonance does not match decay products");
670 mT =
sqrt(eT*eT - pxT*pxT - pyT*pyT - pzT*pzT);
672 idT, statusT, mother1T, mother2T, col1T, col2T,
673 pxT, pyT, pzT, eT, mT, tauT, spinT, -1.));
682 idT = (flav == 24) ? 5 : -5;
692 mT =
sqrt(eT*eT - pxT*pxT - pyT*pyT - pzT*pzT);
694 idT, statusT, mother1T, mother2T, col1T, col2T,
695 pxT, pyT, pzT, eT, mT, tauT, spinT, -1.));
699 if (outOfOrder) idx += 4;
715 if (
lprup == 13)
for (
int i = 0;
i < 2;
i++)
749 if (
i < 2) pIn += pNow;
760 double pxDiff = (pOut.px() - pIn.px()) / nOut,
761 pyDiff = (pOut.py() - pIn.py()) / nOut;
765 if (infoPtr) infoPtr->errorMsg(
"Warning in LHAupAlpgen::setEvent: "
766 "large pT imbalance in incoming event");
771 cout <<
"pxDiff = " << pxDiff <<
", pyDiff = " << pyDiff << endl;
790 double de = (pOut.e() - pIn.e());
791 double dp = (pOut.pz() - pIn.pz());
802 if (infoPtr) infoPtr->errorMsg(
"Warning in LHAupAlpgen::setEvent: "
803 "large rescaling factor");
808 cout <<
"de = " << de <<
", dp = " << dp
809 <<
", a = " << a <<
", b = " << b << endl
810 <<
"Absolute energy change for incoming 0 = "
812 <<
"Absolute energy change for incoming 1 = "
856 string agFile = pythia.settings.word(
"Alpgen:file");
857 if (agFile !=
"void") {
859 pythia.settings.mode(
"Beams:frameType", 5);
875 bool setMasses = settingsPtr->flag(
"Alpgen:setMasses");
876 bool setNjet = settingsPtr->flag(
"Alpgen:setNjet");
877 bool setMLM = settingsPtr->flag(
"Alpgen:setMLM");
881 string parStr = infoPtr->header(
"AlpgenPar");
882 if (!parStr.empty()) {
900 settingsPtr->mode(
"JetMatching:nJet", par.
getParamAsInt(
"njets"));
902 infoPtr->errorMsg(
"Warning in AlpgenHooks:init: "
903 "no ALPGEN nJet parameter found");
910 double ptjmin = par.
getParam(
"ptjmin");
911 ptjmin =
max(ptjmin + 5., 1.2 * ptjmin);
912 settingsPtr->parm(
"JetMatching:eTjetMin", ptjmin);
913 settingsPtr->parm(
"JetMatching:coneRadius", par.
getParam(
"drjmin"));
914 settingsPtr->parm(
"JetMatching:etaJetMax", par.
getParam(
"etajmax"));
918 infoPtr->errorMsg(
"Warning in AlpgenHooks:init: "
919 "no ALPGEN merging parameters found");
948 stringstream paramStream(paramStr);
962 size_t idz = line.find(
"#");
963 if ( !(idz == string::npos) )
return;
964 size_t idx = line.find(
"=");
965 size_t idy = line.find(
"!");
966 if (idy == string::npos) idy = line.size();
967 if (idx == string::npos)
return;
968 string paramName =
trim( line.substr( idx + 1, idy - idx - 1) );
969 string paramVal =
trim( line.substr( 0, idx) );
970 replace( paramVal.begin(), paramVal.end(),
'd',
'e');
973 istringstream iss(paramVal);
975 if (paramName.find(
",") != string::npos) {
977 istringstream issName( paramName);
978 while ( getline(issName, paramNameNow,
',') ) {
981 params[paramNameNow] = val;
1000 <<
" *-------- Madgraph parameters --------*" << endl;
1001 for (map<string,double>::iterator it =
params.begin();
1002 it !=
params.end(); ++it)
1003 cout <<
" | " << left << setw(15) << it->first
1004 <<
" | " << right << setw(15) << it->second
1006 cout <<
" *---------------------------------------*" << endl;
1019 "warnParamOverwrite: overwriting existing parameter", paramIn);
1031 if ( (i = s.find_last_not_of(
" \t\r\n")) != string::npos)
1032 s = s.substr(0, i + 1);
1033 if ( (i = s.find_first_not_of(
" \t\r\n")) != string::npos)
static const double PTWARNTHRESHOLD
void warnParamOverwrite(const string ¶mIn, double val)
bool haveParam(const string ¶mIn)
void setPtr(std::vector< T, A > const &obj, std::type_info const &iToType, unsigned long iIndex, void const *&oPtr)
LHAupAlpgen(const char *baseFNin, Pythia8::Info *infoPtrIn=NULL)
vector< Pythia8::LHAParticle > myParticles
map< string, double > params
static const bool LHADEBUGRESCALE
double getParam(const string ¶mIn)
const T & max(const T &a, const T &b)
bool parse(const string paramStr)
Abs< T >::type abs(const T &t)
static string trim(string s)
double getParam(const string ¶mIn)
static const double ZEROTHRESHOLD
void warnParamOverwrite(const string ¶mIn, double val)
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
static const double ZEROTHRESHOLD
static string trim(string s)
bool haveParam(const string ¶mIn)
void extractRunParam(string line)
static const double EWARNTHRESHOLD
static const bool LHADEBUG
bool setEvent(int, double)
static const double ZEROTHRESHOLD
static const double INCOMINGMIN
AlpgenHooks(Pythia8::Pythia &pythia)
void extractRunParam(string line)
bool parse(const string paramStr)
int getParamAsInt(const string ¶mIn)