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