# Is there a way to use Eval() for a histogram?

**URL:** <https://root-forum.cern.ch/t/is-there-a-way-to-use-eval-for-a-histogram/50717>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [July 7, 2022, 8:07pm UTC](https://root-forum.cern.ch/t/is-there-a-way-to-use-eval-for-a-histogram/50717 "2022-07-07T20:07:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nisha](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/nisha/32/28801_2.png) [@Nisha](https://root-forum.cern.ch/u/Nisha)\
**Post date:** [July 7, 2022, 8:07pm UTC](https://root-forum.cern.ch/t/is-there-a-way-to-use-eval-for-a-histogram/50717/1 "2022-07-07T20:07:12Z")

</div>

Hello Experts,  
I have an efficiency histogram. I want to divide an energy histogram with the efficiency and used this -  
\\   
h2-\>Divide(h1);  
However, this is not working since the binning for both is different. Is there a way to use something like  
Eval() for the histogram directly without fitting so that I can read the values from h1 and divide the corresponding values of h2?  
I am sure there is a simple way. Can anyone please help with any suggestions?

Please help! Thank you for your time!

_ROOT Version:_ 6.18/04  
_Platform:_ C++  
_Compiler:_ Visual Studio Code

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [July 7, 2022, 8:08pm UTC](https://root-forum.cern.ch/t/is-there-a-way-to-use-eval-for-a-histogram/50717/2 "2022-07-07T20:08:21Z")

</div>

Maybe @moneta knows a simple way

---

<div class="post-metadata">

**Author:** ![Dilicus](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dilicus/32/14338_2.png) [@Dilicus](https://root-forum.cern.ch/u/Dilicus)\
**Post date:** [July 8, 2022, 7:17am UTC](https://root-forum.cern.ch/t/is-there-a-way-to-use-eval-for-a-histogram/50717/3 "2022-07-08T07:17:46Z")

</div>

Hi,  
I think there is nothing like Eval for histograms, but you can try to do something like

```auto
h->GetBinContent(h->FindBin(x));

```

this should work.

Stefano

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [July 8, 2022, 12:28pm UTC](https://root-forum.cern.ch/t/is-there-a-way-to-use-eval-for-a-histogram/50717/4 "2022-07-08T12:28:25Z")

</div>

You could convert your efficiency histogram to a TGraph first.

Then, you go to your energy histogram and bin by bin, you divide the bin content by `gr->Eval(h->GetXaxis()->GetBinCenter(i))`

---

<div class="post-metadata">

**Author:** ![Nisha](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/nisha/32/28801_2.png) [@Nisha](https://root-forum.cern.ch/u/Nisha)\
**Post date:** [July 11, 2022, 8:37pm UTC](https://root-forum.cern.ch/t/is-there-a-way-to-use-eval-for-a-histogram/50717/5 "2022-07-11T20:37:09Z")

</div>

Thank you for getting back @Dilicus and @ferhue. Both of your suggestions worked like a charm. However, I ended up using @ferhue’s suggestion which was exactly what I was looking for.  
Thank you for your time and help!
