Skip to content

Commit 4699532

Browse files
committed
Add RDataFrameh1Analysis benchmark
1 parent 6633ca5 commit 4699532

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

root/tree/dataframe/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ if(rootbench-datafiles)
1010
DOWNLOAD_DATAFILES Run2012B_DoubleMuParked.root Run2012C_DoubleMuParked.root
1111
LABEL long
1212
LIBRARIES Core Hist Imt RIO Tree TreePlayer ROOTDataFrame ROOTVecOps Gpad Graf)
13+
14+
RB_ADD_GBENCHMARK(RDataFrameh1Analysis
15+
RDataFrameh1Analysis.cxx
16+
LABEL long
17+
DOWNLOAD_DATAFILES h1analysis.root
18+
LIBRARIES Core Hist Imt RIO Tree TreePlayer ROOTDataFrame ROOTVecOps)
1319
endif()
1420

1521
if(NUMPY_FOUND)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include <ROOT/RDataFrame.hxx>
2+
#include <ROOT/RVec.hxx>
3+
4+
#include <benchmark/benchmark.h>
5+
#include <rootbench/RBConfig.h>
6+
7+
auto Select = [](ROOT::RDataFrame &dataFrame) {
8+
using Farray_t = ROOT::VecOps::RVec<float>;
9+
using Iarray_t = ROOT::VecOps::RVec<int>;
10+
11+
auto ret = dataFrame.Filter("TMath::Abs(md0_d - 1.8646) < 0.04")
12+
.Filter("ptds_d > 2.5")
13+
.Filter("TMath::Abs(etads_d) < 1.5")
14+
.Filter([](int ik, int ipi, Iarray_t& nhitrp) { return nhitrp[ik - 1] * nhitrp[ipi - 1] > 1; },
15+
{"ik", "ipi", "nhitrp"})
16+
.Filter([](int ik, Farray_t& rstart, Farray_t& rend) { return rend[ik - 1] - rstart[ik - 1] > 22; },
17+
{"ik", "rstart", "rend"})
18+
.Filter([](int ipi, Farray_t& rstart, Farray_t& rend) { return rend[ipi - 1] - rstart[ipi - 1] > 22; },
19+
{"ipi", "rstart", "rend"})
20+
.Filter([](int ik, Farray_t& nlhk) { return nlhk[ik - 1] > 0.1; }, {"ik", "nlhk"})
21+
.Filter([](int ipi, Farray_t& nlhpi) { return nlhpi[ipi - 1] > 0.1; }, {"ipi", "nlhpi"})
22+
.Filter([](int ipis, Farray_t& nlhpi) { return nlhpi[ipis - 1] > 0.1; }, {"ipis", "nlhpi"})
23+
.Filter("njets >= 1");
24+
25+
return ret;
26+
};
27+
28+
const Double_t dxbin = (0.17 - 0.13) / 40; // Bin-width
29+
30+
Double_t fdm5(Double_t *xx, Double_t *par)
31+
{
32+
Double_t x = xx[0];
33+
if (x <= 0.13957)
34+
return 0;
35+
Double_t xp3 = (x - par[3]) * (x - par[3]);
36+
Double_t res =
37+
dxbin * (par[0] * pow(x - 0.13957, par[1]) + par[2] / 2.5066 / par[4] * exp(-xp3 / 2 / par[4] / par[4]));
38+
return res;
39+
}
40+
41+
Double_t fdm2(Double_t *xx, Double_t *par)
42+
{
43+
static const Double_t sigma = 0.0012;
44+
Double_t x = xx[0];
45+
if (x <= 0.13957)
46+
return 0;
47+
Double_t xp3 = (x - 0.1454) * (x - 0.1454);
48+
Double_t res = dxbin * (par[0] * pow(x - 0.13957, 0.25) + par[1] / 2.5066 / sigma * exp(-xp3 / 2 / sigma / sigma));
49+
return res;
50+
}
51+
52+
void df101_h1Analysis()
53+
{
54+
ROOT::RDataFrame dataFrame("h42", RB::GetDataDir() + "/h1analysis*.root");
55+
auto selected = Select(dataFrame);
56+
auto hdmdARP = selected.Histo1D({"hdmd", "Dm_d", 40, 0.13, 0.17}, "dm_d");
57+
auto selectedAddedBranch = selected.Define("h2_y", "rpd0_t / 0.029979f * 1.8646f / ptd0_d");
58+
auto h2ARP = selectedAddedBranch.Histo2D({"h2", "ptD0 vs Dm_d", 30, 0.135, 0.165, 30, -3, 6}, "dm_d", "h2_y");
59+
60+
h2ARP.GetValue(); // trigger event loop
61+
}
62+
63+
static void BM_RDataFrame_h1Analysis(benchmark::State &state)
64+
{
65+
for (auto _ : state)
66+
df101_h1Analysis();
67+
}
68+
BENCHMARK(BM_RDataFrame_h1Analysis)->Repetitions(1);
69+
70+
static void BM_RDataFrame_h1Analysis_MT(benchmark::State &state)
71+
{
72+
ROOT::EnableImplicitMT(state.range(0));
73+
for (auto _ : state)
74+
df101_h1Analysis();
75+
ROOT::DisableImplicitMT();
76+
}
77+
BENCHMARK(BM_RDataFrame_h1Analysis_MT)->Repetitions(1)->Arg(8);
78+
79+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)