Hi @StephanH,
In the end I actually do want to take the fits and sum them, not fit a sum of multiple PDFs.
For example, if I have a range of some mass M that is 1-10 GeV/c^{2}, I want to do fits in 10 individual 1 GeV/c^{2} bins. I want to save the fit curves and results from the 10 fits, then sum them and plot that sum against the full 1-10 GeV/c^{2} as to do some comparisons.
file.WriteObject(histogram, “name that it should have in the file”);
Yes, thank you but creating this histogram is what I need some clarification on. It would be helpful to see a simple example of its usage.
There is some example on page 57 here http://roofit.sourceforge.net/docs/tutorial/plot/roofit_tutorial_plot.pdf and page 102 here http://cicpi.ustc.edu.cn/indico/getFile.py/access?sessionId=2&resId=1&materialId=0&confId=678.
I try to reproduce them like this
model = ROOT.RooAddPdf("model", "total sig+bkg", ROOT.RooArgList(sig_pdf, bkg_pdf), ROOT.RooArgList(sig_yield, bkg_yield))
# data is an ntuple of M
r = model.fitTo(data, ROOT.RooFit.Extended(), ROOT.RooFit.Save(True))
model.plotOn(test_frame, ROOT.RooFit.Name("NAME"))
hist1 = model.createHistogram("fitCurve", M, ROOT.RooFit.IntrinsicBinning()))
f = ROOT.TFile("test.root","RECREATE")
f.WriteObject(hist1, "fitCurve")
f.Close()
Does this actually same the fit curve generated from fitting model
to data
, it doesn’t seem to? The normalization, given by the fitted values of sig_yield
and bkg_yield
, seems to not be correct. How is this done correctly with createHistogram
?
UPDATE
After looking here How to save fit curve and erros in file (roofit)?.
This is kind of what I was looking to do
hist1 = test_frame.getCurve()
f = ROOT.TFile("test2.root","RECREATE")
f.WriteObject(hist1, "hName")
f.Close()
It seems to give the correct result, though without plotting it with the data the plot normalization looks distorted. Can you confirm this saves the fitted curve/model? I want to do this over multiple mass ranges and save each individual one as a histogram to a ROOT file, then same them. Is there am equivalent way to do this with createHistogram
?