17 using FourVector = ROOT::Math::XYZTVector; 18 using FourVectors = std::vector<FourVector>; 19 using CylFourVector = ROOT::Math::RhoEtaPhiVector; 21 void fill_tree(const char *filename, const char *treeName) 23 TFile f(filename, "RECREATE"); 24 TTree t(treeName, treeName); 26 t.Branch("tracks", &tracks); 28 const double M = 0.13957; // set pi+ mass 31 for (int i = 0; i < 50; ++i) { 32 auto nPart = R.Poisson(15); 34 tracks.reserve(nPart); 35 for (int j = 0; j < nPart; ++j) { 36 double px = R.Gaus(0, 10); 37 double py = R.Gaus(0, 10); 38 double pt = sqrt(px * px + py * py); 39 double eta = R.Uniform(-3, 3); 40 double phi = R.Uniform(0.0, 2 * TMath::Pi()); 41 CylFourVector vcyl(pt, eta, phi); 43 double E = sqrt(vcyl.R() * vcyl.R() + M * M); 44 FourVector q(vcyl.X(), vcyl.Y(), vcyl.Z(), E); 46 tracks.emplace_back(q); 58 fileName =
"tdf002_dataModel_py.root" 60 ROOT.gInterpreter.Declare(fill_tree_code)
61 ROOT.fill_tree(fileName, treeName)
65 TDF = ROOT.ROOT.Experimental.TDataFrame
66 d = TDF(treeName, fileName)
71 n_cut =
'tracks.size() > 8' 72 nentries = d.Filter(n_cut).Count();
74 print(
"%s passed all filters" %nentries.GetValue())
82 std::vector<double> getPt (const FourVectors &tracks) 84 std::vector<double> pts; 85 pts.reserve(tracks.size()); 86 for (auto &t : tracks) pts.emplace_back(t.Pt()); 90 ROOT.gInterpreter.Declare(getPt_code)
92 getPtWeights_code =
''' 93 std::vector<double> getPtWeights (const FourVectors &tracks) { 94 std::vector<double> ptsw; 95 ptsw.reserve(tracks.size()); 96 for (auto &t : tracks) ptsw.emplace_back(1. / t.Pt()); 100 ROOT.gInterpreter.Declare(getPtWeights_code)
102 augmented_d = d.Define(
'tracks_n',
'(int)tracks.size()') \
103 .Filter(
'tracks_n > 2') \
104 .Define(
'tracks_pts',
'getPt( tracks )') \
105 .Define(
"tracks_pts_weights",
'getPtWeights( tracks )' )
109 trN = augmented_d.Histo1D((
"",
"", 40, -.5, 39.5),
"tracks_n")
110 trPts = augmented_d.Histo1D(
"tracks_pts")
111 trWPts = augmented_d.Histo1D(
"tracks_pts",
"tracks_pts_weights")
115 c1.Print(
"tracks_n.png")
119 c2.Print(
"tracks_pt.png")
123 c3.Print(
"tracks_Wpt.png")