8 #include "Pythia8/Info.h"
25 const int Info::TIMESTOPRINT = 1;
28 const double Info::CONVERTMB2PB = 1e9;
34 void Info::list()
const {
37 cout <<
"\n -------- PYTHIA Info Listing ------------------------"
38 <<
"---------------- \n \n"
39 << scientific << setprecision(3)
40 <<
" Beam A: id = " << setw(6) << idASave <<
", pz = " << setw(10)
41 << pzASave <<
", e = " << setw(10) << eASave <<
", m = " << setw(10)
43 <<
" Beam B: id = " << setw(6) << idBSave <<
", pz = " << setw(10)
44 << pzBSave <<
", e = " << setw(10) << eBSave <<
", m = " << setw(10)
48 if (codeSave == 0 && nFinalSave == 0) {
49 cout <<
" No process has been set; something must have gone wrong! \n"
50 <<
"\n -------- End PYTHIA Info Listing --------------------"
51 <<
"----------------" << endl;
57 cout <<
" In 1: id = " << setw(4) << id1pdfSave[0] <<
", x = "
58 << setw(10) << x1pdfSave[0] <<
", pdf = " << setw(10) << pdf1Save[0]
59 <<
" at Q2 = " << setw(10) << Q2FacSave[0] <<
".\n"
60 <<
" In 2: id = " << setw(4) << id2pdfSave[0] <<
", x = "
61 << setw(10) << x2pdfSave[0] <<
", pdf = " << setw(10) << pdf2Save[0]
64 if (id1pdfSave[0] != id1Save[0] || id2pdfSave[0] != id2Save[0])
66 if (abs(x1pdfSave[0] - x1Save[0]) > 1e-4 * x1Save[0]) matchIdX =
false;
67 if (abs(x2pdfSave[0] - x2Save[0]) > 1e-4 * x2Save[0]) matchIdX =
false;
68 if (!matchIdX) cout <<
" Warning: above flavour/x info does not match"
69 <<
" incoming partons in event!\n";
74 cout << ((isRes && !hasSubSave[0]) ?
" Subprocess " :
" Process ")
75 << nameSave <<
" with code " << codeSave <<
" is 2 -> "
76 << nFinalSave <<
".\n";
80 cout <<
" Subprocess " << nameSubSave[0] <<
" with code " << codeSubSave[0]
81 <<
" is 2 -> " << nFinalSubSave[0] <<
".\n";
84 if ( isRes && nFinalSave == 1)
85 cout <<
" It has sHat = " << setw(10) << sH[0] <<
".\n";
86 else if ( isRes && nFinalSave == 2)
87 cout <<
" It has sHat = " << setw(10) << sH[0] <<
", tHat = "
88 << setw(10) << tH[0] <<
", uHat = " << setw(10) << uH[0] <<
",\n"
89 <<
" pTHat = " << setw(10) << pTH[0] <<
", m3Hat = "
90 << setw(10) << m3H[0] <<
", m4Hat = " << setw(10) << m4H[0] <<
",\n"
91 <<
" thetaHat = " << setw(10) << thetaH[0] <<
", phiHat = "
92 << setw(10) << phiH[0] <<
".\n";
93 else if ( nFinalSave == 2)
94 cout <<
" It has s = " << setw(10) << sH[0] <<
", t = " << setw(10)
95 << tH[0] <<
", u = " << setw(10) << uH[0] <<
",\n"
96 <<
" pT = " << setw(10) << pTH[0] <<
", m3 = " << setw(10)
97 << m3H[0] <<
", m4 = " << setw(10) << m4H[0] <<
",\n"
98 <<
" theta = " << setw(10) << thetaH[0] <<
", phi = " << setw(10)
100 else if ( isRes && nFinalSave == 3)
101 cout <<
" It has sHat = " << setw(10) << sH[0] <<
", <pTHat> = "
102 << setw(10) << pTH[0] <<
".\n";
103 else if ( nFinalSave == 3)
104 cout <<
" It has s = " << setw(10) << sH[0] <<
", t_A = " << setw(10)
105 << tH[0] <<
", t_B = " << setw(10) << uH[0] <<
",\n"
106 <<
" <pT> = " << setw(10) << pTH[0] <<
".\n";
109 if (isRes) cout <<
" alphaEM = " << setw(10) << alphaEMSave[0]
110 <<
", alphaS = " << setw(10) << alphaSSave[0] <<
" at Q2 = "
111 << setw(10) << Q2RenSave[0] <<
".\n";
114 for (
int iDS = 1; iDS < 4; ++iDS)
if (id1Save[iDS] != 0) {
115 if (iDS == 1) cout <<
"\n Diffractive system on side A: \n";
116 if (iDS == 2) cout <<
"\n Diffractive system on side B: \n";
117 if (iDS == 3) cout <<
"\n Central diffractive system: \n";
118 cout <<
" In 1: id = " << setw(4) << id1pdfSave[iDS] <<
", x = "
119 << setw(10) << x1pdfSave[iDS] <<
", pdf = " << setw(10)
120 << pdf1Save[iDS] <<
" at Q2 = " << setw(10) << Q2FacSave[iDS]
121 <<
".\n" <<
" In 2: id = " << setw(4) << id2pdfSave[iDS]
122 <<
", x = " << setw(10) << x2pdfSave[iDS] <<
", pdf = "
123 << setw(10) << pdf2Save[iDS] <<
" at same Q2.\n";
124 cout <<
" Subprocess " << nameSubSave[iDS] <<
" with code "
125 << codeSubSave[iDS] <<
" is 2 -> " << nFinalSubSave[iDS] <<
".\n";
126 if (nFinalSubSave[iDS] == 1) {
127 cout <<
" It has sHat = " << setw(10) << sH[iDS] <<
".\n";
128 }
else if (nFinalSubSave[iDS] == 2) {
129 cout <<
" It has sHat = " << setw(10) << sH[iDS] <<
", tHat = "
130 << setw(10) << tH[iDS] <<
", uHat = " << setw(10) << uH[iDS]
131 <<
",\n" <<
" pTHat = " << setw(10) << pTH[iDS]
132 <<
", m3Hat = " << setw(10) << m3H[iDS] <<
", m4Hat = "
133 << setw(10) << m4H[iDS] <<
",\n" <<
" thetaHat = " << setw(10)
134 << thetaH[iDS] <<
", phiHat = " << setw(10) << phiH[iDS] <<
".\n";
136 cout <<
" alphaEM = " << setw(10) << alphaEMSave[iDS]
137 <<
", alphaS = " << setw(10) << alphaSSave[iDS] <<
" at Q2 = "
138 << setw(10) << Q2RenSave[iDS] <<
".\n";
142 if (bIsSet) cout <<
"\n Impact parameter b = " << setw(10) << bMPISave
143 <<
" gives enhancement factor = " << setw(10) << enhanceMPISave
147 if (evolIsSet) cout <<
" Max pT scale for MPI = " << setw(10) << pTmaxMPISave
148 <<
", ISR = " << setw(10) << pTmaxISRSave <<
", FSR = " << setw(10)
149 << pTmaxISRSave <<
".\n Number of MPI = " << setw(5) << nMPISave
150 <<
", ISR = " << setw(5) << nISRSave <<
", FSRproc = " << setw(5)
151 << nFSRinProcSave <<
", FSRreson = " << setw(5) << nFSRinResSave
155 cout <<
"\n -------- End PYTHIA Info Listing --------------------"
156 <<
"----------------" << endl;
164 double Info::weight(
int iWeight)
const {
165 double wt = (iWeight <= 0 || iWeight >= int(weightSave.size()))
166 ? weightSave[0] : weightSave[iWeight];
167 return (abs(lhaStrategySave) == 4) ? CONVERTMB2PB * wt : wt;
170 double Info::weightSum()
const {
171 return (abs(lhaStrategySave) == 4) ? CONVERTMB2PB * wtAccSum : wtAccSum;
177 void Info::initUncertainties(vector<string>* variationListIn,
bool isISR) {
178 size_t vNames = weightLabelSave.size();
179 externalVariations.clear();
180 externalVarNames.clear();
181 externalGroupNames.clear();
183 initialNameSave.clear();
184 externalVariations.push_back(
"Baseline");
185 initialNameSave.push_back(
"Baseline");
186 for(vector<string>::const_iterator v=variationListIn->begin();
187 v != variationListIn->end(); ++v) {
190 while (line.find(
" ") == 0) line.erase( 0, 1);
193 if( isISR && ((pos = line.find(
"isr:pdf:family")) != string::npos) ) {
194 size_t posEnd = line.find(
" ",pos);
195 if( posEnd == string::npos ) posEnd = line.size();
196 for(
size_t i=0; i < vNames; ++i) {
197 string local = weightLabelSave[i];
198 if( local.find(
"isr:pdf:member") != string::npos ) {
199 size_t iEqual = local.find(
"=")+1;
200 string nMember = local.substr(iEqual,local.size());
202 string tmpLine = line;
203 tmpLine.replace(pos,posEnd-pos,local);
204 size_t iBlank = line.find_first_of(
" ");
205 tmpLine.replace(iBlank,1,nMember);
206 externalVariations.push_back(tmpLine);
207 initialNameSave.push_back(line.substr(0,line.find_first_of(
" ")));
211 externalVariations.push_back(line);
212 initialNameSave.push_back(line.substr(0,line.find_first_of(
" ")));
215 externalVariationsSize = externalVariations.size();
216 size_t nNames = externalVariationsSize;
217 externalVarNames.resize(nNames);
218 externalVarNames[0].push_back(
"Baseline");
219 externalGroupNames.resize(nNames);
220 externalGroupNames[0]=
"Baseline";
221 for(
size_t iWeight = 0; iWeight < nNames; ++iWeight) {
222 string uVarString = toLower(externalVariations[iWeight]);
223 size_t firstBlank = uVarString.find_first_of(
" ");
224 size_t endLine = uVarString.size();
225 if( firstBlank > endLine)
continue;
226 externalGroupNames[iWeight] = uVarString.substr(0,firstBlank);
227 uVarString = uVarString.substr(firstBlank+1,endLine);
229 while ((pos = uVarString.find(
" ")) != string::npos) {
230 string token = uVarString.substr(0, pos);
231 externalVarNames[iWeight].push_back(token);
232 uVarString.erase(0, pos + 1);
234 if (uVarString ==
"" || uVarString ==
" ")
continue;
235 externalVarNames[iWeight].push_back(uVarString);
237 externalMap.resize(nNames);
238 for(
size_t iWeight = 0; iWeight < vNames; ++iWeight) {
239 for(
size_t iV = 0; iV < nNames; ++iV) {
240 for(
size_t iW = 0; iW < externalVarNames[iV].size(); ++iW) {
241 if( externalVarNames[iV][iW] == weightLabelSave[iWeight] ) {
242 externalMap[iV].push_back(iWeight);
243 }
else if ( isISR && externalVarNames[iV][iW].find(
"isr:pdf:family")
244 != string::npos && weightLabelSave[iWeight].find(
"isr:pdf:member")
246 externalMap[iV].push_back(iWeight);
257 vector<int> Info::codesHard() {
258 vector<int> codesNow;
259 for (map<int, long>::iterator nTryEntry = nTryM.begin();
260 nTryEntry != nTryM.end(); ++nTryEntry)
261 codesNow.push_back( nTryEntry->first );
269 void Info::errorMsg(
string messageIn,
string extraIn,
bool showAlways) {
272 int times = messages[messageIn];
273 ++messages[messageIn];
276 if (times < TIMESTOPRINT || showAlways) cout <<
" PYTHIA "
277 << messageIn <<
" " << extraIn << endl;
285 int Info::errorTotalNumber() {
288 for ( map<string, int>::iterator messageEntry = messages.begin();
289 messageEntry != messages.end(); ++messageEntry)
290 nTot += messageEntry->second;
299 void Info::errorStatistics() {
302 cout <<
"\n *------- PYTHIA Error and Warning Messages Statistics "
303 <<
"----------------------------------------------------------* \n"
306 <<
" | times message "
312 map<string, int>::iterator messageEntry = messages.begin();
313 if (messageEntry == messages.end())
314 cout <<
" | 0 no errors or warnings to report "
316 while (messageEntry != messages.end()) {
318 string temp = messageEntry->first;
319 int len = temp.length();
320 temp.insert( len, max(0, 102 - len),
' ');
321 cout <<
" | " << setw(6) << messageEntry->second <<
" "
329 <<
" *------- End PYTHIA Error and Warning Messages Statistics"
330 <<
" ------------------------------------------------------* "
339 vector < string > Info::headerKeys() {
340 vector < string > keys;
341 for (map < string, string >::iterator it = headers.begin();
342 it != headers.end(); it++)
343 keys.push_back(it->first);
351 void Info::setLHEF3InitInfo() {
363 void Info::setLHEF3InitInfo(
int LHEFversionIn, LHAinitrwgt *initrwgtIn,
364 vector<LHAgenerator> *generatorsIn,
365 map<string,LHAweightgroup> *weightgroupsIn,
366 map<string,LHAweight> *init_weightsIn,
string headerBlockIn ) {
367 LHEFversionSave = LHEFversionIn;
368 initrwgt = initrwgtIn;
369 generators = generatorsIn;
370 weightgroups = weightgroupsIn;
371 init_weights = init_weightsIn;
372 headerBlock = headerBlockIn;
379 void Info::setLHEF3EventInfo() {
381 weights_detailed = 0;
382 weights_compressed = 0;
386 weights_detailed_vector.resize(0);
388 eventWeightLHEF = 1.0;
395 void Info::setLHEF3EventInfo( map<string, string> *eventAttributesIn,
396 map<string,double> *weights_detailedIn,
397 vector<double> *weights_compressedIn,
398 LHAscales *scalesIn, LHAweights *weightsIn,
399 LHArwgt *rwgtIn, vector<double> weights_detailed_vecIn,
400 string eventCommentsIn,
double eventWeightLHEFIn ) {
401 eventAttributes = eventAttributesIn;
402 weights_detailed = weights_detailedIn;
403 weights_compressed = weights_compressedIn;
407 weights_detailed_vector = weights_detailed_vecIn;
408 eventComments = eventCommentsIn;
409 eventWeightLHEF = eventWeightLHEFIn;
416 string Info::getEventAttribute(
string key,
bool doRemoveWhitespace) {
417 if (!eventAttributes)
return "";
418 if ( eventAttributes->find(key) != eventAttributes->end() ) {
419 string res = (*eventAttributes)[key];
420 if (doRemoveWhitespace)
421 res.erase (
remove (res.begin(), res.end(),
' '), res.end());
431 int Info::LHEFversion() {
return LHEFversionSave;}
437 unsigned int Info::getInitrwgtSize() {
438 if (!initrwgt)
return 0;
439 return initrwgt->weights.size();
446 unsigned int Info::getGeneratorSize() {
447 if (!generators)
return 0;
448 return generators->size();
451 string Info::getGeneratorValue(
unsigned int n) {
452 if (!generators || generators->size() < n+1)
return "";
453 return (*generators)[n].contents;
456 string Info::getGeneratorAttribute(
unsigned int n,
string key,
457 bool doRemoveWhitespace) {
458 if (!generators || generators->size() < n+1)
return "";
460 if ( key ==
"name") {
461 res = (*generators)[n].name;
462 }
else if ( key ==
"version") {
463 res = (*generators)[n].version;
464 }
else if ( (*generators)[n].
attributes.find(key)
465 != (*generators)[n].attributes.end() ) {
466 res = (*generators)[n].attributes[key];
468 if (doRemoveWhitespace && res !=
"")
469 res.erase (
remove (res.begin(), res.end(),
' '), res.end());
477 unsigned int Info::getWeightsDetailedSize() {
478 if (!weights_detailed)
return 0;
479 return weights_detailed->size();
482 double Info::getWeightsDetailedValue(
string n) {
483 if (weights_detailed->empty()
484 || weights_detailed->find(n) == weights_detailed->end())
485 return std::numeric_limits<double>::quiet_NaN();
486 return (*weights_detailed)[n];
489 string Info::getWeightsDetailedAttribute(
string n,
string key,
490 bool doRemoveWhitespace) {
491 if (!rwgt || rwgt->wgts.find(n) == rwgt->wgts.end())
495 res = rwgt->wgts[n].id;
496 }
else if ( rwgt->wgts[n].attributes.find(key)
497 != rwgt->wgts[n].attributes.end() ) {
498 res = rwgt->wgts[n].attributes[key];
500 if (doRemoveWhitespace && res !=
"")
501 res.erase (
remove (res.begin(), res.end(),
' '), res.end());
509 unsigned int Info::getWeightsCompressedSize() {
510 if (!weights_compressed)
return 0;
511 return weights_compressed->size();
514 double Info::getWeightsCompressedValue(
unsigned int n) {
515 if (weights_compressed->empty() || weights_compressed->size() < n+1)
516 return std::numeric_limits<double>::quiet_NaN();
517 return (*weights_compressed)[n];
520 string Info::getWeightsCompressedAttribute(
string key,
521 bool doRemoveWhitespace) {
522 if (!weights || weights->attributes.find(key) == weights->attributes.end())
525 if ( weights->attributes.find(key)
526 != weights->attributes.end() ) {
527 res = weights->attributes[key];
529 if (doRemoveWhitespace && res !=
"")
530 res.erase (
remove (res.begin(), res.end(),
' '), res.end());
538 string Info::getScalesValue(
bool doRemoveWhitespace) {
539 if (!scales)
return "";
540 string res = scales->contents;
541 if (doRemoveWhitespace && res !=
"")
542 res.erase (
remove (res.begin(), res.end(),
' '), res.end());
546 double Info::getScalesAttribute(
string key) {
547 if (!scales)
return std::numeric_limits<double>::quiet_NaN();
548 double res = std::numeric_limits<double>::quiet_NaN();
551 }
else if ( key ==
"mur") {
553 }
else if ( key ==
"mups") {
555 }
else if ( key ==
"SCALUP") {
556 res = scales->SCALUP;
557 }
else if ( scales->attributes.find(key)
558 != scales->attributes.end() ) {
559 res = scales->attributes[key];