# Aligning two histograms by shifting bins

Hello users,

I have two histograms that are shifted by some factor

Is it possible to shift the bins of one wrt to the other to align them?

So far, I am having the centroids of the peaks for both the histograms obtained by fitting. The ultimate goal is to align these centroids such that the peaks overlap.

I am a new user with minimal experience in these operations, so any suggestion will be precious.

It is possible in principle, see Can we shift histogram for several channels? - #2 by Pepe_Le_Pew

1 Like

Hi @yus ,

Thanks a lot for pointing to the valuable thread.

I think I should scale the contents, however from the documentation it seems function `TH1::Scale` only changes the contents by a multiplicative factor `this = this*c1`

Is it possible to change the contents by `this = this*c1 + c2`
c2 is a constant offset

I think you have to change the X-axis values, not the Y-axis ones. `TH1::Scale` changes the Y-axis values.

1 Like

Yes, you are correct.
I think I should use the

``````ScaleXaxis(hist1, ScaleX);
``````

However, doing so gives an error.

``````ScaleXaxis(his1, Scale)

``````
``````ROOT_prompt_396:1:18: error: cannot initialize an array element of type 'void *' with an rvalue of type 'Double_t (*)(Double_t)' (aka 'double (*)(double)')

``````

The function scale

``````#include "TAxis.h"
#include "TH1.h"
#include "TArrayD.h"

Double_t Scale(Double_t x)
{
Double_t v;
v = 10 * x + 100; // "linear scaling" function example
return v;
}
``````

Can you please suggest what I am messing up here ?

Can you show your full the code? You should have three functions defined (`ScaleX`, `ScaleAxis`, `ScaleXaxis`), and call the latter in your own code.

Ya, my bad I did not copy the whole code. Now it seems to work.

Thanks a lot for your help and time.