# Manipulation of root files returned by a SecondaryProduction actor

**URL:** <https://root-forum.cern.ch/t/manipulation-of-root-files-returned-by-a-secondaryproduction-actor/59428>\
**Category:** Newbie\
**Tags:** root\
**Created:** [May 22, 2024, 6:07am UTC](https://root-forum.cern.ch/t/manipulation-of-root-files-returned-by-a-secondaryproduction-actor/59428 "2024-05-22T06:07:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SarahBlind](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@SarahBlind](https://root-forum.cern.ch/u/SarahBlind)\
**Post date:** [May 22, 2024, 6:07am UTC](https://root-forum.cern.ch/t/manipulation-of-root-files-returned-by-a-secondaryproduction-actor/59428/1 "2024-05-22T06:07:53Z")

</div>

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

 ![2](https://root-forum.cern.ch/uploads/default/original/3X/f/4/f47ca3fa97e39a2b2c7fe5c29b1b7d8e1994dd49.png)

which gives rise to

 ![1](https://root-forum.cern.ch/uploads/default/original/3X/5/7/570055c0b38761712b273981909fab5e74d0c9d4.png)

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 ?

The

> fragments-\>Draw(“e+”)

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,  
Regards,  
Sarah

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

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [May 22, 2024, 7:22am UTC](https://root-forum.cern.ch/t/manipulation-of-root-files-returned-by-a-secondaryproduction-actor/59428/2 "2024-05-22T07:22:14Z")

</div>

The histogram drawing options are here:  
[https://root.cern/doc/master/classTHistPainter.html](https://root.cern/doc/master/classTHistPainter.html)  
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:

```auto
h->SetRangeUser(3,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:

```auto
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](https://root.cern/doc/master/classTH1.html#ac70dcb4082bd510f5aa3e6efeb043f39)(yourbinnumber))

---

<div class="post-metadata">

**Author:** ![SarahBlind](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@SarahBlind](https://root-forum.cern.ch/u/SarahBlind)\
**Post date:** [May 22, 2024, 8:36am UTC](https://root-forum.cern.ch/t/manipulation-of-root-files-returned-by-a-secondaryproduction-actor/59428/3 "2024-05-22T08:36:42Z")

</div>

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 :

![3](https://root-forum.cern.ch/uploads/default/original/3X/9/5/9572e6cb6625293aee04c027f31cc8082aaac70d.png)

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 :

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

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

    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](https://root.cern/doc/master/classTHistPainter.html) you sent me.

Many thanks,  
Sarah

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [May 22, 2024, 8:45am UTC](https://root-forum.cern.ch/t/manipulation-of-root-files-returned-by-a-secondaryproduction-actor/59428/4 "2024-05-22T08:45:26Z")

</div>

Check out the histogram tutorials:  
[https://root.cern/doc/master/group\_\_tutorial\_\_hist.html](https://root.cern/doc/master/group __tutorial__ hist.html)  
for instance, this one to read from a TFile:  
[https://root.cern/doc/master/h1ReadAndDraw\_8C.html](https://root.cern/doc/master/h1ReadAndDraw_8C.html)

---

<div class="post-metadata">

**Author:** ![SarahBlind](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/6bbea6/32.png) [@SarahBlind](https://root-forum.cern.ch/u/SarahBlind)\
**Post date:** [May 22, 2024, 10:08am UTC](https://root-forum.cern.ch/t/manipulation-of-root-files-returned-by-a-secondaryproduction-actor/59428/6 "2024-05-22T10:08:07Z")

</div>

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

```auto
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;
            }
        }
}

```
