I have a macro which fits a TH2F and I want to format the way the parameters are drawn. I would like a box in the top left corner, like what’s drawn, which contains, in this order:
ax^2+bx+c
a = Form("a = %f #pm %f",aP,eaP)
b = Form("b = %f #pm %f",bP,ebP)
c = Form("c = %f #pm %f",cP,ecP)
When I tried to draw a TBox
previously, nothing seemed to appear, probably because I was using NDC coordinates when TBox wants User coordinates. Is there a way of 1. getting the chisquared/NOF of the fit, and 2. of drawing a TBox with the NDC coordinates I want?
TFile *_file0 = TFile::Open("AnalysisOutputFile.root");
gStyle->SetOptStat(0);
gStyle->SetOptFit(100);
gStyle->SetTextFont(42);
gStyle->SetTextSize(0.03);
TLatex *qe = new TLatex(0,0,"ax^{2}+bx+c");
double x1=0.08;
double x2=0.42;
double y1=0.775;
double y2=0.965;
TF1 *fnP = new TF1("fnP","[0]+[1]*x+[2]*x*x");
fnP->SetParName(0,"c");
fnP->SetParName(1,"b");
fnP->SetParName(2,"a");
TH1F *hP = (TH1F*)_file0->Get("hP");
TCanvas *canP = new TCanvas("canP","canP",900,700);
hSwumEnergyToChannelPVeto->Draw("colz");
hSwumEnergyToChannelPVeto->Fit("fnP","","",20,90);
hSwumEnergyToChannelPVeto->SetTitle(";PVetoChannelID;ParticleEnergy");
hSwumEnergyToChannelPVeto->GetYaxis()->SetTitleOffset(1.1);
canP->SetRightMargin(0.13);
canP->SetLeftMargin(0.08);
canP->SetTopMargin(0.0351);
canP->SetBottomMargin(0.075);
canP->SetBorderMode(1);
canP->SetHighLightColor(0);
canP->Modified();
canP->Update();
TPaveStats *sP = (TPaveStats*)hSwumEnergyToChannelPVeto->FindObject("stats");
sP->SetName("P");
TList *lP = sP->GetListOfLines();
double cP = fnP->GetParameter(0);
double bP = fnP->GetParameter(1);
double aP = fnP->GetParameter(2);
double ecP = fnP->GetParError(0);
double ebP = fnP->GetParError(1);
double eaP = fnP->GetParError(2);
sP->SetX1NDC(x1);
sP->SetX2NDC(x2);
sP->SetY1NDC(y1);
sP->SetY2NDC(y2);
TLatex *texaP = new TLatex(0,0,Form("a = %f #pm %f",aP,eaP));
TLatex *texbP = new TLatex(0,0,Form("b = %f #pm %f",bP,ebP));
TLatex *texcP = new TLatex(0,0,Form("c = %f #pm %f",cP,ebP));
lP->Add(qe);
lP->Add(texaP);
lP->Add(texbP);
lP->Add(texcP);
hSwumEnergyToChannelPVeto->SetStats(0);
canP->Modified();
canP->Update();