Histograms with Root from Pythia8

Dear developers,

I am trying to couple Pythia8 and Root together.
I mean I want to use Root to diplay histograms from Pythia8.

I have copied the following example from the Welcome Webpage of Pythia:

//gSystem.Load("…/libPythia8");
// File: main01.cc
// This is a simple test program. It fits on one slide in a talk.
// It studies the charged multiplicity distribution at the LHC.
// Copyright C 2007 Torbjorn Sjostrand
//#include “Pythia.h”
#include "TH1.h"
using namespace Pythia8;
int ex1() {
// Generator. Process selection. LHC initialization. Histogram.
Pythia pythia;
pythia.readString(“HardQCD:all = on”);
pythia.readString(“PhaseSpace:pTHatMin = 20.”);
pythia.init( 2212, 2212, 14000.);
TFile *file = TFile::Open(“ex1.root”,“recreate”);
Event *event = &pythia.event;
TTree *T = new TTree(“T”,“ev1 Tree”);
T->Branch(“event”,“Event”,&event);
TH1F *mult = new TH1F(“mult”,“charged multiplicity”, 100, -0.5, 799.5);
// Begin event loop. Generate event. Skip if error. List first one.
for (int iEvent = 0; iEvent < 100; ++iEvent) {
if (!pythia.next()) continue;
//if (iEvent < 1) {pythia.info.list(); pythia.event.list();}
// Find number of all final charged particles and fill histogram.
int nCharged = 0;
for (int i = 0; i < pythia.event.size(); ++i)
if (pythia.event[i].isFinal() && pythia.event[i].isCharged())
++nCharged;
mult->Fill( nCharged );
T->Fill();
// End of event loop. Statistics. Histogram. Done.
}
pythia.statistics();
cout << mult;
T->Print();
T->Write();
delete file;
return 0;
}

When I run this example the error message is:

[mpellen@ppepc22 examples]$ make mymain011
g++ -O2 -ansi -pedantic -W -Wall -Wshadow -I…/include mymain011.cc -o …/bin/mymain011.exe
-L…/lib/archive -lpythia8 -llhapdfdummy
mymain011.cc:8:17: TH1.h: No such file or directory
mymain011.cc:9: error: Pythia8' is not a namespace-name mymain011.cc:9: error: expected namespace-name before ';' token mymain011.cc: In functionint ex1()’:
mymain011.cc:12: error: Pythia' was not declared in this scope mymain011.cc:12: error: expected;’ before "pythia"
mymain011.cc:13: error: pythia' was not declared in this scope mymain011.cc:16: error:TFile’ was not declared in this scope
mymain011.cc:16: error: file' was not declared in this scope mymain011.cc:16: error:TFile’ is not a class or namespace
mymain011.cc:16: error: Open' was not declared in this scope mymain011.cc:17: error:Event’ was not declared in this scope
mymain011.cc:17: error: event' was not declared in this scope mymain011.cc:18: error:TTree’ was not declared in this scope
mymain011.cc:18: error: T' was not declared in this scope mymain011.cc:18: error:TTree’ is not a type
mymain011.cc:20: error: TH1F' was not declared in this scope mymain011.cc:20: error:mult’ was not declared in this scope
mymain011.cc:20: error: TH1F' is not a type mymain011.cc:35: error:cout’ was not declared in this scope
mymain011.cc:38: error: type <type error>' argument given todelete’, expected pointer
mymain011.cc:12: warning: unused variable 'Pythia’
mymain011.cc:16: warning: unused variable 'TFile’
mymain011.cc:16: warning: unused variable 'Open’
mymain011.cc:17: warning: unused variable 'Event’
mymain011.cc:18: warning: unused variable 'TTree’
mymain011.cc:20: warning: unused variable 'TH1F’
mymain011.cc:35: warning: unused variable 'cout’
make: *** [mymain011] Error 1

or:

