28parser = argparse.ArgumentParser()
29parser.add_argument(
"--lumi-scale", type=float, default=0.001,
30 help=
"Run only on a fraction of the total available 10 fb^-1 (only usable together with --full-dataset)")
31parser.add_argument(
"--full-dataset", action=
"store_true", default=
False,
32 help=
"Use the full dataset (use --lumi-scale to run only on a fraction of it)")
33parser.add_argument(
"-b", action=
"store_true", default=
False, help=
"Use ROOT batch mode")
34parser.add_argument(
"-t", action=
"store_true", default=
False, help=
"Use implicit multi threading (for the full dataset only possible with --lumi-scale 1.0)")
35args = parser.parse_args()
37if args.b: ROOT.gROOT.SetBatch(
True)
40if not args.full_dataset: lumi_scale = 0.001
41else: lumi_scale = args.lumi_scale
43print(
'Run on data corresponding to {:.2f} fb^-1 ...'.format(lumi * lumi_scale / 1000.0))
45if args.full_dataset: dataset_path =
"root://eospublic.cern.ch//eos/opendata/atlas/OutreachDatasets/2020-01-22"
46else: dataset_path =
"root://eospublic.cern.ch//eos/root-eos/reduced_atlas_opendata/w"
50files = json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)),
"df105_WBosonAnalysis.json")))
51processes = files.keys()
64 samples.append(sample)
65 df[sample] =
ROOT.RDataFrame(
"mini",
"{}/1lep/{}/{}.1lep.root".format(dataset_path, folder, sample))
68 if args.full_dataset
and lumi_scale < 1.0:
69 df[sample] = df[sample].
Range(
int(num_events * lumi_scale))
74ROOT.gInterpreter.Declare(
"""
75bool GoodElectronOrMuon(int type, float pt, float eta, float phi, float e, float trackd0pv, float tracksigd0pv, float z0)
77 ROOT::Math::PtEtaPhiEVector p(pt / 1000.0, eta, phi, e / 1000.0);
78 if (abs(z0 * sin(p.theta())) > 0.5) return false;
79 if (type == 11 && abs(eta) < 2.46 && (abs(eta) < 1.37 || abs(eta) > 1.52)) {
80 if (abs(trackd0pv / tracksigd0pv) > 5) return false;
83 if (type == 13 && abs(eta) < 2.5) {
84 if (abs(trackd0pv / tracksigd0pv) > 3) return false;
93 df[s] = df[s].Filter(
"trigE || trigM")\
94 .Filter(
"met_et > 30000")
97 df[s] = df[s].Define(
"good_lep",
"lep_isTightID && lep_pt > 35000 && lep_ptcone30 / lep_pt < 0.1 && lep_etcone20 / lep_pt < 0.1")\
98 .Filter(
"ROOT::VecOps::Sum(good_lep) == 1")
101 df[s] = df[s].Define(
"idx",
"ROOT::VecOps::ArgMax(good_lep)")\
102 .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])")
107 df[s] = df[s].Define(
"weight",
"1.0")
109 df[s] = df[s].Define(
"weight",
"scaleFactor_ELE * scaleFactor_MUON * scaleFactor_LepTRIGGER * scaleFactor_PILEUP * mcWeight * {} / {} * {}".format(xsecs[s], sumws[s], lumi))
112ROOT.gInterpreter.Declare(
"""
113float ComputeTransverseMass(float met_et, float met_phi, float lep_pt, float lep_eta, float lep_phi, float lep_e)
115 ROOT::Math::PtEtaPhiEVector met(met_et, 0, met_phi, met_et);
116 ROOT::Math::PtEtaPhiEVector lep(lep_pt, lep_eta, lep_phi, lep_e);
117 return (met + lep).Mt() / 1000.0;
123 df[s] = df[s].Define(
"mt_w",
"ComputeTransverseMass(met_et, met_phi, lep_pt[idx], lep_eta[idx], lep_phi[idx], lep_E[idx])")
124 histos[s] = df[s].Histo1D(
ROOT.RDF.TH1DModel(s,
"mt_w", 24, 60, 180),
"mt_w",
"weight")
134def merge_histos(label):
136 for i, d
in enumerate(files[label]):
137 t = histos[d[1]].GetValue()
138 if i == 0: h = t.Clone()
140 h.SetNameTitle(label, label)
143data = merge_histos(
"data")
144wjets = merge_histos(
"wjets")
145zjets = merge_histos(
"zjets")
146ttbar = merge_histos(
"ttbar")
147diboson = merge_histos(
"diboson")
148singletop = merge_histos(
"singletop")
153ROOT.gROOT.SetStyle(
"ATLAS")
156c = ROOT.TCanvas(
"c",
"", 600, 600)
162stack = ROOT.THStack()
164 [singletop, diboson, ttbar, zjets, wjets],
165 [(208, 240, 193), (195, 138, 145), (155, 152, 204), (248, 206, 104), (222, 90, 106)]):
168 h.SetFillColor(ROOT.TColor.GetColor(*color))
171stack.GetXaxis().SetLabelSize(0.04)
172stack.GetXaxis().SetTitleSize(0.045)
173stack.GetXaxis().SetTitleOffset(1.3)
174stack.GetXaxis().SetTitle(
"m_{T}^{W#rightarrow l#nu} [GeV]")
175stack.GetYaxis().SetTitle(
"Events")
176stack.GetYaxis().SetLabelSize(0.04)
177stack.GetYaxis().SetTitleSize(0.045)
178stack.SetMaximum(1e10 * args.lumi_scale)
182data.SetMarkerStyle(20)
183data.SetMarkerSize(1.2)
185data.SetLineColor(ROOT.kBlack)
189legend = ROOT.TLegend(0.60, 0.65, 0.92, 0.92)
190legend.SetTextFont(42)
191legend.SetFillStyle(0)
192legend.SetBorderSize(0)
193legend.SetTextSize(0.04)
194legend.SetTextAlign(32)
195legend.AddEntry(data,
"Data" ,
"lep")
196legend.AddEntry(wjets,
"W+jets",
"f")
197legend.AddEntry(zjets,
"Z+jets",
"f")
198legend.AddEntry(ttbar,
"t#bar{t}",
"f")
199legend.AddEntry(diboson,
"Diboson",
"f")
200legend.AddEntry(singletop,
"Single top",
"f")
207text.SetTextSize(0.045)
208text.DrawLatex(0.21, 0.86,
"ATLAS")
210text.DrawLatex(0.21 + 0.16, 0.86,
"Open Data")
211text.SetTextSize(0.04)
212text.DrawLatex(0.21, 0.80,
"#sqrt{{s}} = 13 TeV, {:.2f} fb^{{-1}}".format(lumi * args.lumi_scale / 1000.0))
215c.SaveAs(
"df105_WBosonAnalysis.png")
216print(
"Saved figure to df105_WBosonAnalysis.png")
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.
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
A struct which stores the parameters of a TH1D.