ATLAS Offline Software
egammaMVACalibConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaCommon.Logging import logging
4 from AthenaConfiguration.ComponentFactory import CompFactory
5 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
6 from xAODEgamma.xAODEgammaParameters import xAOD
7 
8 
9 def egammaMVAToolCfg(flags, **kwargs):
10  acc = ComponentAccumulator()
11  acc.setPrivateTools(CompFactory.egammaMVACalibTool(**kwargs))
12  return acc
13 
14 
15 def egammaMVASvcCfg(flags, name="egammaMVASvc", **kwargs):
16 
17  acc = ComponentAccumulator()
18 
19  if "folder" not in kwargs:
20  folder = flags.Egamma.Calib.MVAVersion
21  else:
22  # we pop. As folder is not a property of
23  # egammaMVASvc but of the tools
24  folder = kwargs.pop("folder")
25 
26  if "ElectronTool" not in kwargs:
27  kwargs["ElectronTool"] = acc.popToolsAndMerge(
29  flags,
30  name="electronMVATool",
31  ParticleType=xAOD.EgammaParameters.electron,
32  folder=folder)
33  )
34 
35  if "UnconvertedPhotonTool" not in kwargs:
36  kwargs["UnconvertedPhotonTool"] = acc.popToolsAndMerge(
38  flags,
39  name="unconvertedPhotonMVATool",
40  ParticleType=xAOD.EgammaParameters.unconvertedPhoton,
41  folder=folder)
42  )
43 
44  if "ConvertedPhotonTool" not in kwargs:
45  kwargs["ConvertedPhotonTool"] = acc.popToolsAndMerge(
47  flags,
48  name="convertedPhotonMVATool",
49  ParticleType=xAOD.EgammaParameters.convertedPhoton,
50  folder=folder)
51  )
52 
53  acc.addService(
54  CompFactory.egammaMVASvc(
55  name=name,
56  **kwargs), primary=True)
57  return acc
58 
59 
60 if __name__ == "__main__":
61 
62  from AthenaConfiguration.AllConfigFlags import initConfigFlags
63  from AthenaConfiguration.ComponentAccumulator import printProperties
64  from AthenaConfiguration.TestDefaults import defaultTestFiles
65  flags = initConfigFlags()
66  flags.Input.Files = defaultTestFiles.RDO_RUN2
67  flags.fillFromArgs()
68  flags.lock()
69 
71  mlog = logging.getLogger("egammaMVASvcConfigTest")
72  mlog.info("Configuring egammaMVASvc :")
73  printProperties(mlog, cfg.getPrimaryAndMerge(
74  egammaMVASvcCfg(flags,
75  folder=flags.Egamma.Calib.MVAVersion)),
76  nestLevel=1,
77  printDefaults=True)
78  cfg.printConfig()
79 
80  f = open("egmvatools.pkl", "wb")
81  cfg.store(f)
82  f.close()
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.egammaMVACalibConfig.egammaMVASvcCfg
def egammaMVASvcCfg(flags, name="egammaMVASvc", **kwargs)
Definition: egammaMVACalibConfig.py:15
extractSporadic.printProperties
def printProperties(h, q, hLB)
Definition: extractSporadic.py:8
Trk::open
@ open
Definition: BinningType.h:40
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.egammaMVACalibConfig.egammaMVAToolCfg
def egammaMVAToolCfg(flags, **kwargs)
Definition: egammaMVACalibConfig.py:9