How to Draw fitting plots from Roofitresult

Hi, I’m trying to separate plot from roofit procedure, thus I follow the tutorial : to save the roofitresult and access it in another marco.

However, in the tutorial , the plot is for fitting parameter correlation matrix. I tried to change it to something like : r->plotOn(frame,x), but did not work. the createHessePdf () function also can not load the fitting parameter correctly. Does anyone know how to draw from Roofitresult directly? or we must create the same PDF again, and load the parameter from Roofitresult? Thanks.

for completeness here’s the code fragment I am using:

RooRealVar Dmass(“Dmass”,“Dmass”,DsDataFitRangeLow,DsDataFitRangeHigh);
RooDataSet RooDS(“RooDS”,“RooDS”,RooArgSet(Dmass),Import(*t_Data));
RooRealVar DsMassMean(“DsMassMean”,“DsMassMean”,DsMassMeanV,1.965,1.971);
RooRealVar DsWidth1(“DsWidth1”,“DsWidth1”,DsWidth1V,0.000001,0.1);
RooRealVar DsWidth2(“DsWidth2”,“DsWidth2”,DsWidth2V,0.000001,0.1);
RooRealVar DsGaus1Fr(“DsGaus1Fr”,“DsGaus1Fr”,DsGaus1FrV,0.0,1);
RooRealVar DsFloatWidth(“DsFloatWidth”,“DsFloatWidth”,DsFloatWidthV,-1,1);

RooRealVar Cheb1(“Cheb1”,“Cheb1”,0,-1,1);
RooRealVar Cheb2(“Cheb2”,“Cheb2”,0,-1,1);
RooFormulaVar scale_width1(“scale width1”,“scaled width1”,“DsWidth1*(1+DsFloatWidth)”,RooArgSet(DsWidth1,DsFloatWidth));
RooFormulaVar scale_width2(“scale width2”,“scaled width2”,“DsWidth2*(1+DsFloatWidth)”,RooArgSet(DsWidth2,DsFloatWidth));
RooGaussian Gaus1(“Gaus1”,“gauss(Dmass,DsMassMean,scale_width1)”,Dmass,DsMassMean,scale_width1);
RooGaussian Gaus2(“Gaus2”,“gauss(Dmass,DsMassMean,scale_width2)”,Dmass,DsMassMean,scale_width2);
RooAddPdf SigPdf(“SigPdf”,“SigPdf”,RooArgList(Gaus1,Gaus2),DsGaus1Fr);
RooChebychev BkgPdf(“BkgPdf”,“BkgPdf”,Dmass,RooArgList(Cheb1,Cheb2));
RooRealVar NumSig(“NumSig”,“Number of Signal”,N_sigV,-1e4,1e4);
RooRealVar NumBkg(“NumBkg”,“Number of Background”,N_bkgV,0,1e6);
RooAddPdf RooDsMixPdf(“RooDsMixPdf”,“RooDsMixPdf”,RooArgList(SigPdf,BkgPdf),RooArgList(NumSig,NumBkg));
RooFitResult *fitresult = RooDsMixPdf.fitTo(RooDS,Extended(kTRUE),Save());

and what I want to do is like :

RooFitresult fitresult=(RooFitresult)file->Get(“fitresult”);
RooPlot* massframe = Dmass.frame(Title(“Dmass”));

but the plotOn does not work in these way,
also the createHessePdf() does not work,:

RooAbsPdf *paraPdf fitresult->createHessePdf(RooArgSet(NumSig,NumBkg,scale_width1,scale_width2,Cheb1,Cheb2,DsMassMean,SigPdf,BkgPdf));

another question is how to access value of parameter from Roofitresult , from , there is no getV, but we can only print the value on screen, which is not efficient since we need to write code to print out and another code to read the print out.


You should plot your fit function, here should be RooDsMixPdf.plotOn(…) in your case.

The parameter value should be obtain by itself, i.e., DsMassMean.getVal() to get the value of your Ds mass mean from the fit.

Good luck!


Thanks, I know it works if you are using the same code and directly plot with the RooAbsPdf.plotOn() and getValV() with the RooRealVal.
But it is NOT my question. I want to separate fit and plot to two different code, since the fit is very time consuming and I need to refine the plot after the fit, do not want to repeat the fit everytime when I just want to change the style of the plot.
Thus I am asking about how could I plot from the Roofitresult , and how to access the fitting parameter through the Roofitresult , or how could I save the fitresult which can let me retrieve later and plot.

Then you might create a ROOT file to store your fit results, and later you may read this ROOT file to do the further operation. I guess this should work, but not for sure.

That’s what I asked in my original post. Is there anyone know how to do that? the RooFitresult seems not work.

Does anyone have idea for that?

Does anyone have idea for that?

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