25parser = argparse.ArgumentParser()
26parser.add_argument(
"--lumi-scale", default=0.01, help=
"Scale of the overall lumi of 10 fb^-1")
27parser.add_argument(
"-b", action=
"store_true", default=
False, help=
"Use ROOT batch mode")
28args = parser.parse_args()
29if args.b: ROOT.gROOT.SetBatch(
True)
33path =
"root://eospublic.cern.ch//eos/opendata/atlas/OutreachDatasets/2020-01-22"
34files = json.load(
open(os.path.join(os.environ[
"ROOTSYS"],
"tutorials/dataframe",
"df105_WBosonAnalysis.json")))
35processes = files.keys()
48 samples.append(sample)
49 df[sample] =
ROOT.RDataFrame(
"mini",
"{}/1lep/{}/{}.1lep.root".format(path, folder, sample))
52 df[sample] = df[sample].
Range(
int(num_events * args.lumi_scale))
55ROOT.gInterpreter.Declare(
"""
56bool GoodElectronOrMuon(int type, float pt, float eta, float phi, float e, float trackd0pv, float tracksigd0pv, float z0)
58 ROOT::Math::PtEtaPhiEVector p(pt / 1000.0, eta, phi, e / 1000.0);
59 if (abs(z0 *
sin(p.theta())) > 0.5)
return false;
60 if (type == 11 && abs(eta) < 2.46 && (abs(eta) < 1.37 || abs(eta) > 1.52)) {
61 if (abs(trackd0pv / tracksigd0pv) > 5)
return false;
64 if (type == 13 && abs(eta) < 2.5) {
65 if (abs(trackd0pv / tracksigd0pv) > 3)
return false;
74 df[s] = df[s].
Filter(
"met_et > 30000")
76 df[s] = df[s].
Filter(
"trigE || trigM")
78 df[s] = df[s].Define(
"good_lep",
"lep_isTightID && lep_pt > 35000 && lep_ptcone30 / lep_pt < 0.1 && lep_etcone20 / lep_pt < 0.1")\
79 .
Filter(
"Sum(good_lep) == 1")
81 df[s] = df[s].Define(
"idx",
"ROOT::VecOps::ArgMax(good_lep)")\
82 .
Filter(
"GoodElectronOrMuon(lep_type[idx], lep_pt[idx], lep_eta[idx], lep_phi[idx], lep_E[idx], lep_trackd0pvunbiased[idx], lep_tracksigd0pvunbiased[idx], lep_z0[idx])")
88 df[s] = df[s].Define(
"weight",
"1.0")
90 df[s] = df[s].Define(
"weight",
"scaleFactor_ELE * scaleFactor_MUON * scaleFactor_LepTRIGGER * scaleFactor_PILEUP * mcWeight * {} / {} * {}".format(xsecs[s], sumws[s], lumi))
93ROOT.gInterpreter.Declare(
"""
94float ComputeTransverseMass(float met_et, float met_phi, float lep_pt, float lep_eta, float lep_phi, float lep_e)
96 ROOT::Math::PtEtaPhiEVector met(met_et, 0, met_phi, met_et);
97 ROOT::Math::PtEtaPhiEVector lep(lep_pt, lep_eta, lep_phi, lep_e);
98 return (met + lep).Mt() / 1000.0;
104 df[s] = df[s].Define("mt_w",
"ComputeTransverseMass(met_et, met_phi, lep_pt[idx], lep_eta[idx], lep_phi[idx], lep_E[idx])")
105 histos[s] = df[s].Histo1D(
ROOT.RDF.TH1DModel(s,
"mt_w", 40, 60, 180),
"mt_w",
"weight")
109def merge_histos(label):
111 for i, d
in enumerate(files[label]):
112 t = histos[d[1]].GetValue()
113 if i == 0: h = t.Clone()
115 h.SetNameTitle(label, label)
118data = merge_histos(
"data")
119wjets = merge_histos(
"wjets")
120zjets = merge_histos(
"zjets")
121ttbar = merge_histos(
"ttbar")
122diboson = merge_histos(
"diboson")
123singletop = merge_histos(
"singletop")
128ROOT.gROOT.SetStyle(
"ATLAS")
131c = ROOT.TCanvas(
"c",
"", 600, 600)
132pad = ROOT.TPad(
"upper_pad",
"", 0, 0, 1, 1)
140stack = ROOT.THStack()
142 [singletop, diboson, ttbar, zjets, wjets],
143 [(208, 240, 193), (195, 138, 145), (155, 152, 204), (248, 206, 104), (222, 90, 106)]):
146 h.SetFillColor(ROOT.TColor.GetColor(*color))
149stack.GetXaxis().SetLabelSize(0.04)
150stack.GetXaxis().SetTitleSize(0.045)
151stack.GetXaxis().SetTitleOffset(1.3)
152stack.GetXaxis().SetTitle(
"m_{T}^{W#rightarrow l#nu} [GeV]")
153stack.GetYaxis().SetTitle(
"Events")
154stack.GetYaxis().SetLabelSize(0.04)
155stack.GetYaxis().SetTitleSize(0.045)
156stack.SetMaximum(1e10 * args.lumi_scale)
160data.SetMarkerStyle(20)
161data.SetMarkerSize(1.2)
163data.SetLineColor(ROOT.kBlack)
167legend = ROOT.TLegend(0.60, 0.65, 0.92, 0.92)
168legend.SetTextFont(42)
169legend.SetFillStyle(0)
170legend.SetBorderSize(0)
171legend.SetTextSize(0.04)
172legend.SetTextAlign(32)
173legend.AddEntry(data,
"Data" ,
"lep")
174legend.AddEntry(wjets,
"W+jets",
"f")
175legend.AddEntry(zjets,
"Z+jets",
"f")
176legend.AddEntry(ttbar,
"t#bar{t}",
"f")
177legend.AddEntry(diboson,
"Diboson",
"f")
178legend.AddEntry(singletop,
"Single top",
"f")
185text.SetTextSize(0.045)
186text.DrawLatex(0.21, 0.86,
"ATLAS")
188text.DrawLatex(0.21 + 0.16, 0.86,
"Open Data")
189text.SetTextSize(0.04)
190text.DrawLatex(0.21, 0.80,
"#sqrt{{s}} = 13 TeV, {:.1f} fb^{{-1}}".format(lumi * args.lumi_scale / 1000.0))
193c.SaveAs(
"WBosonAnalysis.pdf")
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
RVec< T > Filter(const RVec< T > &v, F &&f)
Create a new collection with the elements passing the filter expressed by the predicate.
A struct which stores the parameters of a TH1D.