Esempio n. 1
0
for iBin in range(1, nOutputBins + 1):
    sigVal = sigScoreHist.GetBinContent(iBin)
    bkgVal = bkgScoreHist.GetBinContent(iBin)
    sigScoreHist.SetBinContent(iBin, 1.)
    if sigVal > 0.:
        bkgScoreHist.SetBinContent(iBin, bkgVal / sigVal)
    else:
        bkgScoreHist.SetBinContent(iBin, 0)

sigScoreHist.Scale(1. / sigScoreHist.Integral())
bkgScoreHist.Scale(1. / bkgScoreHist.Integral())
sigScoreHist.SetLineColor(r.kBlue)
sigScoreHist.Draw('hist')
bkgScoreHist.SetLineColor(r.kRed)
bkgScoreHist.Draw('hist,same')
useSty.drawCMS()
useSty.drawEnPu(lumi='35.9 fb^{-1}')
theCanv.SaveAs('%s/outputScores.pdf' % plotDir)

#draw sig vs background distribution
theCanv = useSty.setCanvas()
sigScoreW = diphoTestFW * (diphoTestY == 1)
sigScoreHist = r.TH1F('sigScoreHist', 'sigScoreHist', nOutputBins, 0., 1.)
useSty.formatHisto(sigScoreHist)
sigScoreHist.SetTitle('')
sigScoreHist.GetXaxis().SetTitle('Diphoton BDT score')
fill_hist(sigScoreHist, altDiphoPredY, weights=sigScoreW)
bkgScoreW = diphoTestFW * (diphoTestY == 0)
bkgScoreHist = r.TH1F('bkgScoreHist', 'bkgScoreHist', nOutputBins, 0., 1.)
useSty.formatHisto(bkgScoreHist)
bkgScoreHist.SetTitle('')
Esempio n. 2
0
 def crossCheck(self, lumi, plotDir):
     '''Run a check to ensure the random search found a good mimimum'''
     for iName, name in enumerate(self.names):
         for iCat in range(self.nCats):
             best = self.boundaries[name][iCat]
             rnge = 0.2 * self.highs[name] - self.lows[name]
             graph = r.TGraph()
             for iVal, val in enumerate(
                     np.arange(best - rnge / 2., best + rnge / 2.,
                               rnge / 10.)):
                 sigs = []
                 bkgs = []
                 nons = []
                 cuts = {}
                 cuts[name] = self.boundaries[name]
                 cuts[name][iCat] = val
                 bests = Bests(self.nCats)
                 for jCat in range(self.nCats):
                     lastCat = (jCat + 1 == self.nCats)
                     sigWeights = self.sigWeights
                     bkgWeights = self.bkgWeights
                     if self.addNonSig: nonSigWeights = self.nonSigWeights
                     for jName, jname in enumerate(self.names):
                         sigWeights = sigWeights * (self.sigDiscrims[jname]
                                                    > cuts[jname][jCat])
                         bkgWeights = bkgWeights * (self.bkgDiscrims[jname]
                                                    > cuts[jname][jCat])
                         if self.addNonSig:
                             nonSigWeights = nonSigWeights * (
                                 self.nonSigDiscrims[jname] >
                                 cuts[jname][jCat])
                         if not lastCat:
                             if jName == 0 or self.sortOthers:
                                 sigWeights = sigWeights * (
                                     self.sigDiscrims[jname] <
                                     cuts[jname][jCat + 1])
                                 bkgWeights = bkgWeights * (
                                     self.bkgDiscrims[jname] <
                                     cuts[jname][jCat + 1])
                                 if self.addNonSig:
                                     nonSigWeights = nonSigWeights * (
                                         self.nonSigDiscrims[jname] <
                                         cuts[jname][jCat + 1])
                     sigHist = r.TH1F('sigHistTemp', 'sigHistTemp', 160,
                                      100, 180)
                     fill_hist(sigHist, self.sigMass, weights=sigWeights)
                     sigCount = 0.68 * lumi * sigHist.Integral()
                     sigWidth = self.getRealSigma(sigHist)
                     bkgHist = r.TH1F('bkgHistTemp', 'bkgHistTemp', 160,
                                      100, 180)
                     fill_hist(bkgHist, self.bkgMass, weights=bkgWeights)
                     bkgCount = self.computeBkg(bkgHist, sigWidth)
                     if self.addNonSig:
                         nonSigHist = r.TH1F('nonSigHistTemp',
                                             'nonSigHistTemp', 160, 100,
                                             180)
                         fill_hist(nonSigHist,
                                   self.nonSigMass,
                                   weights=nonSigWeights)
                         nonSigCount = 0.68 * lumi * nonSigHist.Integral()
                     else:
                         nonSigCount = 0.
                     sigs.append(sigCount)
                     bkgs.append(bkgCount)
                     nons.append(nonSigCount)
                 bests.update(sigs, bkgs, nons)
                 graph.SetPoint(iVal, val - best, bests.getTotSignif())
             canv = useSty.setCanvas()
             graphName = 'CrossCheck_%s_Cat%g' % (name, iCat)
             graph.SetTitle(graphName.replace('_', ' '))
             graph.GetXaxis().SetTitle('Cut value - chosen value')
             graph.GetYaxis().SetTitle('Significance (#sigma)')
             graph.Draw()
             useSty.drawCMS(text='Internal')
             useSty.drawEnPu(lumi=lumi)
             canv.Print('%s/%s.pdf' % (plotDir, graphName))
             canv.Print('%s/%s.png' % (plotDir, graphName))
    for iBin, iPar in enumerate(pars.values()):
        for jBin, jPar in enumerate(pars.values()):
            proc = theMatrix.GetXaxis().GetBinLabel(iPar + 1)
            #print 'Got proc %s, expecting proc %s'%(proc, revPars[iPar])
            theVal = theMatrix.GetBinContent(iPar + 1, jPar + 1)
            #print 'Value for correlation between %s and %s is %.3f'%(revPars[iPar],revPars[jPar],theVal)
            theHist.GetXaxis().SetBinLabel(iBin + 1, prettyProc(revPars[iPar]))
            theHist.GetYaxis().SetBinLabel(jBin + 1, prettyProc(revPars[jPar]))
            theHist.Fill(iBin, jBin, theVal)

    set_color_palette('frenchFlag')
    r.gStyle.SetNumberContours(500)
    r.gStyle.SetPaintTextFormat('1.2f')

    #canv = r.TCanvas('canv','canv')
    canv = setCanvas()
    formatHisto(theHist)
    theHist.GetXaxis().SetTickLength(0.)
    theHist.GetXaxis().SetLabelSize(0.05)
    theHist.GetYaxis().SetTickLength(0.)
    theHist.GetYaxis().SetLabelSize(0.05)
    theHist.GetZaxis().SetRangeUser(-1., 1.)
    theHist.GetZaxis().SetTickLength(0.)

    theHist.Draw('colz,text')
    drawCMS(True)
    drawEnPu(lumi='%2.1f fb^{-1}' % lumi)
    canv.Print('Plots/corrMatrixFormal_%s.png' % ext)
    canv.Print('Plots/corrMatrixFormal_%s.pdf' % ext)
