Fitting a histogram to another one

Hi All,

I have ran almost same code on two different datasets and got my results in two 1D histograms, now I want to fit them together to analyze them but after reading many of these pages and guidlines here still I’m confused and don’t know what I should do exactly to do this fitting.I found these codes somewhere in the link below in here (root webpage) that seems useful : … t2D.C.html

// scale histograms to same heights (for fitting)
double dx1 = (xup1-xlow1)/double(nbx1);
double dy1 = (yup1-ylow1)/double(nby1);
double dx2 = (xup2-xlow2)/double(nbx2);
double dy2 = (yup2-ylow2)/double(nby2);
// h1->Sumw2();
// h1->Scale( 1.0 / ( n1 * dx1 * dy1 ) );
// scale histo 2 to scale of 1
h2->Scale( ( double(n1) * dx1 * dy1 ) / ( double(n2) * dx2 * dy2 ) );

… but I don’t know what the function of double(nbx) is ! I know nbx would be the maximum bin of x axis but don’t know how double(nbx) works and where finally I should use “Scale” to draw the final fitted histogram !? I will appreciate if anyone helps me and explains this to me.

“double(n1)” is simply a call to the “double” constructor, which means … create a “double value” from the current value of “n1” (which is an “integer variable”, I assume).
Note: as soon as you call “h2->Scale(…);”, your “h2” histogram will be changed (see the TH1::Scale method discription for more details). If you afterwards execute “h2->Draw(…);”, you will see its new contents.