# Getting a 1D histogram by looping over a pair of histograms under multiple categories

**URL:** <https://root-forum.cern.ch/t/getting-a-1d-histogram-by-looping-over-a-pair-of-histograms-under-multiple-categories/41367>\
**Category:** Newbie\
**Created:** [September 9, 2020, 6:46pm UTC](https://root-forum.cern.ch/t/getting-a-1d-histogram-by-looping-over-a-pair-of-histograms-under-multiple-categories/41367 "2020-09-09T18:46:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hep\_1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/hep_1/32/21930_2.png) [@hep\_1](https://root-forum.cern.ch/u/hep_1)\
**Post date:** [September 9, 2020, 6:46pm UTC](https://root-forum.cern.ch/t/getting-a-1d-histogram-by-looping-over-a-pair-of-histograms-under-multiple-categories/41367/1 "2020-09-09T18:46:46Z")

</div>

So I have a three categories “A”,“B”,“C”. They are stored in a vector called **vec\_hist**. Within each categories, there are six 2D histograms each of same bin sizes (5 by 6 to be specific) that are named as follows:

> **A** has _hist\_A\_1a, hist\_A\_1b, hist\_A\_2a, hist\_A\_2b, hist\_A\_3a,hist\_A\_3b_  
> **B** has _hist\_B\_1a, hist\_B\_1b, hist\_B\_2a, hist\_B\_2b, hist\_B\_3a,hist\_B\_3b_  
> **C** has _hist\_C\_1a, hist\_C\_1b, hist\_C\_2a, hist\_C\_2b, hist\_C\_3a,hist\_C\_3b_

What I want to do is something like this in the order:  
i) Go to category “A”  
ii) Take _hist\_A\_1a_ and _hist\_A\_1b_, and get their bin contents and fill a 1D histogram with them.  
iii) Take _hist\_A\_2a_ and _hist\_A\_2b_ and again get their bin contents and fill a different histogram with them.  
iv) After done with “A”, go to “B” repeat ii) and iii) and then move on to “C”.

So, in total I am supposed to have nine 1D histograms. I wish I had a script to show but, I have no clue where to start. So any pointer would be useful. Let me know if my question does not make sense.

_ROOT Version:_ 5.18  
_Platform:_ Ubuntu 18.04  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [October 6, 2020, 10:37am UTC](https://root-forum.cern.ch/t/getting-a-1d-histogram-by-looping-over-a-pair-of-histograms-under-multiple-categories/41367/2 "2020-10-06T10:37:46Z")

</div>

Hi @hep_1,  
I’m very sorry for the late reply, it looks this post slipped through the cracks! In general feel free to ping us if you don’t receive any reply after a few days.

I hoped you resolved your problem in the meanwhile. I am not sure what you mean when you say that you have three categories stored in a vector: what is a category, is it a histogram (i.e. you have a vector of 3 histograms)?  
A small code snippet or a ROOT file with the input histograms might help.

Cheers,  
Enrico

P.S.  
Note that ROOT 5.18 is _ancient_. The latest, currently unmaintained, ROOT version in the 5 series is 5.34. Users are strongly encouraged to move to ROOT version 6 if at all possible.

---

<div class="post-metadata">

**Author:** ![hep\_1](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/hep_1/32/21930_2.png) [@hep\_1](https://root-forum.cern.ch/u/hep_1)\
**Post date:** [October 18, 2020, 7:57pm UTC](https://root-forum.cern.ch/t/getting-a-1d-histogram-by-looping-over-a-pair-of-histograms-under-multiple-categories/41367/3 "2020-10-18T19:57:54Z")

</div>

Hi @eguiraud, yes, I resolved the problem. I did move to ROOT 6 after asking this question. Thank you for your reply.
