Re: Cannot set log scale

From: Erkcan Ozcan <eo_at_hep.ucl.ac.uk>
Date: Tue, 8 Jul 2008 18:05:10 +0200


Hi again,

Sorry for the red herring. I have identified the problem: it was due to a piece of code that was scaling the y-axis range in order to fit various histograms drawn on the same pad.

Apologies for spamming.

Cheers,
e.

On 8 Jul 2008, at 16:43, Olivier Couet wrote:

> Hi,
>
> Can you send a small running macro reproducing your problem ?
>
> Cheers, O.Couet
>
> -----Original Message-----
> From: owner-roottalk_at_root.cern.ch [mailto:owner-roottalk_at_root.cern.ch]
> On Behalf Of Erkcan Ozcan
> Sent: Tuesday, July 08, 2008 4:36 PM
> To: roottalk_at_root.cern.ch
> Subject: [ROOT] Cannot set log scale
>
> Hi,
>
> I have a macro to read some 1D histograms from a file and draw them.
> If I do gPad->SetLogy() before drawing, the histograms are nicely
> plotted in the log scale. However if I draw the histograms first and
> then try to switch to log scale (either by issuing gPad->SetLogy() or
> simply by right clicking the TPad and choosing log scale in the menu),
> I get the error:
>
> Error in <THistPainter::PaintInit>: log scale requested with zero or
> negative argument (0.000000)
>
> To overcome this problem I implemented a function (attached below) to
> loop through all the 1D histos on the gPad and SetMinimum() for all of
> them before calling gPad->SetLogy().
>
> While this solves my problem, I still find it unintuitive to go
> through all this. While protection against negative arguments makes
> sense, bins with zero content are encountered quite often, so I am not
> sure if the current behavior is really desired for them.
>
> My question: 1-Is there a gStyle kind of switch which turns off this
> error? (I am using ROOT 5.18/00.) 2-If not, could it be implemented in
> a future release of ROOT?
>
> Thanks,
>
> Erkcan
>
>
> void PadToLogScale() {
>
> if ( gROOT->GetListOfCanvases()->GetEntries() == 0 ) return;
> if ( gPad->GetLogy() ) return;
>
> TPad *oldpad = gPad;
>
> // Now loop through histos and find the extrema
> TList *glist = oldpad->GetListOfPrimitives();
> for (int i=0; i<glist->GetEntries(); ++i) {
> TObject *obj = glist->At(i);
> if ( obj->InheritsFrom("TH1") ) {
>
> // If there is a 2D histogram, don't do anything.
> if ( obj->InheritsFrom("TH2") ) return;
>
> TH1 *histo = (TH1*)obj;
> histo->SetMinimum();
>
> }
> }
>
> gPad->SetLogy();
> gPad->Modified();
>
> }
>
>
> --
>
> In case they are not written explicitly, please be aware that my
> greetings and farewell are inherently implied in this email.
>
> V. Erkcan Ozcan
> Research Fellow
> University College London
> Dept. of Physics & Astronomy
>

-- 

In case they are not written explicitly, please be aware that my  
greetings and farewell are inherently implied in this email.

V. Erkcan Ozcan
Research Fellow
University College London
Dept. of Physics & Astronomy
Received on Tue Jul 08 2008 - 18:05:22 CEST

This archive was generated by hypermail 2.2.0 : Tue Jul 08 2008 - 23:50:02 CEST