Logo ROOT   6.16/01
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
14from math import sqrt
15
16filename = ROOT.gROOT.GetTutorialDir().Data() + "/dataframe/df017_vecOpsHEP.root"
17treename = "myDataset"
18RDF = ROOT.ROOT.RDataFrame
19
20def WithPyROOT():
21 f = ROOT.TFile(filename)
22 h = ROOT.TH1F("pt", "pt", 16, 0, 4)
23 for event in f.myDataset:
24 for E, px, py in zip(event.E, event.px, event.py):
25 if (E > 100):
26 h.Fill(sqrt(px*px + py*py))
27 h.DrawCopy()
28
29def WithRDataFrameVecOpsJit():
30 f = RDF(treename, filename)
31 h = f.Define("good_pt", "sqrt(px*px + py*py)[E>100]")\
32 .Histo1D(("pt", "pt", 16, 0, 4), "good_pt")
33 h.DrawCopy()
34
35## We plot twice the same quantity, the key is to look into the implementation
36## of the functions above
37c = ROOT.TCanvas()
38c.Divide(2,1)
39c.cd(1)
40WithPyROOT()
41c.cd(2)
42WithRDataFrameVecOpsJit()
double sqrt(double)