def mergeFunc(self,products) : self.setupDicts() for eLumis in products["staticEpochLumis"] : for epoch in eLumis : for run in eLumis[epoch] : self.epochLumis[epoch][run] |= eLumis[epoch][run] if not self.epochLumis : return lumiDir = self.outputFileName if not os.path.exists(lumiDir) : utils.mkdir(lumiDir) lumis = utils.luminosity.recordedInvMicrobarnsShotgun( [utils.jsonFromRunDict(self.epochLumis[epoch]) for epoch in self.epochLumis ] , cores = 4, cacheDir = lumiDir) probs = [ [1./prescale if prescale else 0 for prescale in epoch] for epoch in self.epochLumis ] inclu = [ [utils.unionProbability(prob[:i+1]) for i in range(len(prob))] for prob in probs ] thresholds = sorted(set(self.thresholds)) inclusives = [ [max([0]+[p for p,t in zip(inc,self.thresholds) if t is thresh]) for thresh in thresholds] for inc in inclu ] weights = np.array(lumis).dot(inclusives) / sum(lumis) # write total lumi and weight by threshold lumiHist = r.TH1D('susyTreeLumi','luminosity from susyTree;;1/pb',1,0,1) lumiHist.SetBinContent(1,sum(lumis)) lumiHist.Write() weightHist = r.TH1D(self.name,";%s;%s"%(self.var,self.name), len(thresholds), np.array([0.]+thresholds+[max(thresholds)+10])) for i,w in enumerate(weights) : weightHist.SetBinContent(i+2, w) weightHist.SetBinContent(len(thresholds)+3, 1) weightHist.Write()
def mergeFunc(self, products): self.setup(None, None) for eLumis in products["staticEpochLumis"]: for epoch in eLumis: for run in eLumis[epoch]: self.epochLumis[epoch][run] |= eLumis[epoch][run] lumiProbs = [] with open(self.outputFileName, "w") as file: print >> file, self.triggers print >> file, "" for epoch in self.epochLumis: json = utils.jsonFromRunDict(self.epochLumis[epoch]) lumi = utils.luminosity.recordedInvMicrobarns(json) / 1e6 probs = [ (thresh, 1.0 / prescale) for thresh, prescale in zip(self.thresh, epoch)[: epoch.index(1.0) + 1] if prescale ] inclusive = [ ( probs[i][0], probs[i + 1][0] if (i < len(probs) - 1) else None, utils.unionProbability(zip(*probs[: i + 1])[1]), ) for i in range(len(probs)) ] lumiProbs.append((lumi, inclusive)) print >> file, epoch print >> file, json print >> file, lumi, " /pb" print >> file, [(thresh, "%.4f" % w) for thresh, nextThresh, w in inclusive] print >> file, "" print "Wrote prescale jsons by epoch : " + self.outputFileName lumiVal = sum(lumi for lumi, probs in lumiProbs) lumiHist = r.TH1D("susyTreeLumi", "luminosity from susyTree;;1/pb", 1, 0, 1) lumiHist.Fill(0.5, lumiVal) lumiHist.Write() ptMax = 10 + max(self.thresh) weight = r.TH1D("prescaleWeight", "prescaleWeight", ptMax, 0, ptMax) for lumi, probs in lumiProbs: epochWeight = lumi / lumiVal for thresh, nextThresh, prob in probs: for bin in range(thresh, nextThresh if nextThresh else ptMax): weight.Fill(bin, epochWeight * prob) weight.Write()
def mergeFunc(self, products): self.setup(None, None) for eLumis in products["staticEpochLumis"]: for epoch in eLumis: for run in eLumis[epoch]: self.epochLumis[epoch][run] |= eLumis[epoch][run] lumiProbs = [] with open(self.outputFileName, "w") as file: print >> file, self.triggers print >> file, "" for epoch in self.epochLumis: json = utils.jsonFromRunDict(self.epochLumis[epoch]) lumi = utils.luminosity.recordedInvMicrobarns(json) / 1e6 probs = [(thresh, 1. / prescale) for thresh, prescale in zip( self.thresh, epoch)[:epoch.index(1.0) + 1] if prescale] inclusive = [(probs[i][0], probs[i + 1][0] if (i < len(probs) - 1) else None, utils.unionProbability(zip(*probs[:i + 1])[1])) for i in range(len(probs))] lumiProbs.append((lumi, inclusive)) print >> file, epoch print >> file, json print >> file, lumi, " /pb" print >> file, [(thresh, "%.4f" % w) for thresh, nextThresh, w in inclusive] print >> file, "" print "Wrote prescale jsons by epoch : " + self.outputFileName lumiVal = sum(lumi for lumi, probs in lumiProbs) lumiHist = r.TH1D("susyTreeLumi", "luminosity from susyTree;;1/pb", 1, 0, 1) lumiHist.Fill(0.5, lumiVal) lumiHist.Write() ptMax = 10 + max(self.thresh) weight = r.TH1D("prescaleWeight", "prescaleWeight", ptMax, 0, ptMax) for lumi, probs in lumiProbs: epochWeight = lumi / lumiVal for thresh, nextThresh, prob in probs: for bin in range(thresh, nextThresh if nextThresh else ptMax): weight.Fill(bin, epochWeight * prob) weight.Write()
def mergeFunc(self, products): self.setupDicts() for eLumis in products["staticEpochLumis"]: for epoch in eLumis: for run in eLumis[epoch]: self.epochLumis[epoch][run] |= eLumis[epoch][run] if not self.epochLumis: return lumiDir = self.outputFileName if not os.path.exists(lumiDir): utils.mkdir(lumiDir) lumis = utils.luminosity.recordedInvMicrobarnsShotgun([ utils.jsonFromRunDict(self.epochLumis[epoch]) for epoch in self.epochLumis ], cores=4, cacheDir=lumiDir) probs = [[1. / prescale if prescale else 0 for prescale in epoch] for epoch in self.epochLumis] inclu = [[ utils.unionProbability(prob[:i + 1]) for i in range(len(prob)) ] for prob in probs] thresholds = sorted(set(self.thresholds)) inclusives = [[ max([0] + [p for p, t in zip(inc, self.thresholds) if t is thresh]) for thresh in thresholds ] for inc in inclu] weights = np.array(lumis).dot(inclusives) / sum(lumis) # write total lumi and weight by threshold lumiHist = r.TH1D('susyTreeLumi', 'luminosity from susyTree;;1/pb', 1, 0, 1) lumiHist.SetBinContent(1, sum(lumis)) lumiHist.Write() weightHist = r.TH1D( self.name, ";%s;%s" % (self.var, self.name), len(thresholds), np.array([0.] + thresholds + [max(thresholds) + 10])) for i, w in enumerate(weights): weightHist.SetBinContent(i + 2, w) weightHist.SetBinContent(len(thresholds) + 3, 1) weightHist.Write()