Structure of stored Tuples

Hello!
I am relatively new to Geant4, and wanted to ask a thing about how I can store some simulated events. The idea is to build a .root file with some variables (positions, momenta and deposited energies per step). Right now I managed to dump everything in a single file, but I would like to add some structure to it. Essentially, if I generate 100 photons, I would like to access the data for every single one of them by opening the file in root with something like
‘’’
TFile* my_file = new TFile(‘photons.root’);
TTree* my_tree = (TTree*)my_file->Get(“stored_tree”);
… //code
my_tree->GetEntry(index)
‘’’
where index running from 0 to 99 selects the single events.
If you have any idea, example or pointer it would be extremely helpful :slight_smile:
Thank you!

Federico

Store structured data. If you’re dealing with ROOT directly in your G4 application, then you could define “nested branches”, where you have a top level branch with one entry per event, and that branch has “child branches” for the individual hits. You could also define a class object with a ROOT “ClassDictionary”, and save fully structured data. In both those cases, see the ROOT documentation for what to do.

If you want to stick with a very simple N-tuple, with one row per hit, then just add a new column with “EventID”, that you store for each hit. you might even want to include TrackID and ParentID columns, to let you do some analysis of the event structure, not just the deposited energy. In this model, you would process your data with actual code, where you loop over entries and select/consolidate the ones with the same EventID value.

Numpy_root provides some very nice functionality for doing this compactly in Python. RDataFrame also provices similarly nice functionality in a plain ROOT environment.

Thanks a lot! The ID column does the job for now, but I’ll definitely have a look at the rest in a while :slight_smile:

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