forked from CMS-LUMI-POG/VdMFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakePlots.py
237 lines (188 loc) · 7.5 KB
/
makePlots.py
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
from fitResultReader import fitResultReader
import ROOT as r
import sys, json
from vdmUtilities import makeCorrString
def addXsecPlots(description, paramName, param, paramErr, ouFileName):
noScanPairs = len(param)
canvas = r.TCanvas()
marker = [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
color = [2,3,4,6,7,2,3,4,6,7]
plot = r.TGraphErrors()
plot.SetMarkerStyle(8)
plot.SetMarkerSize(0.4)
plot.SetTitle(description + " " + paramName)
plot.GetXaxis().SetTitle('Scan number')
plot.GetYaxis().SetTitle(paramName)
i = 0
scanpairno = 0
scanpairList = []
for scanpair in sorted(param):
print "scanpair", scanpair
scanpairList.append(scanpair)
scanpairno = scanpairno + 1
for bcid in param[scanpair]:
try:
value = int(bcid)
except: TypeError
else:
plot.SetPoint(i, scanpairno, param[scanpair][bcid])
i = i+1
plot.GetXaxis().SetTitle('Scanpair')
plot.GetYaxis().SetTitle(paramName)
plot.Draw("AP")
canvas.SaveAs(outFileName +'(')
max = plot.GetHistogram().GetMaximum()
min = plot.GetHistogram().GetMinimum()
print "max, min", max, min
max = max*1.1
min = min*0.9
plot_byBX=[r.TGraphErrors() for i in range(noScanPairs)]
scanpairno = 0
for scanpair in param:
scanpairno= scanpairno + 1
i = 0
for bcid in param[scanpair]:
try:
value = int(bcid)
except: TypeError
else:
plot_byBX[int(scanpairno)-1].SetPoint(i, int(bcid), param[scanpair][bcid])
plot_byBX[int(scanpairno)-1].SetPointError(i, 0.0, paramErr[scanpair][bcid])
i = i+1
plot_byBX[0].SetMaximum(max)
plot_byBX[0].SetMinimum(min)
plot_byBX[0].SetMarkerColor(color[0])
plot_byBX[0].SetMarkerStyle(marker[0])
plot_byBX[0].SetMarkerSize(0.4)
plot_byBX[0].SetTitle(description + " " + paramName + " scan pair " + scanpairList[0])
plot_byBX[0].GetXaxis().SetTitle('BCID')
plot_byBX[0].GetYaxis().SetTitle(paramName)
plot_byBX[0].Draw("AP")
for i in range(1,noScanPairs):
plot_byBX[i].SetTitle(description + " " + paramName +" scan pair " + scanpairList[i])
plot_byBX[i].SetMarkerColor(color[i])
plot_byBX[i].SetMarkerStyle(marker[i])
plot_byBX[i].SetMarkerSize(0.4)
plot_byBX[i].Draw("P")
canvas.BuildLegend(0.65,0.8,0.95,0.95,"")
plot_byBX[0].SetTitle(description + " " + paramName)
canvas.SaveAs(outFileName +'(')
def addPlots(description, paramName, param, paramErr, ouFileName):
noScans = len(param)
canvas = r.TCanvas()
marker = [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
color = [2,3,4,6,7,2,3,4,6,7]
plot = r.TGraphErrors()
plot.SetMarkerStyle(8)
plot.SetMarkerSize(0.4)
plot.SetTitle(description + " " + paramName)
plot.GetXaxis().SetTitle('Scan number')
plot.GetYaxis().SetTitle(paramName)
# XorY = scan[scan.keys()[0]]
i = 0
for scan in param:
scanno= int(scan.strip("Scan_"))
for bcid in param[scan]:
try:
value = int(bcid)
except: TypeError
else:
plot.SetPoint(i, scanno, param[scan][bcid])
i = i+1
plot.GetXaxis().SetTitle('Scan')
plot.GetYaxis().SetTitle(paramName)
plot.Draw("AP")
canvas.SaveAs(outFileName +'(')
max = plot.GetHistogram().GetMaximum()
min = plot.GetHistogram().GetMinimum()
plot_byBX=[r.TGraphErrors() for i in range(noScans)]
for scan in param:
scanno= int(scan.strip("Scan_"))
i = 0
for bcid in param[scan]:
try:
value = int(bcid)
except: TypeError
else:
plot_byBX[int(scanno)-1].SetPoint(i, int(bcid), param[scan][bcid])
plot_byBX[int(scanno)-1].SetPointError(i, 0.0, paramErr[scan][bcid])
i = i+1
plot_byBX[0].SetMaximum(max*1.1)
plot_byBX[0].SetMinimum(min)
plot_byBX[0].SetMarkerColor(color[0])
plot_byBX[0].SetMarkerStyle(marker[0])
plot_byBX[0].SetMarkerSize(0.4)
plot_byBX[0].SetTitle(description + " " + paramName + " Scan 1")
plot_byBX[0].GetXaxis().SetTitle('BCID')
plot_byBX[0].GetYaxis().SetTitle(paramName)
plot_byBX[0].Draw("AP")
for i in range(1,noScans):
plot_byBX[i].SetTitle(description + " " + paramName +" " + " Scan " +str(i+1))
plot_byBX[i].SetMarkerColor(color[i])
plot_byBX[i].SetMarkerStyle(marker[i])
plot_byBX[i].SetMarkerSize(0.4)
plot_byBX[i].Draw("P")
canvas.BuildLegend(0.65,0.8,0.95,0.95,"")
plot_byBX[0].SetTitle(description + " " + paramName)
canvas.SaveAs(outFileName +'(')
if __name__ == '__main__':
configFile = sys.argv[1]
config=open(configFile)
ConfigInfo = json.load(config)
config.close()
Fill = ConfigInfo['Fill']
AnalysisDir = ConfigInfo['AnalysisDir']
Luminometer = ConfigInfo['Luminometer']
Corr = ConfigInfo['Corr']
FitName = ConfigInfo['FitName']
InputFitResultsFile = ConfigInfo['InputFitResultsFile']
corrFull = makeCorrString(Corr)
InputFitResultsFile = AnalysisDir + "/" + Luminometer + "/results/" + corrFull + "/" + InputFitResultsFile
InputXsecResultsFile = AnalysisDir + "/" + Luminometer + "/results/" + corrFull + "/" + 'LumiCalibration_'+ Luminometer+ '_'+ FitName + "_" + str(Fill)+'.pkl'
outFileName = AnalysisDir + "/" + Luminometer + "/results/" + corrFull + "/plots_"+FitName+"_"+Fill+".pdf"
fitResult = fitResultReader(InputFitResultsFile)
xsecResult = fitResultReader(InputXsecResultsFile)
# print ">> xsecResult"
# print xsecResult.fitParamNames
# Fit function parameters come in pairs of: value, valueErr
# Hand over value, valuerErr dictionaries to plotAll
# For other parameters, e.g. fit status, chi2, ndf, put them in separate list, for which pseudo error dictionary is provided where all errrors are set to 0.0
# First find out where block of fit function parameters with their errors is
paramlist = fitResult.fitParamNames[3:]
lasterridx = 0
for idx, entry in enumerate(paramlist):
if "Err" in entry:
lasterridx = idx
fitlist = paramlist[:(lasterridx+1)]
otherlist = paramlist[(lasterridx+1):]
# pair fit function parameters with their errors
fiterrpairs = zip(fitlist[0::2], fitlist[1::2])
description = Fill + " " + Luminometer + " " + FitName
for entry in fiterrpairs:
value = entry[0]
err = entry[1]
print value, err
paramName = value
param = fitResult.getFitParam(value)
paramErr = fitResult.getFitParam(err)
canvas = r.TCanvas()
addPlots(description, paramName, param, paramErr, outFileName)
import copy
for entry in otherlist:
paramName = entry
param = fitResult.getFitParam(paramName)
paramErr = copy.deepcopy(param)
for a in paramErr:
for b in paramErr[a]:
paramErr[a][b] = 0.0
canvas = r.TCanvas()
addPlots(description, paramName, param, paramErr, outFileName)
paramName = "xsec"
paramErrName = "xsecErr"
param = xsecResult.getFitParam(paramName)
print "param", param
paramErr = xsecResult.getFitParam(paramErrName)
canvas = r.TCanvas()
addXsecPlots(description, paramName, param, paramErr, outFileName)
canvas = r.TCanvas()
canvas.SaveAs(outFileName +']')