42ROOT.ROOT.EnableImplicitMT()
45higgs_header_path = os.path.join(os.sep, str(ROOT.gROOT.GetTutorialDir()) + os.sep,
"dataframe" + os.sep,
46 "df103_NanoAODHiggsAnalysis_python.h")
48ROOT.gInterpreter.Declare(
'#include "{}"'.format(higgs_header_path))
52def reco_higgs_to_2el2mu(df):
53 """Reconstruct Higgs from two electrons and two muons"""
55 df_base = selection_2el2mu(df)
57 df_z_mass = df_base.Define(
"Z_mass",
"compute_z_masses_2el2mu(Electron_pt, Electron_eta, Electron_phi,"
58 " Electron_mass, Muon_pt, Muon_eta, Muon_phi, Muon_mass)")
60 df_z_cut = filter_z_candidates(df_z_mass)
62 df_h_mass = df_z_cut.Define(
"H_mass",
"compute_higgs_mass_2el2mu(Electron_pt, Electron_eta, Electron_phi,"
63 " Electron_mass, Muon_pt, Muon_eta, Muon_phi, Muon_mass)")
68def selection_2el2mu(df):
69 """Select interesting events with two electrons and two muons"""
70 df_ge2el2mu = df.Filter(
"nElectron>=2 && nMuon>=2",
"At least two electrons and two muons")
71 df_eta = df_ge2el2mu.Filter(
"All(abs(Electron_eta)<2.5) && All(abs(Muon_eta)<2.4)",
"Eta cuts")
73 df_pt = df_eta.Filter(
"pt_cuts(Muon_pt, Electron_pt)",
"Pt cuts")
75 df_dr = df_pt.Filter(
"dr_cuts(Muon_eta, Muon_phi, Electron_eta, Electron_phi)",
"Dr cuts")
77 df_iso = df_dr.Filter(
"All(abs(Electron_pfRelIso03_all)<0.40) && All(abs(Muon_pfRelIso04_all)<0.40)",
78 "Require good isolation")
79 df_el_ip3d = df_iso.Define(
"Electron_ip3d_el",
"sqrt(Electron_dxy*Electron_dxy + Electron_dz*Electron_dz)")
80 df_el_sip3d = df_el_ip3d.Define(
"Electron_sip3d_el",
81 "Electron_ip3d_el/sqrt(Electron_dxyErr*Electron_dxyErr + "
82 "Electron_dzErr*Electron_dzErr)")
83 df_el_track = df_el_sip3d.Filter(
"All(Electron_sip3d_el<4) && All(abs(Electron_dxy)<0.5) &&"
84 " All(abs(Electron_dz)<1.0)",
85 "Electron track close to primary vertex with small uncertainty")
86 df_mu_ip3d = df_el_track.Define(
"Muon_ip3d_mu",
"sqrt(Muon_dxy*Muon_dxy + Muon_dz*Muon_dz)")
88 df_mu_sip3d = df_mu_ip3d.Define(
"Muon_sip3d_mu",
89 "Muon_ip3d_mu/sqrt(Muon_dxyErr*Muon_dxyErr + Muon_dzErr*Muon_dzErr)")
90 df_mu_track = df_mu_sip3d.Filter(
"All(Muon_sip3d_mu<4) && All(abs(Muon_dxy)<0.5) && All(abs(Muon_dz)<1.0)",
91 "Muon track close to primary vertex with small uncertainty")
92 df_2p2n = df_mu_track.Filter(
"Sum(Electron_charge)==0 && Sum(Muon_charge)==0",
93 "Two opposite charged electron and muon pairs")
98def reco_higgs_to_4mu(df):
99 """Reconstruct Higgs from four muons"""
101 df_base = selection_4mu(df)
104 df_z_idx = df_base.Define(
"Z_idx",
"reco_zz_to_4l(Muon_pt, Muon_eta, Muon_phi, Muon_mass, Muon_charge)")
107 df_z_dr = df_z_idx.Filter(
"filter_z_dr(Z_idx, Muon_eta, Muon_phi)",
"Delta R separation of muons building Z system")
110 df_z_mass = df_z_dr.Define(
"Z_mass",
"compute_z_masses_4l(Z_idx, Muon_pt, Muon_eta, Muon_phi, Muon_mass)")
113 df_z_cut = filter_z_candidates(df_z_mass)
116 df_h_mass = df_z_cut.Define(
"H_mass",
"compute_higgs_mass_4l(Z_idx, Muon_pt, Muon_eta, Muon_phi, Muon_mass)")
121def selection_4mu(df):
122 """Select interesting events with four muons"""
123 df_ge4m = df.Filter(
"nMuon>=4",
"At least four muons")
125 df_iso = df_ge4m.Filter(
"All(abs(Muon_pfRelIso04_all)<0.40)",
"Require good isolation")
126 df_kin = df_iso.Filter(
"All(Muon_pt>5) && All(abs(Muon_eta)<2.4)",
"Good muon kinematics")
127 df_ip3d = df_kin.Define(
"Muon_ip3d",
"sqrt(Muon_dxy*Muon_dxy + Muon_dz*Muon_dz)")
128 df_sip3d = df_ip3d.Define(
"Muon_sip3d",
"Muon_ip3d/sqrt(Muon_dxyErr*Muon_dxyErr + Muon_dzErr*Muon_dzErr)")
129 df_pv = df_sip3d.Filter(
"All(Muon_sip3d<4) && All(abs(Muon_dxy)<0.5) && All(abs(Muon_dz)<1.0)",
130 "Track close to primary vertex with small uncertainty")
131 df_2p2n = df_pv.Filter(
"nMuon==4 && Sum(Muon_charge==1)==2 && Sum(Muon_charge==-1)==2",
132 "Two positive and two negative muons")
137def filter_z_candidates(df):
138 """Apply selection on reconstructed Z candidates"""
139 df_z1_cut = df.Filter(
"Z_mass[0] > 40 && Z_mass[0] < 120",
"Mass of first Z candidate in [40, 120]")
140 df_z2_cut = df_z1_cut.Filter(
"Z_mass[1] > 12 && Z_mass[1] < 120",
"Mass of second Z candidate in [12, 120]")
145def reco_higgs_to_4el(df):
146 """Reconstruct Higgs from four electrons"""
148 df_base = selection_4el(df)
151 df_z_idx = df_base.Define(
"Z_idx",
152 "reco_zz_to_4l(Electron_pt, Electron_eta, Electron_phi, Electron_mass, Electron_charge)")
155 df_z_dr = df_z_idx.Filter(
"filter_z_dr(Z_idx, Electron_eta, Electron_phi)",
156 "Delta R separation of Electrons building Z system")
159 df_z_mass = df_z_dr.Define(
"Z_mass",
160 "compute_z_masses_4l(Z_idx, Electron_pt, Electron_eta, Electron_phi, Electron_mass)")
163 df_z_cut = filter_z_candidates(df_z_mass)
166 df_h_mass = df_z_cut.Define(
"H_mass",
167 "compute_higgs_mass_4l(Z_idx, Electron_pt, Electron_eta, Electron_phi, Electron_mass)")
172def selection_4el(df):
173 """Select interesting events with four electrons"""
174 df_ge4el = df.Filter(
"nElectron>=4",
"At least our electrons")
175 df_iso = df_ge4el.Filter(
"All(abs(Electron_pfRelIso03_all)<0.40)",
"Require good isolation")
176 df_kin = df_iso.Filter(
"All(Electron_pt>7) && All(abs(Electron_eta)<2.5)",
"Good Electron kinematics")
177 df_ip3d = df_kin.Define(
"Electron_ip3d",
"sqrt(Electron_dxy*Electron_dxy + Electron_dz*Electron_dz)")
178 df_sip3d = df_ip3d.Define(
"Electron_sip3d",
179 "Electron_ip3d/sqrt(Electron_dxyErr*Electron_dxyErr + Electron_dzErr*Electron_dzErr)")
180 df_pv = df_sip3d.Filter(
"All(Electron_sip3d<4) && All(abs(Electron_dxy)<0.5) && All(abs(Electron_dz)<1.0)",
181 "Track close to primary vertex with small uncertainty")
182 df_2p2n = df_pv.Filter(
"nElectron==4 && Sum(Electron_charge==1)==2 && Sum(Electron_charge==-1)==2",
183 "Two positive and two negative electrons")
188def plot(sig, bkg, data, x_label, filename):
190 Plot invariant mass for signal and background processes from simulated
191 events overlay the measured data.
194 ROOT.gStyle.SetOptStat(0)
195 ROOT.gStyle.SetTextFont(42)
196 d = ROOT.TCanvas(
"",
"", 800, 700)
198 ROOT.SetOwnership(d,
False)
199 d.SetLeftMargin(0.15)
208 h_cmb.GetXaxis().SetTitle(x_label)
209 h_cmb.GetXaxis().SetTitleSize(0.04)
210 h_cmb.GetYaxis().SetTitle(
"N_{Events}")
211 h_cmb.GetYaxis().SetTitleSize(0.04)
212 h_cmb.SetLineColor(ROOT.kRed)
213 h_cmb.SetLineWidth(2)
215 h_bkg.SetLineWidth(2)
216 h_bkg.SetFillStyle(1001)
217 h_bkg.SetLineColor(ROOT.kBlack)
218 h_bkg.SetFillColor(ROOT.kAzure - 9)
222 h_data.SetLineWidth(1)
223 h_data.SetMarkerStyle(20)
224 h_data.SetMarkerSize(1.0)
225 h_data.SetMarkerColor(ROOT.kBlack)
226 h_data.SetLineColor(ROOT.kBlack)
229 h_cmb.DrawCopy(
"HIST")
230 h_bkg.DrawCopy(
"HIST SAME")
231 h_data.DrawCopy(
"PE1 SAME")
234 legend = ROOT.TLegend(0.62, 0.70, 0.82, 0.88)
235 legend.SetFillColor(0)
236 legend.SetBorderSize(0)
237 legend.SetTextSize(0.03)
238 legend.AddEntry(h_data,
"Data",
"PE1")
239 legend.AddEntry(h_bkg,
"ZZ",
"f")
240 legend.AddEntry(h_cmb,
"m_{H} = 125 GeV",
"f")
244 cms_label = ROOT.TLatex()
245 cms_label.SetTextSize(0.04)
246 cms_label.DrawLatexNDC(0.16, 0.92,
"#bf{CMS Open Data}")
247 header = ROOT.TLatex()
248 header.SetTextSize(0.03)
249 header.DrawLatexNDC(0.63, 0.92,
"#sqrt{s} = 8 TeV, L_{int} = 11.6 fb^{-1}")
258 path =
"root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/"
259 if run_fast: path =
"root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod_skimmed/"
275 df_data_doublemu =
ROOT.RDataFrame(
"Events", (path + f
for f
in [
"Run2012B_DoubleMuParked.root",
"Run2012C_DoubleMuParked.root"]))
276 df_data_doubleel =
ROOT.RDataFrame(
"Events", (path + f
for f
in [
"Run2012B_DoubleElectron.root",
"Run2012C_DoubleElectron.root"]))
285 nevt_ZZTo4mu = 1499064.0
288 nevt_ZZTo4el = 1499093.0
290 xsec_ZZTo2el2mu = 0.18
291 nevt_ZZTo2el2mu = 1497445.0
293 xsec_SMHiggsToZZTo4L = 0.0065
294 nevt_SMHiggsToZZTo4L = 299973.0
297 weight_sig_4mu = luminosity * xsec_SMHiggsToZZTo4L / nevt_SMHiggsToZZTo4L
298 weight_bkg_4mu = luminosity * xsec_ZZTo4mu * scale_ZZTo4l / nevt_ZZTo4mu
300 weight_sig_4el = luminosity * xsec_SMHiggsToZZTo4L / nevt_SMHiggsToZZTo4L
301 weight_bkg_4el = luminosity * xsec_ZZTo4el * scale_ZZTo4l / nevt_ZZTo4el
303 weight_sig_2el2mu = luminosity * xsec_SMHiggsToZZTo4L / nevt_SMHiggsToZZTo4L
304 weight_bkg_2el2mu = luminosity * xsec_ZZTo2el2mu * scale_ZZTo4l / nevt_ZZTo2el2mu
307 df_sig_4mu_reco = reco_higgs_to_4mu(df_sig_4l)
309 df_h_sig_4mu = df_sig_4mu_reco.Define(
"weight",
"{}".format(weight_sig_4mu))\
310 .Histo1D((
"h_sig_4mu",
"", nbins, 70, 180),
"H_mass",
"weight")
312 df_bkg_4mu_reco = reco_higgs_to_4mu(df_bkg_4mu)
314 df_h_bkg_4mu = df_bkg_4mu_reco.Define(
"weight",
"{}".format(weight_bkg_4mu))\
315 .Histo1D((
"h_bkg_4mu",
"", nbins, 70, 180),
"H_mass",
"weight")
317 df_data_4mu_reco = reco_higgs_to_4mu(df_data_doublemu)
319 df_h_data_4mu = df_data_4mu_reco.Define(
"weight",
"1.0")\
320 .Histo1D((
"h_data_4mu",
"", nbins, 70, 180),
"H_mass",
"weight")
323 df_sig_4el_reco = reco_higgs_to_4el(df_sig_4l)
325 df_h_sig_4el = df_sig_4el_reco.Define(
"weight",
"{}".format(weight_sig_4el))\
326 .Histo1D((
"h_sig_4el",
"", nbins, 70, 180),
"H_mass",
"weight")
328 df_bkg_4el_reco = reco_higgs_to_4el(df_bkg_4el)
330 df_h_bkg_4el = df_bkg_4el_reco.Define(
"weight",
"{}".format(weight_bkg_4el))\
331 .Histo1D((
"h_bkg_4el",
"", nbins, 70, 180),
"H_mass",
"weight")
333 df_data_4el_reco = reco_higgs_to_4el(df_data_doubleel)
335 df_h_data_4el = df_data_4el_reco.Define(
"weight",
"1.0")\
336 .Histo1D((
"h_data_4el",
"", nbins, 70, 180),
"H_mass",
"weight")
339 df_sig_2el2mu_reco = reco_higgs_to_2el2mu(df_sig_4l)
341 df_h_sig_2el2mu = df_sig_2el2mu_reco.Define(
"weight",
"{}".format(weight_sig_2el2mu))\
342 .Histo1D((
"h_sig_2el2mu",
"", nbins, 70, 180),
"H_mass",
"weight")
344 df_bkg_2el2mu_reco = reco_higgs_to_2el2mu(df_bkg_2el2mu)
346 df_h_bkg_2el2mu = df_bkg_2el2mu_reco.Define(
"weight",
"{}".format(weight_bkg_2el2mu))\
347 .Histo1D((
"h_bkg_2el2mu",
"", nbins, 70, 180),
"H_mass",
"weight")
349 df_data_2el2mu_reco = reco_higgs_to_2el2mu(df_data_doublemu)
351 df_h_data_2el2mu = df_data_2el2mu_reco.Define(
"weight",
"1.0")\
352 .Histo1D((
"h_data_2el2mu_doublemu",
"", nbins, 70, 180),
"H_mass",
"weight")
359 df_h_sig_4el, df_h_bkg_4el, df_h_data_4el,
360 df_h_sig_2el2mu, df_h_bkg_2el2mu, df_h_data_2el2mu])
363 signal_4mu = df_h_sig_4mu.GetValue()
364 background_4mu = df_h_bkg_4mu.GetValue()
365 data_4mu = df_h_data_4mu.GetValue()
367 signal_4el = df_h_sig_4el.GetValue()
368 background_4el = df_h_bkg_4el.GetValue()
369 data_4el = df_h_data_4el.GetValue()
371 signal_2el2mu = df_h_sig_2el2mu.GetValue()
372 background_2el2mu = df_h_bkg_2el2mu.GetValue()
373 data_2el2mu = df_h_data_2el2mu.GetValue()
376 plot(signal_4mu, background_4mu, data_4mu,
"m_{4#mu} (GeV)",
"higgs_4mu.pdf")
377 plot(signal_4el, background_4el, data_4el,
"m_{4e} (GeV)",
"higgs_4el.pdf")
378 plot(signal_2el2mu, background_2el2mu, data_2el2mu,
"m_{2e2#mu} (GeV)",
"higgs_2el2mu.pdf")
385 h_sig_4l = signal_4mu
386 h_sig_4l.Add(signal_4el)
387 h_sig_4l.Add(signal_2el2mu)
389 h_bkg_4l = background_4mu
390 h_bkg_4l.Add(background_4el)
391 h_bkg_4l.Add(background_2el2mu)
394 h_data_4l.Add(data_4el)
395 h_data_4l.Add(data_2el2mu)
398 plot(h_sig_4l, h_bkg_4l, h_data_4l,
"m_{4l} (GeV)",
"higgs_4l.pdf")
401if __name__ ==
"__main__":
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTree,...
void RunGraphs(std::vector< RResultHandle > handles)
Trigger the event loop of multiple RDataFrames concurrently.