# Trying to get each evenement independently

**URL:** <https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219>\
**Category:** Newbie\
**Created:** [May 4, 2024, 11:51am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219 "2024-05-04T11:51:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 4, 2024, 11:51am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/1 "2024-05-04T11:51:24Z")

</div>

Hello;

I would like to analyse evenements in several neutron/gamma detectors independently wish mean evenement per evenement to know if the same evenement happens in two detector at the same time.  
But unfortunately i’m a noob at root, so i know what i want to do, but how can i do it ?  
I know that the fonction GetEntry() can return me the evenement () but i don’t even know how to use it.

Sincerely,

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [May 4, 2024, 12:15pm UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/2 "2024-05-04T12:15:43Z")

</div>

Dear @KillianUB ,

Thanks for reaching out to the forum! You are giving very little information to help you, but I will try nonetheless.

For data analysis with ROOT, I suggest you always use [RDataFrame](https://root.cern/doc/master/classROOT_1_1RDataFrame.html).

For your specific use case, I am imagining your dataset has some column representing the fact that a certain event has happened in a detector.

```python
df = ROOT.RDataFrame("mydataset", "myfile.root")
df = df.Filter("event_happend_in_detector_1 && event_happened_in_detector_2")
# Now the data frame only will consider events that match the condition above
# You can continue your analysis as necessary

```

Keep in mind the snippet above is just fore demonstration purposes, you will need to study the RDataFrame interface and your own dataset in order to arrive at the solution you need.

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 4, 2024, 1:50pm UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/3 "2024-05-04T13:50:16Z")

</div>

Hello, thanks for your answer. I have Trees with tons of graph all based on the number of evenement. I can navigate from one to another detector to get the number of evenement in only one detector depending of lot of thing such as Psd, Tof … What i would like is creating a code able to navigate in evenements one per one, and for each evenement, navigate in all detctor to see if a neutron has been detected in several detector or no. So in a human code, what i’d like look’s like :

- First evenement → check every detectors → let assume 2 detector has detected a neutron → so i have 1 evenement detected by two detectors …  
I would like it for every evenements and get the hist of it.  
So what i have to know is, how may i navigate in each evenement, and how to creat this code.  
The problem is, as a third years of licence student, i dont have the knowledge to do that, i’ve never used ROOT before.

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [May 4, 2024, 5:23pm UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/4 "2024-05-04T17:23:52Z")

</div>

Dear @KillianUB ,

Clearly, this is a learning experience, which involves studying and arriving at concrete solutions on your own, as with any other studying and research subject.

Regarding the idea you described, you have an example from my previous post, which fits exactly in the pseudo-code you have described. The only missing step is a `Histo1D` call after the `Filter` to get a histogram of the column of the dataset you want. What do you want to create an histogram of?

```python
df = ROOT.RDataFrame(...)
df = df.Filter(myselection)
histo = df.Histo1D("my column")

```

From this starting point, and by studying the [tutorials](https://root.cern/doc/master/group __tutorial__ dataframe.html) and the [docs](https://root.cern/doc/master/classROOT_1_1RDataFrame.html), you will get closer to understanding how to implement your requirements.

Once you have made some progress, you can post the code you have written in case you are stuck or you do not understand how to use a particular part of the API.

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 4, 2024, 7:33pm UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/5 "2024-05-04T19:33:04Z")

</div>

Maybe I should just ask my questions one by one. First i would like to get the DATA from all my detector independently. I know that the command tv\_\_tree-\>Draw(“Psd\_All\_Shift[1]\>\>h1(7500,500,8000),”",“colz”); will draw me the graph N(Psd) for the detector 1 wish is nice but i’d like to extract the data to creat a new file with those data. Then i could browse intoo each event.

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [May 5, 2024, 9:45am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/6 "2024-05-05T09:45:09Z")

</div>

Dear @KillianUB ,

> First i would like to get the DATA from all my detector independently.

Alright. How does your dataset look like? What is the schema? Which columns let you know information coming from a certain detector?

> tv\_\_tree-\>Draw(“Psd\_All\_Shift[1]\>\>

Is `Psd_All_Shift` the column you are trying to plot? So the indices of the column represent different channels? Can’t you just create an histogram of every channel separately?

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 5, 2024, 9:58am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/7 "2024-05-05T09:58:18Z")

</div>

![image](https://root-forum.cern.ch/uploads/default/original/3X/8/3/835a3fc0c730ffcd9a37d06536bc7fc974cf9165.png)  
Psd\_All\_Shift is a branch of my tree. tv\_\_tree(Psd\_All\_Shift[1]\>\> will draw for the detector number 1, the number of event in function of Psd.  
So first, i’d like to recover the data from each detector to then creat a code able to navigate in all detctor for each event to know if an event happen in 1 or futher detectors.

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [May 5, 2024, 10:08am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/8 "2024-05-05T10:08:44Z")

</div>

Right,

So you want to get `Psd_All_Shift[1]`, `Psd_All_Shift[2]`, … `Psd_All_Shift[N]`, where `N` is the number of detectors you have, isn’t it? Then you can just sum these values and if it’s greater than 1 you will know that the event was detected more than once. Let me know if this is enough information or if I am missing something.

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 5, 2024, 10:16am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/9 "2024-05-05T10:16:18Z")

</div>

Psd\_All\_Shift[1] will give me the number of event for the detctor 1. But for all event so I’ll clearly keep in mind the fact that i can use a sum to know in how many detector the event has been detected but it’s not the problem for now. So Psd\_All\_Shift is All event in function of All detectors. Psd\_All\_Shift[n] is All event for the detector n. I would like a single event for a single detctor. By the way, i’m french and i’m sorry if my english is not enough good for you to understand everything I write.

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [May 5, 2024, 10:22am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/10 "2024-05-05T10:22:58Z")

</div>

Dear @KillianUB ,

I believe something is missing from the picture here. You say

> Psd\_All\_Shift[n] is All event for the detector n.

But your dataset has more than one entry, right? If you were to draw it as a table, it would show something like

| Psd\_All\_Shift |
| --- |
| [1,0,0,1] |
| [0,0,0,1] |
| [1,0,0,0] |

So you should be able to traverse every row, one at a time, and get the number of events that are detected by each detector independently, at every row. What I mean specifically is write a for loop similar to

```auto
for (auto i = 0; i < nEntries; i++)
{
    auto event_was_detected_by_n = Psd_All_Shift[DETECTOR_N];
}

```

Or as I was suggesting it before, using RDataFrame which makes things much simpler.

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 5, 2024, 10:39am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/11 "2024-05-05T10:39:39Z")

</div>

What ever for some reasons, the command tv\_\_tree-\>Draw… now return me input\_line\_71:2:3: error: use of undeclared identifier ‘tv\_\_tree’ then nothing changed. Guess i’ll just give up. Thanks for your help.

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [May 5, 2024, 10:44am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/12 "2024-05-05T10:44:05Z")

</div>

Dear @KillianUB ,

> use of undeclared identifier ‘tv\_\_tree’ then nothing changed

This simply means you have not declared the variable `tv__tree`. This is either because you need to manually create it, as easily as:

```auto
TFile f{"myfile.root"};
std::unique_ptr<TTree> tv__tree{f.Get<TTree>("Name_of_the_tree")};

```

Or you can use the feature of opening the file and its contents directly via the root command line utility:

```auto
$: root myfile.root
[0] tv__tree->ls() # This will work only if there is a `tv__tree` object in the file though

```

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 5, 2024, 11:04am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/13 "2024-05-05T11:04:25Z")

</div>

> [@vpadulan](#):
>
> ```auto
> TFile f{"myfile.root"};
> std::unique_ptr<TTree> tv__tree{f.Get<TTree>("Name_of_the_tree")};
> 
> ```

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/6/b/6b354af0c886663c3f794d36decb0d4097410783.png)

How ?

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/9/7/97717ea86f3164cda96165bf67c965fd1a735f70.png)

