# Can you select&retrieve events ID in a 3D histogram in R

Hi, I have been using matlab for a while and here is what i had to do:
let us say that we have a dataset of Nx2 entries(each entry is composed by two scalars) and we want to

1. discretize the problem and create a 3D density plot (or a 3D histogram) where X and Y are the discritized coordinates and Z is the frequency
2. have the possibility to select a zone on the plot and retrieve the ID of the events which populate it.

To perform this I have written a matlab script which creates a 3D histogram by resolving X and Y in say 100 intervals each, and then it performs an “inventory”: for each bar of the histogram it stores the ID of the events that populate it. (example, say that the region at the upper left contains 3 events and therefore is 3 unit tall. these events are number 23,25 and 100 of the dataset. if you do this for each bar you have what I call “inventory” )
When the user selects the area of the plot, the routine checks which bars are selected and it gives back the ID of all events populating the area.
This unfortunately was a real pain to achieve in matlab, but now it’s done, even it the process is very slow and cumbersome.

My question is : Since I would like to switch to Python+ROOT, is there a better (and smarter) way to achieve this goal in ROOT?

Thanks a lot and sorry for the long post. Any idea or suggestion are truly welcome

cheers,
Emanuele

Hi,

in ROOT, you would create a TNtuple with three branches, your two values (say “a”, “b”) and the ID. Fill it. Then you can do `myNtuple->Draw("ID","a>100&&a<110 && b>50&&b<60");` You’ll get a histogram of IDs. Usually, people don’t care about the IDs themselves, but about the entries that satisfy a condition. E.g. they want to plot a value “sin©”, where “c” corresponds to a value of an entry, for all entries that satify a condition. In your ntuple, you’d just have the branches “a”,“b”,“c”, and call `myNtuple->Draw("sin(c)","a>100&&a<110 && b>50&&b<60");`
Cheers, Axel.