ATLAS Offline Software
Loading...
Searching...
No Matches
ReadCellNoiseFromCool.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# ReadFloatFromCaloCool.py
6# Carlos.Solans <Carlos.Solans@cern.ch>
7# Each Tile cell has 5 values stored in COOL.
8# The first two values are the RMS of a sigle gaussian model of the electronic noise
9# and the pile-up noise normalized at 10^33cm-2s-1, (backwards compatibility)
10# The next three values are used for a two gaussian model.
11# These are: ratio between first and second gaussian, RMS of the first gaussian, and RMS of the second gaussian
12# change Yuri Smirnov <iouri.smirnov@cern.ch> 2014-12-24
13
14import getopt,sys,os
15os.environ['TERM'] = 'linux'
16
17def usage():
18 print ("Usage: ",sys.argv[0]," [OPTION] ... ")
19 print ("Dumps noise constants from online or offline folders / tags")
20 print ("")
21 print ("-h, --help shows this help")
22 print ("-s, --schema= specify schema to use, ONL or OFL for RUN1 or ONL2 or OFL2 for RUN2 or MC")
23 print ("-S, --server= specify server - ORACLE or FRONTIER, default is FRONTIER")
24 print ("-f, --folder= specify status folder to use f.i. /TILE/OFL02/NOISE/CELL or /CALO/Noise/CellNoise ")
25 print ("-t, --tag= specify tag to use, f.i. UPD1 or UPD4 or tag suffix like 14TeV-N200_dT50-01")
26 print ("-r, --run= specify run number, by default uses latest iov")
27 print ("-l, --lumi= specify lumi block number, default is 0")
28 print ("-n, --channel= specify cool channel to read (48 by defalt)")
29 print ("-c, --cell= specify cell hash (0-5183), default is -1, means all cells")
30 print ("-g, --gain= specify gain to print (0-3), default is -1, means all gains")
31 print ("-i, --index= specify parameter index (0-4), default is -1, means all parameters")
32 print ("-b, --brief print only numbers without character names")
33 print ("-d, --double print values with double precision")
34
35letters = "hS:s:t:f:r:l:n:c:g:i:bd"
36keywords = ["help","server=","schema=","tag=","folder=","run=","lumi=","channel=","cell=","gain=","index=","brief","double"]
37
38try:
39 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
40except getopt.GetoptError as err:
41 print (str(err))
42 usage()
43 sys.exit(2)
44
45# defaults
46run = 2147483647
47lumi = 0
48server = ''
49schema = 'OFL2'
50folderPath = '/TILE/OFL02/NOISE/CELL'
51tag = 'UPD4'
52chan = 48 # represents Tile
53cell = -1
54gain = -1
55index = -1
56brief = False
57doubl = False
58
59for o, a in opts:
60 a = a.strip()
61 if o in ("-s","--schema"):
62 schema = a
63 elif o in ("-S","--server"):
64 server = a
65 elif o in ("-f","--folder"):
66 folderPath = a
67 elif o in ("-t","--tag"):
68 tag = a
69 elif o in ("-n","--channel"):
70 chan = int(a)
71 elif o in ("-c","--cell"):
72 cell = int(a)
73 elif o in ("-g","--gain"):
74 gain = int(a)
75 elif o in ("-i","--index"):
76 index = int(a)
77 elif o in ("-r","--run"):
78 run = int(a)
79 elif o in ("-l","--lumi"):
80 lumi = int(a)
81 elif o in ("-b","--brief"):
82 brief = True
83 elif o in ("-d","--double"):
84 doubl = True
85 elif o in ("-h","--help"):
86 usage()
87 sys.exit(2)
88 else:
89 usage()
90 sys.exit(2)
91
92tile=(chan==48)
93
94import cppyy
95
96from CaloCondBlobAlgs import CaloCondTools, CaloCondLogger
97from TileCalibBlobPython import TileCalibTools
98from TileCalibBlobPython import TileCellTools
99
100#=== get a logger
101log = CaloCondLogger.getLogger("ReadCellNoise")
102
103#=== Read from COOL server:
104
105if schema=='ONL': # shortcut for COOLONL_CALO/COMP200
106 schema='COOLONL_CALO/COMP200'
107 folderPath='/CALO/Noise/CellNoise'
108 if tag=='UPD4':
109 tag='UPD1-00' # change default to latest RUN1 tag
110elif schema=='ONL2': # shortcut for COOLONL_CALO/CONDBR2
111 schema='COOLONL_CALO/CONDBR2'
112 folderPath='/CALO/Noise/CellNoise'
113 if tag=='UPD4':
114 tag='RUN2-UPD1-00' # change default to latest RUN2 tag
115elif schema=='OFL': # shortcut for COOLOFL_TILE/COMP200 or COOLOFL_LAR/COMP200
116 if chan!=48:
117 schema='COOLOFL_LAR/COMP200'
118 folderPath='/LAR/NoiseOfl/CellNoise'
119 if tag=='UPD4':
120 tag='UPD4-02' # change default to latest RUN1 tag
121 else:
122 schema='COOLOFL_TILE/COMP200'
123 folderPath='/TILE/OFL02/NOISE/CELL'
124 if tag=='UPD4':
125 tag='UPD4-10' # change default to latest RUN1 tag
126elif schema=='OFL2': # shortcut for COOLOFL_TILE/CONDBR2 or COOLOFL_LAR/CONDBR2
127 if chan!=48:
128 schema='COOLOFL_LAR/CONDBR2'
129 folderPath='/LAR/NoiseOfl/CellNoise'
130 else:
131 schema='COOLOFL_TILE/CONDBR2'
132 folderPath='/TILE/OFL02/NOISE/CELL'
133elif schema=='ONLMC': # shortcut for COOLONL_CALO/OFLP200
134 schema='COOLONL_CALO/OFLP200'
135 folderPath='/CALO/Noise/CellNoise'
136 if tag=='UPD4':
137 tag='IOVDEP-10' # change default to tag used in DC14
138elif schema=='OFLMC': # shortcut for COOLOFL_CALO/OFLP200
139 schema='COOLOFL_CALO/OFLP200'
140 folderPath='/CALO/Ofl/Noise/CellNoise'
141 if tag=='UPD4':
142 tag='IOVDEP-10' # change default to tag used in DC14
143elif schema=='MC': # shortcut for COOLOFL_TILE/OFLP200 or COOLOFL_LAR/OFLP200
144 if chan!=48:
145 schema='COOLOFL_LAR/OFLP200'
146 folderPath='/LAR/NoiseOfl/CellNoise'
147 else:
148 schema='COOLOFL_TILE/OFLP200'
149 folderPath='/TILE/OFL02/NOISE/CELL'
150 if tag=='UPD4':
151 tag='OFLCOND-MC23-SDR-RUN3-02' # change default to tag used in MC23
152
153if run<222222 or 'COMP200' in schema:
154 cabling = 'RUN1'
155else:
156 if ('OFLP200' in schema and run>=330000) or run>=400000:
157 cabling = 'RUN3'
158 elif ('OFLP200' in schema and run>=310000) or run>=342550:
159 cabling = 'RUN2a'
160 else:
161 cabling = 'RUN2'
162hashMgr=None
163hashMgrDef=TileCellTools.TileCellHashMgr(cabling=cabling)
164hashMgrA=TileCellTools.TileCellHashMgr("UpgradeA")
165hashMgrBC=TileCellTools.TileCellHashMgr("UpgradeBC")
166hashMgrABC=TileCellTools.TileCellHashMgr("UpgradeABC")
167
168db = CaloCondTools.openDbConn(schema, server)
169
170if folderPath.startswith('/TILE') or tag=='UPD1' or tag=='UPD4' or 'COND'in tag:
171 folderTag = TileCalibTools.getFolderTag(db, folderPath, tag )
172elif folderPath.startswith('/CALO/Ofl'):
173 folderTag = 'CaloOflNoiseCellnoise-'+tag
174elif folderPath.startswith('/CALO'):
175 folderTag = 'CaloNoiseCellnoise-'+tag
176elif folderPath.startswith('/LAR'):
177 folderTag = 'LARNoiseOflCellNoise-'+tag
178
179log.info("Initializing folder %s with tag %s", folderPath, folderTag)
180
181folder = db.getFolder(folderPath)
182
183#=== get the blob for a given tag and iov
184iov = CaloCondTools.iovFromRunLumi( run, lumi )
185
186obj = folder.findObject( iov, chan, folderTag )
187blob = obj.payload()[0]
188
189#=== create CaloCondBlobFlt
190blobFlt = cppyy.gbl.CaloCondBlobFlt.getInstance(blob)
191
192#=== retrieve data from the blob
193#cell = 0 # 0..5183 - Tile hash
194#gain = 0 # 0..3 - four Tile cell gains: -11, -12, -15, -16
195#index = 0 # 0..4 - electronic or pile-up noise or 2-G noise parameters
196
197ncell=blobFlt.getNChans()
198ngain=blobFlt.getNGains()
199nval=blobFlt.getObjSizeUint32()
200
201if ncell>hashMgrA.getHashMax():
202 hashMgr=hashMgrABC
203elif ncell>hashMgrBC.getHashMax():
204 hashMgr=hashMgrA
205elif ncell>hashMgrDef.getHashMax():
206 hashMgr=hashMgrBC
207else:
208 hashMgr=hashMgrDef
209log.info("Using %s CellMgr with hashMax %d", hashMgr.getGeometry(),hashMgr.getHashMax())
210
211if cell<0 or cell>=ncell:
212 cellmin=0
213 cellmax=ncell
214else:
215 cellmin=cell
216 cellmax=cell+1
217
218if gain<0 or gain>=ngain:
219 gainmin=0
220 gainmax=ngain
221else:
222 gainmin=gain
223 gainmax=gain+1
224
225if index<0 or index>=nval:
226 indexmin=0
227 indexmax=nval
228else:
229 indexmin=index
230 indexmax=index+1
231
232if brief or doubl:
233 name1 = ["","","0.0 "]
234 names = []
235 dm=" "
236 for i in range(indexmax):
237 names += [""]
238else:
239 name1 = ["Noise cell ", "gain ","0.00 "]
240 names = ["RMS ", "pileup ", "RMS1 ", "RMS2 ", "Ratio "]
241 for i in range(len(names),indexmax):
242 names += ["c"+str(i)+" "]
243 dm="\t"
244for cell in range(cellmin,cellmax):
245 if tile and len(name1[0]):
246 name1[0] = "%s %6s hash " % hashMgr.getNames(cell)
247 for gain in range(gainmin,gainmax):
248 msg="%s%4d %s%d\t" % ( name1[0], cell, name1[1], gain)
249 for index in range(indexmin,indexmax):
250 v=blobFlt.getData(cell, gain, index)
251 if doubl:
252 msg += "%s%s%s" % (names[index],"{0:<15.10g}".format(v).ljust(15),dm)
253 elif v<5.e-7:
254 msg += "%s%s%s" % (names[index],name1[2],dm)
255 elif v<1:
256 msg += "%s%8.6f%s" % (names[index],v,dm)
257 else:
258 msg += "%s%s%s" % (names[index],"{0:<8.7g}".format(v).ljust(8),dm)
259 print (msg)
260
261#=== close DB
262db.closeDatabase()