ATLAS Offline Software
Loading...
Searching...
No Matches
PFRun3Config.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
3from AthenaConfiguration.ComponentFactory import CompFactory
4from AthenaConfiguration.Enums import Format
5
6
7#This configures pflow + everything it needs
8def PFFullCfg(inputFlags,runTauReco=False,**kwargs):
9
10 result=ComponentAccumulator()
11
12 StoreGateSvc=CompFactory.StoreGateSvc
13 result.addService(StoreGateSvc("DetectorStore"))
14
15 #Alias calibrated topoclusters, if they exist already, such that overwrite won't fail
16 from SGComps.AddressRemappingConfig import InputRenameCfg
17 result.merge(InputRenameCfg("xAOD::CaloClusterContainer","CaloCalTopoClusters",""))
18
19 #This is needed to ensure the convertor is correctly configured for each LHC period
20 #Otherwise a default convertor is provided that is not correctly configured for e.g Run4
21 from TrkEventCnvTools.TrkEventCnvToolsConfig import TrkEventCnvSuperToolCfg
22 result.merge(TrkEventCnvSuperToolCfg(inputFlags))
23
24 #setup magnetic field service
25 from MagFieldServices.MagFieldServicesConfig import AtlasFieldCacheCondAlgCfg
26 result.merge(AtlasFieldCacheCondAlgCfg(inputFlags))
27
28 #Configure topocluster algorithmsm, and associated conditions
29 from CaloRec.CaloTopoClusterConfig import CaloTopoClusterCfg
30 result.merge(CaloTopoClusterCfg(inputFlags))
31
32 from CaloTools.CaloNoiseCondAlgConfig import CaloNoiseCondAlgCfg
33 result.merge(CaloNoiseCondAlgCfg(inputFlags,"totalNoise"))
34 result.merge(CaloNoiseCondAlgCfg(inputFlags,"electronicNoise"))
35
36 #Cache the track extrapolations
37 from TrackToCalo.CaloExtensionBuilderAlgCfg import CaloExtensionBuilderAlgCfg
38 # FIXME: This inversion to merge in CAs is a workaround, which can be removed once SiDetElementCondAlgs
39 # don't depend on Muons/TRT/alignment/otherSiSubdetectorAlignment anymore.
40 tempCA = CaloExtensionBuilderAlgCfg(inputFlags)
41 tempCA.merge(result)
42 result = tempCA
43
44 from OutputStreamAthenaPool.OutputStreamConfig import addToAOD, addToESD
45 #PFlow requires tracks, electrons, photons, muons and taus in order to have valid links to them. So lets add these objects to the AOD and ESD
46 #PFlow also requires calo clusters for links to work, but these are added to output streams elsewhere already
47 toESDAndAOD = ["xAOD::TrackParticleContainer#InDetTrackParticles","xAOD::TrackParticleAuxContainer#InDetTrackParticlesAux."]
48 if inputFlags.PF.useElPhotLinks:
49 toESDAndAOD += ["xAOD::ElectronContainer#Electrons","xAOD::ElectronAuxContainer#ElectronsAux."]
50 toESDAndAOD += ["xAOD::PhotonContainer#Photons","xAOD::PhotonAuxContainer#PhotonsAux."]
51 if inputFlags.PF.useMuLinks:
52 toESDAndAOD += ["xAOD::MuonContainer#Muons","xAOD::MuonAuxContainer#MuonsAux."]
53 #If we rerun tau reco then it adds taus to the output itself, which results in an error message
54 #because you cannot mix +ve and -ve aux attributes (the below is considered +ve as a default).
55 if not runTauReco:
56 toESDAndAOD += ["xAOD::TauJetContainer#TauJets","xAOD::TauJetAuxContainer#TauJetsAux."]
57
58 result.merge(addToESD(inputFlags, toESDAndAOD))
59 result.merge(addToAOD(inputFlags, toESDAndAOD))
60
61 result.merge(PFCfg(inputFlags))
62 return result
63
64#Configures only the pflow algorithms and tools - to be used from RecExCommon to avoid
65#conflicts or if you only want to configure just the pflow algorithms and tools
66def PFCfg(inputFlags,**kwargs):
67
68 result=ComponentAccumulator()
69
70 #Configure the pflow algorithms
71 PFLeptonSelectorFactory=CompFactory.PFLeptonSelector
72 PFLeptonSelector = PFLeptonSelectorFactory("PFLeptonSelector")
73 PFLeptonSelector.selectElectrons=False
74 PFLeptonSelector.selectMuons=False
75 result.addEventAlgo(PFLeptonSelector)
76
77 from eflowRec.PFCfg import PFTrackSelectorAlgCfg
78 useCaching = True
79 #If reading ESD/AOD do not make use of caching of track extrapolations.
80 if inputFlags.Input.Format is Format.POOL and "StreamRDO" not in inputFlags.Input.ProcessingTags:
81 useCaching = False
82 result.merge(PFTrackSelectorAlgCfg(inputFlags,"PFTrackSelector",useCaching))
83
84 from eflowRec.PFCfg import getOfflinePFAlgorithm
85 result.merge(getOfflinePFAlgorithm(inputFlags))
86
87 from eflowRec.PFCfg import getChargedFlowElementCreatorAlgorithm,getNeutralFlowElementCreatorAlgorithm,getLCNeutralFlowElementCreatorAlgorithm
88 result.addEventAlgo(getChargedFlowElementCreatorAlgorithm(inputFlags,""))
89 result.addEventAlgo(getNeutralFlowElementCreatorAlgorithm(inputFlags,""))
90 result.addEventAlgo(getLCNeutralFlowElementCreatorAlgorithm(inputFlags,""))
91
92 #Only do linking if not in eoverp mode
93 if not inputFlags.PF.EOverPMode:
94 if inputFlags.PF.useElPhotLinks:
95 from eflowRec.PFCfg import getEGamFlowElementAssocAlgorithm
96 result.addEventAlgo(getEGamFlowElementAssocAlgorithm(inputFlags))
97
98 if inputFlags.PF.useMuLinks and inputFlags.Detector.GeometryMuon:
99 from eflowRec.PFCfg import getMuonFlowElementAssocAlgorithm
100 result.addEventAlgo(getMuonFlowElementAssocAlgorithm(inputFlags))
101
102 from OutputStreamAthenaPool.OutputStreamConfig import addToAOD, addToESD
103 toESDAndAOD = ""
104 if(inputFlags.PF.EOverPMode):
105 toESDAndAOD = ["xAOD::FlowElementContainer#EOverPChargedParticleFlowObjects","xAOD::FlowElementAuxContainer#EOverPChargedParticleFlowObjectsAux."]
106 toESDAndAOD += ["xAOD::FlowElementContainer#EOverPNeutralParticleFlowObjects","xAOD::FlowElementAuxContainer#EOverPNeutralParticleFlowObjectsAux."]
107 else:
108 toESDAndAOD = ["xAOD::FlowElementContainer#JetETMissChargedParticleFlowObjects", "xAOD::FlowElementAuxContainer#JetETMissChargedParticleFlowObjectsAux."]
109 toESDAndAOD += ["xAOD::FlowElementContainer#JetETMissNeutralParticleFlowObjects","xAOD::FlowElementAuxContainer#JetETMissNeutralParticleFlowObjectsAux.-FEShowerSubtractedClusterLink"]
110 toESDAndAOD += ["xAOD::FlowElementContainer#JetETMissLCNeutralParticleFlowObjects","xAOD::ShallowAuxContainer#JetETMissLCNeutralParticleFlowObjectsAux."]
111
112 if inputFlags.PF.addCPData:
113 #if CPData mode, then add PFCaloCluster to ESD and AOD
114 #PFCaloCluster are the clusters modified by the PFlow algorithm
115 toESDAndAOD += ["xAOD::CaloClusterContainer#PFCaloCluster","xAOD::CaloClusterAuxContainer#PFCaloClusterAux."]
116 #also schedule an algoroithm to decorate each calo cluster with the cluster width in eta and phi
117 #this allows clients of the AOD to calculate deltaRPrime for track-calocluster pairs.
118 PFClusterWidthDecorator = CompFactory.PFClusterWidthDecorator()
119 result.addEventAlgo(PFClusterWidthDecorator)
120 #For the CP data we need to keep all the CaloCells and write to AOD
121 from TrigGepPerf.KeepCellsConfig import KeepCellsCfg
122 result.merge(KeepCellsCfg(inputFlags))
123 toESDAndAOD += ["CaloCellContainer#AllCalo"]
124
125 result.merge(addToESD(inputFlags, toESDAndAOD))
126 result.merge(addToAOD(inputFlags, toESDAndAOD))
127
128 #In some workflows we may need to disable this
129 #e.g if running in e/p mode where the standard containers are not produced
130 if inputFlags.PF.doThinning:
131 from ThinningUtils.ThinNegativeEnergyNeutralPFOCfg import ThinNegativeEnergyNeutralPFOCfg
132 result.merge(ThinNegativeEnergyNeutralPFOCfg(inputFlags))
133
134 return result
135
136#Configure tau-FE link algorithm - this cannot be in PFCfg because
137#pflow runs before taus in standard serial reco. Thus the links
138#between taus and FE must happen after tau reco.
139def PFTauFELinkCfg(inputFlags,**kwargs):
140 result=ComponentAccumulator()
141 from eflowRec.PFCfg import getTauFlowElementAssocAlgorithm
142 result.addEventAlgo(getTauFlowElementAssocAlgorithm(inputFlags))
143 return result
144
145# Builder for ML-based neutral flow element creator algorithm
147 result=ComponentAccumulator()
148 from eflowRec.PFCfg import getPFOClusterMLCorrectionAlgorithmCfg, getNeutralPFOClusterMLCorrectionToolCfg
149
150 alg = getPFOClusterMLCorrectionAlgorithmCfg(inputFlags, inputNameBase = "Global", outputNameBase = "GlobalClusterMLCorrected")
151 correctionTool_cfg = getNeutralPFOClusterMLCorrectionToolCfg(
152 inputFlags,
153 toolName = "NeutralPFOClusterMLCorrectionTool",
154 clusterMLCorrectedEnergyDecorationKey = "clusterE_ML"
155 )
156 alg.PFOContainerCorrectionTool = result.popToolsAndMerge(correctionTool_cfg)
157
158 result.addEventAlgo(alg)
159 return result
160
161# Run with python -m eflowRec.PFRun3Config
162def PFRun3ConfigTest(flags=None):
163
164 if flags is None:
165 from AthenaConfiguration.AllConfigFlags import initConfigFlags
166 flags = initConfigFlags()
167
168 from AthenaConfiguration.TestDefaults import defaultTestFiles, defaultConditionsTags
169 flags.Input.Files = defaultTestFiles.ESD_RUN3_MC
170 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN3_MC
171 flags.Output.doWriteAOD=True
172 flags.Output.AODFileName="output_AOD.root"
173
174 flags.fillFromArgs()
175 flags.lock()
176
177 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
178 cfg=MainServicesCfg(flags)
179
180 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
181 cfg.merge(PoolReadCfg(flags))
182 cfg.merge(PFFullCfg(flags))
183
184 from eflowRec.PFRun3Remaps import ListRemaps
185
186 list_remaps=ListRemaps(cfg, 'AOD' if flags.Output.doWriteAOD else [])
187 for mapping in list_remaps:
188 cfg.merge(mapping)
189
190 cfg.run()
191
192if __name__=="__main__":
if(febId1==febId2)
The Athena Transient Store API.
Definition PFCfg.py:1
PFRun3ConfigTest(flags=None)
PFTauFELinkCfg(inputFlags, **kwargs)
PFFullCfg(inputFlags, runTauReco=False, **kwargs)
PFOClusterMLCorrectionAlgorithmBuilder(inputFlags, spec)