# Problem in histogram calibration

**URL:** <https://root-forum.cern.ch/t/problem-in-histogram-calibration/59176>\
**Category:** Newbie\
**Tags:** tree, hist, root\
**Created:** [April 30, 2024, 10:13am UTC](https://root-forum.cern.ch/t/problem-in-histogram-calibration/59176 "2024-04-30T10:13:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [April 30, 2024, 10:13am UTC](https://root-forum.cern.ch/t/problem-in-histogram-calibration/59176/1 "2024-04-30T10:13:41Z")

</div>

Hi,

I am trying to do the energy calibration of a histogram using a second degree polynomial function :

```auto
Double_t HP_Ge::channel_Energy(Double_t x)
{
  Double_t v;
  v = -78.61 + (0.6816*LaBr3Raw[3]) + (1.043*TMath::Power(10,-6)*TMath::Power(LaBr3Raw[3],2));     
  return v;
}

```

and the following is what I have :

 ![Screenshot from 2024-04-30 12-07-28](https://root-forum.cern.ch/uploads/default/original/3X/f/0/f096e7db77ee6f9ec15e14fdc27e84d584d45477.png)

I dont understand why the calibarted spectrum is like this. I already tried using a different binning for the second histogram but I cannot get it to look nice, but it doesnt work.

Thank you!

---

<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:** [April 30, 2024, 10:27am UTC](https://root-forum.cern.ch/t/problem-in-histogram-calibration/59176/2 "2024-04-30T10:27:06Z")

</div>

Can you provide a more complete example reproducing this plot ?

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [April 30, 2024, 10:30am UTC](https://root-forum.cern.ch/t/problem-in-histogram-calibration/59176/3 "2024-04-30T10:30:13Z")

</div>

I have a ttree with the raw data, and I use the make class for the calibration .  
[HP\_Ge.h](https://root-forum.cern.ch/uploads/short-url/8bdYtpuluQJ1GzFqjyxx2XUeR2q.h) (17.2 KB)  
[HP\_Ge.C](https://root-forum.cern.ch/uploads/short-url/sOB18Gyf9FoYd8M56OJLAe7wX3U.C) (3.8 KB)

I tried with a linear function also to fit but I have similar results

---

<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:** [April 30, 2024, 10:40am UTC](https://root-forum.cern.ch/t/problem-in-histogram-calibration/59176/4 "2024-04-30T10:40:44Z")

</div>

```auto
root [0] 
Processing HP_Ge.C...
Error in <TFile::TFile>: file /Users/couet/Downloads/r0207_000a.root does not exist
(HP_Ge) @0x7f79221c0820
root [1] .q

```

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [April 30, 2024, 12:02pm UTC](https://root-forum.cern.ch/t/problem-in-histogram-calibration/59176/5 "2024-04-30T12:02:51Z")

</div>

As the file size is large, please find the root file in the following link:

> **[r0207\_000a.root](https://www.dropbox.com/scl/fi/jm5zibs9aasqe5dsd9kmu/r0207_000a.root?rlkey=h7krs2x3rvt9wsk9cvznqt0sc&st=9w0ky18w&dl=0)**
>
> Shared with Dropbox

---

<div class="post-metadata">

**Author:** ![ajaydeo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@ajaydeo](https://root-forum.cern.ch/u/ajaydeo)\
**Post date:** [April 30, 2024, 1:33pm UTC](https://root-forum.cern.ch/t/problem-in-histogram-calibration/59176/6 "2024-04-30T13:33:14Z")

</div>

@gini

I guess, it is not really a `ROOT` problem.

You may wish to smooth your histogram after you apply calibration function by replacing

`v = 0.6861 * x - 82.4698;`  
with  
`v = 0.6861 * x - 82.4698 + ((float) rand()/(float) RAND_MAX) ;`

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/4/2/42be7fc1aa64ef3d2b17ed1136c0d456def6032a.png)

Hope this helps.

Ajay

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [April 30, 2024, 1:34pm UTC](https://root-forum.cern.ch/t/problem-in-histogram-calibration/59176/7 "2024-04-30T13:34:51Z")

</div>

@ajaydeo thanks for the reply !

In that case what to do with the polynomial function if I use it to calibrate ?

---

<div class="post-metadata">

**Author:** ![ajaydeo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/e19b73/32.png) [@ajaydeo](https://root-forum.cern.ch/u/ajaydeo)\
**Post date:** [April 30, 2024, 1:40pm UTC](https://root-forum.cern.ch/t/problem-in-histogram-calibration/59176/8 "2024-04-30T13:40:11Z")

</div>

@gini

As simple as,

```auto
  v = -78.61 + (0.6816*LaBr3Raw[3]) + (1.043*TMath::Power(10,-6)*TMath::Power(LaBr3Raw[3],2)) + ((float) rand()/(float) RAND_MAX);     

```

Ajay

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 2, 2024, 8:02am UTC](https://root-forum.cern.ch/t/problem-in-histogram-calibration/59176/9 "2024-05-02T08:02:41Z")

</div>

If I may suggest another improvement (which will not fix anything, but it makes the code cleaner and faster):  
consider replacing

```c
1.043*TMath::Power(10,-6)*TMath::Power(LaBr3Raw[3],2)

```

with just

```c
1.043e-6*TMath::Sq(LaBr3Raw[3])

```
