Root macro to retrieve and copy in a csv file the number of photo-electrons from a root file

Dear Root users,

I am using GATE (an open source software dedicated to digital simulations in medical imaging and radiotherapy) to analyze some radio physical quantities (photo-electrons for example) after an X-rays irradiation simulation. I’m using root 6.28/08 on Ubuntu 20.04.6 LTS.

My GATE simulations give rise to .root files in which I can found the number of photo-electrons produced.

I know how to recover this number “by hand” in the T Browser :

or through the root prompt :

But I would like to make a root macro that goes through each root files, recover and copy the number of photo-electrons produced for each root file into an ods or csv file.

I know how to open my root file :

std::unique_ptr myFile( TFile::Open(“phaseSpaceCluster_IN.root”) );

but I can’t manage to find how to retrieve the number of photo-electrons…
In other words, how can I implement the root prompt command line

PhaseSpace->Draw(“Ekine”,“CreatorProcess=="PhotoElectric"”)

into a root macro ? Does anyone have any tips to help me?

Many thanks for your help!

Sarah

You can read the tree with an RDataFrame and use Filter() and Count():

void test() {
  ROOT::RDataFrame d("PhaseSpace", "phaseSpaceCluster_IN.root");
  auto n = d.Filter("CreatorProcess==\"PhotoElectric\"").Count();
  cout << *n << endl;
}

(save as test.C)
Note the *n, since Count() returns a pointer.

More on dataframes:

https://root.cern/doc/master/classROOT_1_1RDataFrame.html

1 Like

Thank you so much for your response dastudillo!

While I’m reading the dataframes info you suggested, here is the error I obtain when running your code:

Check out this thread:

Thank you so much dastudillo, it works !