Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist005_RHist_convert_TH1.C File Reference

Detailed Description

Conversion of RHist to TH1.

#include <ROOT/RHist.hxx>
#include <TCanvas.h>
#include <TH1.h>
#include <cstddef>
#include <random>
{
// Create a histogram and fill with random values.
ROOT::Experimental::RHist<int> hist(40, {0.0, 20.0});
// Create a normal distribution with mean 10.0 and stddev 4.0.
std::mt19937 gen;
std::normal_distribution normal(10.0, 4.0);
for (std::size_t i = 0; i < 1000; i++) {
hist.Fill(normal(gen));
}
// Convert the histogram to TH1I.
// Print (some of) the global statistics.
std::cout << "hist with expected mean = " << normal.mean() << "\n";
std::cout << "entries = " << h1->GetEntries();
std::cout << ", mean = " << h1->GetMean();
std::cout << ", stddev = " << h1->GetStdDev();
std::cout << "\n";
// Draw the converted TH1I.
auto *c = new TCanvas("c", "", 10, 10, 900, 500);
h1->DrawCopy("", "h1");
// All other known methods of TH1 are also available, such as fitting or statistical tests, but go beyond the scope
// of this tutorial.
}
#define c(i)
Definition RSha256.hxx:101
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
A histogram for aggregation of data along multiple dimensions.
Definition RHist.hxx:64
The Canvas class.
Definition TCanvas.h:23
virtual Double_t GetStdDev(Int_t axis=1) const
Returns the Standard Deviation (Sigma).
Definition TH1.cxx:7680
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
Definition TH1.cxx:7608
virtual Double_t GetEntries() const
Return the current number of entries.
Definition TH1.cxx:4438
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
Definition TH1.cxx:3121
TH1F * h1
Definition legend1.C:5
std::unique_ptr< TH1I > ConvertToTH1I(const RHistEngine< int > &engine)
Convert a one-dimensional histogram to TH1I.
hist with expected mean = 10
entries = 1000, mean = 9.97154, stddev = 3.97326
Date
February 2026
Author
The ROOT Team

Definition in file hist005_RHist_convert_TH1.C.