ATLAS Offline Software
CaloNoise_fillDB.py
Go to the documentation of this file.
1 #!/bin/env python
2 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 
4 
5 import sys
6 import math
7 
8 def usage():
9  print ("Syntax for UPD4 open-end IoV noise update")
10  print (" The first parameter is the run number of IoV start, the second parameter is the lumiblock number for IoV start")
11  print (" The third and fourth parameter are the Run/lb for IoV end (if run is -1, uses open ended IoV)")
12  print (" The fifth parameter is the upd4 tag name")
13  print (" The sixth parameter is input text file name (default calonoise.txt)")
14  print (" The seventh parameter is output sqlite file name (default caloSqlite.db)")
15  print (" The eigth parameter is output DB name (default CONDBR2)")
16  print (" The nineth parameter is output folder name (default /LAR/NoiseOfl/CellNoise) ")
17  print (" The tenth parameter is mu (default 30)")
18  print (" The eleventh parameter is dt (default 25)")
19 
20 
21 if len(sys.argv)<6:
22  usage()
23  sys.exit(-1)
24 
25 runSince = sys.argv[1]
26 lbkSince = sys.argv[2]
27 runUntil = sys.argv[3]
28 lbkUntil = sys.argv[4]
29 tag = sys.argv[5]
30 if len(sys.argv)>6:
31  inputFile=sys.argv[6]
32 else:
33  inputFile="calonoise.txt"
34 
35 if len(sys.argv)>7:
36  filename=sys.argv[7]
37 else:
38  filename="larnoisesqlite.db"
39 
40 if len(sys.argv)>8:
41  dbname=sys.argv[8]
42 else:
43  dbname="CONDBR2"
44 
45 if len(sys.argv)>9:
46  folderPath = sys.argv[9]
47 else:
48  folderPath = "/LAR/NoiseOfl/CellNoise"
49 
50 if len(sys.argv)>10:
51  mu = int(sys.argv[10])
52 else:
53  mu = -1
54 
55 if len(sys.argv)>11:
56  dt = int(sys.argv[11])
57 else:
58  dt = -1
59 
60 if len(sys.argv)>11:
61  dt = int(sys.argv[11])
62 else:
63  dt = -1
64 
65 
66 print ("input: ",inputFile)
67 print ("runUntil ", runUntil, lbkUntil)
68 print ("output:",filename)
69 print ("input: ",inputFile)
70 
71 import ROOT
72 import cppyy
73 from PyCool import cool
74 from CaloCondBlobAlgs import CaloCondTools, CaloCondLogger
75 
76 #==================================================
77 #===
78 #=== Configuration section
79 #===
80 #==================================================
81 #=== IOV range
82 iovSince = CaloCondTools.iovFromRunLumi(runSince,lbkSince)
83 iovUntil = cool.ValidityKeyMax
84 print (" iovUntil max ",iovUntil)
85 if int(runUntil) > 0:
86  print (" use run number to define iobUntil ", runUntil)
87  iovUntil = CaloCondTools.iovFromRunLumi(runUntil,lbkUntil)
88 
89 print (" iovSince ", iovSince)
90 print (" iovUntil ", iovUntil)
91 
92 #=== values for the comment channel
93 author = "gunal"
94 comment = "Updated noise values"
95 
96 #==================================================
97 #===
98 #=== Code starts below here
99 #===
100 #==================================================
101 
102 #=== get a logger
103 log = CaloCondLogger.getLogger("CaloNoiseWriter")
104 
105 #=== (re-)create the database
106 dbSvc = cool.DatabaseSvcFactory.databaseService()
107 try:
108  db=dbSvc.openDatabase("sqlite://;schema="+filename+";dbname="+dbname, False)
109 except Exception:
110  db=dbSvc.createDatabase("sqlite://;schema="+filename+";dbname="+dbname)
111 
112 try:
113  #=== creating folder specifications
114  spec = cool.RecordSpecification()
115  spec.extend( 'CaloCondBlob16M', cool.StorageType.Blob16M )
116  fspec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
117 
118  #=== create the folder
119  folderTag = tag
120  log.info( "Filling COOL folder %s with tag %s", folderPath, folderTag )
121  desc = CaloCondTools.getAthenaFolderDescr()
122  try:
123  folder = db.getFolder(folderPath)
124  except Exception:
125  log.warning("Folder %s not found, creating it...", folderPath)
126  #folder = db.createFolder(folderPath, spec, desc, cool.FolderVersioning.MULTI_VERSION, True)
127  folder = db.createFolder(folderPath, fspec, desc, True)
128 
129  #==================================================
130  #=== Create the CaloCondBlobFlt objects
131  #==================================================
132  #=== default a and b to be used for each gain
133  gainDefVec = ROOT.std.vector('float')()
134  gainDefVec.push_back(0.) # a
135  gainDefVec.push_back(0.) # b
136  #=== three gains per channel for LAr
137  #defVecLAr = g.std.vector('std::vector<float>')()
138  defVecLAr = ROOT.std.vector('std::vector<float>')()
139  defVecLAr.push_back(gainDefVec)
140  defVecLAr.push_back(gainDefVec)
141  defVecLAr.push_back(gainDefVec)
142  #=== four "gains" per channel for Tile
143  #defVecTile = g.std.vector('std::vector<float>')()
144  defVecTile = ROOT.std.vector('std::vector<float>')()
145  defVecTile.push_back(gainDefVec)
146  defVecTile.push_back(gainDefVec)
147  defVecTile.push_back(gainDefVec)
148  defVecTile.push_back(gainDefVec)
149 
150  #=== system specific data: sysId -> (nChannel, hash-offset, default-vector, name)
151  systemDict = { 0 : (31872, 0, defVecLAr , 'EMEC, z<0'),
152  1 : (54784, 31872, defVecLAr , 'EMB , z<0'),
153  2 : (54784, 86656, defVecLAr , 'EMB , z>0'),
154  3 : (31872, 141440, defVecLAr , 'EMEC, z>0'),
155  16 : ( 5632, 0, defVecLAr , 'HEC' ),
156  32 : ( 3524, 0, defVecLAr , 'FCAL' ),
157  48 : ( 5184, 0, defVecTile, 'TILE' )
158  }
159  fltDict = {}
160  for systemId, info in systemDict.items():
161  if (systemId<48) :
162  nChannel = info[0]
163  defVec = info[2]
164  sysName = info[3]
165  log.info("Creating BLOB for %s", sysName)
166  data = cool.Record( spec )
167  blob = data['CaloCondBlob16M']
168  flt = ROOT.CaloCondBlobFlt.getInstance(blob)
169  flt.init(defVec,nChannel,1,author,comment)
170  fltDict[systemId] = [data,flt]
171  mbSize = float(blob.size()) / 1024.
172  log.info("---> BLOB size is %4.1f kB", mbSize)
173 
174  #=== read noise values from file
175  lines = open(inputFile,"r").readlines()
176  for line in lines:
177  fields = line.split()
178  if len(fields) < 5:
179  log.info("---> wrong line length %d entries ", len(fields))
180  continue
181  pass
182  systemId = int(fields[0])
183  hash = int(fields[1]) - systemDict[systemId][1]
184  gain = ROOT.CaloCondUtils.getDbCaloGain(int(fields[2]))
185  noiseA = float(fields[3])
186  noiseB = float(fields[4])
187  flt = fltDict[systemId][1]
188  if mu > 0 and dt > 0:
189  # new normalization
190  if dt > 25:
191  noiseB /= math.sqrt(mu/53.*10.)
192  else:
193  noiseB /= math.sqrt(mu/29.*10.)
194  pass
195  flt.setData(hash,gain,0,noiseA)
196  flt.setData(hash,gain,1,noiseB)
197 
198  #=== write to DB
199  for systemId, dataList in fltDict.items():
200  if (systemId<48):
201  sysName = systemDict[systemId][3]
202  log.info("Committing BLOB for %s", sysName)
203  channelId = cool.ChannelId(systemId)
204  log.info("Cool channel ID %s", channelId)
205  data = dataList[0]
206  folder.storeObject(iovSince, iovUntil, data, channelId, folderTag)
207 
208 except Exception as e:
209  log.fatal("Exception caught:")
210  print (e)
211 
212 #=== close the database
213 db.closeDatabase()
214 
CaloNoise_fillDB.usage
def usage()
Definition: CaloNoise_fillDB.py:8
Trk::open
@ open
Definition: BinningType.h:40
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65