ROOT
Version master
v6.36
v6.34
v6.32
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
df017_vecOpsHEP.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_dataframe
3
## \notebook -draw
4
## Use RVecs to plot the transverse momentum of selected particles.
5
##
6
## This tutorial shows how VecOps can be used to slim down the programming
7
## model typically adopted in HEP for analysis.
8
## In this case we have a dataset containing the kinematic properties of
9
## particles stored in individual arrays.
10
## We want to plot the transverse momentum of these particles if the energy is
11
## greater than 100 MeV.
12
13
## \macro_code
14
## \macro_image
15
##
16
## \date March 2018
17
## \authors Danilo Piparo (CERN), Andre Vieira Silva
18
19
import
ROOT
20
import
numpy
as
np
21
22
filename =
ROOT.gROOT.GetTutorialDir
().Data() +
"/analysis/dataframe/df017_vecOpsHEP.root"
23
treename =
"myDataset"
24
25
def
WithPyROOT
(filename):
26
from
math
import
sqrt
27
f =
ROOT.TFile
(filename)
28
h =
ROOT.TH1F
(
"pt"
,
"With PyROOT"
, 16, 0, 4)
29
for
event
in
f[treename]:
30
h.Fill
(
31
np.array
(
32
[
33
sqrt(px * px + py * py)
34
for
E, px, py
in
zip
(
event.E
,
event.px
,
event.py
)
35
if
E > 100
36
]
37
)
38
)
39
h.DrawCopy
()
40
41
def
WithRDataFrameVecOpsJit
(treename, filename):
42
f =
ROOT.RDataFrame
(treename, filename)
43
h =
f.Define
(
"good_pt"
,
"sqrt(px*px + py*py)[E>100]"
)\
44
.Histo1D((
"pt"
,
"With RDataFrame and RVec"
, 16, 0, 4),
"good_pt"
)
45
h.DrawCopy
()
46
47
## We plot twice the same quantity, the key is to look into the implementation
48
## of the functions above.
49
c =
ROOT.TCanvas
()
50
c.Divide
(2,1)
51
c.cd
(1)
52
WithPyROOT
(filename)
53
c.cd
(2)
54
WithRDataFrameVecOpsJit
(treename, filename)
55
c.SaveAs
(
"df017_vecOpsHEP.png"
)
56
57
print(
"Saved figure to df017_vecOpsHEP.png"
)
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
ROOT::RDataFrame
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
Definition
RDataFrame.hxx:41
tutorials
analysis
dataframe
df017_vecOpsHEP.py
ROOT master - Reference Guide Generated on Mon Apr 21 2025 06:30:47 (GVA Time) using Doxygen 1.10.0