93def EGAM9KernelCfg(flags, name="EGAM9Kernel", **kwargs):
94 """Configure the derivation framework driving algorithm (kernel)
95 for EGAM9"""
96 acc = ComponentAccumulator()
97
98
99 from DerivationFrameworkPhys.PhysCommonConfig import PhysCommonAugmentationsCfg
100
101 acc.merge(
102 PhysCommonAugmentationsCfg(
103 flags, TriggerListsHelper=kwargs["TriggerListsHelper"]
104 )
105 )
106
107
108 augmentationTools = []
109
110
111
112
113 from DerivationFrameworkCalo.DerivationFrameworkCaloConfig import (
114 CaloDecoratorKernelCfg)
115 acc.merge(CaloDecoratorKernelCfg(flags))
116
117
118 thinningTools = []
119 streamName = kwargs["StreamName"]
120
121
122 if flags.Derivation.Egamma.doTrackThinning:
123 TrackThinningKeepElectronTracks = False
124 TrackThinningKeepPhotonTracks = True
125 TrackThinningKeepPVTracks = False
126
127
128 if TrackThinningKeepElectronTracks:
129 EGAM9ElectronTPThinningTool = (
130 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
131 name="EGAM9ElectronTPThinningTool",
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(EGAM9ElectronTPThinningTool)
142 thinningTools.append(EGAM9ElectronTPThinningTool)
143
144
145 if TrackThinningKeepPhotonTracks:
146 EGAM9PhotonTPThinningTool = (
147 CompFactory.DerivationFramework.EgammaTrackParticleThinning(
148 name="EGAM9PhotonTPThinningTool",
149 StreamName=streamName,
150 SGKey="Photons",
151 GSFTrackParticlesKey="GSFTrackParticles",
152 InDetTrackParticlesKey="InDetTrackParticles",
153 GSFConversionVerticesKey="GSFConversionVertices",
154 SelectionString="Photons.pt > 0*GeV",
155 BestMatchOnly=True,
156 ConeSize=0.3,
157 )
158 )
159 acc.addPublicTool(EGAM9PhotonTPThinningTool)
160 thinningTools.append(EGAM9PhotonTPThinningTool)
161
162
163 thinning_expression = " && ".join(
164 [
165 "(InDetTrackParticles.DFCommonTightPrimary)",
166 "(abs(DFCommonInDetTrackZ0AtPV)*sin(InDetTrackParticles.theta)<3*mm)",
167 "(InDetTrackParticles.pt > 10*GeV)",
168 ]
169 )
170 if TrackThinningKeepPVTracks:
171 from DerivationFrameworkInDet.InDetToolsConfig import (
172 TrackParticleThinningCfg,
173 )
174
175 EGAM9TPThinningTool = acc.getPrimaryAndMerge(
176 TrackParticleThinningCfg(
177 flags,
178 name="EGAM9TPThinningTool",
179 StreamName=streamName,
180 SelectionString=thinning_expression,
181 InDetTrackParticlesKey="InDetTrackParticles",
182 )
183 )
184 thinningTools.append(EGAM9TPThinningTool)
185
186
187 if flags.Input.isMC:
188
189 truth_cond_WZH = " && ".join(
190 ["(abs(TruthParticles.pdgId) >= 23)", "(abs(TruthParticles.pdgId) <= 25)"]
191 )
192
193 truth_cond_lep = " && ".join(
194 ["(abs(TruthParticles.pdgId) >= 11)", "(abs(TruthParticles.pdgId) <= 16)"]
195 )
196
197 truth_cond_top = "(abs(TruthParticles.pdgId) == 6)"
198
199 truth_cond_gam = " && ".join(
200 ["(abs(TruthParticles.pdgId) == 22)", "(TruthParticles.pt > 1*GeV)"]
201 )
202
203 truth_cond_finalState = "(TruthParticles.isGenStable)"
204 truth_expression = (
205 "( "
206 + truth_cond_WZH
207 + " ) || "
208 + "( "
209 + truth_cond_lep
210 + " ) || "
211 + "( "
212 + truth_cond_top
213 + " ) || "
214 + "( "
215 + truth_cond_gam
216 + " ) || "
217 + "( "
218 + truth_cond_finalState
219 + " )"
220 )
221 print(
"EGAM9 truth thinning expression: ", truth_expression)
222
223 EGAM9TruthThinningTool = CompFactory.DerivationFramework.GenericTruthThinning(
224 name="EGAM9TruthThinningTool",
225 StreamName=streamName,
226 ParticleSelectionString=truth_expression,
227 PreserveDescendants=False,
228 PreserveGeneratorDescendants=True,
229 PreserveAncestors=True,
230 )
231 acc.addPublicTool(EGAM9TruthThinningTool)
232 thinningTools.append(EGAM9TruthThinningTool)
233
234
235 if thinCells:
236 from DerivationFrameworkCalo.CaloCellDFGetterConfig import thinCaloCellsForDFCfg
237
238 acc.merge(
239 thinCaloCellsForDFCfg(
240 flags,
241 inputClusterKeys=["egammaClusters"],
242 streamName="StreamDAOD_EGAM9",
243 inputCellKey="AllCalo",
244 outputCellKey="DFEGAMCellContainer",
245 )
246 )
247
248
249 skimmingTool = acc.getPrimaryAndMerge(EGAM9SkimmingToolCfg(flags))
250
251
252 acc.addEventAlgo(
253 CompFactory.DerivationFramework.DerivationKernel(
254 name,
255 SkimmingTools=[skimmingTool],
256 AugmentationTools=augmentationTools,
257 ThinningTools=thinningTools,
258 )
259 )
260
261 return acc
262
263