def getEfficiencyTGraph(ifile, label, geometry, rebin=1): ''' Return a reconstruction efficiency TGraph ''' denominatorLabel = "nHits{0}_{1}".format(label, geometry) nHitsPt = ifile.Get(denominatorLabel).Clone() nHitsPt.Sumw2() numeratorLabel = "recoTrackHit{0}_true_{1}".format(label, geometry) recoTrackPt_true = ifile.Get(numeratorLabel).Clone() recoTrackPt_true.Sumw2() binslist2 = [x / 2.0 for x in range(0, 21 * 2)] # *2 since we want 0.5 bin width binslist2 += [ 22.0, 24.0, 26.0, 28.0, 30.0, 35.0, 40.0, 50.0, 60.0, 80.0, 100.0 ] binsarray2 = array('d', binslist2) recoTrackPt_true = rebin_plot(recoTrackPt_true, binsarray2) nHitsPt = rebin_plot(nHitsPt, binsarray2) #recoTrackPt_true.Rebin(rebin) #nHitsPt.Rebin(rebin) recoEfficiency = TGraphAsymmErrors(recoTrackPt_true, nHitsPt) recoEfficiency.SetName(recoEfficiency.GetName() + rand_uuid()) return recoEfficiency
def __init__(self, client_info, database): self.token = rand_uuid() self.client_info = client_info self.database = database self.client_log = [] self.client_o_ids = [] self.number_of_client_entries = None self.apply_error = None self.expires = time.time() + 60*60 self.backup_file = self.database.backup() self.database.set_sync_partner_info(client_info)
def drawMultigraph(legendPosition, title, saveName, geometries, graphDict): newCan = TCanvas("newCan" + title + rand_uuid(), "", 500, 500) newCan.SetLeftMargin(0.15) smallestYvalue = 999.0 largestYvalue = -11.0 theGraph = TMultiGraph(rand_uuid(), rand_uuid()) leg = prepareLegend(legendPosition) for geometry in geometries: # find min and max of the TGraphs ... kinda defeats the point of the multigraph ... but yeah ... minX = Double(0.) minY = Double(0.) maxY = Double(0.) dummy = graphDict[geometry].GetPoint(0, minX, minY) dummy = graphDict[geometry].GetPoint(graphDict[geometry].GetN() - 1, minX, maxY) if float(minY) < smallestYvalue: smallestYvalue = minY if float(maxY) > largestYvalue: largestYvalue = maxY theGraph.Add(graphDict[geometry], 'p') theGraph.SetTitle(title) leg.AddEntry(graphDict[geometry], '{0} mm'.format(geometry), 'lp') theGraph.Draw('a') theGraph.GetHistogram().GetYaxis().SetTitleOffset(1.75) leg.Draw() newCan.SaveAs(saveName) # Draw with log y theGraph.GetHistogram().SetMinimum(smallestYvalue / 5) theGraph.GetHistogram().SetMaximum(largestYvalue * 5) newCan.SetLogy(1) saveName = saveName.replace(".pdf", "_log.pdf") newCan.SaveAs(saveName)
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(verbose): BDTMode = False DeltaKappaMode = not BDTMode #pileups = range(0, 1100, 100) pileups = [100, 200, 1000] spacings = [ "Tracks10", "Tracks20", "Tracks30", "Tracks40", "Tracks50", ] colourMap = { "Tracks10": colours.blue, "Tracks20": colours.orange, "Tracks30": colours.red, "Tracks40": colours.green, "Tracks50": colours.grey } bdtCuts = [ -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 ] deltaKappaCuts = range(20, 301, 25) deltaKappaCuts = [ float(x) / 100000.0 for x in range(25, 201, 25) ] # would limit to 301, but already a harsher cut is implemented if BDTMode: cutList = bdtCuts else: cutList = deltaKappaCuts for PILEUP in pileups: can = TCanvas("can" + rand_uuid(), "can", 500, 500) theGraphs = {} leg = prepareLegend("bottomLeft") for spacing in spacings: print 'Drawing for spacing', spacing counter = 0 theGraphs[spacing] = TGraph() theGraphs[spacing].SetMarkerColor(colourMap[spacing]) theGraphs[spacing].SetLineColor(colourMap[spacing]) theGraphs[spacing].SetMaximum(1) theGraphs[spacing].SetMinimum(0.995) theGraphs[spacing].SetMarkerStyle(20) leg.AddEntry(theGraphs[spacing], spacing, 'lp') print "Cut\t<efficiency>\t1-<fake rate>" for cut in cutList: if BDTMode: jFileName = "/atlas/data4/userdata/wfawcett/delphes/results/processedTracks_ROCscan_BDTspecific_{0}/hits_ttbar_pu{1}_multiGeometry.json".format( cut, PILEUP) else: jFileName = "/atlas/data4/userdata/wfawcett/delphes/results/processedTracks_ROCscan_deltaKappa_{0}/hits_ttbar_pu{1}_multiGeometry.json".format( cut, PILEUP) #print 'reading', jFileName # load json file with open(jFileName) as data_file: trackDict = json.load(data_file) # want to plot efficiency and fake rejection for tracks with pT > 2 trackInfo = trackDict[spacing] # number of tracks surviving nFakesPt2 = float(trackInfo["FakeSurviving"]["Pt2"]) nTruesPt2 = float(trackInfo["TrueSurviving"]["Pt2"]) # fake rate is the fraction of (surviving) tracks that are fakes averageFakeRate = nFakesPt2 / (nFakesPt2 + nTruesPt2) # Average efficiency is fraction of true tracks surviving nTrueOriginalPt2 = float(trackInfo["TrueOriginal"]["Pt2"]) averageEfficiency = nTruesPt2 / nTrueOriginalPt2 print '{0} \t {1:.4f} \t {2:.4f}'.format( cut, averageEfficiency, 1 - averageFakeRate) theGraphs[spacing].SetPoint(counter, averageEfficiency, 1 - averageFakeRate) counter += 1 #___________________________________________________________ mg = TMultiGraph() for spacing in spacings: mg.Add(theGraphs[spacing], 'lp') if BDTMode: mg.SetTitle( "BDT pileup={0};Average efficiency;1 - Fake Rate".format( PILEUP)) if DeltaKappaMode: mg.SetTitle( "|#Delta#kappa| pileup={0};Average efficiency;1 - Fake Rate". format(PILEUP)) mg.Draw('a') leg.Draw() if BDTMode: can.SaveAs("BDT_ROC_pu{0}.pdf".format(PILEUP)) if DeltaKappaMode: can.SaveAs("Dk_ROC_pu{0}.pdf".format(PILEUP))