13#include "GaudiKernel/ThreadLocalContext.h"
61 <<
"as the source collection for calo clusters");
67 <<
"as the source collection for topo calo clusters");
71 "No CalCaloTopoCluster or CaloCluster collection provided for thinning.");
72 return StatusCode::FAILURE;
76 ATH_MSG_FATAL(
"No particle collection provided for thinning.");
77 return StatusCode::FAILURE;
80 "Calo clusters associated with objects in "
82 <<
" will be retained in this format with the rest being thinned away");
92 return StatusCode::SUCCESS;
100 <<
" were retained ");
104 return StatusCode::SUCCESS;
111 const EventContext& ctx = Gaudi::Hive::currentContext();
113 bool is_muons =
false;
114 bool is_egamma =
false;
116 bool is_track =
false;
121 importedCaloCluster =
128 importedTopoCaloCluster =
132 unsigned int nClusters = 0;
134 nClusters = importedCaloCluster->size();
136 unsigned int nTopoClusters = 0;
138 nTopoClusters = importedTopoCaloCluster->size();
140 if (nClusters == 0 && nTopoClusters == 0) {
141 return StatusCode::SUCCESS;
145 std::vector<bool> mask(nClusters,
false), topomask(nTopoClusters,
false);
153 importedParticlesHandle.
ptr();
156 unsigned int nParticles(importedParticles->
size());
157 if (nParticles == 0) {
166 return StatusCode::SUCCESS;
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;
206 std::vector<int>
entries = m_parser->evaluateAsVector();
207 unsigned int nEntries =
entries.size();
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;
214 std::vector<const xAOD::IParticle*> particlesToCheck = {};
216 for (
unsigned int i = 0; i < nParticles; ++i) {
217 if (
static_cast<bool>(
entries[i])) {
218 particlesToCheck.push_back((*importedParticles)[i]);
222 for (
const auto* particle : particlesToCheck) {
227 importedCaloCluster.
cptr(),
230 is_tau) != StatusCode::SUCCESS) {
231 return StatusCode::FAILURE;
235 importedCaloCluster.
cptr(),
238 is_track) != StatusCode::SUCCESS) {
239 return StatusCode::FAILURE;
245 importedTopoCaloCluster.
cptr(),
248 is_tau) != StatusCode::SUCCESS) {
249 return StatusCode::FAILURE;
253 importedTopoCaloCluster.
cptr(),
256 is_track) != StatusCode::SUCCESS) {
257 return StatusCode::FAILURE;
262 for (
const auto* particle : *importedParticles) {
266 importedCaloCluster.
cptr(),
269 is_tau) != StatusCode::SUCCESS) {
270 return StatusCode::FAILURE;
274 importedCaloCluster.
cptr(),
277 is_track) != StatusCode::SUCCESS) {
278 return StatusCode::FAILURE;
284 importedTopoCaloCluster.
cptr(),
287 is_tau) != StatusCode::SUCCESS) {
288 return StatusCode::FAILURE;
292 importedTopoCaloCluster.
cptr(),
295 is_track) != StatusCode::SUCCESS) {
296 return StatusCode::FAILURE;
303 for (
unsigned int i = 0; i < nClusters; ++i) {
307 for (
unsigned int i = 0; i < nTopoClusters; ++i) {
321 return StatusCode::SUCCESS;
326 std::vector<bool>& mask,
335 return StatusCode::FAILURE;
342 return StatusCode::FAILURE;
350 return StatusCode::FAILURE;
358 return StatusCode::FAILURE;
362 return StatusCode::SUCCESS;
367 std::vector<bool>& mask,
376 return StatusCode::FAILURE;
383 return StatusCode::FAILURE;
385 auto it = std::find(cps->
begin(), cps->
end(),
egamma->caloCluster());
386 if (it != cps->
end()) {
387 int ItsCluster = std::distance(cps->
begin(), it);
388 mask[ItsCluster] =
true;
396 return StatusCode::FAILURE;
398 auto it = std::find(cps->
begin(), cps->
end(), muon->cluster());
399 if (it != cps->
end()) {
400 int ItsCluster = std::distance(cps->
begin(), it);
401 mask[ItsCluster] =
true;
409 return StatusCode::FAILURE;
413 for (
const auto * pJetConstituent :
vec) {
414 TLorentzVector cluster_P4;
415 cluster_P4.SetPtEtaPhiM(1, pJetConstituent->Eta(), pJetConstituent->Phi(), 1);
416 if (LC_P4.DeltaR(cluster_P4) > 0.2)
420 auto it_cps = std::find(cps->
begin(), cps->
end(), cl);
421 if (it_cps != cps->
end()) {
422 int ItsCluster = std::distance(cps->
begin(), it_cps);
423 mask[ItsCluster] =
true;
428 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
std::vector< size_t > vec
Handle class for reading from StoreGate.
Handle for requesting thinning for a data object.
StatusCode testPhotons(const char *APP_NAME, bool quiet)
StatusCode testElectrons(const char *APP_NAME, bool quiet)
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
std::atomic< unsigned int > m_npass
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
virtual StatusCode doThinning() const override
std::atomic< unsigned int > m_ntotTopo
virtual StatusCode initialize() override
SG::ReadHandleKey< xAOD::IParticleContainer > m_sgKey
std::atomic< unsigned int > m_ntot
std::atomic< unsigned int > m_npassTopo
virtual ~CaloClusterThinning()
SG::ThinningHandleKey< xAOD::CaloClusterContainer > m_CaloClSGKey
StringProperty m_streamName
virtual StatusCode finalize() override
StatusCode setClustersMask(std::vector< bool > &mask, const xAOD::IParticle *particle, const xAOD::CaloClusterContainer *cps, bool is_muons, bool is_egamma, bool is_track) const
std::string m_selectionString
CaloClusterThinning(const std::string &t, const std::string &n, const IInterface *p)
const_pointer_type ptr()
Dereference the pointer.
const_pointer_type cptr()
Dereference the pointer.
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Handle for requesting thinning for a data object.
Class providing the definition of the 4-vector interface.
A vector of jet constituents at the scale used during jet finding.
JetConstituentVector getConstituents() const
Return a vector of consituents. The object behaves like vector<const IParticle*>. See JetConstituentV...
virtual FourMom_t p4() const
The full 4-momentum of the particle.
void select(const xAOD::IParticle *particle, const float coneSize, const xAOD::CaloClusterContainer *clusters, std::vector< bool > &mask)
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Egamma_v1 Egamma
Definition of the current "egamma version".
TauJet_v3 TauJet
Definition of the current "tau version".
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Muon_v1 Muon
Reference the current persistent version:
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
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.