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