# Getting mean from htemp

**URL:** <https://root-forum.cern.ch/t/getting-mean-from-htemp/46894>\
**Category:** Newbie\
**Tags:** python, hist, root\
**Created:** [September 20, 2021, 3:31am UTC](https://root-forum.cern.ch/t/getting-mean-from-htemp/46894 "2021-09-20T03:31:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Titanium\_Flowers](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/titanium_flowers/32/27404_2.png) [@Titanium\_Flowers](https://root-forum.cern.ch/u/Titanium_Flowers)\
**Post date:** [September 20, 2021, 3:31am UTC](https://root-forum.cern.ch/t/getting-mean-from-htemp/46894/1 "2021-09-20T03:31:16Z")

</div>

Hello  
Here’s my question.  
I have multiple branches in a Ttree for different inputs such as energy, angle etc. Around 20 of them are Rear detection and the other 20 are front detection. I would like to iterate over the branches, get the mean for all branches that have ‘Front Detection’ and ‘Rear detection’. Get the ratio of the mean i.e. mean of front/mean of back and create a histogram of this ratio versus the angle, grouped by the energy distribution. Can I please get some help and direction?

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [September 20, 2021, 5:39am UTC](https://root-forum.cern.ch/t/getting-mean-from-htemp/46894/2 "2021-09-20T05:39:47Z")

</div>

Check out this example on how to read and loop over a tree: [ROOT: tutorials/tree/tree1.C Source File](https://root.cern/doc/master/tree1_8C_source.html)  
(in particular, the function tree1r). Once you can read any variable, you can do what you need and fill histograms as also shown in the same example.

---

<div class="post-metadata">

**Author:** ![Titanium\_Flowers](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/titanium_flowers/32/27404_2.png) [@Titanium\_Flowers](https://root-forum.cern.ch/u/Titanium_Flowers)\
**Post date:** [September 20, 2021, 12:54pm UTC](https://root-forum.cern.ch/t/getting-mean-from-htemp/46894/3 "2021-09-20T12:54:05Z")

</div>

Hi. I have looked at this and the documentation as well. I am doing this on Jupyter notebooks and I already have the trees and branches filled. I want to iterate over the branches to get their mean, store them in a result and use those values to draw a histogram. I hope this made more sense than my badly worded question?

---

<div class="post-metadata">

**Author:** ![RENATO\_QUAGLIANI](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/renato_quagliani/32/19496_2.png) [@RENATO\_QUAGLIANI](https://root-forum.cern.ch/u/RENATO_QUAGLIANI)\
**Post date:** [September 22, 2021, 11:15pm UTC](https://root-forum.cern.ch/t/getting-mean-from-htemp/46894/4 "2021-09-22T23:15:40Z")

</div>

Have you tried to use RDataFrame?

```python
RDataFrame df("treeName", "file.root")
dfRear=df.Filter("rearDetectionCondition")
dfFront =df.Filter("feontDetectionCondition")

meanVals={}
for c in df.GetColumnNames():
    meanVals.update( { c : {"front" : dfFront.Mean(c), "rear" :dfRear.Mean(c))

for k in meanVals.keys():
   MeanRear = meanVals[k]["rear"].GetValue()
   MeanFront = meanVals[k]["front"]. GetValue() 

```

Just to give an idea how you can collect on 2 subset of the same tree the mean value of all columns
