Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
evegen_000_pythia8.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_evegen
3/// pythia8 basic example
4///
5/// to run, do:
6///
7/// ~~~{.cpp}
8/// root > .x evegen_000_pythia8.C
9/// ~~~
10///
11/// \macro_code
12///
13/// \author Andreas Morsch
14
15#include "TSystem.h"
16#include "TH1F.h"
17#include "TClonesArray.h"
18#include "TPythia8.h"
19#include "TParticle.h"
20#include "TDatabasePDG.h"
21#include "TCanvas.h"
22
23void evegen_000_pythia8(Int_t nev = 100, Int_t ndeb = 1)
24{
25// Load libraries
26 gSystem->Load("libEG");
27 gSystem->Load("libEGPythia8");
28// Histograms
29 TH1F* etaH = new TH1F("etaH", "Pseudorapidity", 120, -12., 12.);
30 TH1F* ptH = new TH1F("ptH", "pt", 50, 0., 10.);
31
32
33// Array of particles
34 TClonesArray* particles = new TClonesArray("TParticle", 1000);
35// Create pythia8 object
36 TPythia8* pythia8 = new TPythia8();
37
38// Configure
39 pythia8->ReadString("HardQCD:all = on");
40 pythia8->ReadString("Random:setSeed = on");
41 // use a reproducible seed: always the same results for the tutorial.
42 pythia8->ReadString("Random:seed = 42");
43
44
45// Initialize
46
47 pythia8->Initialize(2212 /* p */, 2212 /* p */, 14000. /* TeV */);
48
49// Event loop
50 for (Int_t iev = 0; iev < nev; iev++) {
51 pythia8->GenerateEvent();
52 if (iev < ndeb) pythia8->EventListing();
53 pythia8->ImportParticles(particles,"All");
54 Int_t np = particles->GetEntriesFast();
55// Particle loop
56 for (Int_t ip = 0; ip < np; ip++) {
57 TParticle* part = (TParticle*) particles->At(ip);
58 Int_t ist = part->GetStatusCode();
59 // Positive codes are final particles.
60 if (ist <= 0) continue;
61 Int_t pdg = part->GetPdgCode();
63 if (charge == 0.) continue;
64 Float_t eta = part->Eta();
65 Float_t pt = part->Pt();
66
67 etaH->Fill(eta);
68 if (pt > 0.) ptH->Fill(pt, 1./(2. * pt));
69 }
70 }
71
72 pythia8->PrintStatistics();
73
74 TCanvas* c1 = new TCanvas("c1","Pythia8 test example",800,800);
75 c1->Divide(1, 2);
76 c1->cd(1);
77 etaH->Scale(5./Float_t(nev));
78 etaH->Draw();
79 etaH->SetXTitle("#eta");
80 etaH->SetYTitle("dN/d#eta");
81
82 c1->cd(2);
83 gPad->SetLogy();
84 ptH->Scale(5./Float_t(nev));
85 ptH->Draw();
86 ptH->SetXTitle("p_{t} [GeV/c]");
87 ptH->SetYTitle("dN/dp_{t}^{2} [GeV/c]^{-2}");
88 }
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
#define gPad
The Canvas class.
Definition TCanvas.h:23
An array of clone (identical) objects.
static TDatabasePDG * Instance()
static function
TParticlePDG * GetParticle(Int_t pdgCode) const
Get a pointer to the particle object according to the MC code number.
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:908
virtual void SetXTitle(const char *title)
Definition TH1.h:697
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3489
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3193
virtual void SetYTitle(const char *title)
Definition TH1.h:698
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition TH1.cxx:6815
Int_t GetEntriesFast() const
Definition TObjArray.h:58
TObject * At(Int_t idx) const override
Definition TObjArray.h:170
Double_t Charge() const
Description of the dynamic properties of a particle.
Definition TParticle.h:26
Int_t GetStatusCode() const
Definition TParticle.h:82
Int_t GetPdgCode() const
Definition TParticle.h:83
Double_t Pt() const
Definition TParticle.h:135
Double_t Eta() const
Definition TParticle.h:137
TPythia8 is an interface class to C++ version of Pythia 8.1 event generators, written by T....
Definition TPythia8.h:77
Int_t ImportParticles(TClonesArray *particles, Option_t *option="") override
Import particles from Pythia stack.
Definition TPythia8.cxx:206
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 PrintStatistics() const
Print end of run statistics.
Definition TPythia8.cxx:368
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1880
TPaveText * pt
return c1
Definition legend1.C:41