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