-
Notifications
You must be signed in to change notification settings - Fork 3
/
moduleSummaryPlot.py
executable file
·474 lines (357 loc) · 14.2 KB
/
moduleSummaryPlot.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
#!/usr/bin/env python
from ROOT import *
from array import array
import sys
from optparse import OptionParser
# options
# -v=0 - version of plot to get
# -t TEST which test to get results from
# -b bare plot (no axes or palette, canvas size = sensor size)
# -d directory within shareTestResults to look in
# -i=pxar.root input file
# --logz
### parse the command-line options
parser = OptionParser()
#parser = set_commandline_arguments(parser)
parser.add_option("-z", "--logz", action="store_true", dest="logZ", default=False,
help="sets the z axis to a log scale")
parser.add_option("-b", "--bare", action="store_true", dest="bareModule", default=False,
help="remove axes and palette - canvas will be size of sensor on wafer")
parser.add_option("-v", "--version", dest="plotVersion", default=0,
help="specify which version of plots to get (default = 0)")
parser.add_option("-d", "--dir", dest="inputDir",
help="input directory")
parser.add_option("-i", "--file", dest="inputFile",
help="input file (default = pxar.root)")
parser.add_option("-c", "--config", dest="config",
help="config file name")
parser.add_option("-t", "--test", dest="testType",
help="type of plot to get (default = ?)")
(arguments, args) = parser.parse_args()
print arguments, args
if arguments.config:
sys.path.append(os.getcwd())
exec("from " + re.sub (r".py$", r"", arguments.config) + " import *")
#gROOT.SetBatch()
gStyle.SetOptStat(0)
# true dimensions of a sensor in 10^-4 m (active area + periphery)
SENSOR_WIDTH = 672
SENSOR_HEIGHT = 186
PERIPHERY = 12.
gStyle.SetCanvasDefH(SENSOR_HEIGHT)
gStyle.SetCanvasDefW(SENSOR_WIDTH)
gStyle.SetCanvasBorderMode(0)
gStyle.SetCanvasBorderSize(0)
gStyle.SetPadBorderMode(0)
gStyle.SetPadBorderSize(0)
gStyle.SetFrameBorderMode(0)
gStyle.SetFrameBorderSize(0)
gStyle.SetPadColor(0)
gStyle.SetCanvasColor(0)
gStyle.SetCanvasDefX(0)
gStyle.SetCanvasDefY(0)
gStyle.SetPadTopMargin(PERIPHERY/SENSOR_HEIGHT)
gStyle.SetPadBottomMargin(PERIPHERY/SENSOR_HEIGHT)
gStyle.SetPadLeftMargin(PERIPHERY/SENSOR_WIDTH)
gStyle.SetPadRightMargin(PERIPHERY/SENSOR_WIDTH)
gStyle.SetHistTopMargin(0)
gStyle.SetTitleColor(1, "XYZ")
gStyle.SetTitleFont(42, "XYZ")
gStyle.SetTitleSize(0.1, "XYZ")
gStyle.SetTitleXOffset(1.1)
gStyle.SetTitleYOffset(1.2)
gStyle.SetTextFont(42)
gStyle.SetTextAlign(12)
gStyle.SetLabelColor(1, "XYZ")
gStyle.SetLabelFont(42, "XYZ")
gStyle.SetLabelOffset(0.007, "XYZ")
gStyle.SetLabelSize(0.05, "XYZ")
gStyle.SetLabelSize(0.0, "XYZ")
gStyle.SetAxisColor(1, "XYZ")
gStyle.SetStripDecimals(True)
gStyle.SetTickLength(-0.02, "XYZ")
gStyle.SetTickLength(0.0, "XYZ")
gStyle.SetNdivisions(509, "XYZ")
gStyle.SetPadTickX(0)
gStyle.SetPadTickY(0)
gROOT.ForceStyle()
colors = [kBlack,kRed,kGreen,kBlue]
#input=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/M_LL_915/NoiseScan.root')
#input=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/P-A-03-36/NoiseScan.root')
#input=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/P-A-03-34/NoiseScan.root')
#FR 911
#input=TFile('/Users/lantonel/Xcross_Calibration_Results/robert/n00902data/bbond40_0417.root')
#RR 911
#input=TFile('/Users/lantonel/Xcross_Calibration_Results/robert/n00901data/bbond40_0422.root')
#LL 914
#input=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/P-A-03-42/BBtesting.root')
#LL 915
#input=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/M_LL_915/pxar_20150417_161149.root')
#TT 915
#input=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/P-A-03-36/pxar_20150421_114558.root')
#FR 915
#input=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/P-A-3-34/pxar.root')
#input=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/P-A-3-34/pxar_20150422_172026.root')
#CR 915
#input=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/P-A-3-43/pxar.root')
#RR 915
#input=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/P-A-2-42/pxar.root')
#FR 902 (x-rays)
#input=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/M_FR_902_400V/FluxTest_Total.root')
#LL 914 (x-rays)
#input=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/P-A-3-42/HR_08mA_40Hz_10sOK.root')
#TT 915
#input=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/P-A-3-36/ROCAlignmentTest_BB3.root')
#input2=TFile('/Users/lantonel/PlotsAndTables/pXarSharedResults/P-A-3-36/ROCAlignmentTest_SCurves.root')
###############################################################################
# splits plots into two distributions of odd/even column
def makeColumnPlots(plots):
outputFile = TFile("doubleColumnPlots.root", "RECREATE")
outputFile.cd()
for roc in range(16):
plot = plots[roc]
legend = TLegend(0.7181208,0.6945899,0.9496644,0.9441536)
plot_name = "DoubleColumnSplit_C" + str(roc)
oneDPlot = TH1F(plot_name,plot_name,255,0,255)
oneDEvenPlot = TH1F("1deven","1deven",255,0,255)
oneDOddPlot = TH1F("1dodd","1dodd",255,0,255)
for x in range(1,plot.GetNbinsX()+1):
for y in range(1,plot.GetNbinsY()+1):
content = plot.GetBinContent(x,y)
oneDPlot.Fill(content)
if (x-1)%2 == 0:
oneDEvenPlot.Fill(content)
else:
oneDOddPlot.Fill(content)
mean = oneDPlot.GetMean()
sigma = oneDPlot.GetRMS()
plot_name = "DoubleColumnSplit_C" + str(roc)
canvas = TCanvas(plot_name,"",-1)
oneDPlot.SetLineWidth(6)
oneDEvenPlot.SetLineWidth(2)
oneDOddPlot.SetLineWidth(2)
oneDEvenPlot.SetLineColor(kRed)
oneDOddPlot.SetLineColor(kBlue)
legend.AddEntry(oneDEvenPlot,"even columns")
legend.AddEntry(oneDOddPlot,"odd columns")
legend.AddEntry(oneDPlot,"all columns")
oneDPlot.Draw()
oneDEvenPlot.Draw("same")
oneDOddPlot.Draw("same")
legend.Draw()
canvas.Write()
oneDPlot.Delete()
oneDEvenPlot.Delete()
oneDOddPlot.Delete()
outputFile.Close()
# oneDPlot.Delete()
###############################################################################
# subtracts out the double-column variations
def doSubtraction(plots,normalizations):
for roc in range(16):
plots[roc].Add(normalizations[roc],-1)
###############################################################################
# rescales thr plots by subtracting chip mean
def rescalePlots(plots):
for roc in range(16):
plot = plots[roc]
oneDPlot = TH1F("1d","1d",255,0,255)
for x in range(1,plot.GetNbinsX()+1):
for y in range(1,plot.GetNbinsY()+1):
content = plot.GetBinContent(x,y)
oneDPlot.Fill(content)
mean = oneDPlot.GetMean()
sigma = oneDPlot.GetRMS()
oneDPlot.Delete()
print "******* ROC",roc
print mean, sigma
for x in range(1,plot.GetNbinsX()+1):
for y in range(1,plot.GetNbinsY()+1):
content = plot.GetBinContent(x,y)
content -= mean
content /= sigma
plot.SetBinContent(x,y,content)
###############################################################################
# rescales thr plots by subtracting chip mean
def rescalePlots_DoubleColumn(plots):
for roc in range(16):
plot = plots[roc]
oneDEvenPlot = TH1F("1deven","1deven",255,0,255)
oneDOddPlot = TH1F("1dodd","1dodd",255,0,255)
for x in range(1,plot.GetNbinsX()+1):
for y in range(1,plot.GetNbinsY()+1):
content = plot.GetBinContent(x,y)
if (x-1)%2 == 0:
oneDEvenPlot.Fill(content)
else:
oneDOddPlot.Fill(content)
mean_even = oneDEvenPlot.GetMean()
sigma_even = oneDEvenPlot.GetRMS()
mean_odd = oneDOddPlot.GetMean()
sigma_odd = oneDOddPlot.GetRMS()
oneDEvenPlot.Delete()
oneDOddPlot.Delete()
# print "******* ROC",roc
# print mean, sigma
for x in range(1,plot.GetNbinsX()+1):
for y in range(1,plot.GetNbinsY()+1):
content = plot.GetBinContent(x,y)
if (x-1)%2 == 0:
content -= mean_even
content /= sigma_even
else:
content -= mean_odd
content /= sigma_odd
plot.SetBinContent(x,y,content)
###############################################################################
# fill in units of 50um to account for larger edge pixels
# return merged plot
def mergePlots(plots):
# 100um = 2
# 150um = 3
# 200um = 4
# 300um = 6
# ROCs have 52 columns (x) and 80 rows (y)
# x bins are units of 150um (except for bigger edge pixels)
rocBinEdgesX = [0]
for x in range(0,3*51,3):
rocBinEdgesX.append(x+6) # first bin is 6 wide
# rocBinEdgesX.append(162)
# y bins are units of 100um (except for bigger edge pixels)
rocBinEdgesY = [0]
for y in range(0,2*79,2):
rocBinEdgesY.append(y+2) # first bin is 2 wide
# rocBinEdgesY.append(164)
# ROC plots are 162 wide by 162 high
# we want to create a plot that's 8x2 ROCs
moduleBinEdgesX = []
for roc in range(8): # 0 - 7
for edge in rocBinEdgesX:
moduleBinEdgesX.append(edge + 162*roc)
moduleBinEdgesX.append(1296) # add final bin by hand
moduleBinEdgesY = []
for roc in range(2): # 0 - 1
for edge in rocBinEdgesY:
moduleBinEdgesY.append(edge + 162*roc)
moduleBinEdgesY.append(324) # add final bin by hand
# create clone of plot with new bin sizes
summaryPlot = TH2D("summaryPlot",
"",
len(moduleBinEdgesX)-1,
array('d',moduleBinEdgesX),
len(moduleBinEdgesY)-1,
array('d',moduleBinEdgesY))
# fill new histogram with contents of original plots
# start with ROC 0 at the top right, because reason
# fill bottom row first
for roc in range(8,16):
plot = plots[roc]
for x in range(1,plot.GetNbinsX()+1):
for y in range(1,plot.GetNbinsY()+1):
content = plot.GetBinContent(x,y)
error = plot.GetBinError(x,y)
summaryPlot.SetBinContent(x+52*(roc-8),y,content)
summaryPlot.SetBinError(x+52*(roc-8),y,error)
# fill top row next
for roc in range(7,-1,-1): # loop backwards so 0 is last
plot = plots[roc]
for x in range(1,plot.GetNbinsX()+1):
for y in range(1,plot.GetNbinsY()+1):
content = plot.GetBinContent(x,y)
error = plot.GetBinError(x,y)
summaryPlot.SetBinContent(x+52*(7-roc),y+80,content)
summaryPlot.SetBinError(x+52*(7-roc),y+80,error)
summaryPlot.SetMaximum(5)
summaryPlot.SetMinimum(-5)
#summaryPlot.GetXaxis().SetAxisColor(3,0)
#summaryPlot.GetYaxis().SetAxisColor(3,0)
return summaryPlot
###############################################################################
# input a histogram and return a flipped version
def flipTopRow(plots):
for roc in range(8):
histo = plots[roc].Clone()
histo.SetDirectory(0)
histo.Reset()
nBinsX = histo.GetNbinsX()
nBinsY = histo.GetNbinsY()
for x in range(1,nBinsX+1):
for y in range(1, nBinsY+1):
content = plots[roc].GetBinContent(x,y)
error = plots[roc].GetBinError(x,y)
histo.SetBinContent(nBinsX-x+1, nBinsY-y+1, content)
histo.SetBinError(nBinsX-x+1, nBinsY-y+1, error)
plots[roc] = histo
###############################################################################
# gets the global min and max
# for each ROC, find mean & RMS
# set global range from min(mean-nSigma*RMS) to max(mean+nSigma*RMS)
# where min() and max() operate on the set of ROCs
def setZRange(plots):
zMax = -999
zMin = 999
nSigma = 1
for roc in range(16):
plot = plots[roc]
currentMax = plot.GetMaximum()
currentMin = plot.GetMinimum()
oneDPlot = TH1F("1d","1d",100,currentMin,currentMax)
for x in range(1,plot.GetNbinsX()+1):
for y in range(1,plot.GetNbinsY()+1):
content = plot.GetBinContent(x,y)
oneDPlot.Fill(content)
mean = oneDPlot.GetMean()
sigma = oneDPlot.GetRMS()
oneDPlot.Delete()
currentMax = mean + nSigma*sigma
currentMin = mean - nSigma*sigma
if currentMax > zMax:
zMax = currentMax
if currentMin < zMin:
zMin = currentMin
# reset min to 0 if it's negative
if zMin < 0:
zMin = 0
# # for now (for thr plots)
# zMin = 60
# zMax = 110
# for now (for rescaled plots)
# zMin = -10
# zMax = 10
# zMin = -2.5
# zMax = 2.5
# zMin = 0
# this included the palette as well
for plot in plots:
plot.SetMaximum(zMax)
plot.SetMinimum(zMin)
###############################################################################
# draws 16 plots in the appropriate places
def drawPlot(summaryPlot):
outputFile = TFile("moduleSummaryBareBB.root", "RECREATE")
outputFile.cd()
# draw canvas
canvas = TCanvas("test","",-1)
canvas.SetCanvasSize(SENSOR_WIDTH,SENSOR_HEIGHT)
canvas.SetFixedAspectRatio()
canvas.Draw()
#canvas.SetLogz()
summaryPlot.Draw("col") # in color (without palette)
canvas.Update()
canvas.Write()
outputFile.Close()
#canvas.SaveAs("moduleSummaryBareBB.pdf")
return canvas
###############################################################################
def doIt(input, dir, testType, plotVersion):
plots = []
# get plots
for roc in range(16):
plot = input.Get(dir+'/'+testType+'_C'+str(roc)+'_V'+str(plotVersion))
plot.SetTitle("")
plots.append(plot)
flipTopRow(plots)
setZRange(plots)
summaryPlot = mergePlots(plots)
c=drawPlot(summaryPlot)
return c.Clone()