How to properly use ROOT.Fit.Fitter.SetFunction?

ROOT Version: 6.10/04 (running on LXPLUS)
Platform: SL6 (LXPLUS)
Compiler: g++ 6.2.0 (presumably, I’m not sure how to get that from root-config)

In PyROOT I’m trying to construct a ROOT::Fit::Fitter to do a binned likelihood fit. I understand how to construct the BinData, however, I need to set the model that will be fit with SetFunction(),

void SetFunction(const IModelFunction & func, bool useGradient = false)

However, I’m not exactly clear on the docs on what are reasonable derived classes to use here for the func ( ROOT::Fit::BasicFCN needs to be from a created from a derived class for example).

I had tried writing a class that inherits from ROOT.TPyMultiGenFunction so I could use ROOT::Fit::Fitter::SetFCN but then following that with ROOT::Fit::Fitter::LikelihoodFit with my BinData object causes the error

Error in <ROOT::Math::Fitter::DoBinnedLikelihoodFit>: model function is not set

 *** Break *** segmentation violation

However, if I run FitFCN with my class then I can get it to work. However, I would like to not have to implement everything by hand if possible and use the LikelihoodFit instead.

So it isn’t clear to me how to properly set this. Can anyone give me an example of how to construct a toy model in PyROOT using ROOT::Fit::Fitter?

@moneta can help you with this.

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