Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
13 import ROOT
14 
15 filename = ROOT.gROOT.GetTutorialDir().Data() + "/dataframe/df017_vecOpsHEP.root"
16 treename = "myDataset"
17 
18 def 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 
28 def WithRDataFrameVecOpsJit(treename, filename):
29  f = ROOT.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
36 c = ROOT.TCanvas()
37 c.Divide(2,1)
38 c.cd(1)
39 WithPyROOT(filename)
40 c.cd(2)
41 WithRDataFrameVecOpsJit(treename, filename)