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