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