[ROOT] gROOT->FindObject in TH*::Profile* and TH*::Project*

From: Thomas Bretz (tbretz@astro.uni-wuerzburg.de)
Date: Thu Dec 16 2004 - 18:11:34 MET


Dear rooters,

having a possibility to update an existing profile histogram or a 
projection is a good idea, but finding the already existing histogram 
via gROOT->FindObject in my opinion is not a good idea.

The reason in very simple: gROOT->FindObject searches first everything 
else (eg. canvases, current directory, etc) So the probability is high 
that for example a canvas with the same name is found - which results in 
strange behaviour.

I guess the typical application is that I draw a profile into a pad. 
Somewhere (eg in a Paint-funtion) I change directory (cd()) into this 
pad and call Profile*() to update the existing profile. In this case it 
would be much more convinient if FindObject would first search in the 
current pad. Because I assume that this is a dangerous change - because 
other parts of the code may rely on the order of searches in FindObject 
I suggest to replace gROOT->FindObject by:
TObject *obj = gPad ? gPad->FindObject(pname) : 0;
if (!obj)
    gROOT->FindObject(pname);

This in: TH2::ProfileX, TH2::ProfileY, TH2::ProjectX, TH2::ProjectY, 
TH3::ProjectionZ, TH3::Project3D

Best regards,
Thomas.



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:10 MET