-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_roc_comparison.py
More file actions
154 lines (137 loc) · 5.25 KB
/
Copy pathplot_roc_comparison.py
File metadata and controls
154 lines (137 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import os
import sys
import argparse
from array import array
import json
import ROOT
ROOT.gROOT.SetBatch(True)
import tdrstyle
tdrstyle.setTDRStyle()
parser = argparse.ArgumentParser(description='Plot comparison')
parser.add_argument('jsons', type=str, nargs='+',
help='JSON files for ROC')
parser.add_argument('--labels', type=str, nargs='+',
help='Labels for plot')
args = parser.parse_args()
tag = 'comparison'
jsonFiles = args.jsons
jsonLabels = args.labels
print(jsonFiles)
print(jsonLabels)
colors = [ROOT.kBlack, ROOT.kBlue, ROOT.kGreen+2, ROOT.kRed, ROOT.kMagenta, ROOT.kCyan]
styles = [1,4,2,6,10]
widths = [3,1,7,1,9]
markers = [21,22,23,33,34]
idnames = ['isPFMuon','isTrackerMuon']
pbins = [2,5,10,50]#,1000]
npb = len(pbins)-1
etabins = [0,1.2,1.566,2.322,2.5]
neb = len(etabins)-1
plabels = []
etalabels = []
for pb in range(npb):
plabels += ['{} < p < {} GeV'.format(pbins[pb],pbins[pb+1])]
for eb in range(neb):
etalabels += ['{} < |#eta| < {}'.format(etabins[eb],etabins[eb+1])]
results = {}
for fname in jsonFiles:
with open(fname) as f:
results[fname] = json.load(f)
def plot_hist(savename,allxvals,allyvals,labels=[],additional='',working=[]):
canvas = ROOT.TCanvas('c','c',800,800)
canvas.SetTopMargin(0.2)
canvas.SetLogy()
graphs = {}
wps = {}
mg = ROOT.TMultiGraph()
wpmg = ROOT.TMultiGraph()
legend1 = ROOT.TLegend(0.2,0.8,0.5,0.98,'','NDC')
legend1.SetTextFont(42)
legend1.SetBorderSize(0)
legend1.SetFillColor(0)
#legend1.SetNColumns(len(jsonLabels))
legend2 = ROOT.TLegend(0.55,0.8,0.85,0.98,'','NDC')
legend2.SetTextFont(42)
legend2.SetBorderSize(0)
legend2.SetFillColor(0)
#legend2.SetNColumns(len(jsonLabels))
legendWorking = ROOT.TLegend(0.6,0.15,0.9,0.3,'','NDC')
legendWorking.SetTextFont(42)
legendWorking.SetBorderSize(0)
legendWorking.SetFillColor(0)
for k in range(len(jsonLabels)):
for j,(xvals,yvals) in enumerate(zip(allxvals[k],allyvals[k])):
if j>=len(labels): continue
graphs[(k,j,)] = ROOT.TGraph(len(xvals),array('d',xvals),array('d',yvals))
graphs[(k,j,)].SetLineColor(colors[j])
graphs[(k,j,)].SetLineWidth(widths[k])
graphs[(k,j,)].SetLineStyle(styles[k])
mg.Add(graphs[(k,j,)])
if j==0: legend1.AddEntry(graphs[(k,j,)],jsonLabels[k],'l')
if labels and k==0: legend2.AddEntry(graphs[(k,j,)],labels[j],'l')
if k==0:
if not working: continue
for i, idname in enumerate(idnames):
wps['{}{}'.format(idname,j)] = ROOT.TGraph(1,array('d',[working[j][i][0]]),array('d',[working[j][i][1]]))
wps['{}{}'.format(idname,j)].SetMarkerColor(colors[j])
wps['{}{}'.format(idname,j)].SetMarkerStyle(markers[i])
wpmg.Add(wps['{}{}'.format(idname,j)])
if j==0: legendWorking.AddEntry(wps['{}{}'.format(idname,j)],idname,'p')
mg.Draw('AL')
mg.GetXaxis().SetTitle('True Muon')
mg.GetYaxis().SetTitle('Fake Pion')
mg.GetHistogram().SetMinimum(1e-5)
mg.GetHistogram().SetMaximum(1)
legend1.Draw()
legend2.Draw()
wpmg.Draw('P')
if working: legendWorking.Draw()
if additional:
text = ROOT.TPaveText(0.7,0.2,0.95,0.4,'NB NDC')
text.SetTextFont(42)
text.SetBorderSize(0)
text.SetFillColor(0)
text.SetTextAlign(11)
text.SetTextSize(0.03)
text.AddText(additional)
text.Draw()
canvas.Print('{}.png'.format(savename))
result = None
for pb in range(npb):
#with open('roc_caloCompatibility_pBin{}.json'.format(pb)) as f:
# result = json.load(f)
plot_hist('roc_{}_pBin{}'.format(tag,pb),
[results[jsonFile]['tpr']['pbin{}'.format(pb)] for jsonFile in jsonFiles],
[results[jsonFile]['fpr']['pbin{}'.format(pb)] for jsonFile in jsonFiles],
labels = etalabels,
additional = plabels[pb],
working=result)
for eb in range(neb):
#with open('roc_caloCompatibility_etaBin{}.json'.format(eb)) as f:
# result = json.load(f)
plot_hist('roc_{}_etaBin{}'.format(tag,eb),
[results[jsonFile]['tpr']['etabin{}'.format(eb)] for jsonFile in jsonFiles],
[results[jsonFile]['fpr']['etabin{}'.format(eb)] for jsonFile in jsonFiles],
labels = plabels,
additional = etalabels[eb],
working=result)
#with open('roc_caloCompatibility_pBins.json') as f:
# result = json.load(f)
plot_hist('roc_{}_pBins'.format(tag),
[results[jsonFile]['tpr']['pbins'] for jsonFile in jsonFiles],
[results[jsonFile]['fpr']['pbins'] for jsonFile in jsonFiles],
labels = plabels,
working=result)
#with open('roc_caloCompatibility_etaBins.json') as f:
# result = json.load(f)
plot_hist('roc_{}_etaBins'.format(tag),
[results[jsonFile]['tpr']['etabins'] for jsonFile in jsonFiles],
[results[jsonFile]['fpr']['etabins'] for jsonFile in jsonFiles],
labels = etalabels,
working=result)
#with open('roc_caloCompatibility.json') as f:
# result = json.load(f)
#plot_hist('roc_{}'.format(tag),
# [results[jsonFile]['tpr']['all'] for jsonFile in jsonFiles],
# [results[jsonFile]['fpr']['all'] for jsonFile in jsonFiles],
# working=result)