def muTMuWInterpCodes(opts={}): cont = [ ("InterpCode=0", ROOT.kRed - 3, "output/twoBin/scenarioC/muTmuW_profiledContour_template0.root"), ("InterpCode=4", ROOT.kGreen, "output/twoBin/scenarioC/muTmuW_profiledContour.root"), ("InterpCode=-1", ROOT.kBlue, "output/twoBin/scenarioC/muTmuW_profiledContour_templateM1.root"), ("InterpCode=-4", ROOT.kGray, "output/twoBin/scenarioC/muTmuW_profiledContour_template14_etasgeneric_M4.root" ), ] leg2 = PyROOTUtils.Legend(0.65, 0.90, textSize=0.03) for name, color, inFile in cont: c68 = drawContours(inFile, "muTmuW", scale=2.0, color=color) container.append(c68) if c68: leg2.AddEntry(c68[0], name, "L") leg2.Draw() leg = PyROOTUtils.Legend(0.2, 0.90, textSize=0.03) leg.AddEntry(SMMarker, "Standard Model", "P") leg.AddEntry(blackSolid, "68% CL full model", "L") leg.AddEntry(blackDashed, "68% CL fixed effective", "L") leg.Draw()
def main(): canvas = ROOT.TCanvas("c", "c", 600, 450) axes = canvas.DrawFrame(105, 0, 160, 12) axes.GetXaxis().SetTitle("m_{H} [GeV]") axes.GetYaxis().SetTitle("-2 ln #Lambda") hLine68 = PyROOTUtils.DrawHLine(1.0, lineStyle=ROOT.kDashed, lineWidth=1) hLine95 = PyROOTUtils.DrawHLine(4.0, lineStyle=ROOT.kDotted, lineWidth=1) g, g_statOnly = content() g2, g2_statOnly = content(123.0, 8.0, ROOT.kRed) # create black line proxies for legend expectedLine = PyROOTUtils.DrawHLine(-10.0, lineWidth=2) statOnlyLine = PyROOTUtils.DrawHLine(-10.0, lineWidth=2, lineStyle=ROOT.kDashed) l1 = PyROOTUtils.Legend(0.94, 0.5, textSize=0.035, valign="bottom", halign="right") l1.AddEntry(expectedLine, "expected", "L") l1.AddEntry(statOnlyLine, "stat only", "L") l1.AddEntry(hLine95, "95% CL", "L") l1.AddEntry(hLine68, "68% CL", "L") l1.Draw() canvas.SaveAs('doc/example.svg') canvas.SaveAs('doc/example.png') canvas.SaveAs('doc/example.eps') print('Image saved to doc/example.{svg|png|eps}.')
def main(): inputs = effectiveModel.getInputs(options.input) for i in inputs: i[2] = unit # This function has to be pickle'able. Lambda functions are not allowed. x = [bins[0], plotRange[0], plotRange[2]] y = [bins[1], plotRange[1], plotRange[3]] h = ROOT.TH2F( "muTmuW", "(#mu^{f}_{ggF+ttH},#mu^{f}_{VBF+VH}) plane;#mu^{f}_{ggF+ttH};#mu^{f}_{VBF+VH};-2 ln #Lambda", x[0], x[1], x[2], y[0], y[1], y[2]) npHistograms = {} effectiveModel.fillHist(h, x, y, inputs, options, npHistograms=npHistograms) PyROOTUtils.subtractMinFromHist(h) outF = effectiveModel.outFileName(options.output, options) fOut = ROOT.TFile.Open(outF, "RECREATE") h.Write() for npH in npHistograms.values(): npH.Write() fOut.Close() print("Output written to: " + outF)
def muTMuWOverviewNegScenarios(opts={}): cont = [ ("1x sys, cat. uni.", ROOT.kRed - 3, "output/twoBin/oneAlpha_catUniversal/muTmuW.root"), ("1x sys, not cat. uni.", ROOT.kGreen, "output/twoBin/oneAlpha_catNonUniversal/muTmuW.root"), ("2x sys, cat. uni.", ROOT.kOrange, "output/twoBin/twoAlpha_catUniversal/muTmuW.root"), ("2x sys, not cat. uni.", ROOT.kBlue, "output/twoBin/twoAlpha_catNonUniversal/muTmuW.root"), ] leg2 = PyROOTUtils.Legend(0.65, 0.90, textSize=0.03) for name, color, inFile in cont: c68 = drawContours(inFile, "profiledNLL", scale=2.0, color=color) c68_f = drawContours(inFile.replace(".root", "_eff.root"), "profiledNLL", scale=2.0, color=color, lineStyle=ROOT.kDashed) container.append((c68, c68_f)) leg2.AddEntry(c68[0], name, "L") leg2.Draw() leg = PyROOTUtils.Legend(0.2, 0.90, textSize=0.03) leg.AddEntry(SMMarker, "Standard Model", "P") leg.AddEntry(blackSolid, "68% CL full model", "L") leg.AddEntry(blackDashed, "68% CL fixed effective", "L") leg.Draw()
def muTMuWOverview(opts={}): cont = [ ("scenarioA", ROOT.kRed - 3, "output/twoBin/scenarioA/muTmuW.root"), ("scenarioB", ROOT.kGreen, "output/twoBin/scenarioB/muTmuW.root"), ("scenarioC", ROOT.kBlue, "output/twoBin/scenarioC/muTmuW.root"), ] leg2 = PyROOTUtils.Legend(0.65, 0.90, textSize=0.03) for name, color, inFile in cont: c68 = drawContours(inFile, "profiledNLL", scale=2.0, color=color) c68_f = drawContours(inFile.replace(".root", "_eff.root"), "profiledNLL", scale=2.0, color=color, lineStyle=ROOT.kDashed) container.append((c68, c68_f)) if c68: leg2.AddEntry(c68[0], name, "L") leg2.Draw() leg = PyROOTUtils.Legend(0.2, 0.90, textSize=0.03) leg.AddEntry(SMMarker, "Standard Model", "P") leg.AddEntry(blackSolid, "68% CL full model", "L") leg.AddEntry(blackDashed, "68% CL fixed effective", "L") leg.Draw()
def profiledContourOverlay(opts={}): if 'box' not in opts: fullFile = "output/twoBin/" + opts['type'] + "/muTmuW.root" else: fullFile = "output/twoBin/" + opts['type'] + "_box/muTmuW.root" effFile = "output/twoBin/" + opts['type'] + "/muTmuW_eff.root" learningSuffix = '' if 'learningFull' in opts: learningSuffix = 'Full' profiledFiles = [ ('aligned', "output/twoBin/" + opts['type'] + "/muTmuW_profiledContour_template0.root", ROOT.kRed, ROOT.kSolid), ('learning', "output/twoBin/" + opts['type'] + "/muTmuW_profiledContour_template20_etasgeneric20_learning" + learningSuffix + ".root", ROOT.kBlue, 5), ] if 'byHand' in opts: profiledFiles.insert( 1, ('by hand', "output/twoBin/" + opts['type'] + "/muTmuW_profiledContour_template10_etasgeneric_M5.root", ROOT.kGreen + 2, ROOT.kDashed)) if 'box' in opts: profiledFiles = [(n, f.replace('.root', '_box1.0.root'), c, s) for n, f, c, s in profiledFiles] PyROOTUtils.DrawText(0.22, 0.88, "Recoupled contours", textSize=0.03) leg2 = PyROOTUtils.Legend(0.22, 0.86, textSize=0.03) for label, fileName, color, lineStyle in profiledFiles: c68_p = drawContours(fileName, "muTmuW", color=color, lineStyle=lineStyle) if c68_p: leg2.AddEntry(c68_p[0], label, "L") leg2.Draw() PyROOTUtils.DrawText(0.66, 0.88, "68% CL contours", textSize=0.03) leg = PyROOTUtils.Legend(0.65, 0.86, textSize=0.03) leg.AddEntry(SMMarker, "Standard Model", "P") c68 = drawContours(fullFile, "profiledNLL", scale=2.0, color=ROOT.kBlack, lineStyle=ROOT.kDashed, lineWidth=3) c68_f = drawContours(effFile, "profiledNLL", scale=2.0, color=ROOT.kBlack, lineStyle=ROOT.kDotted) if c68: leg.AddEntry(c68[0], "full model", "L") if c68_f: leg.AddEntry(c68_f[0], "fixed effective", "L") leg.Draw()
def counting_kVkF(opts): c68_nominal = draw_CouplingContour(opts['modelNominal'], opts, color=ROOT.kBlue) c68_alt = draw_CouplingContour(opts['modelAlt'], opts, color=ROOT.kRed) leg2 = PyROOTUtils.Legend(0.67, 0.35, textSize=0.03, valign="bottom") if c68_nominal: leg2.AddEntry(c68_nominal[0], "nominal", "L") if c68_alt: leg2.AddEntry(c68_alt[0], "uncertainties x1.3", "L") leg2.Draw() leg = PyROOTUtils.Legend(0.67, 0.2, textSize=0.03, valign="bottom") leg.AddEntry(SMMarker, "Standard Model", "P") leg.AddEntry(blackSolid, "68% CL", "L") leg.AddEntry(blackDashed, "95% CL", "L") leg.Draw()
def main(): f = ROOT.TFile.Open(options.input, "READ") w = f.Get(options.wsName) mc = w.obj(options.mcName) data = w.data(options.dataName) # prepare model w.var("mu").setVal(1.0) w.var("mu").setConstant() # get nll nll = getNll(mc.GetPdf(), data) kGam = [100, plotRange[0], plotRange[2]] kGlu = [100, plotRange[1], plotRange[3]] h = ROOT.TH2F( "kGlukGamma", "Couplings in (k_{g},k_{#gamma});#kappa_{#gamma};#kappa_{g};-2 ln #Lambda", kGam[0], kGam[1], kGam[2], kGlu[0], kGlu[1], kGlu[2]) for x in range(kGam[0]): kGamVal = kGam[1] + (x + 0.5) * (kGam[2] - kGam[1]) / kGam[0] print("Progress: %.0f%%" % (100.0 * x / kGam[0])) for y in range(kGlu[0]): kGluVal = kGlu[1] + (y + 0.5) * (kGlu[2] - kGlu[1]) / kGlu[0] muTmuW2ph = kGlukGamma.map_2ph(kGamVal, kGluVal) w.var("muT_2ph").setVal(muTmuW2ph[0]) w.var("muW_2ph").setVal(muTmuW2ph[1]) muTmuW4l = kGlukGamma.map_4l(kGamVal, kGluVal) w.var("muT_4l").setVal(muTmuW4l[0]) w.var("muW_4l").setVal(muTmuW4l[1]) muTmuWlvlv = kGlukGamma.map_lvlv(kGamVal, kGluVal) w.var("muT_lvlv").setVal(muTmuWlvlv[0]) w.var("muW_lvlv").setVal(muTmuWlvlv[1]) minimize(nll) h.SetBinContent(h.FindBin(kGamVal, kGluVal), 2.0 * nll.getVal()) PyROOTUtils.subtractMinFromHist(h) fOut = ROOT.TFile.Open(options.output, "RECREATE") h.Write() fOut.Close() print("Output written to: " + options.output)
def counting_kGlukGamma_overlay(opts): leg2 = PyROOTUtils.Legend(0.65, 0.90, textSize=0.03) leg2.AddEntry(SMMarker, "Standard Model", "P") color = [(ROOT.kAzure - 4, ROOT.kAzure + 2), (ROOT.kRed - 4, ROOT.kRed + 1)] lineStyle = [ (ROOT.kSolid, ROOT.kSolid, ROOT.kDashed, ROOT.kDashed), (ROOT.kSolid, ROOT.kSolid, ROOT.kDashed, ROOT.kDashed), ] lineWidth = [ (2, 1, 2, 1), (2, 1, 2, 1), ] ci = 0 for m in opts['model']: c68, c68_p, c68_n, recoupledLabel, recoupledLabel2 = draw_CouplingContour( m, opts, color[ci][0], color[ci][1], lineStyleFull1s=lineStyle[ci][0], lineStyleFull2s=lineStyle[ci][1], lineStyleRecoupled1s=lineStyle[ci][2], lineStyleRecoupled2s=lineStyle[ci][3], lineWidthFull1s=lineWidth[ci][0], lineWidthFull2s=lineWidth[ci][1], lineWidthRecoupled1s=lineWidth[ci][2], lineWidthRecoupled2s=lineWidth[ci][3], couplingType='kGlukGamma', ) lL = PyROOTUtils.DrawHLine(400, lineWidth=2, lineColor=color[ci][1]) container.append(lL) if 'wideGauss' in m: leg2.AddEntry(lL, 'uncertainties x1.3', "L") else: leg2.AddEntry(lL, 'nominal', "L") ci += 1 leg2.Draw() leg = PyROOTUtils.Legend(0.74, 0.75, textSize=0.03) # leg.AddEntry( bestFitBlack, "Best fit", "P" ) leg.AddEntry(blackSolid, "full", "L") leg.AddEntry(blackDashed, "recoupled", "L") leg.AddEntry(None, "", "") leg.AddEntry(blackSolid, "68% CL", "L") leg.AddEntry(blackSolidThin, "95% CL", "L") leg.Draw()
def main(): f = ROOT.TFile.Open( options.input, "READ" ) w = f.Get( options.wsName ) mc = w.obj( options.mcName ) data = w.data( options.dataName ) # prepare model w.var("mu").setVal( 1.0 ) w.var("mu").setConstant() # get nll nll = getNll( mc.GetPdf(), data ) kGam = [100, plotRange[0], plotRange[2]] kGlu = [100, plotRange[1], plotRange[3]] h = ROOT.TH2F( "kGlukGamma", "Couplings in (k_{g},k_{#gamma});#kappa_{#gamma};#kappa_{g};-2 ln #Lambda", kGam[0], kGam[1], kGam[2], kGlu[0], kGlu[1], kGlu[2] ) for x in range( kGam[0] ): kGamVal = kGam[1] + (x+0.5)*(kGam[2]-kGam[1]) / kGam[0] print( "Progress: %.0f%%" % (100.0*x/kGam[0]) ) for y in range( kGlu[0] ): kGluVal = kGlu[1] + (y+0.5)*(kGlu[2]-kGlu[1]) / kGlu[0] muTmuW2ph = kGlukGamma.map_2ph( kGamVal, kGluVal ) w.var("muT_2ph").setVal( muTmuW2ph[0] ) w.var("muW_2ph").setVal( muTmuW2ph[1] ) muTmuW4l = kGlukGamma.map_4l( kGamVal, kGluVal ) w.var("muT_4l").setVal( muTmuW4l[0] ) w.var("muW_4l").setVal( muTmuW4l[1] ) muTmuWlvlv = kGlukGamma.map_lvlv( kGamVal, kGluVal ) w.var("muT_lvlv").setVal( muTmuWlvlv[0] ) w.var("muW_lvlv").setVal( muTmuWlvlv[1] ) minimize( nll ) h.SetBinContent( h.FindBin( kGamVal, kGluVal ), 2.0*nll.getVal() ) PyROOTUtils.subtractMinFromHist( h ) fOut = ROOT.TFile.Open( options.output, "RECREATE" ) h.Write() fOut.Close() print( "Output written to: "+options.output )
def countingMuTMuWArrowsAtMuHat(opts): modelSuffix = '' if 'interpCode0' in opts: modelSuffix = '_interpCode0' arrows = [] for c in ['2ph', '4l', 'lvlv']: try: with open( "output/atlas_counting/" + c + modelSuffix + "/table_etas.pickle", "rb") as f: etasAll = pickle.load(f) muHat = { 'muT': etasAll['generic20_learning'].values()[0]['muT__hat'], 'muW': etasAll['generic20_learning'].values()[0]['muW__hat'], } arrows = etas.drawArrows('fisherInfo', etasAll['fisherInfo'], muHat, lineWidth=2.0) container.append(arrows) label = PyROOTUtils.DrawText( muHat['muT'], muHat['muW'], { '2ph': 'H#rightarrow#gamma#gamma ', '4l': 'H#rightarrowZZ*#rightarrow4l ', 'lvlv': 'H#rightarrowWW*#rightarrowl#nul#nu ', }[c], textSize=0.03, halign="right", valign="top", NDC=False) container.append(label) except IOError: print("WARNING: Could not open:") print("output/atlas_counting/" + c + modelSuffix + "/table_etas.pickle") except: print("ERROR!!!!!!!!!!!!") leg = PyROOTUtils.Legend(0.2, 0.9, textSize=0.03) for a, p in arrows: leg.AddEntry(a, p.replace("alpha_", ""), "L") leg.Draw()
def counting_kGlukGamma(opts): leg2 = PyROOTUtils.Legend(0.67, 0.77, textSize=0.03) c68, c68_p, c68_n, recoupledLabel, recoupledLabel2 = draw_CouplingContour( opts['model'], opts, couplingType='kGlukGamma') if c68: leg2.AddEntry(c68[0], "full", "L") if c68_n: leg2.AddEntry(c68_n[0], "naive", "L") if c68_p: leg2.AddEntry(c68_p[0], recoupledLabel, "L") if recoupledLabel2: leg2.AddEntry(c68_p[0], recoupledLabel2, "") leg2.AddEntry(None, "", "") leg2.Draw() leg = PyROOTUtils.Legend(0.67, 0.90, textSize=0.03) # leg.AddEntry( bestFitBlack, "Best fit", "P" ) leg.AddEntry(SMMarker, "Standard Model", "P") leg.AddEntry(blackSolid, "68% CL", "L") leg.AddEntry(blackDashed, "95% CL", "L") leg.Draw()
def getSmallestBinMarker(hist, color=ROOT.kBlack): bx, by, bz = (ROOT.Long(), ROOT.Long(), ROOT.Long()) hist.GetBinXYZ(hist.GetMinimumBin(), bx, by, bz) cm = PyROOTUtils.CrossMarker( hist.GetXaxis().GetBinCenter(bx), hist.GetYaxis().GetBinCenter(by), markerColor=color, ) return cm
def main(): inputs = effectiveModel.getInputs( options.input ) for i in inputs: i[2] = unit # This function has to be pickle'able. Lambda functions are not allowed. x = [bins[0], plotRange[0], plotRange[2]] y = [bins[1], plotRange[1], plotRange[3]] h = ROOT.TH2F( "muTmuW", "(#mu^{f}_{ggF+ttH},#mu^{f}_{VBF+VH}) plane;#mu^{f}_{ggF+ttH};#mu^{f}_{VBF+VH};-2 ln #Lambda", x[0], x[1], x[2], y[0], y[1], y[2] ) npHistograms = {} effectiveModel.fillHist( h,x,y,inputs, options, npHistograms=npHistograms ) PyROOTUtils.subtractMinFromHist( h ) outF = effectiveModel.outFileName( options.output, options ) fOut = ROOT.TFile.Open( outF, "RECREATE" ) h.Write() for npH in npHistograms.values(): npH.Write() fOut.Close() print( "Output written to: "+outF )
def plot(values, suffix=None): canvas = ROOT.TCanvas("canvas", "canvas", 800, 600) axes = canvas.DrawFrame(-1.55, -0.6, 1.15, 2.6) axes.GetXaxis().SetTitle("#eta#alpha") axes.GetYaxis().SetTitle("response") axes.GetYaxis().SetTitleOffset(1.2) PyROOTUtils.DrawText(0.2, 0.87, "InterpCode = " + str(options.interpcode), textSize=0.03) leg = PyROOTUtils.Legend(0.2, 0.83, textSize=0.03) for etaData in values: eta = etaData['eta'] data = etaData['data'] g = PyROOTUtils.Graph(data) container.append(g) gDerivative = PyROOTUtils.Graph(g.derivativeData(), lineStyle=ROOT.kDashed) container.append(gDerivative) gDerivative2 = PyROOTUtils.Graph(g.derivative2Data(), lineStyle=ROOT.kDotted) if 'secondDerivative' in etaData: gDerivative2 = PyROOTUtils.Graph(etaData['secondDerivative'], lineStyle=ROOT.kDotted) gDerivative2.transformY(lambda y: y / 10.0) container.append(gDerivative2) infoStr = "#eta = " + str(eta) + " " if 'slopeAtZero' in etaData: infoStr += "\nslope(0) = %.2f " % (etaData['slopeAtZero']) t = PyROOTUtils.DrawText(data[0][0], data[0][1], infoStr, textSize=0.025, halign="right", valign="center", NDC=False) container.append(t) g.Draw("L") gDerivative.Draw("L") gDerivative2.Draw("L") leg.AddEntry(g, "f(#eta#alpha)", "L") leg.AddEntry(gDerivative, "f'(#eta#alpha)", "L") leg.AddEntry(gDerivative2, "1/10 f''(#eta#alpha)", "L") leg.Draw() outFileName = options.output if suffix: outFileName = outFileName.replace(".eps", suffix + ".eps") canvas.SaveAs(outFileName)
def main(): inputs = effectiveModel.getInputs( options.input ) for i in inputs: if "2ph" in i[2]: i[2] = map_2ph elif "4l" in i[2]: i[2] = map_4l elif "lvlv" in i[2]: i[2] = map_lvlv else: print( "WARNING: Didn't find functional replacement for "+i[2] ) kGam = [bins[0], plotRange[0], plotRange[2]] kGlu = [bins[1], plotRange[1], plotRange[3]] h = ROOT.TH2F( "kGlukGamma", "Couplings in (k_{g},k_{#gamma});#kappa_{#gamma};#kappa_{g};-2 ln #Lambda", kGam[0], kGam[1], kGam[2], kGlu[0], kGlu[1], kGlu[2] ) npHistograms = {} effectiveModel.fillHist( h,kGam,kGlu,inputs, options, npHistograms=npHistograms ) PyROOTUtils.subtractMinFromHist( h ) outF = effectiveModel.outFileName( options.output, options ) fOut = ROOT.TFile.Open( outF, "RECREATE" ) h.Write() for npH in npHistograms.values(): npH.Write() fOut.Close() print( "Output written to: "+outF )
def getInterpolatedMinimumMarker(hist, color=ROOT.kBlack): """ This takes the neighboring two bins and plots a parabola through the three points defined by the three bins (parabolas are uniquely defined by three points). No fitting has to be done. The minimum of that parabola is used as the interpolated minimum. For the bin heights y1, y2 and y3 at the bin positions 0, \Delta x and 2\Delta x, the parabola minimum x0 is at: -x0 = [4(y2-y1) - (y3-y1)]\Delta x / [2(y3-y1) - 4(y2-y1)] This ignores (off-)diagonal neighboring cells which would go beyond what can be uniquely defined for a parabola. """ bx, by, bz = (ROOT.Long(), ROOT.Long(), ROOT.Long()) hist.GetBinXYZ(hist.GetMinimumBin(), bx, by, bz) # interpolate position horizontally y1 = hist.GetBinContent(hist.GetMinimumBin() - 1) y2 = hist.GetBinContent(hist.GetMinimumBin()) y3 = hist.GetBinContent(hist.GetMinimumBin() + 1) deltax = (hist.GetXaxis().GetBinCenter(bx + 1) - hist.GetXaxis().GetBinCenter(bx - 1)) / 2.0 x0 = hist.GetXaxis().GetBinCenter(bx - 1) + ( (4.0 * (y2 - y1) - (y3 - y1)) * (-deltax)) / (2.0 * (y3 - y1) - 4.0 * (y2 - y1)) # interpolate position vertically bU = hist.GetMinimumBin() + (hist.GetXaxis().GetNbins() + 2) # bin up bD = hist.GetMinimumBin() - (hist.GetXaxis().GetNbins() + 2) # bin down y1 = hist.GetBinContent(bU) y2 = hist.GetBinContent(hist.GetMinimumBin()) y3 = hist.GetBinContent(bD) deltay = (hist.GetYaxis().GetBinCenter(by + 1) - hist.GetYaxis().GetBinCenter(by - 1)) / 2.0 y0 = hist.GetYaxis().GetBinCenter(by - 1) + ( (4.0 * (y2 - y1) - (y3 - y1)) * (-deltay)) / (2.0 * (y3 - y1) - 4.0 * (y2 - y1)) cm = PyROOTUtils.CrossMarker( x0, y0, markerColor=color, ) return cm
def drawH(filename, histname): f = ROOT.TFile.Open(filename, "READ") h = f.Get(histname) h.SetStats(False) h.SetContour(100) #h.Scale( 2 ) h.SetMinimum(-1e-6) h.SetMaximum(6) #h.GetZaxis().SetTitle( "-2 ln #Lambda" ) h.Draw("COLZ,SAME") container.append(h) bFOrig = f.Get(histname + "_bestFit") bF = PyROOTUtils.CrossMarker(bFOrig.GetX(), bFOrig.GetY()) bF.Draw() container.append(bF) openFiles.append(f) return (h, bF)
def content(mHBestFit=130.0, height1SigmaLabel=10.0, color=ROOT.kBlue): # make mock curve linSpace = [100 + i * 60.0 / 300.0 for i in range(300)] likelihood = [(x, (x - mHBestFit) * (x - mHBestFit) / 25.0) for x in linSpace] likelihood_statOnly = [(x, (x - mHBestFit) * (x - mHBestFit) / 20.0) for x in linSpace] # draw curve g = PyROOTUtils.Graph(likelihood, lineColor=color, lineWidth=2) g.Draw() g_statOnly = PyROOTUtils.Graph(likelihood_statOnly, lineColor=color, lineWidth=2, lineStyle=ROOT.kDashed) g_statOnly.Draw() # find 68% CL interval from likelihood low, high = g.getFirstIntersectionsWithValue(1.0) vLineM1Sigma = PyROOTUtils.DrawVLine(low, lineStyle=ROOT.kDashed, lineWidth=1, lineColor=color) vLineP1Sigma = PyROOTUtils.DrawVLine(high, lineStyle=ROOT.kDashed, lineWidth=1, lineColor=color) hLine1Sigma = PyROOTUtils.DrawLine(low, height1SigmaLabel, high, height1SigmaLabel, lineWidth=5, lineColor=color) label1Sigma = PyROOTUtils.DrawText( mHBestFit, height1SigmaLabel, ("#lower[-0.5]{%.1f^{%+.1f}_{%+.1f} GeV}" % (mHBestFit, high - mHBestFit, low - mHBestFit)), NDC=False, textSize=0.025, halign="center", valign="bottom", textColor=color) container.append( (g, g_statOnly, vLineM1Sigma, vLineP1Sigma, hLine1Sigma, label1Sigma)) return (g, g_statOnly)
def drawAllArrows(allEtas, cut=0.03, detailed=False): for etasName, etas in allEtas.iteritems(): canvas = ROOT.TCanvas("c1", "c1", 600, 600) if detailed: axes = canvas.DrawFrame(0.48, 0.48, 1.62, 1.82) else: axes = canvas.DrawFrame(0.58, 0.58, 1.42, 1.42) axes.GetXaxis().SetTitle("#mu^{f}_{ggF+ttH}") axes.GetYaxis().SetTitle("#mu^{f}_{VBF+VH}") #axes.GetYaxis().SetTitleOffset( 1.2 ) template = 0 if 'generic' in etasName: template = 10 if 'generic10' in etasName: template = 10 if 'generic14' in etasName: template = 14 if 'generic20' in etasName: template = 20 if 'generic24' in etasName: template = 24 print("For " + etasName + " chose template " + str(template) + ".") scanPoints = [{'muT': 1.0, 'muW': 1.0}] npVals = [(1.0, 3.0)] # nuis par values and line widths if detailed: scanPoints = [{ 'muT': 1.0, 'muW': 1.0 }, { 'muT': 1.3, 'muW': 1.0 }, { 'muT': 1.0, 'muW': 1.3 }] npVals = [(-1.0, 1.5), (1.0, 2.5)] for muIn in scanPoints: for npVal, lineWidth in npVals: arrows = drawArrows(etas, muIn, npVal, lineWidth, cut, template=template) container.append(arrows) leg = PyROOTUtils.Legend(0.2, 0.85, textSize=0.035) for a, p in arrows: leg.AddEntry(a, parameterNames[p.replace("alpha_", "")], "L") leg.Draw() if cut > 0.0: PyROOTUtils.DrawText(0.2, 0.88, "showing only |#eta| > %.0f%%" % (cut * 100.0), textSize=0.035) if detailed: PyROOTUtils.DrawText( 0.2, 0.25, "positive variation thick\nnegative variation thin", textSize=0.035) if detailed: canvas.SaveAs(options.output + etasName + "_detailed.eps") else: canvas.SaveAs(options.output + etasName + ".eps")
outputtexfile.write(line + "\n") tail = ''' \\hline \\hline \end{tabular} \end{center} \end{table} ''' outputtexfile.write(tail) outputtexfile.close() #gr_med = PyROOTUtils.Graph(masses, medians) gr_obs = PyROOTUtils.Graph(masses, lim_obs) gr_obs.SetMarkerStyle(20) gr_med = PyROOTUtils.Graph(masses, lim_med) #gr_med.SetMarkerStyle(7) gr_med.SetLineStyle(R.kDashed) gr_med.SetLineWidth(2) #band_1sigma = PyROOTUtils.Band(masses, minus1sigmas, plus1sigmas, fillColor=R.kGreen) #band_2sigma = PyROOTUtils.Band(masses, minus2sigmas, plus2sigmas, fillColor=R.kYellow) band_1sigma = PyROOTUtils.Band(masses, minus1sig, plus1sig, fillColor=R.kGreen) band_2sigma = PyROOTUtils.Band(masses, minus2sig, plus2sig, fillColor=R.kYellow) # Prepare frame hframe = R.TH1I("frame", "frame", 1, min(masses), max(masses))
def profiledContour(opts={}): if opts["type"] == "oneAlpha_catUniversal": modelType = "oneAlpha_catUniversal" color = ROOT.kRed - 3 elif opts["type"] == "oneAlpha_catNonUniversal": modelType = "oneAlpha_catNonUniversal" color = ROOT.kGreen - 2 elif opts["type"] == "twoAlpha_catUniversal": modelType = "twoAlpha_catUniversal" color = ROOT.kOrange - 3 elif opts["type"] == "twoAlpha_catNonUniversal": modelType = "twoAlpha_catNonUniversal" color = ROOT.kBlue elif opts["type"] == "oneAlpha_catUniversal_interpCode0": modelType = "oneAlpha_catUniversal_interpCode0" color = ROOT.kRed - 3 elif opts["type"] == "oneAlpha_catNonUniversal_interpCode0": modelType = "oneAlpha_catNonUniversal_interpCode0" color = ROOT.kGreen - 2 elif opts["type"] == "twoAlpha_catUniversal_interpCode0": modelType = "twoAlpha_catUniversal_interpCode0" color = ROOT.kOrange - 3 elif opts["type"] == "twoAlpha_catNonUniversal_interpCode0": modelType = "twoAlpha_catNonUniversal_interpCode0" color = ROOT.kBlue elif opts["type"] == "scenarioA": modelType = "scenarioA" color = ROOT.kRed - 3 elif opts["type"] == "scenarioA2": modelType = "scenarioA2" color = ROOT.kRed - 3 elif opts["type"] == "scenarioB": modelType = "scenarioB" color = ROOT.kGreen - 2 elif opts["type"] == "scenarioC": modelType = "scenarioC" color = ROOT.kBlue elif opts["type"] == "scenarioC2": modelType = "scenarioC2" color = ROOT.kBlue elif opts["type"] == "scenarioD": modelType = "scenarioD" color = ROOT.kGreen elif opts["type"] == "scenarioA_interpCode0": modelType = "scenarioA_interpCode0" color = ROOT.kRed - 3 elif opts["type"] == "scenarioA2_interpCode0": modelType = "scenarioA2_interpCode0" color = ROOT.kRed - 3 elif opts["type"] == "scenarioB_interpCode0": modelType = "scenarioB_interpCode0" color = ROOT.kGreen - 2 elif opts["type"] == "scenarioC_interpCode0": modelType = "scenarioC_interpCode0" color = ROOT.kBlue elif opts["type"] == "scenarioC2_interpCode0": modelType = "scenarioC2_interpCode0" color = ROOT.kBlue elif opts["type"] == "scenarioD_interpCode0": modelType = "scenarioD_interpCode0" color = ROOT.kGreen effFile = "output/twoBin/" + modelType + "/muTmuW_eff.root" if "template0" in opts: inFile = "output/twoBin/" + modelType + "_interpCode0/muTmuW.root" profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template0.root" elif "templateM1" in opts: inFile = "output/twoBin/" + modelType + "_additiveMu_interpCode0/muTmuW.root" profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_templateM1.root" elif "template14_etasgeneric_M4" in opts: inFile = "output/twoBin/" + modelType + "/muTmuW.root" profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template14_etasgeneric_M4.root" elif "template14_etasgeneric_M5" in opts: inFile = "output/twoBin/" + modelType + "/muTmuW.root" profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template14_etasgeneric_M5.root" elif "template14_etasgeneric_fisherInfo" in opts: inFile = "output/twoBin/" + modelType + "/muTmuW.root" profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template14_etasgeneric_fisherInfo.root" elif "template10_etasgeneric10_learning" in opts: inFile = "output/twoBin/" + modelType + "/muTmuW.root" profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template10_etasgeneric10_learning.root" elif "template14_etasgeneric14_learning" in opts: inFile = "output/twoBin/" + modelType + "/muTmuW.root" profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template14_etasgeneric14_learning.root" elif "template20_etasgeneric20_learning" in opts: inFile = "output/twoBin/" + modelType + "/muTmuW.root" profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template20_etasgeneric20_learning.root" elif "template24_etasgeneric24_learning" in opts: inFile = "output/twoBin/" + modelType + "/muTmuW.root" profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template24_etasgeneric24_learning.root" elif "template20_etasgeneric20_learning_box1.0" in opts: inFile = "output/twoBin/" + modelType + "_box/muTmuW.root" profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template20_etasgeneric20_learning_box1.0.root" else: inFile = "output/twoBin/" + modelType + "/muTmuW.root" profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour.root" c68 = drawContours(inFile, "profiledNLL", scale=2.0, color=color) c68_f = drawContours(effFile, "profiledNLL", scale=2.0, color=color, lineStyle=ROOT.kDashed) c68_p = drawContours(profiledFile, "muTmuW", color=ROOT.kGray + 2, lineStyle=ROOT.kDotted) container.append((c68, c68_f, c68_p)) PyROOTUtils.DrawText(0.66, 0.88, "68% CL contours", textSize=0.03) leg2 = PyROOTUtils.Legend(0.65, 0.85, textSize=0.03) leg2.AddEntry(SMMarker, "Standard Model", "P") if c68: leg2.AddEntry(c68[0], "full model", "L") if c68_f: leg2.AddEntry(c68_f[0], "fixed effective", "L") if c68_p: leg2.AddEntry(c68_p[0], "profiled effective", "L") leg2.Draw()
parser = optparse.OptionParser(version=__version__) parser.add_option("-q", "--quiet", dest="verbose", action="store_false", default=True, help="Quiet output.") options, args = parser.parse_args() import ROOT ROOT.gROOT.SetBatch(True) import glob, re, os from array import array import PyROOTUtils PyROOTUtils.style() from Decouple.plot_utils import getContours, getSmallestBinMarker, getInterpolatedMinimumMarker, drawContours, drawH, draw_muTmuW_frame, draw_kVkF_frame, draw_kGlukGamma_frame SMMarker = ROOT.TMarker(1.0, 1.0, 34) SMMarker.SetMarkerColor(ROOT.kBlack) blackSolid = ROOT.TLine(1.2, 1.2, 1.4, 1.4) blackSolid.SetLineWidth(2) blackDashed = ROOT.TLine(1.2, 1.2, 1.4, 1.4) blackDashed.SetLineWidth(2) blackDashed.SetLineStyle(ROOT.kDashed) container = [] openFiles = []
__version__ = "0.1" import optparse parser = optparse.OptionParser(version=__version__) parser.add_option("-q", "--quiet", dest="verbose", action="store_false", default=True, help="Quiet output.") options,args = parser.parse_args() import ROOT ROOT.gROOT.SetBatch( True ) import glob, re, os from array import array import PyROOTUtils PyROOTUtils.style() from Decouple.plot_utils import getContours, getSmallestBinMarker, getInterpolatedMinimumMarker, drawContours, drawH, draw_muTmuW_frame, draw_kVkF_frame, draw_kGlukGamma_frame SMMarker = ROOT.TMarker( 1.0, 1.0, 34 ) SMMarker.SetMarkerColor( ROOT.kBlack ) blackSolid = ROOT.TLine( 1.2,1.2,1.4,1.4 ) blackSolid.SetLineWidth( 2 ) blackDashed = ROOT.TLine( 1.2,1.2,1.4,1.4 ) blackDashed.SetLineWidth( 2 ) blackDashed.SetLineStyle( ROOT.kDashed )
def countingMuTMuW(opts): mainModelSuffix = "" profileSuffix = "" modelSuffix = "" if 'model' in opts and opts['model'] != "" and opts['model'] != "template4": profileSuffix = "_" + opts['model'] if 'model' in opts and 'box' in opts['model']: mainModelSuffix = "_box" if 'model' in opts and 'wideGauss' in opts['model']: mainModelSuffix = "_wideGauss" if 'interpCode0' in opts: modelSuffix = '_interpCode0' # if 'model' in opts and ('template0' in opts['model'] or 'template10' in opts['model']): # if 'model' in opts and ('template0' in opts['model']): # modelSuffix = "_interpCode0" c68_2ph = drawContours("output/atlas_counting/2ph" + modelSuffix + mainModelSuffix + "/muTmuW.root", "profiledNLL", scale=2.0, color=ROOT.kRed - 3, lineStyle=ROOT.kDashed, lineWidth=3, drawSmallestBinMarker=True) c68_4l = drawContours("output/atlas_counting/4l" + modelSuffix + mainModelSuffix + "/muTmuW.root", "profiledNLL", scale=2.0, color=ROOT.kBlue, lineStyle=ROOT.kDashed, lineWidth=3, drawSmallestBinMarker=True) c68_lvlv = drawContours("output/atlas_counting/lvlv" + modelSuffix + mainModelSuffix + "/muTmuW.root", "profiledNLL", scale=2.0, color=ROOT.kGreen - 2, lineStyle=ROOT.kDashed, lineWidth=3, drawSmallestBinMarker=True) c68_2ph_f = drawContours("output/atlas_counting/2ph" + modelSuffix + "/muTmuW_eff.root", "profiledNLL", scale=2.0, color=ROOT.kRed - 3, lineStyle=ROOT.kDotted) c68_4l_f = drawContours("output/atlas_counting/4l" + modelSuffix + "/muTmuW_eff.root", "profiledNLL", scale=2.0, color=ROOT.kBlue, lineStyle=ROOT.kDotted) c68_lvlv_f = drawContours("output/atlas_counting/lvlv" + modelSuffix + "/muTmuW_eff.root", "profiledNLL", scale=2.0, color=ROOT.kGreen - 2, lineStyle=ROOT.kDotted) # c68_2ph_s = drawContours( "output/atlas_counting/2ph"+modelSuffix+"/muTmuW_statOnly.root", "profiledNLL", scale=2.0, color = ROOT.kRed-3, lineStyle=ROOT.kDashed, lineWidth=4, drawSmallestBinMarker=True ) # c68_4l_s = drawContours( "output/atlas_counting/4l"+modelSuffix+"/muTmuW_statOnly.root", "profiledNLL", scale=2.0, color = ROOT.kBlue, lineStyle=ROOT.kDashed, lineWidth=4 ) # c68_lvlv_s = drawContours( "output/atlas_counting/lvlv"+modelSuffix+"/muTmuW_statOnly.root", "profiledNLL", scale=2.0, color = ROOT.kGreen-2, lineStyle=ROOT.kDashed, lineWidth=4 ) if 'model' in opts: c68_2ph_p = drawContours("output/atlas_counting/2ph" + modelSuffix + "/muTmuW_profiledContour" + profileSuffix + ".root", "muTmuW", color=ROOT.kRed - 4, lineStyle=ROOT.kSolid, drawSmallestBinMarker=True) c68_4l_p = drawContours("output/atlas_counting/4l" + modelSuffix + "/muTmuW_profiledContour" + profileSuffix + ".root", "muTmuW", color=ROOT.kAzure - 4, lineStyle=ROOT.kSolid, drawSmallestBinMarker=True) c68_lvlv_p = drawContours("output/atlas_counting/lvlv" + modelSuffix + "/muTmuW_profiledContour" + profileSuffix + ".root", "muTmuW", color=ROOT.kGreen + 1, lineStyle=ROOT.kSolid, drawSmallestBinMarker=True) leg = PyROOTUtils.Legend(0.2, 0.20, textSize=0.025, valign="bottom") leg.AddEntry(SMMarker, "Standard Model", "P") leg.AddEntry(blackDashedThick, "68% CL full model", "L") leg.AddEntry(blackDotted, "68% CL w/o theory uncert.", "L") if 'model' in opts: leg.AddEntry(blackSolid, "68% CL recoupled", "L") leg.Draw() leg2 = PyROOTUtils.Legend(0.65, 0.90, textSize=0.025) l2ph = PyROOTUtils.DrawHLine(400.0, lineWidth=2, lineColor=ROOT.kRed - 3) l4l = PyROOTUtils.DrawHLine(400.0, lineWidth=2, lineColor=ROOT.kBlue) llvlv = PyROOTUtils.DrawHLine(400.0, lineWidth=2, lineColor=ROOT.kGreen - 2) container.append((l2ph, l4l, llvlv)) if c68_2ph: leg2.AddEntry(l2ph, "H #rightarrow #gamma#gamma", "L") if c68_4l: leg2.AddEntry(l4l, "H #rightarrow ZZ* #rightarrow 4l", "L") if c68_lvlv: leg2.AddEntry(llvlv, "H #rightarrow WW* #rightarrow l#nul#nu", "L") leg2.Draw()
def make_hist2(self, br_name, hist_name, bin_list): return PyROOTUtils.draw_hist_from_chain(self.chain, br_name,\ self.cut, hist_name, bin_list)
def countingMuTMuWShifted(opts): modelSuffix = '' if 'interpCode0' in opts: modelSuffix = '_interpCode0' drawMarker = True if 'etaArrows' in opts: drawMarker = False c68_2ph_f = drawContours("output/atlas_counting/2ph" + modelSuffix + "/muTmuW_eff_" + opts['model'] + "_0.0.root", "muTmuW", color=ROOT.kRed - 3, drawSmallestBinMarker=drawMarker) c68_4l_f = drawContours("output/atlas_counting/4l" + modelSuffix + "/muTmuW_eff_" + opts['model'] + "_0.0.root", "muTmuW", color=ROOT.kBlue, drawSmallestBinMarker=drawMarker) c68_lvlv_f = drawContours("output/atlas_counting/lvlv" + modelSuffix + "/muTmuW_eff_" + opts['model'] + "_0.0.root", "muTmuW", color=ROOT.kGreen - 2, drawSmallestBinMarker=drawMarker) c68_2ph_s = drawContours("output/atlas_counting/2ph" + modelSuffix + "/muTmuW_eff_" + opts['model'] + "_1.0.root", "muTmuW", color=ROOT.kRed - 3, lineStyle=ROOT.kDashed, drawSmallestBinMarker=drawMarker) c68_4l_s = drawContours("output/atlas_counting/4l" + modelSuffix + "/muTmuW_eff_" + opts['model'] + "_1.0.root", "muTmuW", color=ROOT.kBlue, lineStyle=ROOT.kDashed, drawSmallestBinMarker=drawMarker) c68_lvlv_s = drawContours("output/atlas_counting/lvlv" + modelSuffix + "/muTmuW_eff_" + opts['model'] + "_1.0.root", "muTmuW", color=ROOT.kGreen - 2, lineStyle=ROOT.kDashed, drawSmallestBinMarker=drawMarker) if 'etaArrows' in opts: arrows = [] for c in ['2ph', '4l', 'lvlv']: try: with open( "output/atlas_counting/" + c + modelSuffix + "/table_etas.pickle", "rb") as f: etasAll = pickle.load(f) muHat = { 'muT': etasAll['generic20_learning'].values()[0]['muT__hat'], 'muW': etasAll['generic20_learning'].values()[0]['muW__hat'], } arrows = etas.drawArrows(etasAll['fisherInfo'], muHat, lineWidth=1.0, template=0) container.append(arrows) except IOError: print("WARNING: Could not open:") print("output/atlas_counting/" + c + modelSuffix + "/table_etas.pickle") except: print("ERROR!!!!!!!!!!") leg = PyROOTUtils.Legend(0.64, 0.78, textSize=0.025) for a, p in arrows: leg.AddEntry(a, parameterNames[p.replace("alpha_", "")], "L") leg.Draw() leg = PyROOTUtils.Legend(0.2, 0.30, textSize=0.025) leg.AddEntry(SMMarker, "Standard Model", "P") leg.AddEntry(blackSolid, "68% CL with #alpha at nominal", "L") leg.AddEntry(blackDashed, "68% CL with #alpha at +1 #sigma", "L") leg.Draw() leg2 = PyROOTUtils.Legend(0.64, 0.90, textSize=0.025) if c68_2ph_f: leg2.AddEntry(c68_2ph_f[0], "H #rightarrow #gamma#gamma", "L") if c68_4l_f: leg2.AddEntry(c68_4l_f[0], "H #rightarrow ZZ* #rightarrow 4l", "L") if c68_lvlv_f: leg2.AddEntry(c68_lvlv_f[0], "H #rightarrow WW* #rightarrow l#nul#nu", "L") leg2.Draw()