Hi expxerts,
I am importing a TH1 with variable binning into a RooDataHist, and the problem is that RooDataHist ‘thinks’ that the original histogram has been normalized for bin size, hence it recalculates the number of entries in each bin based on the bin size (keeping the total normalization constant).
Is there a way/option to tell the RooDataHist that the histogram from which it is being created is a histogram and not a pdf, i.e. not normalized for bin size?
You can run the code below as a macro, the output on the terminal and the plot will hopefully illustrate what I am trying to do and what the problem is.
{
using namespace RooFit;
RooRealVar gl(“gl”,“gl”,0.0, 1);
Double_t gl_bins[9] = {0, 0.25, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 };
RooBinning glbins(8, gl_bins, “glbin”);
gl.setBinning(glbins);
std::cout<<"Making a histo with non uniform binning BUT setting equal content in each bin: "<<std::endl;
TH1D *hdata = new TH1D(“hdata”, “hdata”, 8, gl_bins);
for(int i=1; i<=hdata->GetNbinsX(); i++) hdata->SetBinContent(i, 10);
TH1D check = (TH1D )hdata->Clone(“check”);
for(int i=1; i<=check->GetNbinsX(); i++)
std::cout<<"Bin “<<i<<” has content "<GetBinContent(i)<<std::endl;
std::cout<<"Now make a RooDataHist and plot it"<<std::endl;
RooDataHist Data (“Data”,“Data”, gl, hdata);
RooPlot *frameData = gl.frame();
Data.plotOn(frameData, LineColor(kRed), LineStyle(kSolid) );
frameData->Draw();
std::cout<< “Now make a TH1 from the RooDataHist and inspect bin contents”<<std::endl;
TH1 *Data_b = (TH1 *) Data.createHistogram(“Data_b”, gl, Binning(glbins));
for(int i=1; i<=Data_b->GetNbinsX(); i++)
std::cout<<"from Data_b histo, bin “<<i<<” has content "<<Data_b->GetBinContent(i)<<std::endl;
}