Example #1
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)
        lumi = luminosity.recordedInvMicrobarns(json)/1e6 if self.calculateLumi else -1.0
        with open(self.outputFileName,"w") as file: print >> file, str(json).replace("'",'"')
        print "Wrote %.4f/pb json to : %s"%(lumi,self.outputFileName)
        print utils.hyphens
Example #2
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 = 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()