Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPythia8.cxx
Go to the documentation of this file.
1// @(#)root/pythia8:$Name$:$Id$
2// Author: Andreas Morsch 27/10/2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TPythia8
13 \ingroup pythia8
14
15TPythia8 is an interface class to C++ version of Pythia 8.1
16event generators, written by T.Sjostrand.
17
18The user is assumed to be familiar with the Pythia package.
19This class includes only a basic interface to Pythia8. Because Pythia8 is
20also written in C++, its functions/classes can be called directly from a
21compiled C++ script.
22
23To call Pythia functions not available in this interface a dictionary must
24be generated.
25
26TPythia8.h only forward-declares Pythia8::Pythia. Code that uses the
27object returned by TPythia8::Pythia8() must include the Pythia8 header
28itself, as well as link against Pythia8 in its CMakeLists.txt:
29~~~{.cpp}
30#include "TPythia8.h"
31#include "Pythia8/Pythia.h"
32
33TPythia8 pythia8;
34pythia8.Pythia8()->readString("SoftQCD:elastic = on");
35~~~
36
37See evegen_000_pythia8.C for an example of use from CLING.
38
39Author: Andreas Morsch 27/10/2007
40
41\verbatim
42*------------------------------------------------------------------------------------*
43 | |
44 | *------------------------------------------------------------------------------* |
45 | | | |
46 | | | |
47 | | PPP Y Y TTTTT H H III A Welcome to the Lund Monte Carlo! | |
48 | | P P Y Y T H H I A A This is PYTHIA version 8.100 | |
49 | | PPP Y T HHHHH I AAAAA Last date of change: 20 Oct 2007 | |
50 | | P Y T H H I A A | |
51 | | P Y T H H III A A Now is 27 Oct 2007 at 18:26:53 | |
52 | | | |
53 | | Main author: Torbjorn Sjostrand; CERN/PH, CH-1211 Geneva, Switzerland, | |
54 | | and Department of Theoretical Physics, Lund University, Lund, Sweden; | |
55 | | phone: + 41 - 22 - 767 82 27; e-mail: torbjorn@thep.lu.se | |
56 | | Author: Stephen Mrenna; Computing Division, Simulations Group, | |
57 | | Fermi National Accelerator Laboratory, MS 234, Batavia, IL 60510, USA; | |
58 | | phone: + 1 - 630 - 840 - 2556; e-mail: mrenna@fnal.gov | |
59 | | Author: Peter Skands; CERN/PH, CH-1211 Geneva, Switzerland, | |
60 | | and Theoretical Physics Department, | |
61 | | Fermi National Accelerator Laboratory, MS 106, Batavia, IL 60510, USA; | |
62 | | phone: + 41 - 22 - 767 24 59; e-mail: skands@fnal.gov | |
63 | | | |
64 | | The main program reference is the 'Brief Introduction to PYTHIA 8.1', | |
65 | | T. Sjostrand, S. Mrenna and P. Skands, arXiv:0710.3820 | |
66 | | | |
67 | | The main physics reference is the 'PYTHIA 6.4 Physics and Manual', | |
68 | | T. Sjostrand, S. Mrenna and P. Skands, JHEP05 (2006) 026 [hep-ph/0603175]. | |
69 | | | |
70 | | An archive of program versions and documentation is found on the web: | |
71 | | http://www.thep.lu.se/~torbjorn/Pythia.html | |
72 | | | |
73 | | This program is released under the GNU General Public Licence version 2. | |
74 | | Please respect the MCnet Guidelines for Event Generator Authors and Users. | |
75 | | | |
76 | | Disclaimer: this program comes without any guarantees. | |
77 | | Beware of errors and use common sense when interpreting results. | |
78 | | | |
79 | | Copyright (C) 2007 Torbjorn Sjostrand | |
80 | | | |
81 | | | |
82 | *------------------------------------------------------------------------------* |
83 | |
84 *------------------------------------------------------------------------------------*
85 \endverbatim
86*/
87
88#include "TPythia8.h"
89
90#include "Pythia8/Pythia.h"
91
92#include "TClonesArray.h"
93#include "TParticle.h"
94#include "TDatabasePDG.h"
95#include "TLorentzVector.h"
96
97
99
100////////////////////////////////////////////////////////////////////////////////
101/// Constructor
102
103TPythia8::TPythia8(bool printBanner /*= true*/):
104 TGenerator("TPythia8", "TPythia8"),
105 fPythia(0),
106 fNumberOfParticles(0)
107{
108 if (fgInstance)
109 Fatal("TPythia8", "There's already an instance of TPythia8");
110
111 delete fParticles; // was allocated as TObjArray in TGenerator
112
113 fParticles = new TClonesArray("TParticle",50);
114 // If only we could skip stating the default of the first parameter...:
115 fPythia = new Pythia8::Pythia("../share/Pythia8/xmldoc", printBanner);
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// Constructor with an xmlDir (eg "../xmldoc"
120
121TPythia8::TPythia8(const char *xmlDir, bool printBanner /*= true*/):
122 TGenerator("TPythia8", "TPythia8"),
123 fPythia(0),
124 fNumberOfParticles(0)
125{
126 if (fgInstance)
127 Fatal("TPythia8", "There's already an instance of TPythia8");
128
129 delete fParticles; // was allocated as TObjArray in TGenerator
130
131 fParticles = new TClonesArray("TParticle",50);
132 fPythia = new Pythia8::Pythia(xmlDir, printBanner);
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// Destructor
137
139{
140 if (fParticles) {
142 delete fParticles;
143 fParticles = 0;
144 }
145 delete fPythia;
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// Return an instance of TPythia8
150
152{
153 return fgInstance ? fgInstance : (fgInstance = new TPythia8()) ;
154}
155
156////////////////////////////////////////////////////////////////////////////////
157/// Initialization
158
160{
162
163 // Set arguments in Settings database.
164 fPythia->settings.mode("Beams:idA", idAin);
165 fPythia->settings.mode("Beams:idB", idBin);
166 fPythia->settings.mode("Beams:frameType", 1);
167 fPythia->settings.parm("Beams:eCM", ecms);
168
169 return fPythia->init();
170
171 //return fPythia->init(idAin, idBin, ecms);
172}
173
174////////////////////////////////////////////////////////////////////////////////
175/// Initialization
176
178{
180
181 // Set arguments in Settings database.
182 fPythia->settings.mode("Beams:idA", idAin);
183 fPythia->settings.mode("Beams:idB", idBin);
184 fPythia->settings.mode("Beams:frameType", 2);
185 fPythia->settings.parm("Beams:eA", eAin);
186 fPythia->settings.parm("Beams:eB", eBin);
187
188 // Send on to common initialization.
189 return fPythia->init();
190
191 //return fPythia->init(idAin, idBin, eAin, eBin);
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// Generate the next event
196
198{
199 fPythia->next();
200 fNumberOfParticles = fPythia->event.size() - 1;
202}
203////////////////////////////////////////////////////////////////////////////////
204/// Import particles from Pythia stack
205
207{
208 if (particles == 0) return 0;
209 TClonesArray &clonesParticles = *particles;
210 clonesParticles.Clear();
211 Int_t nparts=0;
212 Int_t i;
213 Int_t ioff = 0;
214 fNumberOfParticles = fPythia->event.size();
215 if (fPythia->event[0].id() == 90) {
216 ioff = -1;
217 }
218
219 if (!strcmp(option,"") || !strcmp(option,"Final")) {
220 for (i = 0; i < fNumberOfParticles; i++) {
221 if (fPythia->event[i].id() == 90) continue;
222 if (fPythia->event[i].isFinal()) {
223 new(clonesParticles[nparts]) TParticle(
224 fPythia->event[i].id(),
225 fPythia->event[i].isFinal(),
226 fPythia->event[i].mother1() + ioff,
227 fPythia->event[i].mother2() + ioff,
228 fPythia->event[i].daughter1() + ioff,
229 fPythia->event[i].daughter2() + ioff,
230 fPythia->event[i].px(), // [GeV/c]
231 fPythia->event[i].py(), // [GeV/c]
232 fPythia->event[i].pz(), // [GeV/c]
233 fPythia->event[i].e(), // [GeV]
234 fPythia->event[i].xProd(), // [mm]
235 fPythia->event[i].yProd(), // [mm]
236 fPythia->event[i].zProd(), // [mm]
237 fPythia->event[i].tProd()); // [mm/c]
238 nparts++;
239 } // final state partice
240 } // particle loop
241 } else if (!strcmp(option,"All")) {
242 for (i = 0; i < fNumberOfParticles; i++) {
243 if (fPythia->event[i].id() == 90) continue;
244 new(clonesParticles[nparts]) TParticle(
245 fPythia->event[i].id(),
246 fPythia->event[i].isFinal(),
247 fPythia->event[i].mother1() + ioff,
248 fPythia->event[i].mother2() + ioff,
249 fPythia->event[i].daughter1() + ioff,
250 fPythia->event[i].daughter2() + ioff,
251 fPythia->event[i].px(), // [GeV/c]
252 fPythia->event[i].py(), // [GeV/c]
253 fPythia->event[i].pz(), // [GeV/c]
254 fPythia->event[i].e(), // [GeV]
255 fPythia->event[i].xProd(), // [mm]
256 fPythia->event[i].yProd(), // [mm]
257 fPythia->event[i].zProd(), // [mm]
258 fPythia->event[i].tProd()); // [mm/c]
259 nparts++;
260 } // particle loop
261 }
262 if(ioff==-1) fNumberOfParticles--;
263 return nparts;
264}
265
266////////////////////////////////////////////////////////////////////////////////
267/// Import particles from Pythia stack
268
270{
271 fParticles->Clear();
272 Int_t ioff = 0;
273 Int_t numpart = fPythia->event.size();
274 if (fPythia->event[0].id() == 90) {
275 numpart--;
276 ioff = -1;
277 }
278
279
281 for (Int_t i = 1; i <= numpart; i++) {
282 new(a[i]) TParticle(
283 fPythia->event[i].id(),
284 fPythia->event[i].isFinal(),
285 fPythia->event[i].mother1() + ioff,
286 fPythia->event[i].mother2() + ioff,
287 fPythia->event[i].daughter1() + ioff,
288 fPythia->event[i].daughter2() + ioff,
289 fPythia->event[i].px(), // [GeV/c]
290 fPythia->event[i].py(), // [GeV/c]
291 fPythia->event[i].pz(), // [GeV/c]
292 fPythia->event[i].e(), // [GeV]
293 fPythia->event[i].xProd(), // [mm]
294 fPythia->event[i].yProd(), // [mm]
295 fPythia->event[i].zProd(), // [mm]
296 fPythia->event[i].tProd()); // [mm/c]
297 }
298 return fParticles;
299}
300
301////////////////////////////////////////////////////////////////////////////////
302/// Initialization
303
305{
306 return (fPythia->event.size() - 1);
307}
308
309////////////////////////////////////////////////////////////////////////////////
310/// Configuration
311
312void TPythia8::ReadString(const char* string) const
313{
314 fPythia->readString(string);
315}
316
317////////////////////////////////////////////////////////////////////////////////
318/// Configuration
319
320void TPythia8::ReadConfigFile(const char* string) const
321{
322 fPythia->readFile(string);
323}
324
325////////////////////////////////////////////////////////////////////////////////
326/// Event listing
327
329{
330 fPythia->settings.listAll();
331}
332
333////////////////////////////////////////////////////////////////////////////////
334/// Event listing
335
337{
338 fPythia->settings.listChanged();
339}
340
341////////////////////////////////////////////////////////////////////////////////
342/// Event listing
343
344void TPythia8::Plist(Int_t id) const
345{
346 fPythia->particleData.list(id);
347}
348
349////////////////////////////////////////////////////////////////////////////////
350/// Event listing
351
353{
354 fPythia->particleData.listAll();
355}
356
357////////////////////////////////////////////////////////////////////////////////
358/// Event listing
359
361{
362 fPythia->particleData.listChanged();
363}
364
365////////////////////////////////////////////////////////////////////////////////
366/// Print end of run statistics
367
369{
370 fPythia->stat();
371}
372
373////////////////////////////////////////////////////////////////////////////////
374/// Event listing
375
377{
378 fPythia->event.list();
379}
380
381////////////////////////////////////////////////////////////////////////////////
382/// Add some pythia specific particle code to the data base
383
385{
387 pdgDB->AddParticle("string","string", 0, kTRUE,
388 0, 0, "QCD string", 90);
389 pdgDB->AddParticle("rho_diff0", "rho_diff0", 0, kTRUE,
390 0, 0, "QCD diffr. state", 9900110);
391 pdgDB->AddParticle("pi_diffr+", "pi_diffr+", 0, kTRUE,
392 0, 1, "QCD diffr. state", 9900210);
393 pdgDB->AddParticle("omega_di", "omega_di", 0, kTRUE,
394 0, 0, "QCD diffr. state", 9900220);
395 pdgDB->AddParticle("phi_diff","phi_diff", 0, kTRUE,
396 0, 0, "QCD diffr. state", 9900330);
397 pdgDB->AddParticle("J/psi_di", "J/psi_di", 0, kTRUE,
398 0, 0, "QCD diffr. state", 9900440);
399 pdgDB->AddParticle("n_diffr0","n_diffr0",0,kTRUE,
400 0, 0, "QCD diffr. state", 9902110);
401 pdgDB->AddParticle("p_diffr+","p_diffr+", 0, kTRUE,
402 0, 1, "QCD diffr. state", 9902210);
403}
404
#define a(i)
Definition RSha256.hxx:99
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
Option_t Option_t option
An array of clone (identical) objects.
void Clear(Option_t *option="") override
Clear the clones array.
Particle database manager class.
static TDatabasePDG * Instance()
static function
virtual TParticlePDG * AddParticle(const char *Name, const char *Title, Double_t Mass, Bool_t Stable, Double_t DecayWidth, Double_t Charge, const char *ParticleClass, Int_t PdgCode, Int_t Anti=-1, Int_t TrackingCode=0)
Particle definition normal constructor.
The interface to various event generators.
Definition TGenerator.h:144
TObjArray * fParticles
Definition TGenerator.h:149
An array of TObjects.
Definition TObjArray.h:31
void Clear(Option_t *option="") override
Remove all objects from the array.
void Delete(Option_t *option="") override
Remove all objects from the array AND delete all heap based objects.
friend class TClonesArray
Definition TObject.h:245
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1124
Description of the dynamic properties of a particle.
Definition TParticle.h:26
TPythia8 is an interface class to C++ version of Pythia 8.1 event generators, written by T....
Definition TPythia8.h:77
void Plist(Int_t id) const
Event listing.
Definition TPythia8.cxx:344
void PlistChanged() const
Event listing.
Definition TPythia8.cxx:360
Int_t ImportParticles(TClonesArray *particles, Option_t *option="") override
Import particles from Pythia stack.
Definition TPythia8.cxx:206
void ListAll() const
Event listing.
Definition TPythia8.cxx:328
void ReadString(const char *string) const
Configuration.
Definition TPythia8.cxx:312
Bool_t Initialize(Int_t idAin, Int_t idBin, Double_t ecms)
Initialization.
Definition TPythia8.cxx:159
void EventListing() const
Event listing.
Definition TPythia8.cxx:376
void GenerateEvent() override
Generate the next event.
Definition TPythia8.cxx:197
void ListChanged() const
Event listing.
Definition TPythia8.cxx:336
Int_t fNumberOfParticles
! Number of particles
Definition TPythia8.h:83
void PrintStatistics() const
Print end of run statistics.
Definition TPythia8.cxx:368
Int_t GetN() const
Initialization.
Definition TPythia8.cxx:304
void PlistAll() const
Event listing.
Definition TPythia8.cxx:352
static TPythia8 * Instance()
Return an instance of TPythia8.
Definition TPythia8.cxx:151
TPythia8(bool printBanner=true)
Constructor.
Definition TPythia8.cxx:103
static TPythia8 * fgInstance
! singleton instance
Definition TPythia8.h:81
void ReadConfigFile(const char *string) const
Configuration.
Definition TPythia8.cxx:320
void AddParticlesToPdgDataBase()
Add some pythia specific particle code to the data base.
Definition TPythia8.cxx:384
Pythia8::Pythia * fPythia
! The pythia8 instance
Definition TPythia8.h:82
~TPythia8() override
Destructor.
Definition TPythia8.cxx:138