def doPlotCutflowNoL1(filename = 'L1MuonHistogram.root'): if(DEBUG): print 'Opening file:',filename file = TFile.Open(filename) if(file == None): print 'Error opening file:',filename histoNames = [ 'hoMuonAnalyzer/count/NoSingleMu_Count', 'hoMuonAnalyzer/count/NoSingleMuInGa_Count', 'hoMuonAnalyzer/count/NoSingleMuInGa5x5_Count', 'hoMuonAnalyzer/count/NoSingleMuInGa3x3_Count', 'hoMuonAnalyzer/count/NoSingleMuInGaCentral_Count', 'hoMuonAnalyzer/count/Events_Count' ] histograms = [] yValues = [] for s in histoNames: histograms.append(file.Get(s)) yValues.append(histograms[-1].GetBinContent(2)) nEvents = histograms[-1].GetEntries() xLabels = [ 'No Single #mu trigger', 'TDMI in GA', 'HO > 0.2 GeV in 5x5', 'HO > 0.2 GeV in 3x3', 'HO > 0.2 GeV in Central' ] c = TCanvas('eventCountCanvas','PostLS1 Single #mu gun',1200,1200) hist = TH1D("eventCount","PostLS1 Single #mu gun",len(xLabels)-1,0,len(xLabels)) paveText = TPaveText(0.51,0.75,0.9,0.9,'NDC') paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[0],yValues[0],yValues[0]/nEvents*100,calcSigma(yValues[0], nEvents)*100)) paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[2],yValues[2],yValues[2]/yValues[1]*100,calcSigma(yValues[2], yValues[1])*100)) paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[4],yValues[4],yValues[4]/yValues[1]*100,calcSigma(yValues[4], yValues[1])*100)) paveText.SetBorderSize(1) print yValues[1] norm = yValues[1] for i,v in enumerate(xLabels): if(i == 0): continue hist.SetBinContent(i,yValues[i]/norm) hist.GetXaxis().SetBinLabel(i,str(v)) hist.SetStats(0) hist.SetLineColor(PlotStyle.colorRwthDarkBlue) hist.GetYaxis().SetTitle('#') # hist.GetYaxis().SetRangeUser(0.5,1.1) hist.SetLabelFont(62) hist.SetTitleFont(62) hist.SetMinimum(0) print yValues hist.Draw("") paveText.Draw() label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() c.Update() c.SaveAs("plots/cutflow/cutflowTdmiNoTrg.png") c.SaveAs("plots/cutflow/cutflowTdmiNoTrg.pdf") c.SaveAs("plots/cutflow/cutflowTdmiNoTrg.root") return c,hist
def doPlotCutflow(filename='L1MuonHistogram.root'): PlotStyle.setPlotStyle() if(DEBUG): print 'Opening file:',filename file = TFile.Open(filename) if(file == None): print 'Error opening file:',filename #Total event count tagEvents = 'hoMuonAnalyzer/count/Events_Count' tagL1Muons = 'hoMuonAnalyzer/count/L1MuonPresent_Count' #Counters without energy threshold tagHo1 = 'hoMuonAnalyzer/count/L1MuonPresentHoMatch_Count' tagHo2 = 'hoMuonAnalyzer/count/L1MuonPresentHoMatchInAcc_Count' tagHo3 = 'hoMuonAnalyzer/count/L1MuonPresentHoMatchInAccNotDead_Count' tagHo4 = 'hoMuonAnalyzer/count/L1MuonPresentHoMatchInAccThr_Count' #Counters with energy threshold tagThr1 = 'hoMuonAnalyzer/count/L1MuonAboveThr_Count' tagThr2 = 'hoMuonAnalyzer/count/L1MuonAboveThrInAcc_Count' tagThr3 = 'hoMuonAnalyzer/count/L1MuonAboveThrInAccNotDead_Count' histEvents = file.Get(tagEvents) histL1Muons = file.Get(tagL1Muons) histHo1 = file.Get(tagHo1) histHo2 = file.Get(tagHo2) histHo3 = file.Get(tagHo3) histHo4 = file.Get(tagHo4) histThr1 = file.Get(tagThr1) histThr2 = file.Get(tagThr2) histThr3 = file.Get(tagThr3) yValues = [ histEvents.GetBinContent(2), histL1Muons.GetBinContent(2), histHo1.GetBinContent(2), # histHo2.GetBinContent(2), # histHo3.GetBinContent(2), histThr1.GetBinContent(2), histThr2.GetBinContent(2), histThr3.GetBinContent(2) ] xLabels = [ 'Event count', 'L1Muon objects', 'HO match (No Thr.)', 'HO match > 0.2 GeV', # '+ HO acceptance' ] norm = yValues[0] for i,v in enumerate(yValues): yValues[i] = v/norm c = TCanvas('cutflowCanvas','PostLS1 Single #mu gun',1200,1200) hist = TH1D("cutflow","PostLS1 Single #mu gun",len(xLabels),0,len(xLabels)) for i,v in enumerate(xLabels): hist.SetBinContent(i+1,yValues[i]) hist.GetXaxis().SetBinLabel(i+1,str(v)) hist.SetStats(0) hist.GetYaxis().SetTitle('rel. Fraction') hist.GetYaxis().SetRangeUser(0.7,1.1) hist.SetLineColor(PlotStyle.colorRwthDarkBlue) hist.SetLabelFont(62) hist.SetTitleFont(62) hist.Draw("") histTrgCount = file.Get('hoMuonAnalyzer/count/L1_SingleMuOpen_Count') hist2 = TH1D("l1TrgCount","PostLS1 Single #mu gun",len(xLabels),0,len(xLabels)) hist2.SetBinContent(1,histTrgCount.GetBinContent(2)/norm) hist2.SetFillStyle(3002) hist2.SetFillColor(PlotStyle.colorRwthMagenta) hist2.SetLineColor(PlotStyle.colorRwthMagenta) hist2.Draw("same") paveText = TPaveText(0.51,0.75,0.9,0.9,'NDC') paveText.AddText('%s: %.2f%% #pm %.2f%%' % (xLabels[1],yValues[1]*100,calcSigma(yValues[1]*norm,norm)*100)) paveText.AddText('%s: %.2f%% #pm %.2f%%' % (xLabels[2],yValues[2]*100,calcSigma(yValues[2]*norm,norm)*100)) paveText.AddText('%s: %.2f%% #pm %.2f%%' % (xLabels[3],yValues[3]*100,calcSigma(yValues[3]*norm,norm)*100)) paveText.SetBorderSize(1) paveText.Draw() legend = TLegend(0.1,0.8,0.45,0.9) legend.AddEntry(hist2,"Fraction with L1 Single #mu Trg.","f") legend.Draw() label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() c.Update() c.SaveAs("plots/cutflow/cutflowL1.png") c.SaveAs("plots/cutflow/cutflowL1.pdf") c.SaveAs("plots/cutflow/cutflowL1.root") nTotal = histEvents.GetBinContent(2) nL1 = histL1Muons.GetBinContent(2) nL1AndHo = histHo1.GetBinContent(2) nL1AndHoAcc = histHo2.GetBinContent(2) nL1AndHoAccNotDead = histHo3.GetBinContent(2) nL1AndHoAccThr = histHo4.GetBinContent(2) nL1AndHoThr = histThr1.GetBinContent(2) nL1AndHoThrAcc = histThr2.GetBinContent(2) nL1AndHoThrAccNotDead = histThr3.GetBinContent(2) print '%s' % (80*'#') print '%s' % (80*'#') print '%25s%d' % ('nEvents:\t',nTotal) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('nL1:\t',nL1,nL1/nTotal*100,calcSigma(nL1, nTotal)*100) print '%s' % (80*'#') print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHo:\t',nL1AndHo,nL1AndHo/nL1*100,calcSigma(nL1AndHo, nL1)*100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoAcc:\t',nL1AndHoAcc,nL1AndHoAcc/nL1*100,calcSigma(nL1AndHoAcc, nL1)*100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoAccNotDead:\t',nL1AndHoAccNotDead,nL1AndHoAccNotDead/nL1*100,calcSigma(nL1AndHoAccNotDead, nL1)*100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoAccThr:\t',nL1AndHoAccThr,nL1AndHoAccThr/nL1*100,calcSigma(nL1AndHoAccThr, nL1)*100) print '%s' % (80*'#') print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoThr:\t',nL1AndHoThr,nL1AndHoThr/nL1*100,calcSigma(nL1AndHoThr, nL1)*100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoThrAcc:\t',nL1AndHoThrAcc,nL1AndHoThrAcc/nL1*100,calcSigma(nL1AndHoThrAcc,nL1)*100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoThrAccNotDead:\t',nL1AndHoThrAccNotDead,nL1AndHoThrAccNotDead/nL1*100,calcSigma(nL1AndHoThrAccNotDead, nL1)*100) print '%s' % (80*'#') print '%s' % (80*'#') return c
nTotal = hist.Integral() nCentral = hist.GetBinContent(hist.FindBin(0,0)) n3x3 = 0 n5x5 = 0 for i in range(-1,2): for j in range(-1,2): n3x3 += hist.GetBinContent(hist.FindBin(0.087*i,0.087*j)) print hist.FindBin(0.087*i,0.087*j),0.087*i,0.087*j for i in range(-2,3): for j in range(-2,3): n5x5 += hist.GetBinContent(hist.FindBin(0.087*i,0.087*j)) print '#'*80 print 'No Single Mu Trigger, TDMI Matched to HO > 0.2 GeV' print 'Total Events:', nTotal print 'Central bin\t%d ==> %.2f%% +/- %.2f%%' % (nCentral,nCentral/nTotal*100,calcSigma(nCentral, nTotal)*100) print '3 x 3 bins\t%d ==> %.2f%% +/- %.2f%%' % (n3x3,n3x3/nTotal*100,calcSigma(n3x3, nTotal)*100) print '5 x 5 bins\t%d ==> %.2f%% +/- %.2f%%' % (n5x5,n5x5/nTotal*100,calcSigma(n5x5, nTotal)*100) print '#'*80 #doPlotCutflow(filename) #doPlotDeltaEtaDeltaPhi(filename) # doPlotDeltaEtaDeltaPhiEnergy(filename) #doPlotCutflowNoL1(filename) #doPlotGenPt(filename) res = doPlotEtaPtOfFailingMatches() #res2 = doPlotEtaPtOfSuccessfulMatches() res3 = doPlotPhiPtOfFailingMatches() raw_input('--> Enter')
def doPlotCutflow(filename='L1MuonHistogram.root'): PlotStyle.setPlotStyle() if (DEBUG): print 'Opening file:', filename file = TFile.Open(filename) if (file == None): print 'Error opening file:', filename #Total event count tagEvents = 'hoMuonAnalyzer/count/Events_Count' tagL1Muons = 'hoMuonAnalyzer/count/L1MuonPresent_Count' #Counters without energy threshold tagHo1 = 'hoMuonAnalyzer/count/L1MuonPresentHoMatch_Count' tagHo2 = 'hoMuonAnalyzer/count/L1MuonPresentHoMatchInAcc_Count' tagHo3 = 'hoMuonAnalyzer/count/L1MuonPresentHoMatchInAccNotDead_Count' tagHo4 = 'hoMuonAnalyzer/count/L1MuonPresentHoMatchInAccThr_Count' #Counters with energy threshold tagThr1 = 'hoMuonAnalyzer/count/L1MuonAboveThr_Count' tagThr2 = 'hoMuonAnalyzer/count/L1MuonAboveThrInAcc_Count' tagThr3 = 'hoMuonAnalyzer/count/L1MuonAboveThrInAccNotDead_Count' histEvents = file.Get(tagEvents) histL1Muons = file.Get(tagL1Muons) histHo1 = file.Get(tagHo1) histHo2 = file.Get(tagHo2) histHo3 = file.Get(tagHo3) histHo4 = file.Get(tagHo4) histThr1 = file.Get(tagThr1) histThr2 = file.Get(tagThr2) histThr3 = file.Get(tagThr3) yValues = [ histEvents.GetBinContent(2), histL1Muons.GetBinContent(2), histHo1.GetBinContent(2), # histHo2.GetBinContent(2), # histHo3.GetBinContent(2), histThr1.GetBinContent(2), histThr2.GetBinContent(2), histThr3.GetBinContent(2) ] xLabels = [ 'Event count', 'L1Muon objects', 'HO match (No Thr.)', 'HO match > 0.2 GeV', # '+ HO acceptance' ] norm = yValues[0] for i, v in enumerate(yValues): yValues[i] = v / norm c = TCanvas('cutflowCanvas', 'PostLS1 Single #mu gun', 1200, 1200) hist = TH1D("cutflow", "PostLS1 Single #mu gun", len(xLabels), 0, len(xLabels)) for i, v in enumerate(xLabels): hist.SetBinContent(i + 1, yValues[i]) hist.GetXaxis().SetBinLabel(i + 1, str(v)) hist.SetStats(0) hist.GetYaxis().SetTitle('rel. Fraction') hist.GetYaxis().SetRangeUser(0.7, 1.1) hist.SetLineColor(PlotStyle.colorRwthDarkBlue) hist.SetLabelFont(62) hist.SetTitleFont(62) hist.Draw("") histTrgCount = file.Get('hoMuonAnalyzer/count/L1_SingleMuOpen_Count') hist2 = TH1D("l1TrgCount", "PostLS1 Single #mu gun", len(xLabels), 0, len(xLabels)) hist2.SetBinContent(1, histTrgCount.GetBinContent(2) / norm) hist2.SetFillStyle(3002) hist2.SetFillColor(PlotStyle.colorRwthMagenta) hist2.SetLineColor(PlotStyle.colorRwthMagenta) hist2.Draw("same") paveText = TPaveText(0.51, 0.75, 0.9, 0.9, 'NDC') paveText.AddText('%s: %.2f%% #pm %.2f%%' % (xLabels[1], yValues[1] * 100, calcSigma(yValues[1] * norm, norm) * 100)) paveText.AddText('%s: %.2f%% #pm %.2f%%' % (xLabels[2], yValues[2] * 100, calcSigma(yValues[2] * norm, norm) * 100)) paveText.AddText('%s: %.2f%% #pm %.2f%%' % (xLabels[3], yValues[3] * 100, calcSigma(yValues[3] * norm, norm) * 100)) paveText.SetBorderSize(1) paveText.Draw() legend = TLegend(0.1, 0.8, 0.45, 0.9) legend.AddEntry(hist2, "Fraction with L1 Single #mu Trg.", "f") legend.Draw() label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() c.Update() c.SaveAs("plots/cutflow/cutflowL1.png") c.SaveAs("plots/cutflow/cutflowL1.pdf") c.SaveAs("plots/cutflow/cutflowL1.root") nTotal = histEvents.GetBinContent(2) nL1 = histL1Muons.GetBinContent(2) nL1AndHo = histHo1.GetBinContent(2) nL1AndHoAcc = histHo2.GetBinContent(2) nL1AndHoAccNotDead = histHo3.GetBinContent(2) nL1AndHoAccThr = histHo4.GetBinContent(2) nL1AndHoThr = histThr1.GetBinContent(2) nL1AndHoThrAcc = histThr2.GetBinContent(2) nL1AndHoThrAccNotDead = histThr3.GetBinContent(2) print '%s' % (80 * '#') print '%s' % (80 * '#') print '%25s%d' % ('nEvents:\t', nTotal) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('nL1:\t', nL1, nL1 / nTotal * 100, calcSigma(nL1, nTotal) * 100) print '%s' % (80 * '#') print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHo:\t', nL1AndHo, nL1AndHo / nL1 * 100, calcSigma(nL1AndHo, nL1) * 100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoAcc:\t', nL1AndHoAcc, nL1AndHoAcc / nL1 * 100, calcSigma(nL1AndHoAcc, nL1) * 100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ( 'L1AndHoAccNotDead:\t', nL1AndHoAccNotDead, nL1AndHoAccNotDead / nL1 * 100, calcSigma(nL1AndHoAccNotDead, nL1) * 100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ( 'L1AndHoAccThr:\t', nL1AndHoAccThr, nL1AndHoAccThr / nL1 * 100, calcSigma(nL1AndHoAccThr, nL1) * 100) print '%s' % (80 * '#') print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoThr:\t', nL1AndHoThr, nL1AndHoThr / nL1 * 100, calcSigma(nL1AndHoThr, nL1) * 100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ( 'L1AndHoThrAcc:\t', nL1AndHoThrAcc, nL1AndHoThrAcc / nL1 * 100, calcSigma(nL1AndHoThrAcc, nL1) * 100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ( 'L1AndHoThrAccNotDead:\t', nL1AndHoThrAccNotDead, nL1AndHoThrAccNotDead / nL1 * 100, calcSigma(nL1AndHoThrAccNotDead, nL1) * 100) print '%s' % (80 * '#') print '%s' % (80 * '#') return c
def doPlotCutflowNoL1(filename='L1MuonHistogram.root'): if (DEBUG): print 'Opening file:', filename file = TFile.Open(filename) if (file == None): print 'Error opening file:', filename histoNames = [ 'hoMuonAnalyzer/count/NoSingleMu_Count', 'hoMuonAnalyzer/count/NoSingleMuInGa_Count', 'hoMuonAnalyzer/count/NoSingleMuInGa5x5_Count', 'hoMuonAnalyzer/count/NoSingleMuInGa3x3_Count', 'hoMuonAnalyzer/count/NoSingleMuInGaCentral_Count', 'hoMuonAnalyzer/count/Events_Count' ] histograms = [] yValues = [] for s in histoNames: histograms.append(file.Get(s)) yValues.append(histograms[-1].GetBinContent(2)) nEvents = histograms[-1].GetEntries() xLabels = [ 'No Single #mu trigger', 'TDMI in GA', 'HO > 0.2 GeV in 5x5', 'HO > 0.2 GeV in 3x3', 'HO > 0.2 GeV in Central' ] c = TCanvas('eventCountCanvas', 'PostLS1 Single #mu gun', 1200, 1200) hist = TH1D("eventCount", "PostLS1 Single #mu gun", len(xLabels) - 1, 0, len(xLabels)) paveText = TPaveText(0.51, 0.75, 0.9, 0.9, 'NDC') paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[0], yValues[0], yValues[0] / nEvents * 100, calcSigma(yValues[0], nEvents) * 100)) paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[2], yValues[2], yValues[2] / yValues[1] * 100, calcSigma(yValues[2], yValues[1]) * 100)) paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[4], yValues[4], yValues[4] / yValues[1] * 100, calcSigma(yValues[4], yValues[1]) * 100)) paveText.SetBorderSize(1) print yValues[1] norm = yValues[1] for i, v in enumerate(xLabels): if (i == 0): continue hist.SetBinContent(i, yValues[i] / norm) hist.GetXaxis().SetBinLabel(i, str(v)) hist.SetStats(0) hist.SetLineColor(PlotStyle.colorRwthDarkBlue) hist.GetYaxis().SetTitle('#') # hist.GetYaxis().SetRangeUser(0.5,1.1) hist.SetLabelFont(62) hist.SetTitleFont(62) hist.SetMinimum(0) hist.Draw("") paveText.Draw() label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() c.Update() c.SaveAs("plots/cutflow/cutflowTdmiNoTrg.png") c.SaveAs("plots/cutflow/cutflowTdmiNoTrg.pdf") c.SaveAs("plots/cutflow/cutflowTdmiNoTrg.root") return c, hist
n3x3 = 0 n5x5 = 0 for i in range(-1, 2): for j in range(-1, 2): n3x3 += hist.GetBinContent(hist.FindBin(0.087 * i, 0.087 * j)) # print hist.FindBin(0.087*i,0.087*j),0.087*i,0.087*j for i in range(-2, 3): for j in range(-2, 3): n5x5 += hist.GetBinContent(hist.FindBin(0.087 * i, 0.087 * j)) print '#' * 80 print 'No Single Mu Trigger, TDMI Matched to HO > 0.2 GeV' print 'Total Events:', nTotal print 'Central bin\t%d ==> %.2f%% +/- %.2f%%' % ( nCentral, nCentral / nTotal * 100, calcSigma(nCentral, nTotal) * 100) print '3 x 3 bins\t%d ==> %.2f%% +/- %.2f%%' % (n3x3, n3x3 / nTotal * 100, calcSigma(n3x3, nTotal) * 100) print '5 x 5 bins\t%d ==> %.2f%% +/- %.2f%%' % (n5x5, n5x5 / nTotal * 100, calcSigma(n5x5, nTotal) * 100) print '#' * 80 #doPlotCutflow(filename) res4 = doPlotDeltaEtaDeltaPhi(filename) # doPlotDeltaEtaDeltaPhiEnergy(filename) #doPlotCutflowNoL1(filename) #doPlotGenPt(filename) res = doPlotEtaPtOfFailingMatches() res2 = doPlotEtaPtOfSuccessfulMatches() res3 = doPlotPhiPtOfFailingMatches() raw_input('--> Enter')
hist.SetLineColor(PlotStyle.colorRwthDarkBlue) hist.SetLabelFont(62) hist.SetTitleFont(62) hist.Draw("") histTrgCount = file.Get('hoMuonAnalyzer/count/L1_SingleMu3_Count') hist2 = TH1D("l1TrgCount","PostLS1 Single #mu gun using L1",len(xLabels),0,len(xLabels)) hist2.SetBinContent(1,histTrgCount.GetBinContent(2)/norm) hist2.SetFillStyle(3002) hist2.SetFillColor(PlotStyle.colorRwthMagenta) hist2.SetLineColor(PlotStyle.colorRwthMagenta) hist2.Draw("same") paveText = TPaveText(0.51,0.1,0.9,0.3,'NDC') paveText.AddText('%s: %.2f%% #pm %.2f%%' % (xLabels[1],yValues[1]*100,calcSigma(yValues[1]*norm,norm)*100)) paveText.AddText('%s: %.2f%% #pm %.2f%%' % (xLabels[2],yValues[2]*100,calcSigma(yValues[2]*norm,norm)*100)) paveText.AddText('%s: %.2f%% #pm %.2f%%' % (xLabels[3],yValues[3]*100,calcSigma(yValues[3]*norm,norm)*100)) #paveText.AddText('%s: %.2f%% #pm %.2f%%' % (xLabels[4],yValues[4]*100,calcSigma(yValues[4]*norm,norm)*100)) paveText.SetBorderSize(1) paveText.Draw() paveText2 = TPaveText(0.51,0.3,0.9,0.4,'NDC') paveText2.AddText('Total Events: %d' % (hEvents.GetBinContent(2))) paveText2.AddText('Events with L1 in GA: %d' % (hL1InGA.GetBinContent(2))) paveText2.SetBorderSize(1) paveText2.Draw() legend = TLegend(0.51,0.85,0.9,0.9) legend.AddEntry(hist2,"Fraction with L1 Single #mu Trg.","f") legend.Draw()