# RHist Underflow, Overflow and RHistStatBox

**URL:** <https://root-forum.cern.ch/t/rhist-underflow-overflow-and-rhiststatbox/52394>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [November 16, 2022, 1:47pm UTC](https://root-forum.cern.ch/t/rhist-underflow-overflow-and-rhiststatbox/52394 "2022-11-16T13:47:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrunoOliveira](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/94ad74/32.png) [@BrunoOliveira](https://root-forum.cern.ch/u/BrunoOliveira)\
**Post date:** [November 16, 2022, 1:47pm UTC](https://root-forum.cern.ch/t/rhist-underflow-overflow-and-rhiststatbox/52394/1 "2022-11-16T13:47:54Z")

</div>

* * *

_ROOT Version:_ 6.26/06 (`pacman -S root`)  
_Platform:_ Arch Linux  
_Compiler:_ gcc

* * *

Hello,

I’m trying to get the number of entries in the under and overflow bins of my RHist (RH1F in particular).

Ideally, I would like to replicate the THIF’s statbox using RHist1StatBox , but thus far I haven’t discovered how to change its contents.  
Additionally, the default statistics don’t look correct, for example in the output of rh1\_large.cxx (as a new user I can’t post a link, but it’s included in the default tutorials under rcanvas/) shown below.

 ![Screenshot from 2022-11-16 12-25-39](https://root-forum.cern.ch/uploads/default/original/3X/b/1/b11b5218b06498c0f6eb8d92eaec248c414eb101.png)

As an alternative, I’ve tried using GetBinContent, but found no documentation on how to extract the contents of the under and overflow bins.

Best regards,  
Bruno Oliveira

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [November 16, 2022, 1:53pm UTC](https://root-forum.cern.ch/t/rhist-underflow-overflow-and-rhiststatbox/52394/2 "2022-11-16T13:53:56Z")

</div>

You’re right. Maybe @linev can take a look?

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [November 17, 2022, 7:26am UTC](https://root-forum.cern.ch/t/rhist-underflow-overflow-and-rhiststatbox/52394/3 "2022-11-17T07:26:44Z")

</div>

Hi Bruno,

Not all methods for new `RHist` classes are implemented yet.

As you can see, on the client side (JavaScript) stats box is not working correctly.

Idea was that C++ provides methods to fill stat box content for the `RHist` - including overflow/underflow bins content (if any). But it is rather question to @Axel - when and how this development will be continued.

For the moment it is not possible to add custom content to `RHistStatBox`.

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [November 17, 2022, 7:35am UTC](https://root-forum.cern.ch/t/rhist-underflow-overflow-and-rhiststatbox/52394/4 "2022-11-17T07:35:59Z")

</div>

Just for clarification - dummy content like:

```auto
Entries = 1
Mean = 2
Std dev = 3

```

Filled on C++ side where stats box has direct access to histogram content.

Unfortunately there was no real implementation provided yet.

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [November 17, 2022, 7:48am UTC](https://root-forum.cern.ch/t/rhist-underflow-overflow-and-rhiststatbox/52394/5 "2022-11-17T07:48:19Z")

</div>

And finally.

Of course, you can create derived class from `RHist1StatBox` class and provide your own  
implementation of `FillStatistic` method like here:

> <https://github.com/root-project/root/blob/master/hist/histdrawv7/src/RHistStatBox.cxx#L40>

But of course, this should be done directly by ROOT.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [November 17, 2022, 9:35am UTC](https://root-forum.cern.ch/t/rhist-underflow-overflow-and-rhiststatbox/52394/6 "2022-11-17T09:35:37Z")

</div>

Whoaa don’t use `Experimental::RHist` for anything by experimentation 🙂 I’ll try to address the issue you mention here in 2023, but for now we don’t have the cycles to make progress here.

---

<div class="post-metadata">

**Author:** ![BrunoOliveira](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/94ad74/32.png) [@BrunoOliveira](https://root-forum.cern.ch/u/BrunoOliveira)\
**Post date:** [November 17, 2022, 10:05am UTC](https://root-forum.cern.ch/t/rhist-underflow-overflow-and-rhiststatbox/52394/7 "2022-11-17T10:05:20Z")

</div>

Hello Sergey and Axel,

Thank you for the rapid and clarifying response.

Following your suggestion, and since `RHist1StatBox` is marked as `final`, I’ve created a class derived from `RHistStatBox<1>` and implemented a `FillStatistic` method that fulfills my needs.  
Though I’m sure this is neither the best solution nor execution, I leave my code below for anyone who stumbles upon this question.

```auto
class BHist1StatBox final : public ROOT::Experimental::RHistStatBox<1> {
 protected:
    void FillStatistic(unsigned, const ROOT::Experimental::RFrame::RUserRanges &,
                       std::vector<std::string> &) const override;

 public:
    template <class HIST>
    BHist1StatBox(const std::shared_ptr<HIST> &hist, const std::string &title = "") : RHistStatBox<1>(hist, title) {}
};

void BHist1StatBox::FillStatistic(unsigned mask, const ROOT::Experimental::RFrame::RUserRanges &, std::vector<std::string> &lines) const
{
    int entries{0};
    double mean{0.}, mean_of_square{0.};

    for (int binidx = 1; binidx <= GetHist()->GetNBinsNoOver(); binidx++) {
        entries += GetHist()->GetBinContentAsDouble(binidx);
        mean += GetHist()->GetBinContentAsDouble(binidx) * GetHist()->GetBinCenter(binidx)[0];
        mean_of_square += GetHist()->GetBinContentAsDouble(binidx) * std::pow(GetHist()->GetBinCenter(binidx)[0], 2);
    }

    mean /= entries;
    mean_of_square /= entries;

    if (mask & kShowEntries) lines.emplace_back("Entries = " + std::to_string(entries));

    if (mask & kShowMean) lines.emplace_back("Mean = " + std::to_string(mean));

    if (mask & kShowDev)
        lines.emplace_back("Std dev = " + std::to_string(std::sqrt(mean_of_square - std::pow(mean, 2))));

    if (mask) {
        lines.emplace_back("Underflow = " + std::to_string(GetHist()->GetBinContentAsDouble(-1)));
        lines.emplace_back("Overflow = " + std::to_string(GetHist()->GetBinContentAsDouble(-2)));
    }
}

```

I admit I may have jumped the gun a bit too early on RHist.  
Nevertheless, as a someone with little experience in both C++ and ROOT, namely a year of working with ROOT6, I’m finding the new v7 interfaces easier to work with, will therefore continue using them for now.

Best regards,  
Bruno

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [November 17, 2022, 10:31am UTC](https://root-forum.cern.ch/t/rhist-underflow-overflow-and-rhiststatbox/52394/8 "2022-11-17T10:31:17Z")

</div>

> I’m finding the new v7 interfaces easier to work with

Ha, interesting. That’s very useful feedback, thanks.
