Double_t aaa(Double_t *x, Double_t *par){ double bin = 0.0125; double mult = 1./par[2]/sqrt(2*3.1415); double func1 = par[0]*mult*exp(-0.5* pow((x[0]-par[1])/par[2],2)); double mult1 = 1./par[5]/sqrt(2*3.1415); double norm = 0.5*(erf(sqrt(0.5/par[5])*(1.-par[4]))-erf(sqrt(0.5/par[5])*(-2.5-par[4]))); double func2 = par[3]*norm*exp(-0.5* pow((x[0]-par[4])/par[5],2)); // double func3 = par[6] + par[7]*x[0] + par[8]*x[0]*x[0] + par[9]*x[0]*x[0]*x[0]; double func3 = par[6] + par[7]*x[0] + par[8]*x[0]*x[0]; double func = bin*(func1 + func2 + func3); return func; } void test(){ gROOT->Reset(); gROOT->SetStyle("Plain"); gROOT->ForceStyle(); gStyle->SetOptStat(0); gStyle->SetOptFit(11); gStyle->SetTitleX(0.1f); gStyle->SetTitleW(0.8f); gStyle->SetTextSize(1.5); gStyle->SetTitleFont(132,"xy"); gStyle->SetLabelFont(132,"xy"); gStyle->SetLabelSize(0.055,"xy"); gStyle->SetTitleSize(0.06,"xy"); gStyle->SetTitleOffset(1.1,"x"); gStyle->SetTitleOffset(1.1,"y"); gStyle->SetTitleBorderSize(0); TFile *file = new TFile ("61914.root","R"); TFile *file1 = new TFile ("empty_target_all.root","R"); TH1F *comp_e6 = (TH1F*)file->Get("comp_e6"); TH1F *comp_sb_e6 = (TH1F*)file->Get("comp_sb_e6"); TH1F *comp_empty_e6 = (TH1F*)file1->Get("comp_e6"); TH1F *comp_empty_sb_e6 = (TH1F*)file1->Get("comp_sb_e6"); TH1 *comp_e6_subt; TH1 *comp_e6_empty_subt; TCanvas *c3 = new TCanvas("c3","c3", 200, 10, 600, 400); gPad->SetBottomMargin(0.15); gPad->SetTopMargin(0.05); gPad->SetLeftMargin(0.125); gPad->SetRightMargin(0.05); comp_e6_subt = (TH1F*) comp_e6->Clone(); comp_e6_subt->Add(comp_sb_e6,-1.); comp_e6_empty_subt = (TH1F*) comp_empty_e6->Clone(); comp_e6_empty_subt->Add(comp_empty_sb_e6,-1.); comp_e6_empty_subt->Scale(0.03248); comp_e6->Draw(); comp_sb_e6->Draw("same"); comp_e6_subt->SetLineColor(4); comp_e6_subt->Draw("same"); comp_e6_empty_subt->SetLineColor(2); comp_e6_empty_subt->Draw("same"); comp_e6_subt->Add(comp_e6_empty_subt,-1); comp_e6_subt->SetLineColor(1); comp_e6_subt->SetLineWidth(2); comp_e6_subt->SetTitle(""); comp_e6_subt->GetXaxis()->SetRangeUser(-1.2, 1.2); comp_e6_subt->GetXaxis()->SetTitle("E_{CCAL} + E_{FCAL} - E_{beam} (GeV)"); comp_e6_subt->GetYaxis()->SetTitle("Events / 12.5 MeV"); comp_e6_subt->Draw(); TF1 *func1 = new TF1("aaa",aaa,-2,1.,9); func1->SetParameter(0,6e4); func1->SetParameter(1,0); func1->SetParameter(2,0.11); func1->SetParameter(3,1e4*0.05); func1->SetParameter(4,-0.); func1->SetParameter(5,0.2); func1->SetParameter(6,0); func1->SetParameter(7,0); func1->SetParameter(8,0); func1->SetParameter(9,0); func1->SetLineColor(2); comp_e6_subt->Fit("aaa","L","",-2.,1.); comp_e6_subt->Fit("aaa","L","",-2.,1.); comp_e6_subt->Fit("aaa","L","",-2.,1.); comp_e6_subt->Fit("aaa","","",-2.,1.); comp_e6_subt->SetBinContent(400,2491); c3->Update(); // comp_e6_subt->Draw("histo"); // TPaveStats *ps = (TPaveStats*)c3->GetPrimitive("stats"); TPaveStats *ps = (TPaveStats*)comp_e6_subt->FindObject("stats"); ps->SetName("mystats"); TList *listOfLines = ps->GetListOfLines(); TText *tconst = ps->GetLineWith("p0"); listOfLines->Remove(tconst); tconst = ps->GetLineWith("p1"); listOfLines->Remove(tconst); tconst = ps->GetLineWith("p2"); listOfLines->Remove(tconst); tconst = ps->GetLineWith("p3"); listOfLines->Remove(tconst); tconst = ps->GetLineWith("p4"); listOfLines->Remove(tconst); tconst = ps->GetLineWith("p5"); listOfLines->Remove(tconst); tconst = ps->GetLineWith("p6"); listOfLines->Remove(tconst); tconst = ps->GetLineWith("p7"); listOfLines->Remove(tconst); tconst = ps->GetLineWith("p8"); listOfLines->Remove(tconst); TLatex *myt = new TLatex(0,0,"S = 2.634 #\pm 0.012 "); myt ->SetTextFont(62); myt ->SetTextSize(0.04); myt ->SetTextColor(kBlack); listOfLines->Add(myt); TLatex *myt1 = new TLatex(0,0,"N = 1.073 #\pm 0.091 "); myt1 ->SetTextFont(62); myt1 ->SetTextSize(0.04); myt1 ->SetTextColor(kBlack); listOfLines->Add(myt1); TLatex *myt2 = new TLatex(0,0,"C = 0.532 #\pm 0.012 "); myt2 ->SetTextFont(62); myt2 ->SetTextSize(0.04); myt2 ->SetTextColor(kBlack); listOfLines->Add(myt2); comp_e6_subt->SetStats(0); c3->Modified(); // comp_e6_subt->Draw(); // ps->Modified(); }