StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tree.cc
1 // File: tree.cc
2 // This is a simple test program.
3 // Modified by Rene Brun and Axcel Naumann to put the Pythia::event
4 // into a TTree.
5 // Copyright (C) 2014 Torbjorn Sjostrand
6 
7 // Header file to access Pythia 8 program elements.
8 #include "Pythia8/Pythia.h"
9 
10 // ROOT, for saving Pythia events as trees in a file.
11 #include "TTree.h"
12 #include "TFile.h"
13 
14 using namespace Pythia8;
15 
16 int main() {
17 
18  // Create Pythia instance and set it up to generate hard QCD processes
19  // above pTHat = 20 GeV for pp collisions at 14 TeV.
20  Pythia pythia;
21  pythia.readString("HardQCD:all = on");
22  pythia.readString("PhaseSpace:pTHatMin = 20.");
23  pythia.readString("Beams:eCM = 14000.");
24  pythia.init();
25 
26  // Set up the ROOT TFile and TTree.
27  TFile *file = TFile::Open("pytree.root","recreate");
28  Event *event = &pythia.event;
29  TTree *T = new TTree("T","ev1 Tree");
30  T->Branch("event",&event);
31 
32  // Begin event loop. Generate event; skip if generation aborted.
33  for (int iEvent = 0; iEvent < 100; ++iEvent) {
34  if (!pythia.next()) continue;
35 
36  // Fill the pythia event into the TTree.
37  // Warning: the files will rapidly become large if all events
38  // are saved. In some cases it may be convenient to do some
39  // processing of events and only save those that appear
40  // interesting for future analyses.
41  T->Fill();
42 
43  // End event loop.
44  }
45 
46  // Statistics on event generation.
47  pythia.stat();
48 
49  // Write tree.
50  T->Print();
51  T->Write();
52  delete file;
53 
54  // Done.
55  return 0;
56 }