ATLAS Offline Software
Loading...
Searching...
No Matches
ReadCellNoiseFromCoolCompare.py
Go to the documentation of this file.
1#!/bin/env python
2
3# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4#
5# ReadCellNoiseFromCoolCompare.py
6# based on ReadCellNoiseFromCool.py and ReadFromCoolCompare.py
7# Yuri Smirnov 2015-03-19
8#
9
10import getopt,sys,os
11os.environ['TERM'] = 'linux'
12
13def usage():
14 print ("Usage: ",sys.argv[0]," [OPTION] ... ")
15 print ("Dumps noise constants from online or offline folders / tags")
16 print ("")
17 print ("-h, --help shows this help")
18 print ("-s, --schema= specify schema to use, ONL or OFL for RUN1 or ONL2 or OFL2 for RUN2 or MC")
19 print ("-S, --server= specify server - ORACLE or FRONTIER, default is FRONTIER")
20 print ("-f, --folder= specify status folder to use f.i. /TILE/OFL02/NOISE/CELL or /CALO/Noise/CellNoise ")
21 print ("-t, --tag= specify tag to use, f.i. UPD1 or UPD4 or tag suffix like 14TeV-N200_dT50-01")
22 print ("-r, --run= specify run number, by default uses latest iov")
23 print ("-l, --lumi= specify lumi block number, default is 0")
24 print ("-s2, --schema2= specify schema2 to use, ONL or OFL for RUN1 or ONL2 or OFL2 for RUN2 or MC")
25 print ("-S2, --server2= specify server2 - ORACLE or FRONTIER, default is FRONTIER")
26 print ("-f2, --folder2= specify status folder2 to use f.i. /TILE/OFL02/NOISE/CELL or /CALO/Noise/CellNoise ")
27 print ("-t2, --tag2= specify tag2 to use, f.i. UPD1 or UPD4 or tag suffix like 14TeV-N200_dT50-01")
28 print ("-r2, --run2= specify 2-nd run number, by default uses latest iov")
29 print ("-l2, --lumi2= specify 2-nd lumi block number, default is 0")
30 print ("-m, --maxdiff= specify an absolute maximal difference to compare constants")
31 print ("-m2, --maxdiffpercent= specify the maximal difference in percents to compare constants")
32 print ("-n, --channel= specify cool channel to read (48 by defalt)")
33 print ("-c, --cell= specify cell hash (0-5183), default is -1, means all cells")
34 print ("-g, --gain= specify gain to print (0-3), default is -1, means all gains")
35 print ("-i, --index= specify parameter index (0-4), default is -1, means all parameters")
36 print ("-z, --zero= zero threshold - treat values in DB below this threshold as zeros")
37 print ("-w, --wide wide format - print all values per cell in one line")
38 print ("-b, --brief print only numbers without character names")
39 print ("-d, --double print values with double precision")
40
41letters = "hS:s:t:f:r:l:S2:s2:t2:f2:r2:l2:m:m2:n:c:g:i:z:wbd"
42keywords = ["help","server=","schema=","tag=","folder=","run=","lumi=","server2=","schema2=","tag2=","folder2=","run2=","lumi2=","maxdiff=","maxdiffpercent=","channel=","cell=","gain=","index=","zero=","wide","brief","double"]
43
44try:
45 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
46except getopt.GetoptError as err:
47 print (str(err))
48 usage()
49 sys.exit(2)
50
51# defaults
52run = 2147483647
53run2 = 0 # will be set to "run" if not on command line
54lumi = 0
55lumi2 = -1 # will be set to "lumi" if not on command line
56server = ''
57server2 = "none"
58schema = 'OFL2'
59schema2 = "none"
60folderPath = '/TILE/OFL02/NOISE/CELL'
61folderPath2 = "none" # will be set to "folderPath" if not on command line
62tag = 'UPD4'
63tag2 = "none"
64maxdiff=-1.0 # dump all values
65maxdiffpercent=-1.0
66chan = 48 # represents Tile
67cell = -1
68gain = -1
69index = -1
70brief = False
71doubl = False
72multi = True
73zthr = 5e-7
74
75for o, a in opts:
76 a = a.strip()
77 if o in ("-s","--schema"):
78 schema = a
79 elif o in ("-s2","--schema2"):
80 schema2 = a
81 elif o in ("-S","--server"):
82 server = a
83 elif o in ("-S2","--server2"):
84 server2 = a
85 elif o in ("-f","--folder"):
86 folderPath = a
87 elif o in ("-f2","--folder2"):
88 folderPath2 = a
89 elif o in ("-t","--tag"):
90 tag = a
91 elif o in ("-t2","--tag2"):
92 tag2 = a
93 elif o in ("-n","--channel"):
94 chan = int(a)
95 elif o in ("-c","--cell"):
96 cell = int(a)
97 elif o in ("-g","--gain"):
98 gain = int(a)
99 elif o in ("-i","--index"):
100 index = int(a)
101 elif o in ("-r","--run"):
102 run = int(a)
103 elif o in ("-r2","--run2"):
104 run2 = int(a)
105 elif o in ("-l","--lumi"):
106 lumi = int(a)
107 elif o in ("-l2","--lumi2"):
108 lumi2 = int(a)
109 elif o in ("-l","--lumi"):
110 lumi = int(a)
111 elif o in ('--maxdiff'):
112 maxdiff = float(a)
113 elif o in ('--maxdiffpercent'):
114 maxdiffpercent = float(a)
115 elif o in ("-z","--zero"):
116 zthr = float(a)
117 elif o in ("-w","--wide"):
118 multi = False
119 elif o in ("-b","--brief"):
120 brief = True
121 elif o in ("-d","--double"):
122 doubl = True
123 elif o in ("-h","--help"):
124 usage()
125 sys.exit(2)
126 else:
127 usage()
128 sys.exit(2)
129
130if not run2:
131 run2=run
132if lumi2<0:
133 lumi2=lumi
134if folderPath2=="none":
135 folderPath2=folderPath
136if tag2=="none":
137 tag2=tag
138if schema2=="none":
139 schema2=schema
140if server2=="none":
141 server2=server
142
143tile=(chan==48)
144
145import cppyy
146
147from CaloCondBlobAlgs import CaloCondTools, CaloCondLogger
148from TileCalibBlobPython import TileCalibTools
149from TileCalibBlobPython import TileCellTools
150
151#=== get a logger
152log = CaloCondLogger.getLogger("ReadCellNoise")
153
154#=== Read from COOL server 1:
155
156if schema=='ONL': # shortcut for COOLONL_CALO/COMP200
157 schema='COOLONL_CALO/COMP200'
158 folderPath='/CALO/Noise/CellNoise'
159 if tag=='UPD4':
160 tag='UPD1-00' # change default to latest RUN1 tag
161elif schema=='ONL2': # shortcut for COOLONL_CALO/CONDBR2
162 schema='COOLONL_CALO/CONDBR2'
163 folderPath='/CALO/Noise/CellNoise'
164 if tag=='UPD4':
165 tag='RUN2-UPD1-00' # change default to latest RUN2 tag
166elif schema=='OFL': # shortcut for COOLOFL_TILE/COMP200 or COOLOFL_LAR/COMP200
167 if chan!=48:
168 schema='COOLOFL_LAR/COMP200'
169 folderPath='/LAR/NoiseOfl/CellNoise'
170 if tag=='UPD4':
171 tag='UPD4-02' # change default to latest RUN1 tag
172 else:
173 schema='COOLOFL_TILE/COMP200'
174 folderPath='/TILE/OFL02/NOISE/CELL'
175 if tag=='UPD4':
176 tag='UPD4-10' # change default to latest RUN1 tag
177elif schema=='OFL2': # shortcut for COOLOFL_TILE/CONDBR2 or COOLOFL_LAR/CONDBR2
178 if chan!=48:
179 schema='COOLOFL_LAR/CONDBR2'
180 folderPath='/LAR/NoiseOfl/CellNoise'
181 else:
182 schema='COOLOFL_TILE/CONDBR2'
183 folderPath='/TILE/OFL02/NOISE/CELL'
184elif schema=='ONLMC': # shortcut for COOLONL_CALO/OFLP200
185 schema='COOLONL_CALO/OFLP200'
186 folderPath='/CALO/Noise/CellNoise'
187 if tag=='UPD4':
188 tag='IOVDEP-10' # change default to tag used in DC14
189elif schema=='OFLMC': # shortcut for COOLOFL_CALO/OFLP200
190 schema='COOLOFL_CALO/OFLP200'
191 folderPath='/CALO/Ofl/Noise/CellNoise'
192 if tag=='UPD4':
193 tag='IOVDEP-10' # change default to tag used in DC14
194elif schema=='MC': # shortcut for COOLOFL_TILE/OFLP200 or COOLOFL_LAR/OFLP200
195 if chan!=48:
196 schema='COOLOFL_LAR/OFLP200'
197 folderPath='/LAR/NoiseOfl/CellNoise'
198 if tag=='UPD4':
199 tag='IOVDEP-00' # change default to tag used in DC14
200 else:
201 schema='COOLOFL_TILE/OFLP200'
202 folderPath='/TILE/OFL02/NOISE/CELL'
203 if tag=='UPD4':
204 tag='IOVDEP-02' # change default to tag used in DC14
205
206if run<222222 or 'COMP200' in schema:
207 cabling = 'RUN1'
208else:
209 if ('OFLP200' in schema and run>=330000) or run>=400000:
210 cabling = 'RUN3'
211 elif ('OFLP200' in schema and run>=310000) or run>=342550:
212 cabling = 'RUN2a'
213 else:
214 cabling = 'RUN2'
215hashMgr=TileCellTools.TileCellHashMgr(cabling=cabling)
216
217db = CaloCondTools.openDbConn(schema, server)
218
219if folderPath.startswith('/TILE') or tag=='UPD1' or tag=='UPD4' or 'COND'in tag:
220 folderTag = TileCalibTools.getFolderTag(db, folderPath, tag )
221elif folderPath.startswith('/CALO/Ofl'):
222 folderTag = 'CaloOflNoiseCellnoise-'+tag
223elif folderPath.startswith('/CALO'):
224 folderTag = 'CaloNoiseCellnoise-'+tag
225elif folderPath.startswith('/LAR'):
226 folderTag = 'LARNoiseOflCellNoise-'+tag
227
228#=== Read from COOL server 2:
229
230if schema2=='ONL': # shortcut for COOLONL_CALO/COMP200
231 schema2='COOLONL_CALO/COMP200'
232 folderPath2='/CALO/Noise/CellNoise'
233 if tag2=='UPD4':
234 tag2='UPD1-00' # change default to latest RUN1 tag
235elif schema2=='ONL2': # shortcut for COOLONL_CALO/CONDBR2
236 schema2='COOLONL_CALO/CONDBR2'
237 folderPath2='/CALO/Noise/CellNoise'
238 if tag2=='UPD4':
239 tag2='RUN2-UPD1-00' # change default to latest RUN2 tag
240elif schema2=='OFL': # shortcut for COOLOFL_TILE/COMP200 or COOLOFL_LAR/COMP200
241 if chan!=48:
242 schema2='COOLOFL_LAR/COMP200'
243 folderPath2='/LAR/NoiseOfl/CellNoise'
244 if tag2=='UPD4':
245 tag2='UPD4-02' # change default to latest RUN1 tag
246 else:
247 schema2='COOLOFL_TILE/COMP200'
248 folderPath='/TILE/OFL02/NOISE/CELL'
249 if tag2=='UPD4':
250 tag2='UPD4-10' # change default to latest RUN1 tag
251elif schema2=='OFL2': # shortcut for COOLOFL_TILE/CONDBR2 or COOLOFL_LAR/CONDBR2
252 if chan!=48:
253 schema2='COOLOFL_LAR/CONDBR2'
254 folderPath2='/LAR/NoiseOfl/CellNoise'
255 else:
256 schema2='COOLOFL_TILE/CONDBR2'
257 folderPath2='/TILE/OFL02/NOISE/CELL'
258elif schema2=='ONLMC': # shortcut for COOLONL_CALO/OFLP200
259 schema2='COOLONL_CALO/OFLP200'
260 folderPath2='/CALO/Noise/CellNoise'
261 if tag2=='UPD4':
262 tag2='IOVDEP-10' # change default to tag used in DC14
263elif schema2=='OFLMC': # shortcut for COOLOFL_CALO/OFLP200
264 schema2='COOLOFL_CALO/OFLP200'
265 folderPath2='/CALO/Ofl/Noise/CellNoise'
266 if tag2=='UPD4':
267 tag2='IOVDEP-10' # change default to tag used in DC14
268elif schema2=='MC': # shortcut for COOLOFL_TILE/OFLP200 or COOLOFL_LAR/OFLP200
269 if chan!=48:
270 schema2='COOLOFL_LAR/OFLP200'
271 folderPath2='/LAR/NoiseOfl/CellNoise'
272 if tag2=='UPD4':
273 tag2='IOVDEP-00' # change default to tag used in DC14
274 else:
275 schema2='COOLOFL_TILE/OFLP200'
276 folderPath2='/TILE/OFL02/NOISE/CELL'
277 if tag2=='UPD4':
278 tag2='IOVDEP-02' # change default to tag used in DC14
279
280db2 = CaloCondTools.openDbConn(schema2, server2)
281
282if folderPath2.startswith('/TILE') or tag2=='UPD1' or tag2=='UPD4' or 'COND'in tag2:
283 folderTag2 = TileCalibTools.getFolderTag(db2, folderPath2, tag2 )
284elif folderPath2.startswith('/CALO/Ofl'):
285 folderTag2 = 'CaloOflNoiseCellnoise-'+tag2
286elif folderPath2.startswith('/CALO'):
287 folderTag2 = 'CaloNoiseCellnoise-'+tag2
288elif folderPath.startswith('/LAR'):
289 folderTag2 = 'LARNoiseOflCellNoise-'+tag2
290
291
292log.info("Initializing folder %s with tag %s", folderPath, folderTag)
293log.info("Initializing folder2 %s with tag2 %s", folderPath2, folderTag2)
294
295folder = db.getFolder(folderPath)
296folder2 = db2.getFolder(folderPath2)
297
298#=== get the blob for a given tag and iov
299iov = CaloCondTools.iovFromRunLumi( run, lumi )
300iov2 = CaloCondTools.iovFromRunLumi( run2, lumi2 )
301
302obj = folder.findObject( iov, chan, folderTag )
303obj2 = folder2.findObject( iov2, chan, folderTag2 )
304
305blob = obj.payload()[0]
306blob2 = obj2.payload()[0]
307
308#=== create CaloCondBlobFlt
309blobFlt = cppyy.gbl.CaloCondBlobFlt.getInstance(blob)
310blobFlt2 = cppyy.gbl.CaloCondBlobFlt.getInstance(blob2)
311
312#=== retrieve data from the blob
313#cell = 0 # 0..5183 - Tile hash
314#gain = 0 # 0..3 - four Tile cell gains: -11, -12, -15, -16
315#index = 0 # 0..4 - electronic or pile-up noise or 2-G noise parameters
316
317ncell=blobFlt.getNChans()
318ngain=blobFlt.getNGains()
319nval=blobFlt.getObjSizeUint32()
320
321if cell<0 or cell>=ncell:
322 cellmin=0
323 cellmax=ncell
324else:
325 cellmin=cell
326 cellmax=cell+1
327
328if gain<0 or gain>=ngain:
329 gainmin=0
330 gainmax=ngain
331else:
332 gainmin=gain
333 gainmax=gain+1
334
335if index<0 or index>=nval:
336 indexmin=0
337 indexmax=nval
338else:
339 indexmin=index
340 indexmax=index+1
341
342log.info("From DB: ncell: %d ngain %d index nval %d", ncell, ngain, nval)
343
344if brief or doubl:
345 name1 = ["","","0.0 "]
346 names = ["S0 ", "Pl ", "S1 ", "S2 ", "Ra "]
347 dm=" "
348else:
349 name1 = ["Noise cell ", "gain ","0.00 "]
350 names = [" RMS ", "pileup ", " RMS1 ", " RMS2 ", " Ratio "]
351 for i in range(len(names),indexmax):
352 names += ["c"+str(i)+" "]
353 dm="\t"
354for cell in range(cellmin,cellmax):
355 if tile and len(name1[0]):
356 name1[0] = "%s %6s hash " % hashMgr.getNames(cell)
357 for gain in range(gainmin,gainmax):
358 msg="%s%4d %s%d\t" % ( name1[0], cell, name1[1], gain)
359 l0=len(msg)
360 if multi:
361 dm="\n"+msg
362 for index in range(indexmin,indexmax):
363 v=blobFlt.getData(cell, gain, index)
364 v2=blobFlt2.getData(cell, gain, index)
365 dv12 = v - v2
366 if abs(dv12)<zthr:
367 dv12 = 0
368 if v2 == 0:
369 if v==0:
370 dp12=0
371 else:
372 dp12=100
373 else:
374 dp12=dv12*100./v2
375
376 if abs(dv12) > maxdiff and abs(dp12) > maxdiffpercent:
377 if doubl:
378 s1 = "{0:<14.9g}".format(v) if v<0 else "{0:<15.10g}".format(v)
379 s2 = "{0:<14.9g}".format(v2) if v2<0 else "{0:<15.10g}".format(v2)
380 s3 = "{0:<14.9g}".format(dv12) if dv12<0 else "{0:<15.10g}".format(dv12)
381 s4 = "{0:<14.9g}".format(dp12) if dp12<0 else "{0:<15.10g}".format(dp12)
382 msg += "%s v1 %s v2 %s diff %s diffpercent %s%s" % (names[index],s1.ljust(15),s2.ljust(15),s3.ljust(15),s4.ljust(15),dm)
383 else:
384 s1 = name1[2] if abs(v)<zthr else "%8.6f" % v if abs(v)<1 else "{0:<8.7g}".format(v).ljust(8)
385 s2 = name1[2] if abs(v2)<zthr else "%8.6f" % v2 if abs(v2)<1 else "{0:<8.7g}".format(v2).ljust(8)
386 s3 = name1[2] if abs(dv12)<zthr else "%8.6f" % dv12 if abs(dv12)<1 else "{0:<8.7g}".format(dv12).ljust(8)
387 s4 = name1[2] if abs(dp12)<zthr else "%8.6f" % dp12 if abs(dp12)<1 else "{0:<8.7g}".format(dp12).ljust(8)
388 msg += "%s v1 %s v2 %s diff %s diffpercent %s%s" % (names[index],s1[:8],s2[:8],s3[:8],s4[:8],dm)
389
390 if len(msg)>l0:
391 print (msg[:len(msg)-len(dm)])
392
393#=== close DB
394db.closeDatabase()
395db2.closeDatabase()