ATLAS Offline Software
IsolationBuilderConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 __doc__ = """
4  Instantiate the electron or photon isolation
5  """
6 
7 from AthenaCommon.Logging import logging
8 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
9 from AthenaConfiguration.ComponentFactory import CompFactory
10 
11 def egIsolationCfg(flags, name='egIsolation', noCalo=False, **kwargs):
12 
13  mlog = logging.getLogger(name)
14  mlog.info('Starting '+name+' configuration')
15 
16  acc = ComponentAccumulator()
17 
18  suff = ''
19  if name.find('photon') >= 0:
20  suff = 'photon'
21  pref = 'Ph'
22  elif name.find('electron') >= 0:
23  suff = 'electron'
24  pref = 'El'
25  else:
26  mlog.error('Name '+name+' should contain electron or photon')
27  return acc
28 
29  from xAODPrimitives.xAODIso import xAODIso as isoPar
30  from IsolationAlgs.IsoToolsConfig import (
31  TrackIsolationToolCfg, ElectronTrackIsolationToolCfg,
32  EGammaCaloIsolationToolCfg)
33 
34  isoType = []
35  isoCor = []
36  isoExCor = []
37 
38  if flags.Detector.EnableID or flags.Detector.EnableITk:
39  isoType.append([ isoPar.ptcone30, isoPar.ptcone20 ])
40  isoCor.append([ isoPar.coreTrackPtr ])
41  isoExCor.append([])
42  if 'TrackIsolationTool' not in kwargs:
43  if pref == 'Ph':
44  kwargs['TrackIsolationTool'] = acc.popToolsAndMerge(
45  TrackIsolationToolCfg(flags))
46  else:
47  kwargs['TrackIsolationTool'] = acc.popToolsAndMerge(
49 
50  if flags.Detector.EnableCalo and not noCalo:
51  isoType.append(
52  [ isoPar.topoetcone20, isoPar.topoetcone30, isoPar.topoetcone40 ])
53  isoCor.append(
54  [ isoPar.core57cells, isoPar.ptCorrection, isoPar.pileupCorrection ])
55  # do not do pileup correction if HI with subtracted clusters
56  if flags.HeavyIon.Egamma.doSubtractedClusters:
57  isoCor[-1] = [ x for x in isoCor[-1] if x != isoPar.pileupCorrection ]
58  isoExCor.append([])
59  if 'CaloTopoIsolationTool' not in kwargs:
60  kwargs['CaloTopoIsolationTool'] = acc.popToolsAndMerge(
62 
63  kwargs[f'{pref}IsoTypes'] = isoType
64  kwargs[f'{pref}CorTypes'] = isoCor
65  kwargs[f'{pref}CorTypesExtra'] = isoExCor
66 
67  kwargs['name'] = suff+'IsolationBuilder'
68 
69  acc.addEventAlgo(CompFactory.IsolationBuilder(**kwargs))
70 
71  mlog.info(suff+" isolation configured")
72 
73  return acc
74 
75 def muIsolationCfg(flags, name='muIsolation', noCalo=False, **kwargs):
76 
77  mlog = logging.getLogger(name)
78  mlog.info('Starting '+name+' configuration')
79 
80  acc = ComponentAccumulator()
81 
82  from xAODPrimitives.xAODIso import xAODIso as isoPar
83  from IsolationAlgs.IsoToolsConfig import (
84  TrackIsolationToolCfg, MuonCaloIsolationToolCfg)
85 
86  isoType = []
87  isoCor = []
88  isoExCor = []
89 
90  if flags.Detector.EnableID or flags.Detector.EnableITk:
91  isoType.append([ isoPar.ptcone40, isoPar.ptcone30, isoPar.ptcone20 ])
92  isoCor.append([ isoPar.coreTrackPtr ])
93  isoExCor.append([])
94  if 'TrackIsolationTool' not in kwargs:
95  kwargs['TrackIsolationTool'] = acc.popToolsAndMerge(
96  TrackIsolationToolCfg(flags))
97 
98  if flags.Detector.EnableCalo and not noCalo:
99  isoType.append(
100  [ isoPar.topoetcone20, isoPar.topoetcone30, isoPar.topoetcone40 ])
101  isoCor.append([ isoPar.coreCone, isoPar.pileupCorrection ])
102  # do not do pileup correction if HI with subtracted clusters
103  if flags.HeavyIon.Egamma.doSubtractedClusters:
104  isoCor[-1] = [ x for x in isoCor[-1] if x != isoPar.pileupCorrection ]
105  isoExCor.append([])
106  if ('CaloTopoIsolationTool' not in kwargs) or (
107  'PFlowIsolationTool' not in kwargs):
108  cisoTool = acc.popToolsAndMerge(MuonCaloIsolationToolCfg(flags))
109  if 'CaloTopoIsolationTool' not in kwargs:
110  kwargs['CaloTopoIsolationTool'] = cisoTool
111  if flags.Reco.EnablePFlow and 'PFlowIsolationTool' not in kwargs:
112  isoType.append(
113  [ isoPar.neflowisol20, isoPar.neflowisol30, isoPar.neflowisol40 ])
114  isoCor.append([ isoPar.coreCone, isoPar.pileupCorrection ])
115  # do not do pileup correction for HI reco...
116  # and pflow iso is more than experimental in such reco anyway
117  if flags.HeavyIon.Egamma.doSubtractedClusters:
118  isoCor[-1] = [ x for x in isoCor[-1] if x != isoPar.pileupCorrection ]
119  isoExCor.append([])
120  kwargs['PFlowIsolationTool'] = cisoTool
121 
122  kwargs['MuIsoTypes'] = isoType
123  kwargs['MuCorTypes'] = isoCor
124  kwargs['MuCorTypesExtra'] = isoExCor
125  kwargs['name'] = 'muonIsolationBuilder'
126 
127  acc.addEventAlgo(CompFactory.IsolationBuilder(**kwargs))
128 
129  mlog.info("muon isolation configured")
130 
131  return acc
132 
133 
134 if __name__ == "__main__":
135  from AthenaConfiguration.AllConfigFlags import initConfigFlags
136  from AthenaConfiguration.ComponentAccumulator import printProperties
137  from AthenaConfiguration.TestDefaults import defaultTestFiles
138  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
139  flags = initConfigFlags()
140  flags.Input.Files = defaultTestFiles.RDO_RUN2
141  flags.Output.doWriteESD = True # To test the ESD parts
142  flags.Output.doWriteAOD = True # To test the AOD parts
143  flags.lock()
144 
145  mlog = logging.getLogger("isolationConfigTest")
146  mlog.info("Configuring photon isolation: ")
147 
148  acc = MainServicesCfg(flags)
149  acc.merge(egIsolationCfg(flags,name = 'photonIsolation'))
150  acc.merge(egIsolationCfg(flags,name = 'electronIsolation'))
151  acc.merge(muIsolationCfg(flags,name = 'muonIsolation'))
152  printProperties(mlog,
153  acc.getEventAlgo("photonIsolationBuilder"),
154  nestLevel=1,
155  printDefaults=True)
156  printProperties(mlog,
157  acc.getEventAlgo("electronIsolationBuilder"),
158  nestLevel=1,
159  printDefaults=True)
160  printProperties(mlog,
161  acc.getEventAlgo("muonIsolationBuilder"),
162  nestLevel=1,
163  printDefaults=True)
164 
165  with open("isolationconfig.pkl", "wb") as f:
166  acc.store(f)
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
IsoToolsConfig.ElectronTrackIsolationToolCfg
def ElectronTrackIsolationToolCfg(flags, **kwargs)
Definition: IsoToolsConfig.py:50
IsoToolsConfig.MuonCaloIsolationToolCfg
def MuonCaloIsolationToolCfg(flags, **kwargs)
Definition: IsoToolsConfig.py:88
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
IsolationBuilderConfig.egIsolationCfg
def egIsolationCfg(flags, name='egIsolation', noCalo=False, **kwargs)
Definition: IsolationBuilderConfig.py:11
python.TrackIsolationDecoratorConfig.TrackIsolationToolCfg
def TrackIsolationToolCfg(ConfigFlags, name="TrackIsolationTool", **kwargs)
Definition: TrackIsolationDecoratorConfig.py:12
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
IsolationBuilderConfig.muIsolationCfg
def muIsolationCfg(flags, name='muIsolation', noCalo=False, **kwargs)
Definition: IsolationBuilderConfig.py:75
IsoToolsConfig.EGammaCaloIsolationToolCfg
def EGammaCaloIsolationToolCfg(flags, **kwargs)
Definition: IsoToolsConfig.py:55