# Change x-axis of histogram from channels to energy

**URL:** <https://root-forum.cern.ch/t/change-x-axis-of-histogram-from-channels-to-energy/34240>\
**Category:** Newbie\
**Created:** [May 24, 2019, 6:22pm UTC](https://root-forum.cern.ch/t/change-x-axis-of-histogram-from-channels-to-energy/34240 "2019-05-24T18:22:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JorgeM](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@JorgeM](https://root-forum.cern.ch/u/JorgeM)\
**Post date:** [May 24, 2019, 6:22pm UTC](https://root-forum.cern.ch/t/change-x-axis-of-histogram-from-channels-to-energy/34240/1 "2019-05-24T18:22:08Z")

</div>

Hi!  
I have a histogram and the x axis is set on the channels from a file.  
Is there a way to change (or calibrate) the x axis if we have a simple linear function that converts: E(KeV)=m\*(channel)+b

Here is my macro:

```auto
{
  auto am241=new TH1F("am241",
		     "am241;N_{counts};# occurencies",
		      4095, //number of bins
		      -0.5, //x-axis min
		      4095.5); //x-axis max
  ifstream inp; double x;
  inp.open("Am241.TKA");
  for (int i=0; i<4095; i++) {
    inp >> x;
    am241->SetBinContent(i,x);
    }
}

```

this is what I get as output:

 ![test](https://root-forum.cern.ch/uploads/default/original/3X/2/8/282bee61a373f54184a0cdcb6c973b2d7988a468.gif)

---

<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 24, 2019, 6:27pm UTC](https://root-forum.cern.ch/t/change-x-axis-of-histogram-from-channels-to-energy/34240/2 "2019-05-24T18:27:33Z")

</div>

> [@Can we shift histogram for several channels?](https://root-forum.cern.ch/t/can-we-shift-histogram-for-several-channels/12050/2):
>
> I’m not sure if this is fully kosher, but suit yourself : #include "TAxis.h" #include "TH1.h" #include "TArrayD.h" Double\_t ScaleX(Double\_t x) { Double\_t v; v = 10 \* x + 100; // "linear scaling" function example return v; } Double\_t ScaleY(Double\_t y) { Double\_t v; v = 20 \* y + 200; // "linear scaling" function example return v; } Double\_t ScaleZ(Double\_t z) { Double\_t v; v = 30 \* z + 300; // "linear scaling" function example return v; } void ScaleAxis(TAxis \*a, Double\_t (…
