24{
25 SG::ReadHandle<xAOD::ElectronContainer> electronInput (
m_elecInput, ctx);
26 SG::ReadHandle<xAOD::CaloClusterContainer> clustersInput (
m_clustersInput, ctx);
27 SG::ReadHandle<xAOD::TrackParticleContainer> tracksInput (
m_tracksInput, ctx);
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
36 SG::ReadDecorHandle<xAOD::TrackParticleContainer, std::vector<ElementLink<xAOD::VertexContainer>>> stdJetTVADecoHandle (
m_stdJetTVADecoKey, ctx);
37 if (!stdJetTVADecoHandle.isPresent())
38 {
39 ATH_MSG_ERROR(
"Standard jet TVA decoration is not valid for InDetTrackParticles");
40 return StatusCode::FAILURE;
41 }
42
43 SG::WriteHandle<xAOD::CaloClusterContainer> clustersOutputHandle (
m_clustersOutput, ctx);
44 ATH_CHECK( clustersOutputHandle.record(std::make_unique<xAOD::CaloClusterContainer>(), std::make_unique<xAOD::CaloClusterAuxContainer>()) );
45
46 SG::WriteHandle<xAOD::TrackParticleContainer> tracksOutputHandle (
m_tracksOutput, ctx);
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
58 selectElectron.at(elec->index()) =
static_cast<bool>(
m_eleLHSelectTool->accept(elec));
59 }
60
61
62
63 if (std::find(selectElectron.begin(),selectElectron.end(),true) == selectElectron.end()) return StatusCode::SUCCESS;
64
66 clustersOutputContainer->
reserve(clustersInput->size());
67
69 tracksOutputContainer->
reserve(tracksInput->size());
70
71 std::vector<const xAOD::TrackParticle *> tracks_to_remove;
72 std::vector<const xAOD::CaloCluster *> clusters_to_remove;
75 {
76 if (selectElectron.at(elec->index()))
77 {
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()){
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 }
92 {
93 auto where = std::find_if(tracks_to_remove.cbegin(), tracks_to_remove.cend(),
95 );
96 if (where == tracks_to_remove.cend())
97 {
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
109 auto where = std::find_if(clusters_to_remove.cbegin(), clusters_to_remove.cend(),
111 );
112 if (where == clusters_to_remove.cend()){
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
124 removedClustersOutputCont->
reserve(clusters_to_remove.size());
127 *new_removed_cluster = *
cls;
128 removedClustersOutputCont->
push_back(new_removed_cluster);
129 }
130
132 removedTracksOutputCont->
reserve(tracks_to_remove.size());
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_WARNING(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.
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
SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > m_stdJetTVADecoKey
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_removedTracksOutput
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".