304def calibConfigToToolList(flags, calibSeqOverride=None, **configDict):
305 """
306 Returns a list of instantiated tools for each of the calibration steps.
307 Tools are instantiated by calling functions declared in the calibStepDic dictionary.
308 The order of the steps is determined by the Sequence block of the config.
309 The calibSeqOverride argument can be set to a '_'-separated string of step names,
310 which will override the step ordering set by the Sequence block.
311 """
312
313
314 isFullSim = True
315 if flags.Input.isMC:
316 metaData = GetFileMD(flags.Input.Files[0])
317 simFlavour = metaData.get('Simulator','')
318 if 'ATLFAST3' in simFlavour:
319 isFullSim = False
320 sampleKey = 'AF3'
321 else:
322 sampleKey = 'FullSim'
323 else:
324 sampleKey = 'Data'
325
326 if flags.GeoModel.Run == LHCPeriod.Run2:
327 runKey = 'Run2'
328 elif flags.GeoModel.Run == LHCPeriod.Run3:
329 runKey = 'Run3'
330 elif flags.GeoModel.Run >= LHCPeriod.Run4:
331 runKey = 'Run4'
332 else:
333 jcslog.warning('LHCPeriod not recognised')
334
335
336 if calibSeqOverride:
337
338 sequence = calibSeqOverride.split('_')
339 jcslog.info('Expert option calibSeqOverride set - overriding step sequence')
340 else:
341
342 try:
343 seqDict = configDict.pop('Sequence')
344 sequence = seqDict[runKey][sampleKey]
345 except KeyError:
346 raise JetCalibConfigError(f"{runKey} {sampleKey} sample identified. YAML should specify step ordering via the following block structure: \n \
347 Sequence:\n \
348 {runKey}: \n \
349 {sampleKey}: [list of steps] ")
350
351 toolList = []
352 jcslog.debug('Configuring jet calib steps:')
353 for step in sequence:
354
355 if step not in configDict:
356 raise JetCalibConfigError(f'Sequence includes step {step} but no YAML block is provided.')
357 configDict.get(step).pop('prereqs',{})
358
359
360 if configDict.get(step).pop('noRun',False):
361 jcslog.warning(f'Expert option: Skipping calib step {step}')
362 continue
363
364
365 if step==
"Insitu" and flags.Input.isMC
and not configDict.get(
"Insitu").
get(
"CalibrateMC",
False):
366 jcslog.warning('Insitu step included for MC but CalibrateMC is False - no calibration will be run')
367
368 if step=="MC2MC":
369
370 if not flags.Input.isMC:
371 jcslog.warning('Running MC2MC calibration for data')
372
373
374 for key, value in flags.Input.GeneratorsInfo.items():
375 generator = key
376 break
377 if 'Pythia' in generator:
378 jcslog.debug('Skipping MC2MC calibration for Pythia8')
379 continue
380
381
382 if step=="AF3":
383 if not flags.Input.isMC:
384 jcslog.warning('Running FastSimulation calibration for data')
385
386 if isFullSim:
387 jcslog.warning('Running FastSimulation calibration for full sim')
388
389 calibFunc = calibStepDic.get(step,None)
390
391 if calibFunc is None:
392 raise NotImplementedError(f'Calibration step {step} is not found in calibStepDic')
393
394 calibConfig = configDict.get(step)
395
396
397 for overrideKey in ['Run2', 'Run3', 'Run4']:
398
399 overrideDict = calibConfig.pop(overrideKey,{})
400
401 if runKey!=overrideKey or not overrideDict:
402 continue
403 jcslog.debug(f'{step}: Applying {runKey} override settings')
404
405 for key in overrideDict:
406 if key in calibConfig:
407 jcslog.warning(f'{key} will be overwritten by {overrideKey} settings')
408 calibConfig[key] = overrideDict[key]
409
410
411 if len(toolList)==0:
412 inScale = 'JetConstitScaleMomentum'
413 else:
414 inScale = toolList[-1].OutScale
415
416 calibConfig.setdefault('InScale', inScale)
417
418 if calibConfig['InScale']!=inScale:
419 jcslog.warning(f'InScale set to {calibConfig['InScale']} in YAML config, but expected {inScale} from Sequence ordering -- is this intentional?')
420
421
422 newToolList = calibFunc(flags, **calibConfig)
423 jcslog.debug(f'{step}: InScale = {newToolList[0].InScale}, OutScale = {newToolList[-1].OutScale}')
424
425 toolList += newToolList
426
427 return toolList
428
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)