def plotPtCorrelation(folder,filename = 'L1MuonHistogram.root'): if(DEBUG): print prefix + 'was called' if(folder == None): print prefix + 'Error! Folder as first argument needed.' return if( not os.path.exists('plots')): os.mkdir('plots') if( not os.path.exists('plots/' + folder)): os.mkdir('plots/' + folder) fullname = folder + '/' + filename if( not os.path.exists(fullname)): print 'Error! File ' + fullname + ' does not exist!' return print 'Opening file:',fullname file = TFile.Open(fullname) #Set plot style PlotStyle.setPlotStyle() l1Muon = file.Get("hoMuonAnalyzer/L1Muon_PtCorrelation") canv = TCanvas("ptCorrelationCanvas",'ptCorrelationCanvas',1200,1200) # frame = TH2D('frame','L1 Efficiency',1,5,150,1,0,1.1) # frame.SetStats(0) # frame.GetXaxis().SetTitle('p_{T} / GeV') # frame.GetYaxis().SetTitle('Efficiency') # frame.Draw() l1Muon.SetMarkerStyle(20) l1Muon.SetMarkerColor(ROOT.kBlack) l1Muon.SetLineColor(ROOT.kBlack) l1Muon.GetXaxis().SetRangeUser(97,103) l1Muon.GetXaxis().SetTitle('p_{T} Gen / GeV') l1Muon.GetYaxis().SetTitle('p_{T} L1Muon / GeV') l1Muon.GetYaxis().SetRangeUser(0,150) l1Muon.Draw('colz') canv.Update() pal = l1Muon.GetListOfFunctions().FindObject("palette") pal.SetX2NDC(0.92) canv.SaveAs("plots/" + folder + "/ptCorrelation.png") canv.SaveAs("plots/" + folder + "/ptCorrelation.pdf") f = TFile.Open("plots/" + folder + "/Efficiency.root","RECREATE") canv.Write() f.Close() return canv
def plotPtCorrelation(folder, filename='L1MuonHistogram.root'): if (DEBUG): print prefix + 'was called' if (folder == None): print prefix + 'Error! Folder as first argument needed.' return if (not os.path.exists('plots')): os.mkdir('plots') if (not os.path.exists('plots/' + folder)): os.mkdir('plots/' + folder) fullname = folder + '/' + filename if (not os.path.exists(fullname)): print 'Error! File ' + fullname + ' does not exist!' return print 'Opening file:', fullname file = TFile.Open(fullname) #Set plot style PlotStyle.setPlotStyle() l1Muon = file.Get("hoMuonAnalyzer/L1Muon_PtCorrelation") canv = TCanvas("ptCorrelationCanvas", 'ptCorrelationCanvas', 1200, 1200) # frame = TH2D('frame','L1 Efficiency',1,5,150,1,0,1.1) # frame.SetStats(0) # frame.GetXaxis().SetTitle('p_{T} / GeV') # frame.GetYaxis().SetTitle('Efficiency') # frame.Draw() l1Muon.SetMarkerStyle(20) l1Muon.SetMarkerColor(ROOT.kBlack) l1Muon.SetLineColor(ROOT.kBlack) l1Muon.GetXaxis().SetRangeUser(97, 103) l1Muon.GetXaxis().SetTitle('p_{T} Gen / GeV') l1Muon.GetYaxis().SetTitle('p_{T} L1Muon / GeV') l1Muon.GetYaxis().SetRangeUser(0, 150) l1Muon.Draw('colz') canv.Update() pal = l1Muon.GetListOfFunctions().FindObject("palette") pal.SetX2NDC(0.92) canv.SaveAs("plots/" + folder + "/ptCorrelation.png") canv.SaveAs("plots/" + folder + "/ptCorrelation.pdf") f = TFile.Open("plots/" + folder + "/Efficiency.root", "RECREATE") canv.Write() f.Close() return canv
def plotDeltaEtaDeltaPhiEnergyProjection(folder,sourceHistogram = 'NoDoubleMuAboveThr_DeltaEtaDeltaPhiEnergy', sourceFile = 'L1MuonHistogram.root'): if(DEBUG): print prefix + 'was called' if(folder == None): print prefix + 'Error! Filename as first argument needed.' return if( not os.path.exists('plots')): os.mkdir('plots') if( not os.path.exists('plots/' + folder)): os.mkdir('plots/' + folder) filename = folder + '/' + sourceFile if( not os.path.exists(filename)): print 'Error! File ' + filename + ' does not exist!' return print prefix + 'Opening file:',filename file = TFile.Open(filename) PlotStyle.setPlotStyle() sourceHisto = file.Get("hoMuonAnalyzer/etaPhi/" + sourceHistogram) histo = sourceHisto.Project3DProfile('yx') canv = TCanvas("canvasDeltaEtaDeltaPhiEnergy",'canvasDeltaEtaDeltaPhiEnergy',1200,1200) histo.GetXaxis().SetRangeUser(-.45,.45) histo.GetXaxis().SetTitle("#Delta#eta") histo.GetYaxis().SetRangeUser(-.45,.45) histo.GetYaxis().SetTitle("#Delta#phi") histo.GetZaxis().SetTitle(sourceHisto.GetZaxis().GetTitle()) histo.Draw("colz") boxList = drawHoBoxes(canv) canv.Update() pal = histo.GetListOfFunctions().FindObject("palette") pal.SetX2NDC(0.92) stats = histo.GetListOfFunctions().FindObject("stats") stats.SetX1NDC(.1) stats.SetX2NDC(.2) stats.SetY1NDC(.1) stats.SetY2NDC(.25) legend = TLegend(0.7,0.8,0.9,0.9) legend.AddEntry(boxList[0],"HO tile dimensions","le") legend.Draw() canv.Update(); canv.SaveAs("plots/" + folder + "/" + sourceHistogram + ".png") canv.SaveAs("plots/" + folder + "/" + sourceHistogram + ".pdf") f = TFile.Open("plots/" + folder + "/" + sourceHistogram + ".root","RECREATE") canv.Write() f.Close() return histo
def plotMultiplicity(folder): if(folder == None): print 'Error! Filename as first argument needed.' return if( not os.path.exists('plots')): os.mkdir('plots') if( not os.path.exists('plots/' + folder)): os.mkdir('plots/' + folder) filename = folder + '/L1MuonHistogram.root' if( not os.path.exists(filename)): print 'Error! File ' + filename + ' does not exist!' return print 'Opening file:',filename file = TFile.Open(filename) #Set plot style PlotStyle.setPlotStyle() L1Muon = file.Get('hoMuonAnalyzer/L1MuonPresent_Multiplicity') ho = file.Get("hoMuonAnalyzer/horecoAboveThreshold_Multiplicity") canv = TCanvas("multiplicityCanvas",'Multiplicity canvas',1200,1200) canv.SetLogy() ho.SetStats(0) ho.SetTitle('Multiplicities') ho.GetXaxis().SetTitle('Multiplicity') ho.GetYaxis().SetTitle('N') ho.GetXaxis().SetRangeUser(-2,6) ho.SetLineColor(ROOT.kBlack) L1Muon.SetLineColor(ROOT.kRed) ho.SetLineWidth(3) L1Muon.SetLineWidth(3) ho.Draw() L1Muon.Draw('same') legend = TLegend(0.6,0.75,0.9,0.9) legend.AddEntry(ho,'HO Rec hits > 0.2 GeV','l') legend.AddEntry(L1Muon,'L1 Muons','l') legend.Draw() canv.SaveAs("plots/" + folder + "/Multiplicity.png") canv.SaveAs("plots/" + folder + "/Multiplicity.pdf") f = TFile.Open("plots/" + folder + "/Multiplicity.root","RECREATE") canv.Write() f.Close()
def plotMultiplicity(folder): if (folder == None): print 'Error! Filename as first argument needed.' return if (not os.path.exists('plots')): os.mkdir('plots') if (not os.path.exists('plots/' + folder)): os.mkdir('plots/' + folder) filename = folder + '/L1MuonHistogram.root' if (not os.path.exists(filename)): print 'Error! File ' + filename + ' does not exist!' return print 'Opening file:', filename file = TFile.Open(filename) #Set plot style PlotStyle.setPlotStyle() L1Muon = file.Get('hoMuonAnalyzer/L1MuonPresent_Multiplicity') ho = file.Get("hoMuonAnalyzer/horecoAboveThreshold_Multiplicity") canv = TCanvas("multiplicityCanvas", 'Multiplicity canvas', 1200, 1200) canv.SetLogy() ho.SetStats(0) ho.SetTitle('Multiplicities') ho.GetXaxis().SetTitle('Multiplicity') ho.GetYaxis().SetTitle('N') ho.GetXaxis().SetRangeUser(-2, 6) ho.SetLineColor(ROOT.kBlack) L1Muon.SetLineColor(ROOT.kRed) ho.SetLineWidth(3) L1Muon.SetLineWidth(3) ho.Draw() L1Muon.Draw('same') legend = TLegend(0.6, 0.75, 0.9, 0.9) legend.AddEntry(ho, 'HO Rec hits > 0.2 GeV', 'l') legend.AddEntry(L1Muon, 'L1 Muons', 'l') legend.Draw() canv.SaveAs("plots/" + folder + "/Multiplicity.png") canv.SaveAs("plots/" + folder + "/Multiplicity.pdf") f = TFile.Open("plots/" + folder + "/Multiplicity.root", "RECREATE") canv.Write() f.Close()
def doPlotGenPt(filename): PlotStyle.setPlotStyle() if(DEBUG): print 'Opening file:',filename file = TFile.Open(filename) if(file == None): print 'Error opening file:',filename c = TCanvas('genPtCanvas','Gen Pt no Single #mu trg',1200,1200) c.cd().SetLeftMargin(0.15) genPtHist = file.Get("hoMuonAnalyzer/NoSingleMu_Pt") genPtHist.SetLineColor(PlotStyle.colorRwthDarkBlue) genPtHist.SetLineWidth(3) genPtHist.Rebin(50) genPtHist.Sumw2() genPtHist.Scale(1/genPtHist.Integral()) genPtHist.GetXaxis().SetRangeUser(0,200) genPtHist.GetYaxis().SetTitle('normalized entries / 5 GeV') genPtHist.GetYaxis().SetTitleOffset(2) genPtHist.GetXaxis().SetTitle('p_{T} Gen / GeV') label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() genPtHist.Draw("ehist") c.Update() stats = genPtHist.GetListOfFunctions().FindObject("stats") stats.SetOptStat(10) stats.SetX1NDC(.7) stats.SetX2NDC(.9) stats.SetY1NDC(.85) stats.SetY2NDC(.9) label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() c.SaveAs('plots/genPtNoSingleMuTrg.png') c.SaveAs('plots/genPtNoSingleMuTrg.pdf') return
def doPlotGenPt(filename): PlotStyle.setPlotStyle() if (DEBUG): print 'Opening file:', filename file = TFile.Open(filename) if (file == None): print 'Error opening file:', filename c = TCanvas('genPtCanvas', 'Gen Pt no Single #mu trg', 1200, 1200) c.cd().SetLeftMargin(0.15) genPtHist = file.Get("hoMuonAnalyzer/NoSingleMu_Pt") genPtHist.SetLineColor(PlotStyle.colorRwthDarkBlue) genPtHist.SetLineWidth(3) genPtHist.Rebin(50) genPtHist.Sumw2() genPtHist.Scale(1 / genPtHist.Integral()) genPtHist.GetXaxis().SetRangeUser(0, 200) genPtHist.GetYaxis().SetTitle('normalized entries / 5 GeV') genPtHist.GetYaxis().SetTitleOffset(2) genPtHist.GetXaxis().SetTitle('p_{T} Gen / GeV') label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() genPtHist.Draw("ehist") c.Update() stats = genPtHist.GetListOfFunctions().FindObject("stats") stats.SetOptStat(10) stats.SetX1NDC(.7) stats.SetX2NDC(.9) stats.SetY1NDC(.85) stats.SetY2NDC(.9) label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() c.SaveAs('plots/genPtNoSingleMuTrg.png') c.SaveAs('plots/genPtNoSingleMuTrg.pdf') return
#!/usr/bin/python from ROOT import ROOT,gROOT,gStyle,TCanvas,TFile,TH1D,TH2D,TLegend,THStack,TPaveText,TBox import sys import os import PlotStyle import numpy as np DEBUG = 1 prefix = '[plotL1Phi] ' PlotStyle.setPlotStyle() gStyle.SetPalette(1) def plotPhi(folder): if(DEBUG): print prefix + 'was called' if(folder == None): print prefix + 'Error! Filename as first argument needed.' return if( not os.path.exists('plots')): os.mkdir('plots') if( not os.path.exists('plots/' + folder)): os.mkdir('plots/' + folder) filename = folder + '/L1MuonHistogram.root' if( not os.path.exists(filename)): print 'Error! File ' + filename + ' does not exist!'
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 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_SingleMu3_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() PlotStyle.labelCmsPrivateSimulation.Draw() c.Update() c.SaveAs("cutflow.png") c.SaveAs("cutflow.pdf") c.SaveAs("cutflow.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
import os, sys from math import sqrt sys.path.append(os.path.abspath("../../python")) from ROOT import TFile, TCanvas, TH1D, TLegend, TPaveText from plotEnergy import plotEnergyVsEtaPhi from plotDeltaEtaDeltaPhi import plotDeltaEtaDeltaPhiEnergyProjection, plotDeltaEtaDeltaPhi DEBUG = 1 import PlotStyle PlotStyle.setPlotStyle() def calcSigma(num, denom): return sqrt(num / (denom * denom) + num * num / (pow(denom, 3))) 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'
def plotDeltaEtaDeltaPhi(folder, sourceHistogram='L1MuonWithHoMatch_DeltaEtaDeltaPhi', sourceFile='L1MuonHistogram.root', storeSubdir='deltaEtaDeltaPhi'): if (DEBUG): print prefix + 'was called' if (folder == None): print prefix + 'Error! Filename as first argument needed.' return if (not os.path.exists('plots')): os.mkdir('plots') if (not os.path.exists('plots/' + storeSubdir)): os.mkdir('plots/' + storeSubdir) filename = folder + '/' + sourceFile if (not os.path.exists(filename)): print 'Error! File ' + filename + ' does not exist!' return print prefix + 'Opening file:', filename file = TFile.Open(filename) PlotStyle.setPlotStyle() h2dDeltaEtaDeltaPhi = file.Get("hoMuonAnalyzer/etaPhi/" + sourceHistogram) hEventCount = file.Get("hoMuonAnalyzer/count/Events_Count") hNoTrgCount = file.Get("hoMuonAnalyzer/count/NoSingleMu_Count") if (h2dDeltaEtaDeltaPhi == None): print 'Could not get histogram %s from file %s' % ( "hoMuonAnalyzer/etaPhi/" + sourceHistogram, filename) canv = TCanvas("canvasDeltaEtaDeltaPhi" + sourceHistogram, 'canvasDeltaEtaDeltaPhi', 1200, 1200) canv.SetLogz() h2dDeltaEtaDeltaPhi.GetXaxis().SetRangeUser(-.45, .45) h2dDeltaEtaDeltaPhi.GetXaxis().SetTitle("#Delta#eta") h2dDeltaEtaDeltaPhi.GetYaxis().SetRangeUser(-.45, .45) h2dDeltaEtaDeltaPhi.GetYaxis().SetTitle("#Delta#phi") h2dDeltaEtaDeltaPhi.GetZaxis().SetTitle("N") h2dDeltaEtaDeltaPhi.Draw("colz") boxList = drawHoBoxes(canv) canv.Update() pal = h2dDeltaEtaDeltaPhi.GetListOfFunctions().FindObject("palette") pal.SetX2NDC(0.92) stats = h2dDeltaEtaDeltaPhi.GetListOfFunctions().FindObject("stats") stats.SetX1NDC(.1) stats.SetX2NDC(.2) stats.SetY1NDC(.1) stats.SetY2NDC(.25) paveText = TPaveText(0.2, 0.1, 0.65, 0.2, 'NDC') paveText.AddText('Total Events: %d' % (hEventCount.GetBinContent(2))) paveText.AddText('Events with no Single #mu Trg: %d' % (hNoTrgCount.GetBinContent(2))) paveText.SetBorderSize(1) paveText.Draw() label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() legend = TLegend(0.7, 0.8, 0.9, 0.9) legend.AddEntry(boxList[0], "HO tile dimensions", "le") legend.Draw() canv.SaveAs("plots/" + storeSubdir + "/" + sourceHistogram + ".png") canv.SaveAs("plots/" + storeSubdir + "/" + sourceHistogram + ".pdf") canv.SaveAs("plots/" + storeSubdir + "/" + sourceHistogram + ".root") SetOwnership(h2dDeltaEtaDeltaPhi, False) return [ h2dDeltaEtaDeltaPhi, canv, legend, boxList, stats, pal, paveText, label ]
def plotDeltaEtaDeltaPhiEnergyProjection( folder, sourceHistogram='NoDoubleMuAboveThr_DeltaEtaDeltaPhiEnergy', sourceFile='L1MuonHistogram.root'): if (DEBUG): print prefix + 'was called' if (folder == None): print prefix + 'Error! Filename as first argument needed.' return if (not os.path.exists('plots')): os.mkdir('plots') if (not os.path.exists('plots/' + folder)): os.mkdir('plots/' + folder) filename = folder + '/' + sourceFile if (not os.path.exists(filename)): print 'Error! File ' + filename + ' does not exist!' return print prefix + 'Opening file:', filename file = TFile.Open(filename) PlotStyle.setPlotStyle() sourceHisto = file.Get("hoMuonAnalyzer/etaPhi/" + sourceHistogram) histo = sourceHisto.Project3DProfile('yx') canv = TCanvas("canvasDeltaEtaDeltaPhiEnergy", 'canvasDeltaEtaDeltaPhiEnergy', 1200, 1200) histo.GetXaxis().SetRangeUser(-.45, .45) histo.GetXaxis().SetTitle("#Delta#eta") histo.GetYaxis().SetRangeUser(-.45, .45) histo.GetYaxis().SetTitle("#Delta#phi") histo.GetZaxis().SetTitle(sourceHisto.GetZaxis().GetTitle()) histo.Draw("colz") boxList = drawHoBoxes(canv) canv.Update() pal = histo.GetListOfFunctions().FindObject("palette") pal.SetX2NDC(0.92) stats = histo.GetListOfFunctions().FindObject("stats") stats.SetX1NDC(.1) stats.SetX2NDC(.2) stats.SetY1NDC(.1) stats.SetY2NDC(.25) legend = TLegend(0.7, 0.8, 0.9, 0.9) legend.AddEntry(boxList[0], "HO tile dimensions", "le") legend.Draw() canv.Update() canv.SaveAs("plots/" + folder + "/" + sourceHistogram + ".png") canv.SaveAs("plots/" + folder + "/" + sourceHistogram + ".pdf") f = TFile.Open("plots/" + folder + "/" + sourceHistogram + ".root", "RECREATE") canv.Write() f.Close() return histo
def plotDigiTest(): #Prepare canvas PlotStyle.setPlotStyle() canvas = TCanvas("canvasBxId", "BXID", 1200, 1200) canvas.SetLogy() histBx = file.Get("hoMuonAnalyzer/hoDigi_BxId") histBx.GetXaxis().SetRangeUser(-3, 3) histBx.SetLineWidth(3) histBx.Scale(1 / histBx.Integral()) histBx.SetStats(0) histBx.SetLineColor(PlotStyle.colorRwthDarkBlue) histBx.Draw('') #Add label label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() # #Add legend # legend = TLegend(0.7,0.65,0.9,0.8) # legend.AddEntry(histBx,"DT Only","l") # legend.AddEntry(histNew,"DT shifted with HO","l") # legend.SetBorderSize(1) # legend.Draw() # #Add text object # pText = TPaveText(0.52,0.8,0.9,0.9,'NDC') # pText.AddText('Fraction in BX ID 0: %6.3f%% #pm %6.3f%%' % (dtBx0/float(dtBxTotal)*100,calcSigma(dtBx0, dtBxTotal))) # pText.AddText('Fraction in BX ID 0 (HO corr.): %6.3f%% #pm %6.3f%%' % (correctedRightFraction*100,calcSigma(correctedBxId0, correctedTotal))) # pText.SetBorderSize(1) # pText.SetFillColor(0) # pText.Draw() # pText2 = TPaveText(0.7, 0.85, 0.9, 0.9, 'NDC') pText2.AddText('Entries: %d' % (histBx.GetEntries())) pText2.SetBorderSize(1) pText2.SetFillColor(0) pText2.Draw() canvas.Update() canvas.SaveAs('plots/timing/digiBxId.pdf') canvas.SaveAs('plots/timing/digiBxId.png') canvasAdcSum = TCanvas("cavasAdcSum", "ADC Sum", 1200, 1200) canvasAdcSum.SetLogy() histAdcSum = file.Get("hoMuonAnalyzer/hoDigiAdcSum_Multiplicity") histAdcSum.GetXaxis().SetRangeUser(-0.5, 500) histAdcSum.GetXaxis().SetTitle('ADC counts') histAdcSum.GetYaxis().SetTitle('#') histAdcSum.SetLineWidth(3) histAdcSum.SetStats(0) histAdcSum.SetLineColor(PlotStyle.colorRwthDarkBlue) histAdcSum.Draw() canvasAdcSum.Update() canvasAdcSum.SaveAs('plots/timing/digiAdcSum.pdf') canvasAdcSum.SaveAs('plots/timing/digiAdcSum.png') canvasTS4 = TCanvas("cavasTS4", "TS4", 1200, 1200) canvasTS4.SetLogy() histAdcTS4 = file.Get("hoMuonAnalyzer/hoDigiAdcTS4_Multiplicity") histAdcTS4.GetXaxis().SetRangeUser(-0.5, 500) histAdcTS4.GetXaxis().SetTitle('ADC counts') histAdcTS4.GetYaxis().SetTitle('#') histAdcTS4.SetLineWidth(3) histAdcTS4.SetStats(0) histAdcTS4.SetLineColor(PlotStyle.colorRwthDarkBlue) histAdcTS4.Draw() canvasTS4.Update() canvasTS4.SaveAs('plots/timing/digiAdcTs4.pdf') canvasTS4.SaveAs('plots/timing/digiAdcTs4.png') print histAdcSum.Integral(histAdcSum.FindBin(17), histAdcSum.FindBin(500)) return canvas, histBx, label, canvasAdcSum, histAdcSum, canvasTS4, histAdcTS4
def plotDigiTest(): #Prepare canvas PlotStyle.setPlotStyle() canvas = TCanvas("canvasBxId","BXID",1200,1200) canvas.SetLogy() histBx = file.Get("hoMuonAnalyzer/hoDigi_BxId") histBx.GetXaxis().SetRangeUser(-3,3) histBx.SetLineWidth(3) histBx.Scale(1/histBx.Integral()) histBx.SetStats(0) histBx.SetLineColor(PlotStyle.colorRwthDarkBlue) histBx.Draw('') #Add label label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() # #Add legend # legend = TLegend(0.7,0.65,0.9,0.8) # legend.AddEntry(histBx,"DT Only","l") # legend.AddEntry(histNew,"DT shifted with HO","l") # legend.SetBorderSize(1) # legend.Draw() # #Add text object # pText = TPaveText(0.52,0.8,0.9,0.9,'NDC') # pText.AddText('Fraction in BX ID 0: %6.3f%% #pm %6.3f%%' % (dtBx0/float(dtBxTotal)*100,calcSigma(dtBx0, dtBxTotal))) # pText.AddText('Fraction in BX ID 0 (HO corr.): %6.3f%% #pm %6.3f%%' % (correctedRightFraction*100,calcSigma(correctedBxId0, correctedTotal))) # pText.SetBorderSize(1) # pText.SetFillColor(0) # pText.Draw() # pText2 = TPaveText(0.7,0.85,0.9,0.9,'NDC') pText2.AddText('Entries: %d' % (histBx.GetEntries())) pText2.SetBorderSize(1) pText2.SetFillColor(0) pText2.Draw() canvas.Update() canvas.SaveAs('plots/timing/digiBxId.pdf') canvas.SaveAs('plots/timing/digiBxId.png') canvasAdcSum = TCanvas("cavasAdcSum","ADC Sum",1200,1200) canvasAdcSum.SetLogy() histAdcSum = file.Get("hoMuonAnalyzer/hoDigiAdcSum_Multiplicity") histAdcSum.GetXaxis().SetRangeUser(-0.5,500) histAdcSum.GetXaxis().SetTitle('ADC counts') histAdcSum.GetYaxis().SetTitle('#') histAdcSum.SetLineWidth(3) histAdcSum.SetStats(0) histAdcSum.SetLineColor(PlotStyle.colorRwthDarkBlue) histAdcSum.Draw() canvasAdcSum.Update() canvasAdcSum.SaveAs('plots/timing/digiAdcSum.pdf') canvasAdcSum.SaveAs('plots/timing/digiAdcSum.png') canvasTS4 = TCanvas("cavasTS4","TS4",1200,1200) canvasTS4.SetLogy() histAdcTS4 = file.Get("hoMuonAnalyzer/hoDigiAdcTS4_Multiplicity") histAdcTS4.GetXaxis().SetRangeUser(-0.5,500) histAdcTS4.GetXaxis().SetTitle('ADC counts') histAdcTS4.GetYaxis().SetTitle('#') histAdcTS4.SetLineWidth(3) histAdcTS4.SetStats(0) histAdcTS4.SetLineColor(PlotStyle.colorRwthDarkBlue) histAdcTS4.Draw() canvasTS4.Update() canvasTS4.SaveAs('plots/timing/digiAdcTs4.pdf') canvasTS4.SaveAs('plots/timing/digiAdcTs4.png') print histAdcSum.Integral(histAdcSum.FindBin(17),histAdcSum.FindBin(500)) return canvas, histBx,label,canvasAdcSum,histAdcSum,canvasTS4,histAdcTS4
def plotDeltaEtaDeltaPhi(folder,sourceHistogram = 'L1MuonWithHoMatch_DeltaEtaDeltaPhi', sourceFile = 'L1MuonHistogram.root',storeSubdir = 'deltaEtaDeltaPhi'): if(DEBUG): print prefix + 'was called' if(folder == None): print prefix + 'Error! Filename as first argument needed.' return if( not os.path.exists('plots')): os.mkdir('plots') if( not os.path.exists('plots/' + storeSubdir)): os.mkdir('plots/' + storeSubdir) filename = folder + '/' + sourceFile if( not os.path.exists(filename)): print 'Error! File ' + filename + ' does not exist!' return print prefix + 'Opening file:',filename file = TFile.Open(filename) PlotStyle.setPlotStyle() h2dDeltaEtaDeltaPhi = file.Get("hoMuonAnalyzer/etaPhi/" + sourceHistogram) hEventCount = file.Get("hoMuonAnalyzer/count/Events_Count") hNoTrgCount = file.Get("hoMuonAnalyzer/count/NoSingleMu_Count") if(h2dDeltaEtaDeltaPhi == None): print 'Could not get histogram %s from file %s'%("hoMuonAnalyzer/etaPhi/" + sourceHistogram,filename) canv = TCanvas("canvasDeltaEtaDeltaPhi" + sourceHistogram,'canvasDeltaEtaDeltaPhi',1200,1200) canv.SetLogz() h2dDeltaEtaDeltaPhi.GetXaxis().SetRangeUser(-.45,.45) h2dDeltaEtaDeltaPhi.GetXaxis().SetTitle("#Delta#eta") h2dDeltaEtaDeltaPhi.GetYaxis().SetRangeUser(-.45,.45) h2dDeltaEtaDeltaPhi.GetYaxis().SetTitle("#Delta#phi") h2dDeltaEtaDeltaPhi.GetZaxis().SetTitle("N") h2dDeltaEtaDeltaPhi.Draw("colz") boxList = drawHoBoxes(canv) canv.Update() pal = h2dDeltaEtaDeltaPhi.GetListOfFunctions().FindObject("palette") pal.SetX2NDC(0.92) stats = h2dDeltaEtaDeltaPhi.GetListOfFunctions().FindObject("stats") stats.SetX1NDC(.1) stats.SetX2NDC(.2) stats.SetY1NDC(.1) stats.SetY2NDC(.25) paveText = TPaveText(0.2,0.1,0.65,0.2,'NDC') paveText.AddText('Total Events: %d' % (hEventCount.GetBinContent(2))) paveText.AddText('Events with no Single #mu Trg: %d' % (hNoTrgCount.GetBinContent(2))) paveText.SetBorderSize(1) paveText.Draw() label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() legend = TLegend(0.7,0.8,0.9,0.9) legend.AddEntry(boxList[0],"HO tile dimensions","le") legend.Draw() canv.SaveAs("plots/" + storeSubdir + "/" + sourceHistogram + ".png") canv.SaveAs("plots/" + storeSubdir + "/" + sourceHistogram + ".pdf") canv.SaveAs("plots/" + storeSubdir + "/" + sourceHistogram + ".root") SetOwnership(h2dDeltaEtaDeltaPhi,False) return [h2dDeltaEtaDeltaPhi,canv,legend,boxList,stats,pal,paveText,label]