ATLAS Offline Software
Loading...
Searching...
No Matches
TauElecSubtractAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
3*/
4
6#include <algorithm>
7
9{
10 ATH_CHECK( m_elecInput.initialize() );
11 ATH_CHECK( m_clustersInput.initialize() );
12 ATH_CHECK( m_clustersOutput.initialize() );
13 ATH_CHECK( m_tracksInput.initialize() );
14 ATH_CHECK( m_tracksOutput.initialize() );
15 ATH_CHECK( m_removedClustersOutput.initialize() );
16 ATH_CHECK( m_removedTracksOutput.initialize() );
17 ATH_CHECK( m_eleLHSelectTool.retrieve() );
18 ATH_CHECK( m_stdJetTVADecoKey.initialize() );
19
20 return StatusCode::SUCCESS;
21}
22
23StatusCode TauElecSubtractAlg::execute (const EventContext& ctx) const
24{
28 if(!electronInput.isValid() || !clustersInput.isValid() || !tracksInput.isValid())
29 {
30 if (!electronInput.isValid()) ATH_MSG_ERROR( "Collection " << electronInput.key() << " is not valid" );
31 if (!clustersInput.isValid()) ATH_MSG_ERROR( "Collection " << clustersInput.key() << " is not valid" );
32 if (!tracksInput.isValid()) ATH_MSG_ERROR( "Collection " << tracksInput.key() << " is not valid" );
33 return StatusCode::FAILURE;
34 }
35
37 if (!stdJetTVADecoHandle.isPresent())
38 {
39 ATH_MSG_ERROR("Standard jet TVA decoration is not valid for InDetTrackParticles");
40 return StatusCode::FAILURE;
41 }
42
44 ATH_CHECK( clustersOutputHandle.record(std::make_unique<xAOD::CaloClusterContainer>(), std::make_unique<xAOD::CaloClusterAuxContainer>()) );
45
47 ATH_CHECK( tracksOutputHandle.record(std::make_unique<xAOD::TrackParticleContainer>(), std::make_unique<xAOD::TrackParticleAuxContainer>()) );
48
50 ATH_CHECK( removedClustersOutputHandle.record(std::make_unique<xAOD::CaloClusterContainer>(), std::make_unique<xAOD::CaloClusterAuxContainer>()) );
51
53 ATH_CHECK( removedTracksOutputHandle.record(std::make_unique<xAOD::TrackParticleContainer>(), std::make_unique<xAOD::TrackParticleAuxContainer>()) );
54
55 std::vector<bool> selectElectron(electronInput->size(), false);
56
57 for (const xAOD::Electron* elec : *electronInput.cptr()) {
58 selectElectron.at(elec->index()) = static_cast<bool>(m_eleLHSelectTool->accept(elec));
59 }
60
61 // early stopping: if no electron is selected, the EleRM reconstruction should not run
62 // the simplest strategy is to write out empty cluster and track containers
63 if (std::find(selectElectron.begin(),selectElectron.end(),true) == selectElectron.end()) return StatusCode::SUCCESS;
64
65 xAOD::CaloClusterContainer* clustersOutputContainer = clustersOutputHandle.ptr();
66 clustersOutputContainer->reserve(clustersInput->size());
67
68 xAOD::TrackParticleContainer* tracksOutputContainer = tracksOutputHandle.ptr();
69 tracksOutputContainer->reserve(tracksInput->size());
70
71 std::vector<const xAOD::TrackParticle *> tracks_to_remove;
72 std::vector<const xAOD::CaloCluster *> clusters_to_remove;
73 if(!m_doNothing){
74 for (const xAOD::Electron* elec : *electronInput.cptr())
75 {
76 if (selectElectron.at(elec->index()))
77 {
78 tracks_to_remove = xAOD::EgammaHelpers::getTrackParticlesVec(elec, true, true);
79 std::vector<ElementLink< xAOD::CaloClusterContainer>> elec_cluster_links = elec->caloClusterLinks();
80 for (const auto& elec_cluster_link : elec_cluster_links){
81 if (elec_cluster_link.isValid()){
82 std::vector<const xAOD::CaloCluster*> orig_clusters = xAOD::EgammaHelpers::getAssociatedTopoClusters(*elec_cluster_link);
83 clusters_to_remove.insert(clusters_to_remove.end(), orig_clusters.cbegin(), orig_clusters.cend());
84 }
85 }
86 }
87 }
88 } else {
89 ATH_MSG_WARNING("DOING NOTHING... For validation only, please check your config.");
90 }
91 for (const xAOD::TrackParticle* old_track : *tracksInput.cptr())
92 {
93 auto where = std::find_if(tracks_to_remove.cbegin(), tracks_to_remove.cend(),
94 [&](const xAOD::TrackParticle* target){return (target == old_track);}
95 );
96 if (where == tracks_to_remove.cend())
97 {
98 auto *new_track = new xAOD::TrackParticle();
99 tracksOutputContainer->push_back(new_track);
100 *new_track = *old_track;
101 auto link = ElementLink< xAOD::TrackParticleContainer >( *tracksInput, old_track->index() );
102 static const SG::Accessor<ElementLink<xAOD::TrackParticleContainer>> acc_originalObjectDecor("ERMOriginalTrack");
103 acc_originalObjectDecor(*new_track) = link;
104 }
105 }
106 ATH_MSG_DEBUG("Old tracks size = " << tracksInput->size() << ", new tracks size = " << tracksOutputContainer->size() << ", expected diff = " << tracks_to_remove.size());
107
108 for (const xAOD::CaloCluster* old_cluster : *clustersInput.cptr()) {
109 auto where = std::find_if(clusters_to_remove.cbegin(), clusters_to_remove.cend(),
110 [&](const xAOD::CaloCluster* target){return (target == old_cluster);}
111 );
112 if (where == clusters_to_remove.cend()){
113 auto *new_cluster = new xAOD::CaloCluster();
114 clustersOutputContainer->push_back(new_cluster);
115 *new_cluster = *old_cluster;
116 auto link = ElementLink< xAOD::CaloClusterContainer >( *clustersInput, old_cluster->index() );
117 static const SG::Accessor<ElementLink<xAOD::CaloClusterContainer>> acc_originalObjectDecor("ERMOriginalCaloCluster");
118 acc_originalObjectDecor(*new_cluster) = link;
119 }
120 }
121 ATH_MSG_DEBUG("Old cluster size = " << clustersInput->size() << ", new cluster size = " << clustersOutputContainer->size() << ", expected diff = " << clusters_to_remove.size());
122
123 xAOD::CaloClusterContainer* removedClustersOutputCont = removedClustersOutputHandle.ptr();
124 removedClustersOutputCont->reserve(clusters_to_remove.size());
125 for (const xAOD::CaloCluster* cls : clusters_to_remove){
126 auto *new_removed_cluster = new xAOD::CaloCluster();
127 *new_removed_cluster = *cls;
128 removedClustersOutputCont->push_back(new_removed_cluster);
129 }
130
131 xAOD::TrackParticleContainer* removedTracksOutputCont = removedTracksOutputHandle.ptr();
132 removedTracksOutputCont->reserve(tracks_to_remove.size());
133 for (const xAOD::TrackParticle* trk : tracks_to_remove){
134 auto *new_removed_track = new xAOD::TrackParticle();
135 *new_removed_track = *trk;
136 removedTracksOutputCont->push_back(new_removed_track);
137 }
138
139 return StatusCode::SUCCESS;
140}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
Helper class to provide type-safe access to aux data.
Handle class for reading a decoration on an object.
bool isPresent() const
Is the referenced container present in SG?
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
SG::ReadHandleKey< xAOD::ElectronContainer > m_elecInput
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_removedClustersOutput
Gaudi::Property< bool > m_doNothing
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_clustersOutput
ToolHandle< IAsgElectronLikelihoodTool > m_eleLHSelectTool
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tracksInput
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_tracksOutput
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > m_stdJetTVADecoKey
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_removedTracksOutput
virtual StatusCode initialize() override
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clustersInput
std::vector< const xAOD::TrackParticle * > getTrackParticlesVec(const xAOD::Egamma *eg, bool useBremAssoc=true, bool allParticles=true)
Return a list of all or only the best TrackParticle associated to the object.
std::vector< const xAOD::CaloCluster * > getAssociatedTopoClusters(const xAOD::CaloCluster *cluster)
Return a vector of all the topo clusters associated with the egamma cluster.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
Electron_v1 Electron
Definition of the current "egamma version".