def plotHoTime(self): c3 = TCanvas("c3","HO Time",1200,1200) skipNoisePlot = False if not skipNoisePlot: c3.Divide(1,2) c3.cd(1).SetLogy() label = getLabelCmsPrivateSimulation() label.Draw() hHoTime = self.fileHandler.getHistogram('hoRecHits_Time') hHoTime.SetStats(0) hHoTime.SetTitle("Time distribution for all HO Rec Hits") hHoTime.SetLineColor(colorRwthDarkBlue) hHoTime.SetLineWidth(3) hHoTime.Draw() label = getLabelCmsPrivateSimulation() label.Draw() hHoTimeAboveThr = self.fileHandler.getHistogram('hoRecHitsAboveThr_Time') c3.cd(2).SetLogy() hHoTimeAboveThr.SetStats(0) hHoTimeAboveThr.SetTitle("Time distribution for HO Rec Hits > 0.2 GeV") hHoTimeAboveThr.SetLineColor(colorRwthDarkBlue) hHoTimeAboveThr.SetLineWidth(3) setupAxes(hHoTimeAboveThr) hHoTimeAboveThr.Draw() label = getLabelCmsPrivateSimulation() label.Draw() self.debug(80*'#') self.debug( 'Integral of HO > 0.2 GeV time histogram:') self.debug( hHoTimeAboveThr.Integral()) self.debug('') xLow = -5 xHigh = 5 histogramBetween = hHoTimeAboveThr.Integral(hHoTimeAboveThr.FindBin(xLow),hHoTimeAboveThr.FindBin(xHigh)) histogramTotal = float(hHoTimeAboveThr.Integral()) self.debug( 'Histogram integral between %.f ns and %.f ns' % (xLow,xHigh) ) self.debug( '%d/%d => %.2f +/- %f' % (histogramBetween,histogramTotal ,histogramBetween/histogramTotal,calcSigma(histogramBetween, histogramTotal))) self.debug( 80*'#') fit = TF1("fit","gaus",-10,10) hHoTimeAboveThr.Fit(fit) pText = TPaveText(0.7,0.8,0.9,0.9,'NDC') pText.AddText('Mean: %.2f ns' % (fit.GetParameter(1))) pText.AddText('#sigma: %.2f ns' % (fit.GetParameter(2))) pText.SetBorderSize(1) pText.SetFillColor(0) pText.Draw() c3.Update() self.storeCanvas(c3,"hoTime") return c3,label,hHoTimeAboveThr,pText
def outputFractionsInTileGrid(self,hist): #Calculate fraction in grids integralCentral = hist.Integral(hist.GetXaxis().FindBin(-.0435),hist.GetXaxis().FindBin(.0435), hist.GetYaxis().FindBin(-.0435),hist.GetYaxis().FindBin(.0435)) integral3x3 = hist.Integral(hist.GetXaxis().FindBin(-.1305),hist.GetXaxis().FindBin(.1305), hist.GetYaxis().FindBin(-.1305),hist.GetYaxis().FindBin(.1305)) integral5x5 = hist.Integral(hist.GetXaxis().FindBin(-.2175),hist.GetXaxis().FindBin(.2175), hist.GetYaxis().FindBin(-.2175),hist.GetYaxis().FindBin(.2175)) integralTotal = hist.Integral() self.debug(80*'#') self.debug('%20s:%5.2f%% +/- %5.2f%%' % ('Central Fraction',calcPercent(integralCentral,integralTotal), calcSigma(integralCentral,integralTotal)*100)) self.debug('%20s:%5.2f%% +/- %5.2f%%' % ('3x3 Fraction',calcPercent(integral3x3,integralTotal), calcSigma(integral3x3,integralTotal)*100)) self.debug('%20s:%5.2f%% +/- %5.2f%%' % ('5x5 Fraction',calcPercent(integral5x5,integralTotal), calcSigma(integral5x5,integralTotal)*100)) self.debug(80*'#')
def printFractionsForDtOnly(self): allL1 = self.fileHandler.getHistogram('count/timingSupport__Count') allTightL1 = self.fileHandler.getHistogram('count/timingSupport_tight__Count') dtOnly = self.makeDtOnlyPlot(sourceDt='UnmatchedDt', sourceDtHo='UnmatchedDtHo')[1] dtOnlyBxWrong = self.makeDtOnlyPlot(sourceDt='UnmatchedDtBxNot0', sourceDtHo='UnmatchedDtHoBxNot0')[1] dtOnlyBxWrongHo = self.makeDtOnlyPlot(sourceDt='UnmatchedDtHoBxNot0', sourceDtHo='')[1] dtOnlyTight = self.makeDtOnlyPlot(sourceDt='tight_UnmatchedDt', sourceDtHo='tight_UnmatchedDtHo')[1] dtOnlyTightBxWrong = self.makeDtOnlyPlot(sourceDt='tight_UnmatchedDtBxNot0', sourceDtHo='tight_UnmatchedDtHoBxNot0')[1] dtOnlyTightBxWrongHo = self.makeDtOnlyPlot(sourceDt='tight_UnmatchedDtHoBxNot0', sourceDtHo='')[1] nAllL1 = allL1.GetEntries() nAllL1Tight = allTightL1.GetEntries() nDtOnly = dtOnly.GetEntries() nDtOnlyBxWrong = dtOnlyBxWrong.GetEntries() nDtOnlyBxWrongHo = dtOnlyBxWrongHo.GetEntries() nDtOnlyTight = dtOnlyTight.GetEntries() nDtOnlyTightBxWrong = dtOnlyTightBxWrong.GetEntries() nDtOnlyTightBxWrongHo = dtOnlyTightBxWrongHo.GetEntries() print header = "%30s %7s %s" % ('Data source','Entries','Fraction of total L1') if (self.ptCut != ""): header += '\tpT cut: ' + self.ptCut self.debug(header) self.debug('-'*len(header)) self.debug("%30s: %7d" % ('L1',nAllL1)) self.debug("%30s: %7d => %6.2f +/- %6.2f" % ('DT only',nDtOnly,calcPercent(nDtOnly, nAllL1),calcSigma(nDtOnly,nAllL1)*100)) self.debug("%30s: %7d => %6.2f +/- %6.2f" % ('DT only, BX wrong',nDtOnlyBxWrong,calcPercent(nDtOnlyBxWrong, nAllL1),calcSigma(nDtOnlyBxWrong,nAllL1)*100)) self.debug("%30s: %7d => %6.2f +/- %6.2f" % ('DT only, BX wrong + HO',nDtOnlyBxWrongHo,calcPercent(nDtOnlyBxWrongHo, nAllL1),calcSigma(nDtOnlyBxWrongHo,nAllL1)*100)) print self.debug("%30s: %7d => %6.2f +/- %6.2f" % ('Tight L1',nAllL1Tight,calcPercent(nAllL1Tight, nAllL1),calcSigma(nAllL1Tight,nAllL1)*100)) self.debug("%30s: %7d => %6.2f +/- %6.2f" % ('Tight DT only',nDtOnlyTight,calcPercent(nDtOnlyTight, nAllL1),calcSigma(nDtOnlyTight,nAllL1)*100)) self.debug("%30s: %7d => %6.2f +/- %6.2f" % ('Tight DT only, BX wrong',nDtOnlyTightBxWrong,calcPercent(nDtOnlyTightBxWrong, nAllL1) ,calcSigma(nDtOnlyTightBxWrong,nAllL1)*100)) self.debug("%30s: %7d => %6.2f +/- %6.2f" % ('Tight DT only, BX wrong + HO',nDtOnlyTightBxWrongHo,calcPercent(nDtOnlyTightBxWrongHo, nAllL1) ,calcSigma(nDtOnlyTightBxWrongHo,nAllL1)*100)) print return
def printFractionsPerIEta(self,graph): self.output("Fractions of HO time in [-12.5,12.5] ns") counterDict = [{'total':0,'inside':0, 'hist':TH1D('hist' + str(i-10),'',201,-100.5,100.5)} for i in range(0,21)] x = Double(0) y = Double(0) nTotal = graph.GetN() ### # Fill histograms for later calculation of mean ### for i in range(0,nTotal): graph.GetPoint(i,x,y) indexHelper = int(x+10) counterDict[indexHelper]['total'] += 1 counterDict[indexHelper]['hist'].Fill(y) ### # Once all histograms are filled, calculate median ### for index,item in enumerate(counterDict): item['median'] = getMedian(item['hist']) ### # Fill the number of objects in interval depending on the # Histogram median ### nDone = 0 if self.DEBUG: self.debug('Filling interval counters') for i in range(0,nTotal): graph.GetPoint(i,x,y) indexHelper = int(x+10) median = counterDict[indexHelper]['median'] if( fabs(median - y) < 12.5 ): counterDict[indexHelper]['inside'] += 1 nDone += 1 self.printProgress(nDone, nTotal) #Graph for results graph = TEfficiency(graph.GetName(),"",21,-10.5,10.5) ### # Plot the results of calculations on CLI ### for index,item in enumerate(counterDict): if(index - 10 == 0): continue total = item['total'] inside = item['inside'] self.output("iEta: %3d\tTotal: %5d\tInside:%5d\tFraction:%6.2f +/- %6.2f" % (index - 10, total, inside, calcPercent(inside,total),calcSigma(inside, total)*100)) graph.SetTotalEvents(graph.FindFixBin(index -10),total) graph.SetPassedEvents(graph.FindFixBin(index -10),inside) return graph,counterDict
def printNoL1Info(self): hEventCount = self.fileHandler.getHistogram('count/Events_Count') nEvents = hEventCount.GetBinContent(2) hNoL1Count = self.fileHandler.getHistogram('count/NoL1Muon_Count') nNoL1Events = hNoL1Count.GetBinContent(2) hNoL1Ho = self.fileHandler.getHistogram( 'deltaEtaDeltaPhiEnergy/averageEMaxAroundPoint_NoL1_Tdmi_2dCounter' ) nNoL1HoEvents = hNoL1Ho.Integral() self.debug(60 * '#') self.debug('%15s %7d' % ('N Events', nEvents)) self.debug('%15s %7d %5.2f%% +/- %5.2f%%' % ('N No L1', nNoL1Events, nNoL1Events / nEvents * 100, calcSigma(nNoL1Events, nEvents) * 100)) self.debug('%15s %7d %5.2f%% +/- %5.2f%%' % ('N No L1 + HO', nNoL1HoEvents, nNoL1HoEvents / nEvents * 100, calcSigma(nNoL1HoEvents, nEvents) * 100)) self.debug(60 * '#')
def plotL1AndTightL1Counters(self): hEvent = self.fileHandler.getHistogram('count/Events_Count') hAllL1 = self.fileHandler.getHistogram('count/L1Muon_Count') hAllL13x3 = self.fileHandler.getHistogram('count/L1Muon3x3_Count') hTightL1 = self.fileHandler.getHistogram('count/L1TightMuons_Count') hTightL13x3 = self.fileHandler.getHistogram('count/L1TightMuons3x3_Count') hL1 = self.fileHandler.getHistogram('count/energyDeposit_L1_Count') hL1Reco = self.fileHandler.getHistogram('count/energyDeposit_L1Reco_Count') hL1RecoHo = self.fileHandler.getHistogram('count/energyDeposit_L1RecoHo_Count') hL1RecoHoTight = self.fileHandler.getHistogram('count/energyDeposit_L1RecoHoTight_Count') hL1RecoTight = self.fileHandler.getHistogram('count/energyDeposit_L1RecoTight_Count') hL1RecoTightHo = self.fileHandler.getHistogram('count/energyDeposit_L1RecoTightHo_Count') hL1RecoHoNoThr = self.fileHandler.getHistogram('count/energyDeposit_L1RecoHoNoThr_Count') hL1RecoGaHoNoThr = self.fileHandler.getHistogram('count/energyDeposit_L1RecoGaHoNoThr_Count') histogramList = [hEvent, hL1, hL1Reco, hL1RecoHo, hL1RecoHoTight, hL1RecoTight, hL1RecoTightHo, hL1RecoHoNoThr, hL1RecoGaHoNoThr ] names = ['hEvent','hL1','hL1Reco','hL1RecoHo','hL1RecoHoTight','hL1RecoTight','hL1RecoTightHo','hL1RecoHoNoThr','hL1RecoGaHoNoThr'] nL1 = hL1.GetBinContent(2) self.commandLine.output('###############################################') for i,h in enumerate(histogramList): self.commandLine.output('%-20s:%8d\t=> %6.2f%% +/- %5.2f%%' % (names[i],h.GetBinContent(2) ,calcPercent(h.GetBinContent(2),nL1),calcSigma(h.GetBinContent(2),nL1)*100)) self.commandLine.output('###############################################') nL1Reco = hL1Reco.GetBinContent(2) nL1RecoHo = hL1RecoHo.GetBinContent(2) nL1RecoHoTight = hL1RecoHoTight.GetBinContent(2) nL1RecoTight = hL1RecoTight.GetBinContent(2) nL1RecoTightHo = hL1RecoTightHo.GetBinContent(2) N_BINS = 4 binContents = [nL1,nL1Reco,nL1RecoHo,nL1RecoHoTight] binLabels = ['L1','L1 -> Reco','L1 + R -> HO','L1 + R + HO -> tight'] binContentsInverted = [nL1,nL1Reco,nL1RecoTight,nL1RecoTightHo] binLabelsInverted = ['L1','L1 -> Reco','L1 + R -> tight','L1 + R + tight -> HO'] c = TCanvas('cL1AndTightL1Count','L1AndTightL1Count',1200,900) h = TH1D('hL1AndTightL1Count','',4,-0.5,N_BINS - .5) hInverted = TH1D('hL1AndTightL1CountInverted','',4,-0.5,N_BINS - .5) hInverted.SetFillStyle(1001) hInverted.SetFillColorAlpha(colorRwthOrange,.5) hInverted.SetLineColorAlpha(colorRwthOrange,.5) hL13x3Alone = TH1D('hL1And3x3Alone','',1,1.5,2.5) hL13x3Alone.SetBinContent(1,nL1RecoHo/nL1Reco) hL13x3Alone.SetBinError(1,calcSigma(nL1RecoHo,nL1Reco)) hL13x3Alone.SetLineColor(colorRwthMagenta) hTightL13x3Alone = TH1D('hTightL1And3x3Alone','',1,2.5,3.5) hTightL13x3Alone.SetBinContent(1,nL1RecoHoTight/nL1RecoHo) hTightL13x3Alone.SetBinError(1,calcSigma(nL1RecoHoTight,nL1RecoHo)) hTightL13x3Alone.SetLineColor(colorRwthTuerkis) for i in range(2,N_BINS + 1): h.SetBinContent(i,binContents[i-1]/binContents[1]) h.GetXaxis().SetBinLabel(i,binLabels[i-1]) hInverted.SetBinContent(i,binContentsInverted[i-1]/binContentsInverted[1]) #Very dirty hack to change the order of plotting but have the correct labels !!! hInverted.GetXaxis().SetBinLabel(i,binLabels[i-1])#binLabelsInverted[i-1]) h.GetXaxis().SetBinLabel(1,'L1') h.SetBinContent(1,1) hInverted.SetLabelSize(0.05) hInverted.GetXaxis().SetBinLabel(1,'L1') hInverted.SetBinContent(1,1) h.SetLineColor(colorRwthDarkBlue) hInverted.SetStats(0) hInverted.GetYaxis().SetTitle('rel. fraction') # hL13x3Alone.Draw('same e') # hTightL13x3Alone.Draw('same e') hInverted.Draw('') hInverted.GetXaxis().Draw('same') h.Draw('same') setupAxes(hInverted) legend = getLegend(y1=.85,y2=.95,x1=.64,x2=.98) legend.AddEntry(h,'First match HO then use tight','l') # legend.AddEntry(hL13x3Alone,'3x3 matching normed to # L1 + R','le') # legend.AddEntry(hTightL13x3Alone,'Normed to # L1 + R + HO','l') legend.AddEntry(hInverted,'Inverted order for HO and tight','f') legend.Draw() #label = self.drawLabel(x1ndc=.69,x2ndc=.99) textObjects = [] #Manually determined xNdcCoordinates = [0.42,0.64,0.86] #for (Int_t i=1;i<=30;i++) t.DrawText(h->GetBinCenter(i),yt,Form("%d",i%10)); for i in range(1,4): t = TText() t.SetTextSize(0.035) t.SetTextAlign(22) t.SetTextColor(colorRwthOrange) t.DrawTextNDC(xNdcCoordinates[i-1],0.035,binLabelsInverted[i]) # Double_t yt = - h->GetMaximum()/15.; textObjects.append(t) c.Update() self.storeCanvas(c, 'l1AndTightL1Counters',marginRight=.02) return h,c,hL13x3Alone,hTightL13x3Alone,legend,hInverted,textObjects
def plotImprovementInTightDt(self): #Prepare canvas canvas = TCanvas("canvasTightDtImprovement","tight DT improvement",1200,1200) canvas.SetLogy() histDt = self.fileHandler.getHistogram("timingSupport_tight_UnmatchedDtHo_BxId") histDtNoHo = self.fileHandler.getHistogram("timingSupport_tight_UnmatchedDt_BxId") #Define variables for integrals histHoTime = self.fileHandler.getHistogram('timingSupport_tight_UnmatchedDtHo_Time') integralHoCorrect = histHoTime.Integral(histHoTime.FindBin(-12.5),histHoTime.FindBin(12.5)) integralHoTotal = histHoTime.Integral() integralHoOutside = integralHoTotal - integralHoCorrect hoFractionWrong = integralHoOutside/float(integralHoTotal) hoFractionRight = integralHoCorrect/float(integralHoTotal) #Print some information heading = 'Integrals of the Ho timing (tight):' print CliColors.OKBLUE print 80*'#' print heading print len(heading)*'-' print 'Timing correct:\t%d\t=>\t%6.3f%% +/- %6.3f%%'%(integralHoCorrect,hoFractionRight*100,calcSigma(integralHoCorrect, integralHoTotal)*100) print 'Timing outside:\t%d\t=>\t%6.3f%% +/- %f%%'%(integralHoOutside,hoFractionWrong*100,calcSigma(integralHoOutside, integralHoTotal)*100) print 'Timing total:%d'%(integralHoTotal) print #Define Variables for bx id counts dtBx0 = histDt.GetBinContent(6) dtBxM1 = histDt.Integral(histDt.FindBin(-10),histDt.FindBin(-1))#histDt.GetBinContent(5) dtBxP1 = histDt.Integral(histDt.FindBin(1),histDt.FindBin(10))#histDt.GetBinContent(7) dtBxTotal = dtBx0 + dtBxM1 + dtBxP1 dtFractionWrongM1 = dtBxM1/float(dtBxTotal) dtFractionWrongP1 = dtBxP1/float(dtBxTotal) noHodtBx0 = histDtNoHo.GetBinContent(6) noHodtBxM1 = histDtNoHo.Integral(histDtNoHo.FindBin(-10),histDtNoHo.FindBin(-1)) noHodtBxP1 = histDtNoHo.Integral(histDtNoHo.FindBin(1),histDtNoHo.FindBin(10)) noHodtBxTotal = noHodtBx0 + noHodtBxM1 + noHodtBxP1 noHodtFractionWrongM1 = noHodtBxM1/float(noHodtBxTotal) noHodtFractionWrongP1 = noHodtBxP1/float(noHodtBxTotal) #Print some information heading = 'Bin contents for tight DT timing:' print heading print len(heading)*'-' print 'BX ID 0:\t%d\t=>\t%6.3f%% +/- %6.3f%%'%(dtBx0,dtBx0/float(dtBxTotal)*100,calcSigma(dtBx0, dtBxTotal)*100) print 'BX ID -1:\t%d\t=>\t%6.3f%% +/- %6.3f%%'%(dtBxM1,dtFractionWrongM1*100,calcSigma(dtBxM1, dtBxTotal)*100) print 'BX ID +1:\t%d\t=>\t%6.3f%% +/- %6.3f%%'%(dtBxP1,dtFractionWrongP1*100,calcSigma(dtBxP1, dtBxTotal)*100) print 'BX ID total:\t%d\t(hist integral: %d)' % (dtBxTotal,histDt.Integral()) print print 'NO HO' print 'BX ID 0:\t%d\t=>\t%6.3f%% +/- %6.3f%%'%(noHodtBx0,noHodtBx0/float(noHodtBxTotal)*100,calcSigma(noHodtBx0, noHodtBxTotal)*100) print 'BX ID -1:\t%d\t=>\t%6.3f%% +/- %6.3f%%'%(noHodtBxM1,noHodtFractionWrongM1*100,calcSigma(noHodtBxM1, noHodtBxTotal)*100) print 'BX ID +1:\t%d\t=>\t%6.3f%% +/- %6.3f%%'%(noHodtBxP1,noHodtFractionWrongP1*100,calcSigma(noHodtBxP1, noHodtBxTotal)*100) print 'BX ID total:\t%d\t(hist integral: %d)' % (noHodtBxTotal,histDtNoHo.Integral()) print #Calculate corrected numbers correctedBxIdM1 = dtBxM1 + hoFractionWrong*dtBx0/2. - hoFractionRight*dtBxM1 correctedBxId0 = dtBx0 - hoFractionWrong*dtBx0 + hoFractionRight*dtBxM1 + hoFractionRight*dtBxP1 correctedBxIdP1 = dtBxP1 + hoFractionWrong*dtBx0/2. - hoFractionRight*dtBxP1 correctedTotal = correctedBxIdM1 + correctedBxId0 + correctedBxIdP1 correctedRightFraction = correctedBxId0/float(correctedTotal) heading = 'DT After correction:' print heading print len(heading)*'-' print 'BX -1:\t',int(correctedBxIdM1) print 'BX 0:\t',int(correctedBxId0) print 'BX +1:\t',int(correctedBxIdP1) print #Fill corrected histogram histNew = TH1D("histNewTight","BX ID in tight DT only triggers;BX ID;rel. fraction",6,-2.5,3.5) histNew.SetBinContent(histNew.FindBin(-1),correctedBxIdM1) histNew.SetBinContent(histNew.FindBin(0),correctedBxId0) histNew.SetBinContent(histNew.FindBin(1),correctedBxIdP1) histNew.SetLineColor(colorRwthMagenta) histNew.SetStats(0) histNew.Scale(1/histNew.Integral()) histNew.SetLineStyle(9) setupAxes(histNew) setBigAxisTitles(histNew) histDt.GetXaxis().SetRangeUser(-3,3) histDt.SetLineWidth(3) histDt.Scale(1/histDt.Integral()) histDt.SetLineColor(colorRwthDarkBlue) histNew.Draw() histDt.Draw('same') histNew.Draw('same') histDtNoHo.Scale(1/histDtNoHo.Integral()) histDtNoHo.SetLineWidth(3) #histDtNoHo.Draw('same') #Add label label = self.drawLabel() #Add legend legend = TLegend(0.7,0.65,0.9,0.8) legend.AddEntry(histDt,"tight DT Only + HO","l") legend.AddEntry(histNew,"tight 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 tight BX ID 0: %5.2f%% #pm %5.2f%%' % (dtBx0/float(dtBxTotal)*100,calcSigma(dtBx0, dtBxTotal)*100)) pText.AddText('Fraction in tight BX ID 0 (HO corr.): %5.2f%% #pm %5.2f%%' % (correctedRightFraction*100,calcSigma(correctedBxId0, correctedTotal)*100)) pText.SetBorderSize(1) pText.SetFillColor(0) pText.Draw() pText2 = TPaveText(0.7,0.6,0.9,0.65,'NDC') pText2.AddText('Entries: %d' % (histDt.GetEntries())) pText2.SetBorderSize(1) pText2.SetFillColor(0) pText2.Draw() #Print again some information heading = 'Fraction of correct BXID (tight):' print heading print len(heading)*'-' print 'Uncorrected:\t%5.2f%% #pm %f%%' % (dtBx0/float(dtBxTotal)*100,calcSigma(dtBx0, dtBxTotal)*100) print 'Corrected\t%5.2f%% #pm %f%%' % (correctedRightFraction*100,calcSigma(correctedBxId0, correctedTotal)*100) print 80*'#' print CliColors.ENDC setupAxes(histNew) canvas.Update() self.storeCanvas(canvas, 'correctedTightDt') return canvas, histDt,histNew,label,legend,pText2,pText,histDtNoHo
def plotMatchedHoTime(self): c2 = TCanvas("cTimeforMatchedHoHits","Matched Ho time",1200,400) c2.Divide(3,1) ### Plot matched DT/RPC c2.cd(1).SetLogy() hBxIdBest = self.fileHandler.getHistogram('timingSupport_MatchedDtRpcHo_Time') hBxIdDtOnly = self.fileHandler.getHistogram('timingSupport_UnmatchedDtHo_Time') hBxIdDtOnlyTight = self.fileHandler.getHistogram('timingSupport_tight_UnmatchedDtHo_Time') hBxIdOther = self.fileHandler.getHistogram('timingSupport_OtherCodesHo_Time') hIntegral = hBxIdDtOnly.Integral() hIntegralCentral = hBxIdDtOnly.Integral( hBxIdDtOnly.FindBin(-12.5), hBxIdDtOnly.FindBin(12.5)) hIntegralTight = hBxIdDtOnlyTight.Integral() hIntegralTighCentral = hBxIdDtOnlyTight.Integral( hBxIdDtOnlyTight.FindBin(-12.5), hBxIdDtOnlyTight.FindBin(12.5)) # hBxIdBest.Sumw2() # hBxIdDtOnly.Sumw2() # hBxIdOther.Sumw2() hBxIdBest.SetLineColor(colorRwthDarkBlue) hBxIdBest.SetLineWidth(3) hBxIdBest.SetStats(0) hBxIdBest.SetTitle("Matched DT/RPC + HO") hBxIdBest.GetXaxis().SetRangeUser(-50,50) #hBxIdBest.GetYaxis().SetRangeUser(2e-4,1) hBxIdBest.Scale(1/hBxIdBest.Integral()) hBxIdBest.GetYaxis().SetTitle("rel. fraction") setupAxes(hBxIdBest) setBigAxisTitles(hBxIdBest) hBxIdBest.Draw() label = self.drawLabel() ### Plot unmatched DT c2.cd(2).SetLogy() hBxIdDtOnly.SetLineColor(colorRwthDarkBlue) hBxIdDtOnly.SetLineWidth(3) hBxIdDtOnly.SetStats(0) hBxIdDtOnly.SetTitle("Unmatched DT + HO") hBxIdDtOnly.GetXaxis().SetRangeUser(-50,50) #hBxIdDtOnly.GetYaxis().SetRangeUser(2e-4,1) hBxIdDtOnly.Scale(1/hBxIdDtOnly.Integral()) hBxIdDtOnly.GetYaxis().SetTitle("rel. fraction") setupAxes(hBxIdDtOnly) setBigAxisTitles(hBxIdDtOnly) hBxIdDtOnly.Draw() ### Plot other codes c2.cd(3).SetLogy() hBxIdOther.SetLineColor(colorRwthDarkBlue) hBxIdOther.SetLineWidth(3) hBxIdOther.SetStats(0) hBxIdOther.SetTitle("Lower quality muon + HO") hBxIdOther.GetXaxis().SetRangeUser(-50,50) #hBxIdOther.GetYaxis().SetRangeUser(2e-4,1) hBxIdOther.Scale(1/hBxIdOther.Integral()) hBxIdOther.GetYaxis().SetTitle("rel. fraction") setupAxes(hBxIdOther) setBigAxisTitles(hBxIdOther) hBxIdOther.Draw() self.storeCanvas(c2,"matchedHoTime") c = TCanvas('cDtOnlyWithTight',"DT only with tight",600,600) c.SetLogy() hBxIdDtOnlyCopy = hBxIdDtOnly.DrawCopy() hBxIdDtOnlyTight.Scale(1/hBxIdDtOnlyTight.Integral()) hBxIdDtOnlyTight.SetLineColor(colorRwthMagenta) hBxIdDtOnlyTight.Draw('same') legend = getLegend(y1=0.75,y2=.9) legend.AddEntry(hBxIdDtOnlyCopy,'DT only','l') legend.AddEntry(hBxIdDtOnlyTight,'DT only, tight','l') legend.Draw() self.debug(80*'#') self.debug('Not tight: Integral in [-12.5,12.5]:\t %8d => %5.2f%% +/- %5.2f%%' % (hIntegral, hIntegralCentral/float(hIntegral)*100,calcSigma(hIntegralCentral, hIntegral)*100)) self.debug('Tight: Integral in [-12.5,12.5]:\t\t %8d => %5.2f%% +/- %5.2f%%' % (hIntegralTight, hIntegralTighCentral/float(hIntegralTight)*100,calcSigma(hIntegralTighCentral, hIntegralTight)*100)) self.debug(80*'#') self.storeCanvas(c, 'matchedHoDtOnlyWithTight') return label,c2,hBxIdBest,hBxIdDtOnly,hBxIdOther,hBxIdDtOnlyTight,hBxIdDtOnlyCopy,c,legend
def plotDeltaTime(self): hDeltaTAllHo = self.fileHandler.getHistogram('L1MuonPresentHoMatch_DeltaTime') hDeltaTCleanHo = self.fileHandler.getHistogram('timingSupport_UnmatchedDtHo_DeltaTime') c = TCanvas("c","Delta Time",1200,1200) c.SetLogy() hDeltaTAllHo.SetLineColor(colorRwthDarkBlue) hDeltaTAllHo.SetLineWidth(3) hDeltaTAllHo.SetFillColor(colorRwthDarkBlue) hDeltaTAllHo.SetFillStyle(3017) hDeltaTAllHo.SetTitle("#Delta time") hDeltaTAllHo.SetStats(0) hDeltaTCleanHo.SetLineColor(8) hDeltaTCleanHo.SetFillColor(8) hDeltaTCleanHo.SetLineWidth(3) hDeltaTCleanHo.SetFillStyle(3002) #hDeltaTAllHo.Scale(1/hDeltaTAllHo.Integral()) #hDeltaTCleanHo.Scale(1/hDeltaTCleanHo.Integral()) print hDeltaTCleanHo.Integral(),hDeltaTAllHo.Integral() fitFirstMin = TF1("fitFirstMin","[0]+x*[1]+[2]*x**2") fitSecondMin = TF1("fitsecondMin","[0]+x*[1]+[2]*x**2",10,20) hDeltaTCleanHo.Fit(fitFirstMin,"+q","",-20,-10) hDeltaTCleanHo.Fit(fitSecondMin,"R+q","") hDeltaTAllHo.Draw() legend = TLegend(0.6,0.75,0.9,0.9) legend.AddEntry(hDeltaTAllHo,"L1Muon matched to any HO","le") legend.Draw() label = getLabelCmsPrivateSimulation() label.Draw() c.Update() self.storeCanvas(c,"deltaTimeAllHo") hDeltaTCleanHo.Draw('same') fitFirstMin.SetRange(-50,50) fitSecondMin.SetRange(-50,50) #fitFirstMin.Draw('lSame') #fitSecondMin.Draw('lSame') lineFirstMin = TLine(fitFirstMin.GetMinimumX(-20,-10),hDeltaTAllHo.GetMinimum(),fitFirstMin.GetMinimumX(-20,-10),hDeltaTAllHo.GetMaximum()) lineFirstMin.SetLineWidth(3) lineFirstMin.SetLineColor(colorRwthRot) lineFirstMin.Draw() lineSecondMin = TLine(fitSecondMin.GetMinimumX(10,20),hDeltaTAllHo.GetMinimum(),fitSecondMin.GetMinimumX(10,20),hDeltaTAllHo.GetMaximum()) lineSecondMin.SetLineWidth(3) lineSecondMin.SetLineColor(colorRwthRot) lineSecondMin.Draw() legend.AddEntry(hDeltaTCleanHo,"L1Muon matched to HO > 0.2 GeV","le") legend.AddEntry(lineFirstMin,"Integral boundaries","e") legend.Draw() integralCenter = hDeltaTCleanHo.Integral(hDeltaTCleanHo.FindBin(fitFirstMin.GetMinimumX(-20,-10)),hDeltaTCleanHo.FindBin(fitSecondMin.GetMinimumX(10,20))) integralCenterAll = hDeltaTAllHo.Integral(hDeltaTAllHo.FindBin(fitFirstMin.GetMinimumX(-20,-10)),hDeltaTAllHo.FindBin(fitSecondMin.GetMinimumX(10,20))) self.debug(80*'#') self.debug('Integral of center area in clean histogram :%d' % integralCenter) self.debug('==> %.2f%% +/- %.2f%%' % (integralCenter/hDeltaTCleanHo.Integral()*100 ,calcSigma(integralCenter, hDeltaTCleanHo.Integral())*100)) self.debug('Integral of center area in all matched HO events:%d' % integralCenterAll) self.debug('==> %.2f%% +/- %.2f%%' % (integralCenterAll/hDeltaTAllHo.Integral()*100 ,calcSigma(integralCenterAll, hDeltaTAllHo.Integral())*100)) self.debug(80*'#') paveText = TPaveText(0.6,0.7,0.9,0.75,'NDC') paveText.AddText('%s' % ('Central peak contains (filtered hist.)')) paveText.AddText('%.2f%% +/- %.2f%%' % (integralCenter/hDeltaTCleanHo.Integral()*100,calcSigma(integralCenter, hDeltaTCleanHo.Integral())*100)) paveText.SetBorderSize(1) paveText.Draw() label = getLabelCmsPrivateSimulation() label.Draw() c.Update() self.storeCanvas(c,"deltaTime") return c, hDeltaTCleanHo
def plotL1BxId(self,tight = False): TIGHT_TOKEN = '_tight' if tight else '' c2 = TCanvas("cBxId" + TIGHT_TOKEN,"BX ID" + TIGHT_TOKEN,1200,400) c2.Divide(3,1) hBxIdBest = self.fileHandler.getHistogram('timingSupport%s_MatchedDtRpcHo_BxId' % TIGHT_TOKEN) hBxIdDtOnly = self.fileHandler.getHistogram('timingSupport%s_UnmatchedDtHo_BxId' % TIGHT_TOKEN) hBxIdOther = self.fileHandler.getHistogram('timingSupport%s_OtherCodesHo_BxId' % TIGHT_TOKEN) if not hBxIdBest or not hBxIdDtOnly or not hBxIdOther: return dtBx0BestCentral = hBxIdBest.GetBinContent(hBxIdBest.FindBin(0)) dtBx0BestIntegral = hBxIdBest.Integral() dtBx0BestOther = dtBx0BestIntegral - dtBx0BestCentral dtBx0DtOnlyCentral = hBxIdDtOnly.GetBinContent(hBxIdDtOnly.FindBin(0)) dtBx0DtOnlyIntegral = hBxIdDtOnly.Integral() dtBx0DtOnlyOther = dtBx0DtOnlyIntegral - dtBx0DtOnlyCentral dtBx0OtherCentral = hBxIdOther.GetBinContent(hBxIdOther.FindBin(0)) dtBx0OtherIntegral = hBxIdOther.Integral() dtBx0OtherOther = dtBx0OtherIntegral - dtBx0OtherCentral self.debug('#'*20) self.debug('!TIGHT!' if tight else '') self.debug('DT/RPC') self.debug('-'*10) self.debug('Events in BXID 0: %d\t%6.3f%% +/- %6.3f%%' % (dtBx0BestCentral,dtBx0BestCentral/float(dtBx0BestIntegral)*100,calcSigma(dtBx0BestCentral, dtBx0BestIntegral)*100)) self.debug('Events in other BXID: %d\t%6.3f%% +/- %6.3f%%' % (dtBx0BestOther,dtBx0BestOther/float(dtBx0BestIntegral)*100,calcSigma(dtBx0BestOther, dtBx0BestIntegral)*100)) self.debug('Consistency check (Central + Other, Integral): %d, %d' % (dtBx0BestCentral + dtBx0BestOther,dtBx0BestIntegral)) self.debug('') self.debug('DT') self.debug('-'*10) self.debug('Events in BXID 0: %d\t%6.3f%% +/- %6.3f%%' % (dtBx0DtOnlyCentral,dtBx0DtOnlyCentral/float(dtBx0DtOnlyIntegral)*100,calcSigma(dtBx0DtOnlyCentral, dtBx0DtOnlyIntegral)*100)) self.debug('Events in other BXID: %d\t%6.3f%% +/- %6.3f%%' % (dtBx0DtOnlyOther,dtBx0DtOnlyOther/float(dtBx0DtOnlyIntegral)*100,calcSigma(dtBx0DtOnlyOther, dtBx0DtOnlyIntegral)*100)) self.debug('Consistency check (Central + Other, Integral): %d, %d' % (dtBx0DtOnlyCentral + dtBx0DtOnlyOther,dtBx0DtOnlyIntegral)) self.debug('') self.debug('Other') self.debug('-'*10) self.debug('Events in BXID 0: %d\t%6.3f%% +/- %6.3f%%' % (dtBx0OtherCentral,dtBx0OtherCentral/float(dtBx0OtherIntegral)*100,calcSigma(dtBx0OtherCentral, dtBx0OtherIntegral)*100)) self.debug('Events in other BXID: %d\t%6.3f%% +/- %6.3f%%' % (dtBx0OtherOther,dtBx0OtherOther/float(dtBx0OtherIntegral)*100,calcSigma(dtBx0OtherOther, dtBx0OtherIntegral)*100)) self.debug('Consistency check (Central + Other, Integral): %d, %d' % (dtBx0OtherCentral + dtBx0OtherOther,dtBx0OtherIntegral)) self.debug('') self.debug('#'*20) ### Plot matched DT/RPC c2.cd(1).SetLogy() hBxIdBest.SetLineColor(colorRwthDarkBlue) hBxIdBest.SetLineWidth(3) hBxIdBest.SetStats(0) hBxIdBest.SetTitle("Matched DT/RPC + HO") hBxIdBest.GetXaxis().SetRangeUser(-5,5) hBxIdBest.GetYaxis().SetRangeUser(2e-4,1) hBxIdBest.Scale(1/hBxIdBest.Integral()) hBxIdBest.GetYaxis().SetTitle("rel. fraction") setupAxes(hBxIdBest) setBigAxisTitles(hBxIdBest) hBxIdBest.Draw() label = self.drawLabel() ### Plot unmatched DT c2.cd(2).SetLogy() hBxIdDtOnly.SetLineColor(colorRwthDarkBlue) hBxIdDtOnly.SetLineWidth(3) hBxIdDtOnly.SetStats(0) hBxIdDtOnly.SetTitle("Unmatched DT + HO") hBxIdDtOnly.GetXaxis().SetRangeUser(-5,5) hBxIdDtOnly.GetYaxis().SetRangeUser(2e-4,1) hBxIdDtOnly.Scale(1/hBxIdDtOnly.Integral()) hBxIdDtOnly.GetYaxis().SetTitle("rel. fraction") setupAxes(hBxIdDtOnly) setBigAxisTitles(hBxIdDtOnly) hBxIdDtOnly.Draw() ### Plot other codes c2.cd(3).SetLogy() hBxIdOther.SetLineColor(colorRwthDarkBlue) hBxIdOther.SetLineWidth(3) hBxIdOther.SetStats(0) hBxIdOther.SetTitle("Lower quality muon + HO") hBxIdOther.GetXaxis().SetRangeUser(-5,5) hBxIdOther.GetYaxis().SetRangeUser(2e-4,1) hBxIdOther.Scale(1/hBxIdOther.Integral()) hBxIdOther.GetYaxis().SetTitle("rel. fraction") setupAxes(hBxIdOther) setBigAxisTitles(hBxIdOther) hBxIdOther.Draw() self.storeCanvas(c2,"bxId" + TIGHT_TOKEN) return label,c2,hBxIdBest,hBxIdDtOnly,hBxIdOther
def printNoL1Info(self): hEventCount = self.fileHandler.getHistogram('count/Events_Count') nEvents = hEventCount.GetBinContent(2) hNoL1Count = self.fileHandler.getHistogram('count/NoL1Muon_Count') nNoL1Events = hNoL1Count.GetBinContent(2) hNoL1Ho = self.fileHandler.getHistogram('deltaEtaDeltaPhiEnergy/averageEMaxAroundPoint_NoL1_Tdmi_2dCounter') nNoL1HoEvents = hNoL1Ho.Integral() self.debug(60*'#') self.debug('%15s %7d' % ('N Events',nEvents)) self.debug('%15s %7d %5.2f%% +/- %5.2f%%' % ('N No L1',nNoL1Events,nNoL1Events/nEvents*100,calcSigma(nNoL1Events,nEvents)*100)) self.debug('%15s %7d %5.2f%% +/- %5.2f%%' % ('N No L1 + HO',nNoL1HoEvents,nNoL1HoEvents/nEvents*100,calcSigma(nNoL1HoEvents,nEvents)*100)) self.debug(60*'#')
def printFractionsForDtOnly(self): allL1 = self.fileHandler.getHistogram('count/timingSupport__Count') allTightL1 = self.fileHandler.getHistogram( 'count/timingSupport_tight__Count') dtOnly = self.makeDtOnlyPlot(sourceDt='UnmatchedDt', sourceDtHo='UnmatchedDtHo')[1] dtOnlyBxWrong = self.makeDtOnlyPlot( sourceDt='UnmatchedDtBxNot0', sourceDtHo='UnmatchedDtHoBxNot0')[1] dtOnlyBxWrongHo = self.makeDtOnlyPlot(sourceDt='UnmatchedDtHoBxNot0', sourceDtHo='')[1] dtOnlyTight = self.makeDtOnlyPlot(sourceDt='tight_UnmatchedDt', sourceDtHo='tight_UnmatchedDtHo')[1] dtOnlyTightBxWrong = self.makeDtOnlyPlot( sourceDt='tight_UnmatchedDtBxNot0', sourceDtHo='tight_UnmatchedDtHoBxNot0')[1] dtOnlyTightBxWrongHo = self.makeDtOnlyPlot( sourceDt='tight_UnmatchedDtHoBxNot0', sourceDtHo='')[1] nAllL1 = allL1.GetEntries() nAllL1Tight = allTightL1.GetEntries() nDtOnly = dtOnly.GetEntries() nDtOnlyBxWrong = dtOnlyBxWrong.GetEntries() nDtOnlyBxWrongHo = dtOnlyBxWrongHo.GetEntries() nDtOnlyTight = dtOnlyTight.GetEntries() nDtOnlyTightBxWrong = dtOnlyTightBxWrong.GetEntries() nDtOnlyTightBxWrongHo = dtOnlyTightBxWrongHo.GetEntries() print header = "%30s %7s %s" % ('Data source', 'Entries', 'Fraction of total L1') if (self.ptCut != ""): header += '\tpT cut: ' + self.ptCut self.debug(header) self.debug('-' * len(header)) self.debug("%30s: %7d" % ('L1', nAllL1)) self.debug("%30s: %7d => %6.2f +/- %6.2f" % ('DT only', nDtOnly, calcPercent( nDtOnly, nAllL1), calcSigma(nDtOnly, nAllL1) * 100)) self.debug("%30s: %7d => %6.2f +/- %6.2f" % ('DT only, BX wrong', nDtOnlyBxWrong, calcPercent(nDtOnlyBxWrong, nAllL1), calcSigma(nDtOnlyBxWrong, nAllL1) * 100)) self.debug("%30s: %7d => %6.2f +/- %6.2f" % ('DT only, BX wrong + HO', nDtOnlyBxWrongHo, calcPercent(nDtOnlyBxWrongHo, nAllL1), calcSigma(nDtOnlyBxWrongHo, nAllL1) * 100)) print self.debug("%30s: %7d => %6.2f +/- %6.2f" % ('Tight L1', nAllL1Tight, calcPercent(nAllL1Tight, nAllL1), calcSigma(nAllL1Tight, nAllL1) * 100)) self.debug( "%30s: %7d => %6.2f +/- %6.2f" % ('Tight DT only', nDtOnlyTight, calcPercent( nDtOnlyTight, nAllL1), calcSigma(nDtOnlyTight, nAllL1) * 100)) self.debug("%30s: %7d => %6.2f +/- %6.2f" % ('Tight DT only, BX wrong', nDtOnlyTightBxWrong, calcPercent(nDtOnlyTightBxWrong, nAllL1), calcSigma(nDtOnlyTightBxWrong, nAllL1) * 100)) self.debug("%30s: %7d => %6.2f +/- %6.2f" % ('Tight DT only, BX wrong + HO', nDtOnlyTightBxWrongHo, calcPercent(nDtOnlyTightBxWrongHo, nAllL1), calcSigma(nDtOnlyTightBxWrongHo, nAllL1) * 100)) print return
def printFractionsPerIEta(self, graph): self.output("Fractions of HO time in [-12.5,12.5] ns") counterDict = [{ 'total': 0, 'inside': 0, 'hist': TH1D('hist' + str(i - 10), '', 201, -100.5, 100.5) } for i in range(0, 21)] x = Double(0) y = Double(0) nTotal = graph.GetN() ### # Fill histograms for later calculation of mean ### for i in range(0, nTotal): graph.GetPoint(i, x, y) indexHelper = int(x + 10) counterDict[indexHelper]['total'] += 1 counterDict[indexHelper]['hist'].Fill(y) ### # Once all histograms are filled, calculate median ### for index, item in enumerate(counterDict): item['median'] = getMedian(item['hist']) ### # Fill the number of objects in interval depending on the # Histogram median ### nDone = 0 if self.DEBUG: self.debug('Filling interval counters') for i in range(0, nTotal): graph.GetPoint(i, x, y) indexHelper = int(x + 10) median = counterDict[indexHelper]['median'] if (fabs(median - y) < 12.5): counterDict[indexHelper]['inside'] += 1 nDone += 1 self.printProgress(nDone, nTotal) #Graph for results graph = TEfficiency(graph.GetName(), "", 21, -10.5, 10.5) ### # Plot the results of calculations on CLI ### for index, item in enumerate(counterDict): if (index - 10 == 0): continue total = item['total'] inside = item['inside'] self.output( "iEta: %3d\tTotal: %5d\tInside:%5d\tFraction:%6.2f +/- %6.2f" % (index - 10, total, inside, calcPercent( inside, total), calcSigma(inside, total) * 100)) graph.SetTotalEvents(graph.FindFixBin(index - 10), total) graph.SetPassedEvents(graph.FindFixBin(index - 10), inside) return graph, counterDict
def plotMatchedHoTime(self): c2 = TCanvas("cTimeforMatchedHoHits","Matched Ho time",1200,400) c2.Divide(3,1) c2.cd(1).SetLeftMargin(.12) c2.cd(2).SetLeftMargin(.12) c2.cd(3).SetLeftMargin(.12) ### Plot matched DT/RPC c2.cd(1).SetLogy() hBxIdBest = self.fileHandler.getHistogram('timingSupport_MatchedDtRpcHo_Time') hBxIdDtOnly = self.fileHandler.getHistogram('timingSupport_UnmatchedDtHo_Time') hBxIdDtOnlyTight = self.fileHandler.getHistogram('timingSupport_tight_UnmatchedDtHo_Time') hBxIdOther = self.fileHandler.getHistogram('timingSupport_OtherCodesHo_Time') hIntegral = hBxIdDtOnly.Integral() hIntegralCentral = hBxIdDtOnly.Integral( hBxIdDtOnly.FindBin(-12.5), hBxIdDtOnly.FindBin(12.5)) hIntegralTight = hBxIdDtOnlyTight.Integral() hIntegralTighCentral = hBxIdDtOnlyTight.Integral( hBxIdDtOnlyTight.FindBin(-12.5), hBxIdDtOnlyTight.FindBin(12.5)) # hBxIdBest.Sumw2() # hBxIdDtOnly.Sumw2() # hBxIdOther.Sumw2() hBxIdBest.SetLineColor(colorRwthDarkBlue) hBxIdBest.SetLineWidth(3) hBxIdBest.SetStats(0) hBxIdBest.SetTitle("Matched DT/RPC + HO") hBxIdBest.GetXaxis().SetRangeUser(-50,50) #hBxIdBest.GetYaxis().SetRangeUser(2e-4,1) hBxIdBest.Scale(1/hBxIdBest.Integral()) hBxIdBest.GetYaxis().SetTitle("rel. fraction") setupAxes(hBxIdBest) setBigAxisTitles(hBxIdBest) hBxIdBest.Draw() ### Plot unmatched DT c2.cd(2).SetLogy() hBxIdDtOnly.SetLineColor(colorRwthDarkBlue) hBxIdDtOnly.SetLineWidth(3) hBxIdDtOnly.SetStats(0) hBxIdDtOnly.SetTitle("Unmatched DT + HO") hBxIdDtOnly.GetXaxis().SetRangeUser(-50,50) #hBxIdDtOnly.GetYaxis().SetRangeUser(2e-4,1) hBxIdDtOnly.Scale(1/hBxIdDtOnly.Integral()) hBxIdDtOnly.GetYaxis().SetTitle("rel. fraction") setupAxes(hBxIdDtOnly) setBigAxisTitles(hBxIdDtOnly) hBxIdDtOnly.Draw() ### Plot other codes c2.cd(3).SetLogy() hBxIdOther.SetLineColor(colorRwthDarkBlue) hBxIdOther.SetLineWidth(3) hBxIdOther.SetStats(0) hBxIdOther.SetTitle("Lower quality muon + HO") hBxIdOther.GetXaxis().SetRangeUser(-50,50) #hBxIdOther.GetYaxis().SetRangeUser(2e-4,1) hBxIdOther.Scale(1/hBxIdOther.Integral()) hBxIdOther.GetYaxis().SetTitle("rel. fraction") setupAxes(hBxIdOther) setBigAxisTitles(hBxIdOther) hBxIdOther.Draw() hBxIdBest.GetYaxis().SetTitleOffset(1) hBxIdDtOnly.GetYaxis().SetTitleOffset(1) hBxIdOther.GetYaxis().SetTitleOffset(1) self.storeCanvas(c2,"matchedHoTime") c = TCanvas('cDtOnlyWithTight',"DT only with tight",600,600) c.SetLogy() hBxIdDtOnlyCopy = hBxIdDtOnly.DrawCopy() hBxIdDtOnlyTight.Scale(1/hBxIdDtOnlyTight.Integral()) hBxIdDtOnlyTight.SetLineColor(colorRwthMagenta) hBxIdDtOnlyTight.Draw('same') legend = getLegend(y1=0.75,y2=.9) legend.AddEntry(hBxIdDtOnlyCopy,'DT only','l') legend.AddEntry(hBxIdDtOnlyTight,'DT only, tight','l') legend.Draw() self.debug(80*'#') self.debug('Not tight: Integral in [-12.5,12.5]:\t %8d => %5.2f%% +/- %5.2f%%' % (hIntegral, hIntegralCentral/float(hIntegral)*100,calcSigma(hIntegralCentral, hIntegral)*100)) self.debug('Tight: Integral in [-12.5,12.5]:\t\t %8d => %5.2f%% +/- %5.2f%%' % (hIntegralTight, hIntegralTighCentral/float(hIntegralTight)*100,calcSigma(hIntegralTighCentral, hIntegralTight)*100)) self.debug(80*'#') self.storeCanvas(c, 'matchedHoDtOnlyWithTight') return c2,hBxIdBest,hBxIdDtOnly,hBxIdOther,hBxIdDtOnlyTight,hBxIdDtOnlyCopy,c,legend
def plotL1BxId(self,tight = False): TIGHT_TOKEN = '_tight' if tight else '' c2 = TCanvas("cBxId" + TIGHT_TOKEN,"BX ID" + TIGHT_TOKEN,1200,400) c2.Divide(3,1) c2.cd(1).SetLeftMargin(.12) c2.cd(2).SetLeftMargin(.12) c2.cd(3).SetLeftMargin(.12) hBxIdBest = self.fileHandler.getHistogram('timingSupport%s_MatchedDtRpcHo_BxId' % TIGHT_TOKEN) hBxIdDtOnly = self.fileHandler.getHistogram('timingSupport%s_UnmatchedDtHo_BxId' % TIGHT_TOKEN) hBxIdOther = self.fileHandler.getHistogram('timingSupport%s_OtherCodesHo_BxId' % TIGHT_TOKEN) if not hBxIdBest or not hBxIdDtOnly or not hBxIdOther: return dtBx0BestCentral = hBxIdBest.GetBinContent(hBxIdBest.FindBin(0)) dtBx0BestIntegral = hBxIdBest.Integral() dtBx0BestOther = dtBx0BestIntegral - dtBx0BestCentral dtBx0DtOnlyCentral = hBxIdDtOnly.GetBinContent(hBxIdDtOnly.FindBin(0)) dtBx0DtOnlyIntegral = hBxIdDtOnly.Integral() dtBx0DtOnlyOther = dtBx0DtOnlyIntegral - dtBx0DtOnlyCentral dtBx0OtherCentral = hBxIdOther.GetBinContent(hBxIdOther.FindBin(0)) dtBx0OtherIntegral = hBxIdOther.Integral() dtBx0OtherOther = dtBx0OtherIntegral - dtBx0OtherCentral self.debug('#'*20) self.debug('!TIGHT!' if tight else '') self.debug('DT/RPC') self.debug('-'*10) self.debug('Events in BXID 0: %d\t%6.3f%% +/- %6.3f%%' % (dtBx0BestCentral,dtBx0BestCentral/float(dtBx0BestIntegral)*100,calcSigma(dtBx0BestCentral, dtBx0BestIntegral)*100)) self.debug('Events in other BXID: %d\t%6.3f%% +/- %6.3f%%' % (dtBx0BestOther,dtBx0BestOther/float(dtBx0BestIntegral)*100,calcSigma(dtBx0BestOther, dtBx0BestIntegral)*100)) self.debug('Consistency check (Central + Other, Integral): %d, %d' % (dtBx0BestCentral + dtBx0BestOther,dtBx0BestIntegral)) self.debug('') self.debug('DT') self.debug('-'*10) self.debug('Events in BXID 0: %d\t%6.3f%% +/- %6.3f%%' % (dtBx0DtOnlyCentral,dtBx0DtOnlyCentral/float(dtBx0DtOnlyIntegral)*100,calcSigma(dtBx0DtOnlyCentral, dtBx0DtOnlyIntegral)*100)) self.debug('Events in other BXID: %d\t%6.3f%% +/- %6.3f%%' % (dtBx0DtOnlyOther,dtBx0DtOnlyOther/float(dtBx0DtOnlyIntegral)*100,calcSigma(dtBx0DtOnlyOther, dtBx0DtOnlyIntegral)*100)) self.debug('Consistency check (Central + Other, Integral): %d, %d' % (dtBx0DtOnlyCentral + dtBx0DtOnlyOther,dtBx0DtOnlyIntegral)) self.debug('') self.debug('Other') self.debug('-'*10) self.debug('Events in BXID 0: %d\t%6.3f%% +/- %6.3f%%' % (dtBx0OtherCentral,dtBx0OtherCentral/float(dtBx0OtherIntegral)*100,calcSigma(dtBx0OtherCentral, dtBx0OtherIntegral)*100)) self.debug('Events in other BXID: %d\t%6.3f%% +/- %6.3f%%' % (dtBx0OtherOther,dtBx0OtherOther/float(dtBx0OtherIntegral)*100,calcSigma(dtBx0OtherOther, dtBx0OtherIntegral)*100)) self.debug('Consistency check (Central + Other, Integral): %d, %d' % (dtBx0OtherCentral + dtBx0OtherOther,dtBx0OtherIntegral)) self.debug('') self.debug('#'*20) ### Plot matched DT/RPC c2.cd(1).SetLogy() hBxIdBest.SetLineColor(colorRwthDarkBlue) hBxIdBest.SetLineWidth(3) hBxIdBest.SetStats(0) hBxIdBest.SetTitle("Matched DT/RPC + HO") hBxIdBest.GetXaxis().SetRangeUser(-5,5) hBxIdBest.GetYaxis().SetRangeUser(2e-4,1) hBxIdBest.Scale(1/hBxIdBest.Integral()) hBxIdBest.GetYaxis().SetTitle("rel. fraction") setupAxes(hBxIdBest) setBigAxisTitles(hBxIdBest) hBxIdBest.Draw() ### Plot unmatched DT c2.cd(2).SetLogy() hBxIdDtOnly.SetLineColor(colorRwthDarkBlue) hBxIdDtOnly.SetLineWidth(3) hBxIdDtOnly.SetStats(0) hBxIdDtOnly.SetTitle("Unmatched DT + HO") hBxIdDtOnly.GetXaxis().SetRangeUser(-5,5) hBxIdDtOnly.GetYaxis().SetRangeUser(2e-4,1) hBxIdDtOnly.Scale(1/hBxIdDtOnly.Integral()) hBxIdDtOnly.GetYaxis().SetTitle("rel. fraction") setupAxes(hBxIdDtOnly) setBigAxisTitles(hBxIdDtOnly) hBxIdDtOnly.Draw() ### Plot other codes c2.cd(3).SetLogy() hBxIdOther.SetLineColor(colorRwthDarkBlue) hBxIdOther.SetLineWidth(3) hBxIdOther.SetStats(0) hBxIdOther.SetTitle("Lower quality muon + HO") hBxIdOther.GetXaxis().SetRangeUser(-5,5) hBxIdOther.GetYaxis().SetRangeUser(2e-4,1) hBxIdOther.Scale(1/hBxIdOther.Integral()) hBxIdOther.GetYaxis().SetTitle("rel. fraction") setupAxes(hBxIdOther) setBigAxisTitles(hBxIdOther) hBxIdOther.Draw() hBxIdBest.GetYaxis().SetTitleOffset(1) hBxIdDtOnly.GetYaxis().SetTitleOffset(1) hBxIdOther.GetYaxis().SetTitleOffset(1) self.storeCanvas(c2,"bxId" + TIGHT_TOKEN, drawLabel = False) return c2,hBxIdBest,hBxIdDtOnly,hBxIdOther
def plotL1AndTightL1Counters(self): hEvent = self.fileHandler.getHistogram('count/Events_Count') hAllL1 = self.fileHandler.getHistogram('count/L1Muon_Count') hAllL13x3 = self.fileHandler.getHistogram('count/L1Muon3x3_Count') hTightL1 = self.fileHandler.getHistogram('count/L1TightMuons_Count') hTightL13x3 = self.fileHandler.getHistogram( 'count/L1TightMuons3x3_Count') hL1 = self.fileHandler.getHistogram('count/energyDeposit_L1_Count') hL1Reco = self.fileHandler.getHistogram( 'count/energyDeposit_L1Reco_Count') hL1RecoHo = self.fileHandler.getHistogram( 'count/energyDeposit_L1RecoHo_Count') hL1RecoHoTight = self.fileHandler.getHistogram( 'count/energyDeposit_L1RecoHoTight_Count') hL1RecoTight = self.fileHandler.getHistogram( 'count/energyDeposit_L1RecoTight_Count') hL1RecoTightHo = self.fileHandler.getHistogram( 'count/energyDeposit_L1RecoTightHo_Count') hL1RecoHoNoThr = self.fileHandler.getHistogram( 'count/energyDeposit_L1RecoHoNoThr_Count') hL1RecoGaHoNoThr = self.fileHandler.getHistogram( 'count/energyDeposit_L1RecoGaHoNoThr_Count') histogramList = [ hEvent, hL1, hL1Reco, hL1RecoHo, hL1RecoHoTight, hL1RecoTight, hL1RecoTightHo, hL1RecoHoNoThr, hL1RecoGaHoNoThr ] names = [ 'hEvent', 'hL1', 'hL1Reco', 'hL1RecoHo', 'hL1RecoHoTight', 'hL1RecoTight', 'hL1RecoTightHo', 'hL1RecoHoNoThr', 'hL1RecoGaHoNoThr' ] nL1 = hL1.GetBinContent(2) self.commandLine.output( '###############################################') for i, h in enumerate(histogramList): self.commandLine.output('%-20s:%8d\t=> %6.2f%% +/- %5.2f%%' % (names[i], h.GetBinContent(2), calcPercent(h.GetBinContent(2), nL1), calcSigma(h.GetBinContent(2), nL1) * 100)) self.commandLine.output( '###############################################') nL1Reco = hL1Reco.GetBinContent(2) nL1RecoHo = hL1RecoHo.GetBinContent(2) nL1RecoHoTight = hL1RecoHoTight.GetBinContent(2) nL1RecoTight = hL1RecoTight.GetBinContent(2) nL1RecoTightHo = hL1RecoTightHo.GetBinContent(2) N_BINS = 4 binContents = [nL1, nL1Reco, nL1RecoHo, nL1RecoHoTight] binLabels = [ 'L1', 'L1 -> Reco', 'L1 + R -> HO', 'L1 + R + HO -> tight' ] binContentsInverted = [nL1, nL1Reco, nL1RecoTight, nL1RecoTightHo] binLabelsInverted = [ 'L1', 'L1 -> Reco', 'L1 + R -> tight', 'L1 + R + tight -> HO' ] c = TCanvas('cL1AndTightL1Count', 'L1AndTightL1Count') h = TH1D('hL1AndTightL1Count', 'L1 Cutflow', 4, -0.5, N_BINS - .5) hInverted = TH1D('hL1AndTightL1CountInverted', 'L1 Efficiency', 4, -0.5, N_BINS - .5) hInverted.SetFillStyle(3002) hInverted.SetFillColor(colorRwthOrange) hInverted.SetLineColor(colorRwthOrange) hInverted.SetLineStyle(3) hL13x3Alone = TH1D('hL1And3x3Alone', '', 1, 1.5, 2.5) hL13x3Alone.SetBinContent(1, nL1RecoHo / nL1Reco) hL13x3Alone.SetBinError(1, calcSigma(nL1RecoHo, nL1Reco)) hL13x3Alone.SetLineColor(colorRwthMagenta) hTightL13x3Alone = TH1D('hTightL1And3x3Alone', '', 1, 2.5, 3.5) hTightL13x3Alone.SetBinContent(1, nL1RecoHoTight / nL1RecoHo) hTightL13x3Alone.SetBinError(1, calcSigma(nL1RecoHoTight, nL1RecoHo)) hTightL13x3Alone.SetLineColor(colorRwthTuerkis) for i in range(2, N_BINS + 1): h.SetBinContent(i, binContents[i - 1] / binContents[1]) h.GetXaxis().SetBinLabel(i, binLabels[i - 1]) hInverted.SetBinContent( i, binContentsInverted[i - 1] / binContentsInverted[1]) hInverted.GetXaxis().SetBinLabel(i, binLabelsInverted[i - 1]) h.GetXaxis().SetBinLabel(1, 'L1') h.SetBinContent(1, 1) hInverted.GetXaxis().SetBinLabel(1, 'L1') hInverted.SetBinContent(1, 1) h.SetLineColor(colorRwthDarkBlue) h.SetStats(0) h.GetYaxis().SetTitle('rel. fraction') h.Draw() # hL13x3Alone.Draw('same e') # hTightL13x3Alone.Draw('same e') hInverted.Draw('same') hInverted.GetXaxis().Draw('same') setupAxes(h) legend = getLegend(y2=.9, x1=.55) legend.AddEntry(h, 'First match HO then use tight', 'l') # legend.AddEntry(hL13x3Alone,'3x3 matching normed to # L1 + R','le') # legend.AddEntry(hTightL13x3Alone,'Normed to # L1 + R + HO','l') legend.AddEntry(hInverted, 'Inverted order for HO and tight', 'f') legend.Draw() label = self.drawLabel() textObjects = [] #for (Int_t i=1;i<=30;i++) t.DrawText(h->GetBinCenter(i),yt,Form("%d",i%10)); for i in range(1, 4): t = TText() t.SetTextSize(0.025) t.SetTextAlign(22) t.SetTextColor(colorRwthOrange) t.DrawTextNDC(getXinNDC(hInverted.GetBinCenter(i + 1)), 0.05, binLabelsInverted[i]) # Double_t yt = - h->GetMaximum()/15.; textObjects.append(t) c.Update() self.storeCanvas(c, 'l1AndTightL1Counters') return h, c, hL13x3Alone, hTightL13x3Alone, label, legend, hInverted, textObjects