Creating multiple histograms for different user ranges

Hello!
I am doing some analyses from a root file, which I write a macro for. In this macro, I have a main histogram that consists of all the data points I need, it has 30 bins and x-axis range is from 0 to 150(meters), signifying 1 bin for each 5m distance.
I need to produce multiple histograms, where each histogram is the of one bin width. So, one histo for 0-5m, another for 5-10m, another for 10-15m and so on. And one final histogram that contains the entire plot from 0 to 150.
I could write an if loop/switch for each range but I assume that would require creating 30(+1) different histograms which seems inefficient.
Is there any other way to solve this?

ROOT Version: 6.28
Platform: Ubuntu 22.04
Compiler: g++


Hi,

It depends in the end on the context where this has to be done, but I do not necessarily see issues with that.
It is not unusual to book histograms and other resources, e.g. for data reduction techniques, at the beginning of macros/programs/classes, also explicitly, on multiple lines.

Cheers,
D

Thank you for reply!
It seems that this is the way to go.

Hi, I took a slightly different approach, instead of re-calculating the values for each distance, I tried making multiple canvases having different x axis ranges of the same TProfile. This is essentially what I want, one canvas that contains all ranges, and then multiple canvases that contain each bin x-axis range.
I have attached the code, although multiple canvases are created, all of them contains the user range that was mentioned the latest. So, all canvases created have range 15-20, despite setting different ranges in each canvas. Any help on how to fix this is greatly appreciated!

lateralDist.cpp (4.9 KB)

The range it set on the histogram pEpos (as you did it0 not on the canvases . So the last rnage wlll be used plotting the hisotgram on different canaves will not help. You will need to make copies/ Clones of pEpos.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.