def efficiencyPerSpacing(path, geometry, pileups): ''' Plot reconstruction efficiency for fixed triplet spacing, varying pileup ''' can = TCanvas("can", "can", 500, 500) # get the histograms #leg = prepareLegend('topRight') leg = TLegend(0.725, 0.725, .98, .98) leg.SetTextSize(TEXT_SIZE) leg.SetHeader("ttbar + pileup") counter = 0 theGraphs = {} for pu in pileups: fName = path + "hits_ttbar_pu{0}_multiGeometry.root".format(pu) ifile = TFile.Open(fName) recoEfficiency = getEfficiencyTGraph(ifile, "Pt", geometry, 1) recoEfficiency.SetTitle("") myText(0.25, 0.9, 'Triplet spacing: 30 mm', TEXT_SIZE) xaxis = recoEfficiency.GetXaxis() yaxis = recoEfficiency.GetYaxis() xaxis.SetRangeUser(0, 50) yaxis.SetRangeUser(0.9, 1.1) xaxis.SetTitle( "Outer Hit (Track) p_{T} [GeV]") # hit pT of the track ... yaxis.SetTitle("Reconstruction efficiency") yaxis.SetNdivisions(5, 5, 0) # Add colours if counter == 0: icol = colours.blue elif counter == 1: icol = colours.orange elif counter == 2: icol = colours.red recoEfficiency.SetMarkerColor(icol) recoEfficiency.SetLineColor(icol) theGraphs[pu] = recoEfficiency leg.AddEntry(recoEfficiency, '#LT#mu#GT = {0}'.format(pu), 'lp') if counter == 0: recoEfficiency.Draw("APEl") else: recoEfficiency.Draw("PEl same") counter += 1 recoEfficiency.GetHistogram().GetYaxis().SetTitleOffset(Y_AXIS_OFFSET) #recoEfficiency.GetHistogram().GetYaxis().SetTitleOffset(1.75) leg.Draw() can.SaveAs("reconstructionEfficiency{0}mm.pdf".format(geometry)) can.SaveAs("reconstructionEfficiency{0}mm.eps".format(geometry))
def plotSignalAcceptances(pu, branchPair, doTrack=True): # plot acceptances for (all) signal models for each of the track multiplicities TRACK = True TRACK = False hhFName = INPUT_DIR + 'mg_pp_hh_pu{0}.root'.format(pu) tthFName = INPUT_DIR + 'mg_pp_tth_pu{0}.root'.format(pu) print 'opening file', hhFName hhFile = TFile.Open(hhFName) tthFile = TFile.Open(tthFName) gStyle.SetGridStyle(3) gStyle.SetGridColor(kGray) can = TCanvas('can2', 'can', 500, 500) can.SetGrid() #can.SetLogx() if doTrack: NOBJECTS = 5 else: NOBJECTS = 7 for i in xrange(1, NOBJECTS): if doTrack: histName = '{1}_track{0}Pt'.format(i, branchPair[0]) histNamePB = '{1}_track{0}Pt'.format(i, branchPair[1]) else: histName = '{1}_jet{0}Pt'.format(i, branchPair[0]) histNamePB = '{1}_jet{0}Pt'.format(i, branchPair[1]) print histName print histNamePB hhPlot_base = hhFile.Get(histName) tthPlot_base = tthFile.Get(histName) hhPlot_base2 = hhFile.Get(histNamePB) tthPlot_base2 = tthFile.Get(histNamePB) #print type(hhPlot_base) hhPlot = getReverseCumulativeHisto(hhPlot_base) hhPlotPB = getReverseCumulativeHisto(hhPlot_base2) tthPlot = getReverseCumulativeHisto(tthPlot_base) tthPlotPB = getReverseCumulativeHisto(tthPlot_base2) # colours REBIN = 1 hhPlot.Rebin(REBIN) tthPlot.Rebin(REBIN) hhPlot.SetLineColor(colours.darkRed) hhPlot.SetMarkerColor(colours.darkRed) tthPlot.SetLineColor(colours.darkBlue) tthPlot.SetMarkerColor(colours.darkBlue) hhPlotPB.SetLineColor(colours.darkRed) hhPlotPB.SetMarkerColor(colours.darkRed) tthPlotPB.SetLineColor(colours.darkBlue) tthPlotPB.SetMarkerColor(colours.darkBlue) # markers hhPlot.SetMarkerStyle(24) tthPlot.SetMarkerStyle(32) hhPlotPB.SetMarkerStyle(20) tthPlotPB.SetMarkerStyle(23) # size (if gStyle didn't work) hhPlot.SetTitleSize(TITLE_SIZE, 'X') hhPlot.SetLabelSize(TITLE_SIZE, 'X') hhPlot.SetTitleSize(TITLE_SIZE, 'Y') hhPlot.SetLabelSize(TITLE_SIZE, 'Y') # Legend aLeg = TLegend(0.57, 0.54, 0.85, 0.73) aLeg.SetTextSize(TEXT_SIZE) aLeg.AddEntry(hhPlot, 'HH (all tracks)', 'lp') aLeg.AddEntry(tthPlot, 'ttH (all tracks)', 'lp') aLeg.AddEntry(hhPlotPB, 'HH (PB tracks)', 'lp') aLeg.AddEntry(tthPlotPB, 'ttH (PB tracks)', 'lp') xaxis = hhPlot.GetXaxis() yaxis = hhPlot.GetYaxis() yaxis.SetTitle('Acceptance') xaxis.SetNdivisions(5, 5, 0) xaxis.SetTitleOffset(X_AXIS_OFFSET) yaxis.SetTitleOffset(Y_AXIS_OFFSET) # For tracks if doTrack: xaxis.SetTitle('Track {0}'.format(i) + ' p_{T} [GeV]') xaxis.SetRangeUser(0, 175) if i == 1: xaxis.SetRangeUser(0, 175) if i == 2: xaxis.SetRangeUser(0, 150) if i == 3: xaxis.SetRangeUser(0, 70) if i == 4: xaxis.SetRangeUser(0, 50) else: # for jets xaxis.SetTitle('Track Jet {0}'.format(i) + ' p_{T} [GeV]') xaxis.SetRangeUser(X_MIN, 500) if i == 1: xaxis.SetRangeUser(X_MIN, 600) if i == 2: xaxis.SetRangeUser(X_MIN, 400) if i == 3: xaxis.SetRangeUser(X_MIN, 300) if i == 4: xaxis.SetRangeUser(X_MIN, 400) if i == 5: xaxis.SetRangeUser(X_MIN, 300) if i == 6: xaxis.SetRangeUser(X_MIN, 300) hhPlot.Draw() myText(0.57, 0.84, '#sqrt{s} = 100 TeV', TEXT_SIZE) myText(0.57, 0.79, 'Madgraph+pythia8', TEXT_SIZE) myText(0.57, 0.74, '#LT#mu#GT = {0}'.format(pu), TEXT_SIZE) myText(0.6, 0.5, '|#eta| < 2.0', TEXT_SIZE) tthPlot.Draw('same') hhPlotPB.Draw('same') tthPlotPB.Draw('same') aLeg.Draw() if doTrack: can.SaveAs(OUTPUD_BASE_DIR + '/signalAcceptances/{2}_{3}_pu{0}_track{1}Pt.pdf'. format(pu, i, branchPair[0], branchPair[1])) else: can.SaveAs(OUTPUD_BASE_DIR + '/signalAcceptances/{2}_{3}_pu{0}_jet{1}Pt.pdf'.format( pu, i, branchPair[0], branchPair[1]))
def makeRatePlot(scenarioSet, doTrack, outputBaseDir, plotDict, sample, pileup): gStyle.SetGridStyle(3) gStyle.SetGridColor(kGray) can = TCanvas("can3", "", 500, 500) can.SetGrid() can.SetLogy() #can.SetLogx() # scenario set contains the "nominal" objects and the PB matched objects outputDir = outputBaseDir + "Rates/" checkDir(outputDir) outputDir = outputDir + scenarioSet.keys()[0] + '/' checkDir(outputDir) plots = plotDict[scenarioSet.keys()[0]].keys() for plot in plots: pCounter = 0 #leg = prepareLegend('topRight') if doTrack: #leg = TLegend(0.55, 0.55, 0.8, 0.70) # legend for modified boarders leg = TLegend(0.65, 0.65, 0.9, 0.80) else: leg = TLegend(0.3, 0.5, 0.8, 0.70) leg.SetTextSize(TEXT_SIZE) for scenario in scenarioSet.keys(): # get style dict style = scenarioSet[scenario] # scale to trigger rate rate = plotDict[scenario][plot]['acceptance'] titleInfo = sampleInfo[sample] rate.Scale( 40 * 1e3 ) # scale to 40 MHz (appropriate for minbias, not for other samples) rate.SetTitleSize(TITLE_SIZE, 'X') rate.SetLabelSize(TITLE_SIZE, 'X') rate.SetTitleSize(TITLE_SIZE, 'Y') rate.SetLabelSize(TITLE_SIZE, 'Y') # style #rate.SetTitle("{0} #LT#mu#GT = {1}".format(titleInfo['title'], pileup)) xaxis = rate.GetXaxis() yaxis = rate.GetYaxis() yaxis.SetTitle('Rate [kHz]') rate.SetMinimum(300) # settings for larger font xaxis.SetNdivisions(5, 5, 0) xaxis.SetTitleOffset(X_AXIS_OFFSET) yaxis.SetTitleOffset(Y_AXIS_OFFSET) if doTrack: xaxis.SetRangeUser(0, 175) if '1Pt' in plot: xaxis.SetRangeUser(0, 175) if '2Pt' in plot: xaxis.SetRangeUser(0, 150) if '3Pt' in plot: xaxis.SetRangeUser(0, 70) if '4Pt' in plot: xaxis.SetRangeUser(0, 50) myText(0.65, 0.90, '#sqrt{s} = 100 TeV', TEXT_SIZE) myText(0.65, 0.85, '{0}'.format(titleInfo['title']), TEXT_SIZE) myText(0.65, 0.80, "#LT#mu#GT = {0}".format(pileup), TEXT_SIZE) else: myText(0.3, 0.80, '#sqrt{s} = 100 TeV', TEXT_SIZE) myText(0.3, 0.75, '{0}'.format(titleInfo['title']), TEXT_SIZE) myText(0.3, 0.70, "#LT#mu#GT = {0}".format(pileup), TEXT_SIZE) xaxis.SetRangeUser(X_MIN, 300) rate.SetMarkerStyle(style['marker']) rate.SetMarkerColor(style['colour']) rate.SetLineColor(style['colour']) if pCounter == 0: rate.Draw() #elif 'jet' in plot: # only draw PU supressed for jet histograms else: rate.Draw('same') pCounter += 1 leg.AddEntry(rate, style['leg'], 'lp') leg.Draw() can.SaveAs(outputDir + 'rate_{0}.pdf'.format(plot))
def main(): # gaussian parameters mean = 0.0 bunch_length = 75.0 # mm luminous_length = bunch_length / math.sqrt(2) print 'Calculation for pileup of ', PILEUP print 'Bunch length: {0} mm'.format(bunch_length) print 'Luminous length: {0} mm'.format(luminous_length) mygaus = TF1("mygaus", "TMath::Gaus(x,0," + str(luminous_length) + ")", -luminous_length * 5, luminous_length * 5) ######################################### # make some plots to show results ######################################### can = TCanvas('can', 'can', 500, 500) um = 1000 # units #____________________________________________ # Distribution of vertices #____________________________________________ vertices = TH1D("vertexDistribution", "", 100, -400 * um, 400 * um) vals = [] nEvents = 1000 weight = 1.0 / float(nEvents) for i in xrange(nEvents): val = mygaus.GetRandom() * um # um vertices.Fill(val, weight) vals.append(val) xaxis = vertices.GetXaxis() yaxis = vertices.GetYaxis() xaxis.SetTitle('Vertex z position [#mum]') xaxis.SetRangeUser(-250 * um, 250 * um) yaxis.SetTitle('Fraction') yaxis.SetRangeUser(0.0, 0.1) vertices.Draw() vertices.Fit( "gaus", "M" ) # M: "improve fit", Q: "quiet" (no printing), O: "Don't draw fit or histo myText(0.2, 0.80, '#LT#mu#GT = 1000', TEXT_SIZE) myText(0.2, 0.75, 'Luminous length = {0:.1f} mm'.format(luminous_length), TEXT_SIZE) theFit = vertices.GetFunction("gaus") can.SaveAs('vertexDistribution.pdf') #____________________________________________ # Distribution of distances between vertices #____________________________________________ distances = calculateDistances(vals, MAX_Z * um) can.SetLogy(1) dist = TH1D("distanceDistribution", "", 1000, 0, 10 * um) for d in distances: dist.Fill(d, weight) #distOriginal.GetXaxis().SetRangeUser(0, 1000) #dist = distOriginal.Clone('clone') xaxis = dist.GetXaxis() yaxis = dist.GetYaxis() meanDistance = dist.GetMean() print meanDistance xaxis.SetRangeUser(0, 100) yaxis.SetTitle('Fraction of vertices') xaxis.SetTitle('Distance between vertices, #deltaz [#mum]') dist.Rebin(2) dist.GetXaxis().SetRangeUser(0, 1000) dist.Draw('E') myText(0.45, 0.75, '#LT#mu#GT = 1000', TEXT_SIZE) myText(0.45, 0.8, 'Mean distance = 344 #mum', TEXT_SIZE) can.SaveAs('distance.pdf') #____________________________________________ # Cumulative distribution of vertex distances #____________________________________________ can.SetLogy(0) #distPc = getReverseCumulativeHisto(dist) distPc = dist.GetCumulative() xaxis = distPc.GetXaxis() yaxis = distPc.GetYaxis() xaxis.SetTitle('Distance between vertices, #deltaz [#mum]') yaxis.SetTitle('Fraction of vertices #deltaz < X') xaxis.SetRangeUser(0, 1500) yaxis.SetRangeUser(0, 1) distPc.SetMarkerStyle(20) distPc.Draw('E') distPc.SetLineWidth(3) # find where 95% is for ibin in xrange(0, distPc.GetNbinsX() + 1): yval = distPc.GetBinContent(ibin) if yval > 0.95: pc95bin = ibin break print '95% of distances are smaller than:' print ibin, distPc.GetBinCenter(ibin), distPc.GetBinContent(ibin) avVertex95 = distPc.GetBinCenter(ibin) myText(0.4, 0.6, '#LT#mu#GT = 1000', TEXT_SIZE) myText( 0.4, 0.5, '#LT#deltaz#GT_{Vertex}^{95%} #approx ' + '{0} #mum'.format(avVertex95), TEXT_SIZE) myText(0.4, 0.4, 'Bunch length = {0} mm'.format(bunch_length), TEXT_SIZE) #can.SaveAs('cumulativeDistance.pdf') ######################################### # More serious calculation ######################################### means = [] pc95s = [] pc05s = [] for i in xrange(1000): [mean, pc95, pc05] = calculateMeanAnd95(mygaus) means.append(mean) pc95s.append(pc95) pc05s.append(pc05) # calculate the mean of the mean mean95 = np.mean(pc95s) mean05 = np.mean(pc05s) meanMeans = np.mean(means) print '' print 'Average mean distance: {0} um'.format(meanMeans * 1000) print 'Average 95% distance: {0} um'.format(mean95 * 1000) print 'Average 05% distance: {0} um'.format(mean05 * 1000)
def fakeRatePerSpacing(path, geometry, pileups, label="Pt"): ''' Create plot of fake rate as a function of <label> (e.g. pT) for a given triplet spacing, varying pileup ''' can = TCanvas("can" + rand_uuid(), "can", 500, 500) fakeRates = {} leg = prepareLegend('topRight') leg = TLegend(0.725, 0.725, .98, .98) leg.SetTextSize(TEXT_SIZE) leg.SetHeader('ttbar + pileup') counter = 0 for pu in pileups: #print 'getting input histograms' fName = path + "hits_ttbar_pu{0}_multiGeometry.root".format(pu) ifile = TFile.Open(fName) nReco = ifile.Get("recoTrack{0}_{1}".format(label, geometry)).Clone() nReco.Sumw2() nRecoFake = ifile.Get("recoTrack{0}_fake_{1}".format( label, geometry)).Clone() nRecoFake.Sumw2() # rebin and create fake rate #print 'rebin' nReco = rebin_plot(nReco, binsarray) nRecoFake = rebin_plot(nRecoFake, binsarray) #print 'create rate' fakeRate = TGraphAsymmErrors(nRecoFake, nReco) fakeRate.SetName(fakeRate.GetName() + rand_uuid()) fakeRates[pu] = fakeRate #print 'style' xaxis = fakeRate.GetXaxis() yaxis = fakeRate.GetYaxis() yaxis.SetNdivisions(5, 5, 0) xaxis.SetRangeUser(0, 100) xaxis.SetTitle("Reconstructed Track p_{T} [GeV]") yaxis.SetRangeUser(0, 0.05) yaxis.SetTitleOffset(1.5) yaxis.SetTitle("Fake Rate") fakeRate.SetTitle('') myText(0.25, 0.9, 'Triplet spacing: 30 mm', TEXT_SIZE) # colour if counter == 0: icol = colours.blue elif counter == 1: icol = colours.orange elif counter == 2: icol = colours.red fakeRate.SetMarkerColor(icol) fakeRate.SetLineColor(icol) leg.AddEntry(fakeRate, "#LT#mu#GT = {0}".format(pu), "lp") if counter == 0: fakeRate.Draw("APE") else: fakeRate.Draw("PE same") #fakeRate.GetHistogram().GetYaxis().SetTitleOffset(1.75) fakeRate.GetHistogram().GetYaxis().SetTitleOffset(Y_AXIS_OFFSET) counter += 1 leg.Draw() can.SaveAs('fakeRate{0}mm.pdf'.format(geometry)) can.SaveAs('fakeRate{0}mm.eps'.format(geometry))
def main(): pileup = ["py8_pp_minbias_pu0.root"] signals = [ "mg_pp_tth_pu0.root", #"mg_pp_tt_nlo_pu0.root", "mg_pp_hh_pu0.root", ] toPlot = { #"allTrackEta": {'xrange' : [-10, 10], 'xtitle' : 'Truth Track #eta', 'logy' : 1}, "track1Eta": { 'xrange': [-6, 6], 'xtitle': 'Truth Track 1 #eta', 'logy': 1 }, #"allTrackPt": {'xrange' : [0, 100], 'xtitle' : 'Truth Track p_{T} [GeV]', 'logy' : 1}, "track1Pt": { 'xrange': [0, 150], 'xtitle': 'Truth Track 1 p_{T} [GeV]', 'logy': 1 }, "track2Pt": { 'xrange': [0, 100], 'xtitle': 'Truth Track 2 p_{T} [GeV]', 'logy': 1 }, "track3Pt": { 'xrange': [0, 100], 'xtitle': 'Truth Track 3 p_{T} [GeV]', 'logy': 1 }, "track4Pt": { 'xrange': [0, 100], 'xtitle': 'Truth Track 4 p_{T} [GeV]', 'logy': 1 } } colz = { "py8_pp_minbias_pu0.root": { 'col': colours.blue, 'leg': 'Minbias' }, "mg_pp_tth_pu0.root": { 'col': colours.orange, 'leg': 'ttH' }, "mg_pp_tt_nlo_pu0.root": { 'col': colours.purple, 'leg': 'ttbar' }, "mg_pp_hh_pu0.root": { 'col': colours.red, 'leg': 'HH' } } # open f*****g files files = {} for f in signals + pileup: files[f] = TFile.Open(STORE + f) can = TCanvas("can", "can", 500, 500) for plot in toPlot.keys(): storedPlots = {} counter = 0 leg = prepareLegend('topRight') for sig in pileup + signals: style = colz[sig] fName = STORE + sig #print 'opening', fName #print 'getting plot', plot h = files[sig].Get("TruthTrack_" + plot) h.Rebin(2) ''' if sig == 'py8_pp_minbias_pu0.root': h.Rebin(10) else: h.Rebin(2) ''' storedPlots[sig] = h h.SetMarkerColor(style['col']) h.SetLineColor(style['col']) xaxis = h.GetXaxis() yaxis = h.GetYaxis() xaxis.SetRangeUser(*toPlot[plot]['xrange']) xaxis.SetTitle(toPlot[plot]['xtitle']) yaxis.SetTitle('Frequency') print yaxis.GetXmin(), h.GetMinimum() #yaxis.SetRangeUser(yaxis.GetXmin(), yaxis.GetXmax()*1.1) # increase y range by 10% h.SetMaximum(h.GetMaximum() * 4) h.SetMinimum(1e-3) leg.AddEntry(h, style['leg'], 'lp') myText(0.2, 0.8, '#sqrt{s}=100 TeV', TEXT_SIZE) can.SetLogy(toPlot[plot]['logy']) if counter == 0: h.Draw('hist e2') else: h.Draw('hist e2 same') counter += 1 leg.Draw() can.SaveAs("particleProperties/" + plot + '.pdf') can.SaveAs("particleProperties/" + plot + '.eps') ''' counter = 0 for sig in signals: print type(storedPlots[sig]) if counter == 0: storedPlots[sig].Draw() else: storedPlots[sig].Draw('same') ''' print ''