28from ROOT.Experimental import RCanvas, RText, RAttrText, RAttrFont, RPadPos, TObjectDrawable
31parser = argparse.ArgumentParser()
36 help=
"Run only on a fraction of the total available 10 fb^-1 (only usable together with --full-dataset)",
42 help=
"Use the full dataset (use --lumi-scale to run only on a fraction of it)",
44parser.add_argument(
"-b", action=
"store_true", default=
False, help=
"Use ROOT batch mode")
49 help=
"Use implicit multi threading (for the full dataset only possible with --lumi-scale 1.0)",
51if "df105.py" in sys.argv[0]:
53 args = parser.parse_args()
56 args = parser.parse_args(args=[])
59 ROOT.gROOT.SetBatch(
True)
63if not args.full_dataset:
66 lumi_scale = args.lumi_scale
68print(
"Run on data corresponding to {:.2f} fb^-1 ...".format(lumi * lumi_scale / 1000.0))
71 dataset_path =
"root://eospublic.cern.ch//eos/opendata/atlas/OutreachDatasets/2020-01-22"
73 dataset_path =
"root://eospublic.cern.ch//eos/root-eos/reduced_atlas_opendata/w"
77files = json.load(open(os.path.join(ROOT.gROOT.GetTutorialsDir(),
"analysis/dataframe/df105_WBosonAnalysis.json")))
78processes = files.keys()
91 samples.append(sample)
92 df[sample] =
ROOT.RDataFrame(
"mini",
"{}/1lep/{}/{}.1lep.root".format(dataset_path, folder, sample))
95 if args.full_dataset
and lumi_scale < 1.0:
96 df[sample] = df[sample].
Range(
int(num_events * lumi_scale))
101ROOT.gInterpreter.Declare(
"""
102bool GoodElectronOrMuon(int type, float pt, float eta, float phi, float e, float trackd0pv, float tracksigd0pv, float z0)
104 ROOT::Math::PtEtaPhiEVector p(pt / 1000.0, eta, phi, e / 1000.0);
105 if (abs(z0 * sin(p.theta())) > 0.5) return false;
106 if (type == 11 && abs(eta) < 2.46 && (abs(eta) < 1.37 || abs(eta) > 1.52)) {
107 if (abs(trackd0pv / tracksigd0pv) > 5) return false;
110 if (type == 13 && abs(eta) < 2.5) {
111 if (abs(trackd0pv / tracksigd0pv) > 3) return false;
120 df[s] = df[s].Filter(
"trigE || trigM").Filter(
"met_et > 30000")
126 "good_lep",
"lep_isTightID && lep_pt > 35000 && lep_ptcone30 / lep_pt < 0.1 && lep_etcone20 / lep_pt < 0.1"
128 .Filter(
"ROOT::VecOps::Sum(good_lep) == 1")
134 .Define(
"idx",
"ROOT::VecOps::ArgMax(good_lep)")
136 "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])"
143 df[s] = df[s].Define(
"weight",
"1.0")
145 df[s] = df[s].Define(
147 "scaleFactor_ELE * scaleFactor_MUON * scaleFactor_LepTRIGGER * scaleFactor_PILEUP * mcWeight * {} / {} * {}".format(
148 xsecs[s], sumws[s], lumi
153ROOT.gInterpreter.Declare(
"""
154float ComputeTransverseMass(float met_et, float met_phi, float lep_pt, float lep_eta, float lep_phi, float lep_e)
156 ROOT::Math::PtEtaPhiEVector met(met_et, 0, met_phi, met_et);
157 ROOT::Math::PtEtaPhiEVector lep(lep_pt, lep_eta, lep_phi, lep_e);
158 return (met + lep).Mt() / 1000.0;
164 df[s] = df[s].Define(
165 "mt_w",
"ComputeTransverseMass(met_et, met_phi, lep_pt[idx], lep_eta[idx], lep_phi[idx], lep_E[idx])"
167 histos[s] = df[s].Histo1D(
ROOT.RDF.TH1DModel(s,
"mt_w", 24, 60, 180),
"mt_w",
"weight")
178def merge_histos(label):
180 for i, d
in enumerate(files[label]):
181 t = histos[d[1]].GetValue()
186 h.SetNameTitle(label, label)
190data = merge_histos(
"data")
191wjets = merge_histos(
"wjets")
192zjets = merge_histos(
"zjets")
193ttbar = merge_histos(
"ttbar")
194diboson = merge_histos(
"diboson")
195singletop = merge_histos(
"singletop")
200ROOT.gROOT.SetStyle(
"ATLAS")
203c = RCanvas.Create(
"df105_WBosonAnalysis")
205frame.margins.top = 0.05
206frame.margins.right = 0.05
207frame.margins.left = 0.16
208frame.margins.bottom = 0.16
214frame.x.title.value =
"m_{T}^{W#rightarrow l#nu} [GeV]"
215frame.x.title.size = 0.045
216frame.x.title.offset = 0.01
217frame.x.labels.size = 0.04
220frame.y.max = 1e10 * args.lumi_scale
222frame.y.title.value =
"Events"
223frame.y.title.size = 0.045
224frame.y.labels.size = 0.04
230stack = ROOT.THStack()
232 [singletop, diboson, ttbar, zjets, wjets],
233 [(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)],
236 h.SetLineColor(
"black")
237 h.SetFillColor(ROOT.TColor.GetColor(*color))
241c.Add[TObjectDrawable]().Set(stack,
"HIST SAME")
244data.SetMarkerStyle(20)
245data.SetMarkerSize(1.2)
247data.SetLineColor(
"black")
248c.Add[TObjectDrawable]().Set(data,
"E SAME")
251legend = ROOT.TLegend(0.60, 0.65, 0.92, 0.92)
252legend.SetTextFont(42)
253legend.SetFillStyle(0)
254legend.SetBorderSize(0)
255legend.SetTextSize(0.04)
256legend.SetTextAlign(32)
257legend.AddEntry(data,
"Data",
"lep")
258legend.AddEntry(wjets,
"W+jets",
"f")
259legend.AddEntry(zjets,
"Z+jets",
"f")
260legend.AddEntry(ttbar,
"t#bar{t}",
"f")
261legend.AddEntry(diboson,
"Diboson",
"f")
262legend.AddEntry(singletop,
"Single top",
"f")
263c.Add[TObjectDrawable]().Set(legend)
266lbl1 = c.Add[RText](RPadPos(0.05, 0.88),
"ATLAS")
268lbl1.text.font = RAttrFont.kArialBoldOblique
270lbl1.text.align = RAttrText.kLeftBottom
271lbl2 = c.Add[RText](RPadPos(0.05 + 0.20, 0.88),
"Open Data")
273lbl2.text.font = RAttrFont.kArial
275lbl2.text.align = RAttrText.kLeftBottom
277 RPadPos(0.05, 0.82),
"#sqrt{{s}} = 13 TeV, {:.2f} fb^{{-1}}".format(lumi * args.lumi_scale / 1000.0)
280lbl3.text.font = RAttrFont.kArial
282lbl3.text.align = RAttrText.kLeftBottom
289if c.SaveAs(
"df105.png"):
290 print(
"Saved figure to df105.png")
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
Namespace for ROOT features in testing.
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.