#include #include #include #include #include #include #include #include #include #include #include #include #include #include // fit functions Double_t bin, xmean, xlow, xhigh; Double_t DYS_fit (Double_t *x, Double_t *p) { Double_t p0 = p[0]*bin / (-1./p[3] + p[1]/p[4] + p[2]/p[5]); Double_t x0 = x[0]-xlow; Double_t fv = p0 * (-exp(-p[3]*x0) + p[1]*exp(-p[4]*x0) + p[2]*exp(-p[5]*x0)); return fv; } Double_t DYS_fip (Double_t *x, Double_t *p){ Double_t xc = xmean-xlow; Double_t xv = x[0]-xmean; Double_t p0 = p[0]*bin / (p[1]*exp(p[3]*xc) + exp(p[4]*xc) + p[2]*exp(p[5]*xc)); Double_t fv = p0 * (p[1]*p[3]*exp(-p[3]*xv) + p[4]*exp(-p[4]*xv) + p[2]*p[5]*exp(-p[5]*xv)); return fv; } // main function void testfit(){ // Get the hist into the root ntuple TFile *file = new TFile("histo.root"); TH1F *h1 = (TH1F*) file->Get("h37"); gStyle->SetOptStat(1111111); gStyle->SetOptFit(011111); // Variables Int_t i=0; // Declaration of histos TH1F *h2 = (TH1F*) h1->Clone(); h2->SetName("h2"); TH1F *h3 = (TH1F*) h1->Clone(); h3->SetName("h3"); // Fit function Float_t parVal[6], parErr[6]; TF1 *mfit3 = new TF1("mfit3", "[0]*([1]*exp(-[3]*(x-2.2))+exp(-[4]*(x-2.2))+[2]*exp(-[5]*(x-2.2)))",0.,100000.); mfit3->SetParName(0,"const0"); mfit3->SetParName(1,"const1"); mfit3->SetParName(2,"const3"); mfit3->SetParName(3,"slope1"); mfit3->SetParName(4,"slope2"); mfit3->SetParName(5,"slope3"); // Fits mfit3->SetParameter(0, 2100); mfit3->SetParameter(1, -0.89); mfit3->SetParameter(2, 0.023); mfit3->SetParameter(3, 2.20); mfit3->SetParameter(4, 2.10); mfit3->SetParameter(5, 0.52); h2->Fit(mfit3,"","",1.2,15.0); for (i=0; i<6; i++) { parVal[i] = (Float_t)mfit3->GetParameter(i); parErr[i] = (Float_t)mfit3->GetParError (i); } // bin = 0.1; xmean = 2.2; xlow = 1.2; xhigh = 15.0; TF1 *newfit = new TF1("newfit", DYS_fit, xlow,xhigh, 6); newfit->SetParameter(0,5729.69); newfit->SetParameter(1,0.998238); newfit->SetParameter(2, 0.00475432); newfit->SetParameter(3, 2.19718); newfit->SetParameter(4, 2.08281); newfit->SetParameter(5, 0.518135); h3->Fit(newfit,"","",xlow,xhigh); TCanvas *c1 = new TCanvas("canvas","canvas", 60, 80,700,700); c1->Divide(1,3); c1->cd(1); gPad->SetLogy(); h1->Draw(); c1->cd(2); gPad->SetLogy(); h2->Draw(); c1->cd(3); gPad->SetLogy(); h3->Draw(); //h->Fit(newfip,"","",xlow,xhigh); }