Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tutorials/hist/histv7/hist001_RHist_basics.C
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void hist001_RHist_basics()
ROOT::Experimental::RRegularAxis axis(40, {0.0, 20.0});

// Create a first histogram and fill with random values.
ROOT::Experimental::RHist<int> hist1({axis});
ROOT::Experimental::RHist<int> hist1(axis);

// Create a normal distribution with mean 5.0 and stddev 2.0.
std::mt19937 gen;
Expand All @@ -75,7 +75,7 @@ void hist001_RHist_basics()
std::cout << "\n";

// Create a second histogram and fill with random values of a different distribution.
ROOT::Experimental::RHist<int> hist2({axis});
ROOT::Experimental::RHist<int> hist2(axis);
std::normal_distribution normal2(13.0, 4.0);
for (std::size_t i = 0; i < 1500; i++) {
hist2.Fill(normal2(gen));
Expand All @@ -85,7 +85,7 @@ void hist001_RHist_basics()
std::cout << "\n";

// Create a third, merged histogram from the two previous two.
ROOT::Experimental::RHist<int> hist3({axis});
ROOT::Experimental::RHist<int> hist3(axis);
hist3.Add(hist1);
hist3.Add(hist2);
std::cout << "hist3 with expected entries = " << (hist1.GetNEntries() + hist2.GetNEntries()) << "\n";
Expand Down
6 changes: 3 additions & 3 deletions tutorials/hist/histv7/hist002_RHist_weighted.C
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ void hist002_RHist_weighted()
ROOT::Experimental::RRegularAxis axis(40, {0.0, 20.0});

// Create two histograms, one of which will be filled with weighted entries.
ROOT::Experimental::RHist<double> hist1({axis});
ROOT::Experimental::RHist<double> hist2({axis});
ROOT::Experimental::RHist<double> hist1(axis);
ROOT::Experimental::RHist<double> hist2(axis);

// Create a normal distribution with mean 10.0 and stddev 5.0.
std::mt19937 gen;
Expand All @@ -86,7 +86,7 @@ void hist002_RHist_weighted()

// Create and fill a third histogram with the special RBinWithError bin content type.
// In addition to the sum of weights, it tracks the sum of weights squared to compute the bin errors.
ROOT::Experimental::RHist<ROOT::Experimental::RBinWithError> hist3({axis});
ROOT::Experimental::RHist<ROOT::Experimental::RBinWithError> hist3(axis);
for (std::size_t i = 0; i < 25000; i++) {
double value = normal(gen);
double weight = 0.2 + 0.008 * value * value;
Expand Down
64 changes: 64 additions & 0 deletions tutorials/hist/histv7/hist003_RHist_multi.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// \file
/// \ingroup tutorial_histv7
///
/// Multidimensional RHist with dynamic axis types.
///
/// \macro_code
/// \macro_output
///
/// \date January 2026
/// \author The ROOT Team

#include <ROOT/RBinIndex.hxx>
#include <ROOT/RHist.hxx>
#include <ROOT/RRegularAxis.hxx>
#include <ROOT/RVariableBinAxis.hxx>

#include <cmath>
#include <cstddef>
#include <iostream>
#include <random>
#include <vector>

void hist003_RHist_multi()
{
// Define the bin edges and variable bin axis for the eta dimension.
std::vector<double> etaEdges = {-5.0, -3.0, -2.4, -1.5, 0.0, 1.5, 2.4, 3.0, 5.0};
ROOT::Experimental::RVariableBinAxis etaAxis(etaEdges);

// Define the regular axis for the phi dimension (in radians), disabling under- and overflow bins.
static constexpr double Pi = 3.14159;
ROOT::Experimental::RRegularAxis phiAxis(20, {-Pi / 2, Pi / 2}, false);

// Define the logarithmic axis for the energy (in GeV).
ROOT::Experimental::RVariableBinAxis energyAxis({0, 1, 10, 100, 1000});

// Create the multidimensional histogram.
ROOT::Experimental::RHist<int> hist(etaAxis, phiAxis, energyAxis);

// Print some information about the histogram.
std::cout << "Created a histogram with " << hist.GetNDimensions() << " dimensions and " << hist.GetTotalNBins()
<< "\n";

// Generate angles and energies to fill the histogram.
std::mt19937 gen;
std::uniform_real_distribution dist(0.0, 1.0);
static constexpr double maxE = 1000;
for (std::size_t i = 0; i < 100000; i++) {
double delta = 2 * Pi * dist(gen);
double eta = -std::log(std::tan(delta / 2));
double phi = std::acos(2 * dist(gen) - 1) - Pi / 2;
double E = maxE * dist(gen);
hist.Fill(eta, phi, E);
}
std::cout << " ... filled with " << hist.GetNEntries() << " entries.\n\n";

// Get the content for specific bins:
std::cout << "eta in [1.5, 2.4), phi in [0, 0.157), E between 10 GeV and 100 GeV\n";
auto content = hist.GetBinContent(5, 10, 2);
std::cout << " content = " << content << "\n";

std::cout << "eta in [-1.5, 0), phi in [-0.785, -0.628), E between 1 GeV and 10 GeV\n";
content = hist.GetBinContent(3, 5, 1);
std::cout << " content = " << content << "\n";
}
1 change: 1 addition & 0 deletions tutorials/hist/histv7/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Examples demonstrating ROOT's histogram package.
|---|---|
| hist001_RHist_basics.C | Basics of RHist, including filling and adding them. |
| hist002_RHist_weighted.C | Weighted filling of RHist and RBinWithError bin content type. |
| hist003_RHist_multi.C | Multidimensional RHist with dynamic axis types. |
Loading