Iterate RooFitResult

Dear experts,

how does one iterate an instance of RooFitResult? I want to obtain a list of each value name, actual value and error after the fit without knowing the names a priori. I am thinking of something similar to:

for (auto p : myFitResult->floatParsFinal()) {
    cout << p.getTitle() << endl;
    cout << p.getValue() << endl;
    cout << p.getError() << endl;
}

Thanks

You can get a RooArgList of the parameters using RooFitResult::floatParsFinal(), as you already found out. However, RooArgList does not have a begin or end defined, so simple iterating using a C++ auto loop does not work. You have to do it manually, as far as I know:

auto pars = myFitResult->floatParsFinal();
RooRealVar *p;
for (int i = 0; i < pars->getSize(); i++)
{
    p = (RooRealVar *)pars->at(i);
    cout << p->getTitle() << endl;
    cout << p->getVal() << endl;
    cout << p->getError() << endl;
}
1 Like

Thank you for your help. This works for me!

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