def test_get_matching_cuts_path_with_asterisk(self): """ Test getMatchingCuts when supplied with a cut path with an asterisk. """ # beginning base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "*/CutPreselectionSR") self.assertEqual(cuts.GetEntries(), 1) self.assertEqual(cuts.At(0).GetName(), "CutPreselectionSR") # mid base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutTrigger/*/CutPreselectionSR") self.assertEqual(cuts.GetEntries(), 1) self.assertEqual(cuts.At(0).GetName(), "CutPreselectionSR") # end base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutTrigger/CutOS/CutBVeto/*") self.assertEqual(cuts.GetEntries(), 4) self.assertEqual(cuts.At(0).GetName(), "CutBVeto") self.assertEqual(cuts.At(1).GetName(), "CutPreselectionSR") self.assertEqual(cuts.At(2).GetName(), "CutVbfSR") self.assertEqual(cuts.At(3).GetName(), "CutBoostedSR")
def test_get_matching_cuts_path_with_question_mark(self): """ Test getMatchingCuts when supplied with a cut path with a question mark. """ # beginning base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "?/CutOS") self.assertEqual(cuts.GetEntries(), 1) self.assertEqual(cuts.At(0).GetName(), "CutOS") # mid base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutTrigger/CutOS/?/CutPreselectionSR") self.assertEqual(cuts.GetEntries(), 1) self.assertEqual(cuts.At(0).GetName(), "CutPreselectionSR") # end base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutTrigger/CutOS/?") self.assertEqual(cuts.GetEntries(), 2) self.assertEqual(cuts.At(0).GetName(), "CutBVeto") self.assertEqual(cuts.At(1).GetName(), "CutBReq")
def make_reso(file_name, out_tag, show, thr=0.08): f = TFile(file_name, "READ") h = f.Get("qa-tracking-resolution/impactParameter/impactParameterRPhiVsPt") h.SetDirectory(0) f.Close() h.SetBit(TH1.kNoStats) if show: c = "2d" + out_tag c = TCanvas(c, c) canvases.append(c) c.SetLogz() h.Draw("COLZ") o = TObjArray() h.GetYaxis().SetRangeUser(-200, 200) h.FitSlicesY(0, 0, -1, 0, "QNR", o) h.GetYaxis().SetRange() hmean = o.At(1) hsigma = o.At(2) if show: hmean = hmean.DrawCopy("SAME") hsigma = hsigma.DrawCopy("SAME") hsigma.SetLineColor(2) c.Update() g = TGraph() g.SetName(out_tag) g.SetTitle(out_tag) g.GetXaxis().SetTitle(h.GetXaxis().GetTitle()) g.GetYaxis().SetTitle(h.GetYaxis().GetTitle()) for i in range(1, h.GetNbinsX() + 1): x = h.GetXaxis().GetBinCenter(i) if x < thr: continue hh = h.ProjectionY(f"{h.GetName()}_{i}", i, i) y = hh.GetRMS() y = hsigma.GetBinContent(hsigma.GetXaxis().FindBin(x)) g.SetPoint(g.GetN(), x, y) if show: can2 = "1d" + out_tag can2 = TCanvas(can2, can2) canvases.append(can2) can2.SetLogy() can2.SetLogx() g.SetMarkerStyle(8) g.Draw() can2.Update() print(g.Eval(0.1)) # input("press enter to continue") g.SaveAs(f"{out_tag}.root") return g
def test_get_matching_cuts_path_with_two_trailing_asterisk(self): """ Test getMatchingCuts when supplied with a cut path with two trailing asterisk. """ base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutVbfTopCR/*/*") self.assertEqual(cuts.GetEntries(), 1) self.assertEqual(cuts.At(0).GetName(), "CutVbfTopCR")
def test_get_matching_cuts_single_name(self): """ Test getMatchingCuts when supplied with a single (existing) cut name. """ base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutTrigger") self.assertEqual(cuts.GetEntries(), 1) self.assertEqual(cuts.At(0).GetName(), "CutTrigger")
def test_get_matching_cuts_path_with_optional_asterisk(self): """ Test getMatchingCuts when supplied with a cut path containing an optional asterisk """ base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutPreselectionSR/*/CutVbfSR") self.assertEqual(cuts.GetEntries(), 1) self.assertEqual(cuts.At(0).GetName(), "CutVbfSR")
def test_get_matching_cuts_path_non_wildcards(self): """ Test getMatchingCuts when supplied with a cut path. """ base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutTrigger/CutOS/CutBVeto/CutPreselectionSR") self.assertEqual(cuts.GetEntries(), 1) self.assertEqual(cuts.At(0).GetName(), "CutPreselectionSR")
def test_get_matching_cuts_path_with_asterisk_inner_name(self): """ Test getMatchingCuts when supplied with a cut path with an asterisk in a cut name. """ # mid base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutTrigger/CutOS/CutB*/CutPreselection*R") self.assertEqual(cuts.GetEntries(), 2) self.assertEqual(cuts.At(0).GetName(), "CutPreselectionSR") self.assertEqual(cuts.At(1).GetName(), "CutPreselectionTopCR") # end base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutTrigger/CutOS/CutB*") self.assertEqual(cuts.GetEntries(), 2) self.assertEqual(cuts.At(0).GetName(), "CutBVeto") self.assertEqual(cuts.At(1).GetName(), "CutBReq")
def test_get_matching_cuts_path_non_base(self): """ Test getMatchingCuts when supplied with a cut path not starting at the base cut. """ base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutPreselection*/*SR") self.assertEqual(cuts.GetEntries(), 2) self.assertEqual(cuts.At(0).GetName(), "CutVbfSR") self.assertEqual(cuts.At(1).GetName(), "CutBoostedSR") base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutPreselectionSR/CutVbf?R") self.assertEqual(cuts.GetEntries(), 1) self.assertEqual(cuts.At(0).GetName(), "CutVbfSR") base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutOS/?") self.assertEqual(cuts.GetEntries(), 2) self.assertEqual(cuts.At(0).GetName(), "CutBVeto") self.assertEqual(cuts.At(1).GetName(), "CutBReq") base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutOS/*") self.assertEqual(cuts.GetEntries(), 9) self.assertEqual(cuts.At(0).GetName(), "CutOS") self.assertEqual(cuts.At(1).GetName(), "CutBVeto") self.assertEqual(cuts.At(2).GetName(), "CutPreselectionSR") self.assertEqual(cuts.At(3).GetName(), "CutVbfSR") self.assertEqual(cuts.At(4).GetName(), "CutBoostedSR") self.assertEqual(cuts.At(5).GetName(), "CutBReq") self.assertEqual(cuts.At(6).GetName(), "CutPreselectionTopCR") self.assertEqual(cuts.At(7).GetName(), "CutVbfTopCR") self.assertEqual(cuts.At(8).GetName(), "CutBoostedTopCR") base = self.get_cut_hierarchy() cuts = TObjArray() base.getMatchingCuts(cuts, "CutOS/Cut*") self.assertEqual(cuts.GetEntries(), 2) self.assertEqual(cuts.At(0).GetName(), "CutBVeto") self.assertEqual(cuts.At(1).GetName(), "CutBReq")
def getCurve(h): # Temporary draw c = TCanvas() c.cd() h.Smooth() h.SetContour(2) #h.Draw("COLZ") h.Draw("CONT Z LIST") c.Update() # Get contours curves = [] conts = TObjArray(gROOT.GetListOfSpecials().FindObject("contours")) gs = TGraphSmooth("normal") gin = TGraph(conts.At(0).At(0)) gout = gs.SmoothSuper(gin, "", 3) x_m = array('d', []) x_p = array('d', []) y_m = array('d', []) y_p = array('d', []) for p in xrange(0, gout.GetN()): gr_x = ROOT.Double(0.) gr_y = ROOT.Double(0.) gout.GetPoint(p, gr_x, gr_y) x_m.append(-gr_x) y_m.append(-gr_y) x_p.append(gr_x) y_p.append(gr_y) # if opt == 'w': # x_p[0] = 0. # x_m[0] = 0. curves.append(TGraph(len(x_p), x_p, y_p)) curves.append(TGraph(len(x_m), x_m, y_m)) curves.append(TGraph(len(x_p), x_p, y_m)) curves.append(TGraph(len(x_m), x_m, y_p)) c.Close() return curves