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