ATLAS Offline Software
IsoDensityConfig.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, photon and muon isolation
5  """
6 
7 from AthenaCommon.Logging import logging
8 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
9 from AthenaConfiguration.ComponentFactory import CompFactory
10 
11 def EMTopoInputAlgCfg(flags, name='EMTopoInputAlg', **kwargs):
12 
13  mlog = logging.getLogger(name)
14  mlog.info('Starting input building for isolation density configuration')
15 
16  acc = ComponentAccumulator()
17 
18  from JetRecConfig.StandardJetConstits import stdConstitDic as cst
19  from JetRecConfig.JetRecConfig import JetInputCfg, getConstitPJGAlg
20 
21  # Get the input (from CaloCal to EM scale, no origin correction)
22  acc.merge(JetInputCfg(flags, cst.EMTopo))
23 
24  # Get the pseudo jets for this input
25  acc.addEventAlgo(getConstitPJGAlg(cst.EMTopo))
26 
27  return acc
28 
29 def NFlowInputAlgCfg(flags, name='NFlowInputAlg', **kwargs):
30 
31  mlog = logging.getLogger(name)
32  mlog.info('Starting input building for neutral eflow isolation density configuration')
33 
34  acc = ComponentAccumulator()
35 
36  from JetRecConfig.StandardJetConstits import stdConstitDic as cst
37  from JetRecConfig.JetRecConfig import JetInputCfg
38 
39  # Get the input (FlowObject, with CHS and origin (for neutral) and weight (for charged) correction)
40  if 'InputType' not in kwargs:
41  kwargs['InputType'] = 'EMPFlow'
42  cstI = cst[kwargs['InputType']]
43  acc.merge(JetInputCfg(flags, cstI))
44 
45  cstO = cstI.containername[0:cstI.containername.find('ParticleFlowObjects')]
46  mlog.info('Configuring density for type '+cstO)
47  cstOs = cstO if cstO != 'CHS' else ''
48 
49  # Then transform into pseudo-jets for the neutral only
50  constitpjalg = CompFactory.PseudoJetAlgorithm(
51  name = "PseudoJetAlgForIso"+cstOs+"NFlow",
52  InputContainer = cstO+"NeutralParticleFlowObjects",
53  OutputContainer = "PseudoJet"+cstOs+"NFlow",
54  Label = "EM"+cstOs+"NPFlow",
55  SkipNegativeEnergy=True)
56 
57  # Add the algs to the sequence in the ComponentAccumulator
58  acc.addEventAlgo(constitpjalg)
59 
60  return acc
61 
62 
63 def DensityForIsoAlgCfg(flags, name = "CentralDensityForTopoIso", **kwargs):
64 
65  mlog = logging.getLogger(name)
66  mlog.info('Starting density alg for isolation configuration')
67 
68  acc = ComponentAccumulator()
69 
70  # And then the density tool and algs. By default the central one
71  if name.find('Topo') >= 0:
72  inputO = 'PseudoJetEMTopoClusters'
73  outputS = 'TopoCluster'
74  elif name.find('NFlow') >= 0:
75  suff = 'CSSK' if name.find('CSSK') >= 0 else ''
76  inputO = 'PseudoJet'+suff+'NFlow'
77  outputS = 'NeutralParticle'+suff+'Flow'
78  kwargs['InputContainer'] = inputO
79  kwargs['JetRadius'] = 0.5
80  kwargs['UseFourMomArea'] = True
81  kwargs['VoronoiRfact'] = 0.9
82  kwargs['JetAlgorithm'] = 'Kt'
83  if name.find('Central') >= 0:
84  kwargs['OutputContainer'] = outputS+'IsoCentralEventShape'
85  kwargs['AbsRapidityMin'] = 0.0
86  kwargs['AbsRapidityMax'] = 1.5
87  elif name.find('Forward') >= 0:
88  kwargs['OutputContainer'] = outputS+'IsoForwardEventShape'
89  kwargs['AbsRapidityMin'] = 1.5
90  kwargs['AbsRapidityMax'] = 3.0
91  densityTool = CompFactory.EventDensityTool(
92  name = name+'Tool',**kwargs)
93 
94  densityAlg = CompFactory.EventDensityAthAlg(
95  name = name+'Alg',
96  EventDensityTool = densityTool)
97  acc.addEventAlgo(densityAlg)
98 
99  return acc
100 
101 
102 if __name__ == "__main__":
103  from AthenaConfiguration.AllConfigFlags import initConfigFlags
104  from AthenaConfiguration.ComponentAccumulator import printProperties
105  from AthenaConfiguration.TestDefaults import defaultTestFiles
106  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
107  flags = initConfigFlags()
108  flags.Input.Files = defaultTestFiles.RDO_RUN2
109  flags.Output.doWriteESD = True # To test the ESD parts
110  flags.Output.doWriteAOD = True # To test the AOD parts
111  flags.lock()
112 
113  mlog = logging.getLogger("densityForIsolationConfigTest")
114  mlog.info("Configuring density for isolation: ")
115 
116  acc = MainServicesCfg(flags)
117  acc.merge(EMTopoInputAlgCfg(flags))
118  acc.merge(DensityForIsoAlgCfg(flags))
119  acc.merge(DensityForIsoAlgCfg(flags, name='ForwardDensityForIso'))
120  acc.merge(NFlowInputAlgCfg(flags))
121  acc.merge(DensityForIsoAlgCfg(flags,name='CentralDensityForNFlowIso'))
122  printProperties(mlog,
123  acc.getEventAlgo('CentralDensityForTopoIsoAlg'),
124  nestLevel=1,
125  printDefaults=True)
126  printProperties(mlog,
127  acc.getEventAlgo('JetModAlgForIsoNFlow'),
128  nestLevel=1,
129  printDefaults=True)
130 
131  with open("isolationdensityconfig.pkl", "wb") as f:
132  acc.store(f)
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
IsoDensityConfig.NFlowInputAlgCfg
def NFlowInputAlgCfg(flags, name='NFlowInputAlg', **kwargs)
Definition: IsoDensityConfig.py:29
IsoDensityConfig.DensityForIsoAlgCfg
def DensityForIsoAlgCfg(flags, name="CentralDensityForTopoIso", **kwargs)
Definition: IsoDensityConfig.py:63
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
IsoDensityConfig.EMTopoInputAlgCfg
def EMTopoInputAlgCfg(flags, name='EMTopoInputAlg', **kwargs)
Definition: IsoDensityConfig.py:11
python.JetRecConfig.getConstitPJGAlg
def getConstitPJGAlg(constitdef, suffix=None, flags=None, parent_jetdef=None)
Definition: JetRecConfig.py:350
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
JetRecAlgTestCfg.JetInputCfg
def JetInputCfg(flags)
Definition: JetRecAlgTestCfg.py:44