---

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 5, 2024, 11:08am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/14 "2024-05-05T11:08:20Z")

</div>

I guess what’s asking to me it’s just way to far of my knowledge I would need some lessons before. I know exaclty what i have to do but i hav no idea how to use Root so it makes it litteraly not possible.

---

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 5, 2024, 11:12am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/15 "2024-05-05T11:12:45Z")

</div>

![image](https://root-forum.cern.ch/uploads/default/original/3X/a/2/a230aa7595e96e6cba1c10f35b6793a34b2fb9f3.png)

That absolutely always work until now.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 5, 2024, 11:15am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/16 "2024-05-05T11:15:57Z")

</div>

> [@KillianUB](#):
>
> > [@vpadulan](#):
> >
> > ```auto
> > TFile f{"myfile.root"};
> > std::unique_ptr<TTree> tv__tree{f.Get<TTree>("Name_of_the_tree")};
> > 
> > ```
> 
> ![image](https://root-forum.cern.ch/uploads/default/original/3X/6/b/6b354af0c886663c3f794d36decb0d4097410783.png)
> 
> How ?

You forgot “`.root`” after the file name.

P.S. “Evenement” is in French. It is “event” in English.

---

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 5, 2024, 11:28am UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/17 "2024-05-05T11:28:42Z")

</div>

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

Kinda proud of my self i finally write something who return me something elses than an error !

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [May 5, 2024, 12:54pm UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/18 "2024-05-05T12:54:13Z")

</div>

Dear @KillianUB ,

I am glad to see you are making progress. Allow me to suggest once again to take the time to read through the [manual](https://root.cern/manual/) and [documentation](https://root.cern/doc/master/) of ROOT (for example you could have easily found almost exactly the same example [here](https://root.cern/manual/root_files/)), especially for the classes/objects/workflows more related to your needs, to maximise your future scientific throughput.

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 5, 2024, 3:36pm UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/19 "2024-05-05T15:36:46Z")

</div>

I’ll defenetly try to read and apply everything in that tutorial. But since i only have 6 weeks of intership, i’ll to do it while i’m trying to find a solution of my problem. Now that i know how to Draw the hist of one detector, i have to get the data of it.

---

<div class="post-metadata">

**Author:** ![KillianUB](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/46a35a/32.png) [@KillianUB](https://root-forum.cern.ch/u/KillianUB)\
**Post date:** [May 5, 2024, 4:35pm UTC](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219/22 "2024-05-05T16:35:37Z")

</div>

![image](https://root-forum.cern.ch/uploads/default/original/3X/2/5/25165682029da113fc37d512b33ece41cf9fd1da.png)

Ok so here I understand the problem, root don’t know what’s x , but how can i do ?  
However I don’t think it’s what i want for now. Now i would like to get my data event per event and detector per detector.  
What could i use now to get the data of each event in each detector ?

[Next page](https://root-forum.cern.ch/t/trying-to-get-each-evenement-independently/59219.md?page=2)
