Using ROOT::Fit::FitResult::Print method with pyroot: Ofstream

Hi there,

I’m trying to print the result of a fit using the new ROOT::Fit classes (7.7, … 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)
WrappedMCFit = ROOT.Math.WrappedMultiTF1(ModelFitFTF1, ModelFitFTF1.GetNdim())
fitter = ROOT.Fit.Fitter()
fitter.SetFunction(WrappedMCFit, False)
print fitter.Result().Chi2()


Thanks a lot!


use the C++ standard output:fitter.Result().Print(ROOT.cout)
(I’d have figured it’d be ROOT.std.cout, but that doesn’t exist; looks like a bug and you might want to file a JIRA ticket, but at least ROOT.cout seems to work.)


1 Like

Thanks a lot!
I didn’t know that you can call cout through ROOT.