//%jsroot on
auto c1=new TCanvas;
TH1D * h = new TH1D("h","h",12,0,6);
Double_t count[12]={1,1.5,2,2.5,3,3.5,4,3,2.5,2,1,0.5};
h->Fill(-2,1);//underflow
for(int i=0;i<12;i++) h->Fill(i/2.,count[i]);
h->Fill(15,2);//overflow
h->SetMinimum(0);
h->Draw("hist");
c1->Draw();
bin = 0; underflow bin
bin = 1; first bin with low-edge xlow INCLUDED
bin = nbins; last bin with upper-edge xup EXCLUDED
bin = nbins+1; overflow bin
h->Print("all");
Double_t bin7cen=h->GetBinCenter(7);
Double_t bin7con=h->GetBinContent(7);
Double_t bin7low=h->GetBinLowEdge(7);
Double_t bin7width=h->GetBinWidth(7);
cout<<"GetBinCenter(7)="<<bin7cen<<"; GetBinContent(7)="<<bin7con<<endl;
cout<<"GetBinLowEdge(7)="<<bin7low<<"; GetBinWidth(7)="<<bin7width<<"; BinUpperEdge(7)="<<bin7low+bin7width<<endl;
TF1 * f = new TF1("f","pol1",0,6);
f->SetParameters(0.75,1);
h->Draw("hist");
f->Draw("same");
c1->Draw();
int bin1=1;
int bin2=7;
Double_t sumH=h->Integral(bin1,bin2);
Double_t x1=h->GetBinLowEdge(bin1);
Double_t x2=h->GetBinLowEdge(bin2)+h->GetBinWidth(bin2);
Double_t sumF=f->Integral(x1,x2)/h->GetBinWidth(bin2);//!!!!!!!!!
cout<<"Integraion in TH1: "<<bin1<<"-"<<bin2<<" "<<sumH<<endl;
cout<<"Integraion in TF1: "<<x1<<"-"<<x2<<" "<<sumF<<endl;
Double_t x1=0;
Double_t x2=3.4;
int bin1=h->FindBin(x1);
int bin2=h->FindBin(x2);
double fx1=h->GetBinLowEdge(bin1);
double fx2=h->GetBinLowEdge(bin2)+h->GetBinWidth(bin2);
Double_t sumF=f->Integral(fx1,fx2)/h->GetBinWidth(bin2);
Double_t sumH=h->Integral(bin1,bin2);
cout<<"Original xrange: "<<x1<<"-"<<x2<<endl;
cout<<"Integraion in TF1: "<<fx1<<"-"<<fx2<<" "<<sumF<<endl;
cout<<"Integraion in TH1: "<<bin1<<"-"<<bin2<<" "<<sumH<<endl;