19 from AnalysisAlgorithmsConfig.ConfigSequence
import ConfigSequence
21 from AnaAlgorithm.Logging
import logging
22 logCPAlgCfgFactory = logging.getLogger(
'CPAlgCfgFactory')
26 """return dict(par, val) with all func parameters with defualt values"""
27 signature = inspect.signature(func)
30 for k, v
in signature.parameters.items()
31 if v.default
is not inspect.Parameter.empty
36 """return list of input parameters"""
37 if inspect.isclass(func):
38 args =
list(inspect.signature(func.__init__).parameters.keys())
41 args =
list(inspect.signature(func).parameters.keys())
49 def __init__(self, alg, algName, options, defaults, subAlgs=None):
65 name associated with the algorithm. This name must have been added to the
66 list of available algorithms
68 dictionary containing options for the algorithm read from the YAML file
74 configSeq = ConfigSequence()
85 if arg
in funcOptions:
86 args[arg] = funcOptions[arg]
88 elif arg
in funcDefaults:
89 args[arg] = funcDefaults[arg]
91 elif defaults
is not None and arg
in defaults:
92 args[arg] = defaults[arg]
100 raise ValueError(f
"{arg} is required for {funcName}")
101 if inspect.isclass(func):
102 configSeq.append(func(**args))
105 return configSeq, args.keys()
109 """This class provides a configuration manager that is intended to allow the user to:
110 - define and configure functions that return an algSequence(?) object
121 """Add class to list of available algorithms"""
122 if not callable(alg):
123 raise ValueError(f
"{algName} is not a callable.")
126 if superBlocks
is None:
128 elif not isinstance(superBlocks, list):
129 superBlocks = [superBlocks]
132 for block
in superBlocks:
133 if block
not in self.
_order:
135 order = self.
_order[block]
140 if block
not in self.
_algs:
141 raise ValueError(f
"{block} not added")
142 algs = self.
_algs[block].subAlgs
145 raise ValueError(f
"{algName} has already been added.")
157 order.append(algName)
159 order.insert(order.index(pos), algName)
161 raise ValueError(f
"{pos} does not exit in already added config blocks")
166 """Prints algorithms exposed to configuration"""
169 for alg, algInfo
in algs.items():
170 algName = algInfo.alg.__name__
171 algOptions = algInfo.options
172 if algName
not in printed:
173 printed.append(algName)
174 logCPAlgCfgFactory.info(f
"\033[4m{alg}\033[0m -> \033[4m{algName}\033[0m")
177 if inspect.isclass(algInfo.alg):
179 algInfo.alg().printOptions(verbose=printOpts)
182 seq = ConfigSequence()
184 seq.printOptions(verbose=printOpts)
188 for opt
in algOptions:
189 logCPAlgCfgFactory.info(f
" {opt}")
190 printAlg(algInfo.subAlgs)
198 configSeq: configSequence object
202 algContext, algName = name.split(
'.')
203 block = self.
_algs[algContext].subAlgs[algName]
205 block = self.
_algs[name]
207 raise ValueError(f
"{name} config block not found. Make sure context is correct.")
208 configSeq, _ = block.makeConfig(kwargs)
213 """add algorithms and options"""
216 from AsgAnalysisAlgorithms.AsgAnalysisConfig
import CommonServicesConfig
220 from AsgAnalysisAlgorithms.AsgAnalysisConfig
import PileupReweightingBlock
224 from AsgAnalysisAlgorithms.EventCleaningConfig
import EventCleaningBlock
228 from TriggerAnalysisAlgorithms.TriggerAnalysisConfig
import Trigger
230 from TriggerAnalysisAlgorithms.TriggerAnalysisSFConfig
import TriggerAnalysisSFBlock
234 from JetAnalysisAlgorithms.JetAnalysisConfig
import makeJetAnalysisConfig
236 from JetAnalysisAlgorithms.JetJvtAnalysisConfig
import JetJvtAnalysisConfig
239 from JetAnalysisAlgorithms.BJetCalibAnalysisConfig
import BJetCalibAnalysisConfig
242 from FTagAnalysisAlgorithms.FTagAnalysisConfig
import FTagConfig
244 defaults={
'selectionName':
''},
246 from FTagAnalysisAlgorithms.FTagEventSFAnalysisConfig
import FTagEventSFConfig
248 alg=FTagEventSFConfig,
249 defaults={
'selectionName':
''},
253 from EgammaAnalysisAlgorithms.ElectronAnalysisConfig
import ElectronCalibrationConfig
255 from EgammaAnalysisAlgorithms.ElectronAnalysisConfig
import ElectronWorkingPointConfig
257 superBlocks=
"Electrons")
258 from EgammaAnalysisAlgorithms.ElectronAnalysisConfig
import ElectronTriggerAnalysisSFBlock
260 superBlocks=
"Electrons")
263 from EgammaAnalysisAlgorithms.PhotonAnalysisConfig
import PhotonCalibrationConfig
265 from EgammaAnalysisAlgorithms.PhotonAnalysisConfig
import PhotonWorkingPointConfig
267 superBlocks=
"Photons")
268 from EgammaAnalysisAlgorithms.PhotonExtraVariablesConfig
import PhotonExtraVariablesBlock
270 superBlocks=
"Photons")
273 from MuonAnalysisAlgorithms.MuonAnalysisConfig
import MuonCalibrationConfig
275 from MuonAnalysisAlgorithms.MuonAnalysisConfig
import MuonWorkingPointConfig
278 from MuonAnalysisAlgorithms.MuonAnalysisConfig
import MuonTriggerAnalysisSFBlock
283 from TauAnalysisAlgorithms.TauAnalysisConfig
import TauCalibrationConfig
285 from TauAnalysisAlgorithms.TauAnalysisConfig
import TauWorkingPointConfig
287 superBlocks=
"TauJets")
288 from TauAnalysisAlgorithms.TauAnalysisConfig
import TauTriggerAnalysisSFBlock
290 superBlocks=
"TauJets")
293 from AsgAnalysisAlgorithms.SystObjectLinkConfig
import SystObjectLinkBlock
295 superBlocks=[self.
ROOTNAME,
"Jets",
"Electrons",
"Photons",
"Muons",
"TauJets"])
298 from TruthParticleLevelAnalysisAlgorithms.ParticleLevelElectronsConfig
import ParticleLevelElectronsBlock
300 from TruthParticleLevelAnalysisAlgorithms.ParticleLevelMuonsConfig
import ParticleLevelMuonsBlock
302 from TruthParticleLevelAnalysisAlgorithms.ParticleLevelNeutrinosConfig
import ParticleLevelNeutrinosBlock
304 from TruthParticleLevelAnalysisAlgorithms.ParticleLevelJetsConfig
import ParticleLevelJetsBlock
306 from TruthParticleLevelAnalysisAlgorithms.ParticleLevelTausConfig
import ParticleLevelTausBlock
308 from TruthParticleLevelAnalysisAlgorithms.ParticleLevelPhotonsConfig
import ParticleLevelPhotonsBlock
310 from TruthParticleLevelAnalysisAlgorithms.ParticleLevelMissingETConfig
import ParticleLevelMissingETBlock
312 from TruthParticleLevelAnalysisAlgorithms.ParticleLevelOverlapRemovalConfig
import ParticleLevelOverlapRemovalBlock
313 self.
addAlgConfigBlock(algName=
"PL_OverlapRemoval", alg=ParticleLevelOverlapRemovalBlock)
316 from AsgAnalysisAlgorithms.AsgAnalysisConfig
import IFFLeptonDecorationBlock
317 self.
addAlgConfigBlock(algName=
"IFFClassification", alg=IFFLeptonDecorationBlock,
318 superBlocks=[
"Electrons",
"Muons",
319 "PL_Electrons",
"PL_Muons"])
321 from AsgAnalysisAlgorithms.AsgAnalysisConfig
import MCTCLeptonDecorationBlock
322 self.
addAlgConfigBlock(algName=
"MCTCClassification", alg=MCTCLeptonDecorationBlock,
323 superBlocks=[
"Electrons",
"Muons",
"TauJets",
324 "PL_Electrons",
"PL_Muons",
"PL_Taus"])
327 from AsgAnalysisAlgorithms.AsgAnalysisConfig
import GeneratorAnalysisBlock
328 self.
addAlgConfigBlock(algName=
"GeneratorLevelAnalysis", alg=GeneratorAnalysisBlock)
331 from AsgAnalysisAlgorithms.AsgAnalysisConfig
import PtEtaSelectionBlock
333 defaults={
'selectionName':
''},
335 "Jets",
"Electrons",
"Photons",
"Muons",
"TauJets",
336 "PL_Jets",
"PL_Electrons",
"PL_Photons",
"PL_Muons",
"PL_Taus",
"PL_Neutrinos"])
339 from MetAnalysisAlgorithms.MetAnalysisConfig
import MetAnalysisConfig
343 from AsgAnalysisAlgorithms.OverlapAnalysisConfig
import OverlapAnalysisConfig
345 defaults={
'configName':
'OverlapRemoval'})
348 from AsgAnalysisAlgorithms.AsgAnalysisConfig
import ObjectCutFlowBlock
352 from JetAnalysisAlgorithms.JetReclusteringConfig
import JetReclusteringBlock
356 from EventSelectionAlgorithms.EventSelectionConfig
import makeMultipleEventSelectionConfigs
357 self.
addAlgConfigBlock(algName=
'EventSelection', alg=makeMultipleEventSelectionConfigs)
360 from AsgAnalysisAlgorithms.AsgAnalysisConfig
import EventCutFlowBlock
362 defaults={
'containerName':
'EventInfo',
'selectionName':
''})
365 from AsgAnalysisAlgorithms.BootstrapGeneratorConfig
import BootstrapGeneratorConfig
369 from AsgAnalysisAlgorithms.AsgAnalysisConfig
import PerEventSFBlock
373 from AsgAnalysisAlgorithms.LeptonSFCalculatorConfig
import LeptonSFCalculatorBlock
377 from AsgAnalysisAlgorithms.AsgAnalysisConfig
import OutputThinningBlock
379 defaults={
'configName':
'Thinning'})
382 from AsgAnalysisAlgorithms.AsgAnalysisConfig
import SelectionDecorationBlock
384 alg=SelectionDecorationBlock)
387 from TauAnalysisAlgorithms.DiTauMassConfig
import DiTauMassBlock
391 from AsgAnalysisAlgorithms.FakeBkgConfig
import FakeBkgBlock
395 from AsgAnalysisAlgorithms.VGammaORConfig
import VGammaORBlock
399 from AsgAnalysisAlgorithms.OutputAnalysisConfig
import OutputAnalysisConfig
401 defaults={
'configName':
'Output'})
404 from AsgAnalysisAlgorithms.AsgAnalysisConfig
import IOStatsBlock