Skip to content

Commit 750cb39

Browse files
committed
Add pyrdf dimuon test to baseline folder
1 parent 6947b42 commit 750cb39

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

baseline/pyrdf_dimuon.py

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import PyRDF
2+
3+
import ROOT
4+
5+
PyRDF.use("spark")
6+
7+
8+
def dimuonSpectrum(df):
9+
10+
entries_total = df.Count()
11+
12+
# Select events with exactly two muons
13+
df_2mu = df.Filter("nMuon == 2", "Events with exactly two muons")
14+
15+
# Select events with two muons of opposite charge
16+
df_os = df_2mu.Filter(
17+
"Muon_charge[0] != Muon_charge[1]", "Muons with opposite charge")
18+
19+
# Compute invariant mass of the dimuon system
20+
df_mass = df_os.Define(
21+
"Dimuon_mass",
22+
"ROOT::VecOps::InvariantMass(Muon_pt, Muon_eta, Muon_phi, Muon_mass)")
23+
24+
# Book histogram of dimuon mass spectrum
25+
bins = 30000 # Number of bins in the histogram
26+
low = 0.25 # Lower edge of the histogram
27+
up = 300.0 # Upper edge of the histogram
28+
29+
hist = df_mass.Histo1D(ROOT.RDF.TH1DModel(
30+
"", "", bins, low, up), "Dimuon_mass")
31+
32+
entries_final = df_mass.Count()
33+
34+
# Create canvas for plotting
35+
ROOT.gStyle.SetOptStat(0)
36+
ROOT.gStyle.SetTextFont(42)
37+
c = ROOT.TCanvas("c", "", 800, 700)
38+
c.SetLogx()
39+
c.SetLogy()
40+
41+
# Draw histogram
42+
hist.GetXaxis().SetTitle("m_{#mu#mu} (GeV)")
43+
hist.GetXaxis().SetTitleSize(0.04)
44+
hist.GetYaxis().SetTitle("N_{Events}")
45+
hist.GetYaxis().SetTitleSize(0.04)
46+
hist.SetStats(False)
47+
hist.Draw()
48+
49+
# Draw labels
50+
label = ROOT.TLatex()
51+
label.SetTextAlign(22)
52+
label.DrawLatex(0.55, 3.0e4, "#eta")
53+
label.DrawLatex(0.77, 7.0e4, "#rho,#omega")
54+
label.DrawLatex(1.20, 4.0e4, "#phi")
55+
label.DrawLatex(4.40, 1.0e5, "J/#psi")
56+
label.DrawLatex(4.60, 1.0e4, "#psi'")
57+
label.DrawLatex(12.0, 2.0e4, "Y(1,2,3S)")
58+
label.DrawLatex(91.0, 1.5e4, "Z")
59+
label.SetNDC(True)
60+
label.SetTextAlign(11)
61+
label.SetTextSize(0.04)
62+
label.DrawLatex(0.10, 0.92, "#bf{CMS Open Data}")
63+
label.SetTextAlign(31)
64+
label.DrawLatex(0.90, 0.92, "#sqrt{s} = 8 TeV, L_{int} = 11.6 fb^{-1}")
65+
66+
print("Initial total entries: {}".format(entries_total.GetValue()))
67+
print("Entries after processing: {}".format(entries_final.GetValue()))
68+
# Save Canvas to image
69+
c.SaveAs("dimuonSpectrum.png")
70+
71+
72+
dataset = ("root://eospublic.cern.ch//eos/opendata/cms/derived-data/"
73+
"AOD2NanoAODOutreachTool/Run2012BC_DoubleMuParked_Muons.root")
74+
75+
df = PyRDF.RDataFrame("Events", [dataset])
76+
77+
for i in range(1, 101):
78+
print("Iteration {} with rdf {}".format(i, str(df)))
79+
t = ROOT.TStopwatch()
80+
dimuonSpectrum(df)
81+
t.Stop()
82+
realtime = round(t.RealTime(), 2)
83+
84+
with open("baseline_pyrdf_dimuon.csv", "a+") as f:
85+
f.write(str(realtime))
86+
f.write("\n")

0 commit comments

Comments
 (0)