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