279def calibConfigToToolList(flags, **configDict):
280 """
281 Returns a list of instantiated tools for each of the calibration steps.
282 The order of the steps is determined by the InScale and OutScale properties given in the config.
283 Tools are instantiated by calling functions declared in the calibStepDic dictionary.
284 """
285
286 isFullSim = True
287 if flags.Input.isMC:
288 metaData = GetFileMD(flags.Input.Files[0])
289 simFlavour = metaData.get('Simulator','')
290 if 'ATLFAST3' in simFlavour:
291 isFullSim = False
292
293
294 if flags.Input.isMC and not isFullSim and 'AF3' in configDict:
295
296 for step in configDict:
297 if configDict.get(step)['InScale'] == 'JetGSCScaleMomentum' and step != 'Insitu' and step != 'AF3':
298 configDict.get(step)['InScale'] = 'JetFastSimScaleMomentum'
299 break
300
301 toolDic = {}
302 foundCS = False
303 for step in configDict:
304
305 configDict.get(step).pop('prereqs',{})
306
307 if configDict.get(step).pop('noRun',False):
308 jcslog.warning(f'Expert option: Skipping calib step {step}')
309 continue
310
311
312 if step==
"Insitu" and flags.Input.isMC
and not configDict.get(
"Insitu").
get(
"CalibrateMC",
False):
313 jcslog.info('Skipping Insitu for MC')
314 continue
315
316
317 if step=="MC2MC":
318 if not flags.Input.isMC:
319 jcslog.info('Skipping MC2MC calibration for data')
320 continue
321
322 for key, value in flags.Input.GeneratorsInfo.items():
323 generator = key
324 break
325 if 'Pythia' in generator:
326 jcslog.info('Skipping MC2MC calibration for Pythia8')
327 continue
328
329
330 if step=="AF3":
331 if not flags.Input.isMC:
332 jcslog.info('Skipping additional FastSimulation calibration for data')
333 continue
334
335 if isFullSim:
336 jcslog.info('Skipping additional FastSimulation calibration for full sim')
337 continue
338
339 calibFunc = calibStepDic.get(step,None)
340 if calibFunc is None:
341 raise NotImplementedError(f'Calibration step {step} is not found in calibStepDic')
342
343 calibConfig = configDict.get(step)
344
345
346 toolList = calibFunc(flags, **calibConfig)
347
348 toolDic[step] = toolList
349 if toolList[0].InScale == "JetConstitScaleMomentum":
350 foundCS = True
351
352 if not foundCS:
353 raise JetCalibConfigError('At least one step must have InScale = JetConstitScaleMomentum')
354
355 def findNextSteps(ordered_tools=[], ordered_step_names=[], startScale = "JetConstitScaleMomentum"):
356 ''' Recursively add tools to ordered_tools based on in/out scale '''
357 for step in toolDic:
358 if toolDic[step][0].InScale == startScale:
359 ordered_tools += toolDic[step]
360 ordered_step_names.append(step)
361 ordered_tools, ordered_step_names = findNextSteps(ordered_tools, ordered_step_names, toolDic[step][-1].OutScale)
362
363 return ordered_tools, ordered_step_names
364
365 ordered_tools, ordered_step_names = findNextSteps([], [])
366
367
368 for step in toolDic:
369 if step not in ordered_step_names:
370 raise JetCalibConfigError(f'Could not place calib step {step} - have you set InScale and OutScale correctly?')
371
372 jcslog.info(f'Ordered jet calib steps: {"->".join(ordered_step_names)}')
373
374 return ordered_tools
375
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)