RooPlot SetMaximum and SetLogy

I’m trying to plot a RooDataHist with a log-scale on the Y-axis and a specific Y-axis range. When I specify the range of the Y-axis and use SetLogy(), I get an error:

Error in THistPainter::PaintInit: Cannot set Y axis to log scale

Here’s a simplified version of my code:

#!/usr/bin/env python
from ROOT import *
ht=RooRealVar("ht","Scalar Sum of pT [GeV]",100,12000);
pseudoExp=TH1D("h0","h0",120,0,12000)

#Create a pseudo experiment from a flat distribution
r=TRandom3(0)
for bin in range(1,pseudoExp.GetNbinsX()+1):
    weight=r.PoissonD(1E5)
    pseudoExp.SetBinContent(bin,weight)
    pseudoExp.SetBinError(bin,sqrt(weight))

dh=RooDataHist("dh","Data Hist for HT",RooArgList(ht),pseudoExp)
c1 = TCanvas("c1","c1",1200,800);
c1.Divide(2,1);
c1.cd(1);
c1.GetPad(1).SetLogy()
htFrame = ht.frame(1500,4000);
htFrame.SetMinimum(0.1)
htFrame.SetMaximum(2E5)
dh.plotOn(htFrame)
htFrame.Draw()

There are two problems. The first is that, without using SetLogy(), the minimum and maximum are not set correctly. The second problem is that when I use SetLogy(), the error I showed above my code occurs.

Any help would be greatly appreciated. I know this works in C++, so I might just end up converting it. But I’d rather not have to rewrite the entire script.

I’m not familiar with RooFit, but it could be that your commands are properly written, but the canvas isn’t being updated. Try adding:

gPad.Modified()
gPad.Update()

Jean-François

Hello Jean-François,
I tried your suggestion, but unfortunately it did not fix the problem. However, I managed to discover a solution by plotting the data before setting the minimum and maximum, rather than after.

Thank you!

Brian Amadio