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(InDetTrackParticles.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 = "(TruthParticles.isW || TruthParticles.isZ || TruthParticles.isHiggs)"
246
247 truth_cond_lep = "(TruthParticles.isLepton)"
248
249 truth_cond_top = "(TruthParticles.isTop)"
250
251 truth_cond_gam = " && ".join(
252 ["(TruthParticles.isPhoton)", "(TruthParticles.pt > 1*GeV)"]
253 )
254
255 truth_cond_finalState = "(TruthParticles.isGenStable)"
256 truth_expression = (
257 "( "
258 + truth_cond_WZH
259 + " ) || "
260 + "( "
261 + truth_cond_lep
262 + " ) || "
263 + "( "
264 + truth_cond_top
265 + " ) || "
266 + "( "
267 + truth_cond_gam
268 + " ) || "
269 + "( "
270 + truth_cond_finalState
271 + " )"
272 )
273 print(
"EGAM7 truth thinning expression: ", truth_expression)
274
275 EGAM7TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning(
276 name="EGAM7TruthThinningTool",
277 StreamName=streamName,
278 ParticleSelectionString=truth_expression,
279 PreserveDescendants=False,
280 PreserveGeneratorDescendants=True,
281 PreserveAncestors=True,
282 )
283 acc.addPublicTool(EGAM7TruthThinningTool)
284 thinningTools.append(EGAM7TruthThinningTool)
285
286
287 if thinCells:
288 from DerivationFrameworkCalo.CaloCellDFGetterConfig import thinCaloCellsForDFCfg
289
290 acc.merge(
291 thinCaloCellsForDFCfg(
292 flags,
293 inputClusterKeys=["egammaClusters"],
294 streamName="StreamDAOD_EGAM7",
295 inputCellKey="AllCalo",
296 outputCellKey="DFEGAMCellContainer",
297 )
298 )
299
300
301 skimmingTool = acc.getPrimaryAndMerge(EGAM7SkimmingToolCfg(flags))
302
303
304 acc.addEventAlgo(
305 CompFactory.DerivationFramework.DerivationKernel(
306 name,
307 SkimmingTools=[skimmingTool],
308 AugmentationTools=augmentationTools,
309 ThinningTools=thinningTools,
310 )
311 )
312
313 return acc
314
315