# Channel -\> Energy Calibration: Histogram

**URL:** <https://root-forum.cern.ch/t/channel-energy-calibration-histogram/3459>\
**Category:** ROOT\
**Created:** [June 19, 2006, 2:06pm UTC](https://root-forum.cern.ch/t/channel-energy-calibration-histogram/3459 "2006-06-19T14:06:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris1234](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/779978/32.png) [@chris1234](https://root-forum.cern.ch/u/chris1234)\
**Post date:** [June 19, 2006, 2:06pm UTC](https://root-forum.cern.ch/t/channel-energy-calibration-histogram/3459/1 "2006-06-19T14:06:50Z")

</div>

I need to change the x-axis of my histograms, from their origional 1:1 channel number scale into a calibrated Energy axis.

In my case I have available a function for the required conversion - for example :  
E(ch#) = ch/5000 MeV

how can I do this and leave the y-axis values as they were?

thanks

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [June 19, 2006, 2:43pm UTC](https://root-forum.cern.ch/t/channel-energy-calibration-histogram/3459/2 "2006-06-19T14:43:00Z")

</div>

Hi,

you can either use GetBinContent/SetBinContent to fill a new histogram with the proper bin borders, or a little hack: use GetBinLabel to set the label to the result of your transformation as if it was text, e.g. looping over bin number i: hist-\>SetBinLabel(i, Form("%g",(i-1)/5000.)).

Cheers, Axel.

---

<div class="post-metadata">

**Author:** ![nikulin](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/e495f1/32.png) [@nikulin](https://root-forum.cern.ch/u/nikulin)\
**Post date:** [June 20, 2006, 3:44am UTC](https://root-forum.cern.ch/t/channel-energy-calibration-histogram/3459/3 "2006-06-20T03:44:41Z")

</div>

[quote=“Axel”]or a little hack: use GetBinLabel to set the label to the result of your transformation as if it was text, e.g. looping over bin number i: hist-\>SetBinLabel(i, Form("%g",(i-1)/5000.)).  
[/quote]  
Axel, are there any side effects of TAxis::SetLimits()?

## `TAxis *axis = h->GetXaxis(); axis->SetLimits(h->GetXmin()/5000, h->GetXmax()/5000); `

Thank you,  
Max

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [June 20, 2006, 3:46pm UTC](https://root-forum.cern.ch/t/channel-energy-calibration-histogram/3459/4 "2006-06-20T15:46:11Z")

</div>

Hi Max,

no, your approach is fine for a linear conversion, so it should work for Chris, too. The SetBinLabel approach also works for non-linear axis conversions.

Cheers, Axel.

---

<div class="post-metadata">

**Author:** ![Confused](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@Confused](https://root-forum.cern.ch/u/Confused)\
**Post date:** [November 28, 2017, 12:27pm UTC](https://root-forum.cern.ch/t/channel-energy-calibration-histogram/3459/5 "2017-11-28T12:27:45Z")

</div>

Max, thanks for the simple alternative. I think you meant:

```auto
TAxis *axis = h->GetXaxis();
axis->SetLimits(axis->GetXmin()/5000, axis->GetXmax()/5000);

```

---

<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:** [November 28, 2017, 2:46pm UTC](https://root-forum.cern.ch/t/channel-energy-calibration-histogram/3459/6 "2017-11-28T14:46:02Z")

</div>

[Can we shift histogram for several channels?](https://root-forum.cern.ch/t/can-we-shift-histogram-for-several-channels/12050/2)
