# Creating multiple histograms for different user ranges

**URL:** <https://root-forum.cern.ch/t/creating-multiple-histograms-for-different-user-ranges/60242>\
**Category:** ROOT\
**Tags:** hist\
**Created:** [July 17, 2024, 5:35pm UTC](https://root-forum.cern.ch/t/creating-multiple-histograms-for-different-user-ranges/60242 "2024-07-17T17:35:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![garlicrayburst](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/garlicrayburst/32/35451_2.png) [@garlicrayburst](https://root-forum.cern.ch/u/garlicrayburst)\
**Post date:** [July 17, 2024, 5:35pm UTC](https://root-forum.cern.ch/t/creating-multiple-histograms-for-different-user-ranges/60242/1 "2024-07-17T17:35:52Z")

</div>

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++

* * *

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [July 18, 2024, 5:11am UTC](https://root-forum.cern.ch/t/creating-multiple-histograms-for-different-user-ranges/60242/2 "2024-07-18T05:11:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![garlicrayburst](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/garlicrayburst/32/35451_2.png) [@garlicrayburst](https://root-forum.cern.ch/u/garlicrayburst)\
**Post date:** [July 20, 2024, 9:59am UTC](https://root-forum.cern.ch/t/creating-multiple-histograms-for-different-user-ranges/60242/3 "2024-07-20T09:59:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![garlicrayburst](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/garlicrayburst/32/35451_2.png) [@garlicrayburst](https://root-forum.cern.ch/u/garlicrayburst)\
**Post date:** [July 24, 2024, 9:50am UTC](https://root-forum.cern.ch/t/creating-multiple-histograms-for-different-user-ranges/60242/4 "2024-07-24T09:50:16Z")

</div>

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](https://root-forum.cern.ch/uploads/short-url/br2OZV6NGJQTsU3gk1spKdQ6gPT.cpp) (4.9 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 29, 2024, 11:22am UTC](https://root-forum.cern.ch/t/creating-multiple-histograms-for-different-user-ranges/60242/5 "2024-07-29T11:22:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [August 12, 2024, 11:22am UTC](https://root-forum.cern.ch/t/creating-multiple-histograms-for-different-user-ranges/60242/6 "2024-08-12T11:22:43Z")

</div>

Closed on August 12, 2024, 11:22am UTC

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