Ejemplo n.º 1
0
 def PrintPDFyields(self, name='PDFvariations'):
     ''' Prints a table with the info of PDF systematics '''
     t = OutText(self.outpath, name)
     s = lambda i: ' ' + t.fix('[%d]' % i, 4, 'l', False
                               ) + ' %1.2f (%1.2f %s)' % (self.GetPDFyield(
                                   i), self.GetRelUncPDF(i) * 100, '%')
     c0 = s(1) + ' (nominal) '
     t.SetSeparatorLength(len(c0))
     t.line('### PDF and alpha_s uncertianties')
     t.line()
     if self.nPDFweights == 33:
         t.line(
             ' Using PDF4LHC15_nlo_nf4_30_pdfas, 1+30+2 weights, see Table 6 in '
         )
         t.line(' > https://arxiv.org/pdf/1510.03865.pdf')
     elif self.nPDFweights == 100:
         t.line('### NNPDF variations: 100 (2 alpha_s variations missing)')
         #cout << " >>>> NNPDF systematic uncertainty" << endl;
         #cout << " Evaluated by taking the RMS under the 100 weights" << endl;
         #cout << " Alpha_s variations are added in quadrature after rescaling by 0.75" << endl;
         #cout << " The formula is: sqrt(RMS^2 + ((alphas var 1 - alphas var 2)*0.75/2)^2 )" << endl;
     t.bar()
     t.line(c0)
     for i in range(2, self.nPDFweights + 1):
         t.line(s(i))
     t.sep()
     pdfunc = self.GetPDFunc()
     alphas = self.GetAlphaSunc()
     totunc = self.GetPDFandAlphaSunc()
     if self.nPDFweights == 33:
         t.line(' See reference: ')
         t.line(' > https://arxiv.org/pdf/1510.03865.pdf')
         t.line(' Eq [20] for PDF unc:  %1.2f (%1.2f %s)' %
                (pdfunc * self.GetPDFnom(), pdfunc * 100, '%'))
         t.line(' Eq [27] for alpha_S:  %1.2f (%1.2f %s)' %
                (alphas * self.GetPDFnom(), alphas * 100, '%'))
         t.sep()
     t.line(' Total PDF + alpha_S uncertainty: ')
     t.line('  ## %1.2f (%1.2f %s)' %
            (totunc * self.GetPDFnom(), totunc * 100, '%'))
     t.bar()
     t.write()
Ejemplo n.º 2
0
 def PrintMEscale(self, name='ScaleMEvariations'):
     ''' Prints a table with the info of scale systematics '''
     t = OutText(self.outpath, name)
     s = lambda i, muF, muR: ' [%d] muF = %1.2f, muR = %1.2f  | %1.2f (%1.2f %s)' % (
         i, muF, muR, self.GetScaleYield(i), self.GetRelUncScale(
             i) * 100, '%')
     nom = s(1, 0.5, 0.5)
     t.SetSeparatorLength(len(nom))
     t.line(" Scale ME uncertainties on tt acceptance")
     t.bar()
     t.line(nom)
     t.line(s(2, 0.5, 1.0))
     t.line(s(3, 0.5, 2.0) + ' (unphysical)')
     t.line(s(4, 1.0, 0.5))
     t.line(s(5, 1.0, 1.0) + ' (nominal)')
     t.line(s(6, 1.0, 2.0))
     t.line(s(7, 2.0, 0.5) + ' (unphysical)')
     t.line(s(8, 2.0, 1.0))
     t.line(s(9, 2.0, 2.0))
     t.sep()
     t.line(' Maximum variation: %1.2f %s ' %
            (self.GetMaxRelUncScale() * 100, '%'))
     t.bar()
     t.write()
Ejemplo n.º 3
0
 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()
Ejemplo n.º 4
0
 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()
Ejemplo n.º 5
0
 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()
Ejemplo n.º 6
0
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)
        name += t.vsep() + (t.fix("%1.2f %s"%(unc, '\%'), 20) if lab!='tt' else t.fix("%g"%(val), 20))
        #name += t.vsep() + t.fix("%1.1f (%1.2f %s)"%(val, unc, '%'), 20)
      t.line(name)
  t.bar()
  t.write()

if printGenAndStatUnc:
  t = OutText(outpath+'/genSyst/', 'genSystWithUnc_'+l, "new", textformat='tex')
  t.SetTexAlign("l c c")
Ejemplo n.º 7
0
    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()