Trying to get each evenement independently

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,

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.

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.

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

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.

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?

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

From this starting point, and by studying the tutorials and the docs, 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

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.

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

image
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.

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

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.

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

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

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.

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:

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:

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

Cheers,
Vincenzo

How ?

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.

That absolutely always work until now.

You forgot “.root” after the file name.

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

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

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 and documentation of ROOT (for example you could have easily found almost exactly the same example here), especially for the classes/objects/workflows more related to your needs, to maximise your future scientific throughput.

Cheers,
Vincenzo

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.

image

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 ?