ATLAS Offline Software
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 
14 import getopt,sys,os
15 os.environ['TERM'] = 'linux'
16 
17 def 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 
35 letters = "hS:s:t:f:r:l:n:c:g:i:bd"
36 keywords = ["help","server=","schema=","tag=","folder=","run=","lumi=","channel=","cell=","gain=","index=","brief","double"]
37 
38 try:
39  opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
40 except getopt.GetoptError as err:
41  print (str(err))
42  usage()
43  sys.exit(2)
44 
45 # defaults
46 run = 2147483647
47 lumi = 0
48 server = ''
49 schema = 'OFL2'
50 folderPath = '/TILE/OFL02/NOISE/CELL'
51 tag = 'UPD4'
52 chan = 48 # represents Tile
53 cell = -1
54 gain = -1
55 index = -1
56 brief = False
57 doubl = False
58 
59 for 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 
92 tile=(chan==48)
93 
94 import cppyy
95 
96 from CaloCondBlobAlgs import CaloCondTools, CaloCondLogger
97 from TileCalibBlobPython import TileCalibTools
98 from TileCalibBlobPython import TileCellTools
99 
100 #=== get a logger
101 log = CaloCondLogger.getLogger("ReadCellNoise")
102 
103 #=== Read from COOL server:
104 
105 if 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
110 elif 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
115 elif 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
126 elif 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'
133 elif 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
138 elif 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
143 elif 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 
153 if run<222222 or 'COMP200' in schema:
154  cabling = 'RUN1'
155 else:
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'
162 hashMgr=None
163 hashMgrDef=TileCellTools.TileCellHashMgr(cabling=cabling)
164 hashMgrA=TileCellTools.TileCellHashMgr("UpgradeA")
165 hashMgrBC=TileCellTools.TileCellHashMgr("UpgradeBC")
166 hashMgrABC=TileCellTools.TileCellHashMgr("UpgradeABC")
167 
168 db = CaloCondTools.openDbConn(schema, server)
169 
170 if folderPath.startswith('/TILE') or tag=='UPD1' or tag=='UPD4' or 'COND'in tag:
171  folderTag = TileCalibTools.getFolderTag(db, folderPath, tag )
172 elif folderPath.startswith('/CALO/Ofl'):
173  folderTag = 'CaloOflNoiseCellnoise-'+tag
174 elif folderPath.startswith('/CALO'):
175  folderTag = 'CaloNoiseCellnoise-'+tag
176 elif folderPath.startswith('/LAR'):
177  folderTag = 'LARNoiseOflCellNoise-'+tag
178 
179 log.info("Initializing folder %s with tag %s", folderPath, folderTag)
180 
181 folder = db.getFolder(folderPath)
182 
183 #=== get the blob for a given tag and iov
184 iov = CaloCondTools.iovFromRunLumi( run, lumi )
185 
186 obj = folder.findObject( iov, chan, folderTag )
187 blob = obj.payload()[0]
188 
189 #=== create CaloCondBlobFlt
190 blobFlt = 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 
197 ncell=blobFlt.getNChans()
198 ngain=blobFlt.getNGains()
199 nval=blobFlt.getObjSizeUint32()
200 
201 if ncell>hashMgrA.getHashMax():
202  hashMgr=hashMgrABC
203 elif ncell>hashMgrBC.getHashMax():
204  hashMgr=hashMgrA
205 elif ncell>hashMgrDef.getHashMax():
206  hashMgr=hashMgrBC
207 else:
208  hashMgr=hashMgrDef
209 log.info("Using %s CellMgr with hashMax %d", hashMgr.getGeometry(),hashMgr.getHashMax())
210 
211 if cell<0 or cell>=ncell:
212  cellmin=0
213  cellmax=ncell
214 else:
215  cellmin=cell
216  cellmax=cell+1
217 
218 if gain<0 or gain>=ngain:
219  gainmin=0
220  gainmax=ngain
221 else:
222  gainmin=gain
223  gainmax=gain+1
224 
225 if index<0 or index>=nval:
226  indexmin=0
227  indexmax=nval
228 else:
229  indexmin=index
230  indexmax=index+1
231 
232 if brief or doubl:
233  name1 = ["","","0.0 "]
234  names = []
235  dm=" "
236  for i in range(indexmax):
237  names += [""]
238 else:
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"
244 for 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
262 db.closeDatabase()
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ReadCellNoiseFromCool.usage
def usage()
Definition: ReadCellNoiseFromCool.py:17
str
Definition: BTagTrackIpAccessor.cxx:11