ATLAS Offline Software
Loading...
Searching...
No Matches
TileCalibBlobPython_writePedFromASCII.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# TileCalibBlobPython_writePedFromASCII.py
6# Nils Gollub <nils.gollub@cern.ch>, 2008-03-03
7# modified: Lukas Pribyl <lukas.pribyl@cern.ch>, 2008-06-27
8# modified: Yuri Smirnov <iouri.smirnov@cern.ch>, 2014-12-24
9
10import cppyy
11import os
12
13from TileCalibBlobPython import TileCalibTools
14from TileCalibBlobObjs.Classes import TileCalibUtils
15
16#=== some preparation
17from TileCalibBlobPython.TileCalibLogger import getLogger
18log = getLogger("writeNoise")
19import logging
20log.setLevel(logging.DEBUG)
21
22#
23#________________________________________________________________________
24def fillPed(filePed, tag, comment, since,
25 until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)):
26
27 #=== construct folder path
28 folder = TileCalibTools.getTilePrefix(True,True)+"NOISE/SAMPLE"
29
30 #=== get full folder tag
31 folderTag = TileCalibUtils.getFullTag(folder, tag)
32
33 #=== create default (ADC counts)
34 pedDef = [30.,50.]
35 loGainDef = 0.8
36 hiGainDef = 1.6
37 defaultLo = cppyy.gbl.std.vector('float')()
38 defaultLo.push_back(pedDef[0]) # pedestal mean value
39 defaultLo.push_back(loGainDef) # pedestal rms
40 defaultLo.push_back(0.0) # pedestal low frequency noise
41 defaultLo.push_back(loGainDef) # pedestal HFN1
42 defaultLo.push_back(0.0) # pedestal HFN2
43 defaultLo.push_back(0.0) # pedestal HFN2/HFN1 ratio
44 defaultHi = cppyy.gbl.std.vector('float')()
45 defaultHi.push_back(pedDef[1]) # pedestal mean value
46 defaultHi.push_back(hiGainDef) # pedestal rms
47 defaultHi.push_back(0.0) # pedestal low frequency noise
48 defaultHi.push_back(hiGainDef) # pedestal HFN1
49 defaultHi.push_back(0.0) # pedestal HFN2
50 defaultHi.push_back(0.0) # pedestal HFN2/HFN1 ratio
51 defVec = cppyy.gbl.std.vector('std::vector<float>')()
52 defVec.push_back(defaultLo)
53 defVec.push_back(defaultHi)
54
55 #=====================================================
56 #=== fill
57 #=====================================================
58 writer = TileCalibTools.TileBlobWriter(db,folder,'Flt')
59 writer.setComment(os.getlogin(),comment)
60 parser = TileCalibTools.TileASCIIParser2(filePed,"")
61 #=== loop over whole detector
62 for ros in range(0,5):
63 #for mod in range(64):
64 for mod in range(0, min(64,TileCalibUtils.getMaxDrawer(ros))):
65 #=== need to invalidate previous blob in DB when reading from ASCII file
66 writer.zeroBlob(ros,mod)
67 #=== init drawer with defaults for first entry
68 calibDrawer = writer.getDrawer(ros,mod)
69 if not calibDrawer.getNObjs():
70 log.info("Initializing drawer %i/%2i\t%i", ros,mod,calibDrawer.getNObjs())
71 calibDrawer.init(defVec,48,0)
72 for chn in range(48):
73 #=== loop over gains
74 for adc in range(2):
75 calibDrawer.setData(chn,adc,0,pedDef[adc]+(chn+1)/48.)
76 values = parser.getData(ros,mod,chn,adc)
77 if not len(values):
78 log.warning("%i/%2i/%2i/%i: No value found in file", ros,mod,chn,adc)
79 values = parser.getData(0,ros*4,chn,adc)
80 if not len(values):
81 log.warning("No default per partition available")
82 values = parser.getData(0,0,chn,adc)
83 if not len(values):
84 log.warning("No global default available - give up")
85 continue
86 else:
87 log.warning("Using global default")
88 else:
89 log.warning("Using default per partition")
90 #=== the order of columns in the ASCII file is different to the order in DB
91 lvl = float(values[0]) # pedestal level
92 hfn = float(values[1]) # high frequency noise
93 lfn = float(values[2]) # low frequency noise
94 hfn1= float(values[3]) # hfn1
95 hfn2= float(values[4]) # hfn2
96 norm= float(values[5]) # hfn2/hfn1
97 log.debug("%i/%2i/%2i/%i: pedLvl=%f\thfn=%f\tlfn=%f\thfn1=%f\thfn2=%f\tnorm=%f", ros,mod,chn,adc, lvl,hfn,lfn,hfn1,hfn2,norm)
98 calibDrawer.setData(chn,adc,0,lvl)
99 calibDrawer.setData(chn,adc,1,hfn)
100 calibDrawer.setData(chn,adc,2,lfn)
101 calibDrawer.setData(chn,adc,3,hfn1)
102 calibDrawer.setData(chn,adc,4,hfn2)
103 calibDrawer.setData(chn,adc,5,norm)
104 #=== register in DB
105 writer.register(since, until, folderTag)
106
107
108
109#===================================================================
110#====================== FILL DB BELOW ==============================
111#===================================================================
112
113#=== open the database
114db = TileCalibTools.openDb('SQLITE', 'OFLP200', 'UPDATE')
115tag = "TwoGauss-19"
116file = "TileDefault.ped"
117run = 222222
118comment = "Intial tag with 2G noise for RUN2, all modules are identical, 2014-07-11"
119
120#=== read ascii file and put it in DB
121fillPed(file, tag, comment, (run,0))
122
123#=== close the database connection
124db.closeDatabase()
#define min(a, b)
Definition cfImp.cxx:40
static unsigned int getMaxDrawer(unsigned int ros)
Returns the maximal channel number for a given drawer.
static std::string getFullTag(const std::string &folder, const std::string &tag)
Returns the full tag string, composed of camelized folder name and tag part.
fillPed(filePed, tag, comment, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK))