How to retrieve a histogram from a fit in roofit


I am trying to fit one histogram to another in roofit and I believe I have the fitting part down but now I cannot figure out how to retrieve the histogram that was allowed to vary. Here is the general idea of the process I am using:

RooRealVar x(“x”,“x”,-2.0,2.0);

RooDataHist data(“data”,“data”,x,hdata);
RooDataHist sig(“sig”,“sig”,x,hsig);

RooHistPdf sigPdf(“sigPdf”,“sigPdf”,x,sig);

RooRealVar Nsig(Nsig,Nsig,650000,0,5000000);

RooAddPdf sum(“sum”,“sum”,RooArgSet(sigPdf),RooArgSet(Nsig));


I need a histogram from sig in order to find the error in an integral after fitting with the histogram data.


I am not sure exactly which histogram do you need. The fit will give you a best value of Nsig, the fit parameter

Best Regards



Sorry, I should have been a bit more clear. I need the histogram for sig so I can pull and display the error in each bin after the fit. I understand that I can get the integral from the fit in the range with Nsig.getVal(); and Nsig.getError(); but I want to be able to display the error in each bin from the fit.

thanks for helping,



Would you like to get the error in the fitted function values after the fit in each bin ?
You can do this by using the option RooFit::VisualizeError(fitResult) in the plotOn method of the pdf .

See figure 1.3 of … t_3.00.pdf




Sorry, that didn’t seem to work. In that the function VisualizeError() doesn’t seem to be defined. Perhaps I can define what I want in another way. In Root for a normal TH1F* histogram I can use the function histogram->Integral(min,max); to get the error between min and max I can do this

[color=#00FF00]Double_t error = 0;
for(Int_t i=min; i<=max; i++){
Double_t binerror = histogram->GetBinError(i);



so is there anyway to do that with the data types RooDataHist, RooHistPdf, or RooAddPdf?

Thank you for all your help!