Example #1
0
    def mergeFunc(self, products):
        dd = collections.defaultdict
        epochs = dd(lambda: dd(set))
        prescales = {}
        for ps in products['prescales']:
            prescales.update(ps)
        if not prescales: return
        for (run, lumi), val in prescales.iteritems():
            epochs[val][run].add(lumi)

        lumiDir = self.outputFileName
        if not os.path.exists(lumiDir): utils.mkdir(lumiDir)

        lumis = utils.luminosity.recordedInvMicrobarnsShotgun(
            [utils.jsonFromRunDict(rundict) for rundict in epochs.values()],
            cores=4,
            cacheDir=lumiDir)
        lumiA, lumiB, lumiBPF = [
            sum(lumis)
            for lumis in zip(*[(lumi / A if A else 0, lumi / B if B else 0,
                                lumi / BPF if BPF else 0)
                               for (A, B,
                                    BPF), lumi in zip(epochs.keys(), lumis)])
        ]
        lumiHist = r.TH1D('lumis', 'luminosity by path;;1/pb', 3, 0, 3)
        lumiHist.SetBinContent(1, lumiA * 1e-6)
        lumiHist.GetXaxis().SetBinLabel(1, '2011A')
        lumiHist.SetBinContent(2, lumiB * 1e-6)
        lumiHist.GetXaxis().SetBinLabel(2, '2011B')
        lumiHist.SetBinContent(3, lumiBPF * 1e-6)
        lumiHist.GetXaxis().SetBinLabel(3, '2011BPF')
        lumiHist.Write()
        return
Example #2
0
    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()
Example #3
0
    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()
Example #4
0
    def mergeFunc(self, products) :
        d = collections.defaultdict(list)
        for lumisByRun in products["lumisByRun"] :
            for run,lumis in lumisByRun.iteritems() :
                d[run] += lumis

        d2 = {}
        for run,lumis in d.iteritems() :
            d2[run] = sorted(set(lumis))
            for ls in d2[run] :
                if 1 < lumis.count(ls) :
                    print "Run %d ls %d appears %d times in the lumiTree."%(run,ls,lumis.count(ls))

        json = utils.jsonFromRunDict(d2)
        with open(self.outputFileName,"w") as file: print >> file, str(json).replace("'",'"')

        print "Wrote %.4f/pb json to : %s"%(self.lumi(json),self.outputFileName)
        print utils.hyphens
Example #5
0
    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()
Example #6
0
    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()
Example #7
0
    def mergeFunc(self, products):
        d = collections.defaultdict(list)
        for lumisByRun in products["lumisByRun"]:
            for run, lumis in lumisByRun.iteritems():
                d[run] += lumis

        d2 = {}
        for run, lumis in d.iteritems():
            d2[run] = sorted(set(lumis))
            for ls in d2[run]:
                if 1 < lumis.count(ls) and self.verbose:
                    print "Run %d ls %d appears %d times in the lumiTree." % (
                        run, ls, lumis.count(ls))

        json = utils.jsonFromRunDict(d2)
        with open(self.outputFileName, "w") as file:
            print >> file, str(json).replace("'", '"')

        print "Wrote %.4f/pb json to : %s" % (self.lumi(json),
                                              self.outputFileName)
        print utils.hyphens
Example #8
0
    def mergeFunc(self,products) :
        dd = collections.defaultdict
        epochs = dd(lambda: dd(set))
        prescales = {}
        for ps in products['prescales'] : prescales.update(ps)
        if not prescales : return
        for (run,lumi),val in prescales.iteritems() : epochs[val][run].add(lumi)

        lumiDir = self.outputFileName
        if not os.path.exists(lumiDir) : utils.mkdir(lumiDir)

        lumis = utils.luminosity.recordedInvMicrobarnsShotgun( [ utils.jsonFromRunDict(rundict) for rundict in epochs.values() ],
                                                               cores = 4, cacheDir = lumiDir)
        lumiA,lumiB,lumiBPF = [ sum(lumis) for lumis in zip(*[(lumi/A if A else 0,
                                                               lumi/B if B else 0,
                                                               lumi/BPF if BPF else 0) for (A,B,BPF),lumi in zip(epochs.keys(),lumis) ] ) ]
        lumiHist = r.TH1D('lumis','luminosity by path;;1/pb', 3,0,3)
        lumiHist.SetBinContent(1,lumiA * 1e-6)   ; lumiHist.GetXaxis().SetBinLabel(1,'2011A')
        lumiHist.SetBinContent(2,lumiB * 1e-6)   ; lumiHist.GetXaxis().SetBinLabel(2,'2011B')
        lumiHist.SetBinContent(3,lumiBPF*1e-6) ; lumiHist.GetXaxis().SetBinLabel(3,'2011BPF')
        lumiHist.Write()
        return