RooDataHist and logarithmic binning

Dear experts,
I’ve been trying to import a histogram with a logarithmic binning using RooDataHist, and I’m having a hard time correctly representing the bin content.
The histogram spans from 1e-8 to 1e2, and I used the following function to implement a log binning.

void BinLogX(TH1*h)
{

   TAxis *axis = h->GetXaxis();
   int bins = axis->GetNbins();

   Axis_t from = axis->GetXmin();
   Axis_t to = axis->GetXmax();
   Axis_t width = (to - from) / bins;
   Axis_t *new_bins = new Axis_t[bins + 1];

   for (int i = 0; i <= bins; i++) {
     new_bins[i] = TMath::Power(10, from + i * width);
   }
   axis->Set(bins, new_bins);
   delete new_bins;
}
TH1F *h_deltat = new TH1F("h_deltat","h_deltat",n_bins_logdt,-8,2);
  BinLogX(h_deltat);

When I do

  RooRealVar x("x", "x", 1e-8, 100);
RooDataHist data("data","data",x,Import(*h_deltat));

The values of the bins are completely off. I found out online that RooDataHist normalises the bin weight to its width, so to overcome this I tried

for(int ii=1;ii<=n_bins_logdt;ii++) {
    int aa=h_deltat->GetBinContent(ii);
    double bb=h_deltat->GetBinWidth(ii);
    h_deltat->SetBinContent(ii,aa/bb);
}
RooDataHist data("data","data",x,Import(*h_deltat,kTRUE),Weight(1.));

This last option produces something similar to the innitial histogram, but there’s a general shift on the x axis of a few bins that I cannot explain.
I tried other options, such as filling the RooDataHist manually

  for(int ii=1;ii<=n_bins_logdt;ii++) {

    RooRealVar bin_edge0("bin_edge0","bin_edge0",h_deltat->GetBinLowEdge(ii));
    RooRealVar bin_edge1("bin_edge1","bin_edge1",h_deltat->GetBinLowEdge(ii)+h_deltat->GetBinWidth(ii));
    RooArgSet *bin_edges = new RooArgSet(bin_edge0,bin_edge1);

data.set(*bin_edges,(double)(h_deltat->GetBinContent(ii)),TMath::Sqrt(h_deltat->GetBinContent(ii)))
}

But without success.
Can someone help?
Thank you!
Alex

Hi Alex,

I’d ask @moneta and @StephanH to give a hand with this one.

It might take some time since they are busy / off at the moment.

1 Like

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