def scaleHistsForProcess(self, group, processName, chan, expandedTheory, append=""): weightHist = group.FindObject(self.weightHistName(chan, processName, append)) if not weightHist: raise ValueError("Failed to find %s. Skipping" % self.weightHistName(chan, processName, append)) if 'scale' not in self.theoryVariations[processName]: return [] scaleVars = self.theoryVariations[processName]['scale'] scaleHists = HistTools.getScaleHists(weightHist, processName, self.rebin, entries=scaleVars['entries'], exclude=scaleVars['exclude'], central=scaleVars['central']) if not self.isUnrolledFit else \ HistTools.getTransformed3DScaleHists(weightHist, HistTools.makeUnrolledHist, [self.unrolledBinsX, self.unrolledBinsY], processName, entries=scaleVars['entries'], exclude=scaleVars['exclude']) if expandedTheory: name = processName if not self.correlateScaleUnc else "" expandedScaleHists = HistTools.getExpandedScaleHists(weightHist, name, self.rebin, entries=scaleVars['entries'], pairs=scaleVars['groups'], ) if not self.isUnrolledFit else \ HistTools.getTransformed3DExpandedScaleHists(weightHist, HistTools.makeUnrolledHist, [self.unrolledBinsX, self.unrolledBinsY], name, entries=scaleVars['entries'], pairs=scaleVars['groups'], ) scaleHists.extend(expandedScaleHists) return scaleHists
def loadHistsForProcess(self, processName, scaleNorm=1, expandedTheory=True): plotsToRead = self.listOfHistsByProcess(processName) group = HistTools.makeCompositeHists(self.inputFile, processName, {proc : self.crossSectionMap[proc] for proc in self.processes[processName]}, self.lumi, plotsToRead, rebin=self.rebin, overflow=False) fitVariable = self.getFitVariable(processName) #TODO:Make optional processedHists = [] for chan in self.channels: histName = "_".join([fitVariable, chan]) if chan != "all" else fitVariable hist = group.FindObject(histName) if not hist: raise RuntimeError("Failed to produce hist %s for process %s" % (histName, processName)) #TODO: Make optional if "data" not in processName.lower(): HistTools.removeZeros(hist) HistTools.addOverflow(hist) processedHists.append(histName) self.yields[chan].update({processName : round(hist.Integral(), 3) if hist.Integral() > 0 else 0.0001}) if chan == self.channels[0]: self.yields["all"][processName] = self.yields[chan][processName] else: self.yields["all"][processName] += self.yields[chan][processName] if processName in self.theoryVariations: weightHist = group.FindObject(self.weightHistName(chan, processName)) if not weightHist: logging.warning("Failed to find %s. Skipping" % self.weightHistName(chan, processName)) continue theoryVars = self.theoryVariations[processName] scaleHists = HistTools.getScaleHists(weightHist, processName, self.rebin, entries=theoryVars['scale']['entries'], central=(theoryVars['scale']['central'] if 'scale' in theoryVars else -1)) if expandedTheory: expandedScaleHists = HistTools.getExpandedScaleHists(weightHist, processName, self.rebin, entries=theoryVars['scale']['entries'], central=(theoryVars['scale']['central'] if 'scale' in theoryVars else -1), ) scaleHists.extend(expandedScaleHists) pdfHists = [] pdfVars = filter(lambda x: 'pdf' in x, theoryVars.keys()) for var in pdfVars: pdfVar = theoryVars[var] pdfType = "SymmMC" if "hessian" in pdfVar['combine']: pdfType = "Hessian" if "assym" not in pdfVar['combine'] else "AssymHessian" pdfFunction = "get%sPDFVariationHists" % pdfType pdfHists += getattr(HistTools, pdfFunction)(weightHist, pdfVar['entries'], processName, self.rebin, central=pdfVar['central'], pdfName=pdfVar['name']) if expandedTheory and "hessian" in pdfVar['combine']: allPdfHists = HistTools.getAllSymmetricHessianVariationHists(weightHist, pdfVar['entries'], processName, self.rebin, central=pdfVar['central']) pdfHists.extend(allPdfHists) cenHist, _ = HistTools.getLHEWeightHists(weightHist, pdfVar['entries'][:1], processName, "pdf", self.rebin) if len(cenHist) and cenHist[0]: pdfHists.append(cenHist[0].Clone()) group.extend(scaleHists+pdfHists) if chan == self.channels[0]: theoryVarLabels = [] for h in group: theoryVarLabels.extend(re.findall("_".join([self.fitVariable, "(.*)", chan]), h.GetName())) self.variations[processName].extend(set(theoryVarLabels)) #TODO: Make optional map(HistTools.addOverflow, filter(lambda x: (x.GetName() not in processedHists), group)) if "data" not in group.GetName().lower(): map(HistTools.removeZeros, filter(lambda x: (x.GetName() not in processedHists), group)) #TODO: You may want to combine channels before removing zeros self.combineChannels(group, processName) self.histData[processName] = group