def doPlot2(limits, legendLabels, name): graphs = [ histograms.HistoGraph(limits[0].expectedGraph(), "Expected", drawStyle="L"), histograms.HistoGraph(limits[0].expectedBandGraph(sigma=1), "Expected1", drawStyle="F", legendStyle="fl"), histograms.HistoGraph(limits[0].expectedBandGraph(sigma=2), "Expected2", drawStyle="F", legendStyle="fl"), ] graphs[0].getRootHisto().SetLineStyle(1) plot = plots.PlotBase(graphs) ll = { "Expected": None, "Expected1": "%s exp. median #pm 1#sigma" % legendLabels[0], "Expected2": "%s exp. median #pm 2#sigma" % legendLabels[0], } stGen = styles.generator() for i in xrange(1, len(limits)): gr = histograms.HistoGraph(limits[i].expectedGraph(), "Exp%d"%i, drawStyle="L") stGen(gr) gr.getRootHisto().SetLineWidth(3) gr.getRootHisto().SetLineStyle(1) plot.histoMgr.insertHisto(len(plot.histoMgr)-2, gr, legendIndex=len(plot.histoMgr)) ll["Exp%d"%i] = "%s exp. median" % legendLabels[i] plot.histoMgr.setHistoLegendLabelMany(ll) legend = histograms.moveLegend(histograms.createLegend(0.48, 0.75, 0.85, 0.92), dx=-0.02) if len(limits[0].getFinalstates()) > 1: legend = histograms.moveLegend(legend, dy=-0.1) plot.setLegend(legend) plot.createFrame(name+"_limits", opts={"ymin": 0, "ymax": limits[0].getFinalstateYmaxBR()}) plot.frame.GetXaxis().SetTitle(limit.mHplus()) plot.frame.GetYaxis().SetTitle(limit.BRlimit) plot.draw() plot.setLuminosity(limits[0].getLuminosity()) plot.addStandardTexts(cmsTextPosition="outframe") size = 20 x = 0.2 histograms.addText(x, 0.88, limit.process, size=size) histograms.addText(x, 0.84, limits[0].getFinalstateText(), size=size) histograms.addText(x, 0.79, limit.BRassumption, size=size) plot.save()
def doPlot(limits, legendLabels, graphs, name, ylabel, opts={}, plotLabel=None, moveLegend={}, log=False): hg = [] ll = {} for i in xrange(len(graphs)): hg.append(histograms.HistoGraph(graphs[i], "Graph%d"%i, drawStyle="PL", legendStyle="lp")) ll["Graph%d"%i] = legendLabels[i] plot = plots.PlotBase(hg) plot.histoMgr.forEachHisto(styles.Generator(styleList[0:len(limits)])) def sty(h): r = h.getRootHisto() r.SetLineWidth(3) r.SetLineStyle(1) plot.histoMgr.forEachHisto(sty) plot.histoMgr.setHistoLegendLabelMany(ll) legend = histograms.createLegend(0.48, 0.65, 0.85, 0.92) if len(limits[0].getFinalstates()) > 1: legend = histograms.moveLegend(legend, dy=-0.1) if plotLabel: legend = histograms.moveLegend(legend, dy=-0.04) legend = histograms.moveLegend(legend, **moveLegend) plot.setLegend(legend) opts_ = {"ymin": 0} opts_.update(opts) plot.createFrame(name, opts=opts_) plot.frame.GetXaxis().SetTitle(limit.mHplus()) plot.frame.GetYaxis().SetTitle(ylabel) ROOT.gPad.SetLogy(log) plot.draw() plot.setLuminosity(limits[0].getLuminosity()) plot.addStandardTexts(cmsTextPosition="outframe") size = 20 x = 0.18 histograms.addText(x, 0.88, limit.process, size=size) histograms.addText(x, 0.84, limits[0].getFinalstateText(), size=size) histograms.addText(x, 0.79, limit.BRassumption, size=size) if plotLabel: histograms.addText(legend.GetX1()+0.01, legend.GetY2(), plotLabel, size=size) plot.save()
def doBRlimit(limits, unblindedStatus, opts, logy=False): graphs = [] if unblindedStatus: gr = limits.observedGraph() if gr != None: gr.SetPoint(gr.GetN() - 1, gr.GetX()[gr.GetN() - 1] - 1e-10, gr.GetY()[gr.GetN() - 1]) if opts.excludedArea: graphs.append( histograms.HistoGraph(gr, "Observed", drawStyle="PL", legendStyle=None)) excluded = gr.Clone() excluded.SetPoint(excluded.GetN(), excluded.GetX()[excluded.GetN() - 1], 0.05) excluded.SetPoint(excluded.GetN(), excluded.GetX()[0], 0.05) limit.setExcludedStyle(excluded) graphs.append( histograms.HistoGraph(excluded, "Excluded", drawStyle="F", legendStyle="lpf", legendLabel="Observed")) else: graphs.append( histograms.HistoGraph(gr, "Observed", drawStyle="PL", legendStyle="lp")) # Add the expected lines graphs.extend([ histograms.HistoGraph(limits.expectedGraph(), "Expected", drawStyle="L"), histograms.HistoGraph(limits.expectedBandGraph(sigma=1), "Expected1", drawStyle="F", legendStyle="fl"), histograms.HistoGraph(limits.expectedBandGraph(sigma=2), "Expected2", drawStyle="F", legendStyle="fl"), ]) # Plot the TGraphs saveFormats = [".png", ".C", ".pdf"] if not opts.excludedArea: saveFormats.append(".eps") plot = plots.PlotBase(graphs, saveFormats=saveFormats) plot.setLuminosity(limits.getLuminosity()) # Customise legend entries plot.histoMgr.setHistoLegendLabelMany({ "Expected": None, "Expected1": "Expected median #pm 1#sigma", "Expected2": "Expected median #pm 2#sigma" }) # Branching Ratio Assumption if 0: limit.BRassumption = "Assuming B(H^{+}#rightarrowt#bar{b}) = 1" # Create legend xPos = 0.53 legend = getLegend(limit, opts, xPos) plot.setLegend(legend) # Get y-min, y-max, and histogram name to be saved as ymin, ymax, saveName = getYMinMaxAndName(limits, "limitsBr", logy, opts) if opts.yMin != -1: ymin = opts.yMin if opts.yMax != -1: ymax = opts.yMax if len(limits.mass) == 1: plot.createFrame(saveName, opts={ "xmin": limits.mass[0] - 5.0, "xmax": limits.mass[0] + 5.0, "ymin": ymin, "ymax": ymax }) else: plot.createFrame(saveName, opts={"ymin": ymin, "ymax": ymax}) # Add cut box? if opts.cutLine > 0: kwargs = {"greaterThan": True} plot.addCutBoxAndLine(cutValue=opts.cutLine, fillColor=ROOT.kRed, box=False, line=True, **kwargs) # Set x-axis title plot.frame.GetXaxis().SetTitle(limit.mHplus()) if limit.BRassumption != "": plot.frame.GetYaxis().SetTitle("95% CL limit for #sigma_{H^{+}} (pb)") else: plot.frame.GetYaxis().SetTitle(limit.sigmaBRlimit) # plot.frame.GetYaxis().SetTitle(limit.BRlimit) # Enable/Disable logscale for axes if logy: plot.getPad().SetLogy(logy) plot.getPad().SetLogx(opts.logx) # Enable grids in x and y? plot.getPad().SetGridx(opts.gridX) plot.getPad().SetGridy(opts.gridY) # Draw the plot with standard texts plot.draw() plot.addStandardTexts() # Add physics-related text on canvas addPhysicsText(histograms, limit, x=xPos) # Save the canvas plot.save() # Save the plots SavePlot(plot, saveName, os.path.join(opts.saveDir, opts.settings)) return
def main(): limits = limit.BRLimits() # Apply TDR style style = tdrstyle.TDRStyle() if limit.forPaper: histograms.cmsTextMode = histograms.CMSMode.PAPER # Get BR limits graphs = {} obs = limits.observedGraph() myBlindedStatus = True for i in xrange(0,obs.GetN()): if abs(obs.GetY()[i]) > 0.00001: myBlindedStatus = False if not myBlindedStatus: graphs["obs"] = obs graphs["exp"] = limits.expectedGraph() graphs["exp1"] = limits.expectedBandGraph(sigma=1) graphs["exp2"] = limits.expectedBandGraph(sigma=2) # Remove m=80 for gr in graphs.values(): limit.cleanGraph(gr, minX=100) # Get theory uncertainties on observed if not myBlindedStatus: obs_th_plus = limit.getObservedPlus(obs) obs_th_minus = limit.getObservedMinus(obs) for gr in [obs_th_plus, obs_th_minus]: gr.SetLineWidth(3) gr.SetLineStyle(5) # gr.SetLineStyle(9) graphs["obs_th_plus"] = obs_th_plus graphs["obs_th_minus"] = obs_th_minus # Interpret in MSSM global mu for key in graphs.keys(): removeNotValid = not (key in ["exp1", "exp2"]) graphs[key] = limit.graphToTanBeta(graphs[key], mu, removeNotValid) doPlot("limitsTanb_mh", graphs, limits, limit.mHplus()) for gr in graphs.values(): limit.graphToMa(gr) doPlot("limitsTanb_ma", graphs, limits, limit.mA()) if myBlindedStatus: print "Refusing cowardly to do mu variation plots for blinded results" return # Mu variations mus = [1000, 200, -200, -1000] muGraphs = [(limit.graphToTanBeta(obs, m), m) for m in mus] def muStyle(h, markerStyle, lineStyle, color): rh = h.getRootHisto() rh.SetMarkerStyle(markerStyle) rh.SetMarkerColor(color) rh.SetLineStyle(lineStyle) rh.SetLineColor(color) rh.SetLineWidth(504) rh.SetFillStyle(3005) st = [lambda h: muStyle(h, 21, 1, 4), lambda h: muStyle(h, 20, 1, 1), lambda h: muStyle(h, 20, 2, 1), lambda h: muStyle(h, 21, 2, 4)] doPlotMu("limitsTanb_mus_mh", muGraphs, st, limits, limit.mHplus()) for gr, mu in muGraphs: limit.graphToMa(gr) doPlotMu("limitsTanb_mus_ma", muGraphs, st, limits, limit.mA())
def main(): if len(sys.argv) == 1: usage() rootfile = "" jsonfile = "limits.json" root_re = re.compile("(?P<rootfile>(\S*\.root))") json_re = re.compile("(?P<jsonfile>(\S*\.json))") for argv in sys.argv: match = root_re.search(argv) if match: rootfile = match.group(0) match = json_re.search(argv) if match: jsonfile = match.group(0) limits = limit.BRLimits( limitsfile=jsonfile, configfile="limitdata/lightHplus_configuration.json") # Enable OpenGL ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1) # Apply TDR style style = tdrstyle.TDRStyle() if limit.forPaper: histograms.cmsTextMode = histograms.CMSMode.PAPER limit.forPaper = True # to get GeV without c^2 # Get BR limits masses = limits.mass brs = limits.observed print "Observed masses and BR's" for i in range(len(masses)): print " ", masses[i], brs[i] global db db = BRXSDB.BRXSDatabaseInterface(rootfile, program="2HDMC", BRvariable="BR_tHpb") for i, m in enumerate(masses): db.addExperimentalBRLimit(m, brs[i]) graphs = {} obs = limits.observedGraph() # Remove blinded obs points for i in reversed(range(0, obs.GetN())): if obs.GetY()[i] < 0.00000001: print " REMOVING POINT", obs.GetY( )[i], " corresponding mass=", obs.GetX()[i] obs.RemovePoint(i) print graphs["exp"] = limits.expectedGraph() graphs["exp1"] = limits.expectedBandGraph(sigma=1) graphs["exp2"] = limits.expectedBandGraph(sigma=2) if obs.GetN() > 0: graphs["obs"] = obs # Get theory uncertainties on observed obs_th_plus = limit.getObservedPlus(obs, 0.21) obs_th_minus = limit.getObservedMinus(obs, 0.21) for gr in [obs_th_plus, obs_th_minus]: gr.SetLineWidth(2) gr.SetLineStyle(9) graphs["obs_th_plus"] = obs_th_plus graphs["obs_th_minus"] = obs_th_minus # Remove m=80 for gr in graphs.values(): limit.cleanGraph(gr, minX=90) print "Plotting graphs" for key in graphs.keys(): for i in range(graphs[key].GetN()): xs = graphs[key].GetX() ys = graphs[key].GetY() print " ", key, xs[i], ys[i] print # Interpret in MSSM xVariable = "mHp" # selection = "mu==200" selection = "mHp>0" # scenario = "MSSM m_{h}^{max}" scenario = os.path.split(rootfile)[-1].replace(".root", "") for key in graphs.keys(): print "Graph--------------------------------", key # graphs[key] = db.graphToTanBetaCombined(graphs[key],xVariable,selection) graphs[key] = db.graphToTanBeta(graphs[key], xVariable, selection, False) print key, "done" graphs["mintanb"] = db.minimumTanbGraph("mHp", selection) doPlot("limitsTanb_light_" + scenario, graphs, limits, limit.mHplus(), scenario)
def main(): if len(sys.argv) == 1: usage() rootfile = "" jsonfile = "limits.json" root_re = re.compile("(?P<rootfile>(\S*\.root))") json_re = re.compile("(?P<jsonfile>(\S*\.json))") for argv in sys.argv: match = root_re.search(argv) if match: rootfile = match.group(0) match = json_re.search(argv) if match: jsonfile = match.group(0) limits = limit.BRLimits( limitsfile=jsonfile, configfile="limitdata/lightHplus_configuration.json") # Enable OpenGL ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1) # Apply TDR style style = tdrstyle.TDRStyle() if limit.forPaper: histograms.cmsTextMode = histograms.CMSMode.PAPER #histograms.cmsTextMode = histograms.CMSMode.PAPER # tmp #histograms.cmsTextMode = histograms.CMSMode.UNPUBLISHED # tmp limit.forPaper = True # to get GeV without c^2 # Get BR limits masses = limits.mass brs = limits.observed print "Observed masses and BR's" for i in range(len(masses)): print " ", masses[i], brs[i] global db db = BRXSDB.BRXSDatabaseInterface(rootfile) for i, m in enumerate(masses): db.addExperimentalBRLimit(m, brs[i]) graphs = {} obs = limits.observedGraph() # Remove blinded obs points for i in reversed(range(0, obs.GetN())): if obs.GetY()[i] < 0.00000001: print " REMOVING POINT", obs.GetY( )[i], " corresponding mass=", obs.GetX()[i] obs.RemovePoint(i) print graphs["exp"] = limits.expectedGraph() graphs["exp1"] = limits.expectedBandGraph(sigma=1) graphs["exp2"] = limits.expectedBandGraph(sigma=2) if obs.GetN() > 0: graphs["obs"] = obs # Get theory uncertainties on observed # obs_th_plus = limit.getObservedPlus(obs,0.21) # obs_th_minus = limit.getObservedMinus(obs,0.21) # for gr in [obs_th_plus, obs_th_minus]: # gr.SetLineWidth(2) # gr.SetLineStyle(9) # graphs["obs_th_plus"] = obs_th_plus # graphs["obs_th_minus"] = obs_th_minus # Remove m=80 for gr in graphs.values(): limit.cleanGraph(gr, minX=90) print "Plotting graphs" for key in graphs.keys(): for i in range(graphs[key].GetN()): xs = graphs[key].GetX() ys = graphs[key].GetY() print " ", key, xs[i], ys[i] print # Interpret in MSSM xVariable = "mHp" # selection = "mu==200" selection = "mHp > 0" # scenario = "MSSM m_{h}^{max}" scenario = os.path.split(rootfile)[-1].replace(".root", "") for key in graphs.keys(): print "Graph--------------------------------", key graphs[key] = db.graphToTanBetaCombined(graphs[key], xVariable, selection) #if key == "obs": #obsplus = db.getTheorUncert(graphs[key],xVariable,selection,"+") #graphs["obs_th_plus"] = db.graphToTanBetaCombined(obsplus,xVariable,selection) #obsminus = db.getTheorUncert(graphs[key],xVariable,selection,"-") #graphs["obs_th_minus"] = db.graphToTanBetaCombined(obsminus,xVariable,selection) print key, "done" graphs["mintanb"] = db.minimumTanbGraph("mHp", selection) if scenario == "lowMH-LHCHXSWG": graphs["Allowed"] = db.mhLimit("mH", "mHp", selection, "125.0+-3.0") else: graphs["Allowed"] = db.mhLimit("mh", "mHp", selection, "125.0+-3.0") graphs["isomass"] = None limit.doTanBetaPlotLight("limitsTanb_light_" + scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mHplus(), scenario) # mH+ -> mA print "Replotting the graphs for (mA,tanb)" for key in graphs.keys(): print key #db.PrintGraph(graphs[key]) #print "check loop db.graphToMa" db.graphToMa(graphs[key]) graphs["isomass"] = db.getIsoMass(160) limit.doTanBetaPlotLight("limitsTanb_mA_light_" + scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mA(), scenario)
def doPlot(self, mAtanbeta=False): graphs = {} #["observed", "observedPlusTheorUncert", "observedMinusTheorUncert", "expected", "expectedPlus1Sigma", "expectedPlus2Sigma", "expectedMinus1Sigma", "expectedMinus2Sigma"] result = self._getResultGraphForOneKey("expected") graphs["exp"] = result[0] graphs["expDown"] = result[1] result = self._getResultGraphForTwoKeys("expectedPlus1Sigma", "expectedMinus1Sigma") graphs["exp1"] = result[0] graphs["exp1Down"] = result[1] result = self._getResultGraphForTwoKeys("expectedPlus2Sigma", "expectedMinus2Sigma") graphs["exp2"] = result[0] graphs["exp2Down"] = result[1] result = self._getResultGraphForOneKey("observed") graphs["obs"] = result[0] graphs["obsDown"] = result[1] myName = _modelPattern % self._mssmModel if not os.path.exists(myName): raise Exception("Error: Cannot find file '%s'!" % myName) db = BRXSDB.BRXSDatabaseInterface(myName) graphs["Allowed"] = db.mhLimit("mh", "mHp", "mHp > 0", "125.0+-3.0") graphs["AllowedCentral"] = db.mhLimit("mh", "mHp", "mHp > 0", "125.0+-0.0") if mAtanbeta: for k in graphs.keys(): print k db.graphToMa(graphs[k]) if mAtanbeta: if self.isLightHp(): graphs["isomass"] = db.getIsoMass(160) else: graphs["isomass"] = db.getIsoMass(200) #graphName = "obsDown" #for i in range(0, graphs[graphName].GetN()): #print graphs[graphName].GetX()[i], graphs[graphName].GetY()[i] db.close() if self._mssmModel == "tauphobic": ## Fix a buggy second upper limit (the order of points is left to right, then right to left; remove further passes to fix the bug) #decreasingStatus = False #i = 0 #while i < graphs["Allowed"].GetN(): #removeStatus = False #y = graphs["Allowed"].GetY()[i] #if i > 0: #if graphs["Allowed"].GetY()[i-1] - y < 0: #decreasingStatus = True #else: #if decreasingStatus: #graphs["Allowed"].RemovePoint(i) #removeStatus = True #if not removeStatus: #i += 1 #for i in range(0, graphs["Allowed"].GetN()): #print graphs["Allowed"].GetX()[i], graphs["Allowed"].GetY()[i] ## Fix m=500 and m=600 n = graphs["Allowed"].GetN() graphs["Allowed"].SetPoint(n - 2, 500, 4.77) graphs["Allowed"].SetPoint(n - 1, 600, 4.71) myFinalStateLabel = [] if float(self._massPoints[0]) < 179: myFinalStateLabel.append( "^{}H^{+}#rightarrow#tau^{+}#nu_{#tau}, ^{}#tau_{h}+jets final state" ) else: myFinalStateLabel.append( "^{}H^{+}#rightarrow#tau^{+}#nu_{#tau} final states:") myFinalStateLabel.append(" ^{}#tau_{h}+jets") #myFinalStateLabel.append(" ^{}#tau_{h}+jets, #mu#tau_{h}, #it{ll}") myFinalStateLabel.append( "^{}H^{+}#rightarrowt#bar{b} final states:") myFinalStateLabel.append(" ^{}#it{l}+jets, #mu#tau_{h}, #it{ll}") if float(self._massPoints[0]) < 179: myName = "tanbeta_%s_light" % self._mssmModel if mAtanbeta: limit.doTanBetaPlotGeneric(myName + "_mA", graphs, 19700, myFinalStateLabel, limit.mA(), self._mssmModel, regime="light") else: limit.doTanBetaPlotGeneric(myName, graphs, 19700, myFinalStateLabel, limit.mHplus(), self._mssmModel, regime="light") else: myName = "limitsTanbCombination_heavy_" + self._mssmModel if mAtanbeta: limit.doTanBetaPlotGeneric(myName + "_mA", graphs, 19700, myFinalStateLabel, limit.mA(), self._mssmModel, regime="combination") else: limit.doTanBetaPlotGeneric(myName, graphs, 19700, myFinalStateLabel, limit.mHplus(), self._mssmModel, regime="combination")
def doBRlimit(limits, unblindedStatus, opts, logy=False): ''' See https://twiki.cern.ch/twiki/bin/viewauth/CMS/Internal/FigGuidelines ''' graphs = [] if unblindedStatus: gr = limits.observedGraph() if gr != None: gr.SetPoint(gr.GetN()-1, gr.GetX()[gr.GetN()-1]-1e-10, gr.GetY()[gr.GetN()-1]) if opts.excludedArea: graphs.append(histograms.HistoGraph(gr, "Observed", drawStyle="PL", legendStyle=None)) excluded = gr.Clone() excluded.SetPoint(excluded.GetN(), excluded.GetX()[excluded.GetN()-1], 0.05) excluded.SetPoint(excluded.GetN(), excluded.GetX()[0], 0.05) limit.setExcludedStyle(excluded) graphs.append(histograms.HistoGraph(excluded, "Excluded", drawStyle="F", legendStyle="lpf", legendLabel="Observed")) else: graphs.append(histograms.HistoGraph(gr, "Observed", drawStyle="PL", legendStyle="lp")) # Add the expected lines graphs.extend([ histograms.HistoGraph(limits.expectedGraph(), "Expected", drawStyle="L"), histograms.HistoGraph(limits.expectedBandGraph(sigma=1), "Expected1", drawStyle="F", legendStyle="f"), #fl histograms.HistoGraph(limits.expectedBandGraph(sigma=2), "Expected2", drawStyle="F", legendStyle="f"), #fl ]) # Plot the TGraphs saveFormats = [".png", ".C", ".pdf"] if not opts.excludedArea: saveFormats.append(".eps") plot = plots.PlotBase(graphs, saveFormats=saveFormats) plot.setLuminosity(limits.getLuminosity()) plot.setLegendHeader("95% CL upper limits") # Customise legend entries plot.histoMgr.setHistoLegendLabelMany({ "Expected": "Median expected", "Expected1": "68% expected", "Expected2": "95% expected" #"Expected" : None, #"Expected1": "Expected median #pm 1#sigma", #"Expected2": "Expected median #pm 2#sigma" }) # Branching Ratio Assumption if 0: limit.BRassumption = "Assuming B(H^{+}#rightarrowt#bar{b}) = 1" # Create legend xPos = 0.53 legend = getLegend(limit, opts, xPos) plot.setLegend(legend) # Get y-min, y-max, and histogram name to be saved as ymin, ymax, saveName = getYMinMaxAndName(limits, "limitsBr", logy, opts) if opts.yMin != -1: ymin = opts.yMin if opts.yMax != -1: ymax = opts.yMax if len(limits.mass) == 1: plot.createFrame(saveName, opts={"xmin": limits.mass[0]-5.0, "xmax": limits.mass[0]+5.0, "ymin": ymin, "ymax": ymax}) else: plot.createFrame(saveName, opts={"ymin": ymin, "ymax": ymax}) # Add cut box? if opts.cutLine > 0: kwargs = {"greaterThan": True} plot.addCutBoxAndLine(cutValue=opts.cutLine, fillColor=ROOT.kRed, box=False, line=True, **kwargs) # Set x-axis title plot.frame.GetXaxis().SetTitle(limit.mHplus()) if limit.BRassumption != "": plot.frame.GetYaxis().SetTitle("95% CL limit for #sigma_{H^{+}} (pb)") else: plot.frame.GetYaxis().SetTitle(limit.sigmaBRlimit) # plot.frame.GetYaxis().SetTitle(limit.BRlimit) # Enable/Disable logscale for axes if logy: plot.getPad().SetLogy(logy) plot.getPad().SetLogx(opts.logx) # Enable grids in x and y? plot.getPad().SetGridx(opts.gridX) plot.getPad().SetGridy(opts.gridY) # Draw the plot with standard texts plot.draw() plot.addStandardTexts() # Add physics-related text on canvas addPhysicsText(histograms, limit, x=xPos) # Save the canvas plot.save() # Save the plots SavePlot(plot, saveName, os.path.join(opts.saveDir, opts.subdir) ) return
def doBRlimit(limits, unblindedStatus, opts, log=False): leptonicFS = False graphs = [] if unblindedStatus: gr = limits.observedGraph() if gr != None: gr.SetPoint(gr.GetN() - 1, gr.GetX()[gr.GetN() - 1] - 1e-10, gr.GetY()[gr.GetN() - 1]) if opts.excludedArea: graphs.append( histograms.HistoGraph(gr, "Observed", drawStyle="PL", legendStyle=None)) excluded = gr.Clone() excluded.SetPoint(excluded.GetN(), excluded.GetX()[excluded.GetN() - 1], 0.05) excluded.SetPoint(excluded.GetN(), excluded.GetX()[0], 0.05) limit.setExcludedStyle(excluded) graphs.append( histograms.HistoGraph(excluded, "Excluded", drawStyle="F", legendStyle="lpf", legendLabel="Observed")) else: graphs.append( histograms.HistoGraph(gr, "Observed", drawStyle="PL", legendStyle="lp")) graphs.extend([ histograms.HistoGraph(limits.expectedGraph(), "Expected", drawStyle="L"), histograms.HistoGraph(limits.expectedBandGraph(sigma=1), "Expected1", drawStyle="F", legendStyle="fl"), histograms.HistoGraph(limits.expectedBandGraph(sigma=2), "Expected2", drawStyle="F", legendStyle="fl"), ]) saveFormats = [".png", ".C", ".pdf"] if not opts.excludedArea: saveFormats.append(".eps") plot = plots.PlotBase(graphs, saveFormats=saveFormats) plot.setLuminosity(limits.getLuminosity()) plot.histoMgr.setHistoLegendLabelMany({ "Expected": None, "Expected1": "Expected median #pm 1#sigma", "Expected2": "Expected median #pm 2#sigma" }) dy = -0.1 limit.BRassumption = "" #limit.BRassumption = "Assuming B(H^{+}#rightarrow#tau^{+}#nu_{#tau}) = 1" #limit.BRassumption = "Assuming B(H^{+}#rightarrowt#bar{b}) = 1" if limit.BRassumption != "": dy -= 0.05 #if len(limits.getFinalstates()) > 1: # dy -= 0.1 # Create legend x = 0.51 x = 0.45 legend = histograms.createLegend(x, 0.78 + dy, x + 0.4, 0.92 + dy) legend.SetMargin(0.17) # Make room for the final state text if opts.excludedArea: legend.SetFillStyle(1001) plot.setLegend(legend) name = "limitsBr" ymin = 0 ymax = limits.getFinalstateYmaxBR() #fixme: alexandros if opts.logx: name += "_logx" if log: name += "_log" if limits.isHeavyStatus: ymin = 1e-3 ymax = 10.0 if limit.BRassumption != "": ymax = 10.0 else: ymin = 1e-3 ymax = 4e-2 if leptonicFS: ymax = 10 if len(limits.mass) == 1: plot.createFrame(name, opts={ "xmin": limits.mass[0] - 5.0, "xmax": limits.mass[0] + 5.0, "ymin": ymin, "ymax": ymax }) else: plot.createFrame(name, opts={"ymin": ymin, "ymax": ymax}) # Set x-axis title plot.frame.GetXaxis().SetTitle(limit.mHplus()) if limits.isHeavyStatus: if limit.BRassumption != "": plot.frame.GetYaxis().SetTitle( "95% CL limit for #sigma_{H^{+}} (pb)") else: plot.frame.GetYaxis().SetTitle(limit.sigmaBRlimit) else: plot.frame.GetYaxis().SetTitle(limit.BRlimit) # Enable/Disable logscale for axes if log: plot.getPad().SetLogy(log) if opts.logx: plot.getPad().SetLogx(log) # Draw the plot with standard texts plot.draw() plot.addStandardTexts() # Add physics-process text size = 20 x = 0.51 x = 0.45 process = limit.process if limits.isHeavyStatus: process = limit.processHeavy histograms.addText(x, 0.88, process, size=size) # Add final-state text # histograms.addText(x, 0.84, limits.getFinalstateText(), size=size) #fixme: alexandros histograms.addText(x, 0.84, "fully hadronic final state", size=size) #fixme: alexandros # histograms.addText(x, 0.84, "#tau_{h}+jets and #mu#tau_{h} final states", size=size) # histograms.addText(x, 0.84, "#tau_{h}+jets final state", size=size) # histograms.addText(x, 0.84, "#tau_{h}+jets, #mu#tau_{h}, ee, e#mu, #mu#mu final states", size=size) if leptonicFS: histograms.addText(x, 0.84, "#mu#tau_{h}, ee, e#mu, #mu#mu final states", size=size) if limit.BRassumption != "": histograms.addText(x, 0.79, limit.BRassumption, size=size) plot.save() return
def doBRlimit(limits, unblindedStatus, opts, log=False): leptonicFS = False graphs = [] if unblindedStatus: gr = limits.observedGraph() if gr != None: gr.SetPoint(gr.GetN()-1, gr.GetX()[gr.GetN()-1]-1e-10, gr.GetY()[gr.GetN()-1]) if opts.excludedArea: graphs.append(histograms.HistoGraph(gr, "Observed", drawStyle="PL", legendStyle=None)) excluded = gr.Clone() excluded.SetPoint(excluded.GetN(), excluded.GetX()[excluded.GetN()-1], 0.05) excluded.SetPoint(excluded.GetN(), excluded.GetX()[0], 0.05) limit.setExcludedStyle(excluded) graphs.append(histograms.HistoGraph(excluded, "Excluded", drawStyle="F", legendStyle="lpf", legendLabel="Observed")) else: graphs.append(histograms.HistoGraph(gr, "Observed", drawStyle="PL", legendStyle="lp")) graphs.extend([ histograms.HistoGraph(limits.expectedGraph(), "Expected", drawStyle="L"), histograms.HistoGraph(limits.expectedBandGraph(sigma=1), "Expected1", drawStyle="F", legendStyle="fl"), histograms.HistoGraph(limits.expectedBandGraph(sigma=2), "Expected2", drawStyle="F", legendStyle="fl"), ]) saveFormats = [".png", ".C"] if opts.excludedArea: saveFormats.append(".pdf") else: saveFormats.append(".eps") plot = plots.PlotBase(graphs, saveFormats=saveFormats) plot.setLuminosity(limits.getLuminosity()) plot.histoMgr.setHistoLegendLabelMany({ "Expected": None, "Expected1": "Expected median #pm 1#sigma", "Expected2": "Expected median #pm 2#sigma" }) dy = -0.1 limit.BRassumption = "Assuming B(H^{+}#rightarrow#tau^{+}#nu_{#tau}) = 1" #limit.BRassumption = "Assuming B(H^{+}#rightarrowt#bar{b}) = 1" if limit.BRassumption != "": dy -= 0.05 #if len(limits.getFinalstates()) > 1: # dy -= 0.1 x = 0.51 x = 0.4 legend = histograms.createLegend(x-0.01, 0.78+dy, 0.92, 0.92+dy) legend.SetMargin(0.17) # make room for the final state text if opts.excludedArea: legend.SetFillStyle(1001) plot.setLegend(legend) name = "limitsBr" ymin = 0 ymax = limits.getFinalstateYmaxBR() if log: name += "_log" if limits.isHeavyStatus: ymin = 1e-2 if limit.BRassumption != "": ymax = 1.5 else: ymin = 1e-3 ymax = 4e-2 if leptonicFS: ymax = 10 if len(limits.mass) == 1: plot.createFrame(name, opts={"xmin": limits.mass[0]-5.0, "xmax": limits.mass[0]+5.0, "ymin": ymin, "ymax": ymax}) else: plot.createFrame(name, opts={"ymin": ymin, "ymax": ymax}) plot.frame.GetXaxis().SetTitle(limit.mHplus()) if limits.isHeavyStatus: if limit.BRassumption != "": plot.frame.GetYaxis().SetTitle("95% CL limit for #sigma_{H^{+}} (pb)") else: plot.frame.GetYaxis().SetTitle(limit.sigmaBRlimit) else: plot.frame.GetYaxis().SetTitle(limit.BRlimit) if log: plot.getPad().SetLogy(log) plot.draw() plot.addStandardTexts() size = 20 x = 0.51 x = 0.4 process = limit.process if limits.isHeavyStatus: process = limit.processHeavy histograms.addText(x, 0.88, process, size=size) #histograms.addText(x, 0.84, limits.getFinalstateText(), size=size) #histograms.addText(x, 0.84, "#tau_{h}+jets final state", size=size) histograms.addText(x, 0.84, "#tau_{h}+jets and #mu#tau_{h} final states", size=size) #histograms.addText(x, 0.84, "#tau_{h}+jets, #mu#tau_{h}, ee, e#mu, #mu#mu final states", size=size) if leptonicFS: histograms.addText(x, 0.84, "#mu#tau_{h}, ee, e#mu, #mu#mu final states", size=size) if limit.BRassumption != "": histograms.addText(x, 0.79, limit.BRassumption, size=size) plot.save()
def main(): if len(sys.argv) == 1: usage() rootfile = "" jsonfile = "limits.json" root_re = re.compile("(?P<rootfile>(\S*\.root))") json_re = re.compile("(?P<jsonfile>(\S*\.json))") for argv in sys.argv: match = root_re.search(argv) if match: rootfile = match.group(0) match = json_re.search(argv) if match: jsonfile = match.group(0) limits = limit.BRLimits(limitsfile=jsonfile,configfile="limitdata/lightHplus_configuration.json") # Enable OpenGL ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1) # Apply TDR style style = tdrstyle.TDRStyle() if limit.forPaper: histograms.cmsTextMode = histograms.CMSMode.PAPER #histograms.cmsTextMode = histograms.CMSMode.PAPER # tmp #histograms.cmsTextMode = histograms.CMSMode.UNPUBLISHED # tmp limit.forPaper = True # to get GeV without c^2 # Get BR limits masses = limits.mass brs = limits.observed print "Observed masses and BR's" for i in range(len(masses)): print " ",masses[i],brs[i] global db db = BRXSDB.BRXSDatabaseInterface(rootfile) for i,m in enumerate(masses): db.addExperimentalBRLimit(m,brs[i]) graphs = {} obs = limits.observedGraph() # Remove blinded obs points for i in reversed(range(0,obs.GetN())): if obs.GetY()[i] < 0.00000001: print " REMOVING POINT",obs.GetY()[i]," corresponding mass=",obs.GetX()[i] obs.RemovePoint(i) print graphs["exp"] = limits.expectedGraph() graphs["exp1"] = limits.expectedBandGraph(sigma=1) graphs["exp2"] = limits.expectedBandGraph(sigma=2) if obs.GetN() > 0: graphs["obs"] = obs # Get theory uncertainties on observed # obs_th_plus = limit.getObservedPlus(obs,0.21) # obs_th_minus = limit.getObservedMinus(obs,0.21) # for gr in [obs_th_plus, obs_th_minus]: # gr.SetLineWidth(2) # gr.SetLineStyle(9) # graphs["obs_th_plus"] = obs_th_plus # graphs["obs_th_minus"] = obs_th_minus # Remove m=80 for gr in graphs.values(): limit.cleanGraph(gr, minX=90) print "Plotting graphs" for key in graphs.keys(): for i in range(graphs[key].GetN()): xs = graphs[key].GetX() ys = graphs[key].GetY() print " ",key,xs[i],ys[i] print # Interpret in MSSM xVariable = "mHp" # selection = "mu==200" selection = "mHp > 0" # scenario = "MSSM m_{h}^{max}" scenario = os.path.split(rootfile)[-1].replace(".root","") for key in graphs.keys(): print "Graph--------------------------------",key graphs[key] = db.graphToTanBetaCombined(graphs[key],xVariable,selection) #if key == "obs": #obsplus = db.getTheorUncert(graphs[key],xVariable,selection,"+") #graphs["obs_th_plus"] = db.graphToTanBetaCombined(obsplus,xVariable,selection) #obsminus = db.getTheorUncert(graphs[key],xVariable,selection,"-") #graphs["obs_th_minus"] = db.graphToTanBetaCombined(obsminus,xVariable,selection) print key,"done" graphs["mintanb"] = db.minimumTanbGraph("mHp",selection) if scenario == "lowMH-LHCHXSWG": graphs["Allowed"] = db.mhLimit("mH","mHp",selection,"125.0+-3.0") else: graphs["Allowed"] = db.mhLimit("mh","mHp",selection,"125.0+-3.0") graphs["isomass"] = None limit.doTanBetaPlotLight("limitsTanb_light_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mHplus(), scenario) # mH+ -> mA print "Replotting the graphs for (mA,tanb)" for key in graphs.keys(): print key #db.PrintGraph(graphs[key]) #print "check loop db.graphToMa" db.graphToMa(graphs[key]) graphs["isomass"] = db.getIsoMass(160) limit.doTanBetaPlotLight("limitsTanb_mA_light_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mA(), scenario)
def doPlot2(limits, legendLabels, name): graphs = [ histograms.HistoGraph(limits[0].expectedGraph(), "Expected", drawStyle="L"), histograms.HistoGraph(limits[0].expectedBandGraph(sigma=1), "Expected1", drawStyle="F", legendStyle="fl"), histograms.HistoGraph(limits[0].expectedBandGraph(sigma=2), "Expected2", drawStyle="F", legendStyle="fl"), ] graphs[0].getRootHisto().SetLineStyle(1) plot = plots.PlotBase(graphs) ll = { "Expected": None, "Expected1": "%s exp. median #pm 1#sigma" % legendLabels[0], "Expected2": "%s exp. median #pm 2#sigma" % legendLabels[0], } stGen = styles.generator() for i in xrange(1, len(limits)): gr = histograms.HistoGraph(limits[i].expectedGraph(), "Exp%d" % i, drawStyle="L") stGen(gr) gr.getRootHisto().SetLineWidth(3) gr.getRootHisto().SetLineStyle(1) plot.histoMgr.insertHisto(len(plot.histoMgr) - 2, gr, legendIndex=len(plot.histoMgr)) ll["Exp%d" % i] = "%s exp. median" % legendLabels[i] plot.histoMgr.setHistoLegendLabelMany(ll) legend = histograms.moveLegend(histograms.createLegend( 0.48, 0.75, 0.85, 0.92), dx=-0.02) if len(limits[0].getFinalstates()) > 1: legend = histograms.moveLegend(legend, dy=-0.1) plot.setLegend(legend) plot.createFrame(name + "_limits", opts={ "ymin": 0, "ymax": limits[0].getFinalstateYmaxBR() }) plot.frame.GetXaxis().SetTitle(limit.mHplus()) plot.frame.GetYaxis().SetTitle(limit.BRlimit) plot.draw() plot.setLuminosity(limits[0].getLuminosity()) plot.addStandardTexts(cmsTextPosition="outframe") size = 20 x = 0.2 histograms.addText(x, 0.88, limit.process, size=size) histograms.addText(x, 0.84, limits[0].getFinalstateText(), size=size) histograms.addText(x, 0.79, limit.BRassumption, size=size) plot.save()
def doPlot(limits, legendLabels, graphs, name, ylabel, opts={}, plotLabel=None, moveLegend={}, log=False): hg = [] ll = {} for i in xrange(len(graphs)): hg.append( histograms.HistoGraph(graphs[i], "Graph%d" % i, drawStyle="PL", legendStyle="lp")) ll["Graph%d" % i] = legendLabels[i] plot = plots.PlotBase(hg) plot.histoMgr.forEachHisto(styles.Generator(styleList[0:len(limits)])) def sty(h): r = h.getRootHisto() r.SetLineWidth(3) r.SetLineStyle(1) plot.histoMgr.forEachHisto(sty) plot.histoMgr.setHistoLegendLabelMany(ll) legend = histograms.createLegend(0.48, 0.65, 0.85, 0.92) if len(limits[0].getFinalstates()) > 1: legend = histograms.moveLegend(legend, dy=-0.1) if plotLabel: legend = histograms.moveLegend(legend, dy=-0.04) legend = histograms.moveLegend(legend, **moveLegend) plot.setLegend(legend) opts_ = {"ymin": 0} opts_.update(opts) plot.createFrame(name, opts=opts_) plot.frame.GetXaxis().SetTitle(limit.mHplus()) plot.frame.GetYaxis().SetTitle(ylabel) ROOT.gPad.SetLogy(log) plot.draw() plot.setLuminosity(limits[0].getLuminosity()) plot.addStandardTexts(cmsTextPosition="outframe") size = 20 x = 0.18 histograms.addText(x, 0.88, limit.process, size=size) histograms.addText(x, 0.84, limits[0].getFinalstateText(), size=size) histograms.addText(x, 0.79, limit.BRassumption, size=size) if plotLabel: histograms.addText(legend.GetX1() + 0.01, legend.GetY2(), plotLabel, size=size) plot.save()
def main(): if len(sys.argv) == 1: usage() rootfile = "" jsonfile = "limits.json" root_re = re.compile("(?P<rootfile>(\S*\.root))") json_re = re.compile("(?P<jsonfile>(\S*\.json))") for argv in sys.argv: match = root_re.search(argv) if match: rootfile = match.group(0) match = json_re.search(argv) if match: jsonfile = match.group(0) jsonfile = "limits2016/limits_withLeptonic_180522.json" limits = limit.BRLimits(limitsfile=jsonfile, configfile="limits2016/mu_configuration.json") # Enable OpenGL ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1) # Apply TDR style style = tdrstyle.TDRStyle() if limit.forPaper: histograms.cmsTextMode = histograms.CMSMode.PAPER # Get BR limits masses = limits.mass brs = limits.observed print "Observed masses and BR's" for i in range(len(masses)): print " ", masses[i], brs[i] global db db = BRXSDB.BRXSDatabaseInterface( rootfile, BRvariable="0.001*831.76*2*tHp_xsec*BR_Hp_taunu") for i, m in enumerate(masses): db.addExperimentalBRLimit(m, brs[i]) graphs = {} obs = limits.observedGraph() # Remove blinded obs points for i in reversed(range(0, obs.GetN())): if obs.GetY()[i] < 0.00000001: print " REMOVING POINT", obs.GetY( )[i], " corresponding mass=", obs.GetX()[i] obs.RemovePoint(i) print # graphs["exp"] = limits.expectedGraph() #x = array.array('d',masses) #y = array.array('d',[0.02]*len(masses)) #graphs["exp"] = ROOT.TGraph(len(masses),x,y) # graphs["exp1"] = limits.expectedBandGraph(sigma=1) # graphs["exp2"] = limits.expectedBandGraph(sigma=2) if obs.GetN() > 0: graphs["obs"] = obs # Remove m=80 for gr in graphs.values(): limit.cleanGraph(gr, 80) print "Plotting graphs" for key in graphs.keys(): for i in range(graphs[key].GetN()): xs = graphs[key].GetX() ys = graphs[key].GetY() print " ", key, xs[i], ys[i] print # Interpret in MSSM xVariable = "mu" scenario = os.path.split(rootfile)[-1].replace(".root", "") if scenario == "lowMHaltv-LHCHXSWG": xVariable = "mHp" selection = "" from JsonWriter import JsonWriter # for i in range(len(masses)): # mass = masses[i] # brlimit = brs[i] # if mass < 90: # continue # if not mass == 160: # continue # selection = "mHp == %s"%mass #graphs["muexcluded"] = db.muLimit(mass,"mu",selection,brlimit) #db.PrintGraph(graphs["muexcluded"],"muexcluded") jsonWriter = JsonWriter() print "check keys", graphs.keys() for key in graphs.keys(): print "Graph--------------------------------", key #db.PrintGraph(graphs[key],"Before graphToTanBetaCombined") graphs[key] = db.graphToTanBetaMu(graphs[key], xVariable, selection, True) print key, "done" jsonWriter.addGraph(key, graphs[key]) #graphs["Allowed"] = db.mhLimit("mH","mu",selection,"125.0+-3.0") if xVariable == "mHp": graphs["Allowed"] = db.mHLimit_mHp(selection, "125.0+-3.0") else: graphs["Allowed"] = db.mHLimit_mu(selection, "125.0+-3.0") jsonWriter.addGraph("Allowed", graphs["Allowed"]) graphs["Inaccessible"] = db.inaccessible(xVariable, selection) jsonWriter.addGraph("Inaccessible", graphs["Inaccessible"]) jsonWriter.addParameter("name", "limitsTanb_light_" + scenario) jsonWriter.addParameter("scenario", scenario) jsonWriter.addParameter("luminosity", limits.getLuminosity()) jsonWriter.addParameter("finalStateText", limits.getFinalstateText()) xvar = limit.mu() if xVariable == "mHp": xvar = limit.mHplus() jsonWriter.addParameter("mHplus", xvar) jsonWriter.addParameter("selection", selection) jsonWriter.addParameter("regime", "mu") jsonWriter.write("MSSMLimitMu_" + scenario + ".json") #limit.doTanBetaPlotLight("limitsTanb_light_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mHplus(), scenario) # if int(mass) in [155, 160]: # graphs["obs_th_plus"] = db.muLimit(mass,"mu",selection,brlimit*(1+0.29)) # graphs["obs_th_minus"] = db.muLimit(mass,"mu",selection,brlimit*(1-0.29)) # # for gr in [graphs["obs_th_plus"], graphs["obs_th_minus"]]: # gr.SetLineWidth(2) # gr.SetLineStyle(9) # # graphs["observed"] = graphs["muexcluded"].Clone() # graphs["observed"].SetLineWidth(2) # graphs["observed"].SetLineStyle(ROOT.kSolid) # graphs["observed"].SetLineColor(ROOT.kBlack) # # # Remove obs point # for name in ["observed", "obs_th_plus", "obs_th_minus"]: # gr = graphs[name] # print "Graph", name # for i in reversed(range(0,gr.GetN())): # if gr.GetY()[i] < 2 or gr.GetY()[i] > 65: # print " REMOVING POINT",gr.GetY()[i]," corresponding mass=",gr.GetX()[i] # gr.RemovePoint(i) # # graphs["Allowed"] = db.getHardCoded_mH_limitForMu(mass,0) # graphs["Allowed2"] = db.getHardCoded_mH_limitForMu(mass,1) # # doPlot(("limitsMu_light_mHp%s_"+scenario)%(int(mass)), graphs, limits, "#mu (GeV)",scenario, int(mass)) sys.exit()
def main(): if len(sys.argv) == 1: usage() rootfile = "" jsonfile = "limits.json" root_re = re.compile("(?P<rootfile>(\S*\.root))") json_re = re.compile("(?P<jsonfile>(\S*\.json))") for argv in sys.argv: match = root_re.search(argv) if match: rootfile = match.group(0) match = json_re.search(argv) if match: jsonfile = match.group(0) limits = limit.BRLimits(limitsfile=jsonfile,configfile="limitdata/lightHplus_configuration.json") # Enable OpenGL ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1) # Apply TDR style style = tdrstyle.TDRStyle() if limit.forPaper: histograms.cmsTextMode = histograms.CMSMode.PAPER limit.forPaper = True # to get GeV without c^2 # Get BR limits masses = limits.mass brs = limits.observed print "Observed masses and BR's" for i in range(len(masses)): print " ",masses[i],brs[i] global db db = BRXSDB.BRXSDatabaseInterface(rootfile,program="2HDMC",BRvariable="BR_tHpb") for i,m in enumerate(masses): db.addExperimentalBRLimit(m,brs[i]) graphs = {} obs = limits.observedGraph() # Remove blinded obs points for i in reversed(range(0,obs.GetN())): if obs.GetY()[i] < 0.00000001: print " REMOVING POINT",obs.GetY()[i]," corresponding mass=",obs.GetX()[i] obs.RemovePoint(i) print graphs["exp"] = limits.expectedGraph() graphs["exp1"] = limits.expectedBandGraph(sigma=1) graphs["exp2"] = limits.expectedBandGraph(sigma=2) if obs.GetN() > 0: graphs["obs"] = obs # Get theory uncertainties on observed obs_th_plus = limit.getObservedPlus(obs,0.21) obs_th_minus = limit.getObservedMinus(obs,0.21) for gr in [obs_th_plus, obs_th_minus]: gr.SetLineWidth(2) gr.SetLineStyle(9) graphs["obs_th_plus"] = obs_th_plus graphs["obs_th_minus"] = obs_th_minus # Remove m=80 for gr in graphs.values(): limit.cleanGraph(gr, minX=90) print "Plotting graphs" for key in graphs.keys(): for i in range(graphs[key].GetN()): xs = graphs[key].GetX() ys = graphs[key].GetY() print " ",key,xs[i],ys[i] print # Interpret in MSSM xVariable = "mHp" # selection = "mu==200" selection = "mHp>0" # scenario = "MSSM m_{h}^{max}" scenario = os.path.split(rootfile)[-1].replace(".root","") for key in graphs.keys(): print "Graph--------------------------------",key # graphs[key] = db.graphToTanBetaCombined(graphs[key],xVariable,selection) graphs[key] = db.graphToTanBeta(graphs[key],xVariable,selection,False) print key,"done" graphs["mintanb"] = db.minimumTanbGraph("mHp",selection) doPlot("limitsTanb_light_"+scenario, graphs, limits, limit.mHplus(),scenario)
def doLimitError(limits, unblindedStatus): expRelErrors = [] expLabels = {} obsRelErrors = [] obsLabels = {} order = [0, 1, -1, 2, -2] expErrors = [limits.expectedErrorGraph(sigma=s) for s in order] if expErrors[0] != None: exps = [limits.expectedGraph(sigma=s) for s in order] expRelErrors = [(limit.divideGraph(expErrors[i], exps[i]), "ExpRelErr%d" % i) for i in xrange(len(exps))] expLabels = { "ExpRelErr0": "Expected median", "ExpRelErr1": "Expected +1#sigma", "ExpRelErr2": "Expected -1#sigma", "ExpRelErr3": "Expected +2#sigma", "ExpRelErr4": "Expected -2#sigma", } if unblindedStatus: obsErr = limits.observedErrorGraph() if obsErr != None: obs = limits.observedGraph() if obs != None: obsRelErrors = [(limit.divideGraph(obsErr, obs), "ObsRelErr")] obsLabels = {"ObsRelErr": "Observed"} if len(expRelErrors) == 0 and len(obsRelErrors) == 0: return # Create the plot plot = plots.PlotBase() if len(expRelErrors) > 0: plot.histoMgr.extendHistos([ histograms.HistoGraph(x[0], x[1], drawStyle="PL", legendStyle="lp") for x in expRelErrors ]) plot.histoMgr.forEachHisto(styles.generator()) def sty(h): r = h.getRootHisto() r.SetLineStyle(1) r.SetLineWidth(3) r.SetMarkerSize(1.4) plot.histoMgr.forEachHisto(sty) plot.histoMgr.setHistoLegendLabelMany(expLabels) if unblindedStatus: if len(obsRelErrors) > 0: obsRelErrors[0][0].SetMarkerSize(1.4) obsRelErrors[0][0].SetMarkerStyle(25) plot.histoMgr.insertHisto( 0, histograms.HistoGraph(obsRelErrors[0][0], obsRelErrors[0][1], drawStyle="PL", legendStyle="lp")) plot.histoMgr.setHistoLegendLabelMany(obsLabels) plot.setLegend( histograms.moveLegend(histograms.createLegend(0.48, 0.75, 0.85, 0.92), dx=0.1, dy=-0.1)) if len(limits.mass) == 1: plot.createFrame("limitsBrRelativeUncertainty", opts={ "xmin": limits.mass[0] - 5.0, "xmax": limits.mass[0] + 5.0, "ymin": 0, "ymaxfactor": 1.5 }) else: plot.createFrame("limitsBrRelativeUncertainty", opts={ "ymin": 0, "ymaxfactor": 1.5 }) plot.frame.GetXaxis().SetTitle(limit.mHplus()) plot.frame.GetYaxis().SetTitle("Uncertainty/limit") plot.draw() plot.setLuminosity(limits.getLuminosity()) plot.addStandardTexts() size = 20 x = 0.2 histograms.addText(x, 0.88, limit.process, size=size) histograms.addText(x, 0.84, limits.getFinalstateText(), size=size) histograms.addText(x, 0.79, limit.BRassumption, size=size) size = 22 x = 0.55 histograms.addText(x, 0.88, "Toy MC relative", size=size) histograms.addText(x, 0.84, "statistical uncertainty", size=size) plot.save()
def doPlot(limits, legendLabels, graphs, name, ylabel, _opts={}, yTitle=None): # Definitions hg = [] ll = {} nGraphs = len(graphs) # For-loop: All HistoGraphs for i in xrange(nGraphs): hg.append( histograms.HistoGraph(graphs[i], "Graph%d" % i, drawStyle="PL", legendStyle="lp")) ll["Graph%d" % (i)] = legendLabels[i] # Create a plot-base object plot = plots.PlotBase(hg) plot.histoMgr.forEachHisto(styles.Generator(styleList[0:len(limits)])) def sty(h): r = h.getRootHisto() r.SetLineWidth(3) r.SetLineStyle(ROOT.kSolid) return # Apply style and set label plot.histoMgr.forEachHisto(sty) plot.histoMgr.setHistoLegendLabelMany(ll) # Create & set legend nGraphs = len(graphs) # If sigma bands are drawn each legend entry is plotted twice. Correct this in the count if "Sigma1" in name or "Sigma2" in name: nGraphs = nGraphs / 2.0 legend = getLegend(nGraphs, limit, xPosLeg) plot.setLegend(legend) # Determine save name, minimum and maximum of y-axis ymin, ymax, saveName = getYMinMaxAndName(limits, name) if _opts.yMin == -1: _opts.yMin = ymin if _opts.yMax == -1: _opts.yMax = ymax # Create the frame and set axes titles plot.createFrame(saveName, opts={"ymin": _opts.yMin, "ymax": _opts.yMax}) # Add cut line? if opts.cutLine != 999.9: kwargs = {"greaterThan": True} plot.addCutBoxAndLine(cutValue=_opts.cutLine, fillColor=ROOT.kRed, box=False, line=True, **kwargs) if opts.cutLineY != 999.9: kwargs = { "greaterThan": True, "mainCanvas": True, "ratioCanvas": False } plot.addCutBoxAndLineY(cutValue=_opts.cutLineY, fillColor=ROOT.kRed, box=False, line=True, **kwargs) # Set axes titles plot.frame.GetXaxis().SetTitle(limit.mHplus()) plot.frame.GetYaxis().SetTitle(ylabel) # Enable/Disable logscale for axes ROOT.gPad.SetLogy(_opts.logY) ROOT.gPad.SetLogx(_opts.logX) # Draw and add text plot.draw() plot.setLuminosity(limits[0].getLuminosity()) plot.addStandardTexts(cmsTextPosition="outframe") addPhysicsText(histograms, limit, x=xPosText) # Save plots and return SavePlot(plot, _opts.saveDir, saveName, [".png"]) #, ".pdf"]) return
def main(): if len(sys.argv) == 1: usage() rootfile = "" jsonfile = "limits.json" root_re = re.compile("(?P<rootfile>(\S*\.root))") json_re = re.compile("(?P<jsonfile>(\S*\.json))") for argv in sys.argv: match = root_re.search(argv) if match: rootfile = match.group(0) match = json_re.search(argv) if match: jsonfile = match.group(0) # jsonfile = "limits_heavy2016.json" # jsonfile = "limits2016/limitsForMSSMplots_ICHEP_v3_heavy.json" jsonfile = "limits2016/limits_heavy_20171011.json" # limits = limit.BRLimits(limitsfile=jsonfile,configfile="configurationHeavy.json") limits = limit.BRLimits( limitsfile=jsonfile, configfile="limits2016/heavyHplus_configuration.json") # Enable OpenGL ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1) # Apply TDR style style = tdrstyle.TDRStyle() #if limit.forPaper: # histograms.cmsTextMode = histograms.CMSMode.PAPER #histograms.cmsTextMode = histograms.CMSMode.PAPER # tmp #histograms.cmsTextMode = histograms.CMSMode.UNPUBLISHED # tmp histograms.cmsTextMode = histograms.CMSMode.PRELIMINARY limit.forPaper = True # to get GeV without c^2 # Get BR limits masses = limits.mass brs = limits.observed print "Observed masses and sigma*BR's" for i in range(len(masses)): print " ", masses[i], brs[i] global db db = BRXSDB.BRXSDatabaseInterface(rootfile) db.BRvariable = "2*0.001*tHp_xsec*BR_Hp_taunu" # XSEC only for H-, multiply with 2 to get H+ and H- ; multiply by 0.001 to fb -> pb for i, m in enumerate(masses): db.addExperimentalBRLimit(m, brs[i]) graphs = {} obs = limits.observedGraph() # Remove blinded obs points for i in reversed(range(0, obs.GetN())): if obs.GetY()[i] < 0.00000001: print " REMOVING POINT", obs.GetY( )[i], " corresponding mass=", obs.GetX()[i] obs.RemovePoint(i) print graphs["exp"] = limits.expectedGraph() graphs["exp1"] = limits.expectedBandGraph(sigma=1) graphs["exp2"] = limits.expectedBandGraph(sigma=2) if obs.GetN() > 0: graphs["obs"] = obs # Get theory uncertainties on observed # obs_th_plus = limit.getObservedPlus(obs,0.32) # obs_th_minus = limit.getObservedMinus(obs,0.32) # for gr in [obs_th_plus, obs_th_minus]: # gr.SetLineWidth(2) # gr.SetLineStyle(9) # graphs["obs_th_plus"] = obs_th_plus # graphs["obs_th_minus"] = obs_th_minus # Remove m=180,190 for gr in graphs.values(): # limit.cleanGraph(gr, 750) limit.cleanGraph(gr, 800) limit.cleanGraph(gr, 1000) limit.cleanGraph(gr, 2000) limit.cleanGraph(gr, 3000) print "Plotting graphs" for key in graphs.keys(): for i in range(graphs[key].GetN()): xs = graphs[key].GetX() ys = graphs[key].GetY() print " ", key, xs[i], ys[i] print # Interpret in MSSM xVariable = "mHp" selection = "mHp > 0 && mu==200" # selection = "mHp > 0 && mu==500" # scenario = "MSSM m_{h}^{max}" scenario = os.path.split(rootfile)[-1].replace(".root", "") print scenario from JsonWriter import JsonWriter jsonWriter = JsonWriter() for key in graphs.keys(): print "Graph--------------------------------", key graphs[key] = db.graphToTanBeta(graphs[key], xVariable, selection, highTanbRegion=True) #if key == "obs": #obsplus = db.getTheorUncert(graphs[key],xVariable,selection,"+") #graphs["obs_th_plus"] = db.graphToTanBeta(obsplus,xVariable,selection) #obsminus = db.getTheorUncert(graphs[key],xVariable,selection,"-") #graphs["obs_th_minus"] = db.graphToTanBeta(obsminus,xVariable,selection) print key, "done" jsonWriter.addGraph(key, graphs[key]) # graphs["mintanb"] = db.minimumTanbGraph("mHp",selection) if scenario == "lowMH-LHCHXSWG": graphs["Allowed"] = db.mhLimit("mH", "mHp", selection, "125.0+-3.0") else: graphs["Allowed"] = db.mhLimit("mh", "mHp", selection + "&&mHp>175", "125.0+-3.0") if scenario == "tauphobic-LHCHXSWG": # Fix a buggy second upper limit (the order of points is left to right, then right to left; remove further passes to fix the bug) decreasingStatus = False i = 0 while i < graphs["Allowed"].GetN(): removeStatus = False y = graphs["Allowed"].GetY()[i] if i > 0: if graphs["Allowed"].GetY()[i - 1] - y < 0: decreasingStatus = True else: if decreasingStatus: graphs["Allowed"].RemovePoint(i) removeStatus = True if not removeStatus: i += 1 #for i in range(0, graphs["Allowed"].GetN()): #print graphs["Allowed"].GetX()[i], graphs["Allowed"].GetY()[i] # del graphs["isomass"] jsonWriter.addGraph("Allowed", graphs["Allowed"]) jsonWriter.addParameter("name", "limitsTanb_heavy_" + scenario) jsonWriter.addParameter("scenario", scenario) jsonWriter.addParameter("luminosity", limits.getLuminosity()) jsonWriter.addParameter("finalStateText", limits.getFinalstateText()) jsonWriter.addParameter("mHplus", limit.mHplus()) jsonWriter.addParameter("selection", selection) jsonWriter.addParameter("regime", "heavy") jsonWriter.write("MSSMLimitHeavy_" + scenario + ".json") limit.doTanBetaPlotHeavy("limitsTanb_heavy_" + scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mHplus(), scenario) sys.exit() # mH+ -> mA print "Replotting the graphs for (mA,tanb)" for key in graphs.keys(): print key #db.PrintGraph(graphs[key]) #print "check loop db.graphToMa" db.graphToMa(graphs[key]) graphs["isomass"] = db.getIsoMass(200) # doPlot("limitsTanb_mA_heavy_"+scenario, graphs, limits, limit.mA(),scenario) limit.doTanBetaPlotHeavy("limitsTanb_mA_heavy_" + scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mA(), scenario)
def doPlotSigmaBands(limits, legendLabels, saveName, _opts={}): # Define graphs to be used graphs = [ histograms.HistoGraph(limits[0].expectedGraph(), "Expected", drawStyle="L"), histograms.HistoGraph(limits[0].expectedBandGraph(sigma=1), "Expected1", drawStyle="F", legendStyle="fl"), histograms.HistoGraph(limits[0].expectedBandGraph(sigma=2), "Expected2", drawStyle="F", legendStyle="fl"), ] # Set line style graphs[0].getRootHisto().SetLineStyle(ROOT.kSolid) # Create plot base object plot = plots.PlotBase(graphs) ll = { "Expected": None, "Expected1": "%s #pm 1#sigma" % legendLabels[0], "Expected2": "%s #pm 2#sigma" % legendLabels[0], #"Expected1": "%s exp. median #pm 1#sigma" % legendLabels[0], #"Expected2": "%s exp. median #pm 2#sigma" % legendLabels[0], } stGen = styles.generator() nLimits = len(limits) # For-loop: All limits for i in xrange(1, nLimits): name = "Exp%d" % i gr = histograms.HistoGraph(limits[i].expectedGraph(), name, drawStyle="L") stGen(gr) gr.getRootHisto().SetLineWidth(3) gr.getRootHisto().SetLineStyle(1) plot.histoMgr.insertHisto(len(plot.histoMgr) - 2, gr, legendIndex=len(plot.histoMgr)) ll[name] = "%s" % legendLabels[i] # "%s exp. median" % legendLabels[i] # Set histo labels plot.histoMgr.setHistoLegendLabelMany(ll) # Create & set legend nGraphs = len(graphs) # If sigma bands are drawn each legend entry is plotted twice. Correct this in the count if "Sigma1" in name or "Sigma2" in name: nGraphs = nGraphs / 2.0 legend = getLegend(nGraphs + 4, limit, xPosLeg) plot.setLegend(legend) # Determine save name, minimum and maximum of y-axis ymin, ymax, saveName = getYMinMaxAndName(limits, saveName) if _opts.yMin == -1: _opts.yMin = ymin if _opts.yMax == -1: _opts.yMax = ymax # Create the frame and set axes titles plot.createFrame(saveName, opts={"ymin": _opts.yMin, "ymax": _opts.yMax}) # Add cut line? if _opts.cutLine != 999.9: kwargs = {"greaterThan": True} plot.addCutBoxAndLine(cutValue=_opts.cutLine, fillColor=ROOT.kRed, box=False, line=True, **kwargs) if opts.cutLineY != 999.9: kwargs = { "greaterThan": True, "mainCanvas": True, "ratioCanvas": False } plot.addCutBoxAndLineY(cutValue=_opts.cutLineY, fillColor=ROOT.kRed, box=False, line=True, **kwargs) # Set axes titles plot.frame.GetXaxis().SetTitle(limit.mHplus()) plot.frame.GetYaxis().SetTitle(limit.BRlimit) # Enable/Disable logscale for axes ROOT.gPad.SetLogy(_opts.logY) ROOT.gPad.SetLogx(_opts.logX) # Draw the plot with standard texts plot.draw() plot.addStandardTexts(cmsTextPosition="outframe") plot.setLuminosity(limits[0].getLuminosity()) addPhysicsText(histograms, limit, x=xPosText) # Save the plots & return SavePlot(plot, _opts.saveDir, saveName, [".png"]) #, ".pdf"]) return
def doLimitError(limits, unblindedStatus): expRelErrors = [] expLabels = {} obsRelErrors = [] obsLabels = {} order = [0, 1, -1, 2, -2] expErrors = [limits.expectedErrorGraph(sigma=s) for s in order] if expErrors[0] != None: exps = [limits.expectedGraph(sigma=s) for s in order] expRelErrors = [(limit.divideGraph(expErrors[i], exps[i]), "ExpRelErr%d"%i) for i in xrange(len(exps))] expLabels = { "ExpRelErr0": "Expected median", "ExpRelErr1": "Expected +1#sigma", "ExpRelErr2": "Expected -1#sigma", "ExpRelErr3": "Expected +2#sigma", "ExpRelErr4": "Expected -2#sigma", } if unblindedStatus: obsErr = limits.observedErrorGraph() if obsErr != None: obs = limits.observedGraph() if obs != None: obsRelErrors = [(limit.divideGraph(obsErr, obs), "ObsRelErr")] obsLabels = {"ObsRelErr": "Observed"} if len(expRelErrors) == 0 and len(obsRelErrors) == 0: return # Create the plot plot = plots.PlotBase() if len(expRelErrors) > 0: plot.histoMgr.extendHistos([histograms.HistoGraph(x[0], x[1], drawStyle="PL", legendStyle="lp") for x in expRelErrors]) plot.histoMgr.forEachHisto(styles.generator()) def sty(h): r = h.getRootHisto() r.SetLineStyle(1) r.SetLineWidth(3) r.SetMarkerSize(1.4) plot.histoMgr.forEachHisto(sty) plot.histoMgr.setHistoLegendLabelMany(expLabels) if unblindedStatus: if len(obsRelErrors) > 0: obsRelErrors[0][0].SetMarkerSize(1.4) obsRelErrors[0][0].SetMarkerStyle(25) plot.histoMgr.insertHisto(0, histograms.HistoGraph(obsRelErrors[0][0], obsRelErrors[0][1], drawStyle="PL", legendStyle="lp")) plot.histoMgr.setHistoLegendLabelMany(obsLabels) plot.setLegend(histograms.moveLegend(histograms.createLegend(0.48, 0.75, 0.85, 0.92), dx=0.1, dy=-0.1)) if len(limits.mass) == 1: plot.createFrame("limitsBrRelativeUncertainty", opts={"xmin": limits.mass[0]-5.0, "xmax": limits.mass[0]+5.0, "ymin": 0, "ymaxfactor": 1.5}) else: plot.createFrame("limitsBrRelativeUncertainty", opts={"ymin": 0, "ymaxfactor": 1.5}) plot.frame.GetXaxis().SetTitle(limit.mHplus()) plot.frame.GetYaxis().SetTitle("Uncertainty/limit") plot.draw() plot.setLuminosity(limits.getLuminosity()) plot.addStandardTexts() size = 20 x = 0.2 histograms.addText(x, 0.88, limit.process, size=size) histograms.addText(x, 0.84, limits.getFinalstateText(), size=size) histograms.addText(x, 0.79, limit.BRassumption, size=size) size = 22 x = 0.55 histograms.addText(x, 0.88, "Toy MC relative", size=size) histograms.addText(x, 0.84, "statistical uncertainty", size=size) plot.save()
def main(): if len(sys.argv) == 1: usage() rootfile = "" jsonfile = "limits.json" root_re = re.compile("(?P<rootfile>(\S*\.root))") json_re = re.compile("(?P<jsonfile>(\S*\.json))") for argv in sys.argv: match = root_re.search(argv) if match: rootfile = match.group(0) match = json_re.search(argv) if match: jsonfile = match.group(0) # jsonfile = "limits_light2016.json" # jsonfile = "limits2016/limitsForMSSMplots_ICHEP_v2_light.json" # jsonfile = "limits2016/limits_light_20171011.json" # jsonfile = "limits2016/limits_light_180131.json" # jsonfile = "limits2016/limits_light_180205.json" # jsonfile = "limits2016/limits_light_180318.json" # jsonfile = "limits2016/limits_light_180417.json" # jsonfile = "limits2016/limits_unblinded_180809/limits_light.json" # jsonfile = "limits2016/limits_unblinded_180809/limits_full_leptonic+hadronic_with_intermediate.json" jsonfile = "limits2016/limits_unblinded_withLeptonic_30082018/taunu_extInt_BR.json" # limits = limit.BRLimits(limitsfile=jsonfile,configfile="limitdata/lightHplus_configuration.json") limits = limit.BRLimits(limitsfile=jsonfile,configfile="limits2016/lightHplus_configuration.json") # Enable OpenGL ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1) # Apply TDR style style = tdrstyle.TDRStyle() # if limit.forPaper: # histograms.cmsTextMode = histograms.CMSMode.PAPER histograms.cmsTextMode = histograms.CMSMode.PRELIMINARY # histograms.cmsTextMode = histograms.CMSMode.PAPER # tmp #histograms.cmsTextMode = histograms.CMSMode.UNPUBLISHED # tmp limit.forPaper = True # to get GeV without c^2 # Get BR limits masses = limits.mass brs = limits.observed print "Observed masses and BR's" for i in range(len(masses)): print " ",masses[i],brs[i] global db db = BRXSDB.BRXSDatabaseInterface(rootfile) for i,m in enumerate(masses): db.addExperimentalBRLimit(m,brs[i]) graphs = {} obs = limits.observedGraph() # Remove blinded obs points for i in reversed(range(0,obs.GetN())): if obs.GetY()[i] < 0.00000001: print " REMOVING POINT",obs.GetY()[i]," corresponding mass=",obs.GetX()[i] obs.RemovePoint(i) print graphs["exp"] = limits.expectedGraph() graphs["exp1"] = limits.expectedBandGraph(sigma=1) graphs["exp2"] = limits.expectedBandGraph(sigma=2) if obs.GetN() > 0: graphs["obs"] = obs # Get theory uncertainties on observed # obs_th_plus = limit.getObservedPlus(obs,0.21) # obs_th_minus = limit.getObservedMinus(obs,0.21) # for gr in [obs_th_plus, obs_th_minus]: # gr.SetLineWidth(2) # gr.SetLineStyle(9) # graphs["obs_th_plus"] = obs_th_plus # graphs["obs_th_minus"] = obs_th_minus # Remove m=80 for gr in graphs.values(): limit.cleanGraph(gr, 80) print "Plotting graphs" for key in graphs.keys(): for i in range(graphs[key].GetN()): xs = graphs[key].GetX() ys = graphs[key].GetY() print " ",key,xs[i],ys[i] print # Interpret in MSSM xVariable = "mHp" selection = "mu==200" # selection = "mHp > 0" # scenario = "MSSM m_{h}^{max}" scenario = os.path.split(rootfile)[-1].replace(".root","") from JsonWriter import JsonWriter jsonWriter = JsonWriter() for key in graphs.keys(): print "Graph--------------------------------",key graphs[key] = db.graphToTanBetaCombined(graphs[key],xVariable,selection) #if key == "obs": #obsplus = db.getTheorUncert(graphs[key],xVariable,selection,"+") #graphs["obs_th_plus"] = db.graphToTanBetaCombined(obsplus,xVariable,selection) #obsminus = db.getTheorUncert(graphs[key],xVariable,selection,"-") #graphs["obs_th_minus"] = db.graphToTanBetaCombined(obsminus,xVariable,selection) print key,"done" jsonWriter.addGraph(key,graphs[key]) graphs["mintanb"] = db.minimumTanbGraph("mHp",selection) if scenario == "lowMH-LHCHXSWG": graphs["Allowed"] = db.mhLimit("mH","mHp",selection,"125.0+-3.0") else: graphs["Allowed"] = db.mhLimit("mh","mHp",selection,"125.0+-3.0") # graphs["isomass"] = None jsonWriter.addGraph("Allowed",graphs["Allowed"]) jsonWriter.addGraph("mintanb",graphs["mintanb"]) name = "limitsTanb_light_" finalStateText = limits.getFinalstateText() if "leptonic" in jsonfile: name = "limitsTanb_light_LeptHadrFS_" finalStateText = "#tau+jets final state" jsonWriter.addParameter("name",name+scenario) jsonWriter.addParameter("scenario",scenario) jsonWriter.addParameter("luminosity",limits.getLuminosity()) jsonWriter.addParameter("finalStateText",finalStateText) jsonWriter.addParameter("mHplus",limit.mHplus()) jsonWriter.addParameter("selection",selection) jsonWriter.addParameter("regime","light") jsonWriter.write(name+scenario+".json") limit.doTanBetaPlotLight("limitsTanb_light_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mHplus(), scenario) sys.exit() # mH+ -> mA print "Replotting the graphs for (mA,tanb)" for key in graphs.keys(): print key #db.PrintGraph(graphs[key]) #print "check loop db.graphToMa" db.graphToMa(graphs[key]) graphs["isomass"] = db.getIsoMass(160) limit.doTanBetaPlotLight("limitsTanb_mA_light_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mA(), scenario)
def main(): limits = limit.BRLimits() # Apply TDR style style = tdrstyle.TDRStyle() if limit.forPaper: histograms.cmsTextMode = histograms.CMSMode.PAPER # Get BR limits graphs = {} obs = limits.observedGraph() myBlindedStatus = True for i in xrange(0, obs.GetN()): if abs(obs.GetY()[i]) > 0.00001: myBlindedStatus = False if not myBlindedStatus: graphs["obs"] = obs graphs["exp"] = limits.expectedGraph() graphs["exp1"] = limits.expectedBandGraph(sigma=1) graphs["exp2"] = limits.expectedBandGraph(sigma=2) # Remove m=80 for gr in graphs.values(): limit.cleanGraph(gr, minX=100) # Get theory uncertainties on observed if not myBlindedStatus: obs_th_plus = limit.getObservedPlus(obs) obs_th_minus = limit.getObservedMinus(obs) for gr in [obs_th_plus, obs_th_minus]: gr.SetLineWidth(3) gr.SetLineStyle(5) # gr.SetLineStyle(9) graphs["obs_th_plus"] = obs_th_plus graphs["obs_th_minus"] = obs_th_minus # Interpret in MSSM global mu for key in graphs.keys(): removeNotValid = not (key in ["exp1", "exp2"]) graphs[key] = limit.graphToTanBeta(graphs[key], mu, removeNotValid) doPlot("limitsTanb_mh", graphs, limits, limit.mHplus()) for gr in graphs.values(): limit.graphToMa(gr) doPlot("limitsTanb_ma", graphs, limits, limit.mA()) if myBlindedStatus: print "Refusing cowardly to do mu variation plots for blinded results" return # Mu variations mus = [1000, 200, -200, -1000] muGraphs = [(limit.graphToTanBeta(obs, m), m) for m in mus] def muStyle(h, markerStyle, lineStyle, color): rh = h.getRootHisto() rh.SetMarkerStyle(markerStyle) rh.SetMarkerColor(color) rh.SetLineStyle(lineStyle) rh.SetLineColor(color) rh.SetLineWidth(504) rh.SetFillStyle(3005) st = [ lambda h: muStyle(h, 21, 1, 4), lambda h: muStyle(h, 20, 1, 1), lambda h: muStyle(h, 20, 2, 1), lambda h: muStyle(h, 21, 2, 4) ] doPlotMu("limitsTanb_mus_mh", muGraphs, st, limits, limit.mHplus()) for gr, mu in muGraphs: limit.graphToMa(gr) doPlotMu("limitsTanb_mus_ma", muGraphs, st, limits, limit.mA())
def main(): if len(sys.argv) == 1: usage() rootfile = "" jsonfile = "limits.json" root_re = re.compile("(?P<rootfile>(\S*\.root))") json_re = re.compile("(?P<jsonfile>(\S*\.json))") for argv in sys.argv: match = root_re.search(argv) if match: rootfile = match.group(0) match = json_re.search(argv) if match: jsonfile = match.group(0) # jsonfile = "limits_light2016.json" # jsonfile = "limits2016/limitsForMSSMplots_ICHEP_v2_light.json" # jsonfile = "limits2016/limits_light_20171011.json" # jsonfile = "limits2016/limits_light_180131.json" # jsonfile = "limits2016/limits_light_180205.json" # jsonfile = "limits2016/limits_light_180318.json" # jsonfile = "limits2016/limits_light_180417.json" # jsonfile = "limits2016/limits_unblinded_180809/limits_light.json" # jsonfile = "limits2016/limits_unblinded_180809/limits_full_leptonic+hadronic_with_intermediate.json" jsonfile = "limits2016/limits_unblinded_withLeptonic_30082018/taunu_extInt_BR.json" # limits = limit.BRLimits(limitsfile=jsonfile,configfile="limitdata/lightHplus_configuration.json") limits = limit.BRLimits( limitsfile=jsonfile, configfile="limits2016/lightHplus_configuration.json") # Enable OpenGL ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1) # Apply TDR style style = tdrstyle.TDRStyle() # if limit.forPaper: # histograms.cmsTextMode = histograms.CMSMode.PAPER histograms.cmsTextMode = histograms.CMSMode.PRELIMINARY # histograms.cmsTextMode = histograms.CMSMode.PAPER # tmp #histograms.cmsTextMode = histograms.CMSMode.UNPUBLISHED # tmp limit.forPaper = True # to get GeV without c^2 # Get BR limits masses = limits.mass brs = limits.observed print "Observed masses and BR's" for i in range(len(masses)): print " ", masses[i], brs[i] global db db = BRXSDB.BRXSDatabaseInterface(rootfile) for i, m in enumerate(masses): db.addExperimentalBRLimit(m, brs[i]) graphs = {} obs = limits.observedGraph() # Remove blinded obs points for i in reversed(range(0, obs.GetN())): if obs.GetY()[i] < 0.00000001: print " REMOVING POINT", obs.GetY( )[i], " corresponding mass=", obs.GetX()[i] obs.RemovePoint(i) print graphs["exp"] = limits.expectedGraph() graphs["exp1"] = limits.expectedBandGraph(sigma=1) graphs["exp2"] = limits.expectedBandGraph(sigma=2) if obs.GetN() > 0: graphs["obs"] = obs # Get theory uncertainties on observed # obs_th_plus = limit.getObservedPlus(obs,0.21) # obs_th_minus = limit.getObservedMinus(obs,0.21) # for gr in [obs_th_plus, obs_th_minus]: # gr.SetLineWidth(2) # gr.SetLineStyle(9) # graphs["obs_th_plus"] = obs_th_plus # graphs["obs_th_minus"] = obs_th_minus # Remove m=80 for gr in graphs.values(): limit.cleanGraph(gr, 80) print "Plotting graphs" for key in graphs.keys(): for i in range(graphs[key].GetN()): xs = graphs[key].GetX() ys = graphs[key].GetY() print " ", key, xs[i], ys[i] print # Interpret in MSSM xVariable = "mHp" selection = "mu==200" # selection = "mHp > 0" # scenario = "MSSM m_{h}^{max}" scenario = os.path.split(rootfile)[-1].replace(".root", "") from JsonWriter import JsonWriter jsonWriter = JsonWriter() for key in graphs.keys(): print "Graph--------------------------------", key graphs[key] = db.graphToTanBetaCombined(graphs[key], xVariable, selection) #if key == "obs": #obsplus = db.getTheorUncert(graphs[key],xVariable,selection,"+") #graphs["obs_th_plus"] = db.graphToTanBetaCombined(obsplus,xVariable,selection) #obsminus = db.getTheorUncert(graphs[key],xVariable,selection,"-") #graphs["obs_th_minus"] = db.graphToTanBetaCombined(obsminus,xVariable,selection) print key, "done" jsonWriter.addGraph(key, graphs[key]) graphs["mintanb"] = db.minimumTanbGraph("mHp", selection) if scenario == "lowMH-LHCHXSWG": graphs["Allowed"] = db.mhLimit("mH", "mHp", selection, "125.0+-3.0") else: graphs["Allowed"] = db.mhLimit("mh", "mHp", selection, "125.0+-3.0") # graphs["isomass"] = None jsonWriter.addGraph("Allowed", graphs["Allowed"]) jsonWriter.addGraph("mintanb", graphs["mintanb"]) name = "limitsTanb_light_" finalStateText = limits.getFinalstateText() if "leptonic" in jsonfile: name = "limitsTanb_light_LeptHadrFS_" finalStateText = "#tau+jets final state" jsonWriter.addParameter("name", name + scenario) jsonWriter.addParameter("scenario", scenario) jsonWriter.addParameter("luminosity", limits.getLuminosity()) jsonWriter.addParameter("finalStateText", finalStateText) jsonWriter.addParameter("mHplus", limit.mHplus()) jsonWriter.addParameter("selection", selection) jsonWriter.addParameter("regime", "light") jsonWriter.write(name + scenario + ".json") limit.doTanBetaPlotLight("limitsTanb_light_" + scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mHplus(), scenario) sys.exit() # mH+ -> mA print "Replotting the graphs for (mA,tanb)" for key in graphs.keys(): print key #db.PrintGraph(graphs[key]) #print "check loop db.graphToMa" db.graphToMa(graphs[key]) graphs["isomass"] = db.getIsoMass(160) limit.doTanBetaPlotLight("limitsTanb_mA_light_" + scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mA(), scenario)
def main(): if len(sys.argv) == 1: usage() rootfile = "" jsonfile = "limits.json" root_re = re.compile("(?P<rootfile>(\S*\.root))") json_re = re.compile("(?P<jsonfile>(\S*\.json))") for argv in sys.argv: match = root_re.search(argv) if match: rootfile = match.group(0) match = json_re.search(argv) if match: jsonfile = match.group(0) # jsonfile = "limits_heavy2016.json" jsonfile = "limits2016/limitsForMSSMplots_ICHEP_v3_heavy.json" # limits = limit.BRLimits(limitsfile=jsonfile,configfile="configurationHeavy.json") limits = limit.BRLimits(limitsfile=jsonfile,configfile="limits2016/heavyHplus_configuration.json") # Enable OpenGL ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1) # Apply TDR style style = tdrstyle.TDRStyle() #if limit.forPaper: # histograms.cmsTextMode = histograms.CMSMode.PAPER #histograms.cmsTextMode = histograms.CMSMode.PAPER # tmp #histograms.cmsTextMode = histograms.CMSMode.UNPUBLISHED # tmp histograms.cmsTextMode = histograms.CMSMode.PRELIMINARY limit.forPaper = True # to get GeV without c^2 # Get BR limits masses = limits.mass brs = limits.observed print "Observed masses and sigma*BR's" for i in range(len(masses)): print " ",masses[i],brs[i] global db db = BRXSDB.BRXSDatabaseInterface(rootfile) db.BRvariable= "2*0.001*tHp_xsec*BR_Hp_taunu" # XSEC only for H-, multiply with 2 to get H+ and H- ; multiply by 0.001 to fb -> pb for i,m in enumerate(masses): db.addExperimentalBRLimit(m,brs[i]) graphs = {} obs = limits.observedGraph() # Remove blinded obs points for i in reversed(range(0,obs.GetN())): if obs.GetY()[i] < 0.00000001: print " REMOVING POINT",obs.GetY()[i]," corresponding mass=",obs.GetX()[i] obs.RemovePoint(i) print graphs["exp"] = limits.expectedGraph() graphs["exp1"] = limits.expectedBandGraph(sigma=1) graphs["exp2"] = limits.expectedBandGraph(sigma=2) if obs.GetN() > 0: graphs["obs"] = obs # Get theory uncertainties on observed # obs_th_plus = limit.getObservedPlus(obs,0.32) # obs_th_minus = limit.getObservedMinus(obs,0.32) # for gr in [obs_th_plus, obs_th_minus]: # gr.SetLineWidth(2) # gr.SetLineStyle(9) # graphs["obs_th_plus"] = obs_th_plus # graphs["obs_th_minus"] = obs_th_minus # Remove m=180,190 for gr in graphs.values(): # limit.cleanGraph(gr, 750) limit.cleanGraph(gr, 800) limit.cleanGraph(gr, 1000) limit.cleanGraph(gr, 2000) limit.cleanGraph(gr, 3000) print "Plotting graphs" for key in graphs.keys(): for i in range(graphs[key].GetN()): xs = graphs[key].GetX() ys = graphs[key].GetY() print " ",key,xs[i],ys[i] print # Interpret in MSSM xVariable = "mHp" selection = "mHp > 0 && mu==200" # selection = "mHp > 0 && mu==500" # scenario = "MSSM m_{h}^{max}" scenario = os.path.split(rootfile)[-1].replace(".root","") print scenario from JsonWriter import JsonWriter jsonWriter = JsonWriter() for key in graphs.keys(): print "Graph--------------------------------",key graphs[key] = db.graphToTanBeta(graphs[key],xVariable,selection,highTanbRegion=True) #if key == "obs": #obsplus = db.getTheorUncert(graphs[key],xVariable,selection,"+") #graphs["obs_th_plus"] = db.graphToTanBeta(obsplus,xVariable,selection) #obsminus = db.getTheorUncert(graphs[key],xVariable,selection,"-") #graphs["obs_th_minus"] = db.graphToTanBeta(obsminus,xVariable,selection) print key,"done" jsonWriter.addGraph(key,graphs[key]) # graphs["mintanb"] = db.minimumTanbGraph("mHp",selection) if scenario == "lowMH-LHCHXSWG": graphs["Allowed"] = db.mhLimit("mH","mHp",selection,"125.0+-3.0") else: graphs["Allowed"] = db.mhLimit("mh","mHp",selection+"&&mHp>175","125.0+-3.0") if scenario == "tauphobic-LHCHXSWG": # Fix a buggy second upper limit (the order of points is left to right, then right to left; remove further passes to fix the bug) decreasingStatus = False i = 0 while i < graphs["Allowed"].GetN(): removeStatus = False y = graphs["Allowed"].GetY()[i] if i > 0: if graphs["Allowed"].GetY()[i-1] - y < 0: decreasingStatus = True else: if decreasingStatus: graphs["Allowed"].RemovePoint(i) removeStatus = True if not removeStatus: i += 1 #for i in range(0, graphs["Allowed"].GetN()): #print graphs["Allowed"].GetX()[i], graphs["Allowed"].GetY()[i] # del graphs["isomass"] jsonWriter.addGraph("Allowed",graphs["Allowed"]) jsonWriter.addParameter("name","limitsTanb_heavy_"+scenario) jsonWriter.addParameter("scenario",scenario) jsonWriter.addParameter("luminosity",limits.getLuminosity()) jsonWriter.addParameter("finalStateText",limits.getFinalstateText()) jsonWriter.addParameter("mHplus",limit.mHplus()) jsonWriter.addParameter("selection",selection) jsonWriter.write("MSSMLimitHeavy_"+scenario+".json") limit.doTanBetaPlotHeavy("limitsTanb_heavy_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mHplus(), scenario) sys.exit() # mH+ -> mA print "Replotting the graphs for (mA,tanb)" for key in graphs.keys(): print key #db.PrintGraph(graphs[key]) #print "check loop db.graphToMa" db.graphToMa(graphs[key]) graphs["isomass"] = db.getIsoMass(200) # doPlot("limitsTanb_mA_heavy_"+scenario, graphs, limits, limit.mA(),scenario) limit.doTanBetaPlotHeavy("limitsTanb_mA_heavy_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mA(), scenario)
def main(): if len(sys.argv) == 1: usage() rootfile = "" jsonfile = "limits.json" root_re = re.compile("(?P<rootfile>(\S*\.root))") json_re = re.compile("(?P<jsonfile>(\S*\.json))") for argv in sys.argv: match = root_re.search(argv) if match: rootfile = match.group(0) match = json_re.search(argv) if match: jsonfile = match.group(0) jsonfile = "limits2016/limits_withLeptonic_180522.json" limits = limit.BRLimits(limitsfile=jsonfile,configfile="limits2016/mu_configuration.json") # Enable OpenGL ROOT.gEnv.SetValue("OpenGL.CanvasPreferGL", 1) # Apply TDR style style = tdrstyle.TDRStyle() if limit.forPaper: histograms.cmsTextMode = histograms.CMSMode.PAPER # Get BR limits masses = limits.mass brs = limits.observed print "Observed masses and BR's" for i in range(len(masses)): print " ",masses[i],brs[i] global db db = BRXSDB.BRXSDatabaseInterface(rootfile,BRvariable= "0.001*831.76*2*tHp_xsec*BR_Hp_taunu") for i,m in enumerate(masses): db.addExperimentalBRLimit(m,brs[i]) graphs = {} obs = limits.observedGraph() # Remove blinded obs points for i in reversed(range(0,obs.GetN())): if obs.GetY()[i] < 0.00000001: print " REMOVING POINT",obs.GetY()[i]," corresponding mass=",obs.GetX()[i] obs.RemovePoint(i) print # graphs["exp"] = limits.expectedGraph() #x = array.array('d',masses) #y = array.array('d',[0.02]*len(masses)) #graphs["exp"] = ROOT.TGraph(len(masses),x,y) # graphs["exp1"] = limits.expectedBandGraph(sigma=1) # graphs["exp2"] = limits.expectedBandGraph(sigma=2) if obs.GetN() > 0: graphs["obs"] = obs # Remove m=80 for gr in graphs.values(): limit.cleanGraph(gr, 80) print "Plotting graphs" for key in graphs.keys(): for i in range(graphs[key].GetN()): xs = graphs[key].GetX() ys = graphs[key].GetY() print " ",key,xs[i],ys[i] print # Interpret in MSSM xVariable = "mu" scenario = os.path.split(rootfile)[-1].replace(".root","") if scenario == "lowMHaltv-LHCHXSWG": xVariable = "mHp" selection = "" from JsonWriter import JsonWriter # for i in range(len(masses)): # mass = masses[i] # brlimit = brs[i] # if mass < 90: # continue # if not mass == 160: # continue # selection = "mHp == %s"%mass #graphs["muexcluded"] = db.muLimit(mass,"mu",selection,brlimit) #db.PrintGraph(graphs["muexcluded"],"muexcluded") jsonWriter = JsonWriter() print "check keys",graphs.keys() for key in graphs.keys(): print "Graph--------------------------------",key #db.PrintGraph(graphs[key],"Before graphToTanBetaCombined") graphs[key] = db.graphToTanBetaMu(graphs[key],xVariable,selection,True) print key,"done" jsonWriter.addGraph(key,graphs[key]) #graphs["Allowed"] = db.mhLimit("mH","mu",selection,"125.0+-3.0") if xVariable == "mHp": graphs["Allowed"] = db.mHLimit_mHp(selection,"125.0+-3.0") else: graphs["Allowed"] = db.mHLimit_mu(selection,"125.0+-3.0") jsonWriter.addGraph("Allowed",graphs["Allowed"]) graphs["Inaccessible"] = db.inaccessible(xVariable,selection) jsonWriter.addGraph("Inaccessible",graphs["Inaccessible"]) jsonWriter.addParameter("name","limitsTanb_light_"+scenario) jsonWriter.addParameter("scenario",scenario) jsonWriter.addParameter("luminosity",limits.getLuminosity()) jsonWriter.addParameter("finalStateText",limits.getFinalstateText()) xvar = limit.mu() if xVariable == "mHp": xvar = limit.mHplus() jsonWriter.addParameter("mHplus",xvar) jsonWriter.addParameter("selection",selection) jsonWriter.addParameter("regime","mu") jsonWriter.write("MSSMLimitMu_"+scenario+".json") #limit.doTanBetaPlotLight("limitsTanb_light_"+scenario, graphs, limits.getLuminosity(), limits.getFinalstateText(), limit.mHplus(), scenario) # if int(mass) in [155, 160]: # graphs["obs_th_plus"] = db.muLimit(mass,"mu",selection,brlimit*(1+0.29)) # graphs["obs_th_minus"] = db.muLimit(mass,"mu",selection,brlimit*(1-0.29)) # # for gr in [graphs["obs_th_plus"], graphs["obs_th_minus"]]: # gr.SetLineWidth(2) # gr.SetLineStyle(9) # # graphs["observed"] = graphs["muexcluded"].Clone() # graphs["observed"].SetLineWidth(2) # graphs["observed"].SetLineStyle(ROOT.kSolid) # graphs["observed"].SetLineColor(ROOT.kBlack) # # # Remove obs point # for name in ["observed", "obs_th_plus", "obs_th_minus"]: # gr = graphs[name] # print "Graph", name # for i in reversed(range(0,gr.GetN())): # if gr.GetY()[i] < 2 or gr.GetY()[i] > 65: # print " REMOVING POINT",gr.GetY()[i]," corresponding mass=",gr.GetX()[i] # gr.RemovePoint(i) # # graphs["Allowed"] = db.getHardCoded_mH_limitForMu(mass,0) # graphs["Allowed2"] = db.getHardCoded_mH_limitForMu(mass,1) # # doPlot(("limitsMu_light_mHp%s_"+scenario)%(int(mass)), graphs, limits, "#mu (GeV)",scenario, int(mass)) sys.exit()