Exemplo n.º 1
0
plt.savefig('%s/altDiphoROC.pdf' % plotDir)
plt.figure(3)
xg.plot_importance(diphoModel)
#plt.show()
plt.savefig('%s/diphoImportances.pdf' % plotDir)
plt.figure(4)
xg.plot_importance(altDiphoModel)
#plt.show()
plt.savefig('%s/altDiphoImportances.pdf' % plotDir)

#draw sig vs background distribution
nOutputBins = 50
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, diphoPredY, weights=sigScoreW)
bkgScoreW = diphoTestFW * (diphoTestY == 0)
bkgScoreHist = r.TH1F('bkgScoreHist', 'bkgScoreHist', nOutputBins, 0., 1.)
useSty.formatHisto(bkgScoreHist)
bkgScoreHist.SetTitle('')
bkgScoreHist.GetXaxis().SetTitle('Diphoton BDT score')
fill_hist(bkgScoreHist, diphoPredY, weights=bkgScoreW)

#apply transformation to flatten ggH
for iBin in range(1, nOutputBins + 1):
    sigVal = sigScoreHist.GetBinContent(iBin)
    bkgVal = bkgScoreHist.GetBinContent(iBin)
    sigScoreHist.SetBinContent(iBin, 1.)
    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)
Exemplo n.º 3
0
            bestSlo = sigCountLo
            bestBlo = bkgCountLo
            bestShi = sigCountHi
            bestBhi = bkgCountHi
    printStr += 'for proc %g the best outcome was tot signif %1.2f:\n' % (
        iProc, bestSignif)
    printStr += 'cutHi %1.3f, Shi %1.2f, Bhi %1.2f, signifHi %1.2f \n' % (
        bestCutHi, bestShi, bestBhi, bestSignifHi)
    printStr += 'cutLo %1.3f, Slo %1.2f, Blo %1.2f, signifLo %1.2f \n' % (
        bestCutLo, bestSlo, bestBlo, bestSignifLo)
    printStr += '\n'

    #now do some checking that random search found a good minimum
    cutLoCheck = r.TGraph()
    cutLoCheck.SetName('cutLoCheck_%g' % iProc)
    useSty.formatHisto(cutLoCheck.GetHistogram())
    cutLoCheck.GetXaxis().SetTitle('Change in cut')
    cutLoCheck.GetYaxis().SetTitle('Significance')
    cutLoCheck.SetTitle('')
    for iCutLo, cutLo in enumerate(
            np.arange(bestCutLo - 0.1, bestCutLo + 0.1, 0.01)):
        cutHi = bestCutHi
        sigHistHi = r.TH1F('sigHistHiTemp', 'sigHistHiTemp', 160, 100, 180)
        sigWeightsHi = diphoFW * (diphoY == 1) * (diphoS - 3 == iProc) * (
            diphoPredY > cutHi) * (diphoR == iProc)
        fill_hist(sigHistHi, diphoM, weights=sigWeightsHi)
        sigCountHi = 0.68 * lumi * sigHistHi.Integral()
        sigWidthHi = getRealSigma(sigHistHi)
        bkgHistHi = r.TH1F('bkgHistHiTemp', 'bkgHistHiTemp', 160, 100, 180)
        bkgWeightsHi = dataFW * (dataPredY > cutHi) * (dataR == iProc)
        fill_hist(bkgHistHi, dataM, weights=bkgWeightsHi)
print 'reconstructed  number of jets =  %s' % classTestN
print 'predicted      number of jets =  %s' % classPredJ
print 'truth          number of jets =  %s' % classTestJ
print
print 'predicted number of jets  =  %s' % classPredJ
print 'reconstructed diphoton pt =  %s' % classTestP
print 'predicted class           =  %s' % classPredY
print 'truth class               =  %s' % classTestY
print

#define reco hists
canv = useSty.setCanvas()
truthHist = r.TH1F('truthHist', 'truthHist', nClasses, -0.5, nClasses - 0.5)
truthHist.SetTitle('')
useSty.formatHisto(truthHist)
predHist = r.TH1F('predHist', 'predHist', nClasses, -0.5, nClasses - 0.5)
useSty.formatHisto(predHist)
predHist.SetTitle('')
rightHist = r.TH1F('rightHist', 'rightHist', nClasses, -0.5, nClasses - 0.5)
useSty.formatHisto(rightHist)
rightHist.SetTitle('')
wrongHist = r.TH1F('wrongHist', 'wrongHist', nClasses, -0.5, nClasses - 0.5)
useSty.formatHisto(wrongHist)
wrongHist.SetTitle('')

for iBin in range(1, nClasses + 1):
    truthHist.GetXaxis().SetBinLabel(iBin, binNames[iBin - 1])
    predHist.GetXaxis().SetBinLabel(iBin, binNames[iBin - 1])
    rightHist.GetXaxis().SetBinLabel(iBin, binNames[iBin - 1])
    wrongHist.GetXaxis().SetBinLabel(iBin, binNames[iBin - 1])
Exemplo n.º 5
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()