def writeRootHisto(self, directory, dstName, srcEmbName, isCounter): if not self.datasetsEmb.hasHistogram(self.datasetName, srcEmbName): return # Get properly normalized embedded data (embDataHisto, tmp) = self.datasetsEmb.getHistogram(self.datasetName, srcEmbName) histo = None if isCounter: embDataCounter = counter.HistoCounter("EmbData", embDataHisto) table = counter.CounterTable() table.appendColumn(embDataCounter) column = table.getColumn(name="EmbData") histo = dataset._counterToHisto(dstName, column.getPairList()) else: histo = embDataHisto histo.SetName(dstName) histo.SetDirectory(directory) histo.Write() histo.Delete() # could this help??? print "%s/%s" % (directory.GetPath(), dstName)
def writeRootHisto(self, directory, dstName, srcEmbName, srcSigName, isCounter): if not self.datasetsEmb.hasHistogram( self.datasetName, srcEmbName) or not self.datasetSig.hasRootHisto(srcSigName): return histo = None # Get properly normalized embedded and normal MC (embMcHisto, tmp) = self.datasetsEmb.getHistogram(self.datasetName, srcEmbName) sigMcHisto = self.datasetSig.getDatasetRootHisto( srcSigName).getHistogram() # ROOT.TH1 #print embMcHisto, sigMcHisto if self.normalOnly: histo = sigMcHisto elif self.embeddedOnly: histo = embMcHisto else: if isCounter: embMcCounter = counter.HistoCounter("EmbMc", embMcHisto) sigMcCounter = counter.HistoCounter("SigMc", sigMcHisto) table = counter.CounterTable() table.appendColumn(embMcCounter) table.appendColumn(sigMcCounter) table.removeNonFullRows() if table.getNrows() == 0: return embMcColumn = table.getColumn(name="EmbMc") sigMcColumn = table.getColumn(name="SigMc") residual = counter.subtractColumn("Correction", sigMcColumn, embMcColumn) histo = dataset._counterToHisto(dstName, residual.getPairList()) else: # Residual MC: normal-embedded sigMcHisto.Add(embMcHisto, -1) histo = sigMcHisto histo.SetName(dstName) histo.SetDirectory(directory) histo.Write() histo.Delete() # could this help??? print "%s/%s" % (directory.GetPath(), dstName)
def writeRootHisto(self, directory, dstName, srcEmbName, srcSigName, isCounter): if not self.datasetsEmb.hasHistogram(self.datasetName, srcEmbName) or not self.datasetSig.hasRootHisto(srcSigName): return histo = None # Get properly normalized embedded and normal MC (embMcHisto, tmp) = self.datasetsEmb.getHistogram(self.datasetName, srcEmbName) sigMcHisto = self.datasetSig.getDatasetRootHisto(srcSigName).getHistogram() # ROOT.TH1 #print embMcHisto, sigMcHisto if self.normalOnly: histo = sigMcHisto elif self.embeddedOnly: histo = embMcHisto else: if isCounter: embMcCounter = counter.HistoCounter("EmbMc", embMcHisto) sigMcCounter = counter.HistoCounter("SigMc", sigMcHisto) table = counter.CounterTable() table.appendColumn(embMcCounter) table.appendColumn(sigMcCounter) table.removeNonFullRows() if table.getNrows() == 0: return embMcColumn = table.getColumn(name="EmbMc") sigMcColumn = table.getColumn(name="SigMc") residual = counter.subtractColumn("Correction", sigMcColumn, embMcColumn) histo = dataset._counterToHisto(dstName, residual.getPairList()) else: # Residual MC: normal-embedded sigMcHisto.Add(embMcHisto, -1) histo = sigMcHisto histo.SetName(dstName) histo.SetDirectory(directory) histo.Write() histo.Delete() # could this help??? print "%s/%s" % (directory.GetPath(), dstName)
def writeRootHisto(self, directory, dstName, srcEmbName, isCounter): if not self.datasetsEmb.hasHistogram(self.datasetName, srcEmbName): return # Get properly normalized embedded data (embDataHisto, tmp) = self.datasetsEmb.getHistogram(self.datasetName, srcEmbName) histo = None if isCounter: embDataCounter = counter.HistoCounter("EmbData", embDataHisto) table = counter.CounterTable() table.appendColumn(embDataCounter) column = table.getColumn(name="EmbData") histo = dataset._counterToHisto(dstName, column.getPairList()) else: histo = embDataHisto histo.SetName(dstName) histo.SetDirectory(directory) histo.Write() histo.Delete() # could this help??? print "%s/%s" % (directory.GetPath(), dstName)
def processDirectory(dset, srcDirName, dstDir, scaleBy, dsetSubtractFrom): # Get directories, recurse to them dirs = dset.getDirectoryContent(srcDirName, lambda o: isinstance(o, ROOT.TDirectory)) dirs = filter(lambda n: n != "configInfo", dirs) for d in dirs: newDir = dstDir.mkdir(d) processDirectory(dset, os.path.join(srcDirName, d), newDir, scaleBy, dsetSubtractFrom) # Then process histograms histos = dset.getDirectoryContent(srcDirName, lambda o: isinstance(o, ROOT.TH1)) dstDir.cd() shouldScale = True if srcDirName == "counters": # Don't touch unweighted counters shouldScale = False isCounter = srcDirName in ["counters", "counters/weighted"] for hname in histos: # drh = dset.getDatasetRootHisto(os.path.join(srcDirName, hname)) # hnew = drh.getHistogram() # TH1 hnew = dset.getAverageHistogram( os.path.join(srcDirName, hname), normalizeMCByCrossSection=(dsetSubtractFrom is not None)) hnew.SetName(hname) if shouldScale and hname not in "SplittedBinInfo": tauEmbedding.scaleTauBRNormalization(hnew) if scaleBy is not None: hnew.Scale(scaleBy) if dsetSubtractFrom is not None: drh = dsetSubtractFrom.getDatasetRootHisto( os.path.join(srcDirName, hname)) if dsetSubtractFrom.isMC(): drh.normalizeByCrossSection() hsub = drh.getHistogram() if not isCounter: # hnew = hsub-hnew hnew.Scale(-1) hnew.Add(hsub) else: cnew = counter.HistoCounter("Emb", hnew) csub = counter.HistoCounter("Norm", hsub) table = counter.CounterTable() table.appendColumn(cnew) table.appendColumn(csub) cres = counter.subtractColumn("Result", table.getColumn(name="Norm"), table.getColumn(name="Emb")) hnew2 = dataset._counterToHisto(hnew.GetName(), cres.getPairList()) hnew2.SetTitle(hnew.GetTitle()) hnew = hnew2 if srcDirName == "counters" and hname == "counter" and hnew.GetBinContent( 1) < 0: hnew.SetBinContent(1, 0) hnew.SetDirectory(dstDir) # # set the first count in main counters to 0 if it is negative, # # this is to circumvent certain assumptions made elsewhere in # # the code # if hname == "counter" and (srcDirName == "counters" or srcDirName == "counters/weighted") and hnew.GetBinContent(1) < 0: # hnew.SetBinContent(1, 0) # hnew.SetBinError(1, 0) hnew.Write() # ROOT.gDirectory.Delete(hname) hnew.Delete()
def processDirectory(dset, srcDirName, dstDir, scaleBy, dsetSubtractFrom): # Get directories, recurse to them dirs = dset.getDirectoryContent(srcDirName, lambda o: isinstance(o, ROOT.TDirectory)) dirs = filter(lambda n: n != "configInfo", dirs) for d in dirs: newDir = dstDir.mkdir(d) processDirectory(dset, os.path.join(srcDirName, d), newDir, scaleBy, dsetSubtractFrom) # Then process histograms histos = dset.getDirectoryContent(srcDirName, lambda o: isinstance(o, ROOT.TH1)) dstDir.cd() shouldScale = True if srcDirName == "counters": # Don't touch unweighted counters shouldScale = False isCounter = srcDirName in ["counters", "counters/weighted"] for hname in histos: # drh = dset.getDatasetRootHisto(os.path.join(srcDirName, hname)) # hnew = drh.getHistogram() # TH1 hnew = dset.getAverageHistogram(os.path.join(srcDirName, hname), normalizeMCByCrossSection = (dsetSubtractFrom is not None)) hnew.SetName(hname) if shouldScale and hname not in "SplittedBinInfo": tauEmbedding.scaleTauBRNormalization(hnew) if scaleBy is not None: hnew.Scale(scaleBy) if dsetSubtractFrom is not None: drh = dsetSubtractFrom.getDatasetRootHisto(os.path.join(srcDirName, hname)) if dsetSubtractFrom.isMC(): drh.normalizeByCrossSection() hsub = drh.getHistogram() if not isCounter: # hnew = hsub-hnew hnew.Scale(-1) hnew.Add(hsub) else: cnew = counter.HistoCounter("Emb", hnew) csub = counter.HistoCounter("Norm", hsub) table = counter.CounterTable() table.appendColumn(cnew) table.appendColumn(csub) cres = counter.subtractColumn("Result", table.getColumn(name="Norm"), table.getColumn(name="Emb")) hnew2 = dataset._counterToHisto(hnew.GetName(), cres.getPairList()) hnew2.SetTitle(hnew.GetTitle()) hnew = hnew2 if srcDirName == "counters" and hname == "counter" and hnew.GetBinContent(1) < 0: hnew.SetBinContent(1, 0) hnew.SetDirectory(dstDir) # # set the first count in main counters to 0 if it is negative, # # this is to circumvent certain assumptions made elsewhere in # # the code # if hname == "counter" and (srcDirName == "counters" or srcDirName == "counters/weighted") and hnew.GetBinContent(1) < 0: # hnew.SetBinContent(1, 0) # hnew.SetBinError(1, 0) hnew.Write() # ROOT.gDirectory.Delete(hname) hnew.Delete()