Re: Basic question on how to read an histo, an ntuple etc. from a file

Rene Brun (Rene.Brun@cern.ch)
Wed, 21 May 1997 09:28:08 +0200


Luca Sfarzo wrote:
>
> Hello,
>
> I've a basic question:
>
> after having converted an hbook file via the h2root.exe utility I want
> to Draw the content of such file (it is made up of TH1Fs and TProfiles)
> on the screen.
> I've searched a bit in the tutorial but I still haven't understood well
> how to find objects in a file (how can I know the content of an unknown
> file??) and how to plot it.
> Is there something useful in the tuotorial or elsewhere?

We are giving several examples in the tutorials. See for example:
http://root.cern.ch/root/html/examples/hsimple.C.html
This example creates a file with histograms, profiles and a Tree.
Many other examples read objects from this file:
http://root.cern.ch/root/html/examples/h1draw.C.html
http://root.cern.ch/root/html/examples/ntuple1.C.html

A summary from these examples. If you have a file (say hsimple.root).
TFile *f = new TFile("hsimple.root"); // connect file in read mode
f->ls(); // list contents of this file

You can use the Root browser to browse this file:
TBrowser b;
and click on the item "Root files". Select the file you want
to browse. This will show icons corresponding to the objects
in the file. If you double click on an histogram icon, this will
automatically display the histogram.
If you click with the right mouse button on the histogram icon,
you will get a context menu where you can choose various actions,
like fits, etc on this histogram.

In a macro, you can get an object from a file in memory.
Example, if you have an histogram (TH1F) on a file with the key "hpx"
you can get this histogram in memory with:
TH1F *hpx = (TH1F*)f->Get("hpx")

Rene Brun