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('') bkgScoreHist.GetXaxis().SetTitle('Diphoton BDT score')
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)
else: wrongHist.Fill(true,w) firstBinVal = -1. for iBin in range(1,truthHist.GetNbinsX()+1): if iBin==1: firstBinVal = truthHist.GetBinContent(iBin) ratio = float(truthHist.GetBinContent(iBin)) / firstBinVal print 'ratio for bin %g is %1.7f'%(iBin,ratio) wrongHist.Add(rightHist) rightHist.Divide(wrongHist) effHist = r.TH1F r.gStyle.SetOptStat(0) truthHist.GetYaxis().SetRangeUser(0.,8.) truthHist.Draw('hist') useSty.drawCMS() useSty.drawEnPu(lumi='35.9 fb^{-1}') canv.Print('truthJetHist.pdf') predHist.GetYaxis().SetRangeUser(0.,8.) predHist.Draw('hist') useSty.drawCMS() useSty.drawEnPu(lumi='35.9 fb^{-1}') canv.Print('recoPredJetHist.pdf') rightHist.GetYaxis().SetRangeUser(0.,1.) rightHist.Draw('hist') useSty.drawCMS() useSty.drawEnPu(lumi='35.9 fb^{-1}') canv.Print('recoEfficiencyJetHist.pdf') #setup 2D hists canv = useSty.setCanvas() truthHist = r.TH1F('truthHist','truthHist',nClasses,-0.5,nClasses-0.5)
else: wrongHist.Fill(true, w) firstBinVal = -1. for iBin in range(1, truthHist.GetNbinsX() + 1): if iBin == 1: firstBinVal = truthHist.GetBinContent(iBin) ratio = float(truthHist.GetBinContent(iBin)) / firstBinVal print 'ratio for bin %g is %1.7f' % (iBin, ratio) wrongHist.Add(rightHist) rightHist.Divide(wrongHist) effHist = r.TH1F r.gStyle.SetOptStat(0) truthHist.GetYaxis().SetRangeUser(0., 8.) truthHist.Draw('hist') useSty.drawCMS() useSty.drawEnPu(lumi='%.1f fb^{-1}' % opts.intLumi) canv.Print('%s/truthJetHist%s.pdf' % (plotDir, paramExt)) canv.Print('%s/truthJetHist%s.png' % (plotDir, paramExt)) predHist.GetYaxis().SetRangeUser(0., 8.) predHist.Draw('hist') useSty.drawCMS() useSty.drawEnPu(lumi='%.1f fb^{-1}' % opts.intLumi) canv.Print('%s/recoPredJetHist%s.pdf' % (plotDir, paramExt)) canv.Print('%s/recoPredJetHist%s.png' % (plotDir, paramExt)) rightHist.GetYaxis().SetRangeUser(0., 1.) rightHist.Draw('hist') useSty.drawCMS() useSty.drawEnPu(lumi='%.1f fb^{-1}' % opts.intLumi) canv.Print('%s/recoEfficiencyJetHist%s.pdf' % (plotDir, paramExt)) canv.Print('%s/recoEfficiencyJetHist%s.png' % (plotDir, paramExt))
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))