31dataset_spec = os.path.join(ROOT.gROOT.GetTutorialsDir(),
"analysis",
"dataframe",
"df106_HiggsToFourLeptons_spec.json")
39df = df.DefinePerSample(
"xsecs",
'rdfsampleinfo_.GetD("xsecs")')
40df = df.DefinePerSample(
"lumi",
'rdfsampleinfo_.GetD("lumi")')
41df = df.DefinePerSample(
"sumws",
'rdfsampleinfo_.GetD("sumws")')
42df = df.DefinePerSample(
"sample_category",
'rdfsampleinfo_.GetS("sample_category")')
45ROOT.gInterpreter.Declare(
47float scale(unsigned int slot, const ROOT::RDF::RSampleInfo &id){
48 return id.Contains("mc_363490.llll.4lep.root") ? 1.3f : 1.0f;
53df = df.DefinePerSample(
"scale",
"scale(rdfslot_, rdfsampleinfo_)")
56ROOT.gInterpreter.Declare(
60bool GoodElectronsAndMuons(const RVecI &type, const RVecF &pt, const RVecF &eta, const RVecF &phi, const RVecF &e, const RVecF &trackd0pv, const RVecF &tracksigd0pv, const RVecF &z0)
62 for (size_t i = 0; i < type.size(); i++) {
63 ROOT::Math::PtEtaPhiEVector p(0.001*pt[i], eta[i], phi[i], 0.001*e[i]);
65 if (pt[i] < 7000 || abs(eta[i]) > 2.47 || abs(trackd0pv[i] / tracksigd0pv[i]) > 5 || abs(z0[i] * sin(p.Theta())) > 0.5) return false;
67 if (abs(trackd0pv[i] / tracksigd0pv[i]) > 5 || abs(z0[i] * sin(p.Theta())) > 0.5) return false;
76df = df.Filter(
"trigE || trigM")
86 "abs(lep_eta) < 2.5 && lep_pt > 5000 && lep_ptcone30 / lep_pt < 0.3 && lep_etcone20 / lep_pt < 0.3",
88 .Filter(
"Sum(good_lep) == 4")
89 .Filter(
"Sum(lep_charge[good_lep]) == 0")
90 .Define(
"goodlep_sumtypes",
"Sum(lep_type[good_lep])")
91 .Filter(
"goodlep_sumtypes == 44 || goodlep_sumtypes == 52 || goodlep_sumtypes == 48")
96 "GoodElectronsAndMuons(lep_type[good_lep], lep_pt[good_lep], lep_eta[good_lep], lep_phi[good_lep], lep_E[good_lep], lep_trackd0pvunbiased[good_lep], lep_tracksigd0pvunbiased[good_lep], lep_z0[good_lep])"
101 df.Define(
"goodlep_pt",
"lep_pt[good_lep]")
102 .Define(
"goodlep_eta",
"lep_eta[good_lep]")
103 .Define(
"goodlep_phi",
"lep_phi[good_lep]")
104 .Define(
"goodlep_E",
"lep_E[good_lep]")
105 .Define(
"goodlep_type",
"lep_type[good_lep]")
109df = df.Filter(
"goodlep_pt[0] > 25000 && goodlep_pt[1] > 15000 && goodlep_pt[2] > 10000")
112ROOT.gInterpreter.Declare(
114double weights(float scaleFactor_1, float scaleFactor_2, float scaleFactor_3, float scaleFactor_4, float scale, float mcWeight, double xsecs, double sumws, double lumi)
116 return scaleFactor_1 * scaleFactor_2 * scaleFactor_3 * scaleFactor_4 * scale * mcWeight * xsecs / sumws * lumi;
122df = df.DefinePerSample(
"isMC",
'rdfsampleinfo_.Contains("mc")')
125 "double x; return isMC ? weights(scaleFactor_ELE, scaleFactor_MUON, scaleFactor_LepTRIGGER, scaleFactor_PILEUP, scale, mcWeight, xsecs, sumws, lumi) : 1.;",
129ROOT.gInterpreter.Declare(
131float ComputeInvariantMass(RVecF pt, RVecF eta, RVecF phi, RVecF e)
133 ROOT::Math::PtEtaPhiEVector p1{pt[0], eta[0], phi[0], e[0]};
134 ROOT::Math::PtEtaPhiEVector p2{pt[1], eta[1], phi[1], e[1]};
135 ROOT::Math::PtEtaPhiEVector p3{pt[2], eta[2], phi[2], e[2]};
136 ROOT::Math::PtEtaPhiEVector p4{pt[3], eta[3], phi[3], e[3]};
137 return 0.001 * (p1 + p2 + p3 + p4).M();
142df = df.Define(
"m4l",
"ComputeInvariantMass(goodlep_pt, goodlep_eta, goodlep_phi, goodlep_E)")
145df.Snapshot(
"tree", ROOT.gROOT.GetTutorialDir().Data() +
"/analysis/dataframe/df106_HiggsToFourLeptons.root", [
"m4l",
"sample_category",
"weight"])
149for sample_category
in [
"data",
"higgs",
"zz",
"other"]:
151 df.Filter(f
'sample_category == "{sample_category}"').Histo1D(
167ROOT.gInterpreter.Declare(
169using namespace ROOT::VecOps;
173 const std::vector<double> x{5.50e3, 5.52e3, 12.54e3, 17.43e3, 22.40e3, 27.48e3, 30e3, 10000e3};
174 const std::vector<double> y{0.06628, 0.06395, 0.06396, 0.03372, 0.02441, 0.01403, 0, 0};
178 VaryHelper() : graph(x.size(), x.data(), y.data()) {}
179 RVec<double> operator()(const double &w, const RVecF &pt, const RVec<unsigned int> &type)
181 const auto v = Mean(Map(pt[type == 11], [this](auto p)
182 {return this->graph.Eval(p); })
184 return RVec<double>{(1 + v) * w, (1 - v) * w};
188VaryHelper variationsFactory;
194 df.Filter(
"isMC == true")
195 .Vary(
"weight",
"variationsFactory(weight, goodlep_pt, goodlep_type)", [
"up",
"down"])
204for i
in range(0, histos_mc[
"nominal"].GetXaxis().GetNbins()):
206 histos_mc[
"nominal"].SetBinError(
207 i, (histos_mc[
"weight:up"].GetBinContent(i) - histos_mc[
"nominal"].GetBinContent(i))
214ROOT.gROOT.SetStyle(
"ATLAS")
217c1 = ROOT.TCanvas(
"c",
"", 600, 600)
218pad = ROOT.TPad(
"upper_pad",
"", 0, 0, 1, 1)
225stack = ROOT.THStack()
230h_data = histos[0].GetValue().Clone()
231h_higgs = histos[1].GetValue().Clone()
232h_zz = histos[2].GetValue().Clone()
233h_other = histos[3].GetValue().Clone()
235for h, color
in zip([h_other, h_zz, h_higgs], [ROOT.kViolet - 9, ROOT.kAzure - 9, ROOT.kRed + 2]):
238 h.SetFillColor(color)
242stack.GetXaxis().SetLabelSize(0.04)
243stack.GetXaxis().SetTitleSize(0.045)
244stack.GetXaxis().SetTitleOffset(1.3)
245stack.GetXaxis().SetTitle(
"m_{4l}^{H#rightarrow ZZ} [GeV]")
246stack.GetYaxis().SetLabelSize(0.04)
247stack.GetYaxis().SetTitleSize(0.045)
248stack.GetYaxis().SetTitle(
"Events")
250stack.GetYaxis().ChangeLabel(1, -1, 0)
255h_nominal = histos_mc[
"nominal"].DrawClone(
"E2 same")
257h_weight_up = histos_mc[
"weight:up"].DrawClone(
"HIST SAME")
259h_weight_down = histos_mc[
"weight:down"].DrawClone(
"HIST SAME")
262h_data.SetMarkerStyle(20)
263h_data.SetMarkerSize(1.2)
264h_data.SetLineWidth(2)
265h_data.SetLineColor(ROOT.kBlack)
269legend = ROOT.TLegend(0.57, 0.65, 0.94, 0.94)
270legend.SetTextFont(42)
271legend.SetFillStyle(0)
272legend.SetBorderSize(0)
273legend.SetTextSize(0.025)
274legend.SetTextAlign(32)
275legend.AddEntry(h_data,
"Data",
"lep")
276legend.AddEntry(h_higgs,
"Higgs MC",
"f")
277legend.AddEntry(h_zz,
"ZZ MC",
"f")
278legend.AddEntry(h_other,
"Other MC",
"f")
279legend.AddEntry(h_weight_down,
"Total MC Variations Down",
"l")
280legend.AddEntry(h_weight_up,
"Total MC Variations Up",
"l")
281legend.AddEntry(h_nominal,
"Total MC Uncertainty",
"f")
286text.SetTextSize(0.04)
287text.DrawLatexNDC(0.19, 0.85,
"ATLAS")
289text.DrawLatexNDC(0.19 + 0.15, 0.85,
"Open Data")
290text.SetTextSize(0.035)
291text.DrawLatexNDC(0.21, 0.80,
"#sqrt{s} = 13 TeV, 10 fb^{-1}")
296c1.SaveAs(
"df106_HiggsToFourLeptons_python.png")
297print(
"Saved figure to df106_HiggsToFourLeptons_python.png")
Option_t Option_t SetFillStyle
Option_t Option_t SetLineColor
Option_t Option_t SetFillColor
ROOT::RDataFrame FromSpec(const std::string &jsonFile)
Factory method to create an RDataFrame from a JSON specification file.
RResultMap< T > VariationsFor(RResultPtr< T > resPtr)
Produce all required systematic variations for the given result.
void AddProgressBar(ROOT::RDF::RNode df)
Add ProgressBar to a ROOT::RDF::RNode.
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.