How do I read a root file as an input

Hi, I’m trying to read a root file that contains photons’ energy, position, and momentum(direction). I checked G4VAnalysisManager and G4RootAnalysisManager but couldn’t get an answer.
How am I able to do that? Any advices would be very helpful to me. Thank you!!!

Hi yinqifang19,

I presume that this data takes the form of an ntuple? One way to achieve this would be to load the data into a C++ vector, then for each event randomly generate an integer from 0 to the size of the vector to determine which event to simulate.

To read in the data, you could either use the G4RootAnalysisReader or you could make some adjustments to your CMake file to compile with ROOT support. Then, you can open a TTree as normal and import the data as you would with a C++ ROOT program.

There a few more difficulties with multithreading if you only want to load the data into memory once. You can see an example implementation here.

Many thanks,
Jay

I found the solution by transferring those ntuple to different .dat files and then read them in geant4.
Thank you very much!

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