# Normalising histogram

**URL:** <https://root-forum.cern.ch/t/normalising-histogram/33055>\
**Category:** Newbie\
**Created:** [March 6, 2019, 7:17pm UTC](https://root-forum.cern.ch/t/normalising-histogram/33055 "2019-03-06T19:17:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [March 6, 2019, 7:17pm UTC](https://root-forum.cern.ch/t/normalising-histogram/33055/1 "2019-03-06T19:17:24Z")

</div>

I am trying to plot Delta N/Delta M from the histogram in this hmass\_copy then normalize but getting error with GetBinContent.- Function GetBinContent(ibins) is not defined in current scope

Int\_t ibins;  
void mass\_fit(const char fname = “h\_mass.root”)  
{  
// Get file and get histogram  
TFile \*file = TFile::Open(“h\_mass.root”);  
TH1F _hmass\_copy = (TH1F_)file -\>Get(“h\_mass”)-\>Clone(“hmass\_copy”);  
TFile \*myfile = new TFile(“hnorm.root”,“RECREATE”);  
hmass\_copy-\> norm/GetBinContent(ibins));  
//cout\<\<“Initial check:”\<\<endl;

---

<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:** [March 6, 2019, 8:15pm UTC](https://root-forum.cern.ch/t/normalising-histogram/33055/2 "2019-03-06T20:15:03Z")

</div>

> [@Prya13](#):
>
> hmass\_copy-\> norm/GetBinContent(ibins));

This is incorrect. It should be `hmass_copy->GetBinContent(ibins);` `GetBinContent()` is a method of the `TH1F` class

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [March 6, 2019, 8:30pm UTC](https://root-forum.cern.ch/t/normalising-histogram/33055/3 "2019-03-06T20:30:12Z")

</div>

Thank you, only with this that I will get the new normalized plot?

---

<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:** [March 6, 2019, 8:35pm UTC](https://root-forum.cern.ch/t/normalising-histogram/33055/4 "2019-03-06T20:35:34Z")

</div>

No, you can either use [TH1F::Scale (Double\_t c1=1, Option\_t \*option="")](https://root.cern.ch/doc/master/classTH1.html#add929909dcb3745f6a52e9ae0860bfbd)  
or [TH1F::DrawNormalized (Option\_t \*option="", Double\_t norm=1)](https://root.cern.ch/doc/master/classTH1.html#a46394b325a71d59fe0009172079b4a62) if you simply want to draw it normalized. See the [TH1F class documentation](https://root.cern.ch/doc/master/classTH1F.html)

---

<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:** [March 6, 2019, 8:41pm UTC](https://root-forum.cern.ch/t/normalising-histogram/33055/5 "2019-03-06T20:41:08Z")

</div>

You probably want something like this:

```auto
hmass_copy->Scale(norm/hmass_copy->GetMaximum());

```

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [March 6, 2019, 9:18pm UTC](https://root-forum.cern.ch/t/normalising-histogram/33055/6 "2019-03-06T21:18:44Z")

</div>

I am sorry, no understand.

I read the DrawNormalized, I no understand what to put in macro so I can store it to use fit function.

---

<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:** [March 6, 2019, 9:22pm UTC](https://root-forum.cern.ch/t/normalising-histogram/33055/7 "2019-03-06T21:22:10Z")

</div>

I told you how to normalize your histogram:

```auto
hmass_copy->Scale(norm/hmass_copy->GetMaximum());

```

Now, if it’s not what you’re asking for, could you explain what you’re trying to achieve exactly?

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [March 7, 2019, 2:27am UTC](https://root-forum.cern.ch/t/normalising-histogram/33055/8 "2019-03-07T02:27:43Z")

</div>

Hey,

First plot of number vs mass. Then want the plot (derivative number)/(derivative mass), This I use to find the number of particles.(Already completed). was looking for 1.0/(hmass\_copy-\>GetBinWidth(1));

Thank you for your help.
