StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Info.cc
1 // Info.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2018 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // Function definitions (not found in the header) for the Info class.
7 
8 #include "Pythia8/Info.h"
9 #include <limits>
10 
11 namespace Pythia8 {
12 
13 //==========================================================================
14 
15 // Info class.
16 // This class contains a mixed bag of information on the event generation
17 // activity, especially on the current subprocess properties.
18 
19 //--------------------------------------------------------------------------
20 
21 // Constants: could be changed here if desired, but normally should not.
22 // These are of technical nature, as described for each.
23 
24 // Number of times the same error message will be repeated at most.
25 const int Info::TIMESTOPRINT = 1;
26 
27 // LHA convention with cross section in pb may require conversion from mb.
28 const double Info::CONVERTMB2PB = 1e9;
29 
30 //--------------------------------------------------------------------------
31 
32 // List (almost) all information currently set.
33 
34 void Info::list() const {
35 
36  // Header and beam info.
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)
42  << mASave << ".\n"
43  << " Beam B: id = " << setw(6) << idBSave << ", pz = " << setw(10)
44  << pzBSave << ", e = " << setw(10) << eBSave << ", m = " << setw(10)
45  << mBSave << ".\n\n";
46 
47  // Done if no subprocess has been defined.
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;
52  return;
53  }
54 
55  // Colliding parton info.
56  if (isRes) {
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]
62  << " at same Q2.\n";
63  bool matchIdX = true;
64  if (id1pdfSave[0] != id1Save[0] || id2pdfSave[0] != id2Save[0])
65  matchIdX = false;
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";
70  cout << "\n";
71  }
72 
73  // Process name and code.
74  cout << ((isRes && !hasSubSave[0]) ? " Subprocess " : " Process ")
75  << nameSave << " with code " << codeSave << " is 2 -> "
76  << nFinalSave << ".\n";
77 
78  // Subprocess name and code for nondiffractive processes.
79  if (hasSubSave[0])
80  cout << " Subprocess " << nameSubSave[0] << " with code " << codeSubSave[0]
81  << " is 2 -> " << nFinalSubSave[0] << ".\n";
82 
83  // Process-type-specific kinematics information.
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)
99  << phiH[0] << ".\n";
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";
107 
108  // Couplings.
109  if (isRes) cout << " alphaEM = " << setw(10) << alphaEMSave[0]
110  << ", alphaS = " << setw(10) << alphaSSave[0] << " at Q2 = "
111  << setw(10) << Q2RenSave[0] << ".\n";
112 
113  // Diffractive subsystems.
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";
135  }
136  cout << " alphaEM = " << setw(10) << alphaEMSave[iDS]
137  << ", alphaS = " << setw(10) << alphaSSave[iDS] << " at Q2 = "
138  << setw(10) << Q2RenSave[iDS] << ".\n";
139  }
140 
141  // Impact parameter.
142  if (bIsSet) cout << "\n Impact parameter b = " << setw(10) << bMPISave
143  << " gives enhancement factor = " << setw(10) << enhanceMPISave
144  << ".\n";
145 
146  // Multiparton interactions and shower evolution.
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
152  << ".\n";
153 
154  // Listing finished.
155  cout << "\n -------- End PYTHIA Info Listing --------------------"
156  << "----------------" << endl;
157 
158 }
159 
160 //--------------------------------------------------------------------------
161 
162 // Event weights and accumulated weight.
163 
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;
168 }
169 
170 double Info::weightSum() const {
171  return (abs(lhaStrategySave) == 4) ? CONVERTMB2PB * wtAccSum : wtAccSum;
172 }
173 //--------------------------------------------------------------------------
174 
175 // Uncertainty variations initialization
176 
177 void Info::initUncertainties(vector<string>* variationListIn, bool isISR) {
178  size_t vNames = weightLabelSave.size();
179  externalVariations.clear();
180  externalVarNames.clear();
181  externalGroupNames.clear();
182  externalMap.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) {
188  string line = *v;
189  // Remove initial blank spaces
190  while (line.find(" ") == 0) line.erase( 0, 1);
191  size_t pos=0;
192  // Search for pdf:family keyword for SpaceShower
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());
201  nMember.append(" ");
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(" ")));
208  }
209  }
210  } else {
211  externalVariations.push_back(line);
212  initialNameSave.push_back(line.substr(0,line.find_first_of(" ")));
213  }
214  }
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);
228  size_t pos = 0;
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);
233  }
234  if (uVarString == "" || uVarString == " ") continue;
235  externalVarNames[iWeight].push_back(uVarString);
236  }
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")
245  != string::npos ) {
246  externalMap[iV].push_back(iWeight);
247  }
248  }
249  }
250  }
251 }
252 
253 //--------------------------------------------------------------------------
254 
255 // List of all hard processes switched on.
256 
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 );
262  return codesNow;
263 }
264 
265 //--------------------------------------------------------------------------
266 
267 // Print a message the first few times. Insert in database.
268 
269  void Info::errorMsg(string messageIn, string extraIn, bool showAlways) {
270 
271  // Recover number of times message occured. Also inserts new string.
272  int times = messages[messageIn];
273  ++messages[messageIn];
274 
275  // Print message the first few times.
276  if (times < TIMESTOPRINT || showAlways) cout << " PYTHIA "
277  << messageIn << " " << extraIn << endl;
278 
279 }
280 
281 //--------------------------------------------------------------------------
282 
283 // Provide total number of errors/aborts/warnings experienced to date.
284 
285 int Info::errorTotalNumber() {
286 
287  int nTot = 0;
288  for ( map<string, int>::iterator messageEntry = messages.begin();
289  messageEntry != messages.end(); ++messageEntry)
290  nTot += messageEntry->second;
291  return nTot;
292 
293 }
294 
295 //--------------------------------------------------------------------------
296 
297 // Print statistics on errors/aborts/warnings.
298 
299 void Info::errorStatistics() {
300 
301  // Header.
302  cout << "\n *------- PYTHIA Error and Warning Messages Statistics "
303  << "----------------------------------------------------------* \n"
304  << " | "
305  << " | \n"
306  << " | times message "
307  << " | \n"
308  << " | "
309  << " | \n";
310 
311  // Loop over all messages
312  map<string, int>::iterator messageEntry = messages.begin();
313  if (messageEntry == messages.end())
314  cout << " | 0 no errors or warnings to report "
315  << " | \n";
316  while (messageEntry != messages.end()) {
317  // Message printout.
318  string temp = messageEntry->first;
319  int len = temp.length();
320  temp.insert( len, max(0, 102 - len), ' ');
321  cout << " | " << setw(6) << messageEntry->second << " "
322  << temp << " | \n";
323  ++messageEntry;
324  }
325 
326  // Done.
327  cout << " | "
328  << " | \n"
329  << " *------- End PYTHIA Error and Warning Messages Statistics"
330  << " ------------------------------------------------------* "
331  << endl;
332 
333 }
334 
335 //--------------------------------------------------------------------------
336 
337 // Return a list of all header key names
338 
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);
344  return keys;
345 }
346 
347 //--------------------------------------------------------------------------
348 
349 // Reset the LHEF3 objects read from the init and header blocks.
350 
351 void Info::setLHEF3InitInfo() {
352  initrwgt = 0;
353  generators = 0;
354  weightgroups = 0;
355  init_weights = 0;
356  headerBlock = "";
357 }
358 
359 //--------------------------------------------------------------------------
360 
361 // Set the LHEF3 objects read from the init and header blocks.
362 
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;
373 }
374 
375 //--------------------------------------------------------------------------
376 
377 // Reset the LHEF3 objects read from the event block.
378 
379 void Info::setLHEF3EventInfo() {
380  eventAttributes = 0;
381  weights_detailed = 0;
382  weights_compressed = 0;
383  scales = 0;
384  weights = 0;
385  rwgt = 0;
386  weights_detailed_vector.resize(0);
387  eventComments = "";
388  eventWeightLHEF = 1.0;
389 }
390 
391 //--------------------------------------------------------------------------
392 
393 // Set the LHEF3 objects read from the event block.
394 
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;
404  scales = scalesIn;
405  weights = weightsIn;
406  rwgt = rwgtIn;
407  weights_detailed_vector = weights_detailed_vecIn;
408  eventComments = eventCommentsIn;
409  eventWeightLHEF = eventWeightLHEFIn;
410 }
411 
412 //--------------------------------------------------------------------------
413 
414 // Retrieve events tag information.
415 
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());
422  return res;
423  }
424  return "";
425 }
426 
427 //--------------------------------------------------------------------------
428 
429 // Retrieve LHEF version.
430 
431 int Info::LHEFversion() { return LHEFversionSave;}
432 
433 //--------------------------------------------------------------------------
434 
435 // Retrieve initrwgt tag information.
436 
437 unsigned int Info::getInitrwgtSize() {
438  if (!initrwgt) return 0;
439  return initrwgt->weights.size();
440 }
441 
442 //--------------------------------------------------------------------------
443 
444 // Retrieve generator tag information.
445 
446 unsigned int Info::getGeneratorSize() {
447  if (!generators) return 0;
448  return generators->size();
449 }
450 
451 string Info::getGeneratorValue(unsigned int n) {
452  if (!generators || generators->size() < n+1) return "";
453  return (*generators)[n].contents;
454 }
455 
456 string Info::getGeneratorAttribute( unsigned int n, string key,
457  bool doRemoveWhitespace) {
458  if (!generators || generators->size() < n+1) return "";
459  string res("");
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];
467  }
468  if (doRemoveWhitespace && res != "")
469  res.erase (remove (res.begin(), res.end(), ' '), res.end());
470  return res;
471 }
472 
473 //--------------------------------------------------------------------------
474 
475 // Retrieve rwgt tag information.
476 
477 unsigned int Info::getWeightsDetailedSize() {
478  if (!weights_detailed) return 0;
479  return weights_detailed->size();
480 }
481 
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];
487 }
488 
489 string Info::getWeightsDetailedAttribute(string n, string key,
490  bool doRemoveWhitespace) {
491  if (!rwgt || rwgt->wgts.find(n) == rwgt->wgts.end())
492  return "";
493  string res("");
494  if ( key == "id") {
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];
499  }
500  if (doRemoveWhitespace && res != "")
501  res.erase (remove (res.begin(), res.end(), ' '), res.end());
502  return res;
503 }
504 
505 //--------------------------------------------------------------------------
506 
507 // Retrieve weights tag information.
508 
509 unsigned int Info::getWeightsCompressedSize() {
510  if (!weights_compressed) return 0;
511  return weights_compressed->size();
512 }
513 
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];
518 }
519 
520 string Info::getWeightsCompressedAttribute(string key,
521  bool doRemoveWhitespace) {
522  if (!weights || weights->attributes.find(key) == weights->attributes.end())
523  return "";
524  string res("");
525  if ( weights->attributes.find(key)
526  != weights->attributes.end() ) {
527  res = weights->attributes[key];
528  }
529  if (doRemoveWhitespace && res != "")
530  res.erase (remove (res.begin(), res.end(), ' '), res.end());
531  return res;
532 }
533 
534 //--------------------------------------------------------------------------
535 
536 // Retrieve scales tag information.
537 
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());
543  return res;
544 }
545 
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();
549  if ( key == "muf") {
550  res = scales->muf;
551  } else if ( key == "mur") {
552  res = scales->mur;
553  } else if ( key == "mups") {
554  res = scales->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];
560  }
561  return res;
562 }
563 
564 //==========================================================================
565 
566 } // end namespace Pythia8