[mpellen@ppepc22 examples]$ root


  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 5.14/00b 17 January 2007 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      [root.cern.ch](http://root.cern.ch)            *
    
  •                                     *
    

FreeType Engine v2.1.9 used to render TrueType fonts.
Compiled on 3 August 2009 for linux with thread support.

CINT/ROOT C/C++ Interpreter version 5.16.16, November 24, 2006
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] .x mymain011.cc++
Info in TUnixSystem::ACLiC: creating shared library /home/mpellen/Pythia/pythia8135/examples/./mymain011_cc.so
Error: namespace Pythia8 is not defined mymain011.cc:9:
Warning: Error occurred during reading source files
Warning: Error occurred during dictionary source generation
!!!Removing /home/mpellen/Pythia/pythia8135/examples/./file6Xd0j0.cxx /home/mpellen/Pythia/pythia8135/examples/./file6Xd0j0.h !!!
Error: rootcint: error loading headers…
Error in : Dictionary generation failed!
Info in : Invoking compiler to check macro’s validity
/home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:9: error: Pythia8' is not a namespace-name /home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:9: error: expected namespace-name before ';' token /home/mpellen/Pythia/pythia8135/examples/./mymain011.cc: In functionint ex1()’:
/home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:12: error: Pythia' was not declared in this scope /home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:12: error: expected;’ before “pythia”
/home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:13: error: pythia' was not declared in this scope /home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:16: error: incomplete typeTFile’ used in nested name specifier
/home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:17: error: Event' was not declared in this scope /home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:17: error:event’ was not declared in this scope
/home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:18: error: TTree' was not declared in this scope /home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:18: error:T’ was not declared in this scope
/home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:18: error: TTree' is not a type /home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:35: error:cout’ was not declared in this scope
/home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:38: warning: possible problem detected in invocation of delete operator:
/home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:16: warning: file' has incomplete type /usr/local/include/root/TUUID.h:39: warning: forward declaration ofstruct TFile’
/home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:38: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined.
/home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:12: warning: unused variable ‘Pythia’
/home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:17: warning: unused variable ‘Event’
/home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:18: warning: unused variable ‘TTree’
/home/mpellen/Pythia/pythia8135/examples/./mymain011.cc:35: warning: unused variable 'cout’
Error: Function mymain011() is not defined in current scope :0:
*** Interpreter error recovered ***

I think that the problem comes from configuration of Root i.e. executing the following lines:
./configure --enable-pythia8
./configure --with-pythia8-incdir=$PYTHIA8/include
./configure --with-pythia8-libdir=$PYTHIA8/lib

So the problem is that I don’t have access to the configuartion of Root on my computer (computing network at the laboratory).
Is there any other possibility?
I’ve also tried to uncomment the first line and #include “Pythia.h” but it doesn’t work either.

I’ve also tried the tutorial pythia8.C but it doesn’t work either:

root [0] .x pythia8.C
Error in TUnixSystem::DynamicPathName: libEGPythia8[.so | .sl | .dl | .a | .dll] does not exist in .:/usr/local/lib/root:
Error: Symbol TPythia8 is not defined in current scope pythia8.C:33:
Error: Symbol TPythia8 is not defined in current scope pythia8.C:33:
Error: type TPythia8 not defined FILE:/home/mpellen/PythiaRoot/True/./pythia8.C LINE:33
Warning: Automatic variable TPythia8* pythia8 is allocated pythia8.C:33:
Error: Undeclared variable TPythia8* pythia8 pythia8.C:33:
*** Interpreter error recovered ***

Am I missing something? If anybody has any idea how to deal with this problem, please let me know.

Best regards,

Mathieu

see example in $ROOTSYS/tutorials/pythia/pythia8.C

You must have ROOT version 5.26 or newer installed with the option pythia8

Rene

Dear,

Now the tutorial pythia8.C works with the ROOT version 5.26.

So thank you very much for that.

But the first program still doesn’t work.

I think the problem comes from the path to a certain library in ROOT or something like that.
Do you have any idea?

Maybe it’s better to contact Pythia developers too?

