RE: Frequency in Histos

From: Olivier Couet <Olivier.Couet_at_cern.ch>
Date: Tue, 13 Apr 2010 11:44:53 +0200


Hi,  

If your main histogram isn't filled with weights equal to 1 then, as Jacques said, you should create one in parallel with the same binning but filled with weight equal to one. Which means you will have something like  

TH1F *h1 = new TH1F("h1", "h1", 10, 0, 10);

TH1F *h1p = new TH1F("h1p", "h1p", 10, 0, 10);  

Then the filling will be:  

h1->Fill(x,w);

h1p->Fill(x);  

then, when the filling is done:  

h1->GetBinContent(i);  

will gives you the bin content of the bin number i of the histogram h1.  

h1p->GetBinContent(i);  

will gives you the number of entries in the bin number i of the histogram h1.  

Olivier  

From: owner-roottalk_at_root.cern.ch [mailto:owner-roottalk_at_root.cern.ch] On Behalf Of xsatya
Sent: Tuesday, April 13, 2010 11:29 AM
To: Jacques Goldberg
Cc: roottalk; roottalk (Mailing list discussing all aspects of the ROOT system.)
Subject: Re: [ROOT] Frequency in Histos  

Hello,

Thanks for reply. Probably I couldn't get you. Here I am attaching a small macro with different histograms. Please check.

With regards,
S

On Tue, Apr 13, 2010 at 1:45 PM, Jacques Goldberg <Jacques.Goldberg_at_cern.ch> wrote:

If the weight of each entry is set to 1 (which is the default), the contents of a bin has the same value as the number of events. If you want weights different from 1, then just add a second histogram with weight set to 1. and use that one to get the numbers of entries in each bin.

There may be fancier solutions, but this one quickly gives the result.

Jacques

xsatya wrote:

Hi,

Is there any way to find the frequency of each bin of any Histos? (TH1F, TH2F). GetBinContent(bin) gives only the contenct value, but waht I want is no of Entries in that bin. Could you please let me know if any ways.

S
--



Research Student,
High Energy Physics, India.  

--



Research Student,
High Energy Physics, India. Received on Tue Apr 13 2010 - 11:44:58 CEST

This archive was generated by hypermail 2.2.0 : Tue Apr 13 2010 - 17:50:01 CEST