//***############## main fitting Fxn ################ *****// void FitPlotAndSave( char *Ifile ){ /** Plot Options***/ //gROOT->Reset(); // gROOT->Clear(); gROOT->SetStyle("Plain") ; gROOT->SetBatch(kFALSE); gStyle->SetOptTitle(1); gStyle->SetOptStat(0); gStyle->SetOptFit(1); gStyle->SetStatX(.89); gStyle->SetStatY(.89) ; gStyle->SetStatBorderSize(0); //gStyle->SetOptStat(1111111) gStyle->SetCanvasColor(kWhite); // background is no longer mouse-dropping white gStyle->SetPalette(1); // blue to red false color palette. Use 9 for b/w gStyle->SetCanvasBorderMode(0); // turn off canvas borders gStyle->SetPadBorderMode(0); gStyle->SetPaintTextFormat("5.2f"); // What precision to put numbers if plotted with "TEXT" // For publishing: gStyle->SetLineWidth(2); gStyle->SetTextSize(1.1); gStyle->SetLabelSize(0.06,"xy"); gStyle->SetTitleSize(0.08,"xy"); gStyle->SetTitleOffset(1.2,"x"); gStyle->SetTitleOffset(1.0,"y"); gStyle->SetPadTopMargin(0.1); gStyle->SetPadRightMargin(0.1); gStyle->SetPadBottomMargin(0.16); gStyle->SetPadLeftMargin(0.12); TGaxis::SetMaxDigits(1); // Set Axis to be of the form 0.11 10^N TFile *ifile = new TFile(Ifile); TF1 *fitFcn = new TF1("fitFcn", mygaus, FitLowRange, FitHighRange, 3 ); fitFcn->SetNpx(500); fitFcn->SetLineWidth(4); fitFcn->SetLineStyle(5); fitFcn->SetLineColor(kBlue); cout <<" Calling Fitting Fxntion" << endl; TH1F*h_Seed_TimeEBEB = (TH1F*)ifile->Get("EBEB/seed time"); if(h_Seed_TimeEBEB == 0){ std::cout <<"!! Histogram Does not exist!!" << std::endl; throw 1;} h_Seed_TimeEBEB->SetTitle("Seed Time[ns]"); h_Seed_TimeEBEB->SetMarkerStyle(20); h_Seed_TimeEBEB->SetMarkerSize(0.8); h_Seed_TimeEBEB->SetStats(1); h_Seed_TimeEBEB->SetTitleSize(0.08, "x"); h_Seed_TimeEBEB->SetTitleOffset(1.0, "x"); h_Seed_TimeEBEB->SetTitleSize(0.06, "y"); h_Seed_TimeEBEB->SetTitleOffset(0.95, "y"); h_Seed_TimeEBEB->SetYTitle("Number of Seeds/0.05ns"); h_Seed_TimeEBEB->SetXTitle("t_{seed}[ns]"); h_Seed_TimeEBEB->GetXaxis()->SetRangeUser(FitLowRange, FitHighRange); /** Set parms as parms of Fit Fxn **/ fitFcn->SetParameters(500, h_Seed_TimeEBEB->GetMean(), h_Seed_TimeEBEB->GetRMS() ); fitFcn->SetParNames("CONST", "#mu(ns)", "#sigma(ns)"); h_Seed_TimeEBEB->Fit("fitFcn", "LL"); /**Fit with improved LL**/ std::cout << "Printing Fit Parameters for EBEB ...... " << std::endl; printf("Integral of function in EBEB = %g\n", fitFcn->Integral( FitLowRange, FitHighRange)); //*** retrive fit results***// int npar = fitFcn->GetNpar(); TVirtualFitter *fit = TVirtualFitter::GetFitter(); fit->PrintResults(2,0.); TMatrixD *CovMatrix = new TMatrixD ( npar, npar, fit->GetCovarianceMatrix() ); CovMatrix->Print(); TCanvas *c1 = new TCanvas("c1","EB-EB",200,10,800,900); c1->SetGridx(); c1->SetGridy(); c1->GetFrame()->SetFillColor(21); c1->GetFrame()->SetBorderMode(-1); c1->GetFrame()->SetBorderSize(5); /* c1->Divide(2,1); */ c1->cd(); h_Seed_TimeEBEB->Draw(); fitFcn->Draw("sames"); c1->SetLogy(0); // draw the legend TLegend *leg = new TLegend(0.15,0.72,0.3,0.85); leg->SetTextFont(72); leg->SetTextSize(0.04); leg->AddEntry(h_Seed_TimeEBEB,"EB","lpe"); leg->AddEntry(fitFcn,"GAUS","l"); leg->Draw(); c1->SaveAs("Seed_Time_DoubleElectron_Run2012A-EB-EB.png"); }