def PrintSystTable(self, name='uncertainties'): t = OutText(self.outpath, name, "new", textformat=self.textformat) t.SetTexAlign("l c") t.SetSeparatorLength(30) t.SetDefaultFixOption(False) t.line('%Uncertainties on tt inclusive cross section \n% ' + 'for channel \'%s\' and level \'%s\'' % (self.GetChan(), self.GetLevel())) exp = self.GetExpUnc() mod = self.GetModUnc() stat = self.GetXsecStatUnc() lum = self.GetXsecLumiUnc() syst = self.GetXsecSystUnc() xsec = self.GetXsec() t.bar() t.line(t.fix(' Source', 18, 'l') + t.vsep() + fix("value (\%)", 6)) t.sep() for b in [x.GetName() for x in self.bkg]: t.line( fix(' ' + b, 18, 'r') + t.vsep() + fix('%1.2f' % (self.GetXsecBkgRelUnc(b) * 100), 6)) t.sep() for e in exp.keys(): t.line( fix(' ' + e, 18, 'l') + t.vsep() + fix('%1.2f' % (exp[e] * 100), 6)) t.sep() for e in mod.keys(): t.line( fix(' ' + e, 18, 'l') + t.vsep() + fix('%1.2f' % (mod[e] * 100), 6)) t.sep() t.line( fix(' Total systematic', 18, 'l') + t.vsep() + fix('%1.2f' % (syst * 100), 6)) t.sep() t.line( fix(' Statistics', 18, 'l') + t.vsep() + fix('%1.2f' % (stat * 100), 6)) t.sep() t.line( fix(' Luminosity', 18, 'l') + t.vsep() + fix('%1.2f' % (lum * 100), 6)) t.bar() t.write()
def PrintYields(self, name='yields', doStat=True, doSyst=True): t = OutText(self.outpath, name, "new", textformat=self.textformat) t.SetTexAlign("l c") nsem = 16 + 3 + 8 + (5 + 8 if doStat else 0) + (5 + 8 if doSyst else 0) t.SetSeparatorLength(nsem) t.line('%' + 'Yields for channel \'%s\' and level \'%s\'' % (self.GetChan(), self.GetLevel())) t.bar() for pr in self.bkg: name = t.fix(" %s" % pr.GetName(), 16, 'l', 0) y = t.fix("%1.2f" % pr.GetYield(), 8, 0) stat = t.fix("%1.2f" % pr.GetStatUnc(), 8, 0) syst = t.fix("%1.2f" % pr.GetSystAbsUnc(), 8, 0) t.line(name + t.vsep() + y + ((t.pm() + stat) if doStat else '') + ((t.pm() + syst) if doSyst else '')) t.sep() totbkg = t.fix("%1.2f" % self.GetTotBkg(), 8, 0) totbkgstat = t.fix("%1.2f" % self.GetTotBkgStatUnc(), 8, 0) totbkgsyst = t.fix("%1.2f" % self.GetTotBkgSystUnc(), 8, 0) t.line( t.fix(" Total bkg", 16, 'l', 0) + t.vsep() + totbkg + ((t.pm() + totbkgstat) if doStat else '') + ((t.pm() + totbkgsyst) if doSyst else '')) t.sep() y = self.GetSignalYield() signal = t.fix(" %s" % (self.GetSignal().GetName()), 16, 'l', 0) ysig = t.fix("%1.2f" % y, 8, 0) sigunc = t.fix("%1.2f" % (self.GetXsecSystUnc() * y), 8, 0) sigsta = t.fix("%1.2f" % self.GetSignal().GetStatUnc(), 8, 0) t.line(signal + t.vsep() + ysig + ((t.pm() + sigsta) if doStat else '') + ((t.pm() + sigunc) if doSyst else '')) t.sep() t.line( t.fix(" Data", 16, 'l', 0) + t.vsep() + t.fix("%i" % self.GetData(), 8, 0)) t.bar() t.write()
def PrintXsec(self, name='xsec'): t = OutText(self.outpath, name, "new", textformat=self.textformat) t.SetTexAlign("l c") t.SetSeparatorLength(26 + 3 + 20 + 5) t.SetDefaultFixOption(False) t.line('%' + 'tt cross section for channel \'%s\' and level \'%s\'' % (self.GetChan(), self.GetLevel())) acc = self.GetAcc() eff = self.GetEff() t.bar() t.line( t.fix(' Acceptance', 16, 'r') + t.vsep() + t.fix("%1.4f" % acc, 6) + t.pm() + t.fix("%1.2f" % (acc * self.GetAccUnc()), 8)) t.line( t.fix(' Efficiency', 16, 'r') + t.vsep() + t.fix("%1.4f" % eff, 6) + t.pm() + t.fix("%1.2f" % (eff * self.GetEffUnc()), 8)) t.sep() t.line( t.fix(' Branching ratio', 16, 'r') + t.vsep() + t.fix("%1.4f" % self.GetBR(), 6)) t.line( t.fix(' Gen events', 16, 'r') + t.vsep() + t.fix("%d" % self.GetGenEvents(), 9)) t.line( t.fix(' Fiducial events', 16, 'r') + t.vsep() + t.fix("%d" % self.GetFiduEvents(), 9)) if self.doFiducial: t.sep() xsec = self.GetFiduXsec() stat = self.GetXsecStatUnc() syst = self.GetEffUnc() lumi = self.GetXsecLumiUnc() #t.line(t.fix(' Fiducial cross section', 26, 'r') + t.vsep() + t.fix("%1.2f"%xsec,6)) #t.line(t.fix(' +\- ', 26, 'r') + ' ' + t.fix('%1.2f (%1.2f'%(stat*xsec,stat*100) + ' %) (stat)',20, 'l')) #t.line(t.fix(' +\- ', 26, 'r') + ' ' + t.fix('%1.2f (%1.2f'%(syst*xsec,syst*100) + ' %) (syst)',20, 'l')) #t.line(t.fix(' +\- ', 26, 'r') + ' ' + t.fix('%1.2f (%1.2f'%(lumi*xsec,lumi*100) + ' %) (lumi)',20, 'l')) t.sep() xsec = self.GetXsec() stat = self.GetXsecStatUnc() syst = self.GetXsecSystUnc() lumi = self.GetXsecLumiUnc() t.line( t.fix(' Inclusive cross section', 26, 'r') + t.vsep() + t.fix("%1.2f" % xsec, 6)) t.line( t.fix(' $\pm$ ', 26, 'r') + ' ' + t.fix('%1.2f (%1.2f' % (stat * xsec, stat * 100) + ' \%) (stat)', 20, 'l') + t.vsep()) t.line( t.fix(' $\pm$ ', 26, 'r') + ' ' + t.fix('%1.2f (%1.2f' % (syst * xsec, syst * 100) + ' \%) (syst)', 20, 'l') + t.vsep()) t.line( t.fix(' $\pm$ ', 26, 'r') + ' ' + t.fix('%1.2f (%1.2f' % (lumi * xsec, lumi * 100) + ' \%) (lumi)', 20, 'l') + t.vsep()) t.bar() t.write()
return [nom, uncnom, var, uncvar, syst, systunc] GetValAndUncString = lambda n,s : '%g \pm %1.2f%s'%(n, s/n*100, '%') ''' def PrintLine(sample, chan): print "Nominal - Variation %s - uncertainty"%sample nom, uncnom, var, uncvar, syst, systunc = GetGAandUnc(sample, chan) print "%s - %s - %s"%(GetValAndUncString(nom, uncnom), GetValAndUncString(var, uncvar), GetValAndUncString(syst, systunc)) PrintLine('hdampUp', 'ElMu') ''' if printRecoAndGen: t = OutText(outpath+'/genSyst/', 'genSyst_'+l, "new", textformat='tex') t.SetTexAlign("l c c c c c") nsem = 12 t.SetSeparatorLength(nsem) #t.line('Underlying event and hdamp uncertainties at reco and gen level (%s)'%l) t.bar() firstline = '' for lab in snames: firstline += t.vsep() + t.fix(lab,20) t.line(firstline) t.sep() for ch in ['ElEl', 'MuMu', 'ElMu']: for mode in ['Reco', 'Gen']: name = ('ee' if ch=='ElEl' else ('$\mu\mu$' if ch =='MuMu' else 'e$\mu$')) +' '+ mode name = t.fix(name, 10) for lab in snames: val, unc = GA(lab, ch) if mode == 'Gen' else RS(lab, ch)
def PrintYields(self, var='counts', tform='%1.2f', save=False, multicategories={}, bkgprocess=None, signalprocess=None, doData=True, doTotBkg=True): if bkgprocess != None: self.SetBkgProcesses(bkgprocess) if signalprocess != None: self.SetSignalProcesses(signalprocess) if multicategories != {}: k0 = multicategories.keys()[0] if not isinstance(multicategories[k0], dict): # Not a multicategory, but single one self.SetMultiCategores({'Yields': multicategories}) else: self.SetMultiCategores(multicategories) else: self.SetMultiCategores(multicategories) if self.multicategories == {}: print('[plotter.PrintYields] ERROR: no categories found!') exit() # Output name name = save if (save and save != '') else 'yields' # Create an OutText object: the output will be a tex file t = OutText(self.outpath, name, 'new', 'tex') t.bar() ncolumns = len(self.multicategories) t.SetTexAlign('l' + ' c' * ncolumns) dic = {} for k in self.multicategories.keys(): self.SetCategories(self.multicategories[k]) dic[k] = self.GetYields(var) # header header = '' for label in dic: header += t.vsep() + ' ' + label t.line(header) t.sep() # backgrounds for bkg in self.bkglist: line = bkg for label in dic: line += t.vsep() + ' ' + (tform % (dic[label][bkg])) t.line(line) if len(self.bkglist) > 0: t.sep() if doTotBkg and len(self.bkglist) > 0: line = 'Total background' for label in dic: line += t.vsep() + ' ' + ( tform % (sum([dic[label][bkg] for bkg in self.bkglist]))) t.line(line) t.sep() for sig in self.signallist: line = sig for label in dic: line += t.vsep() + ' ' + (tform % (dic[label][sig])) t.line(line) if len(self.signallist) > 0: t.sep() if doData: line = self.dataName for label in dic: line += t.vsep() + ' ' + tform % (dic[label][self.dataName]) t.line(line) t.sep() t.write()