# Problem with calibrated energy histogtram

**URL:** <https://root-forum.cern.ch/t/problem-with-calibrated-energy-histogtram/63588>\
**Category:** ROOT\
**Tags:** hist, root\
**Created:** [May 21, 2025, 1:57pm UTC](https://root-forum.cern.ch/t/problem-with-calibrated-energy-histogtram/63588 "2025-05-21T13:57:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chetan](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/f05b48/32.png) [@chetan](https://root-forum.cern.ch/u/chetan)\
**Post date:** [May 21, 2025, 1:57pm UTC](https://root-forum.cern.ch/t/problem-with-calibrated-energy-histogtram/63588/1 "2025-05-21T13:57:41Z")

</div>

I have Energy histogram with 8k channels and need to calibrate it. I am doing this with a macro but the output calibrated histogram has dips at fixed channel difference. In some cases, there are spikes in the calibrated histogram. I have found one article suggesting to use “(float) rand()/(float) RAND\_MAX)” but that doesn’t work. [Problem in histogram calibration](https://root-forum.cern.ch/t/problem-in-histogram-calibration/59176)  
Attachments:

1. Macro I am using named Digitizer.cpp
2. The raw root file has name DataF\_CH2.root
3. The output file I created has name OutputCH2\_0.root

\_ROOT Version:6.22/06  
\_Platform:Ububtu 20.04 LTS  
_Compiler:_ Not Provided

* * *

[OutputCH2\_0.root](https://root-forum.cern.ch/uploads/short-url/hXr6Ees34PjUjkStIrNES3xGvIn.root) (9.5 KB)  
[Digitizer.cpp](https://root-forum.cern.ch/uploads/short-url/luCwEuAm5hs4fj1VOmsxHylAHVP.cpp) (1.2 KB)

> **[Dropbox](https://www.dropbox.com/scl/fi/3slhfkxkj2citmkk5jwh9/DataF_CH2.root?rlkey=pb42ycgewxa5u5ykon8x37r3y&st=038cvgfj&dl=0)**

---

<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 21, 2025, 2:24pm UTC](https://root-forum.cern.ch/t/problem-with-calibrated-energy-histogtram/63588/2 "2025-05-21T14:24:23Z")

</div>

Hi,

do you mind making your input file publicly available to anyone without us needing to ask for access to it in the Google-Drive webform?

As to your issue, my first guess would be that it has to do with the fact that your `Energy` is an `unsigned short`. But I’d like to see your `DataF_CH2.root` to make sure.

---

<div class="post-metadata">

**Author:** ![chetan](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/f05b48/32.png) [@chetan](https://root-forum.cern.ch/u/chetan)\
**Post date:** [May 21, 2025, 3:12pm UTC](https://root-forum.cern.ch/t/problem-with-calibrated-energy-histogtram/63588/3 "2025-05-21T15:12:28Z")

</div>

I have updated the link in the original topic. The input file can be assessed now.

---

<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 21, 2025, 3:58pm UTC](https://root-forum.cern.ch/t/problem-with-calibrated-energy-histogtram/63588/4 "2025-05-21T15:58:35Z")

</div>

Thanks Chetan, I managed to access your file.

Looking at your `EnergyCal_S` histogram from `OutputCH2_0.root`, I do see the dips. For example:

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/8/5/856a32779e41f158af17830ccc7007ef9e2c85f8.png)

There are no entries between 260 and 262. Let’s take a look at the code that fills this histogram:

```auto
EnergyCal_S->Fill(3.589*Energy -35.546 + (float) rand()/(float) RAND_MAX);

```

What should be the value of `Energy` so that the entire expression inside the `Fill()` was within `260 < calibrated energy < 262`? Clearly, it can’t be greater than `Energy=83`, because even with this `Energy=83` you get `3.589×83−35.546+X` (where `0<X<1`), which is `262.3` at the very least (when `X=0`). Also, it can’t be smaller than `Energy=82`, because even with this `Energy=82` you get `3.589×82−35.546+X`, which is `259.8` at the most (when `X=1`). So in order to land between `259.8` and `262.3` you need your `Energy` to be between `82` and `83` (excluding both these values). But it is impossible as `Energy` is an `unsigned short`. So this bin is empty, and so are many others.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 22, 2025, 2:39am UTC](https://root-forum.cern.ch/t/problem-with-calibrated-energy-histogtram/63588/5 "2025-05-22T02:39:34Z")

</div>

`EnergyCal_S->Fill(3.589 * (Energy + gRandom->Rndm()) - 35.546);`

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [June 5, 2025, 2:40am UTC](https://root-forum.cern.ch/t/problem-with-calibrated-energy-histogtram/63588/6 "2025-06-05T02:40:33Z")

</div>

Closed on June 5, 2025, 2:40am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
