5 '''@file RunTileCalibRec.py
6 @brief Script to run Tile Reconstrcution/Monitoring for calibration runs
9 from TileRecEx
import TileInputFiles
10 from AthenaConfiguration.Enums
import Format
11 from TileConfiguration.TileConfigFlags
import TileRunType
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");'
22 RunTileCalibRec.py --run RUNNUMBER @options.txt
24 where "options.txt" is text file which can contain all arguments and Athen configuration flags (one per line), e.g.:
29 --postExec=useSqliteAndTagFor("tileSqlite.db", "RUN2-HLT-UPD1-00", "/TILE/OFL02/TIME/CHANNELOFFSET/LAS");
33 At 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
40 """ Function to return command line arguments parser for reconstuction of Tile calibration runs """
45 parser= argparse.ArgumentParser(parents=parserParents, add_help=
False, fromfile_prefix_chars=
'@', epilog=epiLog, formatter_class=argparse.RawTextHelpFormatter)
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')
53 parser.add_argument(
'--outputVersion', type=str, default=
'0', help=
'Version to be used in output files for ntuple and monitoring')
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)
67 ntuple = parser.add_argument_group(
'Tile h2000 ntuple')
68 ntuple.add_argument(
'--ntuple', default=
True, help=
'Create Tile h2000 ntuple', action=argparse.BooleanOptionalAction)
69 ntuple.add_argument(
'--reduced-ntuple', dest=
'reduced_ntuple', action=
'store_true', help=
'No Tile raw cahnnel container (including DSP) in h2000 ntuple')
72 mon = parser.add_argument_group(
'Tile monitoring')
73 mon.add_argument(
'--mon', default=
False, help=
'Run Tile monitoring', action=argparse.BooleanOptionalAction)
74 mon.add_argument(
'--postprocessing', default=
True, help=
'Run Tile monitoring postprocessing', action=argparse.BooleanOptionalAction)
75 mon.add_argument(
'--digits-mon', dest=
'digits_mon', default=
True, help=
'Run Tile digits monitoring', action=argparse.BooleanOptionalAction)
76 mon.add_argument(
'--channel-mon', dest=
'channel_mon', default=
True, help=
'Run Tile raw channles monitoring', action=argparse.BooleanOptionalAction)
77 mon.add_argument(
'--channel-time-mon', dest=
'channel_time_mon', default=
None, help=
'Run Tile raw channles time monitoring', action=argparse.BooleanOptionalAction)
78 mon.add_argument(
'--tmdb-mon', dest=
'tmdb_mon', default=
True, help=
'Run TMDB monitoring', action=argparse.BooleanOptionalAction)
79 mon.add_argument(
'--tmdb-digits-mon', dest=
'tmdb_digits_mon', default=
True, help=
'Run TMDB digits monitoring', action=argparse.BooleanOptionalAction)
80 mon.add_argument(
'--tmdb-channel-mon', dest=
'tmdb_channel_mon', default=
True, help=
'Run TMDB raw channels monitoring', action=argparse.BooleanOptionalAction)
81 mon.add_argument(
'--digi-noise-mon', dest=
'digi_noise_mon', help=
'Run Tile digi noise monitoring (default: True for pedestals run)', action=argparse.BooleanOptionalAction)
82 mon.add_argument(
'--cell-mon', dest=
'cell_mon', help=
'Run Tile Cell monitoring (default: True for physics run)', action=argparse.BooleanOptionalAction)
83 mon.add_argument(
'--dq-mon', dest=
'dq_mon', default=
True, help=
'Run Tile DQ monitoring for physics run', action=argparse.BooleanOptionalAction)
86 run_type_group = parser.add_argument_group(
'Tile Run Type')
87 run_type = run_type_group.add_mutually_exclusive_group()
88 run_type.add_argument(
'--cis', action=
'store_true', help=
'Tile CIS run type')
89 run_type.add_argument(
'--mono-cis', action=
'store_true', dest=
'mono_cis', help=
'Tile mono CIS run type')
90 run_type.add_argument(
'--gap-cis', action=
'store_true', dest=
'gap_cis', help=
'Tile gap CIS run type')
91 run_type.add_argument(
'--laser', action=
'store_true', help=
'Tile laser run type')
92 run_type.add_argument(
'--gap-laser', action=
'store_true', dest=
'gap_laser', help=
'Tile gap laser run type')
93 run_type.add_argument(
'--pedestals', action=
'store_true', help=
'Tile pedestals run type')
94 run_type.add_argument(
'--physics', action=
'store_true', help=
'Tile physics run type')
97 method = parser.add_argument_group(
'Tile reconstuction method')
98 method.add_argument(
'--opt2', default=
True, help=
'Use Tile Opt2 reconstuction method', action=argparse.BooleanOptionalAction)
99 method.add_argument(
'--opt-atlas', dest=
'opt_atlas', default=
True, help=
'Use Tile OptATLAS reconstuction method', action=argparse.BooleanOptionalAction)
100 method.add_argument(
'--fit', default=
True, help=
'Use Tile Fit reconstuction method', action=argparse.BooleanOptionalAction)
101 method.add_argument(
'--of1', default=
False, help=
'Use Tile OF1 reconstuction method', action=argparse.BooleanOptionalAction)
102 method.add_argument(
'--mf', default=
False, help=
'Use Tile MF reconstuction method', action=argparse.BooleanOptionalAction)
104 run_period_group = parser.add_argument_group(
'LHC Run period')
105 run_period = run_period_group.add_mutually_exclusive_group()
106 run_period.add_argument(
'--run2', action=
'store_true', help=
'LHC Run2 period')
107 run_period.add_argument(
'--run3', action=
'store_true', help=
'LHC Run3 period')
109 parser.add_argument(
'--upd4', action=
'store_true', help=
'Use UPD4 conditions')
115 ''' Function to override tag for DB folder (it should be used in --postExec) '''
116 fullTag = f
'{folder.title().replace("/","")}-{tag}' if folder.startswith(
'/TILE')
and not tag.startswith(
'Tile')
else tag
117 from AthenaCommon.Logging
import log
118 log.info(f
'Use tag {fullTag} for folder: {folder}')
119 cfg.getService(
'IOVDbSvc').overrideTags += [f
'<prefix>{folder}</prefix> <tag>{fullTag}</tag>']
122 ''' Function to use Sqlite file for DB folder (it should be used in --postExec) '''
123 iovDbSvc = cfg.getService(
'IOVDbSvc')
124 from AthenaCommon.Logging
import log
125 log.info(f
'Use Sqlite file {sqliteFile} for folder: {folder}')
126 iovDbSvc.overrideTags += [f
'<prefix>{folder}</prefix> <db>sqlite://;schema={sqliteFile};dbname={iovDbSvc.DBInstance}</db>']
129 ''' Function to use tag from Sqlite file for DB folder (it should be used in --postExec) '''
133 if __name__==
'__main__':
136 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
140 from AthenaCommon.Logging
import log
141 from AthenaCommon
import Constants
142 log.setLevel(Constants.INFO)
145 args, _ = parser.parse_known_args()
148 flags.Input.Files = []
149 flags.Tile.RunType = TileRunType.UNDEFINED
152 flags.fillFromArgs(parser=parser)
157 if not flags.Input.Files
and args.run:
159 if not flags.Input.Files:
160 log.error(
'Input files must be provided! For example: --filesInput=file1,file2,... or --run RUNNUMBER')
164 if flags.Tile.RunType
is TileRunType.UNDEFINED:
166 flags.Tile.RunType = TileRunType.CIS
168 flags.Tile.RunType = TileRunType.MONOCIS
170 flags.Tile.RunType = TileRunType.GAPCIS
172 flags.Tile.RunType = TileRunType.LAS
174 flags.Tile.RunType = TileRunType.GAPLAS
176 flags.Tile.RunType = TileRunType.PED
178 flags.Tile.RunType = TileRunType.PHY
180 log.error(
'The Tile Run Type must be provided! For example: --laser or --cis, ..., or Tile.RunType=TileRunType.PED')
183 if flags.Tile.RunType
not in [TileRunType.PHY, TileRunType.CIS]:
184 flags.Exec.SkipEvents = 1
185 elif flags.Tile.RunType
is TileRunType.CIS:
186 flags.Exec.SkipEvents = 192
189 flags.Tile.doOpt2 = args.opt2
190 flags.Tile.doOptATLAS = args.opt_atlas
191 flags.Tile.doFit = args.fit
192 flags.Tile.doOF1 = args.of1
193 flags.Tile.doMF = args.mf
195 flags.Tile.BestPhaseFromCOOL =
True
196 flags.Tile.NoiseFilter = 0
197 flags.Tile.doOverflowFit =
False
198 flags.Tile.correctAmplitude =
False
199 flags.Tile.correctTime = flags.Tile.RunType
in [TileRunType.PHY, TileRunType.GAPLAS, TileRunType.GAPCIS]
200 flags.Tile.OfcFromCOOL = flags.Tile.RunType
in [TileRunType.PHY, TileRunType.PED]
202 runNumber = flags.Input.RunNumbers[0]
205 if not any([args.run2, args.run3]):
206 if not flags.Input.isMC:
207 if runNumber >= 411938:
209 elif any([args.year
and args.year > 2014, runNumber > 232000, flags.Input.ProjectName.startswith(
"data15_")]):
213 if flags.Input.Format
is Format.BS:
215 condDbTag =
'CONDBR2-BLKPA-2023-01' if args.upd4
else 'CONDBR2-ES1PA-2023-01'
216 detDescrVersion =
'ATLAS-R3S-2021-03-01-00'
218 condDbTag =
'CONDBR2-BLKPA-2018-16' if args.upd4
else 'CONDBR2-ES1PA-2018-05'
219 detDescrVersion =
'ATLAS-R2-2016-01-00-01'
221 condDbTag =
'COMCOND-BLKPA-RUN1-06' if (args.upd4
and runNumber > 141066)
else 'COMCOND-ES1PA-006-05'
222 detDescrVersion =
'ATLAS-R1-2012-03-02-00'
224 flags.IOVDb.GlobalTag = condDbTag
225 flags.GeoModel.AtlasVersion = detDescrVersion
228 flags.DQ.useTrigger =
False
229 flags.DQ.enableLumiAccess =
False
230 if not flags.Output.HISTFileName:
231 flags.Output.HISTFileName = f
'{args.outputDirectory}/tilemon_{runNumber}_{args.outputVersion}.root'
233 if args.tmdb
is None:
234 args.tmdb =
not flags.Input.isMC
236 if args.channel_time_mon
is None:
237 args.channel_time_mon = flags.Tile.RunType
in [TileRunType.GAPLAS, TileRunType.GAPCIS]
and (args.run2
or args.run3)
and flags.Tile.doFit
240 flags.Output.ESDFileName = f
'tile_{runNumber}_{args.outputVersion}.pool.root'
243 flags.Output.doJiveXML =
True
246 flags.fillFromArgs(parser=parser)
248 if args.dumpArguments:
249 log.info(
'=====>>> FINAL ARGUMENTS FOLLOW:')
250 print(
'{:40} : {}'.
format(
'Argument Name',
'Value'))
251 for a,v
in (vars(args)).
items():
252 print(f
'{a:40} : {v}')
255 flags.needFlagsCategory(
'Tile')
258 log.info(
'Executing preExec: %s', args.preExec)
263 log.info(
'=====>>> FINAL CONFIG FLAGS SETTINGS FOLLOW:')
264 flags.dump(pattern=
'Tile.*|Input.*|Exec.*|IOVDb.[D|G].*', evaluate=
True)
266 biGainRun = flags.Tile.RunType.isBiGain()
269 cellsAvailable = (flags.Input.Format
is Format.POOL
and 'AllCalo' in flags.Input.Collections)
270 if args.cells
is None:
271 args.cells =
not cellsAvailable
and (args.towers
or args.clusters
or args.muid
or args.muonfit
272 or args.jivexml
or args.d3pd
or args.pool
273 or flags.Tile.RunType
is TileRunType.PHY)
274 cellsAvailable = cellsAvailable
or args.cells
276 if args.cell_mon
is None:
277 args.cell_mon = cellsAvailable
and flags.Tile.RunType
is TileRunType.PHY
279 if args.digi_noise_mon
is None:
280 args.digi_noise_mon = flags.Tile.RunType
is TileRunType.PED
283 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
287 if flags.Input.Format
is Format.BS:
289 from TileByteStream.TileByteStreamConfig
import TileRawDataReadingCfg
291 readMuRcvDigits=any([args.tmdb_digits_mon, args.tmdb_mon, args.ntuple]),
292 readMuRcvRawCh=any([args.tmdb_channel_mon, args.tmdb_mon, args.ntuple])) )
296 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
300 if flags.Tile.readDigits:
301 from TileRecUtils.TileRawChannelMakerConfig
import TileRawChannelMakerCfg
303 rawChMaker = cfg.getEventAlgo(
'TileRChMaker')
304 if args.threads
and (args.threads > 1):
305 rawChMaker.Cardinality = args.threads
306 for builderTool
in rawChMaker.TileRawChannelBuilder:
307 builderTool.UseDSPCorrection =
not biGainRun
311 from TileRecUtils.TileCellMakerConfig
import TileCellMakerCfg
320 from TileMonitoring.TileTopoClusterConfig
import TileTopoClusterCfg
325 from TileCosmicAlgs.TileMuonFitterConfig
import TileMuonFitterCfg
330 from TileMuId.TileMuIdConfig
import TileLookForMuAlgCfg
334 if flags.Output.doWriteESD:
335 from TileRecAlgs.TileRawChannelToHitConfig
import TileRawChannelToHitCfg
340 ntupleFile = f
'{args.outputDirectory}/tile_{runNumber}_{args.outputVersion}.aan.root'
341 from TileRec.TileAANtupleConfig
import TileAANtupleCfg
343 tileNtuple = cfg.getEventAlgo(
'TileNtuple')
345 tileNtuple.CompressionSettings = 204
346 tileNtuple.SkipEvents = 4
if flags.Tile.RunType
is TileRunType.LAS
else 0
347 tileNtuple.TileRawChannelContainerOpt =
"TileRawChannelOpt2" if flags.Tile.doOpt2
else ""
348 tileNtuple.TileRawChannelContainerDsp =
"" if biGainRun
else "TileRawChannelCnt"
349 if args.reduced_ntuple:
350 tileNtuple.Reduced =
True
351 tileNtuple.TileRawChannelContainer =
""
352 if flags.Tile.RunType
is TileRunType.LAS:
353 tileNtuple.OfflineUnits = 1
354 if flags.Tile.RunType
in [TileRunType.GAPLAS, TileRunType.GAPCIS]:
355 tileNtuple.TileDigitsContainerFlt =
"TileDigitsCnt"
356 tileNtuple.TileDigitsContainer =
""
362 for tool
in alg.GMTools:
363 tool.Histograms = [h.replace(
'OFFLINE',
'ONLINE')
for h
in tool.Histograms]
366 from TileMonitoring.TileDigitsMonitorAlgorithm
import TileDigitsMonitoringConfig
371 from TileMonitoring.TileRawChannelMonitorAlgorithm
import TileRawChannelMonitoringConfig
375 if args.channel_time_mon:
376 from TileMonitoring.TileRawChannelTimeMonitorAlgorithm
import TileRawChannelTimeMonitoringConfig
380 if args.tmdb_digits_mon:
381 from TileMonitoring.TileTMDBDigitsMonitorAlgorithm
import TileTMDBDigitsMonitoringConfig
385 if args.tmdb_channel_mon:
386 from TileMonitoring.TileTMDBRawChannelMonitorAlgorithm
import TileTMDBRawChannelMonitoringConfig
391 from TileMonitoring.TileTMDBMonitorAlgorithm
import TileTMDBMonitoringConfig
395 if args.dq_mon
and flags.Tile.RunType
is TileRunType.PHY
and flags.Tile.readDigits:
396 from TileMonitoring.TileDQFragMonitorAlgorithm
import TileDQFragMonitoringConfig
401 from TileMonitoring.TileCellMonitorAlgorithm
import TileCellMonitoringConfig
406 EnergyThresholdForTime=150.0*MeV))
409 if args.digi_noise_mon:
410 from TileMonitoring.TileDigiNoiseMonitorAlgorithm
import TileDigiNoiseMonitoringConfig
411 triggerTypes = [0x82]
if flags.Tile.RunType
is TileRunType.PHY
else []
415 if any([args.tmdb_digits_mon, args.tmdb_mon])
and args.postprocessing:
416 from AthenaCommon.Utils.unixtools
import find_datafile
419 if any([args.tmdb_digits_mon, args.tmdb_mon]):
420 configurations += [os.path.join(dataPath,
'TileTMDBPostProc.yaml')]
422 configurations += [os.path.join(dataPath,
'TileDigitsPostProc.yaml')]
424 if flags.Tile.RunType
in [TileRunType.CIS]:
425 configurations += [os.path.join(dataPath,
'TileRawChanCisPostProc.yaml')]
427 configurations += [os.path.join(dataPath,
'TileRawChanPostProc.yaml')]
428 if flags.Tile.RunType
is TileRunType.LAS:
429 configurations += [os.path.join(dataPath,
'TileRawChanLasPostProc.yaml')]
431 configurations += [os.path.join(dataPath,
'TileRawChanDspPostProc.yaml')]
433 from DataQualityUtils.DQPostProcessingAlg
import DQPostProcessingAlg
436 if hasattr(self,
'OutputLevel'):
438 return super(TileMonPostProcessingAlg, self).
initialize()
441 ppa.OutputLevel = flags.Exec.OutputLevel
442 ppa.ExtraInputs = {(
'xAOD::EventInfo' ,
'StoreGateSvc+EventInfo' )}
443 ppa.Interval = 1000000
444 ppa.ConfigFiles = configurations
446 ppa.FileKey = f
'/{flags.DQ.FileKey}/'
448 cfg.addEventAlgo(ppa, sequenceName=
'AthEndSeq')
453 if flags.Tile.RunType
is TileRunType.LAS:
454 laserCalibFile = f
'tileCalibLAS_{runNumber}_{args.outputVersion}.root'
455 from TileCalibAlgs.TileLaserCalibAlgConfig
import TileLaserCalibAlgCfg
458 elif flags.Tile.RunType
is TileRunType.CIS:
459 cisCalibFile = f
'tileCalibCIS_{runNumber}_{args.outputVersion}.root'
460 from TileCalibAlgs.TileCisCalibAlgConfig
import TileCisCalibAlgCfg
463 elif flags.Tile.RunType
in [TileRunType.PHY, TileRunType.PED]:
464 defaultVersions = [
'0',
'Ped.0',
'Ped']
466 fileVersion = f
'_{flags.Tile.NoiseFilter}' if flags.Tile.NoiseFilter > 0
else ""
467 if args.outputVersion
not in defaultVersions:
468 fileVersion = f
'_{args.outputVersion}_tnf{flags.Tile.NoiseFilter}'
470 from TileCalibAlgs.TileRawChNoiseCalibAlgConfig
import TileRawChNoiseCalibAlgCfg
472 rawChanNoiseCalibAlg = cfg.getEventAlgo(
'TileRawChNoiseCalibAlg')
473 rawChanNoiseCalibAlg.FileNamePrefix = f
'{args.outputDirectory}/RawCh_NoiseCalib{fileVersion}'
475 rawChanNoiseCalibAlg.doFit =
False
476 rawChanNoiseCalibAlg.doFixed =
False
477 rawChanNoiseCalibAlg.doOpt =
False
478 rawChanNoiseCalibAlg.doDsp =
True
479 rawChanNoiseCalibAlg.UseforCells = 3
481 rawChanNoiseCalibAlg.doDsp = (flags.Tile.RunType
is TileRunType.PHY)
482 rawChanNoiseCalibAlg.UseforCells = 1
485 if args.outputVersion
in defaultVersions:
486 from TileCalibAlgs.TileDigiNoiseCalibAlgConfig
import TileDigiNoiseCalibAlgCfg
488 digiNoiseCalibAlg = cfg.getEventAlgo(
'TileDigiNoiseCalibAlg')
489 digiNoiseCalibAlg.DoAvgCorr =
False
490 rawChanNoiseCalibAlg.FileNamePrefix = f
'{args.outputDirectory}/Digi_NoiseCalib{fileVersion}'
494 if flags.Output.doJiveXML:
495 from TileMonitoring.TileJiveXMLConfig
import TileAlgoJiveXMLCfg
501 d3pdFile = f
'{args.outputDirectory}/tile_{runNumber}_{args.outputVersion}.aan.root'
502 from D3PDMakerConfig.D3PDMakerFlags
import D3PDMakerFlags
503 D3PDMakerFlags.DoTruth = flags.Input.isMC
504 from TileRecEx.TileD3PDConfig
import TileD3PDCfg
507 saveCells=cellsAvailable,
508 saveMBTS=cellsAvailable,
511 saveMuonFitter=args.muonfit,
512 saveClusters=args.clusters,
513 saveEventInfo=(flags.Tile.RunType
is TileRunType.PHY)) )
516 if flags.Output.doWriteESD:
517 outputItemList = [
"TileHitVector#*"]
518 outputItemList += [
"TileDigitsContainer#*"]
519 outputItemList += [
"TileBeamElemContainer#*"]
520 outputItemList += [
"TileRawChannelContainer#*"]
521 outputItemList += [
"TileCellContainer#*"]
522 outputItemList += [
"CaloCellContainer#*"]
523 outputItemList += [
"TileMuContainer#*" ]
524 outputItemList += [
"TileL2Container#*" ]
525 outputItemList += [
"TileCosmicMuonContainer#*" ]
527 from OutputStreamAthenaPool.OutputStreamConfig
import OutputStreamCfg
532 log.info(
'Executing postExec: %s', args.postExec)
535 cfg.printConfig(withDetails=args.printDetailedConfig)
538 sys.exit(0
if sc.isSuccess()
else 1)