Manipulation of root files returned by a SecondaryProduction actor

Dear Root users,

I am using GATE (an open source software dedicated to digital simulations in medical imaging and radiotherapy) to analyze the secondary particles produced after an X-rays irradiation simulation.

I use a SecondaryProductionActor and my GATE simulations give rise to .root files in which I can found the number of secondaries in function of the particle type. I know how to open the root file through the root prompt

which gives rise to

But I would like to display the number of particles for a specific category of secondaries, let’s say for example the e+. How can I do that ?



command seems to display all types of secondaries and the result is not really readable.
In addition, the goal is subsequently to record the number of particles produced for each type in an excel file.

If anyone could give me some pointers on how to get started, I was able to do this task for root files returned by a phaseSpace actor but failed to do so in the case of the SecondaryProductionActor…

Many thank for the help,

Platform : Ubuntu 20.04.6 LTS
Root version : ROOT Version: 6.30/04

The histogram drawing options are here:
I guess you tried Draw("e+") thinking this will select the bin of “e+” (if there is such a bin in the histogram), but that’s not what it does. “E” draws errors, and the “+” in “e+” is ignored (see page above).
You could just zoom in on the x-axis and display only “e+” if you find it, or find the bin number to which it corresponds and then limit the axis range with SetRangeUser, e.g., supposing it is bin 4:


note that the range is from bin i-1 to bin i, if “e+” is bin i.
To find out the bin number, you can print all bin labels and numbers like this:

for (int i=1; i<=h->GetXaxis()->GetNbins(); ++i) {
  cout << i << " " << h->GetXaxis()->GetBinLabel(i) << endl;

With this, you can figure out the rest (you can use h->GetBinContent(yourbinnumber))

Dear dastudillo,

Thank you so much for your help!
Yes, I did try to draw the bin labelled “e+” in the histogram this way.

So know I know how to recover some bin label and its corresponding value through the root prompt :


In order to make a root macro that displays all bin label and corresponding values, how can I recover the variable “fragments” that corresponds to the TH1F object? This does not work :

void dataMacro()
    string path_HYB = "/home/sarah/Documents/ROOT/Layer1-Secondaries.root";

    TFile *f = new TFile("Layer1-Secondaries.root");

    for (int i=1; i<=f.fragments->GetXaxis()->GetNbins(); ++i)
            cout << i << " " << f.fragments->GetXaxis()->GetBinLabel(i) << " " << f.fragments->GetBinContent(i) << endl;

I’m currently reading the link ROOT: THistPainter Class Reference you sent me.

Many thanks,

Check out the histogram tutorials:
for instance, this one to read from a TFile:

It’s okey, it works fine know, thank you very much for your patience and help !

void dataMacro2()
   TFile *f = TFile::Open("/home/sarah/Documents/ROOT/Layer1-Secondaries.root");

   TH1 *hpx = nullptr;

   f->GetObject("fragments", hpx);

   for (int i=1; i<=hpx->GetXaxis()->GetNbins(); ++i)
            if (hpx->GetBinContent(i) != 0)
                cout << hpx->GetXaxis()->GetBinLabel(i) << " : " << hpx->GetBinContent(i) << endl;
1 Like