Thank you very much,

Best regards,

Mathieu

I’m having similar problem with pythia sample program. When I’m trying to compile the program. I get the following errors.

In file included from /usr/local/root/include/TObject.h:31,
from /usr/local/root/include/TNamed.h:26,
from /usr/local/root/include/TAxis.h:25,
from TH1.h:25,
from trial.cc:14:
/usr/local/root/include/Rtypes.h:147:1: warning: use of C99 long long integer constant
/usr/local/root/include/Rtypes.h:84: error: ISO C++ does not support ‘long long’
/usr/local/root/include/Rtypes.h:85: error: ISO C++ does not support ‘long long’
/usr/local/root/include/TString.h: In member function ‘TString& TString::operator+=(Long64_t)’:
/usr/local/root/include/TString.h:487: warning: ISO C++ does not support the ‘ll’ printf length modifier
/usr/local/root/include/TString.h: In member function ‘TString& TString::operator+=(ULong64_t)’:
/usr/local/root/include/TString.h:490: warning: ISO C++ does not support the ‘ll’ printf length modifier
trial.cc: At global scope:
trial.cc:15: error: ‘Pythia8’ is not a namespace-name
trial.cc:15: error: expected namespace-name before ‘;’ token
trial.cc: In function ‘int ex1()’:
trial.cc:18: error: ‘Pythia’ was not declared in this scope
trial.cc:18: error: expected ;' before ‘pythia’ trial.cc:19: error: ‘pythia’ was not declared in this scope trial.cc:22: error: ‘TFile’ was not declared in this scope trial.cc:22: error: ‘file’ was not declared in this scope trial.cc:22: error: ‘TFile’ is not a class or namespace trial.cc:23: error: ‘Event’ was not declared in this scope trial.cc:23: error: ‘event’ was not declared in this scope trial.cc:24: error: ‘TTree’ was not declared in this scope trial.cc:24: error: ‘T’ was not declared in this scope trial.cc:24: error: expected type-specifier before ‘TTree’ trial.cc:24: error: expected;’ before ‘TTree’
trial.cc:41: error: ‘cout’ was not declared in this scope
trial.cc:44: error: type ‘’ argument given to ‘delete’, expected pointer
make: *** [trial] Error 1

And it goes on for few more pages…
I think the problem is with the Makefile. What changes should I do to the Makefile to use ROOT libraries?

When compiling you must specify -I$ROOTSYS/include and when linking add $ROOTSYS/lib to your LD_LIBRARY_PATH.

Rene

[quote=“brun”]When compiling you must specify -I$ROOTSYS/include and when linking add $ROOTSYS/lib to your LD_LIBRARY_PATH.

Rene[/quote]

Thank you for the reply. I tried that and I’m still getting the errors.

