16 auto filename =
gROOT->GetTutorialDir() +
"/dataframe/df017_vecOpsHEP.root";
17 auto treename =
"myDataset";
21 void WithTTreeReader()
29 TH1F h(
"pt",
"pt", 16, 0, 4);
32 for (
auto i=0U;i < px.GetSize(); ++i) {
33 if (
E[i] > 100)
h.Fill(
sqrt(px[i]*px[i] + py[i]*py[i]));
41 RDF
f(treename, filename.Data());
42 auto CalcPt = [](doubles &px, doubles &py, doubles &
E) {
44 for (
auto i=0U;i < px.size(); ++i) {
46 v.emplace_back(
sqrt(px[i]*px[i] + py[i]*py[i]));
51 f.Define(
"pt", CalcPt, {
"px",
"py",
"E"})
52 .Histo1D<doubles>({
"pt",
"pt", 16, 0, 4},
"pt")->DrawCopy();
55 void WithRDataFrameVecOps()
57 RDF
f(treename, filename.Data());
58 auto CalcPt = [](doubles &px, doubles &py, doubles &
E) {
59 auto pt =
sqrt(px*px + py*py);
62 f.Define(
"good_pt", CalcPt, {
"px",
"py",
"E"})
63 .Histo1D<doubles>({
"pt",
"pt", 16, 0, 4},
"good_pt")->DrawCopy();
66 void WithRDataFrameVecOpsJit()
68 RDF
f(treename, filename.Data());
69 f.Define(
"good_pt",
"sqrt(px*px + py*py)[E>100]")
70 .Histo1D({
"pt",
"pt", 16, 0, 4},
"good_pt")->DrawCopy();
84 WithRDataFrameVecOps();
86 WithRDataFrameVecOpsJit();
TTreeReader is a simple, robust and fast interface to read values from a TTree, TChain or TNtuple...
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
1-D histogram with a float per channel (see TH1 documentation)}
A "std::vector"-like collection of values implementing handy operation to analyse them...
constexpr Double_t E()
Base of natural log: .
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees, CSV's and other data formats.
Extracts array data from a TTree.