This repository has been archived by the owner on Jan 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
anaSBitMonitor.py
executable file
·532 lines (450 loc) · 26.8 KB
/
anaSBitMonitor.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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
#!/bin/env python
"""
anaSbitMonitor.py
=================
"""
if __name__ == '__main__':
import os
import sys
import argparse
from gempython.gemplotting.utils.anaoptions import parent_parser
parser = argparse.ArgumentParser(description="Options to give to anaSBitMonitor.py", parents=[parent_parser])
parser.add_argument("--checkInvalid",action="store_true",help="If provided invalid sbits will be considered")
parser.set_defaults(outfilename="SBitMonitorData.root")
args = parser.parse_args()
filename = args.infilename[:-5]
os.system("mkdir " + args.infilename[:-5])
outfilename = args.outfilename
import ROOT as r
#r.TH1.SetDefaultSumw2(True)
r.gROOT.SetBatch(True)
outF = r.TFile(filename+'/'+outfilename, 'recreate')
inF = r.TFile(filename+'.root')
# Determine the rates scanned
print('Determining rates tested')
import numpy as np
import root_numpy as rp #note need root_numpy-4.7.2 (may need to run 'pip install root_numpy --upgrade')
list_bNames = ['calEnable','isValid','ratePulsed']
initInfo = rp.tree2array(tree=inF.sbitDataTree, branches=list_bNames)
calEnableValues = np.unique(initInfo['calEnable'])
isValidValues = np.unique(initInfo['isValid'])
ratesUsed = np.unique(initInfo['ratePulsed'])
##### FIXME
from gempython.gemplotting.mapping.chamberInfo import gemTypeMapping
if 'gemType' not in inF.sbitDataTree.GetListOfBranches():
gemType = "ge11"
else:
gemType = gemTypeMapping[rp.tree2array(tree=inF.sbitDataTree, branches =[ 'gemType' ] )[0][0]]
print gemType
##### END
from gempython.tools.hw_constants import vfatsPerGemVariant
nVFATS = vfatsPerGemVariant[gemType]
from gempython.gemplotting.mapping.chamberInfo import CHANNELS_PER_VFAT as maxChans
print('Initializing histograms')
from gempython.utils.nesteddict import nesteddict as ndict, flatten
# Summary plots - 2D
dict_h_vfatObsVsVfatPulsed = ndict() #Keys as: [isValid][calEnable][rate]
# VFAT lvl plots - 1D
dict_h_sbitMulti = ndict() #Keys as: [isValid][calEnable][rate][vfat]
dict_h_sbitSize = ndict() #Keys as: [isValid][calEnable][rate][vfat]
# VFAT lvl plots - 2D
dict_g_rateObsCTP7VsRatePulsed = ndict() #Keys as: [isValid][vfat]
dict_g_rateObsFPGAVsRatePulsed = ndict() #Keys as: [isValid][vfat]
dict_g_rateObsVFATVsRatePulsed = ndict() #Keys as: [isValid][vfat]
dict_h_chanVsRatePulsed_ZRateObs = ndict() #Z axis is rate observed; Keys as: [isValid][calEnable][vfat]
dict_h_sbitObsVsChanPulsed = ndict() #Keys as: [isValid][calEnable][rate][vfat]
dict_h_sbitMultiVsSbitSize = ndict() #Keys as: [isValid][calEnable][rate][vfat]
rateMap = {}
from gempython.gemplotting.utils.anautilities import formatSciNotation
for isValid in isValidValues:
if not isValid and not args.checkInvalid:
continue
if isValid:
strValidity="validSbits"
else:
strValidity="invalidSbits"
for calEnable in calEnableValues:
if calEnable:
strCalStatus="calEnabled"
strPulsedOrUnmasked="Pulsed"
else:
strCalStatus="calDisabled"
strPulsedOrUnmasked="Unmasked"
postScript = "{0}_{1}".format(strValidity,strCalStatus)
# Summary Case
for rate in ratesUsed:
if ( not ( (calEnable and rate > 0) or (not calEnable and rate == 0.0) ) ):
continue
# 2D Observables
dict_h_vfatObsVsVfatPulsed[isValid][calEnable][rate] = r.TH2F(
"h_vfatObservedVsVfatPulsed_{0}_{1}Hz".format(postScript,int(rate)),
"Summmary - Rate {0} Hz;VFAT {1};VFAT Observed".format(int(rate),strPulsedOrUnmasked),
nVFATS,-0.5,nVFATS-0.5, nVFATS,-0.5,nVFATS-0.5)
dict_h_vfatObsVsVfatPulsed[isValid][calEnable][rate].Sumw2()
for vfat in range(0, nVFATS):
dict_h_chanVsRatePulsed_ZRateObs[isValid][calEnable][vfat] = r.TH2F(
"h_chanVsRatePulsed_ZRateObs_vfat{0}_{1}".format(vfat,postScript),
"VFAT{0};Rate #left(Hz#right);Channel",
len(ratesUsed),0,len(ratesUsed),
maxChans, -0.5, maxChans-0.5)
# Overall Rate Observed by CTP7
if calEnable:
dict_g_rateObsCTP7VsRatePulsed[isValid][vfat] = r.TGraphErrors()
dict_g_rateObsCTP7VsRatePulsed[isValid][vfat].SetName(
"g_rateObsCTP7VsRatePulsed_vfat{0}_{1}".format(vfat,strValidity))
dict_g_rateObsCTP7VsRatePulsed[isValid][vfat].SetTitle(
"VFAT {0};Rate Pulsed #left(Hz#right);Rate Observed #left(Hz#right)".format(vfat))
dict_g_rateObsCTP7VsRatePulsed[isValid][vfat].SetLineColor(r.kBlue)
dict_g_rateObsCTP7VsRatePulsed[isValid][vfat].SetLineWidth(2)
dict_g_rateObsCTP7VsRatePulsed[isValid][vfat].SetMarkerColor(r.kBlue)
dict_g_rateObsCTP7VsRatePulsed[isValid][vfat].SetMarkerStyle(22)
# Overall Rate Observed by OH FPGA
dict_g_rateObsFPGAVsRatePulsed[isValid][vfat] = r.TGraphErrors()
dict_g_rateObsFPGAVsRatePulsed[isValid][vfat].SetName(
"g_rateObsFPGAVsRatePulsed_vfat{0}_{1}".format(vfat,strValidity))
dict_g_rateObsFPGAVsRatePulsed[isValid][vfat].SetTitle(
"VFAT {0};Rate Pulsed #left(Hz#right);Rate Observed #left(Hz#right)".format(vfat))
dict_g_rateObsFPGAVsRatePulsed[isValid][vfat].SetLineColor(r.kRed)
dict_g_rateObsFPGAVsRatePulsed[isValid][vfat].SetLineWidth(2)
dict_g_rateObsFPGAVsRatePulsed[isValid][vfat].SetMarkerColor(r.kRed)
dict_g_rateObsFPGAVsRatePulsed[isValid][vfat].SetMarkerStyle(23)
# Per VFAT Rate Observed by OH
dict_g_rateObsVFATVsRatePulsed[isValid][vfat] = r.TGraphErrors()
dict_g_rateObsVFATVsRatePulsed[isValid][vfat].SetName(
"g_rateObsVFATVsRatePulsed_vfat{0}_{1}".format(vfat,strValidity))
dict_g_rateObsVFATVsRatePulsed[isValid][vfat].SetTitle(
"VFAT {0};Rate Pulsed #left(Hz#right);Rate Observed #left(Hz#right)".format(vfat))
dict_g_rateObsVFATVsRatePulsed[isValid][vfat].SetLineColor(r.kGreen)
dict_g_rateObsVFATVsRatePulsed[isValid][vfat].SetLineWidth(2)
dict_g_rateObsVFATVsRatePulsed[isValid][vfat].SetMarkerColor(r.kGreen)
dict_g_rateObsVFATVsRatePulsed[isValid][vfat].SetMarkerStyle(24)
for binX,rate in enumerate(ratesUsed):
if vfat == 0: # Summary Case
# Set bin labels
rateMap[rate]=binX+1 # Used later to translate rate to bin position
dict_h_chanVsRatePulsed_ZRateObs[isValid][calEnable][vfat].GetXaxis().SetBinLabel(binX+1,formatSciNotation(str(rate)))
# VFAT level
if (calEnable or (not calEnable and rate == 0.0)):
# 1D Obs
dict_h_sbitMulti[isValid][calEnable][rate][vfat] = r.TH1F(
"h_sbitMulti_vfat{0}_{1}_{2}Hz".format(vfat,postScript,int(rate)),
"VFAT{0} - Rate {1} Hz;SBIT Multiplicity;N".format(vfat,int(rate)),
9,-0.5,8.5)
dict_h_sbitMulti[isValid][calEnable][rate][vfat].Sumw2()
dict_h_sbitSize[isValid][calEnable][rate][vfat] = r.TH1F(
"h_sbitSize_vfat{0}_{1}_{2}Hz".format(vfat,postScript,int(rate)),
"VFAT{0} - Rate {1} Hz;SBIT Size;N".format(vfat,int(rate)),
8,-0.5,7.5)
dict_h_sbitSize[isValid][calEnable][rate][vfat].Sumw2()
# 2D Obs
dict_h_sbitObsVsChanPulsed[isValid][calEnable][rate][vfat] = r.TH2F(
"h_sbitObsVsChanPulsed_vfat{0}_{1}_{2}Hz".format(vfat,postScript,int(rate)),
"VFAT{0} - Rate {1} Hz;Channel {2};SBIT Observed".format(vfat,int(rate),strPulsedOrUnmasked),
maxChans, -0.5, maxChans-0.5,64,-0.5,63.5)
dict_h_sbitObsVsChanPulsed[isValid][calEnable][rate][vfat].Sumw2()
dict_h_sbitMultiVsSbitSize[isValid][calEnable][rate][vfat] = r.TH2F(
"h_sbitMultiVsSbitSize_vfat{0}_{1}_{2}Hz".format(vfat,postScript,int(rate)),
"VFAT{0} - Rate {1} Hz;SBIT Size;SBIT Multiplicity".format(vfat,int(rate)),
8,-0.5,7.5,9,-0.5,8.5)
dict_h_sbitMultiVsSbitSize[isValid][calEnable][rate][vfat].Sumw2()
print("Looping over events and filling histograms")
dict_validSbitsPerEvt = ndict()
dict_listSbitSizesPerEvt = ndict()
dict_wrongSbit2ChanMapping = ndict() # Keys [vfatN][vfatSBIT][sbitSize] = number of occurrences
dict_wrongVfatObs2VfatPulsedMapping = ndict() # Key [(vfatN,vfatObs)] = number of occurrences
from math import floor, sqrt
lastPrintedEvt = 0
for entry in inF.sbitDataTree:
# Get Values from tree for readability
calEnable = entry.calEnable
evtNum = entry.evtNum
isValid = entry.isValid
rate = entry.ratePulsed
rateObsCTP7 = entry.rateObservedCTP7
rateObsFPGA = entry.rateObservedFPGA
rateObsVFAT = entry.rateObservedVFAT
sbitSize = entry.sbitClusterSize
vfatCH = entry.vfatCH
vfatSBIT = entry.vfatSBIT
vfatN = entry.vfatN
vfatObs = entry.vfatObserved
if( (evtNum % 1000) == 0 and lastPrintedEvt != evtNum):
lastPrintedEvt = evtNum
print("processed {0} events so far".format(entry.evtNum))
# Skip this event because it's invaldi?
if not isValid and not args.checkInvalid:
continue
# Summary Plots
dict_h_vfatObsVsVfatPulsed[isValid][calEnable][rate].Fill(vfatN,vfatObs)
if(vfatN == vfatObs): # Fill the following plots only when isVFATMappingCorrect is true
# Track if sbit is mismatched
if (vfatSBIT != floor(vfatCH/2)):
if (sbitSize in dict_wrongSbit2ChanMapping[vfatN][vfatSBIT].keys()):
dict_wrongSbit2ChanMapping[vfatN][vfatSBIT][sbitSize] += 1
else:
dict_wrongSbit2ChanMapping[vfatN][vfatSBIT][sbitSize] = 1
# Track sbit multiplicity
if evtNum in dict_validSbitsPerEvt[isValid][calEnable][rate][vfatN].keys():
if isValid:
dict_validSbitsPerEvt[isValid][calEnable][rate][vfatN][evtNum]+=1
else:
if isValid:
dict_validSbitsPerEvt[isValid][calEnable][rate][vfatN][evtNum]=1
else:
dict_validSbitsPerEvt[isValid][calEnable][rate][vfatN][evtNum]=0
# Store sbit size
if evtNum in dict_listSbitSizesPerEvt[isValid][calEnable][rate][vfatN].keys():
if isValid:
dict_listSbitSizesPerEvt[isValid][calEnable][rate][vfatN][evtNum].append(sbitSize)
else:
if isValid:
dict_listSbitSizesPerEvt[isValid][calEnable][rate][vfatN][evtNum] = [sbitSize]
else:
dict_listSbitSizesPerEvt[isValid][calEnable][rate][vfatN][evtNum] = []
# VFAT lvl plots - 1D
dict_h_sbitSize[isValid][calEnable][rate][vfatN].Fill(sbitSize)
# VFAT lvl plots - 2D
newPt = dict_g_rateObsCTP7VsRatePulsed[isValid][vfatN].GetN()
dict_g_rateObsCTP7VsRatePulsed[isValid][vfatN].SetPoint(
newPt,
rate,
rateObsCTP7)
dict_g_rateObsCTP7VsRatePulsed[isValid][vfatN].SetPointError(
newPt,
0,
sqrt(rateObsCTP7))
newPt = dict_g_rateObsFPGAVsRatePulsed[isValid][vfatN].GetN()
dict_g_rateObsFPGAVsRatePulsed[isValid][vfatN].SetPoint(
newPt,
rate,
rateObsFPGA)
dict_g_rateObsFPGAVsRatePulsed[isValid][vfatN].SetPointError(
newPt,
0,
sqrt(rateObsFPGA))
newPt = dict_g_rateObsVFATVsRatePulsed[isValid][vfatN].GetN()
dict_g_rateObsVFATVsRatePulsed[isValid][vfatN].SetPoint(
newPt,
rate,
rateObsVFAT)
dict_g_rateObsVFATVsRatePulsed[isValid][vfatN].SetPointError(
newPt,
0,
sqrt(rateObsVFAT))
#dict_h_chanVsRatePulsed_ZRateObs
dict_h_sbitObsVsChanPulsed[isValid][calEnable][rate][vfatN].Fill(vfatCH,vfatSBIT)
else: #VFAT Mapping is incorrect?
if( (vfatN,vfatObs) in dict_wrongVfatObs2VfatPulsedMapping.keys()):
dict_wrongVfatObs2VfatPulsedMapping[(vfatN,vfatObs)] += 1
else:
dict_wrongVfatObs2VfatPulsedMapping[(vfatN,vfatObs)] = 1
print("Filling multiplicity distributions")
for isValid in isValidValues:
if not isValid and not args.checkInvalid:
continue
for calEnable in calEnableValues:
for rate in ratesUsed:
for vfat in range(0, nVFATS):
for event,multi in dict_validSbitsPerEvt[isValid][calEnable][rate][vfat].iteritems():
dict_h_sbitMulti[isValid][calEnable][rate][vfat].Fill(multi)
for size in dict_listSbitSizesPerEvt[isValid][calEnable][rate][vfat][event]:
dict_h_sbitMultiVsSbitSize[isValid][calEnable][rate][vfat].Fill(size,multi)
print("Making summary plots")
from gempython.gemplotting.utils.anautilities import addPlotToCanvas, getSummaryCanvas
for isValid in isValidValues:
if not isValid and not args.checkInvalid:
continue
if isValid:
strValidity="validSbits"
else:
strValidity="invalidSbits"
# All Rates
rateCanvas = getSummaryCanvas(dict_g_rateObsCTP7VsRatePulsed[isValid],
name="rateObservedVsRatePulsed_{0}".format(strValidity),
drawOpt="APE1", gemType=gemType)
rateCanvas = addPlotToCanvas(rateCanvas, dict_g_rateObsFPGAVsRatePulsed[isValid], drawOpt="PE1", gemType=gemType)
rateCanvas = addPlotToCanvas(rateCanvas, dict_g_rateObsVFATVsRatePulsed[isValid], drawOpt="PE1", gemType=gemType)
# Make the legend
rateLeg = r.TLegend(0.5,0.5,0.9,0.9)
rateLeg.AddEntry(
dict_g_rateObsCTP7VsRatePulsed[isValid][0],
"CTP7 Rate",
"LPE")
rateLeg.AddEntry(
dict_g_rateObsFPGAVsRatePulsed[isValid][0],
"FPGA Rate",
"LPE")
rateLeg.AddEntry(
dict_g_rateObsVFATVsRatePulsed[isValid][0],
"VFAT Rate",
"LPE")
rateCanvas.cd(1)
rateLeg.Draw("same")
# Save Canvas
rateCanvas.SaveAs("{0}/rateObservedVsRatePulsed_{1}.png".format(filename,strValidity))
# CalDisable rate 0 case
getSummaryCanvas(dict_h_sbitMulti[isValid][0][0], name="{0}/sbitMulti_{1}_calDisabled_0Hz.png".format(filename,strValidity), drawOpt="", gemType=gemType, write2Disk=True)
getSummaryCanvas(dict_h_sbitSize[isValid][0][0], name="{0}/sbitSize_{1}_calDisabled_0Hz.png".format(filename,strValidity), drawOpt="", gemType=gemType, write2Disk=True)
getSummaryCanvas(dict_h_sbitObsVsChanPulsed[isValid][0][0], name="{0}/sbitObsVsChanUnmasked_{1}_calDisabled_0Hz.png".format(filename,strValidity), drawOpt="COLZ", gemType=gemType, write2Disk=True)
getSummaryCanvas(dict_h_sbitMultiVsSbitSize[isValid][0][0], name="{0}/sbitMultiVsSbitSize_{1}_calDisabled_0Hz.png".format(filename,strValidity), drawOpt="COLZ", gemType=gemType, write2Disk=True)
for idx,rate in enumerate(ratesUsed):
# Sum over all rates
if rate > 0:
if (-1 not in dict_h_vfatObsVsVfatPulsed[isValid][1].keys()):
name = dict_h_vfatObsVsVfatPulsed[isValid][1][rate].GetName()
title = dict_h_vfatObsVsVfatPulsed[isValid][1][rate].GetTitle()
dict_h_vfatObsVsVfatPulsed[isValid][1][-1] = dict_h_vfatObsVsVfatPulsed[isValid][1][rate].Clone(name.replace("{0}Hz".format(int(rate)),"SumOfAllRates"))
dict_h_vfatObsVsVfatPulsed[isValid][1][-1].SetTitle(title.replace("Rate {0} Hz".format(int(rate)), "Sum of All Rates"))
else:
dict_h_vfatObsVsVfatPulsed[isValid][1][-1].Add(dict_h_vfatObsVsVfatPulsed[isValid][1][rate])
cloneExists = { vfat:False for vfat in range(0, nVFATS) }
for vfat in range(0, nVFATS):
if ( not cloneExists[vfat] ):
cloneExists[vfat] = True
name = dict_h_sbitMulti[isValid][1][rate][vfat].GetName()
title = dict_h_sbitMulti[isValid][1][rate][vfat].GetTitle()
dict_h_sbitMulti[isValid][1][-1][vfat] = dict_h_sbitMulti[isValid][1][rate][vfat].Clone(name.replace("{0}Hz".format(int(rate)),"SumOfAllRates"))
dict_h_sbitMulti[isValid][1][-1][vfat].SetTitle(title.replace("Rate {0} Hz".format(int(rate)), "Sum of All Rates"))
name = dict_h_sbitSize[isValid][1][rate][vfat].GetName()
title = dict_h_sbitSize[isValid][1][rate][vfat].GetTitle()
dict_h_sbitSize[isValid][1][-1][vfat] = dict_h_sbitSize[isValid][1][rate][vfat].Clone(name.replace("{0}Hz".format(int(rate)),"SumOfAllRates"))
dict_h_sbitSize[isValid][1][-1][vfat].SetTitle(title.replace("Rate {0} Hz".format(int(rate)), "Sum of All Rates"))
name = dict_h_sbitObsVsChanPulsed[isValid][1][rate][vfat].GetName()
title = dict_h_sbitObsVsChanPulsed[isValid][1][rate][vfat].GetTitle()
dict_h_sbitObsVsChanPulsed[isValid][1][-1][vfat] = dict_h_sbitObsVsChanPulsed[isValid][1][rate][vfat].Clone(name.replace("{0}Hz".format(int(rate)),"SumOfAllRates"))
dict_h_sbitObsVsChanPulsed[isValid][1][-1][vfat].SetTitle(title.replace("Rate {0} Hz".format(int(rate)), "Sum of All Rates"))
name = dict_h_sbitMultiVsSbitSize[isValid][1][rate][vfat].GetName()
title = dict_h_sbitMultiVsSbitSize[isValid][1][rate][vfat].GetTitle()
dict_h_sbitMultiVsSbitSize[isValid][1][-1][vfat] = dict_h_sbitMultiVsSbitSize[isValid][1][rate][vfat].Clone(name.replace("{0}Hz".format(int(rate)),"SumOfAllRates"))
dict_h_sbitMultiVsSbitSize[isValid][1][-1][vfat].SetTitle(title.replace("Rate {0} Hz".format(int(rate)), "Sum of All Rates"))
else:
dict_h_sbitMulti[isValid][1][-1][vfat].Add(dict_h_sbitMulti[isValid][1][rate][vfat])
dict_h_sbitSize[isValid][1][-1][vfat].Add(dict_h_sbitSize[isValid][1][rate][vfat])
dict_h_sbitObsVsChanPulsed[isValid][1][-1][vfat].Add(dict_h_sbitObsVsChanPulsed[isValid][1][rate][vfat])
dict_h_sbitMultiVsSbitSize[isValid][1][-1][vfat].Add(dict_h_sbitMultiVsSbitSize[isValid][1][rate][vfat])
getSummaryCanvas(dict_h_sbitMulti[isValid][1][-1], name="{0}/sbitMulti_{1}_calEnabled_SumOfAllRates.png".format(filename,strValidity), drawOpt="", gemType=gemType, write2Disk=True)
getSummaryCanvas(dict_h_sbitSize[isValid][1][-1], name="{0}/sbitSize_{1}_calEnabled_SumOfAllRates.png".format(filename,strValidity), drawOpt="", gemType=gemType, write2Disk=True)
getSummaryCanvas(dict_h_sbitObsVsChanPulsed[isValid][1][-1], name="{0}/sbitObsVsChanPulsed_{1}_calEnabled_SumOfAllRates.png".format(filename,strValidity), drawOpt="COLZ", gemType=gemType, write2Disk=True)
getSummaryCanvas(dict_h_sbitMultiVsSbitSize[isValid][1][-1], name="{0}/sbitMultiVsSbitSize_{1}_calEnabled_SumOfAllRates.png".format(filename,strValidity), drawOpt="COLZ", gemType=gemType, write2Disk=True)
print("Storing TObjects in output TFile")
# Per VFAT Plots
for vfat in range(0, nVFATS):
dirVFAT = outF.mkdir("VFAT{0}".format(vfat))
for isValid in isValidValues:
if not isValid and not args.checkInvalid:
continue
if isValid:
strValidity="validSbits"
else:
strValidity="invalidSbits"
dirIsValid = dirVFAT.mkdir(strValidity)
dirIsValid.cd()
dict_g_rateObsCTP7VsRatePulsed[isValid][vfat].Write()
dict_g_rateObsFPGAVsRatePulsed[isValid][vfat].Write()
dict_g_rateObsVFATVsRatePulsed[isValid][vfat].Write()
for calEnable in calEnableValues:
if calEnable:
strCalStatus="calEnabled"
else:
strCalStatus="calDisabled"
dirCalStatus = dirIsValid.mkdir(strCalStatus)
if calEnable:
dirCalStatus.cd()
dict_h_sbitMulti[isValid][calEnable][-1][vfat].Write()
dict_h_sbitSize[isValid][calEnable][-1][vfat].Write()
dict_h_sbitObsVsChanPulsed[isValid][calEnable][-1][vfat].Write()
dict_h_sbitMultiVsSbitSize[isValid][calEnable][-1][vfat].Write()
for rate in ratesUsed:
if ( not ( (calEnable and rate > 0) or (not calEnable and rate == 0.0) ) ):
continue
dirRate = dirCalStatus.mkdir("{0}Hz".format(int(rate)))
dirRate.cd()
dict_h_sbitMulti[isValid][calEnable][rate][vfat].Write()
dict_h_sbitSize[isValid][calEnable][rate][vfat].Write()
dict_h_sbitObsVsChanPulsed[isValid][calEnable][rate][vfat].Write()
dict_h_sbitMultiVsSbitSize[isValid][calEnable][rate][vfat].Write()
# Summary Plots
dirSummary = outF.mkdir("Summary")
for isValid in isValidValues:
if not isValid and not args.checkInvalid:
continue
if isValid:
strValidity="validSbits"
else:
strValidity="invalidSbits"
dirIsValid = dirSummary.mkdir(strValidity)
for calEnable in calEnableValues:
if calEnable:
strCalStatus="calEnabled"
else:
strCalStatus="calDisabled"
dirCalStatus = dirIsValid.mkdir(strCalStatus)
if calEnable:
dirCalStatus.cd()
dict_h_vfatObsVsVfatPulsed[isValid][calEnable][-1].Write()
for rate in ratesUsed:
if ( not ( (calEnable and rate > 0) or (not calEnable and rate == 0.0) ) ):
continue
dirRate = dirCalStatus.mkdir("{0}Hz".format(int(rate)))
dirRate.cd()
dict_h_vfatObsVsVfatPulsed[isValid][calEnable][rate].Write()
# Close input TFile
inF.Close()
# Close output TFile
outF.Close()
arrayPos=0
list_nameNtype = [('vfatN','i4'),('vfatSBIT','i4'),('sbitSize','i4'),('N_Mismatches','i4')]
wrongSBITMapping = np.zeros(len(flatten(dict_wrongSbit2ChanMapping)), dtype=list_nameNtype)
for vfat,dictBadSBits in dict_wrongSbit2ChanMapping.iteritems():
for sbit,dictSizeCounts in dictBadSBits.iteritems():
for size,nTimes in dictSizeCounts.iteritems():
wrongSBITMapping[arrayPos]['vfatN'] = vfat
wrongSBITMapping[arrayPos]['vfatSBIT'] = sbit
wrongSBITMapping[arrayPos]['sbitSize'] = size
wrongSBITMapping[arrayPos]['N_Mismatches'] = nTimes
arrayPos+=1
wrongSBITMapping.sort(order=['vfatN','vfatSBIT','sbitSize','N_Mismatches'])
fileMisMappedSbits = open("{0}/MisMappedSbits.txt".format(filename),"w")
print("List Of Mis-mapped Sbits")
fileMisMappedSbits.write("List Of Mis-mapped Sbits\n")
print("| vfatN | vfatSBIT | SBIT_Size | N_Mismatches |")
fileMisMappedSbits.write("| vfatN | vfatSBIT | SBIT_Size | N_Mismatches |\n")
print("| :---: | :------: | :-------: | :----------: |")
fileMisMappedSbits.write("| :---: | :------: | :-------: | :----------: |\n")
for idx in range(0,len(wrongSBITMapping)):
print("| {0:5d} | {1:8d} | {2:9d} | {3:12d} |".format(
wrongSBITMapping[idx]['vfatN'],
wrongSBITMapping[idx]['vfatSBIT'],
wrongSBITMapping[idx]['sbitSize'],
wrongSBITMapping[idx]['N_Mismatches']))
fileMisMappedSbits.write("| {0} | {1} | {2} | {3} |\n".format(
wrongSBITMapping[idx]['vfatN'],
wrongSBITMapping[idx]['vfatSBIT'],
wrongSBITMapping[idx]['sbitSize'],
wrongSBITMapping[idx]['N_Mismatches']))
fileMisMappedSbits.close()
list_nameNtype = [('vfatN','i4'),('vfatObs','i4'),('N_Mismatches','i4')]
wrongVFATMapping = np.zeros(len(dict_wrongVfatObs2VfatPulsedMapping), dtype=list_nameNtype)
for idx,vfatTuple in enumerate(dict_wrongVfatObs2VfatPulsedMapping.keys()):
wrongVFATMapping[idx]['vfatN']=vfatTuple[0]
wrongVFATMapping[idx]['vfatObs']=vfatTuple[1]
wrongVFATMapping[idx]['N_Mismatches']=dict_wrongVfatObs2VfatPulsedMapping[vfatTuple]
wrongVFATMapping.sort(order='vfatN')
fileMisMappedVFATs = open("{0}/MisMappedVFATs.txt".format(filename),"w")
print("List of Mis-mapped VFATs")
fileMisMappedVFATs.write("List of Mis-mapped VFATs\n")
print("| vfatPulsed | vfatObserved | N_Mismatches |")
fileMisMappedVFATs.write("| vfatPulsed | vfatObserved | N_Mismatches |\n")
print("| :--------: | :----------: | :----------: |")
fileMisMappedVFATs.write("| :--------: | :----------: | :----------: |\n")
for idx in range(0,len(wrongVFATMapping)):
print("| {0:10d} | {1:12d} | {2:12d} |".format(
wrongVFATMapping[idx]['vfatN'],
wrongVFATMapping[idx]['vfatObs'],
wrongVFATMapping[idx]['N_Mismatches']))
fileMisMappedVFATs.write("| {0} | {1} | {2} |".format(
wrongVFATMapping[idx]['vfatN'],
wrongVFATMapping[idx]['vfatObs'],
wrongVFATMapping[idx]['N_Mismatches']))
fileMisMappedVFATs.close()
print("\nDone")