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