Logo ROOT  
Reference Guide
df011_ROOTDataSource.C File Reference

Detailed Description

View in nbviewer Open in SWAN This tutorial illustrates how use the RDataFrame in combination with a RDataSource.

In this case we use a RRootDS. This data source allows to read a ROOT dataset from a RDataFrame in a different way, not based on the regular RDataFrame code. This allows to perform all sorts of consistency checks and illustrate the usage of the RDataSource in a didactic context.

void fill_tree(const char *treeName, const char *fileName)
{
auto i = 0.;
d.Define("b1", [&i]() { return i++; }).Snapshot(treeName, fileName);
}
{
auto fileName = "df011_ROOTDataSources.root";
auto treeName = "myTree";
fill_tree(treeName, fileName);
auto d_s = ROOT::RDF::MakeRootDataFrame(treeName, fileName);
/// Now we have a regular RDataFrame: the ingestion of data is delegated to
/// the RDataSource. At this point everything works as before.
auto h_s = d_s.Define("x", "1./(b1 + 1.)").Histo1D({"h_s", "h_s", 128, 0, .6}, "x");
/// Now we redo the same with a RDF and we draw the two histograms
ROOT::RDataFrame d(treeName, fileName);
auto h = d.Define("x", "1./(b1 + 1.)").Histo1D({"h", "h", 128, 0, .6}, "x");
auto c_s = new TCanvas();
c_s->SetLogy();
h_s->DrawClone();
auto c = new TCanvas();
c->SetLogy();
h->DrawClone();
return 0;
}
#define d(i)
Definition: RSha256.hxx:102
#define c(i)
Definition: RSha256.hxx:101
#define h(i)
Definition: RSha256.hxx:106
RDataSource defines an API that RDataFrame can use to read arbitrary data formats.
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
Definition: RDataFrame.hxx:42
The Canvas class.
Definition: TCanvas.h:31
RDataFrame MakeRootDataFrame(std::string_view treeName, std::string_view fileNameGlob)
Definition: RRootDS.cxx:163
Date
September 2017
Author
Danilo Piparo

Definition in file df011_ROOTDataSource.C.