g++ -O2 -ansi -pedantic -W -Wall -Wshadow -I…/include trial.cc -o …/bin/trial.
exe
-L…/lib/archive -lpythia8 -llhapdfdummy
In file included from trial.cc:7:
TH1.h:25:19: error: TAxis.h: No such file or directory
TH1.h:29:22: error: TAttLine.h: No such file or directory
TH1.h:33:22: error: TAttFill.h: No such file or directory
TH1.h:37:24: error: TAttMarker.h: No such file or directory
TH1.h:41:21: error: TArrayC.h: No such file or directory
TH1.h:44:21: error: TArrayS.h: No such file or directory
TH1.h:47:21: error: TArrayI.h: No such file or directory
TH1.h:50:21: error: TArrayF.h: No such file or directory
TH1.h:53:21: error: TArrayD.h: No such file or directory
TH1.h:55:21: error: Foption.h: No such file or directory
TH1.h:58:25: error: TVectorFfwd.h: No such file or directory
TH1.h:61:25: error: TVectorDfwd.h: No such file or directory
TH1.h:75: error: expected class-name before ‘,’ token
TH1.h:75: error: expected class-name before ‘,’ token
TH1.h:75: error: expected class-name before ‘,’ token
TH1.h:75: error: expected class-name before ‘{’ token
TH1.h:78: error: ‘Int_t’ does not name a type
TH1.h:79: error: ‘TAxis’ does not name a type
TH1.h:80: error: ‘TAxis’ does not name a type
TH1.h:81: error: ‘TAxis’ does not name a type
TH1.h:82: error: ‘Short_t’ does not name a type
TH1.h:83: error: ‘Short_t’ does not name a type
TH1.h:84: error: ‘Double_t’ does not name a type
TH1.h:85: error: ‘Double_t’ does not name a type
TH1.h:86: error: ‘Double_t’ does not name a type
TH1.h:87: error: ‘Double_t’ does not name a type
TH1.h:88: error: ‘Double_t’ does not name a type
TH1.h:89: error: ‘Double_t’ does not name a type
TH1.h:90: error: ‘Double_t’ does not name a type
TH1.h:91: error: ‘Double_t’ does not name a type
TH1.h:92: error: ‘TArrayD’ does not name a type

There is huge list of errors about TH1.h and then

trial.cc:8: error: ‘Pythia8’ is not a namespace-name
trial.cc:8: error: expected namespace-name before ‘;’ token
trial.cc: In function ‘int trial()’:
trial.cc:11: error: ‘Pythia’ was not declared in this scope
trial.cc:11: error: expected ;' before ‘pythia’ trial.cc:12: error: ‘pythia’ was not declared in this scope trial.cc:15: error: ‘TFile’ was not declared in this scope trial.cc:15: error: ‘file’ was not declared in this scope trial.cc:15: error: ‘TFile’ is not a class or namespace trial.cc:16: error: ‘Event’ was not declared in this scope trial.cc:16: error: ‘event’ was not declared in this scope trial.cc:17: error: ‘TTree’ was not declared in this scope trial.cc:17: error: ‘T’ was not declared in this scope trial.cc:17: error: expected type-specifier before ‘TTree’ trial.cc:17: error: expected;’ before ‘TTree’
trial.cc:19: warning: passing ‘double’ for argument 4 to ‘TH1F::TH1F(const char* , const char*, int, int, int)’
trial.cc:19: warning: passing ‘double’ for argument 5 to ‘TH1F::TH1F(const char* , const char*, int, int, int)’
trial.cc:29: error: ‘class TH1F’ has no member named ‘Fill’
trial.cc:34: error: ‘cout’ was not declared in this scope
trial.cc:37: error: type ‘’ argument given to ‘delete’, expected poi

What am I missing?

you did not follow my instructions. Please reread my mail.

Rene

[quote=“brun”]When compiling you must specify -I$ROOTSYS/include and when linking add $ROOTSYS/lib to your LD_LIBRARY_PATH.

Rene[/quote]

Hi I am having the same problem while running the ex1.C code i.e using ROOT for histrogramm in pythia. I don’t know what to do. I have ROOT version 5.26 and pythia8145. The example in /root/tutorial/pythia/pyhia8.C is working perfactly fine but the example in /pythia8145/rootexample/goex1 in giving errors. Can you please suggest me some solution to it.

Regards
WA

Hi,

I also coudn’t get this working.

You gave 2 instructions:

  1. “When compiling you must specify -I$ROOTSYS/include”

What does it mean? I understood one should simply add “-I$ROOTSYS/include” to “goex1” and try “./goex1”, since goex1 does the compilation.

  1. “and when linking add $ROOTSYS/lib to your LD_LIBRARY_PATH.”

I added the following to my “.bashrc”:

export ROOTSYS=/MyRootPath/
export PATH=$ROOTSYS/bin:$PATH
export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH

So, I’m either following instructions 1) or 2), or both incorrectly.

Could you please point me out what I got wrong?

Thank you.

Hi,

Pythia8143 has a few problems with ROOT; we’re working on them. Check Pythia 8 root file corrupt for updates.

Cheers, Axel.