Ejemplo n.º 1
0
        def measureFractions(dist) :
            before = next(self.orgMelded.indicesOfStep("label","selection complete"))
            distTup = self.orgMelded.steps[next(iter(filter(lambda i: before<i, self.orgMelded.indicesOfStepsWithKey(dist))))][dist]
            #distTup = self.orgMelded.steps[next(self.orgMelded.indicesOfStepsWithKey(dist))][dist]

            templateSamples = ['top.t#bar{t}','top.w_jets','QCD.Data 2011']
            templates = [None] * len(templateSamples)
            for ss,hist in zip(self.orgMelded.samples,distTup) :
                contents = [hist.GetBinContent(i) for i in range(hist.GetNbinsX()+2)]
                if ss['name'] == "top.Data 2011" :
                    observed = contents
                    nEventsObserved = sum(observed)
                elif ss['name'] in templateSamples :
                    templates[templateSamples.index(ss['name'])] = contents
                else : pass
        
            from core.fractions import componentSolver,drawComponentSolver
            cs = componentSolver(observed, templates, 1e4)
            csCanvas = drawComponentSolver(cs)
            name = "measuredFractions_%s"%dist
            utils.tCanvasPrintPdf(csCanvas[0], "%s/%s"%(self.globalStem,name))
            with open(self.globalStem+"/%s.txt"%name,"w") as file :
                print >> file, cs
                print >> file, cs.components
            return distTup,cs
Ejemplo n.º 2
0
    def measureQQbarComponent(self) :
        dist = "DiscriminantTopQqQg"
        dists = dict(zip([ss['name'] for ss in self.orgMelded.samples ],
                         self.orgMelded.steps[next(self.orgMelded.indicesOfStepsWithKey(dist))][dist] ) )
        def contents(name) : return np.array([dists[name].GetBinContent(i) for i in range(dists[name].GetNbinsX()+2)])

        from core.fractions import componentSolver, drawComponentSolver
        cs = componentSolver(observed = contents('top.Data 2011'),
                             components = [ contents('top.tt_tauola_fj.wTopAsymP00.tw.nvr'), contents('top.tt_tauola_fj.wNonQQbar.tw.nvr')],
                             ensembleSize = 1e4,
                             base = contents('top.w_jets') + contents('QCD.Data 2011')
                             )
        csCanvas = drawComponentSolver(cs)
        utils.tCanvasPrintPdf(csCanvas[0], "%s/measuredQQFractions"%self.globalStem)
        with open(self.globalStem+"/measuredQQFractions.txt","w") as file :  print >> file, cs
Ejemplo n.º 3
0
    def meldNorm(self) :
        meldSamples = {"top_muon_pf" : ["SingleMu","P00","NonQQbar","w_jets"],
                       #"Wlv_muon_pf" : ["w_jets"],
                       "QCD_muon_pf" : ["SingleMu"]}

        organizers = [organizer.organizer(tag, [s for s in self.sampleSpecs(tag) if any(item in s['name'] for item in meldSamples[tag])])
                      for tag in [p['tag'] for p in self.readyConfs if p["tag"] in meldSamples]]
        if not organizers : return
        for org in organizers :
            org.mergeSamples(targetSpec = {"name":"t#bar{t}", "color":r.kViolet}, sources=["tt_tauola_fj.wNonQQbar.nvr","tt_tauola_fj.wTopAsymP00.nvr"])
            org.mergeSamples(targetSpec = {"name":"w_jets", "color":r.kRed}, allWithPrefix = "w_jets")
            org.mergeSamples(targetSpec = {"name":"Data 2011",
                                           "color":r.kBlue if "qcd_" in org.tag else r.kBlack,
                                           "markerStyle":(20 if "top" in org.tag else 1)}, allWithPrefix="SingleMu")
            
        if True :
            templates = []
            dist = "TriDiscriminant"
            for org in organizers :
                before = next(org.indicesOfStep("label","selection complete"))
                distTup = org.steps[next(iter(filter(lambda i: before<i, org.indicesOfStepsWithKey(dist))))][dist]
                for ss,hist in zip(org.samples,distTup) :            
                    contents = [hist.GetBinContent(i) for i in range(hist.GetNbinsX()+2)]
                    if "top" in org.tag and ss["name"] is "Data 2011":  signal = contents
                    else : templates.append(contents)
                    print org.tag, ss["name"]
            from core import fractions
            cs = fractions.componentSolver(signal, templates, 1e4)
            with open("measuredFractions.txt","w") as file : print >> file, cs
            stuff = fractions.drawComponentSolver(cs)
            stuff[0].Print("measuredFractions.eps")
        
        for org in organizers : org.scale(toPdf=True)
            
        melded = organizer.organizer.meld(organizers = organizers)
        pl = plotter.plotter(melded, psFileName = self.psFileName(melded.tag),
                             doLog = False, blackList = ["lumiHisto","xsHisto","nJobsHisto"] ).plotAll()