forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdf017_vecOpsHEP.py
More file actions
42 lines (37 loc) · 1.08 KB
/
df017_vecOpsHEP.py
File metadata and controls
42 lines (37 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
## \file
## \ingroup tutorial_dataframe
## \notebook -draw
## This tutorial shows how VecOps can be used to slim down the programming
## model typically adopted in HEP for analysis.
##
## \macro_code
## \macro_image
##
## \date March 2018
## \author Danilo Piparo, Andre Vieira Silva
import ROOT
from math import sqrt
filename = ROOT.gROOT.GetTutorialDir().Data() + "/dataframe/df017_vecOpsHEP.root"
treename = "myDataset"
RDF = ROOT.ROOT.RDataFrame
def WithPyROOT():
f = ROOT.TFile(filename)
h = ROOT.TH1F("pt", "pt", 16, 0, 4)
for event in f.myDataset:
for E, px, py in zip(event.E, event.px, event.py):
if (E > 100):
h.Fill(sqrt(px*px + py*py))
h.DrawCopy()
def WithRDataFrameVecOpsJit():
f = RDF(treename, filename)
h = f.Define("good_pt", "sqrt(px*px + py*py)[E>100]")\
.Histo1D(("pt", "pt", 16, 0, 4), "good_pt")
h.DrawCopy()
## We plot twice the same quantity, the key is to look into the implementation
## of the functions above
c = ROOT.TCanvas()
c.Divide(2,1)
c.cd(1)
WithPyROOT()
c.cd(2)
WithRDataFrameVecOpsJit()