Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist101_RDataFrame_Hist.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_histv7
3///
4/// Filling RHist using RDataFrame.
5///
6/// \macro_code
7/// \macro_output
8/// \macro_image
9///
10/// \date February 2026
11/// \author The ROOT Team
12
13#include <ROOT/RDataFrame.hxx>
14#include <ROOT/RHist.hxx>
16#include <TCanvas.h>
17#include <TH1.h>
18
20{
21 // Create a data frame with 100 rows.
22 ROOT::RDataFrame df(100);
23
24 // Define a new column that will be used to fill the histogram.
25 auto dfX = df.Define("x",
26 [](ULong64_t e) {
27 double v = std::exp(0.1 * e);
28 return std::fmod(v, 20.0);
29 },
30 {"rdfentry_"});
31
32 // Create the histogram with 40 bins from 0.0 to 20.0.
33 auto hist = dfX.Hist(40, {0.0, 20.0}, "x");
34
35 // Print (some of) the global statistics.
36 std::cout << "entries = " << hist->GetNEntries();
37 std::cout << ", mean = " << hist->ComputeMean();
38 std::cout << ", stddev = " << hist->ComputeStdDev();
39 std::cout << "\n";
40
41 // Convert the histogram to TH1D.
43
44 // Draw the converted TH1D.
45 auto *c = new TCanvas("c", "", 10, 10, 900, 500);
46 h1->DrawCopy("", "x");
47}
#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.