ATLAS Offline Software
Loading...
Searching...
No Matches
RunTileCalibRec.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'''@file RunTileCalibRec.py
6@brief Script to run Tile Reconstrcution/Monitoring for calibration runs
7'''
8
9from TileRecEx import TileInputFiles
10from AthenaConfiguration.Enums import Format
11from TileConfiguration.TileConfigFlags import TileRunType
12from AthenaCommon.SystemOfUnits import MeV
13
14epiLog = """
15Examples:
16
17 RunTileCalibRec.py --run RUNNUMBER --evtMax 1 --pedestals --loglevel WARNING IOVDb.GlobalTag='CONDBR2-BLKPA-2018-13'
18 RunTileCalibRec.py --filesInput=FILE1,FILE2 Tile.RunType=TileRunType.LAS Tile.correctTime=True Exec.SkipEvents=100
19 RunTileCalibRec.py --run RUNNUMBER --cis --postExec='useTagFor("RUN2-HLT-UPD1-00", "/TILE/OFL02/TIME/CHANNELOFFSET/CIS");'
20 RunTileCalibRec.py --run RUNNUMBER --laser --postExec='useSqliteFor("tileSqlite.db", "/TILE");'
21
22 RunTileCalibRec.py --run RUNNUMBER @options.txt
23
24 where "options.txt" is text file which can contain all arguments and Athen configuration flags (one per line), e.g.:
25 --run2
26 --upd4
27 --laser
28 --loglevel=INFO
29 --postExec=useSqliteAndTagFor("tileSqlite.db", "RUN2-HLT-UPD1-00", "/TILE/OFL02/TIME/CHANNELOFFSET/LAS");
30 Tile.correctTime=True
31 Exec.SkipEvents=100
32
33At least one should provide the following arguments or Athena configuration flags (flags have higher priority):
34 Input file(s), e.g.: --run RUNNUMBER | --filesInput=FILE1,FILE2 | Input.Files="['FILE1','FILE2']"
35 Tile Run Type, e.g.: --cis | --laser | --pedestals | --physics | Tile.RunType=TileRunType.PHY
36"""
37
38
40 """ Function to return command line arguments parser for reconstuction of Tile calibration runs """
41
42 parserParents = [flags.getArgumentParser(), TileInputFiles.getArgumentParser(add_help=False)]
43
44 import argparse
45 parser= argparse.ArgumentParser(parents=parserParents, add_help=False, fromfile_prefix_chars='@', epilog=epiLog, formatter_class=argparse.RawTextHelpFormatter)
46
47 parser.add_argument('--preExec', help='Code to execute before locking configs')
48 parser.add_argument('--postExec', help='Code to execute after setup')
49 parser.add_argument('--printDetailedConfig', action='store_true', help='Print detailed Athena configuration')
50 parser.add_argument('--dumpArguments', action='store_true', help='Print arguments and exit')
51 parser.add_argument('--outputDirectory', default='.', help='Output directory for produced files')
52
53 parser.add_argument('--outputVersion', type=str, default='0', help='Version to be used in output files for ntuple and monitoring')
54
55 parser.add_argument('--calib', default=False, help='Calculate calibration constants and store them in ROOT file', action=argparse.BooleanOptionalAction)
56 parser.add_argument('--tmdb', default=None, help='Enable TMDB', action=argparse.BooleanOptionalAction)
57 parser.add_argument('--cells', help='Reconstruct Tile cells (default depends on if they are needed)', action=argparse.BooleanOptionalAction)
58 parser.add_argument('--clusters', default=False, help='Reconstruct Tile clusters', action=argparse.BooleanOptionalAction)
59 parser.add_argument('--towers', default=False, help='Reconstruct Tile towers', action=argparse.BooleanOptionalAction)
60 parser.add_argument('--muonfit', default=False, help='Reconstruct Tile MuonFit', action=argparse.BooleanOptionalAction)
61 parser.add_argument('--muid', default=False, help='Reconstruct Tile MuID', action=argparse.BooleanOptionalAction)
62 parser.add_argument('--pool', default=False, help='Create output POOL file', action=argparse.BooleanOptionalAction)
63 parser.add_argument('--jivexml', default=False, help='Create output Jive XML files for Atlantis', action=argparse.BooleanOptionalAction)
64 parser.add_argument('--d3pd', default=False, help='Create output D3PD file', action=argparse.BooleanOptionalAction)
65 parser.add_argument('--special-demo-shape', dest='special_demo_shape', type=int, default=None, help='Use special pulse shape for the Demonstrator')
66
67 # Set up Tile h2000 ntuple
68 ntuple = parser.add_argument_group('Tile h2000 ntuple')
69 ntuple.add_argument('--ntuple', default=True, help='Create Tile h2000 ntuple', action=argparse.BooleanOptionalAction)
70 ntuple.add_argument('--reduced-ntuple', dest='reduced_ntuple', action='store_true', help='No Tile raw cahnnel container (including DSP) in h2000 ntuple')
71 ntuple.add_argument('--use-dsp-units', dest='use_dsp_units', action='store_true', help='Use DSP units in h2000 ntuple')
72 ntuple.add_argument('--calibrate', default=None, help='Calibrate energy in h2000 ntuple', action=argparse.BooleanOptionalAction)
73 ntuple.add_argument('--offline-units', dest='offline_units', type=int, default=None, help='Units in h2000 ntuple (see TileRawChannelUnit)')
74
75 # Set up Tile monitoring
76 mon = parser.add_argument_group('Tile monitoring')
77 mon.add_argument('--mon', default=False, help='Run Tile monitoring', action=argparse.BooleanOptionalAction)
78 mon.add_argument('--postprocessing', default=True, help='Run Tile monitoring postprocessing', action=argparse.BooleanOptionalAction)
79 mon.add_argument('--digits-mon', dest='digits_mon', default=True, help='Run Tile digits monitoring', action=argparse.BooleanOptionalAction)
80 mon.add_argument('--channel-mon', dest='channel_mon', default=True, help='Run Tile raw channles monitoring', action=argparse.BooleanOptionalAction)
81 mon.add_argument('--channel-time-mon', dest='channel_time_mon', default=None, help='Run Tile raw channles time monitoring', action=argparse.BooleanOptionalAction)
82 mon.add_argument('--tmdb-mon', dest='tmdb_mon', default=True, help='Run TMDB monitoring', action=argparse.BooleanOptionalAction)
83 mon.add_argument('--tmdb-digits-mon', dest='tmdb_digits_mon', default=True, help='Run TMDB digits monitoring', action=argparse.BooleanOptionalAction)
84 mon.add_argument('--tmdb-channel-mon', dest='tmdb_channel_mon', default=True, help='Run TMDB raw channels monitoring', action=argparse.BooleanOptionalAction)
85 mon.add_argument('--digi-noise-mon', dest='digi_noise_mon', help='Run Tile digi noise monitoring (default: True for pedestals run)', action=argparse.BooleanOptionalAction)
86 mon.add_argument('--cell-mon', dest='cell_mon', help='Run Tile Cell monitoring (default: True for physics run)', action=argparse.BooleanOptionalAction)
87 mon.add_argument('--dq-mon', dest='dq_mon', default=True, help='Run Tile DQ monitoring for physics run', action=argparse.BooleanOptionalAction)
88
89 # Set up Tile run type
90 run_type_group = parser.add_argument_group('Tile Run Type')
91 run_type = run_type_group.add_mutually_exclusive_group()
92 run_type.add_argument('--cis', action='store_true', help='Tile CIS run type')
93 run_type.add_argument('--mono-cis', action='store_true', dest='mono_cis', help='Tile mono CIS run type')
94 run_type.add_argument('--gap-cis', action='store_true', dest='gap_cis', help='Tile gap CIS run type')
95 run_type.add_argument('--l1calo', action='store_true', help='Tile LVL1 Calo (CIS) run type')
96 run_type.add_argument('--laser', action='store_true', help='Tile laser run type')
97 run_type.add_argument('--gap-laser', action='store_true', dest='gap_laser', help='Tile gap laser run type')
98 run_type.add_argument('--pedestals', action='store_true', help='Tile pedestals run type')
99 run_type.add_argument('--physics', action='store_true', help='Tile physics run type')
100
101 # Set up Tile reconstuction method
102 method = parser.add_argument_group('Tile reconstuction method')
103 method.add_argument('--opt2', default=True, help='Use Tile Opt2 reconstuction method', action=argparse.BooleanOptionalAction)
104 method.add_argument('--opt-atlas', dest='opt_atlas', default=True, help='Use Tile OptATLAS reconstuction method', action=argparse.BooleanOptionalAction)
105 method.add_argument('--fit', default=True, help='Use Tile Fit reconstuction method', action=argparse.BooleanOptionalAction)
106 method.add_argument('--of1', default=False, help='Use Tile OF1 reconstuction method', action=argparse.BooleanOptionalAction)
107 method.add_argument('--mf', default=False, help='Use Tile MF reconstuction method', action=argparse.BooleanOptionalAction)
108
109 run_period_group = parser.add_argument_group('LHC Run period')
110 run_period = run_period_group.add_mutually_exclusive_group()
111 run_period.add_argument('--run2', action='store_true', help='LHC Run2 period')
112 run_period.add_argument('--run3', action='store_true', help='LHC Run3 period')
113
114 parser.add_argument('--upd4', action='store_true', help='Use UPD4 conditions')
115
116 return parser
117
118
119def useTagFor(tag, folder):
120 ''' Function to override tag for DB folder (it should be used in --postExec) '''
121 fullTag = f'{folder.title().replace("/","")}-{tag}' if folder.startswith('/TILE') and not tag.startswith('Tile') else tag
122 from AthenaCommon.Logging import log
123 log.info(f'Use tag {fullTag} for folder: {folder}')
124 cfg.getService('IOVDbSvc').overrideTags += [f'<prefix>{folder}</prefix> <tag>{fullTag}</tag>']
125
126def useSqliteFor(sqliteFile, folder):
127 ''' Function to use Sqlite file for DB folder (it should be used in --postExec) '''
128 iovDbSvc = cfg.getService('IOVDbSvc')
129 from AthenaCommon.Logging import log
130 log.info(f'Use Sqlite file {sqliteFile} for folder: {folder}')
131 iovDbSvc.overrideTags += [f'<prefix>{folder}</prefix> <db>sqlite://;schema={sqliteFile};dbname={iovDbSvc.DBInstance}</db>']
132
133def useSqliteAndTagFor(sqliteFile, tag, folder):
134 ''' Function to use tag from Sqlite file for DB folder (it should be used in --postExec) '''
135 useSqliteFor(sqliteFile, folder)
136 useTagFor(tag, folder)
137
138if __name__=='__main__':
139 import sys,os
140
141 from AthenaConfiguration.AllConfigFlags import initConfigFlags
142 flags = initConfigFlags()
143
144 # Setup logs
145 from AthenaCommon.Logging import log
146 from AthenaCommon import Constants
147 log.setLevel(Constants.INFO)
148
149 parser = getArgumentParser(flags)
150 args, _ = parser.parse_known_args()
151
152 # Initially the following flags are not set up (they must be provided)
153 flags.Input.Files = []
154 flags.Tile.RunType = TileRunType.UNDEFINED
155 flags.LAr.doHVCorr = False
156
157 # Initial configuration flags from command line arguments (to be used to set up defaults)
158 flags.fillFromArgs(parser=parser)
159
160 # =======>>> Set up the Athena configuration flags to defaults (can be overriden via comand line)
161
162 # Set up the Tile input files
163 if not flags.Input.Files and args.run:
164 flags.Input.Files = TileInputFiles.findFilesFromAgruments(args)
165 if not flags.Input.Files:
166 log.error('Input files must be provided! For example: --filesInput=file1,file2,... or --run RUNNUMBER')
167 sys.exit(-1)
168
169 # Set up the Tile run type using arguments if it was not set up via configuration flags
170 if flags.Tile.RunType is TileRunType.UNDEFINED:
171 if args.cis:
172 flags.Tile.RunType = TileRunType.CIS
173 elif args.mono_cis:
174 flags.Tile.RunType = TileRunType.MONOCIS
175 elif args.gap_cis:
176 flags.Tile.RunType = TileRunType.GAPCIS
177 elif args.l1calo:
178 flags.Tile.RunType = TileRunType.L1CALO
179 elif args.laser:
180 flags.Tile.RunType = TileRunType.LAS
181 elif args.gap_laser:
182 flags.Tile.RunType = TileRunType.GAPLAS
183 elif args.pedestals:
184 flags.Tile.RunType = TileRunType.PED
185 elif args.physics:
186 flags.Tile.RunType = TileRunType.PHY
187 else:
188 log.error('The Tile Run Type must be provided! For example: --laser or --cis, ..., or Tile.RunType=TileRunType.PED')
189 sys.exit(-1)
190
191 if flags.Tile.RunType in [TileRunType.PED, TileRunType.LAS, TileRunType.BILAS, TileRunType.MONOCIS]:
192 flags.Exec.SkipEvents = 1
193 elif flags.Tile.RunType is TileRunType.CIS:
194 flags.Exec.SkipEvents = 192 # skip all events when just one channel is fired (4*48)
195 elif flags.Tile.RunType is TileRunType.L1CALO:
196 flags.Exec.SkipEvents = 3
197
198 # Set up Tile reconstuction method
199 flags.Tile.doOpt2 = args.opt2
200 flags.Tile.doOptATLAS = args.opt_atlas
201 flags.Tile.doFit = args.fit
202 flags.Tile.doOF1 = args.of1
203 flags.Tile.doMF = args.mf
204
205 flags.Tile.BestPhaseFromCOOL = True
206 flags.Tile.NoiseFilter = 0 # disable noise filter by default
207 flags.Tile.doOverflowFit = False
208 flags.Tile.correctAmplitude = False
209 flags.Tile.correctTime = flags.Tile.RunType in [TileRunType.PHY, TileRunType.GAPLAS, TileRunType.GAPCIS]
210 flags.Tile.OfcFromCOOL = flags.Tile.RunType in [TileRunType.PHY, TileRunType.PED]
211
212 runNumber = flags.Input.RunNumbers[0]
213
214 # Set up LHC Run period
215 if not any([args.run2, args.run3]):
216 if not flags.Input.isMC:
217 if runNumber >= 411938:
218 args.run3 = True
219 elif any([args.year and args.year > 2014, runNumber > 232000, flags.Input.ProjectName.startswith("data15_")]):
220 args.run2 = True
221
222 # Set up the DB global conditions tag
223 if flags.Input.Format is Format.BS:
224 if args.run3:
225 condDbTag = 'CONDBR2-BLKPA-2025-03' if args.upd4 else 'CONDBR2-ES1PA-2025-02'
226 detDescrVersion = 'ATLAS-R3S-2021-03-01-00'
227 elif args.run2:
228 condDbTag = 'CONDBR2-BLKPA-2018-16' if args.upd4 else 'CONDBR2-ES1PA-2018-05'
229 detDescrVersion = 'ATLAS-R2-2016-01-00-01'
230 else:
231 condDbTag = 'COMCOND-BLKPA-RUN1-06' if (args.upd4 and runNumber > 141066) else 'COMCOND-ES1PA-006-05'
232 detDescrVersion = 'ATLAS-R1-2012-03-02-00'
233
234 flags.IOVDb.GlobalTag = condDbTag
235 flags.GeoModel.AtlasVersion = detDescrVersion
236
237 if args.mon:
238 flags.DQ.useTrigger = False
239 flags.DQ.enableLumiAccess = False
240 if not flags.Output.HISTFileName:
241 flags.Output.HISTFileName = f'{args.outputDirectory}/tilemon_{runNumber}_{args.outputVersion}.root'
242
243 if args.tmdb is None:
244 args.tmdb = not flags.Input.isMC
245
246 if args.channel_time_mon is None:
247 args.channel_time_mon = flags.Tile.RunType in [TileRunType.GAPLAS, TileRunType.GAPCIS] and (args.run2 or args.run3) and flags.Tile.doFit
248
249 if args.pool:
250 flags.Output.ESDFileName = f'tile_{runNumber}_{args.outputVersion}.pool.root'
251
252 if args.jivexml:
253 flags.Output.doJiveXML = True
254
255 # Override default configuration flags from command line arguments
256 flags.fillFromArgs(parser=parser)
257
258 if args.dumpArguments:
259 log.info('=====>>> FINAL ARGUMENTS FOLLOW:')
260 print('{:40} : {}'.format('Argument Name', 'Value'))
261 for a,v in (vars(args)).items():
262 print(f'{a:40} : {v}')
263 sys.exit(0)
264
265 flags.needFlagsCategory('Tile')
266
267 if args.preExec:
268 log.info('Executing preExec: %s', args.preExec)
269 exec(args.preExec)
270
271 flags.lock()
272
273 log.info('=====>>> FINAL CONFIG FLAGS SETTINGS FOLLOW:')
274 flags.dump(pattern='Tile.*|Input.*|Exec.*|IOVDb.[D|G].*', evaluate=True)
275
276 biGainRun = flags.Tile.RunType.isBiGain()
277
278 # =======>>> Set up default arguments
279 cellsAvailable = (flags.Input.Format is Format.POOL and 'AllCalo' in flags.Input.Collections)
280 if args.cells is None:
281 args.cells = not cellsAvailable and (args.towers or args.clusters or args.muid or args.muonfit
282 or args.jivexml or args.d3pd or args.pool
283 or flags.Tile.RunType is TileRunType.PHY)
284 cellsAvailable = cellsAvailable or args.cells
285
286 if args.cell_mon is None:
287 args.cell_mon = cellsAvailable and flags.Tile.RunType is TileRunType.PHY
288
289 if args.digi_noise_mon is None:
290 args.digi_noise_mon = flags.Tile.RunType is TileRunType.PED
291
292 # Initialize configuration object, add accumulator, merge, and run.
293 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
294 cfg = MainServicesCfg(flags)
295
296 # =======>>> Set up the File (BS | POOL) reading
297 if flags.Input.Format is Format.BS:
298 # Configure reading the Tile BS files
299 from TileByteStream.TileByteStreamConfig import TileRawDataReadingCfg
300 cfg.merge( TileRawDataReadingCfg(flags, readMuRcv=args.ntuple,
301 readMuRcvDigits=any([args.tmdb_digits_mon, args.tmdb_mon, args.ntuple]),
302 readMuRcvRawCh=any([args.tmdb_channel_mon, args.tmdb_mon, args.ntuple])) )
303
304 else:
305 # Configure reading POOL files
306 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
307 cfg.merge(PoolReadCfg(flags))
308
309 # =======>>> Set up the Tile raw channel maker only if readDigits is set
310 if flags.Tile.readDigits:
311 from TileRecUtils.TileRawChannelMakerConfig import TileRawChannelMakerCfg
312 cfg.merge( TileRawChannelMakerCfg(flags) )
313 rawChMaker = cfg.getEventAlgo('TileRChMaker')
314 if args.threads and (args.threads > 1):
315 rawChMaker.Cardinality = args.threads
316 for builderTool in rawChMaker.TileRawChannelBuilder:
317 builderTool.UseDSPCorrection = not biGainRun
318
319 # =======>>> Set up the Tile cell maker
320 if args.cells:
321 rawChannelContainer = flags.Tile.RawChannelContainer
322 if flags.Tile.doOptATLAS and any([flags.Tile.doFit, flags.Tile.doOpt2]):
323 rawChannelContainer = 'TileRawChannelOpt2' if flags.Tile.doOpt2 else 'TileRawChannelFit'
324 from TileRecUtils.TileCellMakerConfig import TileCellMakerCfg
325 mergeChannels = flags.Tile.RunType is TileRunType.PHY
326 if biGainRun:
327 cfg.merge( TileCellMakerCfg(flags, SkipGain=0, mergeChannels=False) )
328 cfg.merge( TileCellMakerCfg(flags, SkipGain=1, mergeChannels=False) )
329 cfg.getEventAlgo("TileCellMakerHG").CaloCellMakerToolNames["TileCellBuilder"].TileRawChannelContainer = rawChannelContainer
330 cfg.getEventAlgo("TileCellMakerLG").CaloCellMakerToolNames["TileCellBuilder"].TileRawChannelContainer = rawChannelContainer
331 else:
332 cfg.merge( TileCellMakerCfg(flags, mergeChannels=mergeChannels) )
333 cfg.getEventAlgo("TileCellMaker").CaloCellMakerToolNames["TileCellBuilder"].TileRawChannelContainer = rawChannelContainer
334
335 # =======>>> Set up the Tile clusters maker
336 if args.clusters:
337 from TileMonitoring.TileTopoClusterConfig import TileTopoClusterCfg
338 cfg.merge( TileTopoClusterCfg(flags) )
339
340 # =======>>> Set up the Tile muon fitter
341 if args.muonfit:
342 from TileCosmicAlgs.TileMuonFitterConfig import TileMuonFitterCfg
343 cfg.merge( TileMuonFitterCfg(flags) )
344
345 # =======>>> Set up the Tile muon ID reconstuction
346 if args.muid:
347 from TileMuId.TileMuIdConfig import TileLookForMuAlgCfg
348 cfg.merge( TileLookForMuAlgCfg(flags) )
349
350 # =======>>> Set up the Tile raw channel to hit algorithm
351 if flags.Output.doWriteESD:
352 from TileRecAlgs.TileRawChannelToHitConfig import TileRawChannelToHitCfg
353 cfg.merge( TileRawChannelToHitCfg(flags) )
354
355 # =======>>> Set up the Tile Ntuple
356 if args.ntuple:
357 ntupleFile = f'{args.outputDirectory}/tile_{runNumber}_{args.outputVersion}.aan.root'
358 from TileRec.TileAANtupleConfig import TileAANtupleCfg
359 cfg.merge( TileAANtupleCfg(flags, outputFile=ntupleFile, UseDspUnits=args.use_dsp_units) )
360 tileNtuple = cfg.getEventAlgo('TileNtuple')
361 # CompressionSettings: algorithm * 100 + level
362 tileNtuple.CompressionSettings = 204
363 tileNtuple.SkipEvents = 4 if flags.Tile.RunType is TileRunType.LAS else 0
364 tileNtuple.TileRawChannelContainerOpt = "TileRawChannelOpt2" if flags.Tile.doOpt2 else ""
365 tileNtuple.TileRawChannelContainerDsp = "" if biGainRun else "TileRawChannelCnt"
366 if args.reduced_ntuple:
367 tileNtuple.Reduced = True
368 tileNtuple.TileRawChannelContainer = ""
369 if args.offline_units:
370 tileNtuple.OfflineUnits = args.offline_units
371 tileNtuple.CalibrateEnergy = True
372 elif args.calibrate is not None:
373 tileNtuple.CalibrateEnergy = args.calibrate
374 if flags.Tile.RunType in [TileRunType.GAPLAS, TileRunType.GAPCIS]:
375 tileNtuple.TileDigitsContainerFlt = "TileDigitsCnt"
376 tileNtuple.TileDigitsContainer = "" # do not save various error bits
377
378 # =======>>> Set up the Tile monitoring
379 if args.mon:
380
382 for tool in alg.GMTools:
383 tool.Histograms = [h.replace('OFFLINE','ONLINE') for h in tool.Histograms]
384
385 if args.digits_mon:
386 from TileMonitoring.TileDigitsMonitorAlgorithm import TileDigitsMonitoringConfig
387 cfg.merge(TileDigitsMonitoringConfig(flags))
388 setOnlineEnvironment(cfg.getEventAlgo('TileDigitsMonAlg'))
389
390 if args.channel_mon:
391 from TileMonitoring.TileRawChannelMonitorAlgorithm import TileRawChannelMonitoringConfig
392 cfg.merge(TileRawChannelMonitoringConfig(flags))
393 setOnlineEnvironment(cfg.getEventAlgo('TileRawChannelMonAlg'))
394
395 if args.channel_time_mon:
396 from TileMonitoring.TileRawChannelTimeMonitorAlgorithm import TileRawChannelTimeMonitoringConfig
397 cfg.merge(TileRawChannelTimeMonitoringConfig(flags))
398 setOnlineEnvironment(cfg.getEventAlgo('TileRawChanTimeMonAlg'))
399
400 if args.tmdb_digits_mon:
401 from TileMonitoring.TileTMDBDigitsMonitorAlgorithm import TileTMDBDigitsMonitoringConfig
402 cfg.merge(TileTMDBDigitsMonitoringConfig(flags))
403 setOnlineEnvironment(cfg.getEventAlgo('TileTMDBDigitsMonAlg'))
404
405 if args.tmdb_channel_mon:
406 from TileMonitoring.TileTMDBRawChannelMonitorAlgorithm import TileTMDBRawChannelMonitoringConfig
407 cfg.merge(TileTMDBRawChannelMonitoringConfig(flags))
408 setOnlineEnvironment(cfg.getEventAlgo('TileTMDBRawChanDspMonAlg'))
409
410 if args.tmdb_mon:
411 from TileMonitoring.TileTMDBMonitorAlgorithm import TileTMDBMonitoringConfig
412 cfg.merge(TileTMDBMonitoringConfig(flags))
413 setOnlineEnvironment(cfg.getEventAlgo('TileTMDBMonAlg'))
414
415 if args.dq_mon and flags.Tile.RunType is TileRunType.PHY and flags.Tile.readDigits:
416 from TileMonitoring.TileDQFragMonitorAlgorithm import TileDQFragMonitoringConfig
417 cfg.merge(TileDQFragMonitoringConfig(flags))
418 setOnlineEnvironment(cfg.getEventAlgo('TileDQFragMonAlg'))
419
420 if args.cell_mon:
421 from TileMonitoring.TileCellMonitorAlgorithm import TileCellMonitoringConfig
422 if biGainRun:
423 cfg.merge(TileCellMonitoringConfig(flags, CaloCellContainer='AllCaloHG'))
424 else:
425 cfg.merge(TileCellMonitoringConfig(flags, fillTimeHistograms=True,
426 EnergyThresholdForTime=150.0*MeV))
427 setOnlineEnvironment(cfg.getEventAlgo('TileCellMonAlg'))
428
429 if args.digi_noise_mon:
430 from TileMonitoring.TileDigiNoiseMonitorAlgorithm import TileDigiNoiseMonitoringConfig
431 triggerTypes = [0x82] if flags.Tile.RunType is TileRunType.PHY else []
432 cfg.merge(TileDigiNoiseMonitoringConfig(flags, TriggerTypes=triggerTypes))
433 setOnlineEnvironment(cfg.getEventAlgo('TileDigiNoiseMonAlg'))
434
435 if any([args.tmdb_digits_mon, args.tmdb_mon, args.channel_mon, args.digits_mon]) and args.postprocessing:
436 from AthenaCommon.Utils.unixtools import find_datafile
437 configurations = []
438 dataPath = find_datafile('TileMonitoring')
439 if any([args.tmdb_digits_mon, args.tmdb_mon]):
440 configurations += [os.path.join(dataPath, 'TileTMDBPostProc.yaml')]
441 if args.digits_mon:
442 configurations += [os.path.join(dataPath, 'TileDigitsPostProc.yaml')]
443 if args.channel_mon:
444 if flags.Tile.RunType in [TileRunType.CIS]:
445 configurations += [os.path.join(dataPath, 'TileRawChanCisPostProc.yaml')]
446 else:
447 configurations += [os.path.join(dataPath, 'TileRawChanPostProc.yaml')]
448 if flags.Tile.RunType is TileRunType.LAS:
449 configurations += [os.path.join(dataPath, 'TileRawChanLasPostProc.yaml')]
450 if not biGainRun:
451 configurations += [os.path.join(dataPath, 'TileRawChanDspPostProc.yaml')]
452
453 from DataQualityUtils.DQPostProcessingAlg import DQPostProcessingAlg
454 class TileMonPostProcessingAlg(DQPostProcessingAlg):
455 def initialize(self):
456 if hasattr(self, 'OutputLevel'):
457 self.msg.setLevel(self.OutputLevel)
458 return super(TileMonPostProcessingAlg, self).initialize()
459
460 ppa = TileMonPostProcessingAlg("TileMonPostProcessingAlg")
461 ppa.OutputLevel = flags.Exec.OutputLevel
462 ppa.ExtraInputs = {( 'xAOD::EventInfo' , 'StoreGateSvc+EventInfo' )}
463 ppa.Interval = 1000000 # Big number (>evtMax) to do postprocessing during finalization
464 ppa.ConfigFiles = configurations
465 ppa._ctr = 1 # Start postprocessing only after specified number of events (not during the first one)
466 ppa.FileKey = f'/{flags.DQ.FileKey}/'
467
468 cfg.addEventAlgo(ppa, sequenceName='AthEndSeq')
469
470
471 # =======>>> Set up the Tile calibration
472 if args.calib:
473 if flags.Tile.RunType is TileRunType.LAS:
474 laserCalibFile = f'tileCalibLAS_{runNumber}_{args.outputVersion}.root'
475 from TileCalibAlgs.TileLaserCalibAlgConfig import TileLaserCalibAlgCfg
476 cfg.merge( TileLaserCalibAlgCfg(flags, FileName=laserCalibFile) )
477
478 elif flags.Tile.RunType is TileRunType.L1CALO:
479 from TrigT1CaloByteStream.LVL1CaloRun2ByteStreamConfig import LVL1CaloRun2ReadBSCfg
480 cfg.merge( LVL1CaloRun2ReadBSCfg(flags))
481
482 l1caloCalibFile = f'tileCalibL1Calo_{runNumber}_{args.outputVersion}.root'
483 from TileCalibAlgs.TileTriggerCalibAlgConfig import TileTriggerCalibAlgCfg
484 cfg.merge( TileTriggerCalibAlgCfg(flags, FileName=l1caloCalibFile) )
485
486 elif flags.Tile.RunType is TileRunType.CIS:
487 cisCalibFile = f'tileCalibCIS_{runNumber}_{args.outputVersion}.root'
488 from TileCalibAlgs.TileCisCalibAlgConfig import TileCisCalibAlgCfg
489 cfg.merge( TileCisCalibAlgCfg(flags, FileName=cisCalibFile) )
490
491 elif flags.Tile.RunType in [TileRunType.PHY, TileRunType.PED]:
492 defaultVersions = ['0', 'Ped.0', 'Ped']
493
494 fileVersion = f'_{flags.Tile.NoiseFilter}' if flags.Tile.NoiseFilter > 0 else ""
495 if args.outputVersion not in defaultVersions:
496 fileVersion = f'_{args.outputVersion}_tnf{flags.Tile.NoiseFilter}'
497
498 from TileCalibAlgs.TileRawChNoiseCalibAlgConfig import TileRawChNoiseCalibAlgCfg
499 cfg.merge( TileRawChNoiseCalibAlgCfg(flags) )
500 rawChanNoiseCalibAlg = cfg.getEventAlgo('TileRawChNoiseCalibAlg')
501 rawChanNoiseCalibAlg.FileNamePrefix = f'{args.outputDirectory}/RawCh_NoiseCalib{fileVersion}'
502 if flags.Input.isMC:
503 rawChanNoiseCalibAlg.doFit = False
504 rawChanNoiseCalibAlg.doFixed = False
505 rawChanNoiseCalibAlg.doOpt = False
506 rawChanNoiseCalibAlg.doDsp = True
507 rawChanNoiseCalibAlg.UseforCells = 3 # i.e. from TileRawChannelCnt (like DSP)
508 else:
509 rawChanNoiseCalibAlg.doDsp = (flags.Tile.RunType is TileRunType.PHY)
510 rawChanNoiseCalibAlg.UseforCells = 1 # 1= Fixed , 2= Opt2
511
512 # Produce digi noise ntuple only for default version
513 if args.outputVersion in defaultVersions:
514 from TileCalibAlgs.TileDigiNoiseCalibAlgConfig import TileDigiNoiseCalibAlgCfg
515 cfg.merge( TileDigiNoiseCalibAlgCfg(flags) )
516 digiNoiseCalibAlg = cfg.getEventAlgo('TileDigiNoiseCalibAlg')
517 digiNoiseCalibAlg.DoAvgCorr = False # False=> Full AutoCorr matrix calculation
518 digiNoiseCalibAlg.FileNamePrefix = f'{args.outputDirectory}/Digi_NoiseCalib{fileVersion}'
519
520
521 # =======>>> Set up the Tile output Jive XML files
522 if flags.Output.doJiveXML:
523 from TileMonitoring.TileJiveXMLConfig import TileAlgoJiveXMLCfg
524 cfg.merge(TileAlgoJiveXMLCfg(flags))
525
526
527 # =======>>> Set up the Tile output D3PD file
528 if args.d3pd:
529 d3pdFile = f'{args.outputDirectory}/tile_{runNumber}_{args.outputVersion}.aan.root'
530 from D3PDMakerConfig.D3PDMakerFlags import D3PDMakerFlags
531 D3PDMakerFlags.DoTruth = flags.Input.isMC
532 from TileRecEx.TileD3PDConfig import TileD3PDCfg
533 cfg.merge( TileD3PDCfg(flags,
534 outputFile=d3pdFile,
535 saveCells=cellsAvailable,
536 saveMBTS=cellsAvailable,
537 saveE4pr=args.run2,
538 saveMuId=args.muid,
539 saveMuonFitter=args.muonfit,
540 saveClusters=args.clusters,
541 saveEventInfo=(flags.Tile.RunType is TileRunType.PHY)) )
542
543 # =======>>> Set up the Tile output POOL file
544 if flags.Output.doWriteESD:
545 outputItemList = ["TileHitVector#*"]
546 outputItemList += ["TileDigitsContainer#*"]
547 outputItemList += ["TileBeamElemContainer#*"]
548 outputItemList += ["TileRawChannelContainer#*"]
549 outputItemList += ["TileCellContainer#*"]
550 outputItemList += ["CaloCellContainer#*"]
551 outputItemList += [ "TileMuContainer#*" ]
552 outputItemList += [ "TileL2Container#*" ]
553 outputItemList += [ "TileCosmicMuonContainer#*" ]
554
555 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
556 cfg.merge( OutputStreamCfg(flags, streamName='ESD', ItemList=outputItemList) )
557
558 if args.run3:
559 if args.special_demo_shape and args.special_demo_shape > 0 and args.special_demo_shape <= 10:
560 tileInfoLoader = cfg.getService('TileInfoLoader')
561 if flags.RunType.getCommonType() is TileRunType.LAS:
562 # Disable special treatment for demo in laser runs for the moment
563 args.special_demo_shape = -1
564 elif flags.RunType.getCommonType() is TileRunType.CIS:
565 # Put CIS pulse shape for Demo in laser and physics structures
566 args.special_demo_shape = 3
567 tileInfoLoader.filename_lo_las = "pulselo_cis_demo_100.dat"
568 tileInfoLoader.filename_hi_las = "pulsehi_cis_demo_100.dat"
569 tileInfoLoader.filename_lo_las_der = "dpulselo_cis_demo_100.dat"
570 tileInfoLoader.filename_hi_las_der = "dpulsehi_cis_demo_100.dat"
571 tileInfoLoader.filename_lo_phys = "pulselo_cis_demo_5p2.dat"
572 tileInfoLoader.filename_hi_phys = "pulsehi_cis_demo_5p2.dat"
573 tileInfoLoader.filename_lo_phys_der = "dpulselo_cis_demo_5p2.dat"
574 tileInfoLoader.filename_hi_phys_der = "dpulsehi_cis_demo_5p2.dat"
575 else:
576 # Put physics pulse shape for Demo in laser structures
577 args.special_demo_shape = 2
578 tileInfoLoader.filename_lo_las = "pulselo_phys_demo.dat"
579 tileInfoLoader.filename_hi_las = "pulsehi_phys_demo.dat"
580 tileInfoLoader.filename_lo_las_der = "dpulselo_phys_demo.dat"
581 tileInfoLoader.filename_hi_las_der = "dpulsehi_phys_demo.dat"
582 else:
583 # Disable only leakage pulse in CIS/MonoCIS, but use the same pulse shape
584 if not args.special_demo_shape:
585 args.special_demo_shape = 9
586
587 if args.special_demo_shape:
588 if flags.Tile.doFit:
589 fitFilter = cfg.getEventAlgo('TileRChMaker').TileRawChannelBuilder['TileRawChannelBuilderFitFilter']
590 fitFilter.SpecialDemoShape = args.special_demo_shape
591
592 if flags.Input.Format is Format.BS:
593 cfg.getCondAlgo("TileHid2RESrcIDCondAlg").RODStatusProxy = None
594
595 # =======>>> Any last things to do?
596 if args.postExec:
597 log.info('Executing postExec: %s', args.postExec)
598 exec(args.postExec)
599
600 cfg.printConfig(withDetails=args.printDetailedConfig,
601 summariseProps=args.printDetailedConfig,
602 printDefaults=args.printDetailedConfig)
603
604 if args.config_only:
605 cfg.store(open('RunTileCalibRec.pkl', 'wb'))
606 else:
607 sc = cfg.run()
608 # Success should be 0
609 sys.exit(0 if sc.isSuccess() else 1)
void print(char *figname, TCanvas *c1)
useSqliteAndTagFor(sqliteFile, tag, folder)
useTagFor(tag, folder)
useSqliteFor(sqliteFile, folder)
getArgumentParser(**kwargs)
findFilesFromAgruments(args)
void initialize()