77def EGAM7KernelCfg(flags, name="EGAM7Kernel", **kwargs):
78 """Configure the derivation framework driving algorithm (kernel)
79 for EGAM7"""
80 acc = ComponentAccumulator()
81
82
83 from JetRecConfig.StandardSmallRJets import AntiKt4PV0Track
84 from JetRecConfig.JetRecConfig import JetRecCfg
85
86 jetList = [AntiKt4PV0Track]
87 for jd in jetList:
88 acc.merge(JetRecCfg(flags, jd))
89
90
91 from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg
92
93 acc.merge(
94 PhysCommonAugmentationsCfg(
95 flags, TriggerListsHelper=kwargs["TriggerListsHelper"]
96 )
97 )
98
99
100 augmentationTools = []
101
102
103
104
105 from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import (
106 CaloDecoratorKernelCfg)
107 acc.merge(CaloDecoratorKernelCfg(flags))
108
109
110 thinningTools = []
111
112 streamName = kwargs["StreamName"]
113
114
115 if flags.Derivation.Egamma.doTrackThinning:
116 from DerivationFrameworkInDet.InDetToolsConfig import (
117 TrackParticleThinningCfg,
118 MuonTrackParticleThinningCfg,
119 TauTrackParticleThinningCfg,
120 )
121
122 TrackThinningKeepElectronTracks = True
123 TrackThinningKeepPhotonTracks = True
124 TrackThinningKeepAllElectronTracks = False
125 TrackThinningKeepJetTracks = False
126 TrackThinningKeepMuonTracks = False
127 TrackThinningKeepTauTracks = False
128 TrackThinningKeepPVTracks = False
129
130
131 if TrackThinningKeepElectronTracks:
132 EGAM7ElectronTPThinningTool = (
133 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
134 name="EGAM7ElectronTPThinningTool",
135 StreamName=streamName,
136 SGKey="Electrons",
137 GSFTrackParticlesKey="GSFTrackParticles",
138 InDetTrackParticlesKey="InDetTrackParticles",
139 SelectionString="Electrons.pt > 0*GeV",
140 BestMatchOnly=True,
141 ConeSize=0.3,
142 )
143 )
144 acc.addPublicTool(EGAM7ElectronTPThinningTool)
145 thinningTools.append(EGAM7ElectronTPThinningTool)
146
147
148
149 if TrackThinningKeepAllElectronTracks:
150 EGAM7ElectronTPThinningTool2 = (
151 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
152 name="EGAM7ElectronTPThinningTool2",
153 StreamName=streamName,
154 SGKey="Electrons",
155 GSFTrackParticlesKey="GSFTrackParticles",
156 InDetTrackParticlesKey="InDetTrackParticles",
157 SelectionString="Electrons.pt > 4*GeV",
158 BestMatchOnly=False,
159 ConeSize=0.6,
160 )
161 )
162 acc.addPublicTool(EGAM7ElectronTPThinningTool2)
163 thinningTools.append(EGAM7ElectronTPThinningTool2)
164
165
166 if TrackThinningKeepPhotonTracks:
167 EGAM7PhotonTPThinningTool = (
168 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
169 name="EGAM7PhotonTPThinningTool",
170 StreamName=streamName,
171 SGKey="Photons",
172 GSFTrackParticlesKey="GSFTrackParticles",
173 InDetTrackParticlesKey="InDetTrackParticles",
174 GSFConversionVerticesKey="GSFConversionVertices",
175 SelectionString="Photons.pt > 0*GeV",
176 BestMatchOnly=True,
177 ConeSize=0.3,
178 )
179 )
180 acc.addPublicTool(EGAM7PhotonTPThinningTool)
181 thinningTools.append(EGAM7PhotonTPThinningTool)
182
183
184 if TrackThinningKeepJetTracks:
185 EGAM7JetTPThinningTool = (
186 CompFactory.DerivationFramework.JetTrackParticleThinning(
187 name="EGAM7JetTPThinningTool",
188 StreamName=streamName,
189 JetKey="AntiKt4EMPFlowJets",
190 InDetTrackParticlesKey="InDetTrackParticles",
191 )
192 )
193 acc.addPublicTool(EGAM7JetTPThinningTool)
194 thinningTools.append(EGAM7JetTPThinningTool)
195
196
197 if TrackThinningKeepMuonTracks:
198 EGAM7MuonTPThinningTool = acc.getPrimaryAndMerge(
199 MuonTrackParticleThinningCfg(
200 flags,
201 name="EGAM7MuonTPThinningTool",
202 StreamName=streamName,
203 MuonKey="Muons",
204 InDetTrackParticlesKey="InDetTrackParticles",
205 )
206 )
207 thinningTools.append(EGAM7MuonTPThinningTool)
208
209
210 if TrackThinningKeepTauTracks:
211 EGAM7TauTPThinningTool = acc.getPrimaryAndMerge(
212 TauTrackParticleThinningCfg(
213 flags,
214 name="EGAM7TauTPThinningTool",
215 StreamName=streamName,
216 TauKey="TauJets",
217 ConeSize=0.6,
218 InDetTrackParticlesKey="InDetTrackParticles",
219 DoTauTracksThinning=True,
220 TauTracksKey="TauTracks",
221 )
222 )
223 thinningTools.append(EGAM7TauTPThinningTool)
224
225
226 thinning_expression = " && ".join(
227 [
228 "(InDetTrackParticles.DFCommonTightPrimary)",
229 "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)",
230 "(InDetTrackParticles.pt>10*GeV)",
231 ]
232 )
233 if TrackThinningKeepPVTracks:
234 EGAM7TPThinningTool = acc.getPrimaryAndMerge(
235 TrackParticleThinningCfg(
236 flags,
237 name="EGAM7TPThinningTool",
238 StreamName=streamName,
239 SelectionString=thinning_expression,
240 InDetTrackParticlesKey="InDetTrackParticles",
241 )
242 )
243 thinningTools.append(EGAM7TPThinningTool)
244
245
246 if flags.Input.isMC:
247
248 truth_cond_WZH = " && ".join(
249 ["(abs(TruthParticles.pdgId) >= 23)", "(abs(TruthParticles.pdgId) <= 25)"]
250 )
251
252 truth_cond_lep = " && ".join(
253 ["(abs(TruthParticles.pdgId) >= 11)", "(abs(TruthParticles.pdgId) <= 16)"]
254 )
255
256 truth_cond_top = "(abs(TruthParticles.pdgId) == 6)"
257
258 truth_cond_gam = " && ".join(
259 ["(abs(TruthParticles.pdgId) == 22)", "(TruthParticles.pt > 1*GeV)"]
260 )
261
262 truth_cond_finalState = "(TruthParticles.isGenStable)"
263 truth_expression = (
264 "( "
265 + truth_cond_WZH
266 + " ) || "
267 + "( "
268 + truth_cond_lep
269 + " ) || "
270 + "( "
271 + truth_cond_top
272 + " ) || "
273 + "( "
274 + truth_cond_gam
275 + " ) || "
276 + "( "
277 + truth_cond_finalState
278 + " )"
279 )
280 print(
"EGAM7 truth thinning expression: ", truth_expression)
281
282 EGAM7TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning(
283 name="EGAM7TruthThinningTool",
284 StreamName=streamName,
285 ParticleSelectionString=truth_expression,
286 PreserveDescendants=False,
287 PreserveGeneratorDescendants=True,
288 PreserveAncestors=True,
289 )
290 acc.addPublicTool(EGAM7TruthThinningTool)
291 thinningTools.append(EGAM7TruthThinningTool)
292
293
294 if thinCells:
295 from DerivationFrameworkCalo.CaloCellDFGetterConfig import thinCaloCellsForDFCfg
296
297 acc.merge(
298 thinCaloCellsForDFCfg(
299 flags,
300 inputClusterKeys=["egammaClusters"],
301 streamName="StreamDAOD_EGAM7",
302 inputCellKey="AllCalo",
303 outputCellKey="DFEGAMCellContainer",
304 )
305 )
306
307
308 skimmingTool = acc.getPrimaryAndMerge(EGAM7SkimmingToolCfg(flags))
309
310
311 acc.addEventAlgo(
312 CompFactory.DerivationFramework.DerivationKernel(
313 name,
314 SkimmingTools=[skimmingTool],
315 AugmentationTools=augmentationTools,
316 ThinningTools=thinningTools,
317 )
318 )
319
320 return acc
321
322