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-2025 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
41 args = parser.parse_args()
42 if help in args and args.help is not None and args.help:
43 parser.print_help()
44 sys.exit(0)
45
46 for _, value in args._get_kwargs():
47 if value is not None:
48 print(value)
49
50 if len(args.run) < 8:
51 args.run = args.run.zfill(8)
52
53 # now set flags according parsed options
54 if args.indir != "":
55 InputDir = args.indir
56 else:
57 gain=args.gain.lower().capitalize()
58 if not args.supercells:
59 partstr = args.partition
60 else:
61 partstr = args.partition+"-DT"
62 if args.rawdata:
63 partstr += "-RawData"
64 # here - add optional nsamples
65 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/"
66
67 #Import the configution-method we want to use (here: Pedestal and AutoCorr)
68 from LArCalibProcessing.LArCalib_Delay_OFCCaliConfig import LArDelay_OFCCaliCfg
69
70 #Import the MainServices (boilerplate)
71 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
72
73 #Import the flag-container that is the arguemnt to the configuration methods
74 from AthenaConfiguration.AllConfigFlags import initConfigFlags
75 from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
76 flags=initConfigFlags()
77 addLArCalibFlags(flags, args.supercells)
78
79 #Now we set the flags as required for this particular job:
80 #The following flags help finding the input bytestream files:
81 flags.LArCalib.Input.Dir = InputDir
82 flags.LArCalib.Input.Type = args.trig
83 flags.LArCalib.Input.RunNumbers = [int(args.run),]
84 flags.LArCalib.Input.Database = args.outpdir + "/" +args.insql
85 flags.LArCalib.Input.isRawData = args.rawdata
86 gainNumMap={"HIGH":0,"MEDIUM":1,"LOW":2}
87 flags.LArCalib.Gain=gainNumMap[args.gain.upper()]
88
89
90 # Input files
91 flags.Input.Files=flags.LArCalib.Input.Files
92 #Print the input files we found
93 print ("Input files to be processed:")
94 for f in flags.Input.Files:
95 print (f)
96
97 if len(flags.Input.Files) == 0 :
98 print("Unable to find any input files. Please check the input directory:",InputDir)
99 sys.exit(0)
100
101 #Some configs depend on the sub-calo in question
102 #(sets also the preselection of LArRawCalibDataReadingAlg)
103 if not flags.LArCalib.isSC:
104 if args.subdet == 'EMB' or args.subdet == 'EMEC':
105 flags.LArCalib.Input.SubDet="EM"
106 elif args.subdet:
107 flags.LArCalib.Input.SubDet=args.subdet
108
109 if not args.side:
110 flags.LArCalib.Preselection.Side = [0,1]
111 elif args.side == "C":
112 flags.LArCalib.Preselection.Side = [0]
113 elif args.side == "A":
114 flags.LArCalib.Preselection.Side = [1]
115 else:
116 print("unknown side ",args.side)
117 sys.exit(-1)
118
119 if args.subdet != "EM":
120 if args.subdet == 'EMB':
121 flags.LArCalib.Preselection.BEC = [0]
122 else:
123 flags.LArCalib.Preselection.BEC = [1]
124
125 if args.subdet == 'FCAL':
126 flags.LArCalib.Preselection.FT = [6]
127 elif args.subdet == 'HEC':
128 flags.LArCalib.Preselection.FT = [3,10,16,22]
129 elif args.subdet == 'HECFCAL':
130 flags.LArCalib.Preselection.FT = [3,6,10,16,22]
131
132 #Configure the Bad-Channel database we are reading
133 #(the AP typically uses a snapshot in an sqlite file
134
135 if args.badsql.startswith("/"):
136 flags.LArCalib.BadChannelDB = args.badsql
137 else:
138 flags.LArCalib.BadChannelDB = args.outpdir + "/" + args.badsql
139
140 #Output of this job:
141 OutputCaliWaveRootFileName = args.outrwaveprefix + "_" + args.run
142 OutputPoolFileName = args.outpprefix + "_" + args.run
143 OutputOFCCaliRootFileName = args.outrofcprefix + "_" + args.run
144
145 if args.subdet != "" and not flags.LArCalib.isSC:
146 OutputCaliWaveRootFileName += "_"+args.subdet
147 OutputPoolFileName += "_"+args.subdet
148 OutputOFCCaliRootFileName += "_"+args.subdet
149
150 if flags.LArCalib.Input.SubDet=="EM":
151 OutputCaliWaveRootFileName += args.side
152 OutputPoolFileName += args.side
153 OutputOFCCaliRootFileName += args.side
154
155 OutputCaliWaveRootFileName += ".root"
156 OutputPoolFileName += ".pool.root"
157 OutputOFCCaliRootFileName += ".root"
158
159 flags.LArCalib.Output.ROOTFile = args.outrdir + "/" + OutputCaliWaveRootFileName
160 flags.LArCalib.Output.POOLFile = args.outpdir + "/" + OutputPoolFileName
161 flags.LArCalib.Output.ROOTFile2 = args.outrdir + "/" + OutputOFCCaliRootFileName
162 if args.outsql.startswith("/"):
163 flags.IOVDb.DBConnection="sqlite://;schema=" + args.outsql +";dbname=CONDBR2"
164 else:
165 flags.IOVDb.DBConnection="sqlite://;schema="+args.outpdir + "/" + args.outsql +";dbname=CONDBR2"
166
167 #The global tag we are working with
168 flags.IOVDb.GlobalTag = "LARCALIB-RUN2-00"
169
170 #validation not working for SC because no reference in OFL DB
171 if args.supercells:
172 flags.LArCalib.doValidation=False
173 if args.pulseall:
174 flags.LArCalib.CaliWave.Nsteps=1
175 flags.LArCalib.doOFCCali=False
176
177 #Other potentially useful flags-settings:
178
179 # patterns file searching
180 if args.rawdata:
181 if args.emf:
182 pdir='/afs/cern.ch/user/l/lardaq/public/detlar/athena/P1CalibrationProcessing/run/Patterns/EMF/EMF_Oct2024/Delay/emf/'
183 pfile = pdir+args.partition+'/parameters.dat'
184 else:
185 pdir='/afs/cern.ch/user/l/lardaq/public/detlar/athena/P1CalibrationProcessing/run/Patterns/P1/'
186 if args.supercells:
187 pdir += 'LatomeRuns/'
188 if 'Emec' in args.partition:
189 pfile = pdir + 'emec-std/SC_HighDelay/parameters.dat'
190 else:
191 pfile = pdir + 'barrel/Delay_' + args.partition[:-4] + '/parameters.dat'
192
193 else:
194 pdir += 'Delay/'
195 #FIXME create search also for main readout
196 pass
197 flags.LArCalib.Input.paramsFile = pfile
198
199 #Define the global output Level:
200 from AthenaCommon.Constants import INFO
201 flags.Exec.OutputLevel = INFO
202
203 from AthenaConfiguration.Enums import LHCPeriod
204 flags.GeoModel.Run = LHCPeriod.Run3
205
206 from AthenaConfiguration.TestDefaults import defaultGeometryTags
207 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
208
209 if args.emf:
210 # additions for EMF
211 flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
212 flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannelsSC","/LAR/BadChannels/BadChannelsSC","/LAR/Identifier/OnOffIdMap","/LAR/BadChannelsOfl/MissingFEBs","/LAR/BadChannelsOfl/KnownMNBFEBs","/LAR/BadChannelsOfl/KnownBADFEBs","/LAR/BadChannelsOfl/BadChannels",)
213 flags.LArCalib.CorrectBadChannels=False
214 flags.LArCalib.doValidation=False
215
216 flags.lock()
217 flags.dump(evaluate=True)
218
219 cfg=MainServicesCfg(flags)
220
221 cfg.merge(LArDelay_OFCCaliCfg(flags))
222
223 # Switch on, in case some calib. board is failing:
224 # adding new patching, again needed in summer 2023
225 #if flags.LArCalib.CorrectBadChannels:
226 # if flags.LArCalib.doValidation:
227 # cfg.getEventAlgo("CaliWaveVal").PatchCBs=[0x3df70000]
228 #
229 # # block standard patching for this CB
230 # cfg.getEventAlgo("LArCaliWavePatch").DoNotPatchCBs=[0x3df70000]
231
232 if flags.LArCalib.isSC:
233 fwversion=5
234 # autoconfig
235 from LArConditionsCommon.LArRunFormat import getLArDTInfoForRun
236 try:
237 runinfo=getLArDTInfoForRun(flags.Input.RunNumbers[0], connstring="COOLONL_LAR/CONDBR2")
238 log.info("Got DT run info !")
239 except Exception:
240 log.warning("Could not get DT run info, using defaults !")
241 else:
242 fwversion=runinfo.FWversion()
243 if args.fw6 or fwversion==6:
244 from IOVDbSvc.IOVDbSvcConfig import addOverride
245 cfg.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-fw6"))
246
247 if args.emf:
248 # additions for EMF
249 from IOVDbSvc.IOVDbSvcConfig import addOverride
250 cfg.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-EMF"))
251 fldrs=cfg.getService("IOVDbSvc").Folders
252 for i in range(0, len(fldrs)):
253 if 'Align' in fldrs[i]: fldrs[i] += '<forceRunNumber>9999999</forceRunNumber>'
254
255 # ignore some channels ?
256 if args.ignoreB:
257 if args.rawdata:
258 cfg.getEventAlgo("LArRawSCDataReadingAlg").LATOMEDecoder.IgnoreBarrelChannels=args.ignoreB
259 else:
260 cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreBarrelChannels=args.ignoreB
261 if args.ignoreE:
262 if args.rawdata:
263 cfg.getEventAlgo("LArRawSCDataReadingAlg").LATOMEDecoder.IgnoreEndcapChannels=args.ignoreE
264 else:
265 cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreEndcapChannels=args.ignoreE
266
267 cfg.getService("IOVDbSvc").DBInstance=""
268
269 cfg.getService("MessageSvc").defaultLimit=2000000 #more messages
270 #cfg.getEventAlgo("LArCalibDigitMaker").OutputLevel=2
271 #cfg.getEventAlgo("LArCalibDigitsAccumulator").OutputLevel=2
272 #cfg.getEventAlgo("LArCaliWaveBuilder").OutputLevel=2
273 #cfg.getEventAlgo("LArCalibDigitsAccumulator").OutputLevel=2
274
275 #run the application
276 cfg.run()
277
278 #build tag hierarchy in output sqlite file
279 import subprocess
280 cmdline = (['/afs/cern.ch/user/l/larcalib/LArDBTools/python/BuildTagHierarchy.py',args.outpdir + "/" + args.outsql , flags.IOVDb.GlobalTag])
281 print(cmdline)
282 try:
283 subprocess.run(cmdline, check=True)
284 except Exception as e:
285 print('Could not create tag hierarchy in output sqlite file !!!!')
286 sys.exit(-1)
287
void print(char *figname, TCanvas *c1)