Using ROOFIT PDFs with ROOT TH1s?

I have a very basic question :blush: - what is the most straightforward way to fit a ROOFIT PDF (I’d like to use the RooBifurGaussBifurcated PDF) to a TH1 over an interval?

As far as I can tell from the documentation, the two are quite well separated, so I’m not sure how I could e.g. use ROOFIT to fit a TH1 that has been Fill()d, and then plot this fit on top of the TH1 histogram itself.

Am I missing something…? :frowning:

Hi,

The most straightforward ways is to import the TH1 into a RooDataHist, i.e.

TH1* hh ; // from elsewhere
RooRealVar x(“x”,“x”,-10,10) ; // adjust range here
RooDataHist h(“h”,“h”,x,*hh) ;

RooBifurGauss pdf(“pdf”,“pdf”,x,…) ;

pdf.fitTo(h) ;

RooPlot* frame = x.frame() ;
h.plotOn(frame) ;
pdf.plotOn(frame) ;
frame->Draw() ;

If you only want to fit a subset of the TH1 you can either adjust the range
on “x” so that it only includes the wanted range. In this way also only that
part of the data and p.d.f will be plotted. Alternatively, you set the range on
x such so that it imports the full range of the TH1 in ‘h’ and you then only
proceed to fit a subrange of it by adding e.g. Range(-5,5, to the fitTo() command
which will instruct fitTo() to only fit that subrange of the data. In this way the
full TH1 will be shown by h.plotOn(frame) and only the fitted range of the curve
will be shown when you do pdf.plotOn(frame)

Wouter

Many thanks, my program is now working happily!