Logo ROOT  
Reference Guide
df017_vecOpsHEP.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_dataframe
3## \notebook -draw
4## This tutorial shows how VecOps can be used to slim down the programming
5## model typically adopted in HEP for analysis.
6##
7## \macro_code
8## \macro_image
9##
10## \date March 2018
11## \author Danilo Piparo, Andre Vieira Silva
12
13import ROOT
14
15filename = ROOT.gROOT.GetTutorialDir().Data() + "/dataframe/df017_vecOpsHEP.root"
16treename = "myDataset"
17
18def WithPyROOT(filename):
19 from math import sqrt
20 f = ROOT.TFile(filename)
21 h = ROOT.TH1F("pt", "pt", 16, 0, 4)
22 for event in f.myDataset:
23 for E, px, py in zip(event.E, event.px, event.py):
24 if (E > 100):
25 h.Fill(sqrt(px*px + py*py))
26 h.DrawCopy()
27
28def WithRDataFrameVecOpsJit(treename, filename):
29 f = ROOT.RDataFrame(treename, filename)
30 h = f.Define("good_pt", "sqrt(px*px + py*py)[E>100]")\
31 .Histo1D(("pt", "pt", 16, 0, 4), "good_pt")
32 h.DrawCopy()
33
34## We plot twice the same quantity, the key is to look into the implementation
35## of the functions above
36c = ROOT.TCanvas()
37c.Divide(2,1)
38c.cd(1)
39WithPyROOT(filename)
40c.cd(2)
41WithRDataFrameVecOpsJit(treename, filename)
double sqrt(double)
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
Definition: RDataFrame.hxx:42