Dear Experts:
I am currently doing a chi-squared fit in root to multiple histograms with a different function for each histogram but with some shared parameters. The question I have is how to make this a binned likelihood fit instead. That is, is there an equivalent for binned likelihood of GlobalChi2 and ROOT::Fit::Chi2Function ?
Also, if yes, what minimizer should I use?
Just showing part of the code for 2 histograms, the relevant code snippets are:
ROOT::Math::WrappedMultiTF1 w05(*sumetcalcxx[0],1);
ROOT::Math::WrappedMultiTF1 w15(*sumetcalcxx[1],1);
ROOT::Fit::DataOptions opt;
ROOT::Fit::DataRange range05;
ROOT::Fit::DataRange range15;
range05.SetRange(0.,1000.);
ROOT::Fit::BinData data05(opt,range05);
ROOT::Fit::FillData(data05,sumet2023muxx[0]);
range15.SetRange(0.,1000.);
ROOT::Fit::BinData data15(opt,range15);
ROOT::Fit::FillData(data15,sumet2023muxx[1]);
ROOT::Fit::Chi2Function chi2_05(data05, w05);
ROOT::Fit::Chi2Function chi2_15(data15, w15);
GlobalChi2 globalChi2(chi2_05, chi2_15, chi2_25, chi2_35, chi2_45, chi2_55, chi2_65, chi2_75);
ROOT::Fit::Fitter fitter;
double par0[7] = long code line not relevant here
fitter.Config().SetParamsSettings(7,par0);
fitter.Config().MinimizerOptions().SetPrintLevel(0);
fitter.Config().SetMinimizer("Minuit2","Migrad");
fitter.FitFCN(7,globalChi2,0,data05.Size()+data15.Size()+data25.Size()+data35.Size()+data45.Size()+data55.Size()+data65.Size()+data75.Size(),true);
ROOT::Fit::FitResult result = fitter.Result();
result.Print(std::cout);
with:
struct GlobalChi2 {
GlobalChi2( ROOT::Math::IMultiGenFunction & f0,
ROOT::Math::IMultiGenFunction & f1,
ROOT::Math::IMultiGenFunction & f2,
ROOT::Math::IMultiGenFunction & f3,
ROOT::Math::IMultiGenFunction & f4,
ROOT::Math::IMultiGenFunction & f5,
ROOT::Math::IMultiGenFunction & f6,
ROOT::Math::IMultiGenFunction & f7) :
fChi2_0(&f0), fChi2_1(&f1) , fChi2_2(&f2), fChi2_3(&f3), fChi2_4(&f4),
fChi2_5(&f5), fChi2_6(&f6), fChi2_7(&f7) {}
double operator() (const double *par) const {
double p0[7];
p0[0] = 20.0;
p0[1] = 5.0;
for (int i = 2; i < 7; ++i) p0[i] = par[i];
etc.
return (*fChi2_0)(p0) + (*fChi2_1)(p1) + (*fChi2_2)(p2) + (*fChi2_3)(p3) +
(*fChi2_4)(p4) + (*fChi2_5)(p5) + (*fChi2_6)(p6) + (*fChi2_7)(p7);
}
Thank you in advance for any help.
ROOT Version: 6.26/06
Platform: macosxarm64
Compiler: Apple clang version 14.0.0 (clang-1400.0.29.202)