Saving RooMCstudy in a ROOT file

Hello all,
I want to save the results of a MC study in a root file, and I’ve tried like:

root_file = R.TFile("mcstudy.root", "RECREATE")

but I get this error:

TKey::TKey:0: RuntimeWarning: since RooMCStudy has no public constructor
        which can be called without argument, objects of this class
        can not be read with the current library. You will need to
        add a default constructor before attempting to read it.

Is there a way to save the results so that I can access again the mcstudy and do operations like mcstudy.fitResult(i).floatParsFinal() or mcstudy.GenData(i)?

Hello @mdgalati,
thanks for your question!
What you get is a warning, not an error, and to my understanding you should be able to save your MCStudy to a root file in this way, but then you’ll not be able to read it, I think @jonas can provide further info about it. What you could do is the following

    root_file = R.TFile("mcstudy.root", "RECREATE")
    for i in range(nTest):


Hi Monica,
Thanks for your answer. I currently by-passed this error by saving the data in a similar way to you:

root_file = R.TFile(rootpath, "RECREATE")
    for i in range(nMCevents):

and I can access the single fitResult and genData:

def plotToy(Ntoy):
    root_file = R.TFile(rootpath, "READ")
    genData_x = root_file.Get(f"genData_{Ntoy}")
    fitResult_x = root_file.Get(f"fitResult_{Ntoy}")

There’s not a way to read everything in a loop I think (?).

However I wanted to know if something was implemented for RooMCStudy in particular.

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