StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
hist.cc
1 // File: hist.cc
2 // This is a simple test program.
3 // It studies the charged multiplicity distribution at the LHC.
4 // Modified by Rene Brun, Axel Naumann and Bernhard Meirose
5 // to use ROOT for histogramming.
6 // Copyright (C) 2012 Torbjorn Sjostrand
7 
8 // Stdlib header file for input and output.
9 #include <iostream>
10 
11 // Header file to access Pythia 8 program elements.
12 #include "Pythia.h"
13 
14 // ROOT, for histogramming.
15 #include "TH1.h"
16 
17 // ROOT, for interactive graphics.
18 #include "TVirtualPad.h"
19 #include "TApplication.h"
20 
21 // ROOT, for saving file.
22 #include "TFile.h"
23 
24 using namespace Pythia8;
25 
26 int main(int argc, char* argv[]) {
27 
28  // Create the ROOT application environment.
29  TApplication theApp("hist", &argc, argv);
30 
31  // Create Pythia instance and set it up to generate hard QCD processes
32  // above pTHat = 20 GeV for pp collisions at 14 TeV.
33  Pythia pythia;
34  pythia.readString("HardQCD:all = on");
35  pythia.readString("PhaseSpace:pTHatMin = 20.");
36  pythia.readString("Beams:eCM = 14000.");
37  pythia.init();
38 
39  // Create file on which histogram(s) can be saved.
40  TFile* outFile = new TFile("hist.root", "RECREATE");
41 
42  // Book histogram.
43  TH1F *mult = new TH1F("mult","charged multiplicity", 100, -0.5, 799.5);
44 
45  // Begin event loop. Generate event; skip if generation aborted.
46  for (int iEvent = 0; iEvent < 100; ++iEvent) {
47  if (!pythia.next()) continue;
48 
49  // Find number of all final charged particles.
50  int nCharged = 0;
51  for (int i = 0; i < pythia.event.size(); ++i)
52  if (pythia.event[i].isFinal() && pythia.event[i].isCharged())
53  ++nCharged;
54 
55  // Fill charged multiplicity in histogram. End event loop.
56  mult->Fill( nCharged );
57  }
58 
59  // Statistics on event generation.
60  pythia.stat();
61 
62  // Show histogram. Possibility to close it.
63  mult->Draw();
64  std::cout << "\nDouble click on the histogram window to quit.\n";
65  gPad->WaitPrimitive();
66 
67  // Save histogram on file and close file.
68  mult->Write();
69  delete outFile;
70 
71  // Done.
72  return 0;
73 }