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 & AstronomyReceived on Tue Jul 08 2008 - 16:35:51 CEST
This archive was generated by hypermail 2.2.0 : Tue Jul 08 2008 - 17:50:02 CEST