How to get the difference between the fit value and the experimental value in every bin?


I want to calculate the difference between the fit value and the experimental value(the histogram value) in every bin, which code should I use?
Or how to get the fit value in per bin?

Hi @meixue
this should work for you

TH1D *h_diff =new TH1D(); //this should have the same binning of your histogram
double x,y;
for(int i=h->FindBin(2040);i<h->FindBin(2410);i++)//h here is your histogram
{
y=h->GetBinContent(i);
x=h->GetBinCenter(i);
h_diff->SetBinContent(  i ,  y - f->Eval(x)   );//f is your fitted function
}

I have also same issue any suggestion for this so please reply. Thanks in advnance.

Hi @Thomas265, the solution proposed should work also for you

Blockquote TH1D *h_diff =new TH1D(); //this should have the same binning of your histogram
double x,y;
for(int i=h->FindBin(2040);iFindBin(2410);i++)//h here is your histogram
{
y=h->GetBinContent(i);
x=h->GetBinCenter(i);
h_diff->SetBinContent( i , y - f->Eval(x) );//f is your fitted function
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.