-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakePixelBadComponentsPlot.py
More file actions
executable file
·296 lines (272 loc) · 10.1 KB
/
Copy pathmakePixelBadComponentsPlot.py
File metadata and controls
executable file
·296 lines (272 loc) · 10.1 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
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
#!/usr/bin/python3
import json
import argparse
import ROOT
import math
import sys
import os
import runregistry
from array import array
ROOT.gROOT.SetBatch(1)
parser = argparse.ArgumentParser(description='Extract runs list filtering with DCS informations.',prog='DCSonly')
parser.add_argument('-d','--dataset', dest='dset', type=str, action='store', default='Prompt',
help='Dataset for which the plot will be created')
parser.add_argument('-m','--min', dest='minrun', type=int, action='store',default=342000,
help='Minimum run number to be included in the plot')
parser.add_argument('-M','--max', dest='maxrun', type=int, action='store',default=999999,
help='Maximum run number to be included in the plot')
parser.add_argument('-y','--year', dest='year', type=int, action='store', default=2024,
help='Year to analyze')
parser.add_argument('-g','--good', dest='good', action='store_true',
help='Use only runs flagged GOOD on RR')
args = parser.parse_args()
headers = {"content-type": "application/x-www-form-urlencoded"}
globalpath=("/eos/cms/store/group/tracker-cctrack/www/HDQM/v4/alljsons/%d" % args.year)
ymax=15
def getGoodRuns(dset,rmin,rmax):
rrfilter={
"and": [
{"rr_attributes.class": {"=": "Collisions22"}},
{"name": {"like": ("%%%s%%" % dset)}},
# {"triplet_summary.tracker-track.GOOD": {">": 0}},
{"triplet_summary.tracker-pixel.GOOD": {">": 0}},
# {"triplet_summary.tracker-strip.GOOD": {">": 0}},
{"run_number": {">": ("%d" % rmin)}},
{"run_number": {"<": ("%d" % rmax)}}
]}
print(rrfilter)
datasets = runregistry.get_datasets(filter=rrfilter,ignore_filter_transformation=True)
outlist=[]
for run in datasets:
outlist.append(run['run_number'])
return outlist
def getData(subdet,path,goodlist):
f=open(("%s/deadROC_%s.json" % (path,subdet)))
raw=json.load(f)
data={}
for item in raw[("deadROC_%s" % subdet)]:
if args.good:
if int(item["run"]) in goodlist:
data[item["run"]]=item["y"]
else:
if int(item["run"])>= args.minrun and int(item["run"])<= args.maxrun:
data[item["run"]]=item["y"]
return data
def getRunDuration(path):
f=open(("%s/Run_LHCFill_RunDuration.json" % path))
raw=json.load(f)
data={}
fill={}
for item in raw["Run_LHCFill_RunDuration.json"]:
data[int(item["run"])]=item["rundur"]
fill[int(item["run"])]=item["lhcfill"]
return data,fill
def generateBinning(dur,control):
bins=[0]
idx=0
for run in dur.keys():
if run in control:
bins.append(bins[idx]+dur[run])
idx=idx+1
return bins
def generateFill(fillList,control):
fills={}
first=True
nbins=0
afill=-999
for run in fill.keys():
if run in control:
if first:
afill=fill[run]
first=False
nbins=1
elif fill[run]==afill:
nbins=nbins+1
else:
fills[afill]=nbins
afill=fill[run]
nbins=nbins+1
fills[afill]=nbins
return fills
def draw_line(lines,x1,x2,y1,y2,width=1,style=1,color=1):
from ROOT import TLine
l=TLine(x1,y1,x2,y2)
l.SetBit(ROOT.kCanDelete)
l.SetLineWidth(width)
l.SetLineStyle(style)
l.SetLineColor(color)
l.Draw()
lines.append(l)
def drawLines(bins,fills):
for idx in range(1,(len(bins)-1)):
draw_line(linelist,bins[idx],bins[idx],0,ymax,1,2,ROOT.kGray+1)
for fill in fills.keys():
if fills[fill]!=(len(bins)-1):
draw_line(linelist,bins[fills[fill]]-2,bins[fills[fill]]-2,0,ymax,2,3,ROOT.kGreen+1)
def drawRuler(bins):
xran=bins[len(bins)-1]-bins[0]
#print(xran)
if xran/10>1150:
nls=math.ceil(xran/10/(23*50))*50
else:
nls=50
#print(nls)
lenght=nls*23
draw_line(linelist,bins[0]+xran/8,bins[0]+xran/8+lenght,ymax*0.95,ymax*0.95,2,1,ROOT.kBlack)
draw_line(linelist,bins[0]+xran/8,bins[0]+xran/8,ymax*0.95,ymax*0.965,2,1,ROOT.kBlack)
draw_line(linelist,bins[0]+xran/8+lenght,bins[0]+xran/8+lenght,ymax*0.95,ymax*0.965,2,1,ROOT.kBlack)
t=ROOT.TPaveText((bins[0]+xran/8+lenght)*1.05,ymax*0.94,(bins[0]+xran/8+lenght)*1.3,ymax*0.975)
t.AddText(("%d LS" % nls))
t.SetBorderSize(0)
t.SetFillStyle(0)
t.Draw()
linelist.append(t)
print("Pixel Dead ROC plot generation")
if args.dset=="Prompt":
path=globalpath+"/Prompt/ZeroBias/PixelPhase1/"
elif args.dset=="Express":
path=globalpath+"/StreamExpress/PixelPhase1/"
else:
print("Not supported dataset")
os.popen('cp Error.png current/PixelBadComponents.png')
sys.exit()
print(path)
linelist=[]
if args.good:
goodruns=getGoodRuns(args.dset,args.minrun,args.maxrun)
else:
goodruns=[]
bpixl1data=getData("BPix_L1",path,goodruns)
bpixl2data=getData("BPix_L2",path,goodruns)
bpixl3data=getData("BPix_L3",path,goodruns)
bpixl4data=getData("BPix_L4",path,goodruns)
fpixr1data=getData("FPix_R1",path,goodruns)
fpixr2data=getData("FPix_R2",path,goodruns)
#globaldata=getData("Global",path)
rundur,fill=getRunDuration(globalpath)
binning=generateBinning(rundur,bpixl1data.keys())
fillList=generateFill(fill,bpixl1data.keys())
print(fillList)
print("Number of Bins: %d" % (len(binning)-1))
print("BPix L1 Run: %d" % len(bpixl1data.keys()))
print("BPix L2 Run: %d" % len(bpixl2data.keys()))
print("BPix L3 Run: %d" % len(bpixl3data.keys()))
print("BPix L4 Run: %d" % len(bpixl4data.keys()))
print("FPix R1 Run: %d" % len(fpixr1data.keys()))
print("FPix R2 Run: %d" % len(fpixr2data.keys()))
hBPIXL1=ROOT.TH1F("hBPIXL1",("%s dataset" % args.dset),len(binning)-1,array('d',binning))
hBPIXL1.GetYaxis().SetRangeUser(0,ymax)
hBPIXL1.GetYaxis().SetTitle("% of Pixel Dead ROC")
hBPIXL1.GetXaxis().SetTickSize(0)
hBPIXL1.SetLineColor(ROOT.kRed+2)
hBPIXL1.SetLineWidth(2)
sbpix1=0.
nbpix1=0
for i,run in enumerate(bpixl1data.keys()):
hBPIXL1.SetBinContent(i+1,bpixl1data[run])
if bpixl1data[run] != 100.:
sbpix1 += bpixl1data[run]*rundur[run]
nbpix1 +=1*rundur[run]
if(rundur[run]>1200):
hBPIXL1.GetXaxis().SetBinLabel(i+1,str(run))
else:
hBPIXL1.GetXaxis().SetBinLabel(i+1,"")
if i==0:
firstRun=run
elif i==len(bpixl1data.keys())-1:
lastRun=run
hBPIXL1.LabelsOption("v","X")
hBPIXL2=ROOT.TH1F("hBPIXL2","BPix L2 Bad Components",len(binning)-1,array('d',binning))
hBPIXL2.GetYaxis().SetRangeUser(0,ymax)
hBPIXL2.GetYaxis().SetTitle("% of Pixel Dead ROC")
hBPIXL2.GetXaxis().SetTitle("Time (s)")
hBPIXL2.SetLineColor(ROOT.kOrange+2)
hBPIXL2.SetLineWidth(2)
sbpix2=0.
nbpix2=0
for i,run in enumerate(bpixl2data.keys()):
if bpixl2data[run] != 100.:
sbpix2 += bpixl2data[run]*rundur[run]
nbpix2 +=1*rundur[run]
hBPIXL2.SetBinContent(i+1,bpixl2data[run])
hBPIXL3=ROOT.TH1F("hBPIXL3","BPix L3 Bad Components",len(binning)-1,array('d',binning))
hBPIXL3.GetYaxis().SetRangeUser(0,ymax)
hBPIXL3.GetYaxis().SetTitle("% of Pixel Dead ROC")
hBPIXL3.GetXaxis().SetTitle("Time (s)")
hBPIXL3.SetLineColor(ROOT.kViolet+2)
hBPIXL3.SetLineWidth(2)
sbpix3=0.
nbpix3=0
for i,run in enumerate(bpixl3data.keys()):
if bpixl3data[run] != 100.:
sbpix3 += bpixl3data[run]*rundur[run]
nbpix3 +=1*rundur[run]
hBPIXL3.SetBinContent(i+1,bpixl3data[run])
hBPIXL4=ROOT.TH1F("hBPIXL4","BPix L4 Bad Components",len(binning)-1,array('d',binning))
hBPIXL4.GetYaxis().SetRangeUser(0,ymax)
hBPIXL4.GetYaxis().SetTitle("% of Pixel Dead ROC")
hBPIXL4.GetXaxis().SetTitle("Time (s)")
hBPIXL4.SetLineColor(ROOT.kMagenta+1)
hBPIXL4.SetLineWidth(2)
sbpix4=0.
nbpix4=0
for i,run in enumerate(bpixl4data.keys()):
if bpixl4data[run] != 100.:
sbpix4 += bpixl4data[run]*rundur[run]
nbpix4 +=1*rundur[run]
hBPIXL4.SetBinContent(i+1,bpixl4data[run])
hFPIXR1=ROOT.TH1F("hFPIXR1","FPix R1 Bad Components",len(binning)-1,array('d',binning))
hFPIXR1.GetYaxis().SetRangeUser(0,ymax)
hFPIXR1.GetYaxis().SetTitle("% of Pixel Dead ROC")
hFPIXR1.GetXaxis().SetTitle("Time (s)")
hFPIXR1.SetLineColor(ROOT.kAzure+1)
hFPIXR1.SetLineWidth(2)
sfpixr1=0.
nfpixr1=0
for i,run in enumerate(fpixr1data.keys()):
if fpixr1data[run] != 100.:
sfpixr1 += fpixr1data[run]*rundur[run]
nfpixr1 +=1*rundur[run]
hFPIXR1.SetBinContent(i+1,fpixr1data[run])
hFPIXR2=ROOT.TH1F("hFPIXR2","FPix R2 Bad Components",len(binning)-1,array('d',binning))
hFPIXR2.GetYaxis().SetRangeUser(0,ymax)
hFPIXR2.GetYaxis().SetTitle("% of Pixel Dead ROC")
hFPIXR2.GetXaxis().SetTitle("Time (s)")
hFPIXR2.SetLineColor(ROOT.kCyan+1)
hFPIXR2.SetLineWidth(2)
sfpixr2=0.
nfpixr2=0
for i,run in enumerate(fpixr2data.keys()):
if fpixr2data[run] != 100.:
sfpixr2 += fpixr2data[run]*rundur[run]
nfpixr2 +=1*rundur[run]
hFPIXR2.SetBinContent(i+1,fpixr2data[run])
c=ROOT.TCanvas("c","c",1800,1000)
c.SetGridy(1)
c.SetRightMargin(0.13)
ROOT.gStyle.SetOptStat(0)
hBPIXL1.Draw()
hBPIXL2.Draw("same")
hBPIXL3.Draw("same")
hBPIXL4.Draw("same")
hFPIXR1.Draw("same")
hFPIXR2.Draw("same")
drawLines(binning,fillList)
drawRuler(binning)
leg=ROOT.TLegend(0.88,0.7,0.98,0.9)
leg.SetBorderSize(1)
leg.AddEntry("hBPIXL1","BPix L1({}%)".format(round(sbpix1/nbpix1,1)),"l")
leg.AddEntry("hBPIXL2","BPix L2({}%)".format(round(sbpix2/nbpix2,1)),"l")
leg.AddEntry("hBPIXL3","BPix L3({}%)".format(round(sbpix3/nbpix3,1)),"l")
leg.AddEntry("hBPIXL4","BPix L4({}%)".format(round(sbpix4/nbpix4,1)),"l")
leg.AddEntry("hFPIXR1","FPix R1({}%)".format(round(sfpixr1/nfpixr1,1)),"l")
leg.AddEntry("hFPIXR2","FPix R2({}%)".format(round(sfpixr2/nfpixr2,1)),"l")
leg.Draw()
outdir="/eos/cms/store/group/tracker-cctrack/www/TrackerMapsReloaded/files/data/users/event_display/BadComponentsTrends/"
if args.good:
c.SaveAs(("%s/PixelBadComponents_%s_%d-%d_GOOD.pdf" %(outdir,args.dset,firstRun,lastRun)))
c.SaveAs("current/PixelBadComponents.png")
else:
c.SaveAs(("%s/PixelBadComponents_%s_%d-%d.pdf" %(outdir,args.dset,firstRun,lastRun)))
c.SaveAs("current/PixelBadComponents.png")
print("output files can be found on https://tkmaps.web.cern.ch/tkmaps/files/data/users/event_display/BadComponentsTrends/")