110{
111 const EventContext& ctx = Gaudi::Hive::currentContext();
112
113 bool is_muons = false;
114 bool is_egamma = false;
115 bool is_tau = false;
116 bool is_track = false;
117
118
119 SG::ReadHandle<xAOD::CaloClusterContainer> importedCaloCluster;
121 importedCaloCluster =
122 SG::ReadHandle<xAOD::CaloClusterContainer>(
m_CaloClSGKey, ctx);
123 }
124
125
126 SG::ReadHandle<xAOD::CaloClusterContainer> importedTopoCaloCluster;
128 importedTopoCaloCluster =
129 SG::ReadHandle<xAOD::CaloClusterContainer>(
m_TopoClSGKey, ctx);
130 }
131
132 unsigned int nClusters = 0;
134 nClusters = importedCaloCluster->size();
135 }
136 unsigned int nTopoClusters = 0;
138 nTopoClusters = importedTopoCaloCluster->size();
139 }
140 if (nClusters == 0 && nTopoClusters == 0) {
141 return StatusCode::SUCCESS;
142 }
143
144
145 std::vector<bool>
mask(nClusters,
false), topomask(nTopoClusters,
false);
148
149
150 SG::ReadHandle<xAOD::IParticleContainer> importedParticlesHandle{
m_sgKey,
151 ctx };
153 importedParticlesHandle.
ptr();
154
155
156 unsigned int nParticles(importedParticles->
size());
157 if (nParticles == 0) {
159 SG::ThinningHandle<xAOD::CaloClusterContainer> thin(
m_CaloClSGKey, ctx);
160 thin.keep(mask);
161 }
163 SG::ThinningHandle<xAOD::CaloClusterContainer> thin(
m_TopoClSGKey, ctx);
164 thin.keep(topomask);
165 }
166 return StatusCode::SUCCESS;
167 }
168
169 is_egamma = false;
170 is_muons = false;
171 is_track = false;
172
173
179 is_egamma = true;
180 }
183 if (testMuons) {
184 is_muons = true;
185 }
188 if (testTaus) {
189 is_tau = true;
190 }
193 if (testTracks) {
194 is_track = true;
195 }
196
197 if (!(is_egamma || is_muons || is_tau || is_track)) {
198 ATH_MSG_ERROR(
"This tool only works with Egamma, Muons, Taus and Tracks "
199 <<
m_sgKey.key() <<
" is not a compatible collection");
200 return StatusCode::FAILURE;
201 }
202
203
204
206 std::vector<int>
entries = m_parser->evaluateAsVector();
208
209 if (nParticles != nEntries) {
210 ATH_MSG_ERROR(
"Sizes incompatible! Are you sure your selection string "
211 "used e-gamma objects??");
212 return StatusCode::FAILURE;
213 }
214 std::vector<const xAOD::IParticle*> particlesToCheck = {};
215
216 for (
unsigned int i = 0;
i < nParticles; ++
i) {
217 if (
static_cast<bool>(
entries[i])) {
218 particlesToCheck.push_back((*importedParticles)[i]);
219 }
220 }
222 for (const auto* particle : particlesToCheck) {
224
226 particle,
227 importedCaloCluster.
cptr(),
228 is_muons,
229 is_egamma,
230 is_tau) != StatusCode::SUCCESS) {
231 return StatusCode::FAILURE;
232 }
234 particle,
235 importedCaloCluster.
cptr(),
236 is_muons,
237 is_egamma,
238 is_track) != StatusCode::SUCCESS) {
239 return StatusCode::FAILURE;
240 }
241 }
244 particle,
245 importedTopoCaloCluster.
cptr(),
246 is_muons,
247 is_egamma,
248 is_tau) != StatusCode::SUCCESS) {
249 return StatusCode::FAILURE;
250 }
252 particle,
253 importedTopoCaloCluster.
cptr(),
254 is_muons,
255 is_egamma,
256 is_track) != StatusCode::SUCCESS) {
257 return StatusCode::FAILURE;
258 }
259 }
260 }
261 } else {
262 for (const auto* particle : *importedParticles) {
265 particle,
266 importedCaloCluster.
cptr(),
267 is_muons,
268 is_egamma,
269 is_tau) != StatusCode::SUCCESS) {
270 return StatusCode::FAILURE;
271 }
273 particle,
274 importedCaloCluster.
cptr(),
275 is_muons,
276 is_egamma,
277 is_track) != StatusCode::SUCCESS) {
278 return StatusCode::FAILURE;
279 }
280 }
283 particle,
284 importedTopoCaloCluster.
cptr(),
285 is_muons,
286 is_egamma,
287 is_tau) != StatusCode::SUCCESS) {
288 return StatusCode::FAILURE;
289 }
291 particle,
292 importedTopoCaloCluster.
cptr(),
293 is_muons,
294 is_egamma,
295 is_track) != StatusCode::SUCCESS) {
296 return StatusCode::FAILURE;
297 }
298 }
299 }
300 }
301
302
303 for (
unsigned int i = 0;
i < nClusters; ++
i) {
304 if (mask[i])
306 }
307 for (
unsigned int i = 0;
i < nTopoClusters; ++
i) {
308 if (topomask[i])
310 }
311
312
314 SG::ThinningHandle<xAOD::CaloClusterContainer> thin(
m_CaloClSGKey, ctx);
315 thin.keep(mask);
316 }
318 SG::ThinningHandle<xAOD::CaloClusterContainer> thin(
m_TopoClSGKey, ctx);
319 thin.keep(topomask);
320 }
321 return StatusCode::SUCCESS;
322}
StatusCode testPhotons(const char *APP_NAME, bool quiet)
StatusCode testElectrons(const char *APP_NAME, bool quiet)
size_type size() const noexcept
Returns the number of elements in the collection.
StatusCode particleCluster(std::vector< bool > &mask, const xAOD::IParticle *particle, const xAOD::CaloClusterContainer *cps, bool is_muons, bool is_egamma, bool is_tau) const
SG::ThinningHandleKey< xAOD::CaloClusterContainer > m_TopoClSGKey
SG::ReadHandleKey< xAOD::IParticleContainer > m_sgKey
SG::ThinningHandleKey< xAOD::CaloClusterContainer > m_CaloClSGKey
StatusCode setClustersMask(std::vector< bool > &mask, const xAOD::IParticle *particle, const xAOD::CaloClusterContainer *cps, bool is_muons, bool is_egamma, bool is_track) const
const_pointer_type ptr()
Dereference the pointer.
const_pointer_type cptr()
Dereference the pointer.
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.