Fatal error: TTree.h while using Root and Geant4

Hi Everyone!
I tried to run a code but got this problem:

[  4%] Building CXX object CMakeFiles/emphaticSim.dir/emphaticSim.cc.o
/emph/app/ydeniz/local/GCC-8.2.0/bin/g++  -DG4ANALYSIS_USE_ROOT -DG4INTY_USE_XT -DG4LIB_BUILD_DLL -DG4UI_USE_TCSH -DG4VIS_USE_OPENGL -DG4VIS_USE_OPENGLX -I/emph/app/ydeniz/EMPHATIC/DetectorSim/EMPHATICSim/include -I/emph/app/ydeniz/EMPHATIC/DetectorSim/EMPHATICSim/include/Materials -I/emph/app/ydeniz/EMPHATIC/DetectorSim/EMPHATICSim/include/Detectors -isystem /emph/app/ydeniz/GEANT4/geant4.10.6/geant4.10.06-install/include/Geant4  -W -Wall -pedantic -Wno-non-virtual-dtor -Wno-long-long -Wwrite-strings -Wpointer-arith -Woverloaded-virtual -Wno-variadic-macros -Wshadow -pipe -std=c++11  -O3 -DNDEBUG -fno-trapping-math -ftree-vectorize -fno-math-errno -O3 -DNDEBUG   -o CMakeFiles/emphaticSim.dir/emphaticSim.cc.o -c /emph/app/ydeniz/EMPHATIC/DetectorSim/EMPHATICSim/emphaticSim.cc
In file included from /emph/app/ydeniz/EMPHATIC/DetectorSim/EMPHATICSim/emphaticSim.cc:3:
/emph/app/ydeniz/EMPHATIC/DetectorSim/EMPHATICSim/include/EMPHATICSimAnalysisManager.hh:6:10: fatal error: TTree.h: No such file or directory

Have you faced something similar?

I did some research and found similar problems… i understand that the possible issue could be a wrong header location for ROOT

Is there a way to specify the correct headers in cmake or make command while building the simulation.

Any other suggestion or approach would be appreciate.
Sorry if it is a basic question and thanks for all your time guys! :slight_smile:


It seems that the PATH to ROOT is not set up correctly.
In general you should set-up in your environment:

export ROOTSYS=/path_to_ROOT/root
export PATH

(not sure why the dollar sign does not appear before the { but it should be included)

Then you have to change your CMakeLists.txt to link ROOT libraries. Look at the extended example: AnaEx02/CMakeLists.txt

I hope this helps,

1 Like

@guatelli Thanks a lot!! i will tried this now! Can you update AnaEx02/CMakeLists.txt i think the link did’t save any file and It would be super helpful for me :slight_smile:

Best, Yael.

You can find it in the examples/extended/analysis directory of Geant4

1 Like

@guatelli Thanks for all the time you have spent on this post and sorry for bothering you again, i’m still learning how GEANT4 works so i’m still a novice here.

I ran AnaEx02 to find out if it has the same error as my simulations. i can run the AnaEx02 sim but no histograms or Root canvas are displayed. The Root canvas are see in a different location or they must be displayed alongside the simulation?

I also modified my .bashrc and .bash_profile as you suggested (i add some more variables i found online) but still getting the same error, even i remove CmakeCache from the building dir.

Here is my current bash: BASHYAEL.txt (1005 Bytes)

Is that the correct variable set up for G4 and Root Interface?
i really appreciate one last advice, since i’m running out of options :upside_down_face:

Hi. I have done as follows:
source path_to_root/bin/thisroot.sh
then I compiled AnaEx02 and I ran it. The output of the simulation is AnaEx02.root. Then you need to use root to open it. e.g.
type: root
then you can create a TBrowser which allows to navigate easily in the root file. Type: new TBrowser()
then you will see your directories. Click on the root file you intend to open.

I hope this helps you.


1 Like

@Thanks!! I figure out how to set up my CMakeList properly!!

Also Ana Run Successfully :slight_smile:
i really appreciate your time

Cheers, Yael

Dear @guatelli ,

what do you mean path_to_ROOT? The path where the executable is located? Since I don’t find any path which contain lib in a root folder.
Anyway, I think it is not the problem of my case and I did not set ROOTSYS. I tried to run the example and I have the following message:

-- Found nlohmann_json: /lib64/cmake/nlohmann_json/nlohmann_jsonConfig.cmake (found suitable version "3.6.1", minimum required is "3.6.1") 
-- Configuring done
-- Generating done
-- Build files have been written to: /gpfs0/gilad/users/castagna/Geant4/Geant4_examples/AnaEx02/build
[ 20%] Building CXX object CMakeFiles/AnaEx02.dir/AnaEx02.cc.o
[ 40%] Building CXX object CMakeFiles/AnaEx02.dir/shared/src/DetectorConstruction.cc.o
[ 40%] Building CXX object CMakeFiles/AnaEx02.dir/shared/src/ActionInitialization.cc.o
[ 40%] Building CXX object CMakeFiles/AnaEx02.dir/shared/src/DetectorMessenger.cc.o
[ 50%] Building CXX object CMakeFiles/AnaEx02.dir/shared/src/EventAction.cc.o
[ 60%] Building CXX object CMakeFiles/AnaEx02.dir/shared/src/PrimaryGeneratorAction.cc.o
[ 70%] Building CXX object CMakeFiles/AnaEx02.dir/shared/src/RunAction.cc.o
[ 80%] Building CXX object CMakeFiles/AnaEx02.dir/shared/src/SteppingAction.cc.o
[ 90%] Building CXX object CMakeFiles/AnaEx02.dir/src/HistoManager.cc.o
In file included from /usr/include/root/RtypesCore.h:23,
                 from /usr/include/root/Rtypes.h:23,
                 from /usr/include/root/TObject.h:17,
                 from /usr/include/root/TNamed.h:25,
                 from /usr/include/root/TAxis.h:24,
                 from /usr/include/root/TH1.h:24,
                 from /usr/include/root/TH1D.h:24,
                 from /gpfs0/userFolder/Geant4/Geant4_examples/AnaEx02/src/HistoManager.cc:33:
/usr/include/root/ROOT/RConfig.hxx:48:4: error: #error "ROOT requires support for C++14 or higher."
 #  error "ROOT requires support for C++14 or higher."
/usr/include/root/ROOT/RConfig.hxx:50:5: error: #error "Pass `-std=c++14` as compiler argument."
 #   error "Pass `-std=c++14` as compiler argument."

Any suggestion, please?
Thanks in advance for your time.
Best regards,


Which version of Geant4 are you using? The above error suggests that Geant4 was built with C++11, and ROOT is requiring 14 or better. If Geant4 is 10.7 or older, then C++11 will be the default. It should be possible to build your example as:

$ cmake -DCMAKE_CXX_STANDARD=14 <otherargs>

to force the standard to 14 if it’s not using it already.

1 Like

@bmorgan, it works, thank you very much!

I have the following warning but I don’t think should be a problem:

/bin/ld: warning: libhdf5.so.103, needed by /projects/Geant4/geant4.10.07-install/lib64/libG4Tree.so, may conflict with libhdf5.so.200
/bin/ld: warning: libhdf5.so.103, needed by /projects/Geant4/geant4.10.07-install/lib64/libG4Tree.so, may conflict with libhdf5.so.200


That might cause an issue as the hdf5 libraries look to have different versions. That might cause odd runtime errors if your application uses the hdf5 functionality. If you don’t need hdf5, I’d recommend reinstalling Geant4 without this enabled.

1 Like

Ok @bmorgan thanks for the clarification and your very useful answers!