# Energy Calibration: binned vs unbinned data

**URL:** <https://root-forum.cern.ch/t/energy-calibration-binned-vs-unbinned-data/58451>\
**Category:** Newbie\
**Created:** [March 9, 2024, 10:55am UTC](https://root-forum.cern.ch/t/energy-calibration-binned-vs-unbinned-data/58451 "2024-03-09T10:55:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [March 9, 2024, 10:55am UTC](https://root-forum.cern.ch/t/energy-calibration-binned-vs-unbinned-data/58451/1 "2024-03-09T10:55:36Z")

</div>

Hi everyone,

While trying to transform(calibrate) the channel numbers on X axis to energies using a quadratic polynomial, I am confused as to what shall be the better and error free approach at the same avoiding issues with re-binning, variable bin width, missing bins etc. as highlighted in below posts

> [@Change scale of a TH1F (energy calibration)](https://root-forum.cern.ch/t/change-scale-of-a-th1f-energy-calibration/4971/4):
>
> OK now I understand your question. This is possible with some approximation as in principle to make a clean operation you would need to start from teh original unbinned x values. The approximation could be the following TH1F \*h; //your original histogram int nbins = h-\>GetXaxis()-\>GetNbins(); TH1F \*hnew = new TH1F("hnew","title",nbins,xminnew,xmaxnew); for (int i=1;i\<=nbins;i++0 { double y = h-\>getBinContent(i); double x = h-\>GetXaxis()-\>GetBinCenter(i); double xn…

> [@Energy calibrated histogram/spectrum](https://root-forum.cern.ch/t/energy-calibrated-histogram-spectrum/18159):
>
> I am trying to create a multiple histograms in one plot with data from the attached file. Actually I am trying to apply an energy callibration on the x-axis values which are channels i.e. where a=2.7361 and b=-64.608 while channels = the old values and energy=the new values. I am creating the histograms using the following code [code]#include “Riostream.h” #include “TArrow.h” #include “TLatex.h” void MgB2(){ gROOT-\>SetStyle("Plain"); gStyle-\>SetOptStat(0000); gStyle-\>SetOptFit(1111); gSt…

The post below highlights that for a linear transformation it’s better to rescale the axis itself  
[After energy calibration, some histogram bins are empty - #4 by Wile\_E\_Coyote](https://root-forum.cern.ch/t/after-energy-calibration-some-histogram-bins-are-empty/53539/4)

1.) The first method that I am thinking is to directly transform the binned data using the. `Set(Get)BinContent()` as discussed below

> [@Energy calibration of gamma ray-detector](https://root-forum.cern.ch/t/energy-calibration-of-gamma-ray-detector/33852/3):
>
> The energy calibration curve for Ge or Scintillation detector is usually described by the following 2 degrees polynomial function: //suppose you have five gamma peaks for the calibration. Float\_t energy[5]={121.78, 244.7, 344.28, 411.12, 443.96};//fill with your 152Eu gamma peak energies Float\_t channel[5]={100,200,300,400,500};//fill with your channel numbers from gamma peak fitting TGraph \*g=new TGraph; g-\>SetPoint(5, channel, energy);//fill data to a Graph g-\>Fit("pol2");//fit the gr…

2.) Whereas secondly, is to directly transform the unbinnned values and then make a histogram.

Can anyone please share their point of view on which method is better or share any better approaches to achieve this X axis “calibration”.

Any comments, suggestions or recepies will be of tremendous help. Thanks a lot.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [March 9, 2024, 2:45pm UTC](https://root-forum.cern.ch/t/energy-calibration-binned-vs-unbinned-data/58451/2 "2024-03-09T14:45:42Z")

</div>

Hi,

Posting a lot these days!  
Could you perhaps be a bit more specific with the question you have in mind? Maybe the question you could try to answer is why rescaling according to the value of your calibration function evaluated in the bin center is not ok in your case?

Cheers,  
Danilo

---

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [March 11, 2024, 7:28am UTC](https://root-forum.cern.ch/t/energy-calibration-binned-vs-unbinned-data/58451/3 "2024-03-11T07:28:58Z")

</div>

Hi,

Thanks for noticing that. Sorry for not being specific here.

Sure, Il try the rescaling bin centers for my specific case and share the results.

---

<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:** [March 11, 2024, 9:05am UTC](https://root-forum.cern.ch/t/energy-calibration-binned-vs-unbinned-data/58451/4 "2024-03-11T09:05:59Z")

</div>

If you can, always “scale” your _raw_ unbinned data (i.e., from “_raw_ experimental values” to values in “energy units”).  
Create your histogram with the axis in “energy units” and fill it with your (still unbinned) “energy _calibrated_” data.  
If you only have a histogram already filled with “_raw_ experimental values”, then you are doomed.

---

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [March 11, 2024, 9:24am UTC](https://root-forum.cern.ch/t/energy-calibration-binned-vs-unbinned-data/58451/5 "2024-03-11T09:24:32Z")

</div>

Hi @Wile_E_Coyote ,  
Thanks for the suggestion.  
Yes, so far I was trying to scale the “raw experimental values” according to the calibration function and then binning the scaled version to “calibrated” spectra.

```auto
If you only have a histogram already filled with “raw experimental values”, then you are doomed.

```

I guess due to the problem of empty bins and variable bin widths or there is more to that. Can you please highlight it?

---

<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:** [March 11, 2024, 9:36am UTC](https://root-forum.cern.ch/t/energy-calibration-binned-vs-unbinned-data/58451/6 "2024-03-11T09:36:54Z")

</div>

Unfortunately, this was never implemented: “[TAxis FixedToVariable and VariableToFixed proposal](https://root-forum.cern.ch/t/taxis-fixedtovariable-and-variabletofixed-proposal/30048)”

---

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [March 11, 2024, 9:52am UTC](https://root-forum.cern.ch/t/energy-calibration-binned-vs-unbinned-data/58451/7 "2024-03-11T09:52:55Z")

</div>

Hmmm…okay. Thanks for sharing
