Thank you so much. I understand now. But here comes another problem(I’m afraid that I have to bother you again).
I used a TTree Class to fill my unbinned data. But I cannot get the correct fitting result even if I set initial parameter values and limits, or let us say, it returned the boundary of the limits I set. Could you help me with this new question? Here is my main code:
TTree *tree = new TTree("TreeName","");// I tried to create a tree with only one branch.
tree->Branch("mq1",&mq1,"mq1/D");
in.open("mvsq.txt");// original data, the forum forbidden new user from uploading files
while(in>>mq1)
{
if(mq1>xrange1&&mq1<xrange2)
{
tree->Fill();
}
}
in.close();
tree->Print();
//Unbindata defination
int nevt = tree->Draw("mq1","","goff");
std::vector<double> dataX( tree->GetV1(), tree->GetV1() + nevt);
ROOT::Fit::UnBinData data(nevt,dataX.data());
//Function defination and parameter settings
TF1 *func=new TF1("func","[0]*exp(-(x-[1])*(x-[1])/(2*[2]*[2]))+[3]*exp(-(x-[4])*(x-[4])/(2*[5]*[5]))+[6]",xrange1 ,xrange2 );
double par[7]={80,1.750425 ,2e-5 ,150,1.750525 ,2e-5 ,0.00000001};
// func->SetParameters(par);
// func->SetParLimits(0,50,150);
// func->SetParLimits(1,(1.7504 ) ,(1.75045 ) );
// func->SetParLimits(2,0.000001 ,0.00005 );
// func->SetParLimits(3,110,190);
// func->SetParLimits(4,(1.7505 ) ,(1.75055 ) );
// func->SetParLimits(5,0.000001 ,0.00005 );
// func->SetParLimits(6,0,10);
ROOT::Math::WrappedMultiTF1 fitFunction(*func,func->GetNdim());
ROOT::Fit::Fitter fitter;
fitter.SetFunction(fitFunction, false);
fitter.Config().SetParamsSettings(7,par);
fitter.Config().ParSettings(0).SetLimits(0,200);
fitter.Config().ParSettings(1).SetLimits(1.7504,1.75045 );
fitter.Config().ParSettings(2).SetLimits(0.000001 ,0.00005 );
fitter.Config().ParSettings(2).SetStepSize(1e-7 );
fitter.Config().ParSettings(3).SetLimits(0,300);
fitter.Config().ParSettings(4).SetLimits(1.7505 ,1.75055 );
fitter.Config().ParSettings(5).SetLimits(0.000001 ,0.00005 );
fitter.Config().ParSettings(5).SetStepSize(1e-7);
fitter.Config().ParSettings(6).SetLimits(0,10);
fitter.Config().SetMinimizer("Minuit", "Migrad");
fitter.LikelihoodFit(data);
ROOT::Fit::FitResult result=fitter.Result();
result.Print(std::cout);