ATLAS Offline Software
IsolationSteeringDerivConfig.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 pflow isolation for egamma in derivation
5  """
6 
7 from AthenaCommon.Logging import logging
8 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
9 from AthenaConfiguration.ComponentFactory import CompFactory
10 
11 def IsolationSteeringDerivCfg(flags, name = 'IsolationSteeringDeriv', inType = 'EMPFlow'):
12 
13  mlog = logging.getLogger(name)
14  mlog.info('Starting Isolation steering')
15 
16  acc = ComponentAccumulator()
17 
18  # Prepare densities
19  from IsolationAlgs.IsoDensityConfig import (
20  NFlowInputAlgCfg, DensityForIsoAlgCfg)
21  acc.merge(NFlowInputAlgCfg(flags,InputType = inType))
22  suff = 'CSSK' if inType.find('CSSK') >= 0 else ''
23  acc.merge(DensityForIsoAlgCfg(flags,name='CentralDensityFor'+suff+'NFlowIso'))
24  acc.merge(DensityForIsoAlgCfg(flags,name='ForwardDensityFor'+suff+'NFlowIso'))
25 
26  # Prepare CaloIsolationTool
27  kwargs = dict()
28  margs = dict()
29  margs['FlowElementsInConeTool'] = CompFactory.xAOD.FlowElementsInConeTool(
30  name=suff+'FlowElementsInConeTool')
31  if len(suff) > 0:
32  kwargs['CustomConfigurationNameEl'] = suff
33  kwargs['CustomConfigurationNamePh'] = suff
34  margs['EFlowEDCentralContainer'] = 'NeutralParticle'+suff+'FlowIsoCentralEventShape'
35  margs['EFlowEDForwardContainer'] = 'NeutralParticle'+suff+'FlowIsoForwardEventShape'
36  margs['FlowElementsInConeTool'].PFlowKey=suff+'NeutralParticleFlowObjects'
37  from IsolationAlgs.IsoToolsConfig import EGammaCaloIsolationToolCfg
38  kwargs['PFlowIsolationTool'] = acc.popToolsAndMerge(EGammaCaloIsolationToolCfg(flags,**margs))
39 
40  # Prepare IsolationBuilder
41  from xAODPrimitives.xAODIso import xAODIso as isoPar
42  isoType = [ [ isoPar.neflowisol20, isoPar.neflowisol30, isoPar.neflowisol40 ] ]
43  isoCor = [ [ isoPar.coreCone, isoPar.pileupCorrection ] ]
44  isoExCor = [ [ isoPar.coreConeSC ] ]
45  kwargs['ElIsoTypes'] = isoType
46  kwargs['ElCorTypes'] = isoCor
47  kwargs['ElCorTypesExtra'] = isoExCor
48  kwargs['PhIsoTypes'] = isoType
49  kwargs['PhCorTypes'] = isoCor
50  kwargs['PhCorTypesExtra'] = isoExCor
51 
52  kwargs['name'] = suff+'PFlowIsolationBuilder'
53 
54  acc.addEventAlgo(CompFactory.IsolationBuilder(**kwargs))
55 
56  mlog.info("PFlow isolation configured")
57 
58  return acc
59 
60 def LRTElectronIsolationSteeringDerivCfg(flags, name = 'LRTElectronCaloIsolationSteeringDeriv'):
61 
62  mlog = logging.getLogger(name)
63  mlog.info('Starting LRT electron calo Isolation steering')
64 
65  acc = ComponentAccumulator()
66 
67  # Need to add density inputs for mc20 (containers present in MC21 AODs)
68  from IsolationAlgs.IsoDensityConfig import (
69  NFlowInputAlgCfg, DensityForIsoAlgCfg)
70  acc.merge(NFlowInputAlgCfg(flags,InputType = "EMPFlow"))
71  acc.merge(DensityForIsoAlgCfg(flags,name='CentralDensityForNFlowIso'))
72  acc.merge(DensityForIsoAlgCfg(flags,name='ForwardDensityForNFlowIso'))
73 
74  # Prepare CaloIsolationTool
75  kwargs = dict()
76  the_pflowElementsTool = CompFactory.xAOD.FlowElementsInConeTool(
77  name='FlowElementsInConeTool')
78 
79  from IsolationAlgs.IsoToolsConfig import EGammaCaloIsolationToolCfg
80  cisoTool = acc.popToolsAndMerge(EGammaCaloIsolationToolCfg(flags,
81  FlowElementsInConeTool = the_pflowElementsTool))
82 
83  # Prepare IsolationBuilder
84  from xAODPrimitives.xAODIso import xAODIso as isoPar
85  isoType = [ [ isoPar.topoetcone20, isoPar.topoetcone30, isoPar.topoetcone40 ],
86  [ isoPar.neflowisol20, isoPar.neflowisol30, isoPar.neflowisol40 ] ]
87  isoCor = [ [ isoPar.core57cells, isoPar.ptCorrection, isoPar.pileupCorrection ],
88  [ isoPar.coreCone, isoPar.pileupCorrection ] ]
89  isoExCor = [ [ ], [ isoPar.coreConeSC ] ]
90 
91  acc.addEventAlgo(CompFactory.IsolationBuilder(**kwargs,
92  name = 'LRTElectronCaloIsolationBuilder',
93  ElectronCollectionContainerName = 'LRT'+flags.Egamma.Keys.Output.Electrons,
94  ElIsoTypes = isoType,
95  ElCorTypes = isoCor,
96  ElCorTypesExtra = isoExCor,
97  CaloTopoIsolationTool = cisoTool,
98  PFlowIsolationTool = cisoTool))
99 
100  mlog.info("LRTElectron calo isolation configured")
101 
102  return acc
103 
104 def LRTMuonIsolationSteeringDerivCfg(flags, name = 'LRTMuonCaloIsolationSteeringDeriv'):
105 
106  mlog = logging.getLogger(name)
107  mlog.info('Starting LRT muon calo Isolation steering')
108 
109  acc = ComponentAccumulator()
110 
111  # Need to add density inputs for mc20 (containers present in MC21 AODs)
112  from IsolationAlgs.IsoDensityConfig import (
113  NFlowInputAlgCfg, DensityForIsoAlgCfg)
114  acc.merge(NFlowInputAlgCfg(flags,InputType = "EMPFlow"))
115  acc.merge(DensityForIsoAlgCfg(flags,name='CentralDensityForNFlowIso'))
116  acc.merge(DensityForIsoAlgCfg(flags,name='ForwardDensityForNFlowIso'))
117 
118  # Prepare CaloIsolationTool
119  the_pflowElementsTool = CompFactory.xAOD.FlowElementsInConeTool(
120  name='FlowElementsInConeTool')
121 
122  from IsolationAlgs.IsoToolsConfig import MuonCaloIsolationToolCfg
123  cisoTool = acc.popToolsAndMerge(MuonCaloIsolationToolCfg(flags,
124  FlowElementsInConeTool = the_pflowElementsTool ))
125  # Prepare IsolationBuilder
126  from xAODPrimitives.xAODIso import xAODIso as isoPar
127  misoType = [ [ isoPar.topoetcone20, isoPar.topoetcone30, isoPar.topoetcone40 ],
128  [ isoPar.neflowisol20, isoPar.neflowisol30, isoPar.neflowisol40 ] ]
129  misoCor = [ [ isoPar.coreCone, isoPar.pileupCorrection ],
130  [ isoPar.coreCone, isoPar.pileupCorrection ] ]
131  misoExCor = [ [ ], [ ] ]
132 
133  acc.addEventAlgo(CompFactory.IsolationBuilder(name= "LRTMuonCaloIsolationBuilder",
134  MuonCollectionContainerName = "MuonsLRT",
135  MuCorTypesExtra = misoExCor,
136  MuCorTypes = misoCor,
137  CaloTopoIsolationTool = cisoTool,
138  PFlowIsolationTool = cisoTool,
139  MuIsoTypes = misoType ))
140 
141  mlog.info("MuonLRT calo isolation configured")
142 
143  return acc
144 
145 if __name__ == "__main__":
146  from AthenaConfiguration.AllConfigFlags import initConfigFlags
147  from AthenaConfiguration.ComponentAccumulator import printProperties
148  from AthenaConfiguration.TestDefaults import defaultTestFiles
149  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
150  flags = initConfigFlags()
151  flags.Input.Files = defaultTestFiles.RDO_RUN2
152  flags.Output.doWriteESD = True # To test the ESD parts
153  flags.Output.doWriteAOD = True # To test the AOD parts
154  flags.lock()
155 
156  mlog = logging.getLogger("isolationConfigTest")
157  mlog.info("Configuring isolation: ")
158 
159  acc = MainServicesCfg(flags)
160  acc.merge(IsolationSteeringDerivCfg(flags))
161  acc.merge(LRTElectronIsolationSteeringDerivCfg(flags))
162  acc.merge(LRTMuonIsolationSteeringDerivCfg(flags))
163  acc.printConfig(withDetails=True,
164  printDefaults=True)
165  printProperties(mlog,
166  acc.getEventAlgo('PFlowIsolationBuilder'),
167  nestLevel=1,
168  printDefaults=True)
169  printProperties(mlog,
170  acc.getEventAlgo('LRTElectronCaloIsolationBuilder'),
171  nestLevel=1,
172  printDefaults=True)
173  printProperties(mlog,
174  acc.getEventAlgo('LRTMuonCaloIsolationBuilder'),
175  nestLevel=1,
176  printDefaults=True)
177 
178  with open("isolationconfig.pkl", "wb") as f:
179  acc.store(f)
IsolationSteeringDerivConfig.LRTMuonIsolationSteeringDerivCfg
def LRTMuonIsolationSteeringDerivCfg(flags, name='LRTMuonCaloIsolationSteeringDeriv')
Definition: IsolationSteeringDerivConfig.py:104
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
IsolationSteeringDerivConfig.IsolationSteeringDerivCfg
def IsolationSteeringDerivCfg(flags, name='IsolationSteeringDeriv', inType='EMPFlow')
Definition: IsolationSteeringDerivConfig.py:11
IsoDensityConfig.NFlowInputAlgCfg
def NFlowInputAlgCfg(flags, name='NFlowInputAlg', **kwargs)
Definition: IsoDensityConfig.py:29
IsoDensityConfig.DensityForIsoAlgCfg
def DensityForIsoAlgCfg(flags, name="CentralDensityForTopoIso", **kwargs)
Definition: IsoDensityConfig.py:63
IsoToolsConfig.MuonCaloIsolationToolCfg
def MuonCaloIsolationToolCfg(flags, **kwargs)
Definition: IsoToolsConfig.py:88
IsolationSteeringDerivConfig.LRTElectronIsolationSteeringDerivCfg
def LRTElectronIsolationSteeringDerivCfg(flags, name='LRTElectronCaloIsolationSteeringDeriv')
Definition: IsolationSteeringDerivConfig.py:60
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
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
IsoToolsConfig.EGammaCaloIsolationToolCfg
def EGammaCaloIsolationToolCfg(flags, **kwargs)
Definition: IsoToolsConfig.py:55