int fit_dscb(TH1F*& hrsp, const double nsigma, const double jtptmin, const int niter, const string alg, const double fitmin, const double fitmax ) { if (0==hrsp) { cout<<"ERROR: Empty pointer to fit_dscb()"<<endl;return -1; } // first use a gaussian to constrain crystal ball gaussian core fit_gaussian(hrsp, nsigma, jtptmin, niter, alg); TF1* fgaus = hrsp->GetFunction("fgaus"); if (0==fgaus) { hrsp->GetListOfFunctions()->Delete(); return -1; } // implementation of the low pt bias threshold string histname = hrsp->GetName(); double ptRefMax(1.0),rspMax(0.0); int pos1 = histname.find("RefPt"); int pos2 = histname.find("to",pos1); string ss = histname.substr(pos1+5,pos2); if (from_string(ptRefMax,ss,std::dec)) { if (histname.find("RelRsp")==0) rspMax = jtptmin/ptRefMax; if (histname.find("AbsRsp")==0) rspMax = jtptmin-ptRefMax; } double fitrange_min(fitmin); double fitrange_max(fitmax); fitrange_min = std::max(rspMax,fitmin); adjust_fitrange(hrsp,fitrange_min,fitrange_max); TF1* fdscb = new TF1("fdscb",fnc_dscb,fitrange_min,fitrange_max,7); fdscb->SetLineWidth(2); fdscb->SetLineStyle(2); double norm = 2*fgaus->GetParameter(0); double mean = fgaus->GetParameter(1); double sigma= fgaus->GetParameter(2); //cout << hrsp->GetName() << " fgaus "<< mean << " \t " << hrsp->GetMean() << endl; // double norm = 2*hrsp->GetMaximum(); // double mean = hrsp->GetMean(); // //double mean = GetPeak(hrsp); // cout << " mean : " << mean << " hist mean : "<< hrsp->GetMean() << endl; // double sigma= hrsp->GetRMS(); double aone(2.0),atwo(2.0),pone(10.0),ptwo(10.0); //double aone(1.0),atwo(1.0),pone(10.0),ptwo(10.0); TVirtualFitter::SetDefaultFitter("Minuit"); int fitstatus(0); for (int i=0;i<niter;i++) { fdscb->SetParameter(0,norm); // N fdscb->SetParameter(1,mean); // mean fdscb->SetParameter(2,sigma);// sigma fdscb->SetParameter(3,aone); // a1 fdscb->SetParameter(4,pone); // p1 fdscb->SetParameter(5,atwo); // a2 fdscb->SetParameter(6,ptwo); // p2 fdscb->FixParameter(1,mean); fdscb->FixParameter(2,sigma); if (i>0) fdscb->FixParameter(3,aone); else{ fdscb->SetParLimits(3,0.,20.); //! best } if (i>1) fdscb->FixParameter(5,atwo); else{ fdscb->SetParLimits(5,0.,20.); //! best } //! best fdscb->SetParLimits(4,0.,60.); fdscb->SetParLimits(6,0.,60.); fitstatus = hrsp->Fit(fdscb,"RQ+"); if (0==fitstatus) i=999; delete fdscb; fdscb = hrsp->GetFunction("fdscb"); if (0==fdscb) return -1; norm = fdscb->GetParameter(0); aone = fdscb->GetParameter(3); pone = fdscb->GetParameter(4); atwo = fdscb->GetParameter(5); ptwo = fdscb->GetParameter(6); //cout << " aone : " << aone << " atwo : " << atwo << " pone : " << pone << " ptwo : " << ptwo << endl; //reset sigma and mean to gauss values... fdscb->SetParameter(1,fgaus->GetParameter(1)); fdscb->SetParError (1,fgaus->GetParError(1)); fdscb->SetParameter(2,fgaus->GetParameter(2)); fdscb->SetParError (2,fgaus->GetParError(2)); } if (0!=fitstatus){ cout<<"fit_fdscb() to "<<alg.c_str()<<" " <<hrsp->GetName() <<" failed. Fitstatus: "<<fitstatus<<endl; hrsp->GetFunction("fdscb")->Delete(); } else fdscb->ResetBit(TF1::kNotDraw); //cout << " aone : " << aone << " atwo : " << atwo << " pone : " << pone << " ptwo : " << ptwo << endl; return fitstatus; }