ATLAS Offline Software
Loading...
Searching...
No Matches
LArNewCalib_Delay_OFC_Cali.py
Go to the documentation of this file.
1#!/usr/bin/env python
2#
3# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
4#
5
6if __name__=='__main__':
7
8 import os,sys
9 import argparse
10 from AthenaCommon import Logging
11 log = Logging.logging.getLogger( 'LArDelayOFCCali' )
12
13 # now process the CL options and assign defaults
14 parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
15 #parser.add_argument('-r','--runlist', dest='runlist', default=RunNumberList, nargs='+', help='Run numbers string list', type=str)
16 parser.add_argument('-r','--run', dest='run', default='00408918', help='Run number string as in input filename', type=str)
17 parser.add_argument('-g','--gain', dest='gain', default="MEDIUM", help='Gain string', type=str)
18 parser.add_argument('-p','--partition', dest='partition', default="Em", help='Data taking partition string', type=str)
19 parser.add_argument('-f','--fileprefix', dest='fprefix', default="data25_calib", help='File prefix string', type=str)
20 parser.add_argument('-i','--indirprefix', dest='dprefix', default="/eos/atlas/atlastier0/rucio/", help='Input directory prefix string', type=str)
21 parser.add_argument('-d','--indir', dest='indir', default="", help='Full input dir string', type=str)
22 parser.add_argument('-t','--trigger', dest='trig', default='calibration_', help='Trigger string in filename', type=str)
23 parser.add_argument('-o','--outrwaveprefix', dest='outrwaveprefix', default="LArCaliWave", help='Prefix of CaliWave output root filename', type=str)
24 parser.add_argument('-l','--outpprefix', dest='outpprefix', default="LArCaliWave_OFC_Cali", help='Prefix of output pool filename', type=str)
25 parser.add_argument('-j','--outrofcprefix', dest='outrofcprefix', default="LArOFCCali", help='Prefix of output Cali OFC root filename', type=str)
26 parser.add_argument('-e','--outrdir', dest='outrdir', default="/eos/atlas/atlascerngroupdisk/det-larg/Temp/Weekly/ntuples", help='Output root file directory', type=str)
27 parser.add_argument('-k','--outpdir', dest='outpdir', default="/eos/atlas/atlascerngroupdisk/det-larg/Temp/Weekly/poolFiles", help='Output pool file directory', type=str)
28 parser.add_argument('-u','--insqlite', dest='insql', default="mysql.db", help='Input sqlite file with pedestals, in pool output dir.', type=str)
29 parser.add_argument('-n','--outsqlite', dest='outsql', default="mysql_delay.db", help='Output sqlite file, in pool output dir.', type=str)
30 parser.add_argument('-m','--subdet', dest='subdet', default="EMB", help='Subdetector, EMB, EMEC, HEC, FCAL or HECFCAL', type=str)
31 parser.add_argument('-s','--side', dest='side', default="C", help='Detector side empty (means both), C or A', type=str)
32 parser.add_argument('-c','--isSC', dest='supercells', default=False, action="store_true", help='is SC data ?')
33 parser.add_argument('-a','--isRawdata', dest='rawdata', default=False, action="store_true", help='is raw data ?')
34 parser.add_argument('-x','--ignoreBarrel', dest='ignoreB', default=False, action="store_true", help='ignore Barrel channels ?')
35 parser.add_argument('-v','--ignoreEndcap', dest='ignoreE', default=False, action="store_true", help='ignore Endcap channels ?')
36 parser.add_argument('-b','--badchansqlite', dest='badsql', default="SnapshotBadChannel.db", help='Output sqlite file, in pool output dir.', type=str)
37 parser.add_argument('--FW6', dest='fw6', default=False, help='Is it for fw v. 6', action='store_true')
38 parser.add_argument('--EMF', dest='emf', default=False, help='Is it for EMF', action='store_true')
39 parser.add_argument('--pulseAll', dest='pulseall', default=False, help='Is it PulseAll run ?', action='store_true')
40 parser.add_argument('--pattdir', dest='pdir', default="", help='Full input pattern dir string', type=str)
41 parser.add_argument('--noValid', dest='novalid', default=False, action="store_true", help='stop the validation ?')
42 parser.add_argument('--nopatch', dest='nopatch', default=False, action="store_true", help='stop the patching ?')
43
44 args = parser.parse_args()
45 if help in args and args.help is not None and args.help:
46 parser.print_help()
47 sys.exit(0)
48
49 for _, value in args._get_kwargs():
50 if value is not None:
51 print(value)
52
53 if len(args.run) < 8:
54 args.run = args.run.zfill(8)
55
56 # now set flags according parsed options
57 if args.indir != "":
58 InputDir = args.indir
59 else:
60 gain=args.gain.lower().capitalize()
61 if not args.supercells:
62 partstr = args.partition
63 else:
64 partstr = args.partition+"-DT"
65 if args.rawdata:
66 partstr += "-RawData"
67 # here - add optional nsamples
68 InputDir = args.dprefix+args.fprefix+"/calibration_LArElec-Delay-32s-"+gain+"-"+partstr+"/"+args.run+"/"+args.fprefix+"."+args.run+".calibration_LArElec-Delay-32s-"+gain+"-"+partstr+".daq.RAW/"
69
70 #Import the configution-method we want to use (here: Pedestal and AutoCorr)
71 from LArCalibProcessing.LArCalib_Delay_OFCCaliConfig import LArDelay_OFCCaliCfg
72
73 #Import the MainServices (boilerplate)
74 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
75
76 #Import the flag-container that is the arguemnt to the configuration methods
77 from AthenaConfiguration.AllConfigFlags import initConfigFlags
78 from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
79 flags=initConfigFlags()
80 addLArCalibFlags(flags, args.supercells)
81
82 #Now we set the flags as required for this particular job:
83 #The following flags help finding the input bytestream files:
84 flags.LArCalib.Input.Dir = InputDir
85 flags.LArCalib.Input.Type = args.trig
86 flags.LArCalib.Input.RunNumbers = [int(args.run),]
87 flags.LArCalib.Input.Database = args.outpdir + "/" +args.insql
88 flags.LArCalib.Input.isRawData = args.rawdata
89 gainNumMap={"HIGH":0,"MEDIUM":1,"LOW":2}
90 flags.LArCalib.Gain=gainNumMap[args.gain.upper()]
91
92
93 # Input files
94 flags.Input.Files=flags.LArCalib.Input.Files
95 #Print the input files we found
96 print ("Input files to be processed:")
97 for f in flags.Input.Files:
98 print (f)
99
100 if len(flags.Input.Files) == 0 :
101 print("Unable to find any input files. Please check the input directory:",InputDir)
102 sys.exit(0)
103
104 #Some configs depend on the sub-calo in question
105 #(sets also the preselection of LArRawCalibDataReadingAlg)
106 if not flags.LArCalib.isSC:
107 if args.subdet == 'EMB' or args.subdet == 'EMEC':
108 flags.LArCalib.Input.SubDet="EM"
109 elif args.subdet:
110 flags.LArCalib.Input.SubDet=args.subdet
111
112 if not args.side:
113 flags.LArCalib.Preselection.Side = [0,1]
114 elif args.side == "C":
115 flags.LArCalib.Preselection.Side = [0]
116 elif args.side == "A":
117 flags.LArCalib.Preselection.Side = [1]
118 else:
119 print("unknown side ",args.side)
120 sys.exit(-1)
121
122 if args.subdet != "EM":
123 if args.subdet == 'EMB':
124 flags.LArCalib.Preselection.BEC = [0]
125 else:
126 flags.LArCalib.Preselection.BEC = [1]
127
128 if args.subdet == 'FCAL':
129 flags.LArCalib.Preselection.FT = [6]
130 elif args.subdet == 'HEC':
131 flags.LArCalib.Preselection.FT = [3,10,16,22]
132 elif args.subdet == 'HECFCAL':
133 flags.LArCalib.Preselection.FT = [3,6,10,16,22]
134
135 #Configure the Bad-Channel database we are reading
136 #(the AP typically uses a snapshot in an sqlite file
137
138 if args.badsql.startswith("/"):
139 flags.LArCalib.BadChannelDB = args.badsql
140 else:
141 flags.LArCalib.BadChannelDB = args.outpdir + "/" + args.badsql
142
143 #Output of this job:
144 OutputCaliWaveRootFileName = args.outrwaveprefix + "_" + args.run
145 OutputPoolFileName = args.outpprefix + "_" + args.run
146 OutputOFCCaliRootFileName = args.outrofcprefix + "_" + args.run
147
148 if args.subdet != "" and not flags.LArCalib.isSC:
149 OutputCaliWaveRootFileName += "_"+args.subdet
150 OutputPoolFileName += "_"+args.subdet
151 OutputOFCCaliRootFileName += "_"+args.subdet
152
153 if flags.LArCalib.Input.SubDet=="EM":
154 OutputCaliWaveRootFileName += args.side
155 OutputPoolFileName += args.side
156 OutputOFCCaliRootFileName += args.side
157
158 OutputCaliWaveRootFileName += ".root"
159 OutputPoolFileName += ".pool.root"
160 OutputOFCCaliRootFileName += ".root"
161
162 flags.LArCalib.Output.ROOTFile = args.outrdir + "/" + OutputCaliWaveRootFileName
163 flags.LArCalib.Output.POOLFile = args.outpdir + "/" + OutputPoolFileName
164 flags.LArCalib.Output.ROOTFile2 = args.outrdir + "/" + OutputOFCCaliRootFileName
165 if args.outsql.startswith("/"):
166 flags.IOVDb.DBConnection="sqlite://;schema=" + args.outsql +";dbname=CONDBR2"
167 else:
168 flags.IOVDb.DBConnection="sqlite://;schema="+args.outpdir + "/" + args.outsql +";dbname=CONDBR2"
169
170 #The global tag we are working with
171 flags.IOVDb.GlobalTag = "LARCALIB-RUN2-00"
172
173 #validation not working for SC because no reference in OFL DB
174 if args.supercells:
175 flags.LArCalib.doValidation=False
176 if args.pulseall:
177 flags.LArCalib.CaliWave.Nsteps=1
178 flags.LArCalib.doOFCCali=False
179
180 #Other potentially useful flags-settings:
181
182 # patterns file searching
183 if args.rawdata:
184 if args.emf:
185 pdir='/afs/cern.ch/user/l/lardaq/public/detlar/athena/P1CalibrationProcessing/run/Patterns/EMF/EMF_Oct2024/Delay/emf/'
186 pfile = pdir+args.partition+'/parameters.dat'
187 else:
188 pdir='/afs/cern.ch/user/l/lardaq/public/detlar/athena/P1CalibrationProcessing/run/Patterns/P1/'
189 if args.supercells:
190 pdir += 'LatomeRuns/'
191 if 'Emec' in args.partition:
192 pfile = pdir + 'emec-std/SC_HighDelay/parameters.dat'
193 else:
194 pfile = pdir + 'barrel/Delay_' + args.partition[:-4] + '/parameters.dat'
195
196 else:
197 pdir=args.pdir
198 pfile = pdir + '/parameters.dat'
199 #FIXME create search also for main readout
200 pass
201 flags.LArCalib.Input.paramsFile = pfile
202
203 #Define the global output Level:
204 from AthenaCommon.Constants import INFO
205 flags.Exec.OutputLevel = INFO
206
207 from AthenaConfiguration.Enums import LHCPeriod
208 flags.GeoModel.Run = LHCPeriod.Run3
209
210 from AthenaConfiguration.TestDefaults import defaultGeometryTags
211 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
212
213 if args.emf:
214 # additions for EMF
215 flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
216 flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannelsSC","/LAR/BadChannels/BadChannelsSC","/LAR/Identifier/OnOffIdMap","/LAR/BadChannelsOfl/MissingFEBs","/LAR/BadChannelsOfl/KnownMNBFEBs","/LAR/BadChannelsOfl/KnownBADFEBs","/LAR/BadChannelsOfl/BadChannels",)
217 flags.LArCalib.CorrectBadChannels=False
218 flags.LArCalib.doValidation=False
219
220 if args.novalid:
221 flags.LArCalib.doValidation=False
222 if args.nopatch:
223 flags.LArCalib.CorrectBadChannels=False
224
225 flags.lock()
226 flags.dump(evaluate=True)
227
228 cfg=MainServicesCfg(flags)
229
230 cfg.merge(LArDelay_OFCCaliCfg(flags))
231
232 # Switch on, in case some calib. board is failing:
233 # adding new patching, again needed in summer 2023
234 #if flags.LArCalib.CorrectBadChannels:
235 # if flags.LArCalib.doValidation:
236 # cfg.getEventAlgo("CaliWaveVal").PatchCBs=[0x3df70000]
237 #
238 # # block standard patching for this CB
239 # cfg.getEventAlgo("LArCaliWavePatch").DoNotPatchCBs=[0x3df70000]
240
241 if flags.LArCalib.isSC:
242 fwversion=5
243 # autoconfig
244 from LArConditionsCommon.LArRunFormat import getLArDTInfoForRun
245 try:
246 runinfo=getLArDTInfoForRun(flags.Input.RunNumbers[0], connstring="COOLONL_LAR/CONDBR2")
247 log.info("Got DT run info !")
248 except Exception:
249 log.warning("Could not get DT run info, using defaults !")
250 else:
251 fwversion=runinfo.FWversion()
252 if args.fw6 or fwversion==6:
253 from IOVDbSvc.IOVDbSvcConfig import addOverride
254 cfg.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-fw6"))
255
256 if args.emf:
257 # additions for EMF
258 from IOVDbSvc.IOVDbSvcConfig import addOverride
259 cfg.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-EMF"))
260 fldrs=cfg.getService("IOVDbSvc").Folders
261 for i in range(0, len(fldrs)):
262 if 'Align' in fldrs[i]: fldrs[i] += '<forceRunNumber>9999999</forceRunNumber>'
263
264 # ignore some channels ?
265 if args.ignoreB:
266 if args.rawdata:
267 cfg.getEventAlgo("LArRawSCDataReadingAlg").LATOMEDecoder.IgnoreBarrelChannels=args.ignoreB
268 else:
269 cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreBarrelChannels=args.ignoreB
270 if args.ignoreE:
271 if args.rawdata:
272 cfg.getEventAlgo("LArRawSCDataReadingAlg").LATOMEDecoder.IgnoreEndcapChannels=args.ignoreE
273 else:
274 cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreEndcapChannels=args.ignoreE
275
276 cfg.getService("IOVDbSvc").DBInstance=""
277
278 cfg.getService("MessageSvc").defaultLimit=200 #less messages
279 #cfg.getService("MessageSvc").OutputLevel=2
280 #cfg.getEventAlgo("LArCalibDigitMaker").OutputLevel=2
281 #cfg.getEventAlgo("LArCalibDigitsAccumulator").OutputLevel=2
282 #cfg.getEventAlgo("LArCaliWaveBuilder").OutputLevel=2
283 #cfg.getEventAlgo("LArCalibDigitsAccumulator").OutputLevel=2
284
285 #run the application
286 cfg.run()
287
288 #build tag hierarchy in output sqlite file
289 script = "/afs/cern.ch/user/l/larcalib/LArDBTools/python/BuildTagHierarchy.py"
290 if not os.path.isfile(script): script = "/det/lar/project/athena/BuildTagHierarchy.py"
291 import subprocess
292 cmdline = [script,
293 f"{args.outpdir}/{args.outsql}" if args.outsql[0]!="/" else args.outsql,
294 flags.IOVDb.GlobalTag]
295 print(cmdline)
296 try:
297 subprocess.run(cmdline, check=True)
298 except Exception as e:
299 print('Could not create tag hierarchy in output sqlite file !!!!')
300 sys.exit(-1)
void print(char *figname, TCanvas *c1)