I have a TGraphErrors which has two separate distributions in it, which I therefore fit with two pol0s. I would like to be able to draw the fit boxes of these two distributions. Currently what I have doesn’t give me errors, but it seems to put the result from the second fit in the first fit box, as seen in the attached image.
How can I make this work? Thanks in advance
Double_t pol0f(Double_t *x, Double_t *par) {
return par[0];
}
void MWE(){
gStyle->SetOptStat(1110);
gStyle->SetOptFit(0001);
TGraphErrors* ge1 = new TGraphErrors();
TRandom3 *myRNG=new TRandom3();
myRNG->SetSeed(1);
for(int ii=0;ii<100;ii++)
{
double rand = myRNG->Gaus(100,0.01);
double rand2 = myRNG->Gaus(200,0.01);
if(ii<50) ge1->SetPoint(ii,ii,rand);
else ge1->SetPoint(ii,ii,rand2);
}
TCanvas* c1 = new TCanvas("c1","c1",900,700);
ge1->Draw("AP");
ge1->SetMarkerStyle(kStar);
TF1 *lowfunc = new TF1("lowfit","pol0f",20,47,1);
lowfunc->SetParName(0,"Low");
lowfunc->SetLineColor(kRed);
lowfunc->Draw("same");
ge1->Fit("lowfit","R");
lowfunc->SetLineWidth(4);
c1->Modified();
c1->Update();
TPaveStats *sLow = (TPaveStats*)ge1->FindObject("stats");
sLow->SetName("sLow");
TF1 *highfunc = new TF1("highfit","pol0f",50,70,1);
highfunc->SetParName(0,"High");
highfunc->SetLineColor(kRed);
highfunc->Draw("same");
ge1->Fit("highfit","R");
highfunc->SetLineWidth(4);
TPaveStats *sHigh = (TPaveStats*)sLow->Clone();
sHigh->SetName("sHigh");
}