88def EGAM9KernelCfg(flags, name="EGAM9Kernel", **kwargs):
89 """Configure the derivation framework driving algorithm (kernel)
90 for EGAM9"""
91 acc = ComponentAccumulator()
92
93
94 from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg
95
96 acc.merge(
97 PhysCommonAugmentationsCfg(
98 flags, TriggerListsHelper=kwargs["TriggerListsHelper"]
99 )
100 )
101
102
103 augmentationTools = []
104
105
106
107
108 from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import (
109 CaloDecoratorKernelCfg)
110 acc.merge(CaloDecoratorKernelCfg(flags))
111
112
113 thinningTools = []
114 streamName = kwargs["StreamName"]
115
116
117 if flags.Derivation.Egamma.doTrackThinning:
118 TrackThinningKeepElectronTracks = False
119 TrackThinningKeepPhotonTracks = True
120 TrackThinningKeepPVTracks = False
121
122
123 if TrackThinningKeepElectronTracks:
124 EGAM9ElectronTPThinningTool = (
125 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
126 name="EGAM9ElectronTPThinningTool",
127 StreamName=streamName,
128 SGKey="Electrons",
129 GSFTrackParticlesKey="GSFTrackParticles",
130 InDetTrackParticlesKey="InDetTrackParticles",
131 SelectionString="Electrons.pt > 0*GeV",
132 BestMatchOnly=True,
133 ConeSize=0.3,
134 )
135 )
136 acc.addPublicTool(EGAM9ElectronTPThinningTool)
137 thinningTools.append(EGAM9ElectronTPThinningTool)
138
139
140 if TrackThinningKeepPhotonTracks:
141 EGAM9PhotonTPThinningTool = (
142 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
143 name="EGAM9PhotonTPThinningTool",
144 StreamName=streamName,
145 SGKey="Photons",
146 GSFTrackParticlesKey="GSFTrackParticles",
147 InDetTrackParticlesKey="InDetTrackParticles",
148 GSFConversionVerticesKey="GSFConversionVertices",
149 SelectionString="Photons.pt > 0*GeV",
150 BestMatchOnly=True,
151 ConeSize=0.3,
152 )
153 )
154 acc.addPublicTool(EGAM9PhotonTPThinningTool)
155 thinningTools.append(EGAM9PhotonTPThinningTool)
156
157
158 thinning_expression = " && ".join(
159 [
160 "(InDetTrackParticles.DFCommonTightPrimary)",
161 "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)",
162 "(InDetTrackParticles.pt > 10*GeV)",
163 ]
164 )
165 if TrackThinningKeepPVTracks:
166 from DerivationFrameworkInDet.InDetToolsConfig import (
167 TrackParticleThinningCfg,
168 )
169
170 EGAM9TPThinningTool = acc.getPrimaryAndMerge(
171 TrackParticleThinningCfg(
172 flags,
173 name="EGAM9TPThinningTool",
174 StreamName=streamName,
175 SelectionString=thinning_expression,
176 InDetTrackParticlesKey="InDetTrackParticles",
177 )
178 )
179 thinningTools.append(EGAM9TPThinningTool)
180
181
182 if flags.Input.isMC:
183
184 truth_cond_WZH = " && ".join(
185 ["(abs(TruthParticles.pdgId) >= 23)", "(abs(TruthParticles.pdgId) <= 25)"]
186 )
187
188 truth_cond_lep = " && ".join(
189 ["(abs(TruthParticles.pdgId) >= 11)", "(abs(TruthParticles.pdgId) <= 16)"]
190 )
191
192 truth_cond_top = "(abs(TruthParticles.pdgId) == 6)"
193
194 truth_cond_gam = " && ".join(
195 ["(abs(TruthParticles.pdgId) == 22)", "(TruthParticles.pt > 1*GeV)"]
196 )
197
198 truth_cond_finalState = "(TruthParticles.isGenStable)"
199 truth_expression = (
200 "( "
201 + truth_cond_WZH
202 + " ) || "
203 + "( "
204 + truth_cond_lep
205 + " ) || "
206 + "( "
207 + truth_cond_top
208 + " ) || "
209 + "( "
210 + truth_cond_gam
211 + " ) || "
212 + "( "
213 + truth_cond_finalState
214 + " )"
215 )
216 print(
"EGAM9 truth thinning expression: ", truth_expression)
217
218 EGAM9TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning(
219 name="EGAM9TruthThinningTool",
220 StreamName=streamName,
221 ParticleSelectionString=truth_expression,
222 PreserveDescendants=False,
223 PreserveGeneratorDescendants=True,
224 PreserveAncestors=True,
225 )
226 acc.addPublicTool(EGAM9TruthThinningTool)
227 thinningTools.append(EGAM9TruthThinningTool)
228
229
230 if thinCells:
231 from DerivationFrameworkCalo.CaloCellDFGetterConfig import thinCaloCellsForDFCfg
232
233 acc.merge(
234 thinCaloCellsForDFCfg(
235 flags,
236 inputClusterKeys=["egammaClusters"],
237 streamName="StreamDAOD_EGAM9",
238 inputCellKey="AllCalo",
239 outputCellKey="DFEGAMCellContainer",
240 )
241 )
242
243
244 skimmingTool = acc.getPrimaryAndMerge(EGAM9SkimmingToolCfg(flags))
245
246
247 acc.addEventAlgo(
248 CompFactory.DerivationFramework.DerivationKernel(
249 name,
250 SkimmingTools=[skimmingTool],
251 AugmentationTools=augmentationTools,
252 ThinningTools=thinningTools,
253 )
254 )
255
256 return acc
257
258