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 ?
[quote=“Wile E. Coyote”]And where did you find the “GetEntry” method for a TH1D Perhaps you should read the “ROOT User’s Guide -> Histograms” chapter
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 ? 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.
[quote=“y33t”][quote=“Wile E. Coyote”]And where did you find the “GetEntry” method for a TH1D Perhaps you should read the “ROOT User’s Guide -> Histograms” chapter
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 ? 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. [/quote]
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.