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