ATLAS Offline Software
Loading...
Searching...
No Matches
LArNewCalib_Ramp.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( 'LArRamp' )
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='00408920', 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','--outrprefix', dest='outrprefix', default="LArRamp", help='Prefix of output ramp root filename', type=str)
24 parser.add_argument('-j','--outpprefix', dest='outpprefix', default="LArRamp", help='Prefix of output ramp pool filename', type=str)
25 parser.add_argument('-e','--outrdir', dest='outrdir', default="/eos/atlas/atlascerngroupdisk/det-larg/Temp/Weekly/ntuples", help='Output root file directory', type=str)
26 parser.add_argument('-k','--outpdir', dest='outpdir', default="/eos/atlas/atlascerngroupdisk/det-larg/Temp/Weekly/poolFiles", help='Output pool file directory', type=str)
27 parser.add_argument('-u','--inpsqlite', dest='inpsql', default="mysql.db", help='Input sqlite file with pedestals, in pool output dir.', type=str)
28 parser.add_argument('-l','--inofcsqlite', dest='inofcsql', default="mysql_delay.db", help='Input sqlite file with ofcs, in pool output dir', type=str)
29 parser.add_argument('-n','--outsqlite', dest='outsql', default="mysql_ramp.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 or FCAL', 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('-b','--badchansqlite', dest='badsql', default="SnapshotBadChannel.db", help='Output sqlite file, in pool output dir.', type=str)
35 parser.add_argument('-x','--ignoreBarrel', dest='ignoreB', default=False, action="store_true", help='ignore Barrel channels ?')
36 parser.add_argument('-v','--ignoreEndcap', dest='ignoreE', default=False, action="store_true", help='ignore Endcap channels ?')
37 parser.add_argument('-w','--doValid', dest='doValid', default=False, action="store_true", help='run vcalidation ?')
38 parser.add_argument('--pattdir', dest='pdir', default="", help='Full input pattern dir string', type=str)
39 parser.add_argument('--ntrigg', dest='ntrig', default=100, help='Number of trigger per step', type=int)
40 parser.add_argument('--nsteps', dest='nstep', default=5, help='Number of delay steps', type=int)
41 parser.add_argument('--nsubstep', dest='nsubstep', default=1, help='Number of subststeps', type=int)
42 parser.add_argument('--FW6', dest='fw6', default=False, help='Is it for fw v. 6', action='store_true')
43 parser.add_argument('--EMF', dest='emf', default=False, help='Is it for EMF', action='store_true')
44
45
46 args = parser.parse_args()
47 if help in args and args.help is not None and args.help:
48 parser.print_help()
49 sys.exit(0)
50
51 for _, value in args._get_kwargs():
52 if value is not None:
53 print(_,":",value)
54
55 if len(args.run) < 8:
56 args.run = args.run.zfill(8)
57
58 # now set flags according parsed options
59 if args.indir != "":
60 InputDir = args.indir
61 else:
62 gain=args.gain.lower().capitalize()
63
64 if not args.supercells:
65 partstr = args.partition
66 else:
67 partstr = args.partition+"-DT"
68 if args.rawdata:
69 partstr += "-RawData"
70 # here - add optional nsamples
71 if args.supercells:
72 InputDir = args.dprefix+args.fprefix+"/calibration_LArElec-Ramp-32s-"+gain+"-"+partstr+"/"+args.run+"/"+args.fprefix+"."+args.run+".calibration_LArElec-Ramp-32s-"+gain+"-"+partstr+".daq.RAW/"
73 else:
74 InputDir = args.dprefix+args.fprefix+"/calibration_LArElec-Ramp-7s-"+gain+"-"+partstr+"/"+args.run+"/"+args.fprefix+"."+args.run+".calibration_LArElec-Ramp-7s-"+gain+"-"+partstr+".daq.RAW/"
75
76
77 #Import the configution-method we want to use (here: Pedestal and AutoCorr)
78 from LArCalibProcessing.LArCalib_RampConfig import LArRampCfg
79
80 #Import the MainServices (boilerplate)
81 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
82
83 #Import the flag-container that is the arguemnt to the configuration methods
84 from AthenaConfiguration.AllConfigFlags import initConfigFlags
85 from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
86 flags=initConfigFlags()
87 addLArCalibFlags(flags, args.supercells)
88
89 #Now we set the flags as required for this particular job:
90 #The following flags help finding the input bytestream files:
91 flags.LArCalib.Input.Dir = InputDir
92 flags.LArCalib.Input.Type = args.trig
93 flags.LArCalib.Input.RunNumbers = [int(args.run),]
94 flags.LArCalib.Input.Database = args.outpdir + "/" +args.inpsql
95 flags.LArCalib.Input.isRawData = args.rawdata
96 if 'db' in args.inofcsql:
97 flags.LArCalib.Input.Database2 = args.outpdir + "/" +args.inofcsql
98 else:
99 flags.LArCalib.Input.Database2 = args.inofcsql
100 gainNumMap={"HIGH":0,"MEDIUM":1,"LOW":2}
101 flags.LArCalib.Gain=gainNumMap[args.gain.upper()]
102
103 # Input files
104 flags.Input.Files=flags.LArCalib.Input.Files
105 #Print the input files we found
106 print ("Input files to be processed:")
107 for f in flags.Input.Files:
108 print (f)
109
110 if len(flags.Input.Files) == 0 :
111 print("Unable to find any input files. Please check the input directory:",InputDir)
112 sys.exit(0)
113
114 #Some configs depend on the sub-calo in question
115 #(sets also the preselection of LArRawCalibDataReadingAlg)
116 if not flags.LArCalib.isSC:
117 if args.subdet == 'EMB' or args.subdet == 'EMEC':
118 flags.LArCalib.Input.SubDet="EM"
119 elif args.subdet:
120 flags.LArCalib.Input.SubDet=args.subdet
121
122 if not args.side:
123 flags.LArCalib.Preselection.Side = [0,1]
124 elif args.side == "C":
125 flags.LArCalib.Preselection.Side = [0]
126 elif args.side == "A":
127 flags.LArCalib.Preselection.Side = [1]
128 else:
129 print("unknown side ",args.side)
130 sys.exit(-1)
131
132 if args.subdet != "EM":
133 if args.subdet == 'EMB':
134 flags.LArCalib.Preselection.BEC = [0]
135 else:
136 flags.LArCalib.Preselection.BEC = [1]
137
138 if args.subdet == 'FCAL':
139 flags.LArCalib.Preselection.FT = [6]
140 elif args.subdet == 'HEC':
141 flags.LArCalib.Preselection.FT = [3,10,16,22]
142 elif args.subdet == 'HECFCAL':
143 flags.LArCalib.Preselection.FT = [3,6,10,16,22]
144 else:
145 flags.LArCalib.Input.SubDet=args.subdet
146
147 #Configure the Bad-Channel database we are reading
148 #(the AP typically uses a snapshot in an sqlite file
149 flags.LArCalib.BadChannelDB = args.outpdir + "/" + args.badsql
150
151 #Output of this job:
152 OutputRampRootFileName = args.outrprefix + "_" + args.run
153 OutputRampPoolFileName = args.outpprefix + "_" + args.run
154
155 if args.subdet != "" and not flags.LArCalib.isSC:
156 OutputRampRootFileName += "_"+args.subdet
157 OutputRampPoolFileName += "_"+args.subdet
158 if flags.LArCalib.Input.SubDet=="EM":
159 OutputRampRootFileName += args.side
160 OutputRampPoolFileName += args.side
161
162 OutputRampRootFileName += ".root"
163 OutputRampPoolFileName += ".pool.root"
164
165 flags.LArCalib.Output.ROOTFile = args.outrdir + "/" + OutputRampRootFileName
166 flags.LArCalib.Output.POOLFile = args.outpdir + "/" + OutputRampPoolFileName
167 flags.IOVDb.DBConnection="sqlite://;schema="+args.outpdir + "/" + args.outsql +";dbname=CONDBR2"
168
169 #The global tag we are working with
170 flags.IOVDb.GlobalTag = "LARCALIB-RUN2-00"
171
172 from AthenaConfiguration.TestDefaults import defaultGeometryTags
173 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
174
175 #run validation:
176 if flags.LArCalib.isSC:
177 flags.LArCalib.doValidation= args.doValid
178 else:
179 flags.LArCalib.doValidation=True
180
181 # patterns file searching
182 if args.rawdata:
183 # nsteps
184 flags.LArCalib.CaliWave.Nsteps=args.nstep
185 # patterns file
186 if args.pdir:
187 pdir=args.pdir
188 else:
189 pdir='/afs/cern.ch/user/l/lardaq/public/detlar/athena/P1CalibrationProcessing/run/Patterns/P1/'
190 if args.supercells:
191 pdir += 'LatomeRuns/'
192 if 'Emec' in args.partition:
193 pfile = pdir + 'emec-std/SC_HighRamp'
194 else:
195 pfile = pdir + 'barrel/Ramp_' + args.partition[:-4]
196
197 flags.LArCalib.Input.paramsFile = pfile
198 #FIXME create search also for main readout
199 pass
200
201 pfile = pdir + '/parameters.dat'
202 flags.LArCalib.Input.paramsFile = pfile
203 # number of triggers (misusing OFC flags, which are not use in this job)
204 flags.LArCalib.OFC.Ncoll = args.ntrig
205 # number of substeps
206 flags.LArCalib.CaliWave.NSubSteps = args.nsubstep
207
208
209 #Define the global output Level:
210
211 from AthenaCommon.Constants import INFO
212 flags.Exec.OutputLevel = INFO
213
214 from AthenaConfiguration.Enums import LHCPeriod
215 flags.GeoModel.Run = LHCPeriod.Run3
216
217 if args.emf:
218 # additions for EMF
219 flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
220 flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannelsSC","/LAR/BadChannels/BadChannelsSC","/LAR/Identifier/OnOffIdMap",)
221 fldrs=cfg.getService("IOVDbSvc").Folders
222 for i in range(0, len(fldrs)):
223 if 'LatomeMapping' in fldrs[i]: fldrs[i] += '<tag>LARIdentifierLatomeMapping-EMF</tag>'
224
225
226 flags.lock()
227
228 cfg=MainServicesCfg(flags)
229
230 cfg.merge(LArRampCfg(flags))
231
232 # in case debug is needed
233 #if flags.LArCalib.doValidation:
234 # from AthenaCommon.Constants import DEBUG
235 # cfg.getEventAlgo("LArRampPatcher").OutputLevel=DEBUG
236 # cfg.getEventAlgo("RampVal").OutputLevel=DEBUG
237
238 # switch on if some calib. board is failing:
239 # adding new patching, again needed in summer 2023
240 #if flags.LArCalib.CorrectBadChannels:
241 # if flags.LArCalib.doValidation:
242 # cfg.getEventAlgo("RampVal").PatchCBs=[0x3fc70000]
243 #
244 # # block standard patching for this CB
245 # cfg.getEventAlgo("LArRampPatcher").DoNotPatchCBs=[0x3fc70000]
246
247 if flags.LArCalib.isSC:
248 fwversion=5
249 # autoconfig
250 from LArConditionsCommon.LArRunFormat import getLArDTInfoForRun
251 try:
252 runinfo=getLArDTInfoForRun(flags.Input.RunNumbers[0], connstring="COOLONL_LAR/CONDBR2")
253 log.info("Got DT run info !")
254 except Exception:
255 log.warning("Could not get DT run info, using defaults !")
256 else:
257 fwversion=runinfo.FWversion()
258 if args.fw6 or fwversion==6:
259 #FIXME: for some reason addOverride is not working, CA merger is then complaining
260 #from IOVDbSvc.IOVDbSvcConfig import addOverride
261 #cfg.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-fw6"))
262 fldrs=cfg.getService("IOVDbSvc").Folders
263 for i in range(0, len(fldrs)):
264 if 'LatomeMapping' in fldrs[i]: fldrs[i] += '<tag>LARIdentifierLatomeMapping-fw6</tag>'
265
266
267 # ignore some channels ?
268 if args.ignoreB:
269 if args.rawdata:
270 cfg.getEventAlgo("LArRawSCDataReadingAlg").LATOMEDecoder.IgnoreBarrelChannels=args.ignoreB
271 else:
272 cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreBarrelChannels=args.ignoreB
273 if args.ignoreE:
274 if args.rawdata:
275 cfg.getEventAlgo("LArRawSCDataReadingAlg").LATOMEDecoder.IgnoreEndcapChannels=args.ignoreE
276 else:
277 cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreEndcapChannels=args.ignoreE
278
279 cfg.getService("IOVDbSvc").DBInstance=""
280
281 #run the application
282 cfg.run()
283
284 #build tag hierarchy in output sqlite file
285 script = "/afs/cern.ch/user/l/larcalib/LArDBTools/python/BuildTagHierarchy.py"
286 if not os.path.isfile(script): script = "/det/lar/project/athena/BuildTagHierarchy.py"
287 import subprocess
288 cmdline = [script,
289 f"{args.outpdir}/{args.outsql}" if args.outsql[0]!="/" else args.outsql,
290 flags.IOVDb.GlobalTag]
291 print(cmdline)
292 try:
293 subprocess.run(cmdline, check=True)
294 except Exception as e:
295 print('Could not create tag hierarchy in output sqlite file !!!!')
296 sys.exit(-1)
297
void print(char *figname, TCanvas *c1)