ATLAS Offline Software
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 
10 import getopt,sys,os
11 os.environ['TERM'] = 'linux'
12 
13 def 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 
41 letters = "hS:s:t:f:r:l:S2:s2:t2:f2:r2:l2:m:m2:n:c:g:i:z:wbd"
42 keywords = ["help","server=","schema=","tag=","folder=","run=","lumi=","server2=","schema2=","tag2=","folder2=","run2=","lumi2=","maxdiff=","maxdiffpercent=","channel=","cell=","gain=","index=","zero=","wide","brief","double"]
43 
44 try:
45  opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
46 except getopt.GetoptError as err:
47  print (str(err))
48  usage()
49  sys.exit(2)
50 
51 # defaults
52 run = 2147483647
53 run2 = 0 # will be set to "run" if not on command line
54 lumi = 0
55 lumi2 = -1 # will be set to "lumi" if not on command line
56 server = ''
57 server2 = "none"
58 schema = 'OFL2'
59 schema2 = "none"
60 folderPath = '/TILE/OFL02/NOISE/CELL'
61 folderPath2 = "none" # will be set to "folderPath" if not on command line
62 tag = 'UPD4'
63 tag2 = "none"
64 maxdiff=-1.0 # dump all values
65 maxdiffpercent=-1.0
66 chan = 48 # represents Tile
67 cell = -1
68 gain = -1
69 index = -1
70 brief = False
71 doubl = False
72 multi = True
73 zthr = 5e-7
74 
75 for 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 
130 if not run2:
131  run2=run
132 if lumi2<0:
133  lumi2=lumi
134 if folderPath2=="none":
135  folderPath2=folderPath
136 if tag2=="none":
137  tag2=tag
138 if schema2=="none":
139  schema2=schema
140 if server2=="none":
141  server2=server
142 
143 tile=(chan==48)
144 
145 import cppyy
146 
147 from CaloCondBlobAlgs import CaloCondTools, CaloCondLogger
148 from TileCalibBlobPython import TileCalibTools
149 from TileCalibBlobPython import TileCellTools
150 
151 #=== get a logger
152 log = CaloCondLogger.getLogger("ReadCellNoise")
153 
154 #=== Read from COOL server 1:
155 
156 if 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
161 elif 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
166 elif 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
177 elif 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'
184 elif 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
189 elif 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
194 elif 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 
206 if run<222222 or 'COMP200' in schema:
207  cabling = 'RUN1'
208 else:
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'
215 hashMgr=TileCellTools.TileCellHashMgr(cabling=cabling)
216 
217 db = CaloCondTools.openDbConn(schema, server)
218 
219 if folderPath.startswith('/TILE') or tag=='UPD1' or tag=='UPD4' or 'COND'in tag:
220  folderTag = TileCalibTools.getFolderTag(db, folderPath, tag )
221 elif folderPath.startswith('/CALO/Ofl'):
222  folderTag = 'CaloOflNoiseCellnoise-'+tag
223 elif folderPath.startswith('/CALO'):
224  folderTag = 'CaloNoiseCellnoise-'+tag
225 elif folderPath.startswith('/LAR'):
226  folderTag = 'LARNoiseOflCellNoise-'+tag
227 
228 #=== Read from COOL server 2:
229 
230 if 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
235 elif 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
240 elif 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
251 elif 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'
258 elif 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
263 elif 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
268 elif 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 
280 db2 = CaloCondTools.openDbConn(schema2, server2)
281 
282 if folderPath2.startswith('/TILE') or tag2=='UPD1' or tag2=='UPD4' or 'COND'in tag2:
283  folderTag2 = TileCalibTools.getFolderTag(db2, folderPath2, tag2 )
284 elif folderPath2.startswith('/CALO/Ofl'):
285  folderTag2 = 'CaloOflNoiseCellnoise-'+tag2
286 elif folderPath2.startswith('/CALO'):
287  folderTag2 = 'CaloNoiseCellnoise-'+tag2
288 elif folderPath.startswith('/LAR'):
289  folderTag2 = 'LARNoiseOflCellNoise-'+tag2
290 
291 
292 log.info("Initializing folder %s with tag %s", folderPath, folderTag)
293 log.info("Initializing folder2 %s with tag2 %s", folderPath2, folderTag2)
294 
295 folder = db.getFolder(folderPath)
296 folder2 = db2.getFolder(folderPath2)
297 
298 #=== get the blob for a given tag and iov
299 iov = CaloCondTools.iovFromRunLumi( run, lumi )
300 iov2 = CaloCondTools.iovFromRunLumi( run2, lumi2 )
301 
302 obj = folder.findObject( iov, chan, folderTag )
303 obj2 = folder2.findObject( iov2, chan, folderTag2 )
304 
305 blob = obj.payload()[0]
306 blob2 = obj2.payload()[0]
307 
308 #=== create CaloCondBlobFlt
309 blobFlt = cppyy.gbl.CaloCondBlobFlt.getInstance(blob)
310 blobFlt2 = 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 
317 ncell=blobFlt.getNChans()
318 ngain=blobFlt.getNGains()
319 nval=blobFlt.getObjSizeUint32()
320 
321 if cell<0 or cell>=ncell:
322  cellmin=0
323  cellmax=ncell
324 else:
325  cellmin=cell
326  cellmax=cell+1
327 
328 if gain<0 or gain>=ngain:
329  gainmin=0
330  gainmax=ngain
331 else:
332  gainmin=gain
333  gainmax=gain+1
334 
335 if index<0 or index>=nval:
336  indexmin=0
337  indexmax=nval
338 else:
339  indexmin=index
340  indexmax=index+1
341 
342 log.info("From DB: ncell: %d ngain %d index nval %d", ncell, ngain, nval)
343 
344 if brief or doubl:
345  name1 = ["","","0.0 "]
346  names = ["S0 ", "Pl ", "S1 ", "S2 ", "Ra "]
347  dm=" "
348 else:
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"
354 for 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
394 db.closeDatabase()
395 db2.closeDatabase()
ReadCellNoiseFromCoolCompare.usage
def usage()
Definition: ReadCellNoiseFromCoolCompare.py:13
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
str
Definition: BTagTrackIpAccessor.cxx:11
readCCLHist.float
float
Definition: readCCLHist.py:83