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) 2012 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL version 2, 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 #include "Analysis.h"
13 #include "Basics.h"
14 #include "BeamParticle.h"
15 #include "BeamShape.h"
16 #include "Event.h"
17 #include "FragmentationFlavZpT.h"
18 #include "HadronLevel.h"
19 #include "History.h"
20 #include "Info.h"
21 #include "LesHouches.h"
22 #include "MergingHooks.h"
23 #include "PartonLevel.h"
24 #include "ParticleData.h"
25 #include "PartonDistributions.h"
26 #include "PartonSystems.h"
27 #include "ProcessLevel.h"
28 #include "PythiaStdlib.h"
29 #include "ResonanceWidths.h"
30 #include "RHadrons.h"
31 #include "Settings.h"
32 #include "SigmaTotal.h"
33 #include "SpaceShower.h"
34 #include "StandardModel.h"
35 #include "SusyLesHouches.h"
36 #include "TimeShower.h"
37 #include "UserHooks.h"
38 
39 namespace Pythia8 {
40 
41 //==========================================================================
42 
43 // The Pythia class contains the top-level routines to generate an event.
44 
45 class Pythia {
46 
47 public:
48 
49  // Constructor. (See Pythia.cc file.)
50  Pythia(string xmlDir = "../xmldoc");
51 
52  // Destructor. (See Pythia.cc file.)
53  ~Pythia();
54 
55  // Read in one update for a setting or particle data from a single line.
56  bool readString(string, bool warn = true);
57 
58  // Read in updates for settings or particle data from user-defined file.
59  bool readFile(string fileName, bool warn = true,
60  int subrun = SUBRUNDEFAULT);
61  bool readFile(string fileName, int subrun) {
62  return readFile(fileName, true, subrun);}
63  bool readFile(istream& is = cin, bool warn = true,
64  int subrun = SUBRUNDEFAULT);
65  bool readFile(istream& is, int subrun) {
66  return readFile(is, true, subrun);}
67 
68  // Possibility to pass in pointers to PDF's.
69  bool setPDFPtr( PDF* pdfAPtrIn, PDF* pdfBPtrIn, PDF* pdfHardAPtrIn = 0,
70  PDF* pdfHardBPtrIn = 0, PDF* pdfPomAPtrIn = 0, PDF* pdfPomBPtrIn = 0);
71 
72  // Possibility to pass in pointer to external LHA-interfaced generator.
73  bool setLHAupPtr( LHAup* lhaUpPtrIn) {lhaUpPtr = lhaUpPtrIn; return true;}
74 
75  // Possibility to pass in pointer for external handling of some decays.
76  bool setDecayPtr( DecayHandler* decayHandlePtrIn,
77  vector<int> handledParticlesIn) {decayHandlePtr = decayHandlePtrIn;
78  handledParticles.resize(0);
79  for(int i = 0; i < int(handledParticlesIn.size()); ++i)
80  handledParticles.push_back( handledParticlesIn[i] ); return true;}
81 
82  // Possibility to pass in pointer for external random number generation.
83  bool setRndmEnginePtr( RndmEngine* rndmEnginePtrIn)
84  { return rndm.rndmEnginePtr( rndmEnginePtrIn);}
85 
86  // Possibility to pass in pointer for user hooks.
87  bool setUserHooksPtr( UserHooks* userHooksPtrIn)
88  { userHooksPtr = userHooksPtrIn; return true;}
89 
90  // Possibility to pass in pointer for merging hooks.
91  bool setMergingHooksPtr( MergingHooks* mergingHooksPtrIn)
92  { mergingHooksPtr = mergingHooksPtrIn; return true;}
93 
94  // Possibility to pass in pointer for beam shape.
95  bool setBeamShapePtr( BeamShape* beamShapePtrIn)
96  { beamShapePtr = beamShapePtrIn; return true;}
97 
98  // Possibility to pass in pointer(s) for external cross section.
99  bool setSigmaPtr( SigmaProcess* sigmaPtrIn)
100  { sigmaPtrs.push_back( sigmaPtrIn); return true;}
101 
102  // Possibility to pass in pointer(s) for external resonance.
103  bool setResonancePtr( ResonanceWidths* resonancePtrIn)
104  { resonancePtrs.push_back( resonancePtrIn); return true;}
105 
106  // Possibility to pass in pointer for external showers.
107  bool setShowerPtr( TimeShower* timesDecPtrIn,
108  TimeShower* timesPtrIn = 0, SpaceShower* spacePtrIn = 0)
109  { timesDecPtr = timesDecPtrIn; timesPtr = timesPtrIn;
110  spacePtr = spacePtrIn; return true;}
111 
112  // Initialization using the Beams variables.
113  bool init();
114 
115  // Deprecated: initialization in the CM frame.
116  bool init( int idAin, int idBin, double eCMin);
117 
118  // Deprecated: initialization with two collinear beams, e.g. fixed target.
119  bool init( int idAin, int idBin, double eAin, double eBin);
120 
121  // Deprecated: initialization with two acollinear beams.
122  bool init( int idAin, int idBin, double pxAin, double pyAin,
123  double pzAin, double pxBin, double pyBin, double pzBin);
124 
125  // Deprecated: initialization by a Les Houches Event File.
126  bool init( string LesHouchesEventFile, bool skipInit = false);
127 
128  // Deprecated: initialization according to the Les Houches Accord.
129  bool init( LHAup* lhaUpPtrIn);
130 
131  // Generate the next event.
132  bool next();
133 
134  // Generate only a single timelike shower as in a decay.
135  int forceTimeShower( int iBeg, int iEnd, double pTmax, int nBranchMax = 0)
136  { return timesDecPtr->shower( iBeg, iEnd, event, pTmax, nBranchMax); }
137 
138  // Generate only the hadronization/decay stage.
139  bool forceHadronLevel(bool findJunctions = true);
140 
141  // Special routine to allow more decays if on/off switches changed.
142  bool moreDecays() {return hadronLevel.moreDecays(event);}
143 
144  // Special routine to force R-hadron decay when not done before.
145  bool forceRHadronDecays() {return doRHadronDecays();}
146 
147  // List the current Les Houches event.
148  void LHAeventList(ostream& os = cout) {
149  if (lhaUpPtr != nullptr) lhaUpPtr->listEvent(os);}
150 
151  // Skip a number of Les Houches events at input.
152  bool LHAeventSkip(int nSkip) {
153  if (lhaUpPtr != nullptr) return lhaUpPtr->skipEvent(nSkip); return false;}
154 
155  // Main routine to provide final statistics on generation.
156  void stat();
157 
158  // Deprecated: alternative to provide final statistics on generation.
159  void statistics(bool all = false, bool reset = false);
160 
161  // Read in settings values: shorthand, not new functionality.
162  bool flag(string key) {return settings.flag(key);}
163  int mode(string key) {return settings.mode(key);}
164  double parm(string key) {return settings.parm(key);}
165  string word(string key) {return settings.word(key);}
166 
167  // The event record for the parton-level central process.
168  Event process;
169 
170  // The event record for the complete event history.
171  Event event;
172 
173  // Information on the generation: current subprocess and error statistics.
174  Info info;
175 
176  // Settings: databases of flags/modes/parms/words to control run.
177  Settings settings;
178 
179  // ParticleData: the particle data table/database.
180  ParticleData particleData;
181 
182  // Random number generator.
183  Rndm rndm;
184 
185  // Standard Model couplings, including alphaS and alphaEM.
186  Couplings couplings;
187  CoupSUSY coupSUSY;
188  Couplings* couplingsPtr;
189 
190  // SusyLesHouches - SLHA object for interface to SUSY spectra.
191  SusyLesHouches slha;
192 
193  // The partonic content of each subcollision system (auxiliary to event).
194  PartonSystems partonSystems;
195 
196 private:
197 
198  // Constants: could only be changed in the code itself.
199  static const int NTRY, SUBRUNDEFAULT;
200 
201  // Initialization data, extracted from database.
202  string xmlPath;
203  bool doProcessLevel, doPartonLevel, doHadronLevel, abortIfVeto,
204  checkEvent, doDiffraction, decayRHadrons;
205  int nErrList;
206  double epTolErr, epTolWarn;
207 
208  // Initialization data, extracted from init(...) call.
209  bool isConstructed, isInit, isUnresolvedA, isUnresolvedB, showSaV,
210  showMaD;
211  int idA, idB, frameType, boostType, nCount, nShowLHA, nShowInfo,
212  nShowProc, nShowEvt;
213  double mA, mB, pxA, pxB, pyA, pyB, pzA, pzB, eA, eB,
214  pzAcm, pzBcm, eCM, betaZ, gammaZ;
215  Vec4 pAinit, pBinit, pAnow, pBnow;
216  RotBstMatrix MfromCM, MtoCM;
217 
218  // information for error checkout.
219  int nErrEvent;
220  vector<int> iErrId, iErrCol, iErrNan, iErrNanVtx;
221 
222  // Pointers to the parton distributions of the two incoming beams.
223  PDF* pdfAPtr;
224  PDF* pdfBPtr;
225 
226  // Extra PDF pointers to be used in hard processes only.
227  PDF* pdfHardAPtr;
228  PDF* pdfHardBPtr;
229 
230  // Extra Pomeron PDF pointers to be used in diffractive processes only.
231  PDF* pdfPomAPtr;
232  PDF* pdfPomBPtr;
233 
234  // Keep track when "new" has been used and needs a "delete" for PDF's.
235  bool useNewPdfA, useNewPdfB, useNewPdfHard, useNewPdfPomA, useNewPdfPomB;
236 
237  // The two incoming beams.
238  BeamParticle beamA;
239  BeamParticle beamB;
240 
241  // Alternative Pomeron beam-inside-beam.
242  BeamParticle beamPomA;
243  BeamParticle beamPomB;
244 
245  // LHAup object for generating external events.
246  bool doLHA, useNewLHA;
247  LHAup* lhaUpPtr;
248 
249  // Pointer to external decay handler and list of particles it handles.
250  DecayHandler* decayHandlePtr;
251  vector<int> handledParticles;
252 
253  // Pointer to UserHooks object for user interaction with program.
254  UserHooks* userHooksPtr;
255  bool hasUserHooks, doVetoProcess, doVetoPartons;
256 
257  // Pointer to BeamShape object for beam momentum and interaction vertex.
258  BeamShape* beamShapePtr;
259  bool useNewBeamShape, doMomentumSpread, doVertexSpread;
260 
261  // Pointers to external processes derived from the Pythia base classes.
262  vector<SigmaProcess*> sigmaPtrs;
263 
264  // Pointers to external calculation of resonance widths.
265  vector<ResonanceWidths*> resonancePtrs;
266 
267  // Pointers to timelike and spacelike showers.
268  TimeShower* timesDecPtr;
269  TimeShower* timesPtr;
270  SpaceShower* spacePtr;
271  bool useNewTimes, useNewSpace;
272 
273  // The main generator class to define the core process of the event.
274  ProcessLevel processLevel;
275 
276  // The main generator class to produce the parton level of the event.
277  PartonLevel partonLevel;
278 
279  // The main generator class to perform trial showers of the event.
280  PartonLevel trialPartonLevel;
281 
282  // Pointer to MergingHooks object for user interaction with the merging.
283  MergingHooks* mergingHooksPtr;
284  bool hasMergingHooks, hasOwnMergingHooks, doUserMerging,
285  doMGMerging, doKTMerging, doMerging;
286 
287  // The main generator class to produce the hadron level of the event.
288  HadronLevel hadronLevel;
289 
290  // The total cross section class is used both on process and parton level.
291  SigmaTotal sigmaTot;
292 
293  // The RHadrons class is used both at PartonLevel and HadronLevel.
294  RHadrons rHadrons;
295 
296  // Write the Pythia banner, with symbol and version information.
297  void banner(ostream& os = cout);
298 
299  // Check for lines in file that mark the beginning of new subrun.
300  int readSubrun(string line, bool warn = true, ostream& os = cout);
301 
302  // Check that combinations of settings are allowed; change if not.
303  void checkSettings();
304 
305  // Check that beams and beam combination can be handled.
306  bool checkBeams();
307 
308  // Calculate kinematics at initialization.
309  bool initKinematics();
310 
311  // Set up pointers to PDFs.
312  bool initPDFs();
313 
314  // Recalculate kinematics for each event when beam momentum has a spread.
315  void nextKinematics();
316 
317  // Boost from CM frame to lab frame, or inverse. Set production vertex.
318  void boostAndVertex(bool toLab, bool setVertex);
319 
320  // Perform R-hadron decays.
321  bool doRHadronDecays();
322 
323  // Check that the final event makes sense.
324  bool check(ostream& os = cout);
325 
326  // Auxiliary to set parton densities among list of possibilities.
327  PDF* getPDFPtr(int idIn, int sequence = 1);
328 
329  // Initialization of SLHA data.
330  bool initSLHA ();
331 
332  // Function to perform the merging of the history.
333  bool mergeProcess();
334 
335 };
336 
337 //==========================================================================
338 
339 } // end namespace Pythia8
340 
341 #endif // Pythia8_Pythia_H