Binned likelihood multiple histogram fit

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;
  ROOT::Fit::BinData data05(opt,range05);
  ROOT::Fit::BinData data15(opt,range15);

  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


  ROOT::Fit::FitResult result = fitter.Result();


  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];


     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)

Dear @AllenM ,

Thanks for asking your question on the forum! There is this RooFit tutorial ROOT: tutorials/roofit/rf602_chi2fit.C File Reference which might be of help in prototyping what you want to do. Let me know if you find it helpful.


Dear Vincenzo:

If I understand the example correctly, it shows me how to do with RooFit what I am managing to do in root, a chi squared fit to the multiple histograms. Because there is a wide range of entries in my histograms, including bins with a small number of events, the fit is having problems, and I want to try a binned likelihood fit instead. I would therefore like to know how to do such a fit in root. Does it just involve making some changes in the kind of code I am using now for the chisq fit? If it is not possible, then I will have to switch to using RooFit instead, but will have the same sort of question there, since this example is a chisq fit.

Thanks very much!

Best regards,

Dear @AllenM ,

My impression is that RooFit is the tool for your job, but I will let @jonas comment further on this.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.