#include #include #include #include #include void looptest() { ROOT::EnableImplicitMT(); // Create some initial data size_t npoints = 10000000; ROOT::RDataFrame tdf(npoints); auto pidf = tdf.Define("x", "gRandom->Uniform(-1.0, 1.0)"); // The following is tedious // .Define("x0","pow(x,0)") // .Define("x1","pow(x,1)") // .Define("x2","pow(x,2)") // .Define("x3","pow(x,3)") // .Define("x4","pow(x,4)"); // Create values in a loop std::stringstream ss_name; std::stringstream ss_func; for(uint i=0;i<5;i++) { ss_name.str(""); ss_name << "x" << i; ss_func.str(""); ss_func << "pow(x," << i << ")"; pidf=pidf.Define(ss_name.str(), ss_func.str()); } // Apply selection auto seldf = pidf.Filter("x>0"); // Plot the different branches TCanvas c; THStack hs; for(uint i=0;i<5;i++) { ss_name.str(""); ss_name << "x" << i; auto myHisto = seldf.Histo1D({"","",50,0,1},ss_name.str()); hs.Add(static_cast(myHisto->Clone())); } hs.Draw("nostack"); c.SaveAs("test.pdf"); }