StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Info.h
1 // Info.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 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 // This file contains classes that keep track of generic event info.
7 // Info: contains information on the generation process and errors.
8 // Info: user interface to make parts of Info publicly available.
9 
10 #ifndef Pythia8_Info_H
11 #define Pythia8_Info_H
12 
13 #include "Pythia8/Basics.h"
14 #include "Pythia8/LHEF3.h"
15 #include "Pythia8/PythiaStdlib.h"
16 #include "Pythia8/SharedPointers.h"
17 #include "Pythia8/Weights.h"
18 
19 namespace Pythia8 {
20 
21 // Forward declaration of various classes.
22 class Settings;
23 class ParticleData;
24 class Rndm;
25 class CoupSM;
26 class CoupSUSY;
27 class BeamParticle;
28 class PartonSystems;
29 class SigmaTotal;
30 class HadronWidths;
31 
32 // Forward declaration of HIInfo class.
33 class HIInfo;
34 
35 //==========================================================================
36 
37 // The Info class contains a mixed bag of information on the event
38 // generation activity, especially on the current subprocess properties,
39 // and on the number of errors encountered. This is used by the
40 // generation machinery.
41 
42 class Info {
43 
44 public:
45 
46  // Constructors.
47  Info() = default;
48  Info(bool) : Info() {}
49 
50  // Destructor for clean-up.
51  ~Info() {
52  if (hasOwnEventAttributes && eventAttributes != nullptr)
53  delete eventAttributes;
54  }
55 
56  // Assignment operator gives a shallow copy; no objects pointed to
57  // are copied.
58  Info & operator=(const Info &) = default;
59 
60  // Pointers to other class objects, carried piggyback by Info.
61 
62  // Set pointers to other class objects.
63  void setPtrs(Settings* settingsPtrIn, ParticleData* particleDataPtrIn,
64  Rndm* rndmPtrIn, CoupSM* coupSMPtrIn, CoupSUSY* coupSUSYPtrIn,
65  BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn,
66  BeamParticle* beamPomAPtrIn, BeamParticle* beamPomBPtrIn,
67  BeamParticle* beamGamAPtrIn, BeamParticle* beamGamBPtrIn,
68  BeamParticle* beamVMDAPtrIn, BeamParticle* beamVMDBPtrIn,
69  PartonSystems* partonSystemsPtrIn, SigmaTotal* sigmaTotPtrIn,
70  HadronWidths* hadronWidthsPtrIn,
71  WeightContainer* weightContainerPtrIn) {
72  settingsPtr = settingsPtrIn; particleDataPtr = particleDataPtrIn;
73  rndmPtr = rndmPtrIn; coupSMPtr = coupSMPtrIn; coupSUSYPtr = coupSUSYPtrIn;
74  beamAPtr = beamAPtrIn; beamBPtr = beamBPtrIn;
75  beamPomAPtr = beamPomAPtrIn; beamPomBPtr = beamPomBPtrIn;
76  beamGamAPtr = beamGamAPtrIn; beamGamBPtr = beamGamBPtrIn;
77  beamVMDAPtr = beamVMDAPtrIn; beamVMDBPtr = beamVMDBPtrIn;
78  partonSystemsPtr = partonSystemsPtrIn; sigmaTotPtr = sigmaTotPtrIn;
79  hadronWidthsPtr = hadronWidthsPtrIn;
80  weightContainerPtr = weightContainerPtrIn; }
81 
82  // Pointer to the settings database.
83  Settings* settingsPtr{};
84 
85  // Pointer to the particle data table.
86  ParticleData* particleDataPtr{};
87 
88  // Pointer to the random number generator.
89  Rndm* rndmPtr{};
90 
91  // Pointers to Standard Model and Beyond SM couplings.
92  CoupSM* coupSMPtr{};
93  CoupSUSY* coupSUSYPtr{};
94 
95  // Pointers to the two incoming beams and to Pomeron, photon or VMD
96  // beam-inside-beam cases.
97  BeamParticle* beamAPtr{};
98  BeamParticle* beamBPtr{};
99  BeamParticle* beamPomAPtr{};
100  BeamParticle* beamPomBPtr{};
101  BeamParticle* beamGamAPtr{};
102  BeamParticle* beamGamBPtr{};
103  BeamParticle* beamVMDAPtr{};
104  BeamParticle* beamVMDBPtr{};
105 
106  // Pointer to information on subcollision parton locations.
107  PartonSystems* partonSystemsPtr{};
108 
109  // Pointer to the total/elastic/diffractive cross sections.
110  SigmaTotal* sigmaTotPtr{};
111 
112  // Pointer to the hadron widths data table.
113  HadronWidths* hadronWidthsPtr;
114 
115  // Pointer to the UserHooks object set for the run.
116  UserHooksPtr userHooksPtr{};
117 
118  // Pointer to information about a HeavyIons run and the current event.
119  // (Is NULL if HeavyIons object is inactive.)
120  HIInfo* hiInfo{};
121 
122  WeightContainer* weightContainerPtr{};
123 
124  // Listing of most available information on current event.
125  void list() const;
126 
127  // Beam particles (in rest frame). CM energy of event.
128  int idA() const {return idASave;}
129  int idB() const {return idBSave;}
130  double pzA() const {return pzASave;}
131  double pzB() const {return pzBSave;}
132  double eA() const {return eASave;}
133  double eB() const {return eBSave;}
134  double mA() const {return mASave;}
135  double mB() const {return mBSave;}
136  double eCM() const {return eCMSave;}
137  double s() const {return sSave;}
138 
139  // Warnings from initialization.
140  bool tooLowPTmin() const {return lowPTmin;}
141 
142  // Process name and code, and the number of final-state particles.
143  string name() const {return nameSave;}
144  int code() const {return codeSave;}
145  int nFinal() const {return nFinalSave;}
146 
147  // Are beam particles resolved, with pdf's? Are they diffractive?
148  bool isResolved() const {return isRes;}
149  bool isDiffractiveA() const {return isDiffA;}
150  bool isDiffractiveB() const {return isDiffB;}
151  bool isDiffractiveC() const {return isDiffC;}
152  bool isNonDiffractive() const {return isND;}
153  bool isElastic() const {return (codeSave == 102);}
154  // Retained for backwards compatibility.
155  bool isMinBias() const {return isND;}
156 
157  // Information for Les Houches Accord and reading files.
158  bool isLHA() const {return isLH;}
159  bool atEndOfFile() const {return atEOF;}
160 
161  // For nondiffractive and Les Houches Accord identify hardest subprocess.
162  bool hasSub(int i = 0) const {return hasSubSave[i];}
163  string nameSub(int i = 0) const {return nameSubSave[i];}
164  int codeSub(int i = 0) const {return codeSubSave[i];}
165  int nFinalSub(int i = 0) const {return nFinalSubSave[i];}
166 
167  // Incoming parton flavours and x values.
168  int id1(int i = 0) const {return id1Save[i];}
169  int id2(int i = 0) const {return id2Save[i];}
170  double x1(int i = 0) const {return x1Save[i];}
171  double x2(int i = 0) const {return x2Save[i];}
172  double y(int i = 0) const {return 0.5 * log( x1Save[i] / x2Save[i]);}
173  double tau(int i = 0) const {return x1Save[i] * x2Save[i];}
174 
175  // Hard process flavours, x values, parton densities, couplings, Q2 scales.
176  int id1pdf(int i = 0) const {return id1pdfSave[i];}
177  int id2pdf(int i = 0) const {return id2pdfSave[i];}
178  double x1pdf(int i = 0) const {return x1pdfSave[i];}
179  double x2pdf(int i = 0) const {return x2pdfSave[i];}
180  double pdf1(int i = 0) const {return pdf1Save[i];}
181  double pdf2(int i = 0) const {return pdf2Save[i];}
182  double QFac(int i = 0) const {return sqrtpos(Q2FacSave[i]);}
183  double Q2Fac(int i = 0) const {return Q2FacSave[i];}
184  bool isValence1() const {return isVal1;}
185  bool isValence2() const {return isVal2;}
186  double alphaS(int i = 0) const {return alphaSSave[i];}
187  double alphaEM(int i = 0) const {return alphaEMSave[i];}
188  double QRen(int i = 0) const {return sqrtpos(Q2RenSave[i]);}
189  double Q2Ren(int i = 0) const {return Q2RenSave[i];}
190  double scalup(int i = 0) const {return scalupSave[i];}
191 
192  // Kinematics of photons from lepton beams.
193  double xGammaA() const {return x1GammaSave;}
194  double xGammaB() const {return x2GammaSave;}
195  double Q2GammaA() const {return Q2Gamma1Save;}
196  double Q2GammaB() const {return Q2Gamma2Save;}
197  double eCMsub() const {return eCMsubSave;}
198  double thetaScatLepA() const {return thetaLepton1;}
199  double thetaScatLepB() const {return thetaLepton2;}
200  double sHatNew() const {return sHatNewSave;}
201  int photonMode() const {return gammaModeEvent;}
202 
203  // Information on VMD state inside a photon.
204  bool isVMDstateA() const {return isVMDstateAEvent;}
205  bool isVMDstateB() const {return isVMDstateBEvent;}
206  int idVMDA() const {return idVMDASave;}
207  int idVMDB() const {return idVMDBSave;}
208  double mVMDA() const {return mVMDASave;}
209  double mVMDB() const {return mVMDBSave;}
210  double scaleVMDA() const {return scaleVMDASave;}
211  double scaleVMDB() const {return scaleVMDBSave;}
212 
213  // Mandelstam variables (notation as if subcollision).
214  double mHat(int i = 0) const {return sqrt(sH[i]);}
215  double sHat(int i = 0) const {return sH[i];}
216  double tHat(int i = 0) const {return tH[i];}
217  double uHat(int i = 0) const {return uH[i];}
218  double pTHat(int i = 0) const {return pTH[i];}
219  double pT2Hat(int i = 0) const {return pTH[i] * pTH[i];}
220  double m3Hat(int i = 0) const {return m3H[i];}
221  double m4Hat(int i = 0) const {return m4H[i];}
222  double thetaHat(int i = 0) const {return thetaH[i];}
223  double phiHat(int i = 0) const {return phiH[i];}
224 
225  // Weight of current event; normally 1, but used for Les Houches events
226  // or when reweighting phase space selection. Conversion from mb to pb
227  // for LHA strategy +-4. Uncertainty variations can be accessed by
228  // providing an index >= 1 (0 = no variations). Also cumulative sum.
229  double weight(int i = 0) const;
230  double weightSum() const;
231  double lhaStrategy() const {return lhaStrategySave;}
232 
233  // Further access to uncertainty weights: number and labels
234  int nWeights() const
235  { return weightContainerPtr->weightsPS.getWeightsSize(); }
236  string weightLabel(int iWeight) const {
237  return weightContainerPtr->weightsPS.getWeightsName(iWeight);
238  }
239 
240  int nVariationGroups() const { return weightContainerPtr->
241  weightsPS.externalVariations.size(); }
242  string getGroupName(int iGN) const {
243  return weightContainerPtr->weightsPS.getGroupName(iGN);
244  }
245  double getGroupWeight(int iGW) const {
246  return weightContainerPtr->weightsPS.getGroupWeight(iGW)
247  *weightContainerPtr->weightNominal;
248  }
249 
250  // Number of times other steps have been carried out.
251  int nISR() const {return nISRSave;}
252  int nFSRinProc() const {return nFSRinProcSave;}
253  int nFSRinRes() const {return nFSRinResSave;}
254 
255  // Maximum pT scales for MPI, ISR and FSR (in hard process).
256  double pTmaxMPI() const {return pTmaxMPISave;}
257  double pTmaxISR() const {return pTmaxISRSave;}
258  double pTmaxFSR() const {return pTmaxFSRSave;}
259 
260  // Current evolution scale (for UserHooks).
261  double pTnow() const {return pTnowSave;}
262 
263  // Impact parameter picture, global information
264  double a0MPI() const {return a0MPISave;}
265 
266  // Impact parameter picture, as set by hardest interaction.
267  double bMPI() const {return (bIsSet) ? bMPISave : 1.;}
268  double enhanceMPI() const {return (bIsSet) ? enhanceMPISave : 1.;}
269  double enhanceMPIavg() const {return (bIsSet) ? enhanceMPIavgSave : 1.;}
270  double eMPI(int i) const {return (bIsSet) ? eMPISave[i] : 1.;}
271  double bMPIold() const {return (bIsSet) ? bMPIoldSave : 1.;}
272  double enhanceMPIold() const {return (bIsSet) ? enhanceMPIoldSave : 1.;}
273  double enhanceMPIoldavg() const {return (bIsSet)
274  ? enhanceMPIoldavgSave : 1.;}
275 
276  // Number of multiparton interactions, with code and pT for them.
277  int nMPI() const {return nMPISave;}
278  int codeMPI(int i) const {return codeMPISave[i];}
279  double pTMPI(int i) const {return pTMPISave[i];}
280  int iAMPI(int i) const {return iAMPISave[i];}
281  int iBMPI(int i) const {return iBMPISave[i];}
282 
283  // Cross section estimate, optionally process by process.
284  vector<int> codesHard();
285  string nameProc(int i = 0) const {return (i == 0) ? "sum"
286  : ( (procNameM.at(i) == "") ? "unknown process" : procNameM.at(i) );}
287  long nTried(int i = 0) const {return (i == 0) ? nTry : nTryM.at(i);}
288  long nSelected(int i = 0) const {return (i == 0) ? nSel : nSelM.at(i);}
289  long nAccepted(int i = 0) const {return (i == 0) ? nAcc : nAccM.at(i);}
290  double sigmaGen(int i = 0) const {return (i == 0) ? sigGen : sigGenM.at(i);}
291  double sigmaErr(int i = 0) const {return (i == 0) ? sigErr : sigErrM.at(i);}
292 
293  // Counters for number of loops in various places.
294  int getCounter( int i) const {return counters[i];}
295 
296  // Set or increase the value stored in a counter.
297  void setCounter( int i, int value = 0) {counters[i] = value;}
298  void addCounter( int i, int value = 1) {counters[i] += value;}
299 
300  // Reset to empty map of error messages.
301  void errorReset() {messages.clear();}
302 
303  // Print a message the first few times. Insert in database.
304  void errorMsg(string messageIn, string extraIn = " ",
305  bool showAlways = false);
306 
307  // Provide total number of errors/aborts/warnings experienced to date.
308  int errorTotalNumber() const;
309 
310  // Print statistics on errors/aborts/warnings.
311  void errorStatistics() const;
312 
313  // Set initialization warning flag when too low pTmin in ISR/FSR/MPI.
314  void setTooLowPTmin(bool lowPTminIn) {lowPTmin = lowPTminIn;}
315 
316  // Set info on valence character of hard collision partons.
317  void setValence( bool isVal1In, bool isVal2In) {isVal1 = isVal1In;
318  isVal2 = isVal2In;}
319 
320  // Set and get some MPI/ISR/FSR properties needed for matching,
321  // i.e. mainly of internal relevance.
322  void hasHistory( bool hasHistoryIn) {hasHistorySave = hasHistoryIn;}
323  bool hasHistory() {return hasHistorySave;}
324  void zNowISR( double zNowIn) {zNowISRSave = zNowIn;}
325  double zNowISR() {return zNowISRSave;}
326  void pT2NowISR( double pT2NowIn) {pT2NowISRSave = pT2NowIn;}
327  double pT2NowISR() {return pT2NowISRSave;}
328 
329  // Return merging weight.
330  double mergingWeight(int i=0) const {
331  return weightContainerPtr->weightsMerging.getWeightsValue(i);}
332 
333  // Return the complete NLO weight.
334  double mergingWeightNLO(int i=0) const {
335  return weightContainerPtr->weightsMerging.getWeightsValue(i); }
336 
337  // Return an LHEF header
338  string header(const string &key) const {
339  if (headers.find(key) == headers.end()) return "";
340  else return headers.at(key);
341  }
342 
343  // Return a list of all header key names
344  vector<string> headerKeys() const;
345 
346  // Return the number of processes in the LHEF.
347  int nProcessesLHEF() const { return int(sigmaLHEFSave.size());}
348  // Return the cross section information read from LHEF.
349  double sigmaLHEF(int iProcess) const { return sigmaLHEFSave[iProcess];}
350 
351  // LHEF3 information: Public for easy access.
352  int LHEFversionSave;
353 
354  // Save process information as read from init block of LHEF.
355  vector<double> sigmaLHEFSave;
356 
357  // Contents of the LHAinitrwgt tag
358  LHAinitrwgt *initrwgt{};
359 
360  // Contents of the LHAgenerator tags.
361  vector<LHAgenerator > *generators{};
362 
363  // A map of the LHAweightgroup tags, indexed by name.
364  map<string,LHAweightgroup > *weightgroups{};
365 
366  // A map of the LHAweight tags, indexed by name.
367  map<string,LHAweight > *init_weights{};
368 
369  // Store current-event Les Houches event tags.
370  bool hasOwnEventAttributes{};
371  map<string, string > *eventAttributes{};
372 
373  // The weights associated with this event, as given by the LHAwgt tags
374  map<string,double > *weights_detailed{};
375 
376  // The weights associated with this event, as given by the LHAweights tags
377  vector<double > *weights_compressed{};
378 
379  // Contents of the LHAscales tag.
380  LHAscales *scales{};
381 
382  // Contents of the LHAweights tag (compressed format)
383  LHAweights *weights{};
384 
385  // Contents of the LHArwgt tag (detailed format)
386  LHArwgt *rwgt{};
387 
388  // Vectorized version of LHArwgt tag, for easy and ordered access.
389  vector<double> weights_detailed_vector;
390 
391  // Value of the unit event weight read from a Les Houches event, necessary
392  // if additional weights in an otherwise unweighted input file are in
393  // relation to this number.
394  double eventWeightLHEF = {};
395 
396  // Set the LHEF3 objects read from the init and header blocks.
397  void setLHEF3InitInfo();
398  void setLHEF3InitInfo( int LHEFversionIn, LHAinitrwgt *initrwgtIn,
399  vector<LHAgenerator> *generatorsIn,
400  map<string,LHAweightgroup> *weightgroupsIn,
401  map<string,LHAweight> *init_weightsIn, string headerBlockIn );
402  // Set the LHEF3 objects read from the event block.
403  void setLHEF3EventInfo();
404  void setLHEF3EventInfo( map<string, string> *eventAttributesIn,
405  map<string, double > *weights_detailedIn,
406  vector<double > *weights_compressedIn,
407  LHAscales *scalesIn, LHAweights *weightsIn,
408  LHArwgt *rwgtIn, vector<double> weights_detailed_vecIn,
409  vector<string> weights_detailed_name_vecIn,
410  string eventCommentsIn, double eventWeightLHEFIn );
411 
412  // Retrieve events tag information.
413  string getEventAttribute(string key, bool doRemoveWhitespace = false) const;
414 
415  // Externally set event tag auxiliary information.
416  void setEventAttribute(string key, string value, bool doOverwrite = true) {
417  if (eventAttributes == NULL) {
418  eventAttributes = new map<string,string>();
419  hasOwnEventAttributes = true;
420  }
421  map<string, string>::iterator it = eventAttributes->find(key);
422  if ( it != eventAttributes->end() && !doOverwrite ) return;
423  if ( it != eventAttributes->end() ) eventAttributes->erase(it);
424  eventAttributes->insert(make_pair(key,value));
425  }
426 
427  // Retrieve LHEF version
428  int LHEFversion() const { return LHEFversionSave; }
429 
430  // Retrieve initrwgt tag information.
431  unsigned int getInitrwgtSize() const;
432 
433  // Retrieve generator tag information.
434  unsigned int getGeneratorSize() const;
435  string getGeneratorValue(unsigned int n = 0) const;
436  string getGeneratorAttribute( unsigned int n, string key,
437  bool doRemoveWhitespace = false) const;
438 
439  // Retrieve rwgt tag information.
440  unsigned int getWeightsDetailedSize() const;
441  double getWeightsDetailedValue(string n) const;
442  string getWeightsDetailedAttribute(string n, string key,
443  bool doRemoveWhitespace = false) const;
444 
445  // Retrieve weights tag information.
446  unsigned int getWeightsCompressedSize() const;
447  double getWeightsCompressedValue(unsigned int n) const;
448  string getWeightsCompressedAttribute(string key,
449  bool doRemoveWhitespace = false) const;
450 
451  // Retrieve scales tag information.
452  string getScalesValue(bool doRemoveWhitespace = false) const;
453  double getScalesAttribute(string key) const;
454 
455  // Retrieve complete header block and event comments
456  // Retrieve scales tag information.
457  string getHeaderBlock() const { return headerBlock;}
458  string getEventComments() const { return eventComments;}
459 
460  // Set LHEF headers
461  void setHeader(const string &key, const string &val)
462  { headers[key] = val; }
463 
464  // Set abort in parton level.
465  void setAbortPartonLevel(bool abortIn) {abortPartonLevel = abortIn;}
466  bool getAbortPartonLevel() const {return abortPartonLevel;}
467 
468  // Get information on hard diffractive events.
469  bool hasUnresolvedBeams() const {return hasUnresBeams;}
470  bool hasPomPsystem() const {return hasPomPsys;}
471  bool isHardDiffractive() const {return isHardDiffA || isHardDiffB;}
472  bool isHardDiffractiveA() const {return isHardDiffA;}
473  bool isHardDiffractiveB() const {return isHardDiffB;}
474  double xPomeronA() const {return xPomA;}
475  double xPomeronB() const {return xPomB;}
476  double tPomeronA() const {return tPomA;}
477  double tPomeronB() const {return tPomB;}
478 
479  // History information needed to setup the weak shower for 2 -> n.
480  vector<int> getWeakModes() const {return weakModes;}
481  vector<pair<int,int> > getWeakDipoles() const {return weakDipoles;}
482  vector<Vec4> getWeakMomenta() const {return weakMomenta;}
483  vector<int> getWeak2to2lines() const {return weak2to2lines;}
484  void setWeakModes(vector<int> weakModesIn) {weakModes = weakModesIn;}
485  void setWeakDipoles(vector<pair<int,int> > weakDipolesIn)
486  {weakDipoles = weakDipolesIn;}
487  void setWeakMomenta(vector<Vec4> weakMomentaIn)
488  {weakMomenta = weakMomentaIn;}
489  void setWeak2to2lines(vector<int> weak2to2linesIn)
490  {weak2to2lines = weak2to2linesIn;}
491 
492  // From here on what used to be the private part of the class.
493 
494  // Number of times the same error message is repeated, unless overridden.
495  static const int TIMESTOPRINT;
496 
497  // Allow conversion from mb to pb.
498  static const double CONVERTMB2PB;
499 
500  // Store common beam quantities.
501  int idASave{}, idBSave{};
502  double pzASave{}, eASave{}, mASave{}, pzBSave{}, eBSave{}, mBSave{},
503  eCMSave{}, sSave{};
504 
505  // Store initialization information.
506  bool lowPTmin;
507 
508  // Store common integrated cross section quantities.
509  long nTry{}, nSel{}, nAcc{};
510  double sigGen{}, sigErr{}, wtAccSum{};
511  map<int, string> procNameM;
512  map<int, long> nTryM, nSelM, nAccM;
513  map<int, double> sigGenM, sigErrM;
514  int lhaStrategySave{};
515 
516  // Store common MPI information.
517  double a0MPISave;
518 
519  // Store current-event quantities.
520  bool isRes{}, isDiffA{}, isDiffB{}, isDiffC{}, isND{}, isLH{},
521  hasSubSave[4], bIsSet{}, evolIsSet{}, atEOF{}, isVal1{}, isVal2{},
522  hasHistorySave{}, abortPartonLevel{}, isHardDiffA{}, isHardDiffB{},
523  hasUnresBeams{}, hasPomPsys{};
524  int codeSave{}, codeSubSave[4], nFinalSave{}, nFinalSubSave[4], nTotal{},
525  id1Save[4], id2Save[4], id1pdfSave[4], id2pdfSave[4], nMPISave{},
526  nISRSave{}, nFSRinProcSave{}, nFSRinResSave{};
527  double x1Save[4], x2Save[4], x1pdfSave[4], x2pdfSave[4], pdf1Save[4],
528  pdf2Save[4], Q2FacSave[4], alphaEMSave[4], alphaSSave[4],
529  Q2RenSave[4], scalupSave[4], sH[4], tH[4], uH[4], pTH[4], m3H[4],
530  m4H[4], thetaH[4], phiH[4], bMPISave{}, enhanceMPISave{},
531  enhanceMPIavgSave{}, bMPIoldSave{}, enhanceMPIoldSave{},
532  enhanceMPIoldavgSave{}, pTmaxMPISave{}, pTmaxISRSave{},
533  pTmaxFSRSave{}, pTnowSave{}, zNowISRSave{}, pT2NowISRSave{}, xPomA{},
534  xPomB{}, tPomA{}, tPomB{};
535  string nameSave{}, nameSubSave[4];
536  vector<int> codeMPISave, iAMPISave, iBMPISave;
537  vector<double> pTMPISave, eMPISave;
538 
539  // Variables related to photon kinematics.
540  bool isVMDstateAEvent{}, isVMDstateBEvent{};
541  int gammaModeEvent{}, idVMDASave{}, idVMDBSave{};
542  double x1GammaSave{}, x2GammaSave{}, Q2Gamma1Save{}, Q2Gamma2Save{},
543  eCMsubSave{}, thetaLepton1{}, thetaLepton2{}, sHatNewSave{},
544  mVMDASave{}, mVMDBSave{}, scaleVMDASave{}, scaleVMDBSave{};
545 
546  // Vector of various loop counters.
547  int counters[50];
548 
549  // Map for all error messages.
550  map<string, int> messages;
551 
552  // Map for LHEF headers.
553  map<string, string> headers;
554 
555  // Strings for complete header block and event comments.
556  string headerBlock{}, eventComments{};
557 
558  // Map for plugin libraries.
559  map<string, PluginPtr> plugins;
560 
561  // Load a plugin library.
562  PluginPtr plugin(string nameIn) {
563  map<string, PluginPtr>::iterator pluginItr = plugins.find(nameIn);
564  if (pluginItr == plugins.end()) {
565  PluginPtr pluginPtr = make_shared<Plugin>(nameIn, this);
566  plugins[nameIn] = pluginPtr;
567  return pluginPtr;
568  } else return pluginItr->second;
569  };
570 
571  // Set info on the two incoming beams: only from Pythia class.
572  void setBeamA( int idAin, double pzAin, double eAin, double mAin) {
573  idASave = idAin; pzASave = pzAin; eASave = eAin; mASave = mAin;}
574  void setBeamB( int idBin, double pzBin, double eBin, double mBin) {
575  idBSave = idBin; pzBSave = pzBin; eBSave = eBin; mBSave = mBin;}
576  void setECM( double eCMin) {eCMSave = eCMin; sSave = eCMSave * eCMSave;}
577 
578  // Set info related to gamma+gamma subcollision.
579  void setX1Gamma( double x1GammaIn) { x1GammaSave = x1GammaIn; }
580  void setX2Gamma( double x2GammaIn) { x2GammaSave = x2GammaIn; }
581  void setQ2Gamma1( double Q2gammaIn) { Q2Gamma1Save = Q2gammaIn; }
582  void setQ2Gamma2( double Q2gammaIn) { Q2Gamma2Save = Q2gammaIn; }
583  void setTheta1( double theta1In) { thetaLepton1 = theta1In; }
584  void setTheta2( double theta2In) { thetaLepton2 = theta2In; }
585  void setECMsub( double eCMsubIn) { eCMsubSave = eCMsubIn; }
586  void setsHatNew( double sHatNewIn) { sHatNewSave = sHatNewIn; }
587  void setGammaMode( double gammaModeIn) { gammaModeEvent = gammaModeIn; }
588  // Set info on VMD state.
589  void setVMDstateA(bool isVMDAIn, int idAIn, double mAIn, double scaleAIn)
590  {isVMDstateAEvent = isVMDAIn; idVMDASave = idAIn; mVMDASave = mAIn;
591  scaleVMDASave = scaleAIn;}
592  void setVMDstateB(bool isVMDBIn, int idBIn, double mBIn, double scaleBIn)
593  {isVMDstateBEvent = isVMDBIn; idVMDBSave = idBIn; mVMDBSave = mBIn;
594  scaleVMDBSave = scaleBIn;}
595 
596  // Reset info for current event: only from Pythia class.
597  void clear() {
598  isRes = isDiffA = isDiffB = isDiffC = isND = isLH = bIsSet
599  = evolIsSet = atEOF = isVal1 = isVal2 = hasHistorySave
600  = isHardDiffA = isHardDiffB = hasUnresBeams = hasPomPsys = false;
601  codeSave = nFinalSave = nTotal = nMPISave = nISRSave = nFSRinProcSave
602  = nFSRinResSave = 0;
603  bMPISave = enhanceMPISave = enhanceMPIavgSave = bMPIoldSave
604  = enhanceMPIoldSave = enhanceMPIoldavgSave = 1.;
605  pTmaxMPISave = pTmaxISRSave = pTmaxFSRSave = pTnowSave = zNowISRSave
606  = pT2NowISRSave = 0.;
607  nameSave = " ";
608  for (int i = 0; i < 4; ++i) {
609  hasSubSave[i] = false;
610  codeSubSave[i] = nFinalSubSave[i] = id1pdfSave[i] = id2pdfSave[i]
611  = id1Save[i] = id2Save[i] = 0;
612  x1pdfSave[i] = x2pdfSave[i] = pdf1Save[i] = pdf2Save[i]
613  = Q2FacSave[i] = alphaEMSave[i] = alphaSSave[i] = Q2RenSave[i]
614  = scalupSave[i] = x1Save[i] = x2Save[i] = sH[i] = tH[i] = uH[i]
615  = pTH[i] = m3H[i] = m4H[i] = thetaH[i] = phiH[i] = 0.;
616  nameSubSave[i] = " ";
617  }
618  codeMPISave.resize(0); iAMPISave.resize(0); iBMPISave.resize(0);
619  pTMPISave.resize(0); eMPISave.resize(0); setHardDiff();
620  weightContainerPtr->clear();
621  }
622 
623  // Reset info arrays only for parton and hadron level.
624  int sizeMPIarrays() const { return codeMPISave.size(); }
625  void resizeMPIarrays(int newSize) { codeMPISave.resize(newSize);
626  iAMPISave.resize(newSize); iBMPISave.resize(newSize);
627  pTMPISave.resize(newSize); eMPISave.resize(newSize); }
628 
629  // Set info on the (sub)process: from ProcessLevel, ProcessContainer or
630  // MultipartonInteractions classes.
631  void setType( string nameIn, int codeIn, int nFinalIn,
632  bool isNonDiffIn = false, bool isResolvedIn = true,
633  bool isDiffractiveAin = false, bool isDiffractiveBin = false,
634  bool isDiffractiveCin = false, bool isLHAin = false) {
635  nameSave = nameIn; codeSave = codeIn; nFinalSave = nFinalIn;
636  isND = isNonDiffIn; isRes = isResolvedIn; isDiffA = isDiffractiveAin;
637  isDiffB = isDiffractiveBin; isDiffC = isDiffractiveCin; isLH = isLHAin;
638  nTotal = 2 + nFinalSave; bIsSet = false; hasSubSave[0] = false;
639  nameSubSave[0] = " "; codeSubSave[0] = 0; nFinalSubSave[0] = 0;
640  evolIsSet = false;}
641  void setSubType( int iDS, string nameSubIn, int codeSubIn,
642  int nFinalSubIn) { hasSubSave[iDS] = true; nameSubSave[iDS] = nameSubIn;
643  codeSubSave[iDS] = codeSubIn; nFinalSubSave[iDS] = nFinalSubIn;}
644  void setPDFalpha( int iDS, int id1pdfIn, int id2pdfIn, double x1pdfIn,
645  double x2pdfIn, double pdf1In, double pdf2In, double Q2FacIn,
646  double alphaEMIn, double alphaSIn, double Q2RenIn, double scalupIn) {
647  id1pdfSave[iDS] = id1pdfIn; id2pdfSave[iDS] = id2pdfIn;
648  x1pdfSave[iDS] = x1pdfIn; x2pdfSave[iDS] = x2pdfIn;
649  pdf1Save[iDS] = pdf1In; pdf2Save[iDS] = pdf2In; Q2FacSave[iDS] = Q2FacIn;
650  alphaEMSave[iDS] = alphaEMIn; alphaSSave[iDS] = alphaSIn;
651  Q2RenSave[iDS] = Q2RenIn; scalupSave[iDS] = scalupIn;}
652  void setScalup( int iDS, double scalupIn) {scalupSave[iDS] = scalupIn;}
653  void setKin( int iDS, int id1In, int id2In, double x1In, double x2In,
654  double sHatIn, double tHatIn, double uHatIn, double pTHatIn,
655  double m3HatIn, double m4HatIn, double thetaHatIn, double phiHatIn) {
656  id1Save[iDS] = id1In; id2Save[iDS] = id2In; x1Save[iDS] = x1In;
657  x2Save[iDS] = x2In; sH[iDS] = sHatIn; tH[iDS] = tHatIn;
658  uH[iDS] = uHatIn; pTH[iDS] = pTHatIn; m3H[iDS] = m3HatIn;
659  m4H[iDS] = m4HatIn; thetaH[iDS] = thetaHatIn; phiH[iDS] = phiHatIn;}
660  void setTypeMPI( int codeMPIIn, double pTMPIIn, int iAMPIIn = 0,
661  int iBMPIIn = 0, double eMPIIn = 1.) {codeMPISave.push_back(codeMPIIn);
662  pTMPISave.push_back(pTMPIIn); iAMPISave.push_back(iAMPIIn);
663  iBMPISave.push_back(iBMPIIn); eMPISave.push_back(eMPIIn); }
664 
665  // Set info on cross section: from ProcessLevel (reset in Pythia).
666  void sigmaReset() { nTry = nSel = nAcc = 0; sigGen = sigErr = wtAccSum = 0.;
667  procNameM.clear(); nTryM.clear(); nSelM.clear(); nAccM.clear();
668  sigGenM.clear(); sigErrM.clear();}
669  void setSigma( int i, string procNameIn, long nTryIn, long nSelIn,
670  long nAccIn, double sigGenIn, double sigErrIn, double wtAccSumIn) {
671  if (i == 0) {nTry = nTryIn; nSel = nSelIn; nAcc = nAccIn;
672  sigGen = sigGenIn; sigErr = sigErrIn; wtAccSum = wtAccSumIn;}
673  else {procNameM[i] = procNameIn; nTryM[i] = nTryIn; nSelM[i] = nSelIn;
674  nAccM[i] = nAccIn; sigGenM[i] = sigGenIn; sigErrM[i] = sigErrIn;} }
675  void addSigma( int i, long nTryIn, long nSelIn, long nAccIn, double sigGenIn,
676  double sigErrIn) { nTryM[i] += nTryIn; nSelM[i] += nSelIn;
677  nAccM[i] += nAccIn; sigGenM[i] += sigGenIn;
678  sigErrM[i] = sqrtpos(sigErrM[i]*sigErrM[i] + sigErrIn*sigErrIn); }
679 
680  // Set info on impact parameter: from PartonLevel.
681  void setImpact( double bMPIIn, double enhanceMPIIn, double enhanceMPIavgIn,
682  bool bIsSetIn = true, bool pushBack = false) {
683  if (pushBack) {bMPIoldSave = bMPISave; enhanceMPIoldSave = enhanceMPISave;
684  enhanceMPIoldavgSave = enhanceMPIavgSave;}
685  bMPISave = bMPIIn; enhanceMPISave = eMPISave[0] = enhanceMPIIn,
686  enhanceMPIavgSave = enhanceMPIavgIn, bIsSet = bIsSetIn;}
687 
688  // Set info on pTmax scales and number of evolution steps: from PartonLevel.
689  void setPartEvolved( int nMPIIn, int nISRIn) {
690  nMPISave = nMPIIn; nISRSave = nISRIn;}
691  void setEvolution( double pTmaxMPIIn, double pTmaxISRIn, double pTmaxFSRIn,
692  int nMPIIn, int nISRIn, int nFSRinProcIn, int nFSRinResIn) {
693  pTmaxMPISave = pTmaxMPIIn; pTmaxISRSave = pTmaxISRIn;
694  pTmaxFSRSave = pTmaxFSRIn; nMPISave = nMPIIn; nISRSave = nISRIn;
695  nFSRinProcSave = nFSRinProcIn; nFSRinResSave = nFSRinResIn;
696  evolIsSet = true;}
697 
698  // Set current pT evolution scale for MPI/ISR/FSR; from PartonLevel.
699  void setPTnow( double pTnowIn) {pTnowSave = pTnowIn;}
700 
701  // Set a0 from MultipartonInteractions.
702  void seta0MPI(double a0MPIin) {a0MPISave = a0MPIin;}
703 
704  // Set info whether reading of Les Houches Accord file at end.
705  void setEndOfFile( bool atEOFin) {atEOF = atEOFin;}
706 
707  // Set event weight, either for LHEF3 or for uncertainty bands. If weight
708  // has units (lhaStrategy 4 or -4), input in mb
709  void setWeight( double weightIn, int lhaStrategyIn) {
710  for (int i = 0; i < nWeights(); ++i)
711  weightContainerPtr->weightsPS.setValueByIndex(i,1.);
712  // Nominal weight in weightContainer saved in pb for lhaStrategy +-4
713  weightContainerPtr->setWeightNominal(
714  abs(lhaStrategyIn) == 4 ? CONVERTMB2PB*weightIn : weightIn);
715  lhaStrategySave = lhaStrategyIn;}
716  //
717  // Set info on resolved processes.
718  void setIsResolved(bool isResIn) {isRes = isResIn;}
719 
720  // Set info on hard diffraction.
721  void setHardDiff( bool hasUnresBeamsIn = false, bool hasPomPsysIn = false,
722  bool isHardDiffAIn = false, bool isHardDiffBIn = false,
723  double xPomAIn = 0., double xPomBIn = 0., double tPomAIn = 0.,
724  double tPomBIn = 0.) { hasUnresBeams = hasUnresBeamsIn;
725  hasPomPsys = hasPomPsysIn; isHardDiffA = isHardDiffAIn;
726  isHardDiffB = isHardDiffBIn;
727  xPomA = xPomAIn; xPomB = xPomBIn;
728  tPomA = tPomAIn; tPomB = tPomBIn;}
729 
730  // Set information in hard diffractive events.
731  void setHasUnresolvedBeams(bool hasUnresBeamsIn)
732  {hasUnresBeams = hasUnresBeamsIn;}
733  void setHasPomPsystem(bool hasPomPsysIn) {hasPomPsys = hasPomPsysIn;}
734 
735  // Variables for weak shower setup.
736  vector<int> weakModes, weak2to2lines;
737  vector<Vec4> weakMomenta;
738  vector<pair<int, int> > weakDipoles;
739 
740  int numberOfWeights() const {
741  return weightContainerPtr->numberOfWeights(); }
742  double weightValueByIndex(int key=0) const {
743  return weightContainerPtr->weightValueByIndex(key); }
744  string weightNameByIndex(int key=0) const {
745  return weightContainerPtr->weightNameByIndex(key); }
746  vector<double> weightValueVector() const {
747  return weightContainerPtr->weightValueVector(); }
748  vector<string> weightNameVector() const {
749  return weightContainerPtr->weightNameVector(); }
750 
751 };
752 
753 //==========================================================================
754 
755 // Class for loading plugin libraries at run time.
756 
757 class Plugin {
758 
759 public:
760 
761  // Constructor.
762  Plugin(string nameIn = "", Info *infoPtrIn = nullptr);
763 
764  // Destructor.
765  ~Plugin();
766 
767  // Return if the plugin is loaded.
768  bool isLoaded() {return libPtr != nullptr;}
769 
770  // Symbol from the plugin library.
771  typedef void (*Symbol)();
772 
773  // Access plugin library symbols.
774  Symbol symbol(string symName);
775 
776 protected:
777 
778  // Small routine for error printout, depending on infoPtr existing or not.
779  void errorMsg(string errMsg) {
780  if (infoPtr != nullptr) infoPtr->errorMsg(errMsg);
781  else cout << errMsg << endl;
782  }
783 
784  private:
785 
786  // Pointer to info.
787  Info *infoPtr;
788  // The loaded plugin library.
789  void *libPtr;
790  // The plugin library name.
791  string name;
792 
793 };
794 
795 //==========================================================================
796 
797 } // end namespace Pythia8
798 
799 #endif // Pythia8_Info_H