RHist Underflow, Overflow and RHistStatBox


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.

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

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

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

Just for clarification - dummy content like:

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.

And finally.

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

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

Whoaa don’t use Experimental::RHist for anything by experimentation :slight_smile: 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.

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.

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

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

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

1 Like