Mean and MeanError of a variable bin size TH1

Dear ROOT users,

I’ve an histogram with a variable bin size (given by detector time resolution) and I would like to compute the mean (the equivalent for GetMean()) and the uncertainty on the mean (the equivalent for GetMeanError()).
I’m wondering if there is a way to tell ROOT about the variable bin size, because, as far as I could see, it is not accounted for in the GetMean() and GetMeanError() methods.

Thank you in advance

Well, the “precision” of results is somehow limited by bins’ widths …

#if 0 /* 0 or 1 */
  TH1D *h = new TH1D("h", "h", 200, -10., 10.);
#else /* 0 or 1 */
  Double_t x[] = {-10., -6., -3., -1., 0., 5., 10.};
  Int_t n = sizeof(x) / sizeof(Double_t) - 1;
  TH1D *h = new TH1D("h", "h", n, x);
#endif /* 0 or 1 */
  // h->Sumw2(kTRUE);
  h->FillRandom("gaus", 1000000);
  // h->Scale(1.0, "width");
  // h->Sumw2(kFALSE);
  h->Draw(); // note: it should be ... Mean = 0.0, RMS = Std Dev = 1.0
  std::cout << h->GetMean() << " : " << h->GetMeanError() << std::endl;

Hi Wile,
thank you for your reply.
Yes, of course, the “precision” of the result is limited by bins’ widths. We can actually “deforme” a distribution changing the bin width.
What I meant was more like: how to take into account the bin width when computing the mean value (and the mean error). It seems to me (but I could be wrong) that in the GetMean() method what is done is a weighted mean of the bin centres, where the weights are the bins content (and not the bin content * the bin width).
Thank you

Maybe you want to play with (see my previous post again): h->Scale(1.0, "width");

Yep! Thank you Wile!

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