Пример #1
0
    def reportCache(self) :
        r.gStyle.SetOptStat(0)
        fileName = '/'.join(self.outputFileName.split('/')[:-1]+[self.name])
        vars = dict([(sample,hists[self.var]) for sample,hists in self.fromCache(self.allSamples, [self.var]).items()])

        symmantis = dict([(s,(var,)+self.prep(var,self.funcEven,self.funcOdd)) for s,var in vars.items() if var])
        canvas = r.TCanvas()
        textlines = []
        for j,label in enumerate(['','Symmetric','Antisymmetric']) :
            leg = r.TLegend(0.85,0.85,0.98,0.98)
            limit_up = max([val[j].GetMaximum() for val in symmantis.values()] )
            limit_dn = min([val[j].GetMinimum() for val in symmantis.values()] + [0] )
            funcs = []
            for i,(sample,val) in enumerate(sorted(symmantis.items())) :
                val[j].SetMaximum(limit_up * 1.1)
                val[j].SetMinimum(limit_dn * 1.1)
                val[j].SetLineColor(i+1)
                val[j].SetMarkerColor(i+1)
                val[j].SetTitle("%s;%s;p.d.f"%(label,self.var))
                leg.AddEntry(val[j],sample,'l')
                val[j].Draw('hist' if not i else 'hist same')
                if not j : continue
                f = next(iter(val[j].GetListOfFunctions()))
                f.SetLineColor(i+1)
                f.SetLineStyle(2)
                f.SetLineWidth(1)
                f.Draw("same")
                textlines+=["%s : %s"%(sample,label)] + (['%+.4f\t%s'%(f.GetParameter(m),part) for m,part in enumerate(f.GetName().split('++'))] if '++' in f.GetName() else
                                                         ['[%d]\t%+.8f'%(m,f.GetParameter(m)) for m in range(f.GetNpar())]) + ['']
            leg.Draw()
            utils.tCanvasPrintPdf(canvas,fileName, verbose = j==2, option = ['(','',')'][j])
        with open(fileName+'.txt','w') as txtfile : print >> txtfile, '\n'.join(textlines)
Пример #2
0
 def reportCache(self) :
     fileName = '/'.join(self.outputFileName.split('/')[:-1]+[self.name])
     self.setup()
     if not self.p : return
     c = r.TCanvas()
     self.p.SetLineWidth(2)
     self.p.SetMaximum(1)
     self.p.SetMinimum(0)
     self.p.Draw('hist')
     self.q.SetLineWidth(2)
     self.q.SetLineColor(r.kRed)
     self.q.Draw('hist same')
     mean = self.q.Clone('mean'); mean.Reset();
     for i in range(mean.GetNbinsX()) : mean.SetBinContent(i+1,self.mean)
     mean.SetTitle("%.2f"%self.mean)
     mean.SetLineColor(r.kBlue)
     mean.Draw('hist same')
     utils.tCanvasPrintPdf(c,fileName)
     del mean
     del c
Пример #3
0
 def reportCache(self):
     fileName = '/'.join(self.outputFileName.split('/')[:-1]+[self.name])
     c = r.TCanvas()
     utils.tCanvasPrintPdf(c, fileName, False, '[')
     cache = self.fromCache(['merged'],self.parBins.keys(), self.tag)['merged']
     for par,hist in cache.items():
         pivot = self.parBins[par][3]
         lo = hist.ProjectionY(hist.GetName()+'_lo', 0, hist.GetXaxis().FindFixBin(pivot)-1)
         hi = hist.ProjectionY(hist.GetName()+'_hi', hist.GetXaxis().FindFixBin(pivot), -1)
         tot = hist.ProjectionY()
         lo.Divide(tot)
         hi.Divide(tot)
         tot.Scale(1./tot.Integral())
         lo.SetLineColor(r.kBlue)
         hi.SetLineColor(r.kRed)
         lo.SetMinimum(0)
         lo.SetMaximum(1)
         tot.SetFillColor(17)
         tot.SetFillStyle(1001)
         l = r.TLine(pivot,0,pivot,1)
         l.SetLineColor(r.kGreen)
         lo.Draw('hist')
         hi.Draw('hist same')
         tot.Draw('hist same')
         l.Draw()
         utils.tCanvasPrintPdf(c, fileName, False)
     utils.tCanvasPrintPdf(c, fileName, True, ']')
Пример #4
0
 def reportCache(self):
     fileName = '/'.join(self.outputFileName.split('/')[:-1] + [self.name])
     c = r.TCanvas()
     utils.tCanvasPrintPdf(c, fileName, False, '[')
     cache = self.fromCache(['merged'], self.parBins.keys(),
                            self.tag)['merged']
     for par, hist in cache.items():
         pivot = self.parBins[par][3]
         lo = hist.ProjectionY(hist.GetName() + '_lo', 0,
                               hist.GetXaxis().FindFixBin(pivot) - 1)
         hi = hist.ProjectionY(hist.GetName() + '_hi',
                               hist.GetXaxis().FindFixBin(pivot), -1)
         tot = hist.ProjectionY()
         lo.Divide(tot)
         hi.Divide(tot)
         tot.Scale(1. / tot.Integral())
         lo.SetLineColor(r.kBlue)
         hi.SetLineColor(r.kRed)
         lo.SetMinimum(0)
         lo.SetMaximum(1)
         tot.SetFillColor(17)
         tot.SetFillStyle(1001)
         l = r.TLine(pivot, 0, pivot, 1)
         l.SetLineColor(r.kGreen)
         lo.Draw('hist')
         hi.Draw('hist same')
         tot.Draw('hist same')
         l.Draw()
         utils.tCanvasPrintPdf(c, fileName, False)
     utils.tCanvasPrintPdf(c, fileName, True, ']')
