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

Detailed Description

Filling RHist using RDataFrame.

#include <ROOT/RHist.hxx>
#include <TCanvas.h>
#include <TH1.h>
{
// Create a data frame with 100 rows.
// Define a new column that will be used to fill the histogram.
auto dfX = df.Define("x",
[](ULong64_t e) {
double v = std::exp(0.1 * e);
return std::fmod(v, 20.0);
},
{"rdfentry_"});
// Create the histogram with 40 bins from 0.0 to 20.0.
auto hist = dfX.Hist(40, {0.0, 20.0}, "x");
// Print (some of) the global statistics.
std::cout << "entries = " << hist->GetNEntries();
std::cout << ", mean = " << hist->ComputeMean();
std::cout << ", stddev = " << hist->ComputeStdDev();
std::cout << "\n";
// Convert the histogram to TH1D.
// Draw the converted TH1D.
auto *c = new TCanvas("c", "", 10, 10, 900, 500);
h1->DrawCopy("", "x");
}
#define c(i)
Definition RSha256.hxx:101
#define e(i)
Definition RSha256.hxx:103
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
Definition RtypesCore.h:84
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
The Canvas class.
Definition TCanvas.h:23
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
Definition TH1.cxx:3141
TH1F * h1
Definition legend1.C:5
std::unique_ptr< TH1D > ConvertToTH1D(const RHistEngine< double > &engine)
Convert a one-dimensional histogram to TH1D.
entries = 100, mean = 8.2544, stddev = 5.95187
Date
February 2026
Author
The ROOT Team

Definition in file hist101_RDataFrame_Hist.C.