ATLAS Offline Software
Loading...
Searching...
No Matches
TauThinningAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
3*/
4
5#include "TauThinningAlg.h"
9
14{
15 ATH_CHECK( m_taus.initialize(m_streamName) );
16 ATH_CHECK( m_tauTracks.initialize(m_streamName) );
20 ATH_CHECK( m_finalPi0s.initialize(m_streamName) );
21 ATH_CHECK( m_shotPFOs.initialize(m_streamName) );
26 ATH_CHECK( m_cells.initialize(m_streamName) );
28
29 return StatusCode::SUCCESS;
30}
31
36StatusCode TauThinningAlg::execute (const EventContext& ctx) const
37{
39 taus.thinAll();
40
42 tauTracks.thinAll();
43
45 neutralPFOs.thinAll();
46
48 pi0clusters.thinAll();
49
51 pi0CellLinks.thinAll();
52
54 shotPFOs.thinAll();
55
57 hadronicPFOs.thinAll();
58
60 secondaryVertices.thinAll();
61
63 cells.thinAll();
64
66 tauCellLinks.thinAll();
67
68 // The three following containers didn't exist in r21.
69 // Make them optional, so we won't crash processing a r21 ESD.
70
71 std::optional<SG::ThinningHandle<xAOD::ParticleContainer> > finalPi0sOpt;
73 finalPi0sOpt.emplace (m_finalPi0s, ctx);
74 finalPi0sOpt->thinAll();
75 }
76
77 std::optional<SG::ThinningHandle<xAOD::CaloClusterContainer> > shotclustersOpt;
79 shotclustersOpt.emplace (m_shotclusters, ctx);
80 shotclustersOpt->thinAll();
81 }
82
83 std::optional<SG::ThinningHandle<CaloClusterCellLinkContainer> > shotCellLinksOpt;
85 shotCellLinksOpt.emplace (m_shotCellLinks, ctx);
86 shotCellLinksOpt->thinAll();
87 }
88
89 static const SG::ConstAccessor<char> acc_passThinning("passThinning");
90
91 for (const xAOD::TauJet* tau : *taus) {
92
93 if (!acc_passThinning(*tau)) continue;
94
95 // keep tau
96 taus.keep(tau->index());
97
98 // keep tau tracks
99 for (const xAOD::TauTrack* track : tau->allTracks()) {
100
102 continue;
103
104 tauTracks.keep(track->index());
105 }
106
107 // keep tau cluster cell links and cells within 0.2 of the tau axis
108 TLorentzVector tauAxis = tauRecTools::getTauAxis(*tau, m_doVertexCorrection);
109 const xAOD::Vertex* tauVertex = tau->vertex();
110
111 for (const xAOD::IParticle* particle : tau->clusters()) {
112 const xAOD::CaloCluster* cluster = static_cast<const xAOD::CaloCluster*>(particle);
113 TLorentzVector clusterP4 = cluster->p4();
114
115 // correct the four momentum to point to the tau vertex
116 if (tauVertex) {
117 xAOD::CaloVertexedTopoCluster vertexedCluster(*cluster, tauVertex->position());
118 clusterP4 = vertexedCluster.p4();
119 }
120
121 if (clusterP4.DeltaR(tauAxis) > 0.2) continue;
122
123 const CaloClusterCellLink* cellLinks = cluster->getCellLinks();
124 if (!cellLinks) {
125 ATH_MSG_WARNING( "Skipping cluster without cell links." );
126 continue;
127 }
128
129 // cluster cell links
130 CaloClusterCellLinkContainer::const_iterator cellLinks_it = std::find(tauCellLinks->begin(), tauCellLinks->end(), cellLinks);
131 if(cellLinks_it != tauCellLinks->end()) {
132 size_t link_index = std::distance(tauCellLinks->begin(), cellLinks_it);
133 tauCellLinks.keep(link_index);
134 }
135 else {
136 ATH_MSG_WARNING( "Could not find cluster cell link in " << m_tauCellLinks.key() << ", skipping cluster." );
137 continue;
138 }
139
140 // cells
142 CaloClusterCellLink::const_iterator end = cellLinks->end();
143 for (; it != end; ++it) {
144 if (it.index() >= cells->size()) {
145 ATH_MSG_WARNING( "Cell index " << it.index() << " is larger than the number of cells in " << m_cells.key() << " (" << cells->size() << ")" );
146 continue;
147 }
148 cells.keep (it.index());
149 }
150 }
151
152 // keep neutral PFOs, pi0 clusters, cell links and cells
153 for(size_t i=0; i<tau->nNeutralPFOs(); i++) {
154 // neutral PFOs
155 neutralPFOs.keep(tau->neutralPFO(i)->index());
156
157 // pi0 clusters
158 const xAOD::CaloCluster* cluster = tau->neutralPFO(i)->cluster(0);
159 pi0clusters.keep(cluster->index());
160
161 // pi0 cell links
162 const CaloClusterCellLink* cellLinks = cluster->getCellLinks();
163 CaloClusterCellLinkContainer::const_iterator cellLinks_it = std::find(pi0CellLinks->begin(), pi0CellLinks->end(), cellLinks);
164 if(cellLinks_it != pi0CellLinks->end()) {
165 size_t link_index = std::distance(pi0CellLinks->begin(), cellLinks_it);
166 pi0CellLinks.keep(link_index);
167 }
168 else {
169 ATH_MSG_WARNING( "Could not find cluster cell link in " << m_pi0CellLinks.key() << ", won't be saved in xAOD." );
170 }
171
172 // pi0 cells
174 CaloClusterCellLink::const_iterator end = cellLinks->end();
175 for (; it != end; ++it) {
176 if (it.index() >= cells->size()) {
177 ATH_MSG_WARNING( "Cell index " << it.index() << " is larger than the number of cells in " << m_cells.key() << " (" << cells->size() << ")" );
178 continue;
179 }
180 cells.keep (it.index());
181 }
182 }
183
184 // keep final pi0s
185 if (finalPi0sOpt) {
186 for(size_t i=0; i<tau->nPi0s(); i++) {
187 finalPi0sOpt->keep(tau->pi0(i)->index());
188 }
189 }
190
191 // keep shot PFOs, clusters, cell links and cells
192 for(size_t i=0; i<tau->nShotPFOs(); i++) {
193 // shot PFOs
194 shotPFOs.keep(tau->shotPFO(i)->index());
195
196 // shot clusters
197 const xAOD::CaloCluster* cluster = tau->shotPFO(i)->cluster(0);
198 if (!cluster) continue;
199 if (shotclustersOpt) {
200 shotclustersOpt->keep(cluster->index());
201 }
202
203 // shot cell links
204 const CaloClusterCellLink* cellLinks = cluster->getCellLinks();
205 if (shotCellLinksOpt) {
206 CaloClusterCellLinkContainer::const_iterator cellLinks_it = std::find((*shotCellLinksOpt)->begin(), (*shotCellLinksOpt)->end(), cellLinks);
207 if(cellLinks_it != (*shotCellLinksOpt)->end()) {
208 size_t link_index = std::distance((*shotCellLinksOpt)->begin(), cellLinks_it);
209 shotCellLinksOpt->keep(link_index);
210 }
211 else {
212 ATH_MSG_WARNING( "Could not find cluster cell link in " << m_shotCellLinks.key() << ", won't be saved in xAOD." );
213 }
214 }
215
216 // shot cells
218 CaloClusterCellLink::const_iterator end = cellLinks->end();
219 for (; it != end; ++it) {
220 if (it.index() >= cells->size()) {
221 ATH_MSG_WARNING( "Cell index " << it.index() << " is larger than the number of cells in " << m_cells.key() << " (" << cells->size() << ")" );
222 continue;
223 }
224 cells.keep (it.index());
225 }
226 }
227
228 // keep hadronic PFOs
229 for(size_t i=0; i<tau->nHadronicPFOs(); i++) {
230 hadronicPFOs.keep(tau->hadronicPFO(i)->index());
231 }
232
233 // keep secondary vertex when present
234 if (tau->secondaryVertex() != nullptr) {
235 secondaryVertices.keep(tau->secondaryVertex()->index());
236 }
237 }
238
239 return StatusCode::SUCCESS;
240}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
static Double_t taus
Handle class for reading from StoreGate.
Handle for requesting thinning for a data object.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
size_t index() const
Return the index of this element within its container.
Helper class to provide constant type-safe access to aux data.
void thinAll()
Mark that all elements should be thinned away.
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.
virtual StatusCode initialize() override
Gaudi initialize method.
SG::ThinningHandleKey< CaloClusterCellLinkContainer > m_tauCellLinks
SG::ThinningHandleKey< xAOD::ParticleContainer > m_finalPi0s
SG::ThinningHandleKey< xAOD::VertexContainer > m_secondaryVertices
SG::ThinningHandleKey< CaloClusterCellLinkContainer > m_pi0CellLinks
Gaudi::Property< bool > m_saveOnlyGoodTracks
SG::ThinningHandleKey< xAOD::TauJetContainer > m_taus
SG::ThinningHandleKey< xAOD::CaloClusterContainer > m_shotclusters
Gaudi::Property< bool > m_doVertexCorrection
StringProperty m_streamName
virtual StatusCode execute(const EventContext &ctx) const override
Execute the algorithm.
SG::ThinningHandleKey< xAOD::PFOContainer > m_shotPFOs
SG::ThinningHandleKey< xAOD::CaloClusterContainer > m_pi0clusters
SG::ThinningHandleKey< xAOD::PFOContainer > m_hadronicPFOs
SG::ThinningHandleKey< CaloCellContainer > m_cells
SG::ThinningHandleKey< CaloClusterCellLinkContainer > m_shotCellLinks
SG::ThinningHandleKey< xAOD::PFOContainer > m_neutralPFOs
SG::ThinningHandleKey< xAOD::TauTrackContainer > m_tauTracks
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
virtual FourMom_t p4() const
The full 4-momentum of the particle.
virtual FourMom_t p4() const final
The full 4-momentum of the particle.
Evaluate cluster kinematics with a different vertex / signal state.
Class providing the definition of the 4-vector interface.
const Amg::Vector3D & position() const
Returns the 3-pos.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
TLorentzVector getTauAxis(const xAOD::TauJet &tau, bool doVertexCorrection=true)
Return the four momentum of the tau axis The tau axis is widely used to select clusters and cells in ...
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Vertex_v1 Vertex
Define the latest version of the vertex class.
TauTrack_v1 TauTrack
Definition of the current version.
Definition TauTrack.h:16
TauJet_v3 TauJet
Definition of the current "tau version".