31parser = argparse.ArgumentParser()
32parser.add_argument(
"--lumi-scale", type=float, default=0.001,
33 help=
"Run only on a fraction of the total available 10 fb^-1 (only usable together with --full-dataset)")
34parser.add_argument(
"--full-dataset", action=
"store_true", default=
False,
35 help=
"Use the full dataset (use --lumi-scale to run only on a fraction of it)")
36parser.add_argument(
"-b", action=
"store_true", default=
False, help=
"Use ROOT batch mode")
37parser.add_argument(
"-t", action=
"store_true", default=
False, help=
"Use implicit multi threading (for the full dataset only possible with --lumi-scale 1.0)")
38if 'df105_WBosonAnalysis.py' in sys.argv[0]:
40 args = parser.parse_args()
43 args = parser.parse_args(args=[])
45if args.b: ROOT.gROOT.SetBatch(
True)
48if not args.full_dataset: lumi_scale = 0.001
49else: lumi_scale = args.lumi_scale
51print(
'Run on data corresponding to {:.2f} fb^-1 ...'.format(lumi * lumi_scale / 1000.0))
53if args.full_dataset: dataset_path =
"root://eospublic.cern.ch//eos/opendata/atlas/OutreachDatasets/2020-01-22"
54else: dataset_path =
"root://eospublic.cern.ch//eos/root-eos/reduced_atlas_opendata/w"
58files = json.load(open(os.path.join(ROOT.gROOT.GetTutorialsDir(),
"analysis/dataframe/df105_WBosonAnalysis.json")))
59processes = files.keys()
72 samples.append(sample)
73 df[sample] =
ROOT.RDataFrame(
"mini",
"{}/1lep/{}/{}.1lep.root".format(dataset_path, folder, sample))
76 if args.full_dataset
and lumi_scale < 1.0:
77 df[sample] = df[sample].
Range(
int(num_events * lumi_scale))
82ROOT.gInterpreter.Declare(
"""
83bool GoodElectronOrMuon(int type, float pt, float eta, float phi, float e, float trackd0pv, float tracksigd0pv, float z0)
85 ROOT::Math::PtEtaPhiEVector p(pt / 1000.0, eta, phi, e / 1000.0);
86 if (abs(z0 * sin(p.theta())) > 0.5) return false;
87 if (type == 11 && abs(eta) < 2.46 && (abs(eta) < 1.37 || abs(eta) > 1.52)) {
88 if (abs(trackd0pv / tracksigd0pv) > 5) return false;
91 if (type == 13 && abs(eta) < 2.5) {
92 if (abs(trackd0pv / tracksigd0pv) > 3) return false;
101 df[s] = df[s].Filter(
"trigE || trigM")\
102 .Filter(
"met_et > 30000")
105 df[s] = df[s].Define(
"good_lep",
"lep_isTightID && lep_pt > 35000 && lep_ptcone30 / lep_pt < 0.1 && lep_etcone20 / lep_pt < 0.1")\
106 .Filter(
"ROOT::VecOps::Sum(good_lep) == 1")
109 df[s] = df[s].Define(
"idx",
"ROOT::VecOps::ArgMax(good_lep)")\
110 .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])")
115 df[s] = df[s].Define(
"weight",
"1.0")
117 df[s] = df[s].Define(
"weight",
"scaleFactor_ELE * scaleFactor_MUON * scaleFactor_LepTRIGGER * scaleFactor_PILEUP * mcWeight * {} / {} * {}".format(xsecs[s], sumws[s], lumi))
120ROOT.gInterpreter.Declare(
"""
121float ComputeTransverseMass(float met_et, float met_phi, float lep_pt, float lep_eta, float lep_phi, float lep_e)
123 ROOT::Math::PtEtaPhiEVector met(met_et, 0, met_phi, met_et);
124 ROOT::Math::PtEtaPhiEVector lep(lep_pt, lep_eta, lep_phi, lep_e);
125 return (met + lep).Mt() / 1000.0;
131 df[s] = df[s].Define(
"mt_w",
"ComputeTransverseMass(met_et, met_phi, lep_pt[idx], lep_eta[idx], lep_phi[idx], lep_E[idx])")
132 histos[s] = df[s].Histo1D(
ROOT.RDF.TH1DModel(s,
"mt_w", 24, 60, 180),
"mt_w",
"weight")
142def merge_histos(label):
144 for i, d
in enumerate(files[label]):
145 t = histos[d[1]].GetValue()
146 if i == 0: h = t.Clone()
148 h.SetNameTitle(label, label)
151data = merge_histos(
"data")
152wjets = merge_histos(
"wjets")
153zjets = merge_histos(
"zjets")
154ttbar = merge_histos(
"ttbar")
155diboson = merge_histos(
"diboson")
156singletop = merge_histos(
"singletop")
161ROOT.gROOT.SetStyle(
"ATLAS")
164c = ROOT.TCanvas(
"c",
"", 600, 600)
170stack = ROOT.THStack()
172 [singletop, diboson, ttbar, zjets, wjets],
173 [(0.82, 0.94, 0.76), (0.76, 0.54, 0.57), (0.61, 0.6, 0.8), (0.97, 0.81, 0.41), (0.87, 0.35, 0.42)]):
175 h.SetLineColor(
"black")
176 h.SetFillColor(ROOT.TColor.GetColor(*color))
181stack.GetXaxis().SetLabelSize(0.04)
182stack.GetXaxis().SetTitleSize(0.045)
183stack.GetXaxis().SetTitleOffset(1.3)
184stack.GetXaxis().SetTitle(
"m_{T}^{W#rightarrow l#nu} [GeV]")
185stack.GetYaxis().SetTitle(
"Events")
186stack.GetYaxis().SetLabelSize(0.04)
187stack.GetYaxis().SetTitleSize(0.045)
188stack.SetMaximum(1e10 * args.lumi_scale)
192data.SetMarkerStyle(20)
193data.SetMarkerSize(1.2)
195data.SetLineColor(
"black")
199legend = ROOT.TLegend(0.60, 0.65, 0.92, 0.92)
200legend.SetTextFont(42)
201legend.SetFillStyle(0)
202legend.SetBorderSize(0)
203legend.SetTextSize(0.04)
204legend.SetTextAlign(32)
205legend.AddEntry(data,
"Data" ,
"lep")
206legend.AddEntry(wjets,
"W+jets",
"f")
207legend.AddEntry(zjets,
"Z+jets",
"f")
208legend.AddEntry(ttbar,
"t#bar{t}",
"f")
209legend.AddEntry(diboson,
"Diboson",
"f")
210legend.AddEntry(singletop,
"Single top",
"f")
217text.SetTextSize(0.045)
218text.DrawLatex(0.21, 0.86,
"ATLAS")
220text.DrawLatex(0.21 + 0.16, 0.86,
"Open Data")
221text.SetTextSize(0.04)
222text.DrawLatex(0.21, 0.80,
"#sqrt{{s}} = 13 TeV, {:.2f} fb^{{-1}}".format(lumi * args.lumi_scale / 1000.0))
225c.SaveAs(
"df105_WBosonAnalysis.png")
226print(
"Saved figure to df105_WBosonAnalysis.png")
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
unsigned int RunGraphs(std::vector< RResultHandle > handles)
Run the event loops 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 some basic parameters of a TH1D.