Translated in Root format, this gives:
"you have a directory containing objects, including histograms 1-d,
2-d, etc
"you want to get say the first object deriving from TH1"
If the answer is yes, you can use the following loop:
TIter next(gDirectory->GetList());
TObject *obj;
while ((obj = next())) {
if (obj->InheritsFrom("TH1")) {
return obj; // have found an histogram, return the pointer
}
}
Rene Brun
Damir Buskulic wrote:
>
> Hi all,
>
> Probably a stupid question that has been answered many times but I can't
> seem to find it in roottalk
>
> Suppose I have an histogram in a pad, without knowing it's name or
> having a pointer to it. How can I get a pointer to it ? I tried various
> things such as :
>
> * gPad->GetListOfPrimitives()->FindObject(...) need the name or a
> pointer to the object, I don't have it
> * loop on the list of primitives and try to compare with the
> obj.Class()->Compare(known_histo) but all objects are put in the list as
> TObjects, so one doesn't know if they are TH1F's or not...
>
> All in all, one always needs the name or pointer to the histo. Looping
> on the list of histograms found in gDirectory is not very handy,
> especially if one has histograms outside a directory.
> Well, it should be simple...
>
> Cheers
>
> Damir
>
> --
> =====================================================================
> | Damir Buskulic | Universite de Savoie/LAPP |
> | | Chemin de Bellevue, B.P. 110 |
> | Tel : +33 (0)450091600 | F-74941 Annecy-le-Vieux Cedex |
> | e-mail: buskulic@lapp.in2p3.fr | FRANCE |
> =====================================================================
> mailto:buskulic@lapp.in2p3.fr