Is it possible to get individual entries out of a TH1 object?

Given a histogram that is filled with some values, i.e.

TH1F *hist = new TH1F("hist","Histogram",100,0,100);
hist->Fill(a);
hist->Fill(b);
hist->Fill(c);

where a,b,c are some random values.

Is it possible to extract a,b,c out of hist?

If more than one filled value went to the same bin, this info is lost. You can only retrieve the current “total” contents of each bin, with GetBinContent.

2 Likes

By the way, just to be clear: Fill(a) (without a weight) adds 1 to the count of contents of the x-axis bin that contains the value “a” within its upper and lower edges. Therefore, even when filling just one entry, the actual value (a) is already lost unless it happens to be the same as the bin centre or one edge, since you can only retrieve the bin centre and it’s lower/upper edges (GetBinCenter, GetBinLowEdge, GetBinUpEdge, resp.); you would use GetBinContent to know which bins have more than 0 entries and then GetBinCenter to know the corresponding x value.

1 Like

Thank you for the response!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.