def plot_and_get_sig(sig_hist, bkg_hist, input_name, total_sig, total_bkg, mva_name, prefix, out_name, lumi): out_dir = input_name if OUT_DIRECTORY: out_dir = OUT_DIRECTORY sig = get_sig_hist(sig_hist, bkg_hist, total_sig, total_bkg, lumi) set_graph_style(sig, kBlack) sig.SetTitle(";%s;significance" % mva_name) canv = TCanvas("sig", "", 800, 600) sig.Draw("a3") sig.Draw("lx") index_max = TMath.LocMax(sig.GetN(), sig.GetY()) sig_max = "%.1f #pm %.1f" % (sig.GetY()[index_max], sig.GetEY()[index_max]) leg = TLegend(0.2, 0.7, 0.5, 0.8) PlotStyle.legend(leg) leg.AddEntry(sig, "%s @%s/fb" % (sig_max, lumi), "l") #ATLASLabel(0.20,0.75,"Work in progress") #ATLASLumiLabel(0.20,0.895,str(lumi*0.001)) leg.Draw() save_canv(canv, prefix + input_name + out_name, out_dir + "_" + mva_name + out_name) return sig_max
def plotEventsInAcceptance(): c = TCanvas("c","c",1200,1200) gTdmiInGaNotConverted = file.Get("hoMuonAnalyzer/graphs/tdmiInGaNotDead") gTdmiInGa = PlotStyle.convertToHcalCoords(gTdmiInGaNotConverted) gTdmiInGa.GetXaxis().SetTitle("i#eta") gTdmiInGa.GetYaxis().SetTitle("i#phi") gTdmiInGa.SetMarkerStyle(6) gTdmiInGa.SetMarkerColor(PlotStyle.colorRwthDarkBlue) gTdmiInGa.SetTitle("#eta #phi plot of HO geom. Acceptance and not dead channels") gTdmiInGa.Draw("AP") pText = TPaveText(0.7,0.85,0.9,0.9,'NDC') pText.AddText('Total Events: %d' % (totalEvents)) pText.AddText('Events in Plot: %d' % (gTdmiInGa.GetN())) pText.SetBorderSize(1) pText.Draw() chimney1 = PlotStyle.chimney1 chimney2 = PlotStyle.chimney2 labelCmsPrivateSimulation = PlotStyle.getLabelCmsPrivateSimulation() chimney1Converted.Draw("same,l") chimney2Converted.Draw("same,l") labelCmsPrivateSimulation.Draw() legend = TLegend(0.1,0.87,0.3,0.9) legend.AddEntry(chimney2Converted,"chimney","l") legend.Draw() c.Update() c.SaveAs("plots/graphsEtaPhi/gTdmiInGaNotDead.png")
def plotNoL1AndTdmiInAcceptance(): c4 = TCanvas("c4","c4",1200,1200) gNoTrgNoL1TdmiInGa = file.Get("hoMuonAnalyzer/graphs/NoTrgNoL1TdmiInGA") gConvertedToiEtaiPhi = PlotStyle.convertToHcalCoords(gNoTrgNoL1TdmiInGa) gConvertedToiEtaiPhi.SetTitle('No Single #mu Trg, in HO Acceptance') gConvertedToiEtaiPhi.SetMarkerColor(PlotStyle.colorRwthDarkBlue) gConvertedToiEtaiPhi.Draw("AP") chimney1 = PlotStyle.chimney1 chimney2 = PlotStyle.chimney2 chimney1Converted = PlotStyle.convertToHcalCoords(chimney1) chimney2Converted = PlotStyle.convertToHcalCoords(chimney2) chimney1Converted.SetLineColor(PlotStyle.colorRwthMagenta) chimney2Converted.SetLineColor(PlotStyle.colorRwthMagenta) chimney1Converted.Draw('Same,l') chimney2Converted.Draw('Same,l') legend = TLegend(0.7,0.85,0.9,0.9) legend.AddEntry(chimney2Converted,"chimneys","le") legend.Draw() label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() c4.Update() #boxes = PlotStyle.drawHcalBoxesHcalCoords(c4) c4.SaveAs("plots/graphsEtaPhi/gNoTrgNoL1TdmiInGaHocoords.pdf") c4.SaveAs("plots/graphsEtaPhi/gNoTrgNoL1TdmiInGaHocoords.png") return c4,legend,chimney1Converted,chimney2Converted,gConvertedToiEtaiPhi
def plotHoAboveThr(): c5 = TCanvas("c5","c5",1200,1200) noTrgTdmiAboveThrNotConverted = file.Get("hoMuonAnalyzer/graphs/NoTrgTdmiAboveThr") noTrgTdmiAboveThr = PlotStyle.convertToHcalCoords(noTrgTdmiAboveThrNotConverted) noTrgTdmiAboveThr.GetXaxis().SetTitle("i#eta / a.u.") noTrgTdmiAboveThr.GetYaxis().SetTitle("i#phi / a.u.") noTrgTdmiAboveThr.SetMarkerStyle(6) noTrgTdmiAboveThr.SetMarkerColor(PlotStyle.colorRwthDarkBlue) noTrgTdmiAboveThr.SetTitle("#eta #phi plot of HO > 0.2 GeV in no Single #mu Trg. events") noTrgTdmiAboveThr.Draw("AP") pText = TPaveText(0.7,0.85,0.9,0.9,'NDC') pText.AddText('No Single #mu in GA: %d' % (noSingleMuEventsInGa)) pText.AddText('Events in Plot: %d' % (noTrgTdmiAboveThr.GetN())) pText.SetBorderSize(1) pText.Draw() chimney1 = PlotStyle.chimney1 chimney2 = PlotStyle.chimney2 labelCmsPrivateSimulation = PlotStyle.getLabelCmsPrivateSimulation() chimney1Converted.Draw("same,l") chimney2Converted.Draw("same,l") labelCmsPrivateSimulation.Draw() legend = TLegend(0.1,0.87,0.3,0.9) legend.AddEntry(chimney2Converted,"chimney","l") legend.Draw() #c5.SetGridY(0) #c5.SetGridX(0) c5.Update() c5.SaveAs("plots/graphsEtaPhi/gNoTrgTdmiHoAboveThr.png")
def doPlotPhiPtOfFailingMatches(): file = TFile.Open('L1MuonHistogram.root') #Prepare canvas canvas = TCanvas("canvasPtPhiHoMatchFail","PtPhiHoMatchFail",1200,1200) canvas.cd().Draw() #prepare histogram hist = file.Get("hoMuonAnalyzer/etaPhi/3D/NoTrgTdmiNotInGA_EtaPhiPt") stack = THStack(hist,"zy","2dStack","",-1,-1,-1,-1,"zy","") #Create new histogram and add the histograms from the stack histNew = TH2D("histPtEtaHoMatchFail","p_{T} vs. #phi distribution for events not in HO acceptance;#phi;p_{T} / 5 GeV;#",80, -3.2, 3.2,40,0,200) histNew.GetYaxis().SetTitleOffset(1.2) histNew.Sumw2() for i in stack.GetHists(): histNew.Add(i) gStyle.SetPalette(1) histNew.SetStats(0) PlotStyle.setupAxes(histNew) histNew.Draw('COLZ') canvas.Update() palette = histNew.FindObject("palette") palette.SetX1NDC(0.9) palette.SetX2NDC(0.92) #add label label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() canvas.Update() canvas.SaveAs('plots/NoL1NotInHoAcceptancePhiPt.pdf') canvas.SaveAs('plots/NoL1NotInHoAcceptancePhiPt.png') return canvas,hist,stack,histNew,label,palette,file
def compare_results(tree_test, tree_train, lumi, mva_names, out_name, total_sig_events, total_bkg_events, max_lines): roc_dict = {} for name, tree in tree_test.iteritems(): mva_name = mva_names[name] roc = get_roc_curve(tree, name, mva_name) roc_dict[name] = roc rocs = roc_dict.values() canv = TCanvas("comparison_roc", "", 800, 600) leg = TLegend(0.17, 0.17, 0.62, 0.6) PlotStyle.legend(leg) sortedRocs = [] for name, roc in roc_dict.iteritems(): max_sig = get_max_sig(tree_test[name], name, mva_names[name], total_sig_events[name], total_bkg_events[name], lumi) max_sig_train = get_max_sig(tree_train[name], name, mva_names[name], total_sig_events[name], total_bkg_events[name], lumi) #sig_diff = abs(max_sig - max_sig_train) area_test = get_area(tree_test[name], name, mva_names[name]) area_train = get_area(tree_train[name], name, mva_names[name]) diff_area = abs(area_test - area_train) print name, area_test, area_train, diff_area, max_sig, max_sig_train max_sig_error_string = get_max_sig_error(tree_test[name], name, mva_names[name], total_sig_events[name], total_bkg_events[name], lumi) sortedRocs.append((roc, name, diff_area, max_sig_error_string)) sortedRocs.sort(key=get_sig_from_tuple) if max_lines > len(sortedRocs): max_lines = len(sortedRocs) set_graph_style(sortedRocs[0][0], get_color(0, max_lines)) sortedRocs[0][0].SetTitle("; sig. eff.; bkg. rej.") sortedRocs[0][0].Draw("a l") leg.AddEntry(sortedRocs[0][0], "%s: %s %s/fb" % (sortedRocs[0][1], sortedRocs[0][3], lumi), "l") index = 1 for r in sortedRocs[1:max_lines]: set_graph_style(r[0], get_color(index, max_lines)) r[0].Draw("same l") leg.AddEntry(r[0], "%s: %s %s/fb" % (r[1], r[3], lumi), "l") index += 1 leg.Draw() save_canv(canv, out_name)
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 plot_and_save(hist, input_name, mva_name): rho = hist.GetCorrelationFactor() canv = TCanvas("corr_" + hist.GetName(), "", 800, 600) PlotStyle.canv_2d(canv, hist) hist.Draw("colz") PlotStyle.string(.03, .03, "#rho = %.2f" % rho) save_canv(canv, input_name, "corr_" + input_name + "_" + mva_name) canv.SetLogz() canv.Update() save_canv(canv, input_name + "_log", "corr_" + input_name + "_" + mva_name)
def doPlotEtaPtOfSuccessfulMatches(): file = TFile.Open('L1MuonHistogram.root') #Prepare canvas canvas = TCanvas("canvasPtEtaHoMatch", "PtEtaHoMatch", 1200, 1200) canvas.cd().Draw() #prepare histogram hist = file.Get("hoMuonAnalyzer/etaPhi/3D/NoTrgTdmiAboveThr_EtaPhiPt") stack = THStack(hist, "zx", "2dStack", "", -1, -1, -1, -1, "zx", "") #Create new histogram and add the histograms from the stack histNew = TH2D("histPtEtaHoMatch", "p_{T} vs. #eta distribution;#eta;p_{T} / 5 GeV;#", 40, -1.6, 1.6, 40, 0, 200) histNew.GetYaxis().SetTitleOffset(1.2) for i in stack.GetHists(): histNew.Add(i) gStyle.SetPalette(1) histNew.SetStats(0) histNew.Draw('COLZ') canvas.Update() palette = histNew.FindObject("palette") palette.SetX1NDC(0.9) palette.SetX2NDC(0.92) #add label label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() canvas.Update() canvas.SaveAs('plots/NoL1HoMatchPtEta.pdf') canvas.SaveAs('plots/NoL1HoMatchPtEta.png') return canvas, hist, stack, histNew, label, palette, file
def doPlotEtaPtOfSuccessfulMatches(): file = TFile.Open('L1MuonHistogram.root') #Prepare canvas canvas = TCanvas("canvasPtEtaHoMatch","PtEtaHoMatch",1200,1200) canvas.cd().Draw() #prepare histogram hist = file.Get("hoMuonAnalyzer/etaPhi/3D/NoTrgTdmiAboveThr_EtaPhiPt") stack = THStack(hist,"zx","2dStack","",-1,-1,-1,-1,"zx","") #Create new histogram and add the histograms from the stack histNew = TH2D("histPtEtaHoMatch","p_{T} vs. #eta distribution;#eta;p_{T} / 5 GeV;#",40,-1.6,1.6,40,0,200) histNew.GetYaxis().SetTitleOffset(1.2) for i in stack.GetHists(): histNew.Add(i) gStyle.SetPalette(1) histNew.SetStats(0) histNew.Draw('COLZ') canvas.Update() palette = histNew.FindObject("palette") palette.SetX1NDC(0.9) palette.SetX2NDC(0.92) #add label label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() canvas.Update() canvas.SaveAs('plots/NoL1HoMatchPtEta.pdf') canvas.SaveAs('plots/NoL1HoMatchPtEta.png') return canvas,hist,stack,histNew,label,palette,file
def plotGenEtaPhi(): c = TCanvas("canvasGenEtaPhi","canvas Gen Eta Phi",1200,1200) graph = file.Get('hoMuonAnalyzer/graphs/gen') graph.SetMarkerColor(PlotStyle.colorRwthDarkBlue) graph.SetMarkerStyle(2) graph.GetXaxis().SetTitleFont(62) graph.GetYaxis().SetTitleFont(62) graph.GetYaxis().SetLabelFont(62) graph.GetYaxis().SetTitle('#phi') graph.GetXaxis().SetTitle('#eta') graph.SetTitle('#eta #phi distribution for GEN') graph.Draw('AP') #CMS label label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() pText = TPaveText(0.7,0.85,0.9,0.9,'NDC') pText.SetBorderSize(1) pText.AddText('Total Events: %d' % (totalEvents)) pText.Draw() c.SaveAs('plots/genControlPlots/genEtaPhi.pdf') c.SaveAs('plots/genControlPlots/genEtaPhi.png') #Prepare histograms for eta and phi alone histPhi = TH1D('histGenPhi',"#phi GEN;#phi;#",80,-3.48,3.48) histEta = TH1D('histGenEta',"#eta GEN;#eta;#",40,-1.74,1.74) #Get the data from the graph x = Double(0) y = Double(0) for i in range(0,graph.GetN()): graph.GetPoint(i,x,y) histPhi.Fill(y) histEta.Fill(x) #Draw phi histogram cPhi = TCanvas("canvasGenPhi","canvas Gen Phi",1200,1200) histPhi.SetStats(0) histPhi.Draw() label.Draw() cPhi.SaveAs('plots/genControlPlots/genPhi.pdf') cPhi.SaveAs('plots/genControlPlots/genPhi.pdf') #Draw eta histogram cEta = TCanvas("canvasGenEta","canvas Gen Eta",1200,1200) histEta.SetStats(0) histEta.Draw() label.Draw() cEta.SaveAs('plots/genControlPlots/genEta.pdf') cEta.SaveAs('plots/genControlPlots/genEta.pdf') return c,graph,label,histEta,histPhi,cEta,cPhi,pText
def plotGenEtaPhi(): c = TCanvas("canvasGenEtaPhi", "canvas Gen Eta Phi", 1200, 1200) graph = file.Get('hoMuonAnalyzer/graphs/gen') graph.SetMarkerColor(PlotStyle.colorRwthDarkBlue) graph.SetMarkerStyle(2) graph.GetXaxis().SetTitleFont(62) graph.GetYaxis().SetTitleFont(62) graph.GetYaxis().SetLabelFont(62) graph.GetYaxis().SetTitle('#phi') graph.GetXaxis().SetTitle('#eta') graph.SetTitle('#eta #phi distribution for GEN') graph.Draw('AP') #CMS label label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() pText = TPaveText(0.7, 0.85, 0.9, 0.9, 'NDC') pText.SetBorderSize(1) pText.AddText('Total Events: %d' % (totalEvents)) pText.Draw() c.SaveAs('plots/genControlPlots/genEtaPhi.pdf') c.SaveAs('plots/genControlPlots/genEtaPhi.png') #Prepare histograms for eta and phi alone histPhi = TH1D('histGenPhi', "#phi GEN;#phi;#", 80, -3.48, 3.48) histEta = TH1D('histGenEta', "#eta GEN;#eta;#", 40, -1.74, 1.74) #Get the data from the graph x = Double(0) y = Double(0) for i in range(0, graph.GetN()): graph.GetPoint(i, x, y) histPhi.Fill(y) histEta.Fill(x) #Draw phi histogram cPhi = TCanvas("canvasGenPhi", "canvas Gen Phi", 1200, 1200) histPhi.SetStats(0) histPhi.Draw() label.Draw() cPhi.SaveAs('plots/genControlPlots/genPhi.pdf') cPhi.SaveAs('plots/genControlPlots/genPhi.pdf') #Draw eta histogram cEta = TCanvas("canvasGenEta", "canvas Gen Eta", 1200, 1200) histEta.SetStats(0) histEta.Draw() label.Draw() cEta.SaveAs('plots/genControlPlots/genEta.pdf') cEta.SaveAs('plots/genControlPlots/genEta.pdf') return c, graph, label, histEta, histPhi, cEta, cPhi, pText
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
def plot_and_get_sig(train_tree, test_tree, input_name, total_sig, total_bkg, nbins, min, max, mva_name, lumi, output): sig_train = get_sig(train_tree, "train", mva_name, total_sig, total_bkg, lumi, nbins, min, max) sig_test = get_sig(test_tree, "test", mva_name, total_sig, total_bkg, lumi, nbins, min, max) set_graph_style(sig_train, kRed + 1) set_graph_style(sig_test, kBlack) sig_test.SetTitle(";%s;significance" % mva_name) canv = TCanvas("sig", "", 800, 600) sig_test.Draw("a3") sig_train.Draw("3") sig_test.Draw("lx") sig_train.Draw("lx") index_max_train = TMath.LocMax(sig_train.GetN(), sig_train.GetY()) sig_train_max = (sig_train.GetY()[index_max_train], sig_train.GetEY()[index_max_train]) index_max_test = TMath.LocMax(sig_test.GetN(), sig_test.GetY()) sig_test_max = (sig_test.GetY()[index_max_test], sig_test.GetEY()[index_max_test]) leg = TLegend(0.2, 0.75, 0.6, 0.9) PlotStyle.legend(leg) leg.AddEntry( sig_train, "Train: %.1f #pm %.1f @%s/fb" % (sig_train_max[0], sig_train_max[1], lumi), "l") leg.AddEntry( sig_test, "Test: %.1f #pm %.1f @%s/fb" % (sig_test_max[0], sig_test_max[1], lumi), "l") leg.Draw() save_canv(canv, input_name, output) return sig_train_max, sig_test_max
def plotAllEventsInAcceptance(): c = TCanvas("c","c",1200,1200) gTdmiInGa = file.Get("hoMuonAnalyzer/graphs/tdmiInGA") gTdmiInGa = PlotStyle.convertToHcalCoords(gTdmiInGa) gTdmiInGa.GetXaxis().SetTitle("i#eta / a.u.") gTdmiInGa.GetYaxis().SetTitle("i#phi / a.u.") gTdmiInGa.SetMarkerStyle(6) gTdmiInGa.SetMarkerColor(PlotStyle.colorRwthDarkBlue) gTdmiInGa.Draw("AP") pText = TPaveText(0.7,0.85,0.9,0.9,'NDC') pText.AddText('Total Events: %d' % (totalEvents)) pText.AddText('Events in Plot: %d' % (gTdmiInGa.GetN())) pText.SetBorderSize(1) pText.Draw() chimney1 = PlotStyle.chimney1 chimney2 = PlotStyle.chimney2 chimney1Converted = PlotStyle.convertToHcalCoords(chimney1) chimney2Converted = PlotStyle.convertToHcalCoords(chimney2) chimney1Converted.SetLineColor(PlotStyle.colorRwthMagenta) chimney2Converted.SetLineColor(PlotStyle.colorRwthMagenta) chimney1Converted.Draw("same,l") chimney2Converted.Draw("same,l") labelCmsPrivateSimulation = PlotStyle.getLabelCmsPrivateSimulation() labelCmsPrivateSimulation.Draw() legend = TLegend(0.1,0.87,0.3,0.9) legend.AddEntry(chimney2Converted,"chimney","l") legend.Draw() c.Update() c.SaveAs("plots/graphsEtaPhi/gTdmiInGa.pdf") c.SaveAs("plots/graphsEtaPhi/gTdmiInGa.png") return c,chimney1Converted,chimney2Converted,gTdmiInGa,pText
def doPlotPhiPtOfFailingMatches(): file = TFile.Open('L1MuonHistogram.root') #Prepare canvas canvas = TCanvas("canvasPtPhiHoMatchFail", "PtPhiHoMatchFail", 1200, 1200) canvas.cd().Draw() #prepare histogram hist = file.Get("hoMuonAnalyzer/etaPhi/3D/NoTrgTdmiNotInGA_EtaPhiPt") stack = THStack(hist, "zy", "2dStack", "", -1, -1, -1, -1, "zy", "") #Create new histogram and add the histograms from the stack histNew = TH2D( "histPtEtaHoMatchFail", "p_{T} vs. #phi distribution for events not in HO acceptance;#phi;p_{T} / 5 GeV;#", 80, -3.2, 3.2, 40, 0, 200) histNew.GetYaxis().SetTitleOffset(1.2) histNew.Sumw2() for i in stack.GetHists(): histNew.Add(i) gStyle.SetPalette(1) histNew.SetStats(0) PlotStyle.setupAxes(histNew) histNew.Draw('COLZ') canvas.Update() palette = histNew.FindObject("palette") palette.SetX1NDC(0.9) palette.SetX2NDC(0.92) #add label label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() canvas.Update() canvas.SaveAs('plots/NoL1NotInHoAcceptancePhiPt.pdf') canvas.SaveAs('plots/NoL1NotInHoAcceptancePhiPt.png') return canvas, hist, stack, histNew, label, palette, file
def plot_and_get_sig(sig_hist, bkg_hist, input_name, total_sig, total_bkg, mva_name, k_fold, lumi): sig = get_sig_hist(sig_hist, bkg_hist, total_sig, total_bkg, lumi) set_graph_style(sig, kBlack) sig.SetTitle(";%s;significance" % mva_name) canv = TCanvas("sig", "", 800, 600) sig.Draw("a3") sig.Draw("lx") sig_max = TMath.MaxElement(sig.GetN(), sig.GetY()) leg = TLegend(0.2, 0.75, 0.6, 0.9) PlotStyle.legend(leg) leg.AddEntry(sig, "%.1f @%s/fb" % (sig_max, lumi), "l") leg.Draw() save_canv(canv, input_name, input_name + "_" + mva_name + "_" + str(k_fold)) return sig_max
sample["chain"].Draw(var["varStr"]+">>"+histos[sample["name"]][var["name"]].GetName(), "("+weightString+") * ("+cutString+")","goff") for var in allVariables: canv = ROOT.TCanvas(var['name']+'_Window',var['name']+'_Window',600,500) if setRatioPlot: pad1 = ROOT.TPad('pad1','pad1',0.,0.3,1.,1.) pad1.SetBottomMargin(0.018) pad1.SetRightMargin(0.08) else: pad1 = ROOT.TPad('pad1','pad1',0.,0.,1.,1.) if setLogY: pad1.SetLogy() pad1.Draw() pad1.cd() legend = ROOT.TLegend(0.6,0.9-len(allBkg)*0.06,0.88,0.9) PS.legend(legend) first = True nMax = 0. for sample in allBkg: print sample['name'] histos[sample['name']][var['name']].SetLineColor(sample['color']) histos[sample['name']][var['name']].SetLineWidth(2) #histos[sample['name']][var['name']].SetFillColor(sample['color']) histos[sample['name']][var['name']].SetMarkerStyle(20) histos[sample['name']][var['name']].SetMarkerColor(sample['color']) histos[sample['name']][var['name']].SetMarkerSize(0.85) histos[sample['name']][var['name']].GetXaxis().SetTitle(var['Xtitle']) histos[sample['name']][var['name']].GetYaxis().SetTitle(var['Ytitle'])# / '+ str( (var['binning'][2] - var['binning'][1])/var['binning'][0])+'GeV') if setRatioPlot: histos[sample['name']][var['name']].GetXaxis().SetLabelSize(0.0)
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 ]
clsexp = triwsmooth(exampleHarvest, "CLsexp", x, y, transformation=transformation, smooth=smooth, npx=npx, npy=npy) clsexp_up = triwsmooth(exampleHarvest, "clsu1s", x, y, transformation=transformation, smooth=smooth, npx=npx, npy=npy) clsexp_down = triwsmooth(exampleHarvest, "clsd1s", x, y, transformation=transformation, smooth=smooth, npx=npx, npy=npy) fixedhist = FixAndSetBorders(clsexp, "cls", "cls") fixedhist_up = FixAndSetBorders(clsexp_up, "cls_up", "cls_up") fixedhist_down = FixAndSetBorders(clsexp_down, "cls_down", "cls_down") #contours = getContours(fixedhist, level) #contours_up = getContours(fixedhist_up, level) #contours_down = getContours(fixedhist_down, level) #errorband = myOneSigmaBand(contours_up[0], contours_down[0]) contours_5 = getContours(fixedhist, 5) contours_3 = getContours(fixedhist, 3) c = ROOT.TCanvas() c.SetRightMargin(0.15) leg = ROOT.TLegend(0.18, PS.ThirdLine-0.12, 0.4, PS.ThirdLine-0.03) PS.legend(leg) numbers = drawNumbers(exampleHarvest, "CLsexp", x, y, drawOnlyDots=True) fixedhist.Draw("colz") fixedhist.SetMinimum(0.01) fixedhist.GetXaxis().SetTitle('m_{#tilde{t}_{1}}') fixedhist.GetYaxis().SetTitle('m_{#tilde{#chi}_{1}}') #errorband.SetFillStyle(3354) #errorband.SetFillColor(ROOT.kBlack) #errorband.Draw("f same") #for contour in contours_up + contours_down: for contour in contours_3: contour.SetLineColor(ROOT.kBlack) contour.SetLineStyle(7) contour.Draw("l same") #for contour in contours: for contour in contours_5:
def plot_mlp_distribution(train_tree, test_tree, input_name, nbins, min, max, mva_name, output): mlp_train_sig, mlp_train_bkg = load_mlp(train_tree, "train", mva_name, nbins, min, max, norm=True) mlp_test_sig, mlp_test_bkg = load_mlp(test_tree, "test", mva_name, nbins, min, max, norm=True) # save all bdt distributions if output: try: os.makedirs(os.path.join(output, "bdt_dist")) except: pass outfile = TFile(os.path.join(output, "bdt_dist", input_name + ".root"), "recreate") outfile.WriteTObject(mlp_test_sig, "mlp_test_sig") outfile.WriteTObject(mlp_train_sig, "mlp_train_sig") outfile.WriteTObject(mlp_test_bkg, "mlp_test_bkg") outfile.WriteTObject(mlp_train_bkg, "mlp_train_bkg") outfile.Close() set_style(mlp_test_sig, kRed) set_style(mlp_train_sig, kRed) set_style(mlp_test_bkg, kBlue) set_style(mlp_train_bkg, kBlue) # plot train and test canv = TCanvas("train_test", "", 800, 600) mlp_test_bkg.SetTitle("; %s; fraction of events" % mva_name) mlp_test_bkg.GetYaxis().SetRangeUser(0, mlp_test_bkg.GetMaximum() * 1.8) mlp_test_bkg.Draw("hist") mlp_test_sig.Draw("same hist") mlp_train_sig.Draw("same p") mlp_train_bkg.Draw("same p") leg = TLegend(0.2, 0.7, 0.5, 0.9) leg.AddEntry(mlp_test_sig, "Signal Test", "f") leg.AddEntry(mlp_test_bkg, "Background Test", "f") leg.AddEntry(mlp_train_sig, "Signal Train", "pl") leg.AddEntry(mlp_train_bkg, "Background Train", "pl") leg.Draw("same") kolmogorov_bkg = mlp_test_bkg.KolmogorovTest(mlp_train_bkg) kolmogorov_sig = mlp_test_sig.KolmogorovTest(mlp_train_sig) chi2_bkg = mlp_test_bkg.Chi2Test(mlp_train_bkg, "WW CHI2/NDF") chi2_sig = mlp_test_sig.Chi2Test(mlp_train_sig, "WW CHI2/NDF") PlotStyle.string(0.65, 0.85, "Kolomogorov Bkg: %1.2f" % kolmogorov_bkg, rel=0.7) PlotStyle.string(0.65, 0.8, "Kolomogorov Sig: %1.2f" % kolmogorov_sig, rel=0.7) PlotStyle.string(0.65, 0.75, "red. #chi^{2} Bkg: %1.2f" % chi2_bkg, rel=0.7) PlotStyle.string(0.65, 0.7, "red. #chi^{2} Sig: %1.2f" % chi2_sig, rel=0.7) save_canv(canv, input_name, output)
def main(): plotSig = True filename = "SR_RNN0p86-1p0" if plotSig: filename = filename + "_Significance" else: filename = filename + "_signal_contamination" wwwDir = "/project/etp5/dhandl/plots/Stop1L/FullRun2/SignifcanceScan/21.2.60/" if not os.path.exists(wwwDir): os.makedirs(wwwDir) print('Creating Directory...') bkgDir = '/project/etp3/dhandl/samples/SUSY/Stop1L/21.2.60_ML/' #sigDir = '/project/etp5/dhandl/myFork-stop1l/export/default/' sigDir = bkgDir lumi = str(140500.) cut = '(n_jet>=4) && (n_lep==1) && (lep_pt[0]>25e3) && (n_bjet>=1) && (mt>=110e3) && (met>=230e3) && (jet_pt[0]>=25e3) && (jet_pt[1]>=25e3) && (jet_pt[2]>=25e3) && (jet_pt[3]>=25e3) && (dphi_jet0_ptmiss > 0.4) && (dphi_jet1_ptmiss > 0.4) && !((mT2tauLooseTau_GeV > -0.5) && (mT2tauLooseTau_GeV < 80)) && (outputScore_RNN >= 0.86) && (outputScore_RNN<1.0)' weight = 'weight * xs_weight * lumi_weight * sf_total' sampleNames = [ { 'name': 'ttbar', 'target': [ bkgDir + 'mc16a_ttbar/*.root', bkgDir + 'mc16d_ttbar/*.root', bkgDir + 'mc16e_ttbar/*.root' ], 'chain_name': 'ttbar_Nom', 'class': 'bkg' }, { 'name': 'singletop', 'target': [ bkgDir + 'mc16a_singletop/*.root', bkgDir + 'mc16d_singletop/*.root', bkgDir + 'mc16e_singletop/*.root' ], 'chain_name': 'singletop_Nom', 'class': 'bkg' }, { 'name': 'wjets', 'target': [ bkgDir + 'mc16a_wjets/*.root', bkgDir + 'mc16d_wjets/*.root', bkgDir + 'mc16e_wjets/*.root' ], 'chain_name': 'wjets_Nom', 'class': 'bkg' }, { 'name': 'ttV', 'target': [ bkgDir + 'mc16a_ttV/*.root', bkgDir + 'mc16d_ttV/*.root', bkgDir + 'mc16e_ttV/*.root' ], 'chain_name': 'ttV_Nom', 'class': 'bkg' }, { 'name': 'multiboson', 'target': [ bkgDir + 'mc16a_multiboson/*.root', bkgDir + 'mc16d_multiboson/*.root', bkgDir + 'mc16e_multiboson/*.root' ], 'chain_name': 'multiboson_Nom', 'class': 'bkg' }, ### bWN ### { 'name': 'bWN_400_235', 'target': [ bkgDir + 'mc16a_bWN_400_235/*.root', bkgDir + 'mc16d_bWN_400_235/*.root', bkgDir + 'mc16e_bWN_400_235/*.root' ], 'chain_name': 'bWN_400_235_Nom', 'class': 'sig' }, { 'name': 'bWN_400_250', 'target': [ bkgDir + 'mc16a_bWN_400_250/*.root', bkgDir + 'mc16d_bWN_400_250/*.root', bkgDir + 'mc16e_bWN_400_250/*.root' ], 'chain_name': 'bWN_400_250_Nom', 'class': 'sig' }, { 'name': 'bWN_400_280', 'target': [ bkgDir + 'mc16a_bWN_400_280/*.root', bkgDir + 'mc16d_bWN_400_280/*.root', bkgDir + 'mc16e_bWN_400_280/*.root' ], 'chain_name': 'bWN_400_280_Nom', 'class': 'sig' }, { 'name': 'bWN_400_310', 'target': [ bkgDir + 'mc16a_bWN_400_310/*.root', bkgDir + 'mc16d_bWN_400_310/*.root', bkgDir + 'mc16e_bWN_400_310/*.root' ], 'chain_name': 'bWN_400_310_Nom', 'class': 'sig' }, { 'name': 'bWN_450_285', 'target': [ bkgDir + 'mc16a_bWN_450_285/*.root', bkgDir + 'mc16d_bWN_450_285/*.root', bkgDir + 'mc16e_bWN_450_285/*.root' ], 'chain_name': 'bWN_450_285_Nom', 'class': 'sig' }, { 'name': 'bWN_450_300', 'target': [ bkgDir + 'mc16a_bWN_450_300/*.root', bkgDir + 'mc16d_bWN_450_300/*.root', bkgDir + 'mc16e_bWN_450_300/*.root' ], 'chain_name': 'bWN_450_300_Nom', 'class': 'sig' }, { 'name': 'bWN_450_330', 'target': [ bkgDir + 'mc16a_bWN_450_330/*.root', bkgDir + 'mc16d_bWN_450_330/*.root', bkgDir + 'mc16e_bWN_450_330/*.root' ], 'chain_name': 'bWN_450_330_Nom', 'class': 'sig' }, { 'name': 'bWN_450_360', 'target': [ bkgDir + 'mc16a_bWN_450_360/*.root', bkgDir + 'mc16d_bWN_450_360/*.root', bkgDir + 'mc16e_bWN_450_360/*.root' ], 'chain_name': 'bWN_450_360_Nom', 'class': 'sig' }, { 'name': 'bWN_500_335', 'target': [ bkgDir + 'mc16a_bWN_500_335/*.root', bkgDir + 'mc16d_bWN_500_335/*.root', bkgDir + 'mc16e_bWN_500_335/*.root' ], 'chain_name': 'bWN_500_335_Nom', 'class': 'sig' }, { 'name': 'bWN_500_350', 'target': [ bkgDir + 'mc16a_bWN_500_350/*.root', bkgDir + 'mc16d_bWN_500_350/*.root', bkgDir + 'mc16e_bWN_500_350/*.root' ], 'chain_name': 'bWN_500_350_Nom', 'class': 'sig' }, { 'name': 'bWN_500_380', 'target': [ bkgDir + 'mc16a_bWN_500_380/*.root', bkgDir + 'mc16d_bWN_500_380/*.root', bkgDir + 'mc16e_bWN_500_380/*.root' ], 'chain_name': 'bWN_500_380_Nom', 'class': 'sig' }, { 'name': 'bWN_500_410', 'target': [ bkgDir + 'mc16a_bWN_500_410/*.root', bkgDir + 'mc16d_bWN_500_410/*.root', bkgDir + 'mc16e_bWN_500_410/*.root' ], 'chain_name': 'bWN_500_410_Nom', 'class': 'sig' }, { 'name': 'bWN_550_385', 'target': [ bkgDir + 'mc16a_bWN_550_385/*.root', bkgDir + 'mc16d_bWN_550_385/*.root', bkgDir + 'mc16e_bWN_550_385/*.root' ], 'chain_name': 'bWN_550_385_Nom', 'class': 'sig' }, { 'name': 'bWN_550_400', 'target': [ bkgDir + 'mc16a_bWN_550_400/*.root', bkgDir + 'mc16d_bWN_550_400/*.root', bkgDir + 'mc16e_bWN_550_400/*.root' ], 'chain_name': 'bWN_550_400_Nom', 'class': 'sig' }, { 'name': 'bWN_550_430', 'target': [ bkgDir + 'mc16a_bWN_550_430/*.root', bkgDir + 'mc16d_bWN_550_430/*.root', bkgDir + 'mc16e_bWN_550_430/*.root' ], 'chain_name': 'bWN_550_430_Nom', 'class': 'sig' }, { 'name': 'bWN_550_460', 'target': [ bkgDir + 'mc16a_bWN_550_460/*.root', bkgDir + 'mc16d_bWN_550_460/*.root', bkgDir + 'mc16e_bWN_550_460/*.root' ], 'chain_name': 'bWN_550_460_Nom', 'class': 'sig' }, { 'name': 'bWN_600_435', 'target': [ bkgDir + 'mc16a_bWN_600_435/*.root', bkgDir + 'mc16d_bWN_600_435/*.root', bkgDir + 'mc16e_bWN_600_435/*.root' ], 'chain_name': 'bWN_600_435_Nom', 'class': 'sig' }, { 'name': 'bWN_600_450', 'target': [ bkgDir + 'mc16a_bWN_600_450/*.root', bkgDir + 'mc16d_bWN_600_450/*.root', bkgDir + 'mc16e_bWN_600_450/*.root' ], 'chain_name': 'bWN_600_450_Nom', 'class': 'sig' }, { 'name': 'bWN_600_480', 'target': [ bkgDir + 'mc16a_bWN_600_480/*.root', bkgDir + 'mc16d_bWN_600_480/*.root', bkgDir + 'mc16e_bWN_600_480/*.root' ], 'chain_name': 'bWN_600_480_Nom', 'class': 'sig' }, { 'name': 'bWN_600_510', 'target': [ bkgDir + 'mc16a_bWN_600_510/*.root', bkgDir + 'mc16d_bWN_600_510/*.root', bkgDir + 'mc16e_bWN_600_510/*.root' ], 'chain_name': 'bWN_600_510_Nom', 'class': 'sig' }, { 'name': 'bWN_650_485', 'target': [ bkgDir + 'mc16a_bWN_650_485/*.root', bkgDir + 'mc16d_bWN_650_485/*.root', bkgDir + 'mc16e_bWN_650_485/*.root' ], 'chain_name': 'bWN_650_485_Nom', 'class': 'sig' }, { 'name': 'bWN_650_500', 'target': [ bkgDir + 'mc16a_bWN_650_500/*.root', bkgDir + 'mc16d_bWN_650_500/*.root', bkgDir + 'mc16e_bWN_650_500/*.root' ], 'chain_name': 'bWN_650_500_Nom', 'class': 'sig' }, { 'name': 'bWN_650_530', 'target': [ bkgDir + 'mc16a_bWN_650_530/*.root', bkgDir + 'mc16d_bWN_650_530/*.root', bkgDir + 'mc16e_bWN_650_530/*.root' ], 'chain_name': 'bWN_650_530_Nom', 'class': 'sig' }, { 'name': 'bWN_650_560', 'target': [ bkgDir + 'mc16a_bWN_650_560/*.root', bkgDir + 'mc16d_bWN_650_560/*.root', bkgDir + 'mc16e_bWN_650_560/*.root' ], 'chain_name': 'bWN_650_560_Nom', 'class': 'sig' }, { 'name': 'bWN_700_535', 'target': [ bkgDir + 'mc16a_bWN_700_535/*.root', bkgDir + 'mc16d_bWN_700_535/*.root', bkgDir + 'mc16e_bWN_700_535/*.root' ], 'chain_name': 'bWN_700_535_Nom', 'class': 'sig' }, { 'name': 'bWN_700_550', 'target': [ bkgDir + 'mc16a_bWN_700_550/*.root', bkgDir + 'mc16d_bWN_700_550/*.root', bkgDir + 'mc16e_bWN_700_550/*.root' ], 'chain_name': 'bWN_700_550_Nom', 'class': 'sig' }, { 'name': 'bWN_700_580', 'target': [ bkgDir + 'mc16a_bWN_700_580/*.root', bkgDir + 'mc16d_bWN_700_580/*.root', bkgDir + 'mc16e_bWN_700_580/*.root' ], 'chain_name': 'bWN_700_580_Nom', 'class': 'sig' }, { 'name': 'bWN_700_610', 'target': [ bkgDir + 'mc16a_bWN_700_610/*.root', bkgDir + 'mc16d_bWN_700_610/*.root', bkgDir + 'mc16e_bWN_700_610/*.root' ], 'chain_name': 'bWN_700_610_Nom', 'class': 'sig' }, { 'name': 'bWN_750_585', 'target': [ bkgDir + 'mc16a_bWN_750_585/*.root', bkgDir + 'mc16d_bWN_750_585/*.root', bkgDir + 'mc16e_bWN_750_585/*.root' ], 'chain_name': 'bWN_750_585_Nom', 'class': 'sig' }, { 'name': 'bWN_750_600', 'target': [ bkgDir + 'mc16a_bWN_750_600/*.root', bkgDir + 'mc16d_bWN_750_600/*.root', bkgDir + 'mc16e_bWN_750_600/*.root' ], 'chain_name': 'bWN_750_600_Nom', 'class': 'sig' }, { 'name': 'bWN_750_630', 'target': [ bkgDir + 'mc16a_bWN_750_630/*.root', bkgDir + 'mc16d_bWN_750_630/*.root', bkgDir + 'mc16e_bWN_750_630/*.root' ], 'chain_name': 'bWN_750_630_Nom', 'class': 'sig' }, { 'name': 'bWN_750_660', 'target': [ bkgDir + 'mc16a_bWN_750_660/*.root', bkgDir + 'mc16d_bWN_750_660/*.root', bkgDir + 'mc16e_bWN_750_660/*.root' ], 'chain_name': 'bWN_750_660_Nom', 'class': 'sig' }, ### bffN ### { 'name': 'bffN_300_220', 'target': [ bkgDir + 'mc16a_bffN_300_220/*.root', bkgDir + 'mc16d_bffN_300_220/*.root', bkgDir + 'mc16e_bffN_300_220/*.root' ], 'chain_name': 'bffN_300_220_Nom', 'class': 'sig' }, { 'name': 'bffN_300_250', 'target': [ bkgDir + 'mc16a_bffN_300_250/*.root', bkgDir + 'mc16d_bffN_300_250/*.root', bkgDir + 'mc16e_bffN_300_250/*.root' ], 'chain_name': 'bffN_300_250_Nom', 'class': 'sig' }, { 'name': 'bffN_300_280', 'target': [ bkgDir + 'mc16a_bffN_300_280/*.root', bkgDir + 'mc16d_bffN_300_280/*.root', bkgDir + 'mc16e_bffN_300_280/*.root' ], 'chain_name': 'bffN_300_280_Nom', 'class': 'sig' }, { 'name': 'bffN_300_293', 'target': [ bkgDir + 'mc16a_bffN_300_293/*.root', bkgDir + 'mc16d_bffN_300_293/*.root', bkgDir + 'mc16e_bffN_300_293/*.root' ], 'chain_name': 'bffN_300_293_Nom', 'class': 'sig' }, { 'name': 'bffN_350_270', 'target': [ bkgDir + 'mc16a_bffN_350_270/*.root', bkgDir + 'mc16d_bffN_350_270/*.root', bkgDir + 'mc16e_bffN_350_270/*.root' ], 'chain_name': 'bffN_350_270_Nom', 'class': 'sig' }, { 'name': 'bffN_350_300', 'target': [ bkgDir + 'mc16a_bffN_350_300/*.root', bkgDir + 'mc16d_bffN_350_300/*.root', bkgDir + 'mc16e_bffN_350_300/*.root' ], 'chain_name': 'bffN_350_300_Nom', 'class': 'sig' }, { 'name': 'bffN_350_330', 'target': [ bkgDir + 'mc16a_bffN_350_330/*.root', bkgDir + 'mc16d_bffN_350_330/*.root', bkgDir + 'mc16e_bffN_350_330/*.root' ], 'chain_name': 'bffN_350_330_Nom', 'class': 'sig' }, { 'name': 'bffN_350_243', 'target': [ bkgDir + 'mc16a_bffN_350_243/*.root', bkgDir + 'mc16d_bffN_350_243/*.root', bkgDir + 'mc16e_bffN_350_243/*.root' ], 'chain_name': 'bffN_350_243_Nom', 'class': 'sig' }, { 'name': 'bffN_400_320', 'target': [ bkgDir + 'mc16a_bffN_400_320/*.root', bkgDir + 'mc16d_bffN_400_320/*.root', bkgDir + 'mc16e_bffN_400_320/*.root' ], 'chain_name': 'bffN_400_320_Nom', 'class': 'sig' }, { 'name': 'bffN_400_350', 'target': [ bkgDir + 'mc16a_bffN_400_350/*.root', bkgDir + 'mc16d_bffN_400_350/*.root', bkgDir + 'mc16e_bffN_400_350/*.root' ], 'chain_name': 'bffN_400_350_Nom', 'class': 'sig' }, { 'name': 'bffN_400_380', 'target': [ bkgDir + 'mc16a_bffN_400_380/*.root', bkgDir + 'mc16d_bffN_400_380/*.root', bkgDir + 'mc16e_bffN_400_380/*.root' ], 'chain_name': 'bffN_400_380_Nom', 'class': 'sig' }, { 'name': 'bffN_400_393', 'target': [ bkgDir + 'mc16a_bffN_400_393/*.root', bkgDir + 'mc16d_bffN_400_393/*.root', bkgDir + 'mc16e_bffN_400_393/*.root' ], 'chain_name': 'bffN_400_393_Nom', 'class': 'sig' }, { 'name': 'bffN_450_370', 'target': [ bkgDir + 'mc16a_bffN_450_370/*.root', bkgDir + 'mc16d_bffN_450_370/*.root', bkgDir + 'mc16e_bffN_450_370/*.root' ], 'chain_name': 'bffN_450_370_Nom', 'class': 'sig' }, { 'name': 'bffN_450_400', 'target': [ bkgDir + 'mc16a_bffN_450_400/*.root', bkgDir + 'mc16d_bffN_450_400/*.root', bkgDir + 'mc16e_bffN_450_400/*.root' ], 'chain_name': 'bffN_450_400_Nom', 'class': 'sig' }, { 'name': 'bffN_450_430', 'target': [ bkgDir + 'mc16a_bffN_450_430/*.root', bkgDir + 'mc16d_bffN_450_430/*.root', bkgDir + 'mc16e_bffN_450_430/*.root' ], 'chain_name': 'bffN_450_430_Nom', 'class': 'sig' }, { 'name': 'bffN_450_443', 'target': [ bkgDir + 'mc16a_bffN_450_443/*.root', bkgDir + 'mc16d_bffN_450_443/*.root', bkgDir + 'mc16e_bffN_450_443/*.root' ], 'chain_name': 'bffN_450_443_Nom', 'class': 'sig' }, { 'name': 'bffN_500_420', 'target': [ bkgDir + 'mc16a_bffN_500_420/*.root', bkgDir + 'mc16d_bffN_500_420/*.root', bkgDir + 'mc16e_bffN_500_420/*.root' ], 'chain_name': 'bffN_500_420_Nom', 'class': 'sig' }, { 'name': 'bffN_500_450', 'target': [ bkgDir + 'mc16a_bffN_500_450/*.root', bkgDir + 'mc16d_bffN_500_450/*.root', bkgDir + 'mc16e_bffN_500_450/*.root' ], 'chain_name': 'bffN_500_450_Nom', 'class': 'sig' }, { 'name': 'bffN_500_480', 'target': [ bkgDir + 'mc16a_bffN_500_480/*.root', bkgDir + 'mc16d_bffN_500_480/*.root', bkgDir + 'mc16e_bffN_500_480/*.root' ], 'chain_name': 'bffN_500_480_Nom', 'class': 'sig' }, { 'name': 'bffN_500_493', 'target': [ bkgDir + 'mc16a_bffN_500_493/*.root', bkgDir + 'mc16d_bffN_500_493/*.root', bkgDir + 'mc16e_bffN_500_493/*.root' ], 'chain_name': 'bffN_500_493_Nom', 'class': 'sig' }, { 'name': 'bffN_550_470', 'target': [ bkgDir + 'mc16a_bffN_550_470/*.root', bkgDir + 'mc16d_bffN_550_470/*.root', bkgDir + 'mc16e_bffN_550_470/*.root' ], 'chain_name': 'bffN_550_470_Nom', 'class': 'sig' }, { 'name': 'bffN_550_500', 'target': [ bkgDir + 'mc16a_bffN_550_500/*.root', bkgDir + 'mc16d_bffN_550_500/*.root', bkgDir + 'mc16e_bffN_550_500/*.root' ], 'chain_name': 'bffN_550_500_Nom', 'class': 'sig' }, { 'name': 'bffN_550_530', 'target': [ bkgDir + 'mc16a_bffN_550_530/*.root', bkgDir + 'mc16d_bffN_550_530/*.root', bkgDir + 'mc16e_bffN_550_530/*.root' ], 'chain_name': 'bffN_550_530_Nom', 'class': 'sig' }, { 'name': 'bffN_550_543', 'target': [ bkgDir + 'mc16a_bffN_550_543/*.root', bkgDir + 'mc16d_bffN_550_543/*.root', bkgDir + 'mc16e_bffN_550_543/*.root' ], 'chain_name': 'bffN_550_543_Nom', 'class': 'sig' }, { 'name': 'bffN_600_520', 'target': [ bkgDir + 'mc16a_bffN_600_520/*.root', bkgDir + 'mc16d_bffN_600_520/*.root', bkgDir + 'mc16e_bffN_600_520/*.root' ], 'chain_name': 'bffN_600_520_Nom', 'class': 'sig' }, { 'name': 'bffN_600_550', 'target': [ bkgDir + 'mc16a_bffN_600_550/*.root', bkgDir + 'mc16d_bffN_600_550/*.root', bkgDir + 'mc16e_bffN_600_550/*.root' ], 'chain_name': 'bffN_600_550_Nom', 'class': 'sig' }, { 'name': 'bffN_600_580', 'target': [ bkgDir + 'mc16a_bffN_600_580/*.root', bkgDir + 'mc16d_bffN_600_580/*.root', bkgDir + 'mc16e_bffN_600_580/*.root' ], 'chain_name': 'bffN_600_580_Nom', 'class': 'sig' }, { 'name': 'bffN_600_593', 'target': [ bkgDir + 'mc16a_bffN_600_593/*.root', bkgDir + 'mc16d_bffN_600_593/*.root', bkgDir + 'mc16e_bffN_600_593/*.root' ], 'chain_name': 'bffN_600_593_Nom', 'class': 'sig' }, { 'name': 'bffN_650_570', 'target': [ bkgDir + 'mc16a_bffN_650_570/*.root', bkgDir + 'mc16d_bffN_650_570/*.root', bkgDir + 'mc16e_bffN_650_570/*.root' ], 'chain_name': 'bffN_650_570_Nom', 'class': 'sig' }, { 'name': 'bffN_650_600', 'target': [ bkgDir + 'mc16a_bffN_650_600/*.root', bkgDir + 'mc16d_bffN_650_600/*.root', bkgDir + 'mc16e_bffN_650_600/*.root' ], 'chain_name': 'bffN_650_600_Nom', 'class': 'sig' }, { 'name': 'bffN_650_630', 'target': [ bkgDir + 'mc16a_bffN_650_630/*.root', bkgDir + 'mc16d_bffN_650_630/*.root', bkgDir + 'mc16e_bffN_650_630/*.root' ], 'chain_name': 'bffN_650_630_Nom', 'class': 'sig' }, { 'name': 'bffN_650_643', 'target': [ bkgDir + 'mc16a_bffN_650_643/*.root', bkgDir + 'mc16d_bffN_650_643/*.root', bkgDir + 'mc16e_bffN_650_643/*.root' ], 'chain_name': 'bffN_650_643_Nom', 'class': 'sig' }, ### tN ### { 'name': 'tN_190_17', 'target': [ bkgDir + 'mc16a_tN_190_17/*.root', bkgDir + 'mc16d_tN_190_17/*.root', bkgDir + 'mc16e_tN_190_17/*.root' ], 'chain_name': 'tN_190_17_Nom', 'class': 'sig' }, { 'name': 'tN_400_200', 'target': [ bkgDir + 'mc16a_tN_400_200/*.root', bkgDir + 'mc16d_tN_400_200/*.root', bkgDir + 'mc16e_tN_400_200/*.root' ], 'chain_name': 'tN_400_200_Nom', 'class': 'sig' }, { 'name': 'tN_500_300', 'target': [ bkgDir + 'mc16a_tN_500_300/*.root', bkgDir + 'mc16d_tN_500_300/*.root', bkgDir + 'mc16e_tN_500_300/*.root' ], 'chain_name': 'tN_500_300_Nom', 'class': 'sig' }, { 'name': 'tN_500_312', 'target': [ bkgDir + 'mc16a_tN_500_312/*.root', bkgDir + 'mc16d_tN_500_312/*.root', bkgDir + 'mc16e_tN_500_312/*.root' ], 'chain_name': 'tN_500_312_Nom', 'class': 'sig' }, { 'name': 'tN_500_327', 'target': [ bkgDir + 'mc16a_tN_500_327/*.root', bkgDir + 'mc16d_tN_500_327/*.root', bkgDir + 'mc16e_tN_500_327/*.root' ], 'chain_name': 'tN_500_327_Nom', 'class': 'sig' }, { 'name': 'tN_550_350', 'target': [ bkgDir + 'mc16a_tN_550_350/*.root', bkgDir + 'mc16d_tN_550_350/*.root', bkgDir + 'mc16e_tN_550_350/*.root' ], 'chain_name': 'tN_550_350_Nom', 'class': 'sig' }, { 'name': 'tN_550_362', 'target': [ bkgDir + 'mc16a_tN_550_362/*.root', bkgDir + 'mc16d_tN_550_362/*.root', bkgDir + 'mc16e_tN_550_362/*.root' ], 'chain_name': 'tN_550_362_Nom', 'class': 'sig' }, { 'name': 'tN_550_377', 'target': [ bkgDir + 'mc16a_tN_550_377/*.root', bkgDir + 'mc16d_tN_550_377/*.root', bkgDir + 'mc16e_tN_550_377/*.root' ], 'chain_name': 'tN_550_377_Nom', 'class': 'sig' }, { 'name': 'tN_600_400', 'target': [ bkgDir + 'mc16a_tN_600_400/*.root', bkgDir + 'mc16d_tN_600_400/*.root', bkgDir + 'mc16e_tN_600_400/*.root' ], 'chain_name': 'tN_600_400_Nom', 'class': 'sig' }, { 'name': 'tN_600_412', 'target': [ bkgDir + 'mc16a_tN_600_412/*.root', bkgDir + 'mc16d_tN_600_412/*.root', bkgDir + 'mc16e_tN_600_412/*.root' ], 'chain_name': 'tN_600_412_Nom', 'class': 'sig' }, { 'name': 'tN_600_427', 'target': [ bkgDir + 'mc16a_tN_600_427/*.root', bkgDir + 'mc16d_tN_600_427/*.root', bkgDir + 'mc16e_tN_600_427/*.root' ], 'chain_name': 'tN_600_427_Nom', 'class': 'sig' }, { 'name': 'tN_650_450', 'target': [ bkgDir + 'mc16a_tN_650_450/*.root', bkgDir + 'mc16d_tN_650_450/*.root', bkgDir + 'mc16e_tN_650_450/*.root' ], 'chain_name': 'tN_650_450_Nom', 'class': 'sig' }, { 'name': 'tN_650_462', 'target': [ bkgDir + 'mc16a_tN_650_462/*.root', bkgDir + 'mc16d_tN_650_462/*.root', bkgDir + 'mc16e_tN_650_462/*.root' ], 'chain_name': 'tN_650_462_Nom', 'class': 'sig' }, { 'name': 'tN_650_477', 'target': [ bkgDir + 'mc16a_tN_650_477/*.root', bkgDir + 'mc16d_tN_650_477/*.root', bkgDir + 'mc16e_tN_650_477/*.root' ], 'chain_name': 'tN_650_477_Nom', 'class': 'sig' }, { 'name': 'tN_700_500', 'target': [ bkgDir + 'mc16a_tN_700_500/*.root', bkgDir + 'mc16d_tN_700_500/*.root', bkgDir + 'mc16e_tN_700_500/*.root' ], 'chain_name': 'tN_700_500_Nom', 'class': 'sig' }, ] harvest = [ ### bWN ### { 'mT': 400, 'mX': 235, 'yield': 0, 'var': 0 }, { 'mT': 400, 'mX': 250, 'yield': 0, 'var': 0 }, { 'mT': 400, 'mX': 280, 'yield': 0, 'var': 0 }, { 'mT': 400, 'mX': 310, 'yield': 0, 'var': 0 }, { 'mT': 450, 'mX': 285, 'yield': 0, 'var': 0 }, { 'mT': 450, 'mX': 300, 'yield': 0, 'var': 0 }, { 'mT': 450, 'mX': 330, 'yield': 0, 'var': 0 }, { 'mT': 450, 'mX': 360, 'yield': 0, 'var': 0 }, { 'mT': 500, 'mX': 335, 'yield': 0, 'var': 0 }, { 'mT': 500, 'mX': 350, 'yield': 0, 'var': 0 }, { 'mT': 500, 'mX': 380, 'yield': 0, 'var': 0 }, { 'mT': 500, 'mX': 410, 'yield': 0, 'var': 0 }, { 'mT': 550, 'mX': 385, 'yield': 0, 'var': 0 }, { 'mT': 550, 'mX': 400, 'yield': 0, 'var': 0 }, { 'mT': 550, 'mX': 430, 'yield': 0, 'var': 0 }, { 'mT': 550, 'mX': 460, 'yield': 0, 'var': 0 }, { 'mT': 600, 'mX': 435, 'yield': 0, 'var': 0 }, { 'mT': 600, 'mX': 450, 'yield': 0, 'var': 0 }, { 'mT': 600, 'mX': 480, 'yield': 0, 'var': 0 }, { 'mT': 600, 'mX': 510, 'yield': 0, 'var': 0 }, { 'mT': 650, 'mX': 485, 'yield': 0, 'var': 0 }, { 'mT': 650, 'mX': 500, 'yield': 0, 'var': 0 }, { 'mT': 650, 'mX': 530, 'yield': 0, 'var': 0 }, { 'mT': 650, 'mX': 560, 'yield': 0, 'var': 0 }, { 'mT': 700, 'mX': 535, 'yield': 0, 'var': 0 }, { 'mT': 700, 'mX': 550, 'yield': 0, 'var': 0 }, { 'mT': 700, 'mX': 580, 'yield': 0, 'var': 0 }, { 'mT': 700, 'mX': 610, 'yield': 0, 'var': 0 }, { 'mT': 750, 'mX': 585, 'yield': 0, 'var': 0 }, { 'mT': 750, 'mX': 600, 'yield': 0, 'var': 0 }, { 'mT': 750, 'mX': 630, 'yield': 0, 'var': 0 }, { 'mT': 750, 'mX': 660, 'yield': 0, 'var': 0 }, ### bffN ### { 'mT': 300, 'mX': 220, 'yield': 0, 'var': 0 }, { 'mT': 300, 'mX': 250, 'yield': 0, 'var': 0 }, { 'mT': 300, 'mX': 280, 'yield': 0, 'var': 0 }, { 'mT': 300, 'mX': 293, 'yield': 0, 'var': 0 }, { 'mT': 350, 'mX': 270, 'yield': 0, 'var': 0 }, { 'mT': 350, 'mX': 300, 'yield': 0, 'var': 0 }, { 'mT': 350, 'mX': 330, 'yield': 0, 'var': 0 }, { 'mT': 350, 'mX': 343, 'yield': 0, 'var': 0 }, { 'mT': 400, 'mX': 320, 'yield': 0, 'var': 0 }, { 'mT': 400, 'mX': 350, 'yield': 0, 'var': 0 }, { 'mT': 400, 'mX': 380, 'yield': 0, 'var': 0 }, { 'mT': 400, 'mX': 393, 'yield': 0, 'var': 0 }, { 'mT': 450, 'mX': 370, 'yield': 0, 'var': 0 }, { 'mT': 450, 'mX': 400, 'yield': 0, 'var': 0 }, { 'mT': 450, 'mX': 430, 'yield': 0, 'var': 0 }, { 'mT': 450, 'mX': 443, 'yield': 0, 'var': 0 }, { 'mT': 500, 'mX': 420, 'yield': 0, 'var': 0 }, { 'mT': 500, 'mX': 450, 'yield': 0, 'var': 0 }, { 'mT': 500, 'mX': 480, 'yield': 0, 'var': 0 }, { 'mT': 500, 'mX': 493, 'yield': 0, 'var': 0 }, { 'mT': 550, 'mX': 470, 'yield': 0, 'var': 0 }, { 'mT': 550, 'mX': 500, 'yield': 0, 'var': 0 }, { 'mT': 550, 'mX': 530, 'yield': 0, 'var': 0 }, { 'mT': 550, 'mX': 543, 'yield': 0, 'var': 0 }, { 'mT': 600, 'mX': 520, 'yield': 0, 'var': 0 }, { 'mT': 600, 'mX': 550, 'yield': 0, 'var': 0 }, { 'mT': 600, 'mX': 580, 'yield': 0, 'var': 0 }, { 'mT': 600, 'mX': 593, 'yield': 0, 'var': 0 }, { 'mT': 650, 'mX': 570, 'yield': 0, 'var': 0 }, { 'mT': 650, 'mX': 600, 'yield': 0, 'var': 0 }, { 'mT': 650, 'mX': 630, 'yield': 0, 'var': 0 }, { 'mT': 650, 'mX': 643, 'yield': 0, 'var': 0 }, ### tN ### { 'mT': 190, 'mX': 17, 'yield': 0, 'var': 0 }, { 'mT': 400, 'mX': 200, 'yield': 0, 'var': 0 }, { 'mT': 500, 'mX': 300, 'yield': 0, 'var': 0 }, { 'mT': 500, 'mX': 312, 'yield': 0, 'var': 0 }, { 'mT': 500, 'mX': 327, 'yield': 0, 'var': 0 }, { 'mT': 550, 'mX': 350, 'yield': 0, 'var': 0 }, { 'mT': 550, 'mX': 362, 'yield': 0, 'var': 0 }, { 'mT': 550, 'mX': 377, 'yield': 0, 'var': 0 }, { 'mT': 600, 'mX': 400, 'yield': 0, 'var': 0 }, { 'mT': 600, 'mX': 412, 'yield': 0, 'var': 0 }, { 'mT': 600, 'mX': 427, 'yield': 0, 'var': 0 }, { 'mT': 650, 'mX': 450, 'yield': 0, 'var': 0 }, { 'mT': 650, 'mX': 462, 'yield': 0, 'var': 0 }, { 'mT': 650, 'mX': 477, 'yield': 0, 'var': 0 }, { 'mT': 700, 'mX': 500, 'yield': 0, 'var': 0 }, ] for i, sample in enumerate(sampleNames): sample['chain'] = ROOT.TChain(sample['chain_name']) for target in sample['target']: sample['chain'].Add(target) totBkg = 0 totBkgVar = 0 for sample in sampleNames: sample['yield'], sample['error'] = getYieldFromChain(sample['chain'], cut, lumi, weight=weight, returnError=True) if sample['class'] == 'bkg': totBkg += sample['yield'] totBkgVar += sample['error']**2 elif sample['class'] == 'sig': for point in harvest: if (str(point['mT']) in sample['name']) and (str( point['mX']) in sample['name']): point['yield'] += sample['yield'] point['var'] += sample['error']**2 print totBkg, totBkgVar relBkg = math.sqrt(totBkgVar / (totBkg**2) + 0.25 * 0.25) xs = [] ys = [] zs = [] for point in harvest: print "Signal point: mT {}, mX {}".format(point['mT'], point['mX']) point['Z'] = ROOT.RooStats.NumberCountingUtils.BinomialExpZ( point['yield'], totBkg, relBkg) if point['Z'] < 0.: point['Z'] = 0. try: point['A'] = asimovZ(point['yield'], totBkg, math.sqrt(totBkgVar), syst=True) except ValueError: point['A'] = 0. point['C'] = point['yield'] / (point['yield'] + totBkg) xs.append(point['mT']) ys.append(point['mX']) if plotSig: zs.append(point['Z']) else: zs.append(point['C']) print("X" * 50) print(len(xs)) for x in xs: print("{:.5f},".format(x)) print("Y" * 50) print(len(ys)) for y in ys: print("{:.5f},".format(y)) print("Z" * 50) print(len(zs)) for z in zs: print("{:.5f},".format(z)) if plotSig: sig = triwsmooth(harvest, 'A', 'mT', 'mX', transformation=None, smooth=True, npx=100, npy=100) fixedhist = FixAndSetBorders(sig, "significance", "significance") contours = getContours(fixedhist, 3.) else: sig = triwsmooth(harvest, 'C', 'mT', 'mX', transformation=None, smooth=True, npx=100, npy=100) fixedhist = FixAndSetBorders(sig, "signal_contamination", "signal_contamination") contours = getContours(fixedhist, .05) #contours = getContours(fixedhist, .10) c = ROOT.TCanvas() c.SetRightMargin(0.15) leg = ROOT.TLegend(0.18, PS.ThirdLine - 0.12, 0.4, PS.ThirdLine - 0.03) PS.legend(leg) fixedhist.GetXaxis().SetTitle("m_{#tilde{t}} [GeV]") fixedhist.GetYaxis().SetTitle("m_{#tilde{#chi}} [GeV]") #if plotSig: # numbers = drawNumbers(harvest, "Z", x, y) #else: # numbers = drawNumbers(harvest, "C", x, y) fixedhist.Draw("colz") #for contour in contours + contours2: for contour in contours: contour.SetLineStyle(1) contour.SetLineColor(ROOT.kBlack) contour.Draw("l same") if plotSig: leg.AddEntry(contours[0], '3 #sigma', 'l') else: leg.AddEntry(contours[0], '5% sig. cont.', 'l') #if plotSig: # numbers = drawNumbers(exampleHarvest, "Z", x, y) #else: # numbers = drawNumbers(exampleHarvest, "Z", x, y) leg.Draw() PS.atlas('Work in progress') PS.sqrts_lumi(13, 140.5, x=0.18) PS.string(x=0.18, y=PS.ThirdLine, text="Simulation") c.SaveAs(wwwDir + filename + ".pdf") c.SaveAs(wwwDir + filename + ".png") c.SaveAs(wwwDir + filename + ".root")
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 evaluate_k_fold_test_train(sig_tree, bkg_tree, total_sig, total_bkg, mva_name, name, reader_list, var_store_list, nbins, min, max, k_fold, lumi): bkg_mva_test, bkg_mva_train = evaluate_mva_k_fold_test_train( "bkg", bkg_tree, mva_name, reader_list, var_store_list, nbins, min, max, k_fold) sig_mva_test, sig_mva_train = evaluate_mva_k_fold_test_train( "sig", sig_tree, mva_name, reader_list, var_store_list, nbins, min, max, k_fold) sig_train = get_max_sig_hist(sig_mva_train, bkg_mva_train, total_sig, total_bkg, lumi) sig_test = get_max_sig_hist(sig_mva_test, bkg_mva_test, total_sig, total_bkg, lumi) print sig_train, sig_test set_style(sig_mva_test, kRed, norm=True) set_style(sig_mva_train, kRed, norm=True) set_style(bkg_mva_test, kBlue, norm=True) set_style(bkg_mva_train, kBlue, norm=True) # plot train and test canv = TCanvas("mva_dist", "", 800, 600) bkg_mva_test.SetTitle("; %s; fraction of events" % mva_name) bkg_mva_test.GetYaxis().SetRangeUser(0, bkg_mva_test.GetMaximum() * 1.7) bkg_mva_test.Draw("hist") sig_mva_test.Draw("same hist") bkg_mva_train.Draw("same p") sig_mva_train.Draw("same p") leg = TLegend(0.3, 0.7, 0.6, 0.9) leg.AddEntry(sig_mva_test, "Signal Test", "f") leg.AddEntry(bkg_mva_test, "Background Test", "f") leg.AddEntry(sig_mva_train, "Signal Train", "pl") leg.AddEntry(bkg_mva_train, "Background Train", "pl") leg.Draw("same") kolmogorov_bkg = bkg_mva_test.KolmogorovTest(bkg_mva_train) kolmogorov_sig = sig_mva_test.KolmogorovTest(sig_mva_train) chi2_bkg = bkg_mva_test.Chi2Test(bkg_mva_train, "WW CHI2/NDF") chi2_sig = sig_mva_test.Chi2Test(sig_mva_train, "WW CHI2/NDF") PlotStyle.string(0.65, 0.85, "Kolomogorov Bkg: %1.2f" % kolmogorov_bkg, rel=0.7) PlotStyle.string(0.65, 0.8, "Kolomogorov Sig: %1.2f" % kolmogorov_sig, rel=0.7) PlotStyle.string(0.65, 0.75, "red. #chi^{2} Bkg: %1.2f" % chi2_bkg, rel=0.7) PlotStyle.string(0.65, 0.7, "red. #chi^{2} Sig: %1.2f" % chi2_sig, rel=0.7) save_canv(canv, name + "_full", name + "_" + mva_name + "_" + str(k_fold)) # plot roc curve roc_test = get_roc_curve_hist(sig_mva_test, bkg_mva_test) roc_train = get_roc_curve_hist(sig_mva_train, bkg_mva_train) set_style(roc_train, kCyan + 2) set_style(roc_test, kBlack) canv = TCanvas("roc", "", 800, 600) roc_test.SetTitle("; sig. eff.; bkg. rej.") roc_test.Draw("a l") roc_train.Draw("same l") leg = TLegend(0.2, 0.2, 0.5, 0.4) leg.AddEntry(roc_train, "Train: %.1f @%s/fb" % (sig_train, lumi), "l") leg.AddEntry(roc_test, "Test: %.1f @%s/fb" % (sig_test, lumi), "l") leg.Draw("same") save_canv(canv, name + "_full", name + "_" + mva_name + "_" + str(k_fold))
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 doPlotCutflowNoL1(filename = 'L1MuonHistogram.root'): if(DEBUG): print 'Opening file:',filename file = TFile.Open(filename) if(file == None): print 'Error opening file:',filename histoNames = [ 'hoMuonAnalyzer/count/NoSingleMu_Count', 'hoMuonAnalyzer/count/NoSingleMuInGa_Count', 'hoMuonAnalyzer/count/NoSingleMuInGa5x5_Count', 'hoMuonAnalyzer/count/NoSingleMuInGa3x3_Count', 'hoMuonAnalyzer/count/NoSingleMuInGaCentral_Count', 'hoMuonAnalyzer/count/Events_Count' ] histograms = [] yValues = [] for s in histoNames: histograms.append(file.Get(s)) yValues.append(histograms[-1].GetBinContent(2)) nEvents = histograms[-1].GetEntries() xLabels = [ 'No Single #mu trigger', 'TDMI in GA', 'HO > 0.2 GeV in 5x5', 'HO > 0.2 GeV in 3x3', 'HO > 0.2 GeV in Central' ] c = TCanvas('eventCountCanvas','PostLS1 Single #mu gun',1200,1200) hist = TH1D("eventCount","PostLS1 Single #mu gun",len(xLabels)-1,0,len(xLabels)) paveText = TPaveText(0.51,0.75,0.9,0.9,'NDC') paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[0],yValues[0],yValues[0]/nEvents*100,calcSigma(yValues[0], nEvents)*100)) paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[2],yValues[2],yValues[2]/yValues[1]*100,calcSigma(yValues[2], yValues[1])*100)) paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[4],yValues[4],yValues[4]/yValues[1]*100,calcSigma(yValues[4], yValues[1])*100)) paveText.SetBorderSize(1) print yValues[1] norm = yValues[1] for i,v in enumerate(xLabels): if(i == 0): continue hist.SetBinContent(i,yValues[i]/norm) hist.GetXaxis().SetBinLabel(i,str(v)) hist.SetStats(0) hist.SetLineColor(PlotStyle.colorRwthDarkBlue) hist.GetYaxis().SetTitle('#') # hist.GetYaxis().SetRangeUser(0.5,1.1) hist.SetLabelFont(62) hist.SetTitleFont(62) hist.SetMinimum(0) print yValues hist.Draw("") paveText.Draw() label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() c.Update() c.SaveAs("plots/cutflow/cutflowTdmiNoTrg.png") c.SaveAs("plots/cutflow/cutflowTdmiNoTrg.pdf") c.SaveAs("plots/cutflow/cutflowTdmiNoTrg.root") return c,hist
def doPlotCutflow(filename='L1MuonHistogram.root'): PlotStyle.setPlotStyle() if(DEBUG): print 'Opening file:',filename file = TFile.Open(filename) if(file == None): print 'Error opening file:',filename #Total event count tagEvents = 'hoMuonAnalyzer/count/Events_Count' tagL1Muons = 'hoMuonAnalyzer/count/L1MuonPresent_Count' #Counters without energy threshold tagHo1 = 'hoMuonAnalyzer/count/L1MuonPresentHoMatch_Count' tagHo2 = 'hoMuonAnalyzer/count/L1MuonPresentHoMatchInAcc_Count' tagHo3 = 'hoMuonAnalyzer/count/L1MuonPresentHoMatchInAccNotDead_Count' tagHo4 = 'hoMuonAnalyzer/count/L1MuonPresentHoMatchInAccThr_Count' #Counters with energy threshold tagThr1 = 'hoMuonAnalyzer/count/L1MuonAboveThr_Count' tagThr2 = 'hoMuonAnalyzer/count/L1MuonAboveThrInAcc_Count' tagThr3 = 'hoMuonAnalyzer/count/L1MuonAboveThrInAccNotDead_Count' histEvents = file.Get(tagEvents) histL1Muons = file.Get(tagL1Muons) histHo1 = file.Get(tagHo1) histHo2 = file.Get(tagHo2) histHo3 = file.Get(tagHo3) histHo4 = file.Get(tagHo4) histThr1 = file.Get(tagThr1) histThr2 = file.Get(tagThr2) histThr3 = file.Get(tagThr3) yValues = [ histEvents.GetBinContent(2), histL1Muons.GetBinContent(2), histHo1.GetBinContent(2), # histHo2.GetBinContent(2), # histHo3.GetBinContent(2), histThr1.GetBinContent(2), histThr2.GetBinContent(2), histThr3.GetBinContent(2) ] xLabels = [ 'Event count', 'L1Muon objects', 'HO match (No Thr.)', 'HO match > 0.2 GeV', # '+ HO acceptance' ] norm = yValues[0] for i,v in enumerate(yValues): yValues[i] = v/norm c = TCanvas('cutflowCanvas','PostLS1 Single #mu gun',1200,1200) hist = TH1D("cutflow","PostLS1 Single #mu gun",len(xLabels),0,len(xLabels)) for i,v in enumerate(xLabels): hist.SetBinContent(i+1,yValues[i]) hist.GetXaxis().SetBinLabel(i+1,str(v)) hist.SetStats(0) hist.GetYaxis().SetTitle('rel. Fraction') hist.GetYaxis().SetRangeUser(0.7,1.1) hist.SetLineColor(PlotStyle.colorRwthDarkBlue) hist.SetLabelFont(62) hist.SetTitleFont(62) hist.Draw("") histTrgCount = file.Get('hoMuonAnalyzer/count/L1_SingleMuOpen_Count') hist2 = TH1D("l1TrgCount","PostLS1 Single #mu gun",len(xLabels),0,len(xLabels)) hist2.SetBinContent(1,histTrgCount.GetBinContent(2)/norm) hist2.SetFillStyle(3002) hist2.SetFillColor(PlotStyle.colorRwthMagenta) hist2.SetLineColor(PlotStyle.colorRwthMagenta) hist2.Draw("same") paveText = TPaveText(0.51,0.75,0.9,0.9,'NDC') paveText.AddText('%s: %.2f%% #pm %.2f%%' % (xLabels[1],yValues[1]*100,calcSigma(yValues[1]*norm,norm)*100)) paveText.AddText('%s: %.2f%% #pm %.2f%%' % (xLabels[2],yValues[2]*100,calcSigma(yValues[2]*norm,norm)*100)) paveText.AddText('%s: %.2f%% #pm %.2f%%' % (xLabels[3],yValues[3]*100,calcSigma(yValues[3]*norm,norm)*100)) paveText.SetBorderSize(1) paveText.Draw() legend = TLegend(0.1,0.8,0.45,0.9) legend.AddEntry(hist2,"Fraction with L1 Single #mu Trg.","f") legend.Draw() label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() c.Update() c.SaveAs("plots/cutflow/cutflowL1.png") c.SaveAs("plots/cutflow/cutflowL1.pdf") c.SaveAs("plots/cutflow/cutflowL1.root") nTotal = histEvents.GetBinContent(2) nL1 = histL1Muons.GetBinContent(2) nL1AndHo = histHo1.GetBinContent(2) nL1AndHoAcc = histHo2.GetBinContent(2) nL1AndHoAccNotDead = histHo3.GetBinContent(2) nL1AndHoAccThr = histHo4.GetBinContent(2) nL1AndHoThr = histThr1.GetBinContent(2) nL1AndHoThrAcc = histThr2.GetBinContent(2) nL1AndHoThrAccNotDead = histThr3.GetBinContent(2) print '%s' % (80*'#') print '%s' % (80*'#') print '%25s%d' % ('nEvents:\t',nTotal) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('nL1:\t',nL1,nL1/nTotal*100,calcSigma(nL1, nTotal)*100) print '%s' % (80*'#') print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHo:\t',nL1AndHo,nL1AndHo/nL1*100,calcSigma(nL1AndHo, nL1)*100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoAcc:\t',nL1AndHoAcc,nL1AndHoAcc/nL1*100,calcSigma(nL1AndHoAcc, nL1)*100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoAccNotDead:\t',nL1AndHoAccNotDead,nL1AndHoAccNotDead/nL1*100,calcSigma(nL1AndHoAccNotDead, nL1)*100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoAccThr:\t',nL1AndHoAccThr,nL1AndHoAccThr/nL1*100,calcSigma(nL1AndHoAccThr, nL1)*100) print '%s' % (80*'#') print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoThr:\t',nL1AndHoThr,nL1AndHoThr/nL1*100,calcSigma(nL1AndHoThr, nL1)*100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoThrAcc:\t',nL1AndHoThrAcc,nL1AndHoThrAcc/nL1*100,calcSigma(nL1AndHoThrAcc,nL1)*100) print '%25s%d\t=>\t%.2f%% +/- %.2f%%' % ('L1AndHoThrAccNotDead:\t',nL1AndHoThrAccNotDead,nL1AndHoThrAccNotDead/nL1*100,calcSigma(nL1AndHoThrAccNotDead, nL1)*100) print '%s' % (80*'#') print '%s' % (80*'#') return c
def plotFailedHoMatchesNoTrg(): c = TCanvas("cFailedHoMatchesNoTrg","cFailedHoMatchesNoTrg",1200,1200) c.cd().SetRightMargin(0.25) c.cd().SetLeftMargin(0.08) #Graph for in events not in geometric acceptance grNotInGaNC = file.Get("hoMuonAnalyzer/graphs/NoTrgTdmiNotInGA") grNotInGa = PlotStyle.convertToHcalCoords(grNotInGaNC) grNotInGa.GetYaxis().SetTitle("i#phi / a.u.") grNotInGa.GetXaxis().SetTitle("i#eta / a.u.") grNotInGa.GetYaxis().SetTitleFont(62) grNotInGa.GetYaxis().SetLabelFont(62) grNotInGa.SetMarkerStyle(6) grNotInGa.SetMarkerColor(PlotStyle.colorRwthDarkBlue) grNotInGa.SetTitle("#eta #phi plot failed HO matches in no Single #mu Trg. events") grNotInGa.Draw("AP") #Graph of events with HO match below threshold grHoBelowThrNC = file.Get("hoMuonAnalyzer/graphs/NoTrgTdmiBelowThr") grHoBelowThr = PlotStyle.convertToHcalCoords(grHoBelowThrNC) grHoBelowThr.SetMarkerStyle(20) grHoBelowThr.SetMarkerSize(1.2) grHoBelowThr.SetMarkerColor( PlotStyle.colorRwthGruen ) grHoBelowThr.Draw("samep") #Graph for events where HO matching failed grHoMatchFailNC = file.Get("hoMuonAnalyzer/graphs/NoTrgHoMatchFail") grHoMatchFail = PlotStyle.convertToHcalCoords(grHoMatchFailNC) grHoMatchFail.SetMarkerStyle(21) grHoMatchFail.SetMarkerSize(1) grHoMatchFail.SetMarkerColor( PlotStyle.colorRwthRot ) grHoMatchFail.Draw("samep") #Draw chimneys chimney1Converted = PlotStyle.convertToHcalCoords(PlotStyle.chimney1) chimney2Converted = PlotStyle.convertToHcalCoords(PlotStyle.chimney2) chimney1Converted.SetLineColor(PlotStyle.colorRwthMagenta) chimney2Converted.SetLineColor(PlotStyle.colorRwthMagenta) chimney1Converted.Draw('same') chimney2Converted.Draw('same') #cms private label label = TPaveText(PlotStyle.getLabelCmsPrivateSimulation(x1ndc=0.5,x2ndc=0.75)) label.Draw() #create extra marker for the legend marker = TMarker(1,1,2) marker.SetMarkerSize(3) marker.SetMarkerColor(PlotStyle.colorRwthDarkBlue) #legend legend = TLegend(0.75,0.8,0.99,0.9) legend.AddEntry(chimney2Converted,"chimney","l") legend.AddEntry(marker,'Not in GA','p') legend.AddEntry(grHoMatchFail,'HO match fail','p') legend.AddEntry(grHoBelowThr,'HO match < 0.2 GeV','p') legend.Draw() nNotMatching = grHoMatchFail.GetN() nNotInGa = grNotInGa.GetN() nBelowThr = grHoBelowThr.GetN() nTotal = nNotMatching + nNotInGa + nBelowThr print 80*'#' print 'Not Matching:\t%5d/%d\t=> %5.2f%% +- %f%%' % (nNotMatching,nTotal,nNotMatching/float(nTotal)*100,PlotStyle.calcSigma(nNotMatching,float(nTotal))) print 'Not in GA:\t%5d/%d\t=> %5.2f%% +- %f%%' % (nNotInGa,nTotal,nNotInGa/float(nTotal)*100,PlotStyle.calcSigma(nNotInGa,float(nTotal))) print 'Below Thr:\t%5d/%d\t=> %5.2f%% +- %f%%' % (nBelowThr,nTotal,nBelowThr/float(nTotal)*100,PlotStyle.calcSigma(nBelowThr,float(nTotal))) print 80*'#' c.Update() c.SaveAs('plots/graphsEtaPhi/gNoTrgHoMatchingFailed.png') c.SaveAs('plots/graphsEtaPhi/gNoTrgHoMatchingFailed.pdf') return c,grNotInGa,label,chimney1Converted,chimney2Converted,legend,grHoMatchFail,grHoBelowThr
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 doPlotCutflowNoL1(filename='L1MuonHistogram.root'): if (DEBUG): print 'Opening file:', filename file = TFile.Open(filename) if (file == None): print 'Error opening file:', filename histoNames = [ 'hoMuonAnalyzer/count/NoSingleMu_Count', 'hoMuonAnalyzer/count/NoSingleMuInGa_Count', 'hoMuonAnalyzer/count/NoSingleMuInGa5x5_Count', 'hoMuonAnalyzer/count/NoSingleMuInGa3x3_Count', 'hoMuonAnalyzer/count/NoSingleMuInGaCentral_Count', 'hoMuonAnalyzer/count/Events_Count' ] histograms = [] yValues = [] for s in histoNames: histograms.append(file.Get(s)) yValues.append(histograms[-1].GetBinContent(2)) nEvents = histograms[-1].GetEntries() xLabels = [ 'No Single #mu trigger', 'TDMI in GA', 'HO > 0.2 GeV in 5x5', 'HO > 0.2 GeV in 3x3', 'HO > 0.2 GeV in Central' ] c = TCanvas('eventCountCanvas', 'PostLS1 Single #mu gun', 1200, 1200) hist = TH1D("eventCount", "PostLS1 Single #mu gun", len(xLabels) - 1, 0, len(xLabels)) paveText = TPaveText(0.51, 0.75, 0.9, 0.9, 'NDC') paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[0], yValues[0], yValues[0] / nEvents * 100, calcSigma(yValues[0], nEvents) * 100)) paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[2], yValues[2], yValues[2] / yValues[1] * 100, calcSigma(yValues[2], yValues[1]) * 100)) paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[4], yValues[4], yValues[4] / yValues[1] * 100, calcSigma(yValues[4], yValues[1]) * 100)) paveText.SetBorderSize(1) print yValues[1] norm = yValues[1] for i, v in enumerate(xLabels): if (i == 0): continue hist.SetBinContent(i, yValues[i] / norm) hist.GetXaxis().SetBinLabel(i, str(v)) hist.SetStats(0) hist.SetLineColor(PlotStyle.colorRwthDarkBlue) hist.GetYaxis().SetTitle('#') # hist.GetYaxis().SetRangeUser(0.5,1.1) hist.SetLabelFont(62) hist.SetTitleFont(62) hist.SetMinimum(0) hist.Draw("") paveText.Draw() label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() c.Update() c.SaveAs("plots/cutflow/cutflowTdmiNoTrg.png") c.SaveAs("plots/cutflow/cutflowTdmiNoTrg.pdf") c.SaveAs("plots/cutflow/cutflowTdmiNoTrg.root") return c, hist
#!/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 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]