"log scale requested with a negative argument"

Hi,

I have a TH1F with non-negative bin contents and non-integer weights which plots fine in log-y mode. When I attempt to do the same via RooDataHist, I am getting the following error:

Could somebody please have a look at the attached macro and tell me how to fix this?

With many thanks,

–Christos

[code]#ifndef CINT
#include “RooGlobalFunc.h”
#endif
#include “RooRealVar.h”
#include “RooDataSet.h”
#include “RooGaussian.h”
#include “RooBreitWigner.h”
#include “RooAddPdf.h”
#include “TCanvas.h”
#include “RooDataHist.h”
#include “TAxis.h”
#include "RooPlot.h"
using namespace RooFit ;

#include “TH1F.h”
#include “TRandom.h”

void test()
{
TH1::SetDefaultSumw2();
float XMIN = 0; float XMAX = 10;
TH1F * h = new TH1F(“h”, “h”, 100, XMIN, XMAX);
for(int i = 0; i != 1000; ++i)
h->Fill(gRandom->Gaus(5, 1), gRandom->Uniform(0, 1));

TCanvas * c11 = new TCanvas();
c11->SetLogy();
h->Draw();

RooRealVar x(“x”, “x”, XMIN, XMAX);
RooDataHist h2(“h2”, “h2”, x, Import(*h));
RooPlot * xfr = x.frame(Title(“h2”));
h2.plotOn(xfr, DataError(RooAbsData::SumW2));

TCanvas * c22 = new TCanvas();
c22->SetLogy();
xfr->Draw();

}
[/code]

I am not in charge of RooDataHist and I do not know what it does exactly.
When you plot a normal histogram it can be plotted in log scale as soon as the maximum of the histogram is positive. If the minimum of the histogram is negative or null them the histogram is plotted from 0.001*max to max (max should be >0). If max<0 you get an error message.

Dear Olivier,

Thanks for your answer.

It appears that RooFit is not that forgiving about empty bins. I believe this is related to the way it calculates the bin errors. By introducing a simple hack (ie. setting the bin error to zero), I have manged to reproduce the “plain ROOT” (i.e expected) behavior (see below).

I would imagine there is a simple switch that instructs RooFit to not sweat over zero-content bins when plotting in logY. Is there a better mailing list that we can use to get in touch with the experts?

Best,

–Christos

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooBreitWigner.h"
#include "RooAddPdf.h"
#include "TCanvas.h"
#include "RooDataHist.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit ;

#include "TH1F.h"
#include "TRandom.h"

#define fixme 1

void test()
{
  TH1::SetDefaultSumw2();
  float XMIN = 0; float XMAX = 10;
  const int Nbins = 100;
  TH1F * h = new TH1F("h", "h", Nbins, XMIN, XMAX);
  for(int i = 0; i != 1000; ++i)
    h->Fill(gRandom->Gaus(5, 1), gRandom->Uniform(0, 1));

#if fixme
  float epsilon = 1; 
  for(int i = 1; i <= Nbins; ++i)
    if(h->GetBinContent(i) < epsilon)
      h->SetBinError(i, 0);
#endif

  TCanvas * c11 = new TCanvas();
  c11->SetLogy();
  h->Draw();
  RooRealVar x("x", "x", XMIN, XMAX);
  RooDataHist h2("h2", "h2", x, Import(*h));
  RooPlot * xfr = x.frame(Title("h2"));
  h2.plotOn(xfr, DataError(RooAbsData::SumW2));

  TCanvas * c22 = new TCanvas();
  c22->SetLogy();
  xfr->Draw();

}