Fit histogram to another historgam

Hello everyone

I have some experimental data and simulated data of some beta decay. I want to find out a method to scale down the experimental data and stretch or shrink it so it will fit the simulated data, and getting the parameters that root used for this fit, something like:

Ah(ax+b),

where “A” would be the scaling factor, as in the Scale(); function and x the bins of the histogram, where “a” and “b” are some parameters. I have the idea of how this could be done with minimization in a mathematical sense, but I don’t know how to implement it in root.

Thank you for your help!

Thank you!

I read it yesterday while searching the topic (now I know how to do the stretching so it’s great), but my questions was rather how to find the best parameters for the scaling and stretching apart from trial and error, like a minimization of the distance between the two histograms like

\min \int |h_1-h_2|^2

I guess, in general (when stretching/shrinking and scaling are needed), you would need to write your own “chi2” or “likelihood” function.
See: ${ROOTSYS}/tutorials/fit/

You could also try to use (but the involved histograms need to have well “aligned” bins, I guess):

It sounds like a job made for RooFIT.
You should do something like this:

using namespace RooFit;
RooRealVar XAxis("Axis","Axis",0,2000);
RooPlot *Frame = XAxis.frame();

RooRealVar Amount("Amount","Amount",0,0,10000);
RooRealVar Shift("Shift","Shift",0,-10,10);
RooFormulaVar ShiftedX("ShiftedX","ShiftedX",RooArgSet(XAxis,Shift));

RooDataHist *DataHist = new RooDataHist("Data","Data",XAxis,Some_Histogram_Simulated_Data);
RooHistPdf FitCurve("Curve","Curve",ShiftedX,XAxis,*DataHist,0);

RooDataHist RealData("RD","RD",XAxis,Import(*Some_Histogram_Real_Data));
RealData.plotOn(Frame);
FitCurve->fitTo(RealData);
FitCurve->plotOn(Frame);
Frame->Draw();

It is important to have the simulated data and real data with same binning (otherwise it looks horrible). If you fit several histograms, it is also better to only allow a shift on the x Axis that is discrete like the bins

1 Like