As an example, we build a helper for filling THns.
template <typename T, unsigned int NDIM>
class THnHelper : public ROOT::Detail::RDF::RActionImpl<THnHelper<T, NDIM>> {
public:
using Result_t = THn_t;
private:
std::vector<std::shared_ptr<THn_t>> fHistos;
public:
std::array<double, NDIM>
xmax)
{
fHistos.emplace_back(std::make_shared<THn_t>(std::string(name).c_str(), std::string(title).c_str(),
NDIM, nbins.data(), xmins.data(), xmax.data()));
}
}
THnHelper(THnHelper &&) = default;
THnHelper(const THnHelper &) = delete;
std::shared_ptr<THn_t> GetResultPtr() const { return fHistos[0]; }
template <typename... ColumnTypes>
void Exec(unsigned int slot, ColumnTypes... values)
{
std::array<double, sizeof...(ColumnTypes)> valuesArr{static_cast<double>(values)...};
fHistos[slot]->Fill(valuesArr.data());
}
void Finalize()
{
auto &res = fHistos[0];
res->Add(fHistos[slot].get());
}
}
};
void df018_customActions()
{
auto genF = [&genD]() { return (float)genD(); };
auto genI = [&genD]() { return (int)genD(); };
auto dd =
d.Define(
"x0", genD).Define(
"x1", genD).Define(
"x2", genF).Define(
"x3", genI);
using Helper_t = THnHelper<float, 4>;
Helper_t helper{"myThN",
"A THn with 4 dimensions",
{4, 4, 8, 2},
{-10., -10, -4., -6.},
{10., 10, 5., 7.}};
auto myTHnT = dd.Book<double, double, float, int>(std::move(helper), {"x0", "x1", "x2", "x3"});
myTHnT->Print();
}