Code HistFactory Models in JSON.
With the HS3 standard, it is possible to code RooFit-Models of any kind as JSON files. In this tutorial, you can see how to code up a (simple) HistFactory-based model in JSON and import it into a RooWorkspace.
import ROOT
ws = ROOT.RooWorkspace("workspace")
tool = ROOT.RooJSONFactoryWSTool(ws)
tool.importJSON(ROOT.gROOT.GetTutorialDir().Data() + "/roofit/rf515_hfJSON.json")
ws.Print()
model = ws["ModelConfig"]
params = model.GetPdf().getParameters(ws["observed"])
ROOT.SetOwnership(params, True)
params_initial = params.snapshot()
ROOT.SetOwnership(params_initial, True)
result = model.fitTo(ws["observed"], ROOT.RooFit.Save(), ROOT.RooFit.PrintLevel(-1))
ROOT.SetOwnership(result, True)
result.Print()
params.assign(params_initial)
tool.exportJSON("myWorkspace.json")
ws_2 = ROOT.RooWorkspace("workspace")
tool_2 = ROOT.RooJSONFactoryWSTool(ws_2)
tool_2.importJSON("myWorkspace.json")
ws_2.Print()
model_2 = ws_2["ModelConfig"]
result = model_2.fitTo(ws_2["observed"], ROOT.RooFit.Save(), ROOT.RooFit.PrintLevel(-1))
ROOT.SetOwnership(result, True)
result.Print()
- Date
- November 2021
- Author
- Carsten Burgard
Definition in file rf515_hfJSON.py.