def GetROC(htest_s, htest_b): ''' Get ROC curve (signal efficiency vs bkg efficiency) ''' # Calculate signal and background efficiency vs output xvalue, eff_s, eff_b, error = CalcEfficiency(htest_s, htest_b) graph_roc = plot.GetGraph(eff_s, eff_b, error, error, error, error) return graph_roc
def PlotTGraph(xVals, xErrs, yVals, yErrs, saveDir, saveName, jsonWr, saveFormats): # Create a TGraph object graph = plot.GetGraph(xVals, yVals, xErrs, xErrs, yErrs, yErrs) # Create a TCanvas object ROOT.gStyle.SetOptStat(0) canvas = plot.CreateCanvas() canvas.cd() #canvas.SetLogy() # Create the TGraph with asymmetric errors tgraph = ROOT.TGraphAsymmErrors(len(xVals), array.array("d", xVals), array.array("d", yVals), array.array("d", xErrs), array.array("d", xErrs), array.array("d", yErrs), array.array("d", yErrs)) tgraph.SetName(saveName) if "efficiency" in saveName.lower(): legName = "efficiency" if saveName.lower().endswith("sig"): plot.ApplyStyle(tgraph, ROOT.kBlue) else: plot.ApplyStyle(tgraph, ROOT.kRed) elif "significance" in saveName.lower(): legName = "significance" if saveName.lower().endswith("sig"): plot.ApplyStyle(tgraph, ROOT.kGreen) else: plot.ApplyStyle(tgraph, ROOT.kGreen + 3) else: plot.ApplyStyle(tgraph, ROOT.kOrange) # Draw the TGraph tgraph.GetXaxis().SetLimits(-0.05, 1.0) #tgraph.SetMaximum(1.1) #tgraph.SetMinimum(0) tgraph.Draw("AC") # Create legend leg = plot.CreateLegend(0.60, 0.70, 0.85, 0.80) leg.AddEntry(tgraph, legName, "l") leg.Draw() plot.SavePlot(canvas, saveDir, saveName, saveFormats) canvas.Close() # Write the Tgraph into the JSON file jsonWr.addGraph(saveName, tgraph) return
def PlotEfficiency(htest_s, htest_b, saveDir, saveName, saveFormats): ROOT.gStyle.SetOptStat(0) canvas = plot.CreateCanvas() canvas.cd() canvas.SetLeftMargin(0.145) canvas.SetRightMargin(0.11) # Calculate signal and background efficiency vs output xvalue, eff_s, eff_b, error = CalcEfficiency(htest_s, htest_b) graph_s = plot.GetGraph(xvalue, eff_s, error, error, error, error) graph_b = plot.GetGraph(xvalue, eff_b, error, error, error, error) plot.ApplyStyle(graph_s, ROOT.kBlue) plot.ApplyStyle(graph_b, ROOT.kRed) # Calculate significance vs output h_signif0, h_signif1 = CalcSignificance(htest_s, htest_b) plot.ApplyStyle(h_signif0, ROOT.kGreen) plot.ApplyStyle(h_signif1, ROOT.kGreen + 3) #=== Get maximum of significance maxSignif0 = h_signif0.GetMaximum() maxSignif1 = h_signif1.GetMaximum() maxSignif = max(maxSignif0, maxSignif1) # Normalize significance h_signifScaled0 = h_signif0.Clone("signif0") h_signifScaled0.Scale(1. / float(maxSignif)) h_signifScaled1 = h_signif1.Clone("signif1") h_signifScaled1.Scale(1. / float(maxSignif)) #Significance: Get new maximum ymax = max(h_signifScaled0.GetMaximum(), h_signifScaled1.GetMaximum()) for obj in [graph_s, graph_b, h_signifScaled0, h_signifScaled1]: obj.GetXaxis().SetTitle("Output") obj.GetYaxis().SetTitle("Efficiency") obj.SetMaximum(ymax * 1.1) obj.SetMinimum(0) #Draw h_signifScaled0.Draw("HIST") h_signifScaled1.Draw("HIST SAME") graph_s.Draw("PL SAME") graph_b.Draw("PL SAME") graph = plot.CreateGraph([0.5, 0.5], [0, ymax * 1.1]) graph.Draw("same") #Legend leg = plot.CreateLegend(0.50, 0.25, 0.85, 0.45) leg.AddEntry(graph_s, "Signal Efficiency", "l") leg.AddEntry(graph_b, "Bkg Efficiency", "l") leg.AddEntry(h_signifScaled0, "S/#sqrt{S+B}", "l") leg.AddEntry(h_signifScaled1, "2#times(#sqrt{S+B} - #sqrt{B})", "l") leg.Draw() # Define Right Axis (Significance) signifColor = ROOT.kGreen + 2 rightAxis = ROOT.TGaxis(1, 0, 1, 1.1, 0, 1.1 * maxSignif, 510, "+L") rightAxis.SetLineColor(signifColor) rightAxis.SetLabelColor(signifColor) rightAxis.SetTitleColor(signifColor) rightAxis.SetTitleOffset(1.25) rightAxis.SetLabelOffset(0.005) rightAxis.SetLabelSize(0.04) rightAxis.SetTitleSize(0.045) rightAxis.SetTitle("Significance") rightAxis.Draw() plot.SavePlot(canvas, saveDir, saveName, saveFormats) canvas.Close() return