Пример #5
0
 def reportCache(self):
     fileName = '/'.join(self.outputFileName.split('/')[:-1] + [self.name])
     self.setup()
     if not self.p: return
     c = r.TCanvas()
     self.p.SetLineWidth(2)
     self.p.SetMaximum(1)
     self.p.SetMinimum(0)
     self.p.Draw('hist')
     self.q.SetLineWidth(2)
     self.q.SetLineColor(r.kRed)
     self.q.Draw('hist same')
     mean = self.q.Clone('mean')
     mean.Reset()
     for i in range(mean.GetNbinsX()):
         mean.SetBinContent(i + 1, self.mean)
     mean.SetTitle("%.2f" % self.mean)
     mean.SetLineColor(r.kBlue)
     mean.Draw('hist same')
     utils.tCanvasPrintPdf(c, fileName)
     del mean
     del c
Пример #6
0
 def reportCache(self) :
     likes = self.likelihoods()
     fileName = '/'.join(self.outputFileName.split('/')[:-1]+[self.name])
     optstat = r.gStyle.GetOptStat()
     r.gStyle.SetOptStat(0)
     c = r.TCanvas()
     utils.tCanvasPrintPdf(c, fileName, False, '[')
     with open(fileName+'.txt', "w") as file :
         print >> file, '\n'.join(str(d) for d in self.populations)
         print >> file
         for key in sorted((set(likes[0]) & set(likes[1]) & set(likes[2])), key = lambda k: -1 if self.name==k else k) :
             if not all(item[key] for item in likes) : continue
             dilutions = [utils.dilution(bins1,bins2) for bins1,bins2 in itertools.combinations([utils.binValues(item[key]) for item in likes],2)]
             print >> file, "\t".join([key.ljust(25)]+["%.4f"%d for d in dilutions])
             h = 1.1*max(item[key].GetMaximum() for item in likes)
             l = r.TLegend(0.75,0.85,0.98,0.98)
             l.SetHeader("Dilutions :  %.3f  %.3f  %.3f"%tuple(dilutions))
             for i,(item,color,pop) in enumerate(zip(likes,[r.kBlack,r.kRed,r.kBlue],self.populations)) :
                 item[key].SetLineColor(color)
                 item[key].SetMaximum(h)
                 item[key].SetMinimum(0)
                 item[key].GetYaxis().SetTitle("pdf")
                 item[key].Draw("hist" + ('same' if i else ''))
                 l.AddEntry(item[key], pop['pre'],'l')
             l.Draw()
             utils.tCanvasPrintPdf(c, fileName, False)
     c.Clear()
     c.Divide(3,2)
     covs = [self.fromCache([item['pre']], ["_cov_%s_%s"%pair for pair in itertools.combinations(self.dists.keys(),2)], tag = item['tag'])[item['pre']] for item in self.populations]
     for key in (set(covs[0]) & set(covs[1]) & set(covs[2])) :
         if not all(item[key] for item in covs) : continue
         hists = [item[key] for item in covs]
         deps = [utils.dependence(h,limit=1,inSigma=False) for h in hists]
         for i,(h,d,pop) in enumerate(zip(hists,deps,self.populations)) :
             d.SetTitle(pop['pre'])
             c.cd(i+1); h.Draw('colz')
             c.cd(i+4); d.Draw('colz')
         utils.tCanvasPrintPdf(c, fileName, False)
     c.Clear()
     for key in sorted((set(likes[0]) & set(likes[1]) & set(likes[2])), key = lambda k: -1 if self.name==k else k) :
         if not all(item[key] for item in likes) : continue
         for i,j in itertools.combinations(range(3),2) :
             k = next(k for k in range(3) if k not in [i,j])
             templates = [ utils.binValues(likes[ii][key]) for ii in [i,j] ]
             observed = utils.binValues(likes[k][key])
             try:  cs = utils.fractions.componentSolver(observed,templates)
             except: cs = None
             if not cs : continue
             notK = likes[k][key].Clone('bf_not_'+likes[k][key].GetName())
             notK.Reset()
             notK.Add(likes[i][key],likes[j][key],cs.fractions[0],cs.fractions[1])
             dil = utils.dilution(utils.binValues(likes[k][key]),utils.binValues(notK))
             l = r.TLegend(0.75,0.85,0.98,0.98)
             l.SetHeader("Dilution : %.3f"%dil)
             l.AddEntry(likes[k][key], self.populations[k]['pre'], 'l')
             l.AddEntry(notK, 'not '+self.populations[k]['pre'], 'l')
             notK.SetLineStyle(2)
             likes[k][key].Draw('hist')
             notK.Draw('hist same')
             l.Draw()
             utils.tCanvasPrintPdf(c, fileName, False)
     utils.tCanvasPrintPdf(c, fileName, True, ']')
     r.gStyle.SetOptStat(optstat)