Using Pythia6 with ROOT.
To make an event sample (of size 100) do
shell> root
root [0] .L pythiaExample.C
root [1] makeEventSample(1000)
To start the tree view on the generated tree, do
shell> root
root [0] .L pythiaExample.C
root [1] showEventSample()
The following session:
shell> root
root [0] .x pythiaExample.C(500)
will execute makeEventSample(500) and showEventSample()
Alternatively, you can compile this to a program and then generate 1000 events with
To use the program to start the viewer, do
NOTE 1: To run this example, you must have a version of ROOT compiled with the Pythia6 version enabled and have Pythia6 installed. The statement gSystem->Load("$HOME/pythia6/libPythia6");
(see below) assumes that the directory containing the Pythia6 library is in the pythia6 subdirectory of your $HOME. Locations that can specify this, are:
Root.DynamicPath resource in your
ROOT configuration file
(/etc/root/system.rootrc or ~/.rootrc).
Runtime load paths set on the executable (Using GNU ld,
specified with flag `-rpath').
Dynamic loader search path as specified in the loaders
configuration file (On GNU/Linux this file is
etc/ld.so.conf).
For Un*x: Any directory mentioned in LD_LIBRARY_PATH
For Windows: Any directory mentioned in PATH
NOTE 2: The example can also be run with ACLIC:
root >
gSystem->
Load(
"$ROOTSYS/../pythia6/libPythia6");
root > .x pythiaExample.C+
#include <cstdlib>
#define FILENAME "pythia.root"
#define TREENAME "tree"
#define BRANCHNAME "particles"
#define HISTNAME "ptSpectra"
#define PDGNUMBER 211
void loadLibraries()
{
#ifdef R__MACOSX
#endif
}
int makeEventSample(
Int_t nEvents)
{
loadLibraries();
if (!file || !file->IsOpen()) {
Error(
"makeEventSample",
"Couldn;t open file %s", FILENAME);
return 1;
}
TTree* tree = new TTree(TREENAME, "Pythia 6 tree");
tree->Branch(BRANCHNAME, &particles);
for (
Int_t i = 0; i < nEvents; i++) {
if (i % 100 == 0)
cout << "Event # " << i << endl;
tree->Fill();
}
tree->Print();
TH1D* hist =
new TH1D(HISTNAME,
"p_{#perp} spectrum for #pi^{+}",
100, 0, 3);
char expression[64];
sprintf(expression,"sqrt(pow(%s.fPx,2)+pow(%s.fPy,2))>>%s",
BRANCHNAME, BRANCHNAME, HISTNAME);
char selection[64];
sprintf(selection,"%s.fKF==%d", BRANCHNAME, PDGNUMBER);
tree->Draw(expression,selection);
hist->
Fit(
"expo",
"QO+",
"", .25, 1.75);
file->Write();
file->Close();
return 0;
}
int showEventSample()
{
loadLibraries();
if (!file || !file->IsOpen()) {
Error(
"showEventSample",
"Couldn;t open file %s", FILENAME);
return 1;
}
TTree* tree = (TTree*)file->Get(TREENAME);
if (!tree) {
Error(
"showEventSample",
"couldn't get TTree %s", TREENAME);
return 2;
}
tree->StartViewer();
TH1D* hist = (
TH1D*)file->Get(HISTNAME);
if (!hist) {
Error(
"showEventSample",
"couldn't get TH1D %s", HISTNAME);
return 4;
}
char expression[64];
sprintf(expression,
"T #approx %5.1f", -1000 / func->
GetParameter(1));
latex->SetTextSize(.1);
latex->SetTextColor(4);
latex->Draw();
return 0;
}
void pythiaExample(
Int_t n=1000) {
makeEventSample(n);
showEventSample();
}
#ifndef __CINT__
int main(
int argc,
char** argv)
{
if (argc > 1)
n = strtol(argv[1], NULL, 0);
int retVal = 0;
if (n > 0)
retVal = makeEventSample(n);
else {
retVal = showEventSample();
app.Run();
}
return retVal;
}
#endif
- Author
- Christian Holm Christensen
Definition in file pythiaExample.C.