def getFromPF(dataset, pathAll, pathPassed, bin): hall = histograms.dist2pass(dataset.getDatasetRootHisto(pathAll).getHistogram(), greaterThan=True) hpassed= histograms.dist2pass(dataset.getDatasetRootHisto(pathPassed).getHistogram(), greaterThan=True) all = hall.GetBinContent(bin) passed = hpassed.GetBinContent(bin) cutvalue = hpassed.GetBinCenter(bin) if abs(cutvalue-hall.GetBinCenter(bin)) > 1e-4: raise Exception("Internal error, cutvalue %f, hall.GetBinCenter(bin) %f" % (cutvalue, hall.GetBinCenter(bin))) return (all, passed, cutvalue)
def getFromPF(dataset, pathAll, pathPassed, bin): hall = histograms.dist2pass( dataset.getDatasetRootHisto(pathAll).getHistogram(), greaterThan=True) hpassed = histograms.dist2pass( dataset.getDatasetRootHisto(pathPassed).getHistogram(), greaterThan=True) all = hall.GetBinContent(bin) passed = hpassed.GetBinContent(bin) cutvalue = hpassed.GetBinCenter(bin) if abs(cutvalue - hall.GetBinCenter(bin)) > 1e-4: raise Exception( "Internal error, cutvalue %f, hall.GetBinCenter(bin) %f" % (cutvalue, hall.GetBinCenter(bin))) return (all, passed, cutvalue)
def getFromCalo(dataset, path, bin): hpass = histograms.dist2pass( dataset.getDatasetRootHisto(path).getHistogram(), greaterThan=True) all = hpass.GetBinContent(1) passed = hpass.GetBinContent(bin) cutvalue = hpass.GetBinCenter(bin) return (all, passed, cutvalue)
def __init__(self, datasets, treeDraw, doPassed=True, **kwargs): argsPlot = {} argsPass = {} for key in kwargs.keys(): if "normalize" in key: argsPlot[key] = kwargs[key] elif "Than" in key: argsPass[key] = kwargs[key] else: raise Exception("Unsupported keyword argument %s" % key) self.doPassed = doPassed self.dist = plots.MCPlot(datasets, treeDraw, **argsPlot) self.passed = plots.PlotBase() self.sOverB = plots.PlotBase() self.significance = plots.PlotBase() signalsToRemove = filter( lambda name: plots.isSignal(name) and not "_M120" in name, datasets.getMCDatasetNames()) # Create the passed (cumulative) histogram sumBkgDist = None sumBkgPassed = None for histo in self.dist.histoMgr.getHistos(): dist = histo.getRootHisto() passed = histograms.dist2pass(dist, **argsPass) self.passed.histoMgr.appendHisto( histograms.HistoWithDataset(histo.getDataset(), passed, histo.getName())) if not plots.isSignal(histo.getDataset().getName()): if sumBkgDist == None: sumBkgDist = dist.Clone("bkgsum") sumBkgPassed = passed.Clone("bkgsum") else: sumBkgDist.Add(dist) sumBkgPassed.Add(passed) sumBkg = sumBkgDist histos = self.dist.histoMgr.getHistos() if doPassed: histos = self.passed.histoMgr.getHistos() symBkg = symBkgPassed # Create S/B histogram for histo in histos: if plots.isSignal(histo.getDataset().getName()): signal = histo.getRootHisto() sOverB = signal.Clone("sOverB_" + histo.getName()) sOverB.Divide(sumBkg) self.sOverB.histoMgr.appendHisto( histograms.HistoWithDataset(histo.getDataset(), sOverB, histo.getName())) signif = signal.Clone("significance_" + histo.getName()) for bin in xrange(0, signif.GetNbinsX() + 2): signif.SetBinContent( bin, significancePoisson(signif.GetBinContent(bin), sumBkg.GetBinContent(bin))) self.significance.histoMgr.appendHisto( histograms.HistoWithDataset(histo.getDataset(), signif, histo.getName())) # Format passed and dist self.passed.setDefaultStyles() mcNames = filter(lambda name: not plots.isSignal(name), datasets.getMCDatasetNames()) self.passed.histoMgr.forEachHisto( plots.UpdatePlotStyleFill(plots._plotStyles, mcNames)) self.passed.histoMgr.stackHistograms("StackedMC", mcNames) for s in signalsToRemove: self.dist.histoMgr.removeHisto(s) self.passed.histoMgr.removeHisto(s) # Format S/B for plot in [self.sOverB, self.significance]: plot.setDefaultStyles() plot.histoMgr.forEachHisto( lambda h: h.getRootHisto().SetLineStyle(ROOT.kSolid)) plot.histoMgr.forEachHisto( lambda h: h.getRootHisto().SetLineWidth(2))
def __init__(self, datasets, treeDraw, doPassed=True, **kwargs): argsPlot = {} argsPass = {} for key in kwargs.keys(): if "normalize" in key: argsPlot[key] = kwargs[key] elif "Than" in key: argsPass[key] = kwargs[key] else: raise Exception("Unsupported keyword argument %s" % key) self.doPassed = doPassed self.dist = plots.MCPlot(datasets, treeDraw, **argsPlot) self.passed = plots.PlotBase() self.sOverB = plots.PlotBase() self.significance = plots.PlotBase() signalsToRemove = filter(lambda name: plots.isSignal(name) and not "_M120" in name, datasets.getMCDatasetNames()) # Create the passed (cumulative) histogram sumBkgDist = None sumBkgPassed = None for histo in self.dist.histoMgr.getHistos(): dist = histo.getRootHisto() passed = histograms.dist2pass(dist, **argsPass) self.passed.histoMgr.appendHisto(histograms.HistoWithDataset(histo.getDataset(), passed, histo.getName())) if not plots.isSignal(histo.getDataset().getName()): if sumBkgDist == None: sumBkgDist = dist.Clone("bkgsum") sumBkgPassed = passed.Clone("bkgsum") else: sumBkgDist.Add(dist) sumBkgPassed.Add(passed) sumBkg = sumBkgDist histos = self.dist.histoMgr.getHistos() if doPassed: histos = self.passed.histoMgr.getHistos() symBkg = symBkgPassed # Create S/B histogram for histo in histos: if plots.isSignal(histo.getDataset().getName()): signal = histo.getRootHisto() sOverB = signal.Clone("sOverB_"+histo.getName()) sOverB.Divide(sumBkg) self.sOverB.histoMgr.appendHisto(histograms.HistoWithDataset(histo.getDataset(), sOverB, histo.getName())) signif = signal.Clone("significance_"+histo.getName()) for bin in xrange(0, signif.GetNbinsX()+2): signif.SetBinContent(bin, significancePoisson(signif.GetBinContent(bin), sumBkg.GetBinContent(bin))) self.significance.histoMgr.appendHisto(histograms.HistoWithDataset(histo.getDataset(), signif, histo.getName())) # Format passed and dist self.passed.setDefaultStyles() mcNames = filter(lambda name: not plots.isSignal(name), datasets.getMCDatasetNames()) self.passed.histoMgr.forEachHisto(plots.UpdatePlotStyleFill(plots._plotStyles, mcNames)) self.passed.histoMgr.stackHistograms("StackedMC", mcNames) for s in signalsToRemove: self.dist.histoMgr.removeHisto(s) self.passed.histoMgr.removeHisto(s) # Format S/B for plot in [self.sOverB, self.significance]: plot.setDefaultStyles() plot.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetLineStyle(ROOT.kSolid)) plot.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetLineWidth(2))
def getFromCalo(dataset, path, bin): hpass = histograms.dist2pass(dataset.getDatasetRootHisto(path).getHistogram(), greaterThan=True) all = hpass.GetBinContent(1) passed = hpass.GetBinContent(bin) cutvalue = hpass.GetBinCenter(bin) return (all, passed, cutvalue)