def createStyles(): st = [ styles.StyleCompound(styles=[s, styles.StyleLine(lineWidth=5)]) for s in styles.getStyles() ] st[0] = styles.StyleCompound(styles=[st[0], styles.StyleLine(lineStyle=2)]) return st
def doPlotsWTauMuRatio(dsetMgr, selectionName, ratios, unweighted, fitFunction): prefix = era + "_" + selectionName + "_fitFunction%d" % fitFunction + unweighted + "_" st = [s.clone() for s in styles.getStyles()] st[0].marker = 33 st[1].marker = 26 st[2].marker = 32 st = [ styles.StyleCompound(styles=[s, styles.StyleMarker(markerSize=1.5)]) for s in st ] # Do clone to get rid of statistics box p = plots.PlotBase([x[0].Clone() for x in ratios]) p.setEnergy(dsetMgr.getEnergies()) p.histoMgr.setHistoDrawStyleAll("P") p.histoMgr.setHistoLegendStyleAll("P") p.histoMgr.forEachHisto(styles.Generator(st)) for i, x in enumerate(ratios): fitLine = x[1] st[i].apply(fitLine) p.appendPlotObject(fitLine) def customize(plot): xmin = plot.frame.GetXaxis().GetXmin() xmax = plot.frame.GetXaxis().GetXmax() val = 1 l = ROOT.TLine(xmin, val, xmax, val) l.SetLineWidth(2) l.SetLineColor(ROOT.kRed) l.SetLineStyle(2) plot.prependPlotObject(l) val = 1 - 0.038479 l = ROOT.TLine(xmin, val, xmax, val) l.SetLineWidth(2) l.SetLineColor(ROOT.kBlue) l.SetLineStyle(4) plot.prependPlotObject(l) plot.appendPlotObject( histograms.PlotText(0.18, 0.57, "0.038", size=18, color=ROOT.kBlue)) plots.drawPlot(p, prefix + "WMuFraction", "Muon p_{T} (GeV/c)", ylabel="W#rightarrow#mu fraction", opts={ "ymin": 0.9, "ymax": 1.02 }, moveLegend={ "dh": -0.15, "dx": -0.5 }, customizeBeforeDraw=customize)
def MetComparison(datasets): mt = plots.PlotBase(getHistos(datasets,"MetNoJetInHole", "MetJetInHole")) # mt.histoMgr.normalizeMCToLuminosity(datasets.getDataset("Data").getLuminosity()) mt._setLegendStyles() st1 = styles.StyleCompound([styles.styles[2]]) st2 = styles.StyleCompound([styles.styles[1]]) st1.append(styles.StyleLine(lineWidth=3)) st2.append(styles.StyleLine(lineStyle=2, lineWidth=3)) mt.histoMgr.forHisto("MetNoJetInHole", st1) mt.histoMgr.forHisto("MetJetInHole", st2) mt.histoMgr.setHistoLegendLabelMany({ "MetNoJetInHole": "Jets outside dead cells", "MetJetInHole": "Jets within dead cells" }) # mt.histoMgr.setHistoDrawStyleAll("P") mt.appendPlotObject(histograms.PlotText(300, 300, "p_{T}^{jet} > 50 GeV/c", size=20)) xlabel = "PF E_{T}^{miss} (GeV)" ylabel = "Events / %.2f" plots.drawPlot(mt, "MetComparison", xlabel=xlabel, ylabel=ylabel, rebinX=2, log=True, createLegend={"x1": 0.6, "y1": 0.75, "x2": 0.8, "y2": 0.9}, ratio=False, opts2={"ymin": 0.5, "ymax": 1.5})
def dashed(style): return styles.StyleCompound([style, styles.StyleLine(lineStyle=3)])
import HiggsAnalysis.HeavyChHiggsToTauNu.tools.dataset as dataset import HiggsAnalysis.HeavyChHiggsToTauNu.tools.histograms as histograms import HiggsAnalysis.HeavyChHiggsToTauNu.tools.plots as plots import HiggsAnalysis.HeavyChHiggsToTauNu.tools.counter as counter import HiggsAnalysis.HeavyChHiggsToTauNu.tools.tdrstyle as tdrstyle import HiggsAnalysis.HeavyChHiggsToTauNu.tools.styles as styles from HiggsAnalysis.HeavyChHiggsToTauNu.tools.cutstring import * # And, Not, Or import HiggsAnalysis.HeavyChHiggsToTauNu.tools.crosssection as xsect import HiggsAnalysis.HeavyChHiggsToTauNu.tools.tauEmbedding as tauEmbedding analysisEmb = "signalAnalysisCaloMet60TEff" analysisSig = "signalAnalysisGenuineTau" # require that the selected tau is genuine, valid comparison after njets plotStyles = [ styles.StyleCompound([s, styles.StyleLine(lineWidth=4)]) for s in styles.styles[0:2] ] plotStyles[0] = styles.StyleCompound( [plotStyles[0], styles.StyleMarker(markerStyle=21, markerSize=1.2)]) #taujet = "#tau jet" #taujetH = "#tau-jet" taujet = "#tau_{h}" taujetH = "#tau_{h}" def main(): # Adjust paths such that this script can be run inside the first embedding trial directory dirEmbs = ["."] + [os.path.join("..", d) for d in tauEmbedding.dirEmbs[1:]]
return self._cache[dsetName].histogram(name) systematicsSigMC = SystematicsSigMC() systematicsEmbData = dataset.Systematics(shapes=[ "SystVarMuonIdDataEff", "SystVarMuonTrgDataEff", "SystVarWTauMu", "SystVarEmbMTWeight", ], additionalNormalizations = { "CaloMETApproximation": 0.12, "QCDContamination": 0.02, }) plotStyles = styles.styles[0:2] plotStyles[0] = styles.StyleCompound([plotStyles[0], styles.StyleMarker(markerStyle=21, markerSize=1.2)]) def main(): parser = OptionParser(usage="Usage: %prog [options]") parser.add_option("--dirSig", dest="dirSig", default=None, help="Path to signalAnalysisGenTau multicrab directory") (opts, args) = parser.parse_args() if opts.dirSig is None: parser.error("--dirSig missing") dirEmb = "." dirSig = opts.dirSig # Apply TDR style style = tdrstyle.TDRStyle()
def main(): parser = OptionParser(usage="Usage: %prog [options]") parser.add_option("--dirSig", dest="dirSig", default=None, help="Path to signalAnalysisGenTau multicrab directory") parser.add_option("--nortau", dest="nortau", default=False, action="store_true", help="Is Rtau cut disabled?") parser.add_option("--notrigger", dest="notrigger", default=False, action="store_true", help="Is tau+MET trigger disabled?") parser.add_option("--dofit", dest="dofit", default=False, action="store_true", help="Do the fit on mT slope on ttbar?") (opts, args) = parser.parse_args() if opts.dirSig is None: parser.error("--dirSig missing") dirEmb = "." dirSig = opts.dirSig global analysisSig, systematicsSigMC if opts.notrigger: analysisSig = analysisSig.replace("Triggered", "") systematicsSigMC = dataset.Systematics() # Apply TDR style style = tdrstyle.TDRStyle() styles.styles[1] = styles.StyleCompound( [styles.styles[1], styles.StyleMarker(markerStyle=25)]) histograms.cmsTextMode = histograms.CMSMode.SIMULATION_PRELIMINARY # histograms.cmsTextMode = histograms.CMSMode.SIMULATION # histograms.cmsTextMode = histograms.CMSMode.SIMULATION_UNPUBLISHED # histograms.cmsTextMode = histograms.CMSMode.UNPUBLISHED #histograms.createLegend.setDefaults(y1=0.93, y2=0.75, x1=0.52, x2=0.93) histograms.createLegend.setDefaults(textSize=0.04) histograms.createLegend.moveDefaults(dx=-0.25, dh=-0.2, dy=-0.12) histograms.createLegendRatio.setDefaults(ncolumns=2, textSize=0.08, columnSeparation=0.6) histograms.createLegendRatio.moveDefaults(dx=-0.48, dh=-0.1, dw=0.25) if opts.dofit: histograms.uncertaintyMode.set(histograms.uncertaintyMode.StatOnly) histograms.createLegendRatio.moveDefaults(dw=-0.25) plots._legendLabels["BackgroundStatError"] = "Emb. stat. unc." plots._legendLabels[ "BackgroundStatSystError"] = "Emb. stat.#oplussyst. unc." else: histograms.uncertaintyMode.set(histograms.uncertaintyMode.StatAndSyst) # plots._legendLabels["BackgroundStatError"] = "Norm. stat. unc." # plots._legendLabels["BackgroundStatSystError"] = "Norm. stat.#oplussyst. unc." plots._legendLabels["BackgroundStatError"] = "Non-emb. stat. unc." plots._legendLabels[ "BackgroundStatSystError"] = "Non-emb. stat.#oplussyst. unc." plots._legendLabels["Data"] = "Embedded data" plots._legendLabels["EWKMC"] = "EWK+t#bar{t}" # plots._legendLabels["EWKMC"] = "Non-emb. EWK+t#bar{t} with ^{}#tau_{h}" postfix = "" if opts.dofit: postfix = "_fit" for optMode in [ # "OptQCDTailKillerNoCuts", "OptQCDTailKillerLoosePlus", # "OptQCDTailKillerMediumPlus", # "OptQCDTailKillerTightPlus", # None ]: datasetsEmb = dataset.getDatasetsFromMulticrabCfg( directory=dirEmb, dataEra=dataEra, analysisName=analysisEmb, optimizationMode=optMode) datasetsSig = dataset.getDatasetsFromMulticrabCfg( directory=dirSig, dataEra=dataEra, analysisName=analysisSig, optimizationMode=optMode) doDataset(datasetsEmb, datasetsSig, optMode + postfix, opts) datasetsEmb.close() datasetsSig.close() tauEmbedding.writeToFile( optMode + postfix, "input.txt", "Embedded: %s\nSignal analysis (GenTau): %s\n" % (os.getcwd(), dirSig))
def doPlotsWTauMuRatioUncertaintyEstimate(dsetMgr, ratios, analysisName): prefix = era + "_" st = [s.clone() for s in styles.getStyles()] st[0].marker = 33 st = [ styles.StyleCompound(styles=[s, styles.StyleMarker(markerSize=1.5)]) for s in st ] # Nominal p = plots.PlotBase([ratios[analysisName][0].Clone()]) p.setEnergy(dsetMgr.getEnergies()) p.histoMgr.setHistoDrawStyleAll("P") p.histoMgr.setHistoLegendStyleAll("P") p.histoMgr.forEachHisto(styles.Generator(st)) fitLine = ratios[analysisName][1] st[0].apply(fitLine) p.appendPlotObject(fitLine) # Stat. unc. from parameters pars = [fitLine.GetParameter(i) for i in xrange(0, fitLine.GetNpar())] parErrors = [fitLine.GetParError(i) for i in xrange(0, fitLine.GetNpar())] def evalPar(x, i, shift): pars_ = pars[:] pars_[i] += shift return fitLine.EvalPar(x, array.array("d", pars_)) # Fit function fits = [ ratios[analysisName + "SystFunc0"][1], ratios[analysisName + "SystFunc1"][1] ] def maxDiff(x, tf1s, nominal): return max([abs(tf1.Eval(x[0]) - nominal) for tf1 in tf1s]) # Sample samples = [ ratios[analysisName + "SystWJets"][1], ratios[analysisName + "SystSingleTop"][1] ] # Weight systematic variations keys = filter(lambda n: "SystVar" in n, ratios.keys()) weightSources = {} for key in keys: src = key[key.find("SystVar") + 7:].replace("Plus", "").replace("Minus", "") # if src != "TopPtWeight": # continue # if src != "PUWeight": # continue # print src if not src in weightSources: weightSources[src] = [ratios[key][1]] else: weightSources[src].append(ratios[key][1]) def comb(plus, x, p): nominal = fitLine.Eval(x[0]) diff = 0 # stat unc uncStat = 0.0 for i, parErr in enumerate(parErrors): diffI = max(abs(evalPar(x, i, parErr) - nominal), abs(evalPar(x, i, -parErr)) - nominal) uncStat += diffI**2 diff += uncStat # Fit function diffFit = maxDiff(x, fits, nominal) diff += diffFit**2 # Sample diffSample = maxDiff(x, samples, nominal) diff += diffSample**2 # Weights for src, tf1s in weightSources.iteritems(): diffWeight = maxDiff(x, tf1s, nominal) diff += diffWeight**2 diff = math.sqrt(diff) if plus: ret = nominal + diff else: ret = nominal - diff if ret > 1: ret = 1.0 if ret < 0: ret = 0.0 # if ret > 0: # print x[0], (ret-nominal)/ret return ret p.appendPlotObject( ROOT.TF1("combPlus", lambda x, p: comb(True, x, p), fitLine.GetXmin(), fitLine.GetXmax(), fitLine.GetNpar())) p.appendPlotObject( ROOT.TF1("combMinus", lambda x, p: comb(False, x, p), fitLine.GetXmin(), fitLine.GetXmax(), fitLine.GetNpar())) # Simple relative uncertainty def rel(x): return 0.012 def relUnc(plus, x, p): nominal = fitLine.Eval(x[0]) if plus: f = 1 + rel(x[0]) else: f = 1 - rel(x[0]) return nominal * f relPlus = ROOT.TF1("relPlus", lambda x, p: relUnc(True, x, p), fitLine.GetXmin(), fitLine.GetXmax(), fitLine.GetNpar()) relMinus = ROOT.TF1("relMinus", lambda x, p: relUnc(False, x, p), fitLine.GetXmin(), fitLine.GetXmax(), fitLine.GetNpar()) relPlus.SetLineColor(ROOT.kGreen) relMinus.SetLineColor(ROOT.kGreen) p.appendPlotObject(relPlus) p.appendPlotObject(relMinus) def customize(plot): xmin = plot.frame.GetXaxis().GetXmin() xmax = plot.frame.GetXaxis().GetXmax() ymin = plot.frame.GetYaxis().GetXmin() ymax = plot.frame.GetYaxis().GetXmax() val = 1 l = ROOT.TLine(xmin, val, xmax, val) l.SetLineWidth(2) l.SetLineColor(ROOT.kRed) l.SetLineStyle(2) plot.prependPlotObject(l) l = ROOT.TLine(41, ymin, 41, ymax) l.SetLineWidth(2) l.SetLineColor(ROOT.kRed) l.SetLineStyle(2) plot.prependPlotObject(l) plots.drawPlot( p, prefix + "WMuFractionUncertainty", "Muon p_{T} (GeV/c)", ylabel="W#rightarrow#mu fraction", opts={ "ymin": 0.9, "ymax": 1.02 }, createLegend=None, #moveLegend={"dh": -0.15, "dx": -0.5}, customizeBeforeDraw=customize)