41def EGAM12KernelCfg(flags, name="EGAM12Kernel", **kwargs):
42 """Configure the derivation framework driving algorithm (kernel)
43 for EGAM12"""
44 acc = ComponentAccumulator()
45
46
47 from JetRecConfig.StandardSmallRJets import (
48 AntiKt4EMTopo,
49 AntiKt4PV0Track,
50 AntiKt4Truth,
51 )
52 from JetRecConfig.JetRecConfig import JetRecCfg
53
54 jetList = [AntiKt4EMTopo, AntiKt4PV0Track, AntiKt4Truth]
55 for jd in jetList:
56 acc.merge(JetRecCfg(flags, jd))
57 JetKey = "AntiKt4EMTopoJets"
58
59
60
61
62
63
64 from DerivationFrameworkInDet.InDetCommonConfig import InDetCommonCfg
65 from DerivationFrameworkMuons.MuonsCommonConfig import MuonsCommonCfg
66 from DerivationFrameworkEGamma.EGammaCommonConfig import EGammaCommonCfg
67
68 TrackingFlags = flags.Tracking
69
70 acc.merge(
71 InDetCommonCfg(
72 flags,
73 DoVertexFinding=TrackingFlags.doVertexFinding,
74 AddPseudoTracks=TrackingFlags.doPseudoTracking,
75 DecoLRTTTVA=False,
76 DoR3LargeD0=TrackingFlags.doLargeD0,
77 StoreSeparateLargeD0Container=TrackingFlags.storeSeparateLargeD0Container,
78 MergeLRT=False,
79 )
80 )
81 acc.merge(MuonsCommonCfg(flags))
82 acc.merge(EGammaCommonCfg(flags))
83
84
85
86
87
88
89
90
91 from JetJvtEfficiency.JetJvtEfficiencyToolConfig import getJvtSelToolCfg
92
93 algName = "DFJet_EventCleaning_passJvtAlg"
94 passJvtTool = acc.popToolsAndMerge(getJvtSelToolCfg(flags, "AntiKt4EMTopoJets"))
95 passJvtTool.PassFlagName = "DFCommonJets_passJvt"
96 acc.addEventAlgo(
97 CompFactory.JetDecorationAlg(
98 algName, JetContainer="AntiKt4EMTopoJets", Decorators=[passJvtTool]
99 )
100 )
101
102
103
104 from AssociationUtils.AssociationUtilsConfig import OverlapRemovalToolCfg
105
106 outputLabel = "DFCommonJets_passOR_EMTopo"
107 bJetLabel = ""
108 tauLabel = ""
109 tauKey = ""
110 orTool = acc.popToolsAndMerge(
111 OverlapRemovalToolCfg(
112 flags, outputLabel=outputLabel, bJetLabel=bJetLabel, doTaus=False
113 )
114 )
115 algOR = CompFactory.OverlapRemovalGenUseAlg(
116 "OverlapRemovalGenUseAlg",
117 OverlapLabel=outputLabel,
118 OverlapRemovalTool=orTool,
119 TauKey=tauKey,
120 TauLabel=tauLabel,
121 BJetLabel=bJetLabel,
122 )
123 acc.addEventAlgo(algOR)
124
125
126 from JetSelectorTools.JetSelectorToolsConfig import (
127 EventCleaningToolCfg,
128 JetCleaningToolCfg,
129 )
130
131 workingPoints = ["Loose"]
132 prefix = "DFCommonJets_"
133
134 for wp in workingPoints:
135 cleaningLevel = wp + "Bad"
136
137 if "LLP" in wp:
138 cleaningLevel = wp.replace("LLP", "BadLLP")
139
140 jetCleaningTool = acc.popToolsAndMerge(
141 JetCleaningToolCfg(
142 flags,
143 "JetCleaningTool_" + cleaningLevel,
144 "AntiKt4EMTopoJets",
145 cleaningLevel,
146 False,
147 )
148 )
149 acc.addPublicTool(jetCleaningTool)
150
151 ecTool = acc.popToolsAndMerge(
152 EventCleaningToolCfg(flags, "EventCleaningTool_" + wp, cleaningLevel)
153 )
154 ecTool.JetCleanPrefix = prefix
155 ecTool.OrDecorator = "passOR_EMTopo"
156 ecTool.JetContainer = "AntiKt4EMTopoJets"
157 ecTool.JetCleaningTool = jetCleaningTool
158 acc.addPublicTool(ecTool)
159
160
161
162 eventCleanAlg = CompFactory.EventCleaningTestAlg(
163 "EventCleaningTestAlg_" + wp,
164 EventCleaningTool=ecTool,
165 JetCollectionName="AntiKt4EMTopoJets",
166 EventCleanPrefix=prefix,
167 CleaningLevel=cleaningLevel,
168 doEvent=("Loose" in wp),
169 )
170 acc.addEventAlgo(eventCleanAlg)
171
172
173 augmentationTools = []
174
175
176
177
178 if addCaloDecorations:
179 from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import (
180 CaloDecoratorKernelCfg)
181 acc.merge(CaloDecoratorKernelCfg(flags))
182
183
184 thinningTools = []
185 streamName = kwargs["StreamName"]
186
187
188 if flags.Derivation.Egamma.doTrackThinning:
189 from DerivationFrameworkInDet.InDetToolsConfig import (
190 TrackParticleThinningCfg,
191 MuonTrackParticleThinningCfg,
192 TauTrackParticleThinningCfg,
193 )
194
195 TrackThinningKeepElectronTracks = True
196 TrackThinningKeepPhotonTracks = True
197 TrackThinningKeepAllElectronTracks = False
198 TrackThinningKeepJetTracks = False
199 TrackThinningKeepMuonTracks = False
200 TrackThinningKeepTauTracks = False
201 TrackThinningKeepPVTracks = False
202
203
204 if TrackThinningKeepElectronTracks:
205 EGAM12ElectronTPThinningTool = (
206 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
207 name="EGAM12ElectronTPThinningTool",
208 StreamName=streamName,
209 SGKey="Electrons",
210 GSFTrackParticlesKey="GSFTrackParticles",
211 InDetTrackParticlesKey="InDetTrackParticles",
212 SelectionString="Electrons.pt > 0*GeV",
213 BestMatchOnly=True,
214 ConeSize=0.3,
215 )
216 )
217 acc.addPublicTool(EGAM12ElectronTPThinningTool)
218 thinningTools.append(EGAM12ElectronTPThinningTool)
219
220
221
222 if TrackThinningKeepAllElectronTracks:
223 EGAM12ElectronTPThinningTool2 = (
224 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
225 name="EGAM12ElectronTPThinningTool2",
226 StreamName=streamName,
227 SGKey="Electrons",
228 GSFTrackParticlesKey="GSFTrackParticles",
229 InDetTrackParticlesKey="InDetTrackParticles",
230 SelectionString="Electrons.pt > 4*GeV",
231 BestMatchOnly=False,
232 ConeSize=0.6,
233 )
234 )
235 acc.addPublicTool(EGAM12ElectronTPThinningTool2)
236 thinningTools.append(EGAM12ElectronTPThinningTool2)
237
238
239 if TrackThinningKeepPhotonTracks:
240 EGAM12PhotonTPThinningTool = (
241 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
242 name="EGAM12PhotonTPThinningTool",
243 StreamName=streamName,
244 SGKey="Photons",
245 GSFTrackParticlesKey="GSFTrackParticles",
246 InDetTrackParticlesKey="InDetTrackParticles",
247 GSFConversionVerticesKey="GSFConversionVertices",
248 SelectionString="Photons.pt > 0*GeV",
249 BestMatchOnly=True,
250 ConeSize=0.3,
251 )
252 )
253 acc.addPublicTool(EGAM12PhotonTPThinningTool)
254 thinningTools.append(EGAM12PhotonTPThinningTool)
255
256
257 if TrackThinningKeepJetTracks:
258 EGAM12JetTPThinningTool = (
259 CompFactory.DerivationFramework.JetTrackParticleThinning(
260 name="EGAM12JetTPThinningTool",
261 StreamName=streamName,
262 JetKey=JetKey,
263 InDetTrackParticlesKey="InDetTrackParticles",
264 )
265 )
266 acc.addPublicTool(EGAM12JetTPThinningTool)
267 thinningTools.append(EGAM12JetTPThinningTool)
268
269
270 if TrackThinningKeepMuonTracks:
271 EGAM12MuonTPThinningTool = acc.getPrimaryAndMerge(
272 MuonTrackParticleThinningCfg(
273 flags,
274 name="EGAM12MuonTPThinningTool",
275 StreamName=streamName,
276 MuonKey="Muons",
277 InDetTrackParticlesKey="InDetTrackParticles",
278 )
279 )
280 thinningTools.append(EGAM12MuonTPThinningTool)
281
282
283 if TrackThinningKeepTauTracks:
284 EGAM12TauTPThinningTool = acc.getPrimaryAndMerge(
285 TauTrackParticleThinningCfg(
286 flags,
287 name="EGAM12TauTPThinningTool",
288 StreamName=streamName,
289 TauKey="TauJets",
290 ConeSize=0.6,
291 InDetTrackParticlesKey="InDetTrackParticles",
292 DoTauTracksThinning=True,
293 TauTracksKey="TauTracks",
294 )
295 )
296 thinningTools.append(EGAM12TauTPThinningTool)
297
298
299 thinning_expression = " && ".join(
300 [
301 "(InDetTrackParticles.DFCommonTightPrimary)",
302 "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)",
303 "(InDetTrackParticles.pt>10*GeV)",
304 ]
305 )
306 if TrackThinningKeepPVTracks:
307 EGAM12TPThinningTool = acc.getPrimaryAndMerge(
308 TrackParticleThinningCfg(
309 flags,
310 name="EGAM12TPThinningTool",
311 StreamName=streamName,
312 SelectionString=thinning_expression,
313 InDetTrackParticlesKey="InDetTrackParticles",
314 )
315 )
316 thinningTools.append(EGAM12TPThinningTool)
317
318
319 if flags.Input.isMC:
320
321 truth_cond_WZH = " && ".join(
322 ["(abs(TruthParticles.pdgId) >= 23)", "(abs(TruthParticles.pdgId) <= 25)"]
323 )
324
325 truth_cond_lep = " && ".join(
326 ["(abs(TruthParticles.pdgId) >= 11)", "(abs(TruthParticles.pdgId) <= 16)"]
327 )
328
329 truth_cond_top = "(abs(TruthParticles.pdgId) == 6)"
330
331 truth_cond_gam = " && ".join(
332 ["(abs(TruthParticles.pdgId) == 22)", "(TruthParticles.pt > 1*GeV)"]
333 )
334
335 truth_cond_finalState = "(TruthParticles.isGenStable)"
336 truth_expression = (
337 "( "
338 + truth_cond_WZH
339 + " ) || "
340 + "( "
341 + truth_cond_lep
342 + " ) || "
343 + "( "
344 + truth_cond_top
345 + " ) || "
346 + "( "
347 + truth_cond_gam
348 + " ) || "
349 + "( "
350 + truth_cond_finalState
351 + " )"
352 )
353 print(
"EGAM12 truth thinning expression: ", truth_expression)
354
355 EGAM12TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning(
356 name="EGAM12TruthThinningTool",
357 StreamName=streamName,
358 ParticleSelectionString=truth_expression,
359 PreserveDescendants=False,
360 PreserveGeneratorDescendants=True,
361 PreserveAncestors=True,
362 )
363 acc.addPublicTool(EGAM12TruthThinningTool)
364 thinningTools.append(EGAM12TruthThinningTool)
365
366
367 skimmingTool = acc.getPrimaryAndMerge(EGAM12SkimmingToolCfg(flags))
368
369
370 acc.addEventAlgo(
371 CompFactory.DerivationFramework.DerivationKernel(
372 name,
373 SkimmingTools=[skimmingTool],
374 AugmentationTools=augmentationTools,
375 ThinningTools=thinningTools,
376 )
377 )
378
379 return acc
380
381