Can't call TH1D::GetEntry(i)

Hi all,

I am reading from a file containing 1D histograms, there are no branches, leafs or something else ; only TH1D in root file. When I try GetEntries() it gives the number correctly but when I try to iterate through via ;

     test = (TH1D*)f->Get(Form("test"));  
     for(int i=1;i<sizeof(test.GetEntries());i++){  cout<<test.GetEntry(i)<<endl; }

I get ;

Error: Can't call TH1D::GetEntry(i) in current scope filename.C:linenumber:
Possible candidates are...
(in TH1D)
(in TH1)
(class G__CINT_ENDL)40981296
*** Interpreter error recovered ***

Obviously I am doing something wrong here. Any ideas ?

Thanks

And where did you find the “GetEntry” method for a TH1D :question: :open_mouth:
:bulb: Perhaps you should read the “ROOT User’s Guide -> Histograms” chapter :exclamation: :-k
Also maybe you should also read what the “sizeof” keyword does.

[quote=“Wile E. Coyote”]And where did you find the “GetEntry” method for a TH1D :question: :open_mouth:
:bulb: Perhaps you should read the “ROOT User’s Guide -> Histograms” chapter :exclamation: :-k
Also maybe you should also read what the “sizeof” keyword does.[/quote]

I didn’t find it maybe that’s why I might be asking ? :slight_smile: I need to read entries of a 1D histogram.

sizeof() means nothing there since it will return the same output of GetEntries() that’s right. I just sent a snippet.

Thank you for the references.

On the other hand, I would appreciate an answer. :smiley:

[quote=“y33t”][quote=“Wile E. Coyote”]And where did you find the “GetEntry” method for a TH1D :question: :open_mouth:
:bulb: Perhaps you should read the “ROOT User’s Guide -> Histograms” chapter :exclamation: :-k
Also maybe you should also read what the “sizeof” keyword does.[/quote]

I didn’t find it maybe that’s why I might be asking ? :slight_smile: I need to read entries of a 1D histogram.

sizeof() means nothing there since it will return the same output of GetEntries() that’s right. I just sent a snippet.

Thank you for the references.

On the other hand, I would appreciate an answer. :smiley:[/quote]

See root.cern.ch/root/html/TH1F.html … BinContent :laughing:

This doesn’t seem to properly solve the problem as well since I can not access each event individually.

How to GetEntry(i) of a TH1D ?

ROOT Primer -> ROOT Basics -> Histograms in ROOT
ROOT Primer -> Histograms
ROOT User’s Guide -> Histograms
TH1

[quote=“Wile E. Coyote”]ROOT Primer -> ROOT Basics -> Histograms in ROOT
ROOT Primer -> Histograms
ROOT User’s Guide -> Histograms
TH1[/quote]

Thank you for the pointers. However, I can read the bins but I still can’t get the actual entries.

Wile gave you all the details I think. What are you doing exactly ?

For those trying to help: y33t seems to be under the impression that filling a histogram is a reversible operation.

For y33t: filling a histogram is a “lossy” operation. Once you do h.Fill(x), a single value corresponding to the correct bin is incremented by 1, and the exact value of x is not saved. This is how you can have a million entries in a histogram without the histogram taking up a million bytes in memory. Imagine it’s like you have all the values on pieces of paper in a pile, and you manually put checkmarks in boxes on a blackboard corresponding to the bins. After reading each piece of paper for the value, you put a checkmark in the appropriate box, but then you throw away (or recycle) the piece of paper. Those individual values are gone unless you save them somewhere else - the histogram doesn’t save them for you.

If you need to save every single value (and their order), you should use a TNtuple or a TTree. These objects have a GetEntry method that allows you to retrieve & loop over each specific value.

Jean-François