Branch cannot find class in Geant4

Dear ROOT Experts,

I want to save a class named “PrimaryHits” in a Geant4 application.

In the run action class (named “”), I create a branch as below:

phit = new PrimaryHits;
tree->Branch("event", "PrimaryHits", &phit);

The source file (“”) is placed in /src directory, and the header file and LinkDef file is placed in /include directory.

I generated in the /include directory with these commands:

`root-config --cxx --cflags` -fPIC -c ../src/
rootcint -f -c -p PrimaryHits.hh LinkDef.hh
`root-config --cxx --cflags` -fPIC -c
`root-config --cxx --cflags` -fPIC -shared -o PrimaryHits.o PrimaryHitsDict.o

Then i copied the generated and pcm file in directory /lib

I linked the in the cmake file with the command:

set(PrimaryHits_LIBRARIES "/home/cihenp/g4proj/MuImag/lib/")
target_link_libraries(MuImag ${PrimaryHits_LIBRARIES})

The Geant4 application compiles well, but when i execute it, an error occurs saying that:
Error in TTree::Bronch: Cannot find class:PrimaryHits

Does it mean the library has been loaded but the reflection process is not successful?
Is there anything wrong with the steps above?

Zhi Yu

Hi Zhi Yu,

I assume you are using ROOT6, if you are not, I encourage you to move to ROOT6.
Your procedure is correct. You just need to generate a rootmap file and put it next to in order to allow ROOT to autoload the class and its dictionary at runtime. To see how to generate the rootmap with the rootcint invocation, just type

rootcint -h

In a nutshell, your command should become

rootcint -f -rmf libPrimaryHits.rootmap -rml -c -p PrimaryHits.hh LinkDef.hh


Hi dpiparo,

Yes, I am using ROOT6 and the problem has been solved thanks to your reply.:smiley:

Zhi Yu

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.