Dear @moneta thank you.
- I tried to fit by Maximum likelihood,
TF1 *fitgaus = new TF1("fitgaus", "gaus", 0,4000);
auto result= hene4subsum->Fit("fitgaus","S L");
but
a. you see, the function doesnt’ fit well data in this way
b.
double chi2 = 2* result->MinFcnValue();
gives chi2=1620.75
instead, you see…in the stat box chi2=1932
-
Adding these lines
auto rp2 = new TRatioPlot(hene4subsum);
rp2->Draw();
to make the residual plot I get this error, but in this case, the main plot loses the “E” option
even if I write
rp2->Draw("E");
TCanvas *c19 = new TCanvas("c19",canvtitle,1280,1280);
t->SetLineColor(kBlue);
TCut cutsubdet = TString::Format("subdet==%d ", subdetnumb).Data();
TCut cutxhmin = TString::Format("xh>%d ", xhmin).Data();
TCut cutxhmax = TString::Format("xh<%d ", xhmax).Data();
TString hene4substringsum = TString::Format("Calo_EnDep[%d] >> htemp(200., 0., 4000.)", c);
t->Draw(hene4substringsum, cut && cut3sub && cut4sub && cutsubdet && cutxhmin && cutxhmax);
gPad->Modified();
gPad->Update(); // make sure it's really (re)drawn
//t->GetHistogram()->SetTitle(cdenenamesum);
t->GetHistogram()->SetTitle("");
TH1F *hene4subsum = (TH1F*)gPad->GetPrimitive("htemp");
hene4subsum ->GetXaxis()->SetTitle(cdeneXnameab);
hene4subsum ->GetYaxis()->SetTitle(cdeneYnameab);
hene4subsum ->GetYaxis()->SetTitleSize(c_YTitleSize);
hene4subsum ->GetYaxis()->SetTitleFont(c_YTitleFont);
hene4subsum ->GetYaxis()->SetTitleOffset(c_YTitleOffset);
hene4subsum ->GetYaxis()->SetLabelFont(c_YLabelFont);
hene4subsum ->GetYaxis()->SetLabelSize(c_YLabelSize);
hene4subsum ->GetXaxis()->SetTitleSize(c_XTitleSize);
hene4subsum ->GetXaxis()->SetTitleFont(c_XTitleFont);
hene4subsum ->GetXaxis()->SetTitleOffset(c_XTitleOffset);
hene4subsum ->GetXaxis()->SetLabelFont(c_XLabelFont);
hene4subsum ->GetXaxis()->SetLabelSize(c_XLabelSize);
hene4subsum ->SetFillColorAlpha(kBlue, heneabfillcolor);
hene4subsum ->SetStats(0);
hene4subsum ->Draw("E");
TF1 *fitgaus = new TF1("fitgaus", "gaus", 0,4000);
auto result= hene4subsum->Fit("fitgaus","S L");
double chi2 = 2* result->MinFcnValue(); //
double ndf = result->Ndf();
// double chi2 = result->Chi2(); // Least squares fit (i.e. without L option)
hene4subsum ->SetName(heneabname);
gPad->Modified();
gPad->Update(); // make sure it's really (re)drawn
TLegend* legene4subsum = new TLegend(0.15, 0.85, .30, .75);
legene4subsum ->SetHeader("Legend");
legene4subsum ->SetNColumns(1);
legene4subsum ->AddEntry(hene4subsum , "Data", "l");
legene4subsum->AddEntry(fitgaus, "Fit", "l");
legene4subsum ->Draw();
gPad->Update();
gPad->Update();
auto rp2 = new TRatioPlot(hene4subsum);
rp2->Draw("E");
gPad->Update();
gPad->Update();
c19->Print(myploteneout4subsum);
std::cout << "Chi2 : " << chi2 << std::endl;
std::cout << "Ndf " << ndf << std::endl;
results << "Chi2 : " << chi2 << endl;
results << "Nfd " << ndf<<endl;
delete c19;
Lastly, in your macro there is the statbox, but, if I plot with the statbox (i.e. I don’t add
hene4subsum ->SetStats(0);
I get this error
Error in <TRatioPlot::BuildLowerPlot>: h1 does not have a fit function