Home | News | Documentation | Download

RooFit: saving RooDataHist as ROOT TH1 histogram?

Hello - I would like to save my generated data from
RooDataSet and RooDataHist in an output text or ROOT file.

For RooDataSet I see a simple way:

RooDataSet* tmodel_data=tmodel.generate(t,nevtot) ; tmodel_data->write(Form(“datagen/tmodeldata_%d.dat”,niter))

(a question: could above two lines be accomplished in a single call?)

But I could not figure out how to (in a few lines) save

RooDataHist* tmodel_hist=tmodel.generateBinned(t,nevtot) ;

as a ROOT TH1 histogram …:sunglasses: Is there a function built in
RooDataHist that would enable that? (reading in TH1 and
converting it to RooDataHist is covered in manual, but the
opposite direction RooDataHist -> TH1 would also be useful …

                                               Cheers, Emil

Hi Emil,

RooDataHist inherits from RooAbsData which has a method called createHistogram.
root.cern.ch/root/html/RooAbsData.html

something like this:
TH1 *h1 = yourdatahist->createHistogram(...);