Hi there,
I’m trying to print the result of a fit using the new ROOT::Fit classes (7.7, root.cern.ch/root/htmldoc/guide … fit-method).
Briefly speaking, I’d like to know how I can call the method ROOT::Fit::FitResult::Print in pyroot.
The method accepts the following arguments:
FitResult::Print(ostream& os, bool covmat = false)
As such, I need to supply an object similar to the C++ ostream in order to get the results printed to the terminal.
sys.stdout doesn’t work, because it’s not really the same.
Does anybody know how I can use the FitResult::Print method from pyroot?
My code in python looks like this, if it helps:
Data = ROOT.Fit.BinData()
ROOT.Fit.FillData(Data, TH1Data)
def FitFunc(x, par):
xx = x[0]
Bin = TH1Sim.GetXaxis().FindBin(xx)
ModelVal = par[0] * TH1Sim.GetBinContent(Bin)
return ModelVal
ModelFitFTF1 = ROOT.TF1('ModelFitFTF1', FitFunc, 5000, 10000, 1)
ModelFitFTF1.SetParameter(0,1)
WrappedMCFit = ROOT.Math.WrappedMultiTF1(ModelFitFTF1, ModelFitFTF1.GetNdim())
fitter = ROOT.Fit.Fitter()
fitter.SetFunction(WrappedMCFit, False)
fitter.LikelihoodFit(Data)
print fitter.Result().Chi2()
fitter.Result().Print()
Thanks a lot!