StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Pythia.h
1 // Pythia.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 the main class for event generation.
7 // Pythia: provide the main user interface to everything else.
8 
9 #ifndef Pythia8_Pythia_H
10 #define Pythia8_Pythia_H
11 
12 // Version number defined for use in macros and for consistency checks.
13 #define PYTHIA_VERSION 8.303
14 #define PYTHIA_VERSION_INTEGER 8303
15 
16 // Header files for the Pythia class and for what else the user may need.
17 #include "Pythia8/Analysis.h"
18 #include "Pythia8/Basics.h"
19 #include "Pythia8/BeamParticle.h"
20 #include "Pythia8/Event.h"
21 #include "Pythia8/FragmentationFlavZpT.h"
22 #include "Pythia8/HadronLevel.h"
23 #include "Pythia8/HadronWidths.h"
24 #include "Pythia8/Info.h"
25 #include "Pythia8/JunctionSplitting.h"
26 #include "Pythia8/LesHouches.h"
27 #include "Pythia8/Merging.h"
28 #include "Pythia8/MergingHooks.h"
29 #include "Pythia8/PartonLevel.h"
30 #include "Pythia8/ParticleData.h"
31 #include "Pythia8/PartonDistributions.h"
32 #include "Pythia8/PartonSystems.h"
33 #include "Pythia8/PartonVertex.h"
34 #include "Pythia8/PhysicsBase.h"
35 #include "Pythia8/ProcessLevel.h"
36 #include "Pythia8/PythiaStdlib.h"
37 #include "Pythia8/ResonanceWidths.h"
38 #include "Pythia8/RHadrons.h"
39 #include "Pythia8/Ropewalk.h"
40 #include "Pythia8/Settings.h"
41 #include "Pythia8/ShowerModel.h"
42 #include "Pythia8/SigmaTotal.h"
43 #include "Pythia8/SimpleSpaceShower.h"
44 #include "Pythia8/SimpleTimeShower.h"
45 #include "Pythia8/SpaceShower.h"
46 #include "Pythia8/StandardModel.h"
47 #include "Pythia8/StringInteractions.h"
48 #include "Pythia8/SusyCouplings.h"
49 #include "Pythia8/SLHAinterface.h"
50 #include "Pythia8/TimeShower.h"
51 #include "Pythia8/UserHooks.h"
52 #include "Pythia8/VinciaCommon.h"
53 #include "Pythia8/Weights.h"
54 
55 namespace Pythia8 {
56 
57 //==========================================================================
58 
59 // Forward declaration of the HeavyIons and HIUserHooks classes.
60 class HeavyIons;
61 class HIUserHooks;
62 
63 // The Pythia class contains the top-level routines to generate an event.
64 
65 class Pythia {
66 
67 public:
68 
69  // Constructor. (See Pythia.cc file.)
70  Pythia(string xmlDir = "../share/Pythia8/xmldoc", bool printBanner = true);
71 
72  // Constructor to copy settings and particle database from another Pythia
73  // object instead of XML files (to speed up multiple initialisations).
74  Pythia(Settings& settingsIn, ParticleData& particleDataIn,
75  bool printBanner = true);
76 
77  // Constructor taking input from streams instead of files.
78  Pythia( istream& settingsStrings, istream& particleDataStrings,
79  bool printBanner = true);
80 
81  // Destructor.
82  ~Pythia() {}
83 
84  // Copy and = constructors cannot be used.
85  Pythia(const Pythia&) = delete;
86  Pythia& operator=(const Pythia&) = delete;
87 
88  // Check consistency of version numbers (called by constructors).
89  bool checkVersion();
90 
91  // Read in one update for a setting or particle data from a single line.
92  bool readString(string, bool warn = true);
93 
94  // Read in updates for settings or particle data from user-defined file.
95  bool readFile(string fileName, bool warn = true,
96  int subrun = SUBRUNDEFAULT);
97  bool readFile(string fileName, int subrun) {
98  return readFile(fileName, true, subrun);}
99  bool readFile(istream& is = cin, bool warn = true,
100  int subrun = SUBRUNDEFAULT);
101  bool readFile(istream& is, int subrun) {
102  return readFile(is, true, subrun);}
103 
104  // Possibility to pass in pointers to PDF's.
105  bool setPDFPtr( PDFPtr pdfAPtrIn, PDFPtr pdfBPtrIn,
106  PDFPtr pdfHardAPtrIn = nullptr, PDFPtr pdfHardBPtrIn = nullptr,
107  PDFPtr pdfPomAPtrIn = nullptr, PDFPtr pdfPomBPtrIn = nullptr,
108  PDFPtr pdfGamAPtrIn = nullptr, PDFPtr pdfGamBPtrIn = nullptr,
109  PDFPtr pdfHardGamAPtrIn = nullptr, PDFPtr pdfHardGamBPtrIn = nullptr,
110  PDFPtr pdfUnresAPtrIn = nullptr, PDFPtr pdfUnresBPtrIn = nullptr,
111  PDFPtr pdfUnresGamAPtrIn = nullptr, PDFPtr pdfUnresGamBPtrIn = nullptr,
112  PDFPtr pdfVMDAPtrIn = nullptr, PDFPtr pdfVMDBPtrIn = nullptr);
113  bool setPDFAPtr( PDFPtr pdfAPtrIn );
114  bool setPDFBPtr( PDFPtr pdfBPtrIn );
115 
116  // Set photon fluxes externally. Used with option "PDF:lepton2gammaSet = 2".
117  bool setPhotonFluxPtr( PDFPtr photonFluxAIn, PDFPtr photonFluxBIn) {
118  if ( photonFluxAIn ) pdfGamFluxAPtr = photonFluxAIn;
119  if ( photonFluxBIn ) pdfGamFluxBPtr = photonFluxBIn;
120  return true;}
121 
122  // Possibility to pass in pointer to external LHA-interfaced generator.
123  bool setLHAupPtr( LHAupPtr lhaUpPtrIn) {lhaUpPtr = lhaUpPtrIn;
124  useNewLHA = false; return true;}
125 
126  // Possibility to pass in pointer for external handling of some decays.
127  bool setDecayPtr( DecayHandlerPtr decayHandlePtrIn,
128  vector<int> handledParticlesIn) {decayHandlePtr = decayHandlePtrIn;
129  handledParticles = handledParticlesIn; return true;}
130 
131  // Possibility to pass in pointer for external random number generation.
132  bool setRndmEnginePtr( RndmEngine* rndmEnginePtrIn)
133  { return rndm.rndmEnginePtr( rndmEnginePtrIn);}
134 
135  // Possibility to pass in pointer for user hooks.
136  bool setUserHooksPtr(UserHooksPtr userHooksPtrIn) {
137  userHooksPtr = userHooksPtrIn; return true;}
138 
139  // Possibility to add further pointers to allow multiple user hooks.
140  bool addUserHooksPtr( UserHooksPtr userHooksPtrIn) {
141  if ( !userHooksPtrIn ) return false;
142  if ( !userHooksPtr ) return setUserHooksPtr(userHooksPtrIn);
143  shared_ptr<UserHooksVector> uhv =
144  dynamic_pointer_cast<UserHooksVector>(userHooksPtr);
145  if ( !uhv ) { uhv = make_shared<UserHooksVector>();
146  uhv->hooks.push_back(userHooksPtr); userHooksPtr = uhv; }
147  uhv->hooks.push_back(userHooksPtrIn); return true;}
148 
149  // Possibility to pass in pointer for full merging class.
150  bool setMergingPtr( MergingPtr mergingPtrIn)
151  { mergingPtr = mergingPtrIn; return true;}
152 
153  // Possibility to pass in pointer for merging hooks.
154  bool setMergingHooksPtr( MergingHooksPtr mergingHooksPtrIn)
155  { mergingHooksPtr = mergingHooksPtrIn; return true;}
156 
157  // Possibility to pass in pointer for beam shape.
158  bool setBeamShapePtr( BeamShapePtr beamShapePtrIn)
159  { beamShapePtr = beamShapePtrIn; return true;}
160 
161  // Possibility to pass in pointer(s) for external cross section,
162  // with option to include external phase-space generator(s).
163  bool setSigmaPtr( SigmaProcess* sigmaPtrIn, PhaseSpace* phaseSpacePtrIn = 0)
164  { sigmaPtrs.push_back( sigmaPtrIn);
165  phaseSpacePtrs.push_back(phaseSpacePtrIn); return true;}
166 
167  // Possibility to pass in pointer(s) for external resonance.
168  bool setResonancePtr( ResonanceWidths* resonancePtrIn)
169  { resonancePtrs.push_back( resonancePtrIn); return true;}
170 
171  // Possibility to pass in pointer for external showers.
172  bool setShowerModelPtr( ShowerModelPtr showerModelPtrIn)
173  { showerModelPtr = showerModelPtrIn; return true;}
174 
175  // Possibility to pass in pointer for modelling of heavy ion collisions.
176  bool setHeavyIonsPtr( HeavyIonsPtr heavyIonsPtrIn)
177  { heavyIonsPtr = heavyIonsPtrIn; return true;}
178 
179  // Possibility to pass a HIUserHooks pointer for modifying the
180  // behavior of the heavy ion modelling.
181  bool setHIHooks(HIUserHooksPtr hiHooksPtrIn)
182  { hiHooksPtr = hiHooksPtrIn; return true; }
183 
184  // Possibility to get the pointer to a object modelling heavy ion
185  // collisions.
186  HeavyIonsPtr getHeavyIonsPtr() { return heavyIonsPtr;}
187 
188  // Possibility to get the pointer to the parton-shower model.
189  ShowerModelPtr getShowerModelPtr() { return showerModelPtr; }
190 
191  // Possibility to pass in pointer for setting of parton space-time vertices.
192  bool setPartonVertexPtr( PartonVertexPtr partonVertexPtrIn)
193  { partonVertexPtr = partonVertexPtrIn; return true;}
194 
195  // Initialize.
196  bool init();
197 
198  // Generate the next event.
199  bool next();
200 
201  // Generate the next event, either with new energies or new beam momenta.
202  bool next(double eCMin);
203  bool next(double eAin, double eBin);
204  bool next(double pxAin, double pyAin, double pzAin,
205  double pxBin, double pyBin, double pzBin);
206 
207  // Generate only a single timelike shower as in a decay.
208  int forceTimeShower( int iBeg, int iEnd, double pTmax, int nBranchMax = 0)
209  { partonSystems.clear(); infoPrivate.setScalup( 0, pTmax);
210  return timesDecPtr->shower( iBeg, iEnd, event, pTmax, nBranchMax); }
211 
212  // Generate only the hadronization/decay stage.
213  bool forceHadronLevel( bool findJunctions = true);
214 
215  // Special routine to allow more decays if on/off switches changed.
216  bool moreDecays() {return hadronLevel.moreDecays(event);}
217 
218  // Special routine to force R-hadron decay when not done before.
219  bool forceRHadronDecays() {return doRHadronDecays();}
220 
221  // Do a low-energy collision between two hadrons in the event record.
222  bool doLowEnergyProcess(int i1, int i2, int type) {
223  return hadronLevel.doLowEnergyProcess( i1, i2, type, event); }
224 
225  // Get low-energy cross section for two hadrons in the event record.
226  double getLowEnergySigma(int i1, int i2, int type = 0) {
227  double eCM12 = (event[i1].p() + event[i2].p()).mCalc();
228  return getLowEnergySigma( event[i1].id(), event[i2].id(), eCM12,
229  event[i1].m(), event[i2].m(), type); }
230 
231  // Get low-energy cross section for two hadrons standalone.
232  double getLowEnergySigma(int id1, int id2, double eCM12, double m1,
233  double m2, int type = 0) {
234  return hadronLevel.getLowEnergySigma(id1, id2, eCM12, m1, m2, type); }
235 
236  double getLowEnergySigma(int id1, int id2, double eCM12, int type = 0) {
237  return getLowEnergySigma(id1, id2, eCM12,
238  particleData.m0(id1), particleData.m0(id2), type); }
239 
240  // Get b slope in elastic and diffractive interactions standalone.
241  double getLowEnergySlope( int id1, int id2, double eCM12, double m1,
242  double m2, int type = 2) { if (type < 2 || type > 5) return 0.;
243  return hadronLevel.getLowEnergySlope( id1, id2, eCM12, m1, m2, type); }
244 
245  // List the current Les Houches event.
246  void LHAeventList() { if (lhaUpPtr != 0) lhaUpPtr->listEvent();}
247 
248  // Skip a number of Les Houches events at input.
249  bool LHAeventSkip(int nSkip) {
250  if (lhaUpPtr != 0) return lhaUpPtr->skipEvent(nSkip);
251  return false;}
252 
253  // Main routine to provide final statistics on generation.
254  void stat();
255 
256  // Read in settings values: shorthand, not new functionality.
257  bool flag(string key) {return settings.flag(key);}
258  int mode(string key) {return settings.mode(key);}
259  double parm(string key) {return settings.parm(key);}
260  string word(string key) {return settings.word(key);}
261 
262  // Auxiliary to set parton densities among list of possibilities.
263  PDFPtr getPDFPtr(int idIn, int sequence = 1, string beam = "A",
264  bool resolved = true);
265 
266  // The event record for the parton-level central process.
267  Event process = {};
268 
269  // The event record for the complete event history.
270  Event event = {};
271 
272  // Public information and statistic on the generation.
273  const Info& info = infoPrivate;
274 
275  // Settings: databases of flags/modes/parms/words to control run.
276  Settings settings = {};
277 
278  // ParticleData: the particle data table/database.
279  ParticleData particleData = {};
280 
281  // Random number generator.
282  Rndm rndm = {};
283 
284  // Standard Model couplings, including alphaS and alphaEM.
285  CoupSM coupSM = {};
286 
287  // SUSY couplings.
288  CoupSUSY coupSUSY = {};
289 
290  // SLHA Interface
291  SLHAinterface slhaInterface = {};
292 
293  // The partonic content of each subcollision system (auxiliary to event).
294  PartonSystems partonSystems = {};
295 
296  // Merging object as wrapper for matrix element merging routines.
297  MergingPtr mergingPtr = {};
298 
299  // Pointer to MergingHooks object for user interaction with the merging.
300  // MergingHooks also more generally steers the matrix element merging.
301  MergingHooksPtr mergingHooksPtr;
302 
303  // Pointer to a HeavyIons object for generating heavy ion collisions
304  HeavyIonsPtr heavyIonsPtr = {};
305 
306  // Pointer to a HIUserHooks object to modify heavy ion modelling.
307  HIUserHooksPtr hiHooksPtr = {};
308 
309  // HadronWidths: the hadron widths data table/database.
310  HadronWidths hadronWidths = {};
311 
312  // The two incoming beams.
313  BeamParticle beamA = {};
314  BeamParticle beamB = {};
315 
316 private:
317 
318  // The collector of all event generation weights that should eventually
319  // be transferred to the final output.
320  WeightContainer weightContainer = {};
321 
322  // The main keeper/collector of information, accessible from all
323  // PhysicsBase objects. The information is available from the
324  // outside through the public info object.
325  Info infoPrivate = {};
326 
327  // Initialise new Pythia object (called by constructors).
328  void initPtrs();
329 
330  // Functions to be called at the beginning and end of a next() call.
331  void beginEvent();
332  void endEvent(PhysicsBase::Status status);
333 
334  // Register a PhysicsBase object and give it a pointer to the info object.
335  void registerPhysicsBase(PhysicsBase & pb) { pb.initInfoPtr(infoPrivate);
336  physicsPtrs.push_back(&pb); }
337 
338  // If new pointers are set in Info propagate this to all
339  // PhysicsBase objects.
340  void pushInfo();
341 
342  // Constants: could only be changed in the code itself.
343  static const double VERSIONNUMBERHEAD, VERSIONNUMBERCODE;
344  // Maximum number of tries to produce parton level from given input.
345  // Negative integer to denote that no subrun has been set.
346  static const int NTRY = 10, SUBRUNDEFAULT = -999;
347 
348  // Initialization data, extracted from database.
349  string xmlPath = {};
350  bool doProcessLevel = {}, doPartonLevel = {}, doHadronLevel = {},
351  doSoftQCDall = {}, doSoftQCDinel = {}, doCentralDiff = {},
352  doDiffraction = {}, doSoftQCD = {}, doVMDsideA = {}, doVMDsideB = {},
353  doHardDiff = {}, doResDec = {}, doFSRinRes = {}, decayRHadrons = {},
354  doPartonVertex = {}, doVertexPlane = {}, abortIfVeto = {},
355  checkEvent = {}, checkHistory = {}, doNonPert = {};
356  int nErrList = {};
357  double epTolErr = {}, epTolWarn = {}, mTolErr = {}, mTolWarn = {};
358 
359  // Initialization data related to photon-photon/hadron interactions.
360  int gammaMode = {};
361  bool beamA2gamma = {}, beamB2gamma = {};
362  bool beamAResGamma = {}, beamBResGamma = {};
363  bool beamAUnresGamma = {}, beamBUnresGamma = {};
364 
365  // Initialization data, extracted from init(...) call.
366  bool isConstructed = {}, isInit = {}, isUnresolvedA = {},
367  isUnresolvedB = {}, showSaV = {}, showMaD = {}, doReconnect = {},
368  forceHadronLevelCR = {};
369  int idA = {}, idB = {}, frameType = {}, boostType = {}, nCount = {},
370  nShowLHA = {}, nShowInfo = {}, nShowProc = {}, nShowEvt = {},
371  reconnectMode = {};
372  double mA = {}, mB = {}, pxA = {}, pxB = {}, pyA = {}, pyB = {}, pzA = {},
373  pzB = {}, eA = {}, eB = {}, pzAcm = {}, pzBcm = {}, eCM = {},
374  betaZ = {}, gammaZ = {};
375  Vec4 pAinit = {}, pBinit = {}, pAnow = {}, pBnow = {};
376  RotBstMatrix MfromCM = {}, MtoCM = {};
377 
378  // information for error checkout.
379  int nErrEvent = {};
380  vector<int> iErrId = {}, iErrCol = {}, iErrEpm = {}, iErrNan = {},
381  iErrNanVtx = {};
382 
383  // Pointers to the parton distributions of the two incoming beams.
384  PDFPtr pdfAPtr = {};
385  PDFPtr pdfBPtr = {};
386 
387  // Extra PDF pointers to be used in hard processes only.
388  PDFPtr pdfHardAPtr = {};
389  PDFPtr pdfHardBPtr = {};
390 
391  // Extra Pomeron PDF pointers to be used in diffractive processes only.
392  PDFPtr pdfPomAPtr = {};
393  PDFPtr pdfPomBPtr = {};
394 
395  // Extra Photon PDF pointers to be used in lepton -> gamma processes.
396  PDFPtr pdfGamAPtr = {};
397  PDFPtr pdfGamBPtr = {};
398 
399  // Extra PDF pointers to be used in hard lepton -> gamma processes.
400  PDFPtr pdfHardGamAPtr = {};
401  PDFPtr pdfHardGamBPtr = {};
402 
403  // Alternative unresolved PDFs when mixing resolved and unresolved processes.
404  PDFPtr pdfUnresAPtr = {};
405  PDFPtr pdfUnresBPtr = {};
406  PDFPtr pdfUnresGamAPtr = {};
407  PDFPtr pdfUnresGamBPtr = {};
408 
409  // PDF pointers to externally provided photon fluxes.
410  PDFPtr pdfGamFluxAPtr = {};
411  PDFPtr pdfGamFluxBPtr = {};
412 
413  // Extra VMD PDF pointers to be used in SoftQCD with gammas.
414  PDFPtr pdfVMDAPtr = {};
415  PDFPtr pdfVMDBPtr = {};
416 
417  // Alternative Pomeron beam-inside-beam.
418  BeamParticle beamPomA = {};
419  BeamParticle beamPomB = {};
420 
421  // Alternative photon beam-inside-beam.
422  BeamParticle beamGamA = {};
423  BeamParticle beamGamB = {};
424 
425  // Alternative VMD beam-inside-beam.
426  BeamParticle beamVMDA = {};
427  BeamParticle beamVMDB = {};
428 
429  // LHAup object for generating external events.
430  bool doLHA = false;
431  bool useNewLHA = false;
432  LHAupPtr lhaUpPtr = {};
433 
434  // Pointer to external decay handler and list of particles it handles.
435  DecayHandlerPtr decayHandlePtr = {};
436  vector<int> handledParticles = {};
437 
438  // Pointer to UserHooks object for user interaction with program.
439  UserHooksPtr userHooksPtr = {};
440  bool doVetoProcess = {}, doVetoPartons = {}, retryPartonLevel = {};
441 
442  // Pointer to BeamShape object for beam momentum and interaction vertex.
443  BeamShapePtr beamShapePtr = {};
444  bool doMomentumSpread = {}, doVertexSpread = {}, doVarEcm = {};
445  double eMinPert = {}, eWidthPert = {};
446 
447  // Pointers to external processes derived from the Pythia base classes.
448  vector<SigmaProcess*> sigmaPtrs = {};
449 
450  // Pointers to external phase-space generators derived from Pythia
451  // base classes.
452  vector<PhaseSpace*> phaseSpacePtrs = {};
453 
454  // Pointers to external calculation of resonance widths.
455  vector<ResonanceWidths*> resonancePtrs = {};
456 
457  // Pointers to timelike and spacelike showers, including Vincia and Dire.
458  TimeShowerPtr timesDecPtr = {};
459  TimeShowerPtr timesPtr = {};
460  SpaceShowerPtr spacePtr = {};
461  ShowerModelPtr showerModelPtr = {};
462 
463  // Pointer to assign space-time vertices during parton evolution.
464  PartonVertexPtr partonVertexPtr;
465 
466  // The main generator class to define the core process of the event.
467  ProcessLevel processLevel = {};
468 
469  // The main generator class to produce the parton level of the event.
470  PartonLevel partonLevel = {};
471 
472  // The main generator class to perform trial showers of the event.
473  PartonLevel trialPartonLevel = {};
474 
475  // Flags for defining the merging scheme.
476  bool doMerging = {};
477 
478  // The StringInteractions class.
479  StringIntPtr stringInteractionsPtr;
480 
481  // The Colour reconnection class.
482  ColRecPtr colourReconnectionPtr = {};
483 
484  // The junction spltiting class.
485  JunctionSplitting junctionSplitting = {};
486 
487  // The main generator class to produce the hadron level of the event.
488  HadronLevel hadronLevel = {};
489 
490  // The total cross section class is used both on process and parton level.
491  SigmaTotal sigmaTot = {};
492 
493  // The RHadrons class is used both at PartonLevel and HadronLevel.
494  RHadrons rHadrons = {};
495 
496  // Flags for handling generation of heavy ion collisons.
497  bool hasHeavyIons = {}, doHeavyIons = {};
498 
499  // Write the Pythia banner, with symbol and version information.
500  void banner();
501 
502  // Check for lines in file that mark the beginning of new subrun.
503  int readSubrun(string line, bool warn = true);
504 
505  // Check for lines that mark the beginning or end of commented section.
506  int readCommented(string line);
507 
508  // Check that combinations of settings are allowed; change if not.
509  void checkSettings();
510 
511  // Check that beams and beam combination can be handled.
512  bool checkBeams();
513 
514  // Calculate kinematics at initialization.
515  bool initKinematics();
516 
517  // Set up pointers to PDFs.
518  bool initPDFs();
519 
520  // Recalculate kinematics for each event when beam momentum has a spread.
521  void nextKinematics();
522 
523  // Simplified treatment for low-energy nonperturbative collisions.
524  bool nextNonPert();
525 
526  // Boost from CM frame to lab frame, or inverse. Set production vertex.
527  void boostAndVertex(bool toLab, bool setVertex);
528 
529  // Perform R-hadron decays.
530  bool doRHadronDecays();
531 
532  // Check that the final event makes sense.
533  bool check();
534 
535  // Initialization of SLHA data.
536  bool initSLHA();
537  stringstream particleDataBuffer;
538 
539  // Keep track of and initialize all pointers to PhysicsBase-derived objects.
540  vector<PhysicsBase*> physicsPtrs = {};
541 
542 };
543 
544 //==========================================================================
545 
546 } // end namespace Pythia8
547 
548 #endif // Pythia8_Pythia_H
Definition: beam.h:43
Definition: AgUStep.h:26