Running Pythia8 under Root

Please read tips for efficient and successful posting and posting code

_ROOT Version: 6.26.04
_Platform: ubuntu 22.04
Pythia version: 8.307

Hello, I’m new to both Root and Pythia and I have some trouble with linking them. I tried multiple things and still can’t figure to fix this. So first, I got a doc from my advisor explaining how to link them, but it’s talking about root-6.18.04 and pythia 8.240, when I tried to follow that I got multiple errors with installing root and pythia. So I went for latest versions, I tried two ways.
The first way is that I built root from source while configure it to have pythia on, then built and installed pythia then went back to install root.
There are two examples in pythia that I should run, main91 and main92 and then another test file to make sure they are linked fine. Using this way main91 worked fine but main92 returned this error:
“Warning in TBufferFile::WriteObjectAny: since _Sp_counted_ptr_inplace<Pythia8::ParticleDataEntry,allocatorPythia8::ParticleDataEntry,__gnu_cxx::_S_atomic> has no public constructor which can be called without argument, objects of this class
can not be read with the current library. You will need to add a default constructor before attempting to read it.”

Then the test file returned the error:
fatal error: TH1F.h: No such file or directory

The other way that I tried is to build and install Root first then build and install Pythia while configuring both to share/see each other.
This way made the main91 and main92 work fine, but the test file didn’t work and still return the same fatal error: TH1F.h: No such file or directory
I then followed this link: How to add libariers and used the commands given and now I’m getting this error:
g++: fatal error: no input files [while searching they say that this shouldn’t occur if I’m running the files from the correct folder, which I ensured to do but still got the error]
Any help or thoughts with this?
Thanks in advance

Hi @Elhussein_Ahmed_Osam,

You seem to have managed to build ROOT with Pythia support. The only problem now seems to be in the g++ command line; in particular, it is missing the include search paths. Could you share it so that we can further help you?

In principle, assuming that you are compiling a single translation unit, it should resemble the following (note the backquotes, as those cause root-config’s output be inserted in-place):

$ g++ `root-config --cflags --libs` -o test test.C


Hi @jalopezg, I tried to use the command:

g++ -c `root-config --cflags`

[the test file is called main023] but that would return the error: fatal error: ‘Pythia8/Pythia.h’ file not found
#include “Pythia8/Pythia.h”

Now when I change it to the command:

g++ -c `root-config --cflags`  -I${PYTHIA_INCLUDE_DIR}

I’d get the current error which is:
g++: fatal error: no input files

That error seems to be caused due to PYTHIA_INCLUDE_DIR is not defined. You could manually set it to the directory where Pythia headers have been installed, i.e.

$ PYTHIA_INCLUDE_DIR=/path/to/pythia/headers

On a different note, could you check that $ root-config --features shows support for pythia8?


Okay, I’ll try it and see what I get. Meanwhile, the root-config --features show support for pythia8, I also used the command that has something like “haspythia8” and showed yes for me.

When I try the command

g++ `root-config --cflags --libs` -o main023 main023.C

I get the error:
cc1plus: fatal error: main023.C: No such file or directory
I then changed it to be:

g++ `root-config --cflags --libs` -o main023 main023.cpp

And got this error again:
main023.cpp:9:10: fatal error: Pythia8/Pythia.h: No such file or directory
9 | #include “Pythia8/Pythia.h”

And when I set the pythia headers using the:

$ PYTHIA_INCLUDE_DIR=/path/to/pythia/headers

Then run the command:

g++ -c `root-config --cflags`  -I${PYTHIA_INCLUDE_DIR} main023

I get this:

g++: warning: main023: linker input file unused because linking not done
g++: error: main023: linker input file not found: No such file or directory

What about this (no -c option, so as to also invoke the linker to generate an ELF executable)?

g++ `root-config --cflags --libs`  -I${PYTHIA_INCLUDE_DIR} -o main023 main023.cpp

It now goes back to the old error :frowning:

main023.cpp:9:10: fatal error: Pythia8/Pythia.h: No such file or directory
    9 | #include "Pythia8/Pythia.h"
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.

I’m trying to follow this question as well pythia8-pythia.h-no-such-file
but the commands there like:

pythia8-config --cppflags --libs --cxxflags

which pythia8-config
don’t work and I get: pythia8-config: command not found
If I try:
I’d get:
bash: ./pythia8-config: No such file or directory

Not sure what I should do now. Sorry for taking a lot of your time :frowning:

Unless you set PYTHIA_INCLUDE_DIR as part of shell initialization (e.g. in .bashrc), it has to be set manually on each session, i.e. if you are on a new shell, you must set it again. Therefore, if that works, I’d recommend adding that line to your .bashrc file.

Regarding this, it seems that the Pythia8 installation directory is not part of your PATH environment variable

@jalopezg I did as you said and it doesn’t show the error now. But I’m getting a lot of warnings like this then it exists

Not sure if this has to do with the test file or is related to my root/pythia. Do you have any idea about that?

@jalopezg Thanks a lot for your help. I made it run by the following command:

g++ -I/home/alhussein/Downloads/pythia8307/include `root-config --cflags` -o main023 -lpythia8 -L/home/alhussein/Downloads/pythia8307/lib `root-config --glibs`

Not sure why this one worked but yours didn’t, but it’s almost the same. Thanks a lot again!

1 Like