RE: reading histogram contents

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Fri, 29 Apr 2005 17:00:47 -0500


Hi,

If you do not like C style cast, you can also use:

       TFile *f = new TFile("histos4.root");
       TH1 *haccpt; f->GetObject("haccpt",haccpt);

The pointer haccpt would then have a non zero value if and only if there an object named 'haccpt' in the file and this object is of type inheriting from TH1.

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch] On Behalf Of Rene Brun
Sent: Friday, April 29, 2005 2:26 PM
To: Lalith Perera
Cc: roottalk_at_pcroot.cern.ch
Subject: Re: [ROOT] reading histogram contents

Hi,

After the line

       TFile *f = new TFile("histos4.root"); add this line

       TH1 *haccpt = (TH1*)f->Get("haccpt");

At the normal ROOT prompt, the histogram named "haccpt" is automatically read from the current directory. This is not the case when executing a script.

Rene Brun

On Fri, 29 Apr 2005, Lalith
Perera wrote:

>
> Hi,
>
> I am running the following script to read the contents of a
> histogram from a file. But it reads them always as zeros, althogh
> histogram is not empty. I can plot it from the script, which shows the
> filled histogram. Also, When I type the commad interactively
> (ie, like:
>
> root[1] bc= (Float_t)haccpt->GetBinContent(2,0);
> root[2] std::cout << bc << endl; )
>
> it shows the actual value in that bin. Am I missing anything in the
> script?
>
> Thanks
> Lalith
>
> TFile *f = new TFile("histos4.root");
> f->ls();
>
> Int_t j=0;
> Float_t bc;
>
> for(Int_t i=0;i<80;i++)
> {
> bc= (Float_t)haccpt->GetBinContent(i,j);
> std::cout<< i<< " j " << j << " " << bc << endl;
> }
>
> haccpt2->Draw();
>
>
>
>
>
Received on Sat Apr 30 2005 - 00:08:39 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:07 MET