//______________________________________________________________________________ void Fit(TH1* h, Double_t* outPos, Double_t* outFWHM) { // Perform fit. Char_t tmp[256]; Double_t x1 = 50; Double_t x2 = 230; TF1* func = new TF1("func", "gaus(0)+pol5(3)", x1, x2); func->SetParameters(h->GetMaximum(), 135, 8, 1, 1, 0.1, 0.1); func->SetLineColor(kBlue); func->SetParLimits(1, 130, 140); func->SetParLimits(2, 1, 15); h->Fit(func, "RBQO"); // get position and FWHM fPi0Pos = func->GetParameter(1); *outPos = fPi0Pos; *outFWHM = 2.35*func->GetParameter(2); // indicator line TLine* line = new TLine(); line->SetLineWidth(2); line->SetX1(fPi0Pos); line->SetX2(fPi0Pos); line->SetY1(0); line->SetY2(h->GetMaximum()); TF1* fBG = new TF1("funcBG", "pol5", x1, x2); for (Int_t i = 0; i < 6; i++) fBG->SetParameter(i, func->GetParameter(3+i)); fBG->SetLineColor(kRed); // draw h->GetXaxis()->SetRangeUser(0, 300); h->Draw(); func->Draw("same"); fBG->Draw("same"); line->Draw("same"); }
//______________________________________________________________________________ void Fit(TH1* h, Double_t* outPos, Double_t* outFWHM) { // Perform fit. Char_t tmp[256]; // delete old function TF1* func = new TF1(tmp, "pol1+gaus(2)"); func->SetLineColor(2); // estimate peak position Double_t fPi0Pos = h->GetBinCenter(h->GetMaximumBin()); // configure fitting function func->SetRange(fPi0Pos - 0.8, fPi0Pos + 0.8); func->SetLineColor(2); func->SetParameters( 0.1, 0.1, h->GetMaximum(), 0, 0.1); Int_t fitres = h->Fit(func, "RB0Q"); // get position and FWHM fPi0Pos = func->GetParameter(3); *outPos = fPi0Pos; *outFWHM = 2.35*func->GetParameter(4); // indicator line TLine* line = new TLine(); line->SetX1(fPi0Pos); line->SetX2(fPi0Pos); line->SetY1(0); line->SetY2(h->GetMaximum()); // draw h->GetXaxis()->SetRangeUser(-3, 3); h->Draw(); func->Draw("same"); line->Draw("same"); }