124def EGAM8KernelCfg(flags, name="EGAM8Kernel", **kwargs):
125 """Configure the derivation framework driving algorithm (kernel)
126 for EGAM8"""
127 acc = ComponentAccumulator()
128
129
130 from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg
131
132 acc.merge(
133 PhysCommonAugmentationsCfg(
134 flags, TriggerListsHelper=kwargs["TriggerListsHelper"]
135 )
136 )
137
138
139 augmentationTools = []
140
141
142
143
144 EGAM8ZeeMassTool = acc.popToolsAndMerge(EGAM8ZeeMassToolCfg(flags))
145 acc.addPublicTool(EGAM8ZeeMassTool)
146 augmentationTools.append(EGAM8ZeeMassTool)
147
148 EGAM8ZmueMassTool = acc.popToolsAndMerge(EGAM8ZmueMassToolCfg(flags))
149 acc.addPublicTool(EGAM8ZmueMassTool)
150 augmentationTools.append(EGAM8ZmueMassTool)
151
152
153
154
155 from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import (
156 CaloDecoratorKernelCfg)
157 acc.merge(CaloDecoratorKernelCfg(flags))
158
159 from DerivationFrameworkEGamma.EGammaToolsConfig import (
160 EGammaCookieCutClusterToolCfg)
161 cookieCutTool = acc.popToolsAndMerge(
162 EGammaCookieCutClusterToolCfg(flags,
163 name,
164 StoreInputMoments=True,
165 StoreCookedMoments=True))
166 acc.addPublicTool(cookieCutTool)
167 augmentationTools.append(cookieCutTool)
168
169
170 thinningTools = []
171 streamName = kwargs["StreamName"]
172
173
174 if flags.Derivation.Egamma.doTrackThinning:
175 from DerivationFrameworkInDet.InDetToolsConfig import (
176 TrackParticleThinningCfg,
177 MuonTrackParticleThinningCfg,
178 TauTrackParticleThinningCfg,
179 )
180
181 TrackThinningKeepElectronTracks = True
182 TrackThinningKeepPhotonTracks = True
183 TrackThinningKeepAllElectronTracks = False
184 TrackThinningKeepJetTracks = False
185 TrackThinningKeepMuonTracks = True
186 TrackThinningKeepTauTracks = False
187 TrackThinningKeepPVTracks = False
188
189
190 if TrackThinningKeepElectronTracks:
191 EGAM8ElectronTPThinningTool = (
192 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
193 name="EGAM8ElectronTPThinningTool",
194 StreamName=streamName,
195 SGKey="Electrons",
196 GSFTrackParticlesKey="GSFTrackParticles",
197 InDetTrackParticlesKey="InDetTrackParticles",
198 SelectionString="Electrons.pt > 0*GeV",
199 BestMatchOnly=True,
200 ConeSize=0.3,
201 )
202 )
203 acc.addPublicTool(EGAM8ElectronTPThinningTool)
204 thinningTools.append(EGAM8ElectronTPThinningTool)
205
206
207
208 if TrackThinningKeepAllElectronTracks:
209 EGAM8ElectronTPThinningTool2 = (
210 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
211 name="EGAM8ElectronTPThinningTool2",
212 StreamName=streamName,
213 SGKey="Electrons",
214 GSFTrackParticlesKey="GSFTrackParticles",
215 InDetTrackParticlesKey="InDetTrackParticles",
216 SelectionString="Electrons.pt > 4*GeV",
217 BestMatchOnly=False,
218 ConeSize=0.6,
219 )
220 )
221 acc.addPublicTool(EGAM8ElectronTPThinningTool2)
222 thinningTools.append(EGAM8ElectronTPThinningTool2)
223
224
225 if TrackThinningKeepPhotonTracks:
226 EGAM8PhotonTPThinningTool = (
227 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
228 name="EGAM8PhotonTPThinningTool",
229 StreamName=streamName,
230 SGKey="Photons",
231 GSFTrackParticlesKey="GSFTrackParticles",
232 InDetTrackParticlesKey="InDetTrackParticles",
233 GSFConversionVerticesKey="GSFConversionVertices",
234 SelectionString="Photons.pt > 0*GeV",
235 BestMatchOnly=True,
236 ConeSize=0.3,
237 )
238 )
239 acc.addPublicTool(EGAM8PhotonTPThinningTool)
240 thinningTools.append(EGAM8PhotonTPThinningTool)
241
242
243 if TrackThinningKeepJetTracks:
244 EGAM8JetTPThinningTool = (
245 CompFactory.DerivationFramework.JetTrackParticleThinning(
246 name="EGAM8JetTPThinningTool",
247 StreamName=streamName,
248 JetKey="AntiKt4EMPFlowJets",
249 InDetTrackParticlesKey="InDetTrackParticles",
250 )
251 )
252 acc.addPublicTool(EGAM8JetTPThinningTool)
253 thinningTools.append(EGAM8JetTPThinningTool)
254
255
256 if TrackThinningKeepMuonTracks:
257 EGAM8MuonTPThinningTool = acc.getPrimaryAndMerge(
258 MuonTrackParticleThinningCfg(
259 flags,
260 name="EGAM8MuonTPThinningTool",
261 StreamName=streamName,
262 MuonKey="Muons",
263 InDetTrackParticlesKey="InDetTrackParticles",
264 )
265 )
266 thinningTools.append(EGAM8MuonTPThinningTool)
267
268
269 if TrackThinningKeepTauTracks:
270 EGAM8TauTPThinningTool = acc.getPrimaryAndMerge(
271 TauTrackParticleThinningCfg(
272 flags,
273 name="EGAM8TauTPThinningTool",
274 StreamName=streamName,
275 TauKey="TauJets",
276 ConeSize=0.6,
277 InDetTrackParticlesKey="InDetTrackParticles",
278 DoTauTracksThinning=True,
279 TauTracksKey="TauTracks",
280 )
281 )
282 thinningTools.append(EGAM8TauTPThinningTool)
283
284
285 thinning_expression = " && ".join(
286 [
287 "(InDetTrackParticles.DFCommonTightPrimary)",
288 "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3.0*mm)",
289 "(InDetTrackParticles.pt>10*GeV)",
290 ]
291 )
292 if TrackThinningKeepPVTracks:
293 EGAM8TPThinningTool = acc.getPrimaryAndMerge(
294 TrackParticleThinningCfg(
295 flags,
296 name="EGAM8TPThinningTool",
297 StreamName=streamName,
298 SelectionString=thinning_expression,
299 InDetTrackParticlesKey="InDetTrackParticles",
300 )
301 )
302 thinningTools.append(EGAM8TPThinningTool)
303
304
305 if flags.Input.isMC:
306
307 truth_cond_WZH = " && ".join(
308 ["(abs(TruthParticles.pdgId) >= 23)", "(abs(TruthParticles.pdgId) <= 25)"]
309 )
310
311 truth_cond_lep = " && ".join(
312 ["(abs(TruthParticles.pdgId) >= 11)", "(abs(TruthParticles.pdgId) <= 16)"]
313 )
314
315 truth_cond_top = "(abs(TruthParticles.pdgId) == 6)"
316
317 truth_cond_gam = " && ".join(
318 ["(TruthParticles.isPhoton)", "(TruthParticles.pt > 1*GeV)"]
319 )
320
321 truth_cond_finalState = " && ".join(
322 ["(TruthParticles.isGenStable)", "(!TruthParticles.isSimulationParticle)"]
323 )
324 truth_expression = (
325 "( "
326 + truth_cond_WZH
327 + " ) || "
328 + "( "
329 + truth_cond_lep
330 + " ) || "
331 + "( "
332 + truth_cond_top
333 + " ) || "
334 + "( "
335 + truth_cond_gam
336 + " ) || "
337 + "( "
338 + truth_cond_finalState
339 + " )"
340 )
341 print(
"EGAM8 truth thinning expression: ", truth_expression)
342
343 EGAM8TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning(
344 name="EGAM8TruthThinningTool",
345 StreamName=streamName,
346 ParticleSelectionString=truth_expression,
347 PreserveDescendants=False,
348 PreserveGeneratorDescendants=True,
349 PreserveAncestors=True,
350 )
351 acc.addPublicTool(EGAM8TruthThinningTool)
352 thinningTools.append(EGAM8TruthThinningTool)
353
354
355 skimmingTool = acc.popToolsAndMerge(EGAM8SkimmingToolCfg(flags))
356 acc.addPublicTool(skimmingTool)
357
358
359 acc.addEventAlgo(
360 CompFactory.DerivationFramework.DerivationKernel(
361 name,
362 SkimmingTools=[skimmingTool],
363 AugmentationTools=augmentationTools,
364 ThinningTools=thinningTools,
365 )
366 )
367
368 return acc
369
370