Esempio n. 4
0
def main():
  for fileName in fullFileNames:
    if 'M125' not in fileName: continue
    theProc = fileName.split('pythia8_')[1].split('.root')[0]
    theProc0 = theProc.split('_')[0]
    #if theProc not in procsOfInterest: continue
    print 'processing %s'%theProc
    theFile = r.TFile(fileName, 'READ')
    theWS = theFile.Get('tagsDumper/cms_hgg_13TeV')
    for cat in cats:
      dataName = '%s_125_13TeV_%s'%(nameMap[theProc0], cat)
      sumEntries = theWS.data(dataName).sumEntries()
      if sumEntries < 0.: sumEntries = 0.
      if theProc not in procsOfInterest: 
        theProc = 'OTHER'
      sumwProcCatMap[ (theProc,cat) ] += sumEntries
      sumwProcMap[ theProc ] += sumEntries
      sumwCatMap[ cat ] += sumEntries

  print 'got all values'
  nBinsX = len(procsOfInterest)
  nBinsY = len(cats)
  procHist = r.TH2F('procHist','procHist', nBinsX, -0.5, nBinsX-0.5, nBinsY, -0.5, nBinsY-0.5)
  procHist.SetTitle('')
  catHist  = r.TH2F('catHist','catHist', nBinsX, -0.5, nBinsX-0.5, nBinsY, -0.5, nBinsY-0.5)
  catHist.SetTitle('')
  for iProc,proc in enumerate(procsOfInterest):
    #print 'iProc,proc',iProc,proc
    for iCat,cat in enumerate(cats):
      procWeight = 100. * sumwProcCatMap[(proc,cat)] / sumwProcMap[proc]
      if procWeight < 0.5: procWeight=-1
      catWeight  = 100. * sumwProcCatMap[(proc,cat)] / sumwCatMap[cat]
      if catWeight < 0.5: catWeight=-1

      catLabel = cat.split('ECO_')[1]
      catLabel = catLabel.replace('PTH_0_60','low')
      catLabel = catLabel.replace('PTH_60_120','med')
      catLabel = catLabel.replace('PTH_120_200','high')
      catLabel = catLabel.replace('PTH_GT200','BSM')
      catLabel = catLabel.replace('GE2J','2J')
      catLabel = catLabel.replace('PTJET1_GT200','BSM')
      catLabel = catLabel.replace('VBFTOPO','VBF')
      catLabel = catLabel.replace('JET3VETO','2J-like')
      catLabel = catLabel.replace('JET3','3J-like')
      catLabel = catLabel.replace('VH2JET','VH-like')
      catLabel = catLabel.replace('REST','rest')
      catLabel = catLabel.replace('_',' ')

      procHist.Fill( iProc, iCat, procWeight )
      procHist.GetXaxis().SetBinLabel( iProc+1, prettyProc(proc) )
      procHist.GetYaxis().SetBinLabel( iCat+1, catLabel )

      catHist.Fill( iProc, iCat, catWeight )
      catHist.GetXaxis().SetBinLabel( iProc+1, prettyProc(proc) )
      catHist.GetYaxis().SetBinLabel( iCat+1, catLabel )
  
  #canv = r.TCanvas('canv','canv')
  set_color_palette('ed_noice')
  canv = setCanvas()
  formatHisto(procHist)
  procHist.SetStats(0)
  procHist.GetXaxis().SetTitle('STXS process')
  procHist.GetXaxis().SetTitleOffset(3)
  procHist.GetXaxis().SetTickLength(0.)
  procHist.GetXaxis().LabelsOption('v')
  procHist.GetYaxis().SetTitle('Event category')
  procHist.GetYaxis().SetTitleOffset(2.7)
  procHist.GetYaxis().SetTickLength(0.)
  procHist.GetZaxis().SetTitle('Signal category destination (%)')
  procHist.SetMinimum(-0.00001)
  procHist.SetMaximum(100.)
  procHist.Draw('colz,text')
  lines = []
  for iProc,proc in enumerate(procsOfInterest):
    lines.append(r.TLine(iProc+0.5, -0.5, iProc+0.5, len(cats)-0.5))
    lines[-1].SetLineColorAlpha(r.kGray, 0.5)
    lines[-1].SetLineWidth(1)
  lines.append(r.TLine(-0.5, 17.5, len(procsOfInterest)-0.5, 17.5)) #horiontal ggH VBF divider
  lines[-1].SetLineColorAlpha(r.kBlack, 0.5)
  lines[-1].SetLineWidth(1)
  lines.append(r.TLine(10.5, -0.5, 10.5, len(cats)-0.5)) #vertical ggH VBF divider
  lines[-1].SetLineColorAlpha(r.kBlack, 0.5)
  lines[-1].SetLineWidth(1)
  for line in lines: line.Draw()
  drawCMS(True)
  #drawEnPu(lumi='%.1f fb^{-1}'%lumi)
  drawEnYear(year=opts.year)
  canv.Print('procHist_%s.pdf'%ext)
  canv.Print('procHist_%s.png'%ext)
  formatHisto(catHist)
  catHist.SetStats(0)
  catHist.GetXaxis().SetTitle('STXS process')
  catHist.GetXaxis().SetTitleOffset(3)
  catHist.GetXaxis().SetTickLength(0.)
  catHist.GetXaxis().LabelsOption('v')
  catHist.GetYaxis().SetTitle('Event category')
  catHist.GetYaxis().SetTitleOffset(2.7)
  catHist.GetYaxis().SetTickLength(0.)
  catHist.GetZaxis().SetTitle('Category signal composition (%)')
  catHist.SetMinimum(-0.00001)
  catHist.SetMaximum(100.)
  catHist.Draw('colz,text')
  lines = []
  for iCat,cat in enumerate(cats):
    if cat.count('Tag1') or cat.count('RECO_1J_PTH_GT200') or cat.count('RECO_VBFTOPO_REST'):
      lines.append(r.TLine(-0.5, iCat+0.5, len(procsOfInterest)-0.5, iCat+0.5))
      lines[-1].SetLineColorAlpha(r.kGray, 0.5)
      lines[-1].SetLineWidth(1)
    else:
      lines.append(r.TLine(-0.5, iCat+0.5, len(procsOfInterest)-0.5, iCat+0.5))
      lines[-1].SetLineColorAlpha(r.kGray, 0.25)
      lines[-1].SetLineWidth(1)
  lines.append(r.TLine(-0.5, 17.5, len(procsOfInterest)-0.5, 17.5)) #horiontal ggH VBF divider
  lines[-1].SetLineColorAlpha(r.kBlack, 0.5)
  lines[-1].SetLineWidth(1)
  lines.append(r.TLine(10.5, -0.5, 10.5, len(cats)-0.5)) #vertical ggH VBF divider
  lines[-1].SetLineColorAlpha(r.kBlack, 0.5)
  lines[-1].SetLineWidth(1)
  for line in lines: line.Draw()
  drawCMS(True)
  #drawEnPu(lumi='%.1f fb^{-1}'%lumi)
  drawEnYear(year=opts.year)
  canv.Print('catHist_%s.pdf'%ext)
  canv.Print('catHist_%s.png'%ext)
  #save hists
  outFile = r.TFile('stxsStage1Hists_%s.root'%ext,'RECREATE')
  procHist.Write()
  catHist.Write()
  outFile.Close()