ATLAS Offline Software
Loading...
Searching...
No Matches
photonSuperClusterBuilder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6
15#include "xAODTracking/Vertex.h"
16
19
20#include <cmath>
21#include <memory>
22
24 ISvcLocator* pSvcLocator)
25 : egammaSuperClusterBuilderBase(name, pSvcLocator)
26{
27}
28
29StatusCode
31{
32 ATH_MSG_DEBUG(" Initializing photonSuperClusterBuilder");
33
34 // retrieve conversion builder
35 if (m_doConversions) {
37 }
38
40}
41
42
52
53StatusCode
55 const EventContext &ctx,
57) const {
58 if (m_doConversions) {
59 for (auto egRec : *newEgammaRecs) {
60 if (m_conversionBuilder->executeRec(ctx, egRec).isFailure()) {
61 ATH_MSG_ERROR("Problem executing conversioBuilder on photonSuperRecs");
62 return StatusCode::FAILURE;
63 }
64 }
65 }
66
67 return StatusCode::SUCCESS;
68}
69
70// assume egammaRecs != 0, since the ReadHadler is valid
71// assume seed egammaRec has a valid cluster, since it has been already used
72std::vector<std::size_t>
74 std::size_t seedIndex,
75 const EgammaRecContainer* egammaRecs,
76 std::vector<bool>& isUsed) const
77{
78
79 std::vector<std::size_t> secondaryIndices;
80
81 const auto* const seedEgammaRec = (*egammaRecs)[seedIndex];
82 const xAOD::CaloCluster* const seedCaloClus = seedEgammaRec->caloCluster();
83
84 // let's determine some things about the seed
85 std::vector<const xAOD::Vertex*> seedVertices;
86 std::vector<xAOD::EgammaParameters::ConversionType> seedVertexType;
87 std::vector<const xAOD::TrackParticle*>
88 seedVertexTracks; // tracks from conversion vertex
89
90 auto numVertices = seedEgammaRec->getNumberOfVertices();
91 if (m_useOnlyLeadingVertex && numVertices > 0) {
92 numVertices = 1;
93 }
94
95 for (std::size_t vx = 0; vx < numVertices; ++vx) {
96 const auto* const vertex = seedEgammaRec->vertex(vx);
97 const auto convType = xAOD::EgammaHelpers::conversionType(vertex);
98 seedVertices.push_back(vertex);
99 seedVertexType.push_back(convType);
100 const bool addTracks = !m_useOnlySi ||
103 if (addTracks) {
104 for (unsigned int tp = 0; tp < vertex->nTrackParticles(); ++tp) {
105 seedVertexTracks.push_back(vertex->trackParticle(tp));
106 }
107 }
108 }
109
110 // for stats
111 int nWindowClusters = 0;
112 int nExtraClusters = 0;
113
114 // Now loop over the potential secondary clusters
115 for (std::size_t i = 0; i < egammaRecs->size(); ++i) {
116
117 // if already used continue
118 if (isUsed[i]) {
119 continue;
120 }
121
122 const auto* const secEgammaRec = (*egammaRecs)[i];
123 const xAOD::CaloCluster* const secClus = secEgammaRec->caloCluster();
124 if (!secClus) {
126 "The potentially secondary egammaRec does not have a cluster");
127 continue;
128 }
129
130 bool addCluster = false;
131
132 if (matchesInWindow(seedCaloClus, secClus)) {
133 ATH_MSG_DEBUG("Cluster with Et: " << secClus->et()
134 << " matched in window");
135 ++nWindowClusters;
136 addCluster = true;
137 } else if (m_addClustersMatchingVtx &&
138 matchesVtx(seedVertices, seedVertexType, secEgammaRec)) {
139 ATH_MSG_DEBUG("conversion vertices match");
140 addCluster = true;
141 ++nExtraClusters;
143 matchesVtxTrack(seedVertexTracks, secEgammaRec)) {
144 ATH_MSG_DEBUG("conversion track match");
145 addCluster = true;
146 ++nExtraClusters;
147 }
148 // Add it to the list of secondary clusters if it matches.
149 if (addCluster) {
150 secondaryIndices.push_back(i);
151 isUsed[i] = true;
152 }
153 }
154 ATH_MSG_DEBUG("Found: " << secondaryIndices.size() << " secondaries");
155 ATH_MSG_DEBUG("window clusters: " << nWindowClusters);
156 ATH_MSG_DEBUG("extra clusters: " << nExtraClusters);
157
158 return secondaryIndices;
159}
160
161bool
163 const std::vector<const xAOD::Vertex*>& seedVertices,
164 const std::vector<xAOD::EgammaParameters::ConversionType>& seedVertexType,
165 const egammaRec* egRec) const
166{
167
168 auto numTestVertices = egRec->getNumberOfVertices();
169 if (m_useOnlyLeadingVertex && numTestVertices > 0) {
170 numTestVertices = 1;
171 }
172 for (size_t seedVx = 0; seedVx < seedVertices.size(); ++seedVx) {
173 if (!m_useOnlySi ||
174 seedVertexType[seedVx] == xAOD::EgammaParameters::singleSi ||
175 seedVertexType[seedVx] == xAOD::EgammaParameters::doubleSi) {
176
177 for (size_t testVx = 0; testVx < numTestVertices; ++testVx) {
178 if (seedVertices[seedVx] == egRec->vertex(testVx)) {
179 return true;
180 }
181 }
182 }
183 }
184 return false;
185}
186
187bool
189 const std::vector<const xAOD::TrackParticle*>& seedVertexTracks,
190 const egammaRec* egRec) const
191{
192 auto numTestTracks = egRec->getNumberOfTrackParticles();
193 if (m_useOnlyLeadingTrack && numTestTracks > 0) {
194 numTestTracks = 1;
195 }
196 for (const auto* seedVertexTrack : seedVertexTracks) {
197 // selected tracks alread are just Si if we are only looking at Si tracks
198 for (size_t testTk = 0; testTk < numTestTracks; ++testTk) {
199 if (seedVertexTrack == egRec->trackParticle(testTk)) {
200 return true;
201 }
202 }
203 }
204 return false;
205}
#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)
Definition of CaloDetDescrManager.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
size_type size() const noexcept
Returns the number of elements in the collection.
Represent an egamma object for internal egamma usage during reconstruction.
Definition egammaRec.h:31
size_t getNumberOfTrackParticles() const
Return the number xAOD::TrackParticles that match the electron candidate.
const xAOD::Vertex * vertex(size_t index=0) const
Pointer to the xAOD::Vertex/es that match the photon candidate.
Definition egammaRec.cxx:54
const xAOD::TrackParticle * trackParticle(size_t index=0) const
Pointer to the xAOD::TrackParticle/s that match the electron candidate.
Definition egammaRec.cxx:31
size_t getNumberOfVertices() const
Return the number xAOD::Vertex/vertices that match the photon candidate.
egammaSuperClusterBuilderBase(const std::string &name, ISvcLocator *pSvcLocator)
Protected constructor since this class should not be instantiated by itself.
bool matchesInWindow(const xAOD::CaloCluster *ref, const xAOD::CaloCluster *clus) const
Is clus in window center around ref?
virtual StatusCode initialize() override
should be called by the derived class in the initialize phase
Gaudi::Property< bool > m_addClustersMatchingVtx
add the topoclusters matching conversion vertex
Gaudi::Property< bool > m_useOnlyLeadingTrack
use only the leading track for matching
virtual StatusCode redoMatching(const EventContext &ctx, SG::WriteHandle< EgammaRecContainer > &newEgammaRecs) const final override
virtual std::vector< std::size_t > searchForSecondaryClusters(std::size_t photonInd, const EgammaRecContainer *egammaRecs, std::vector< bool > &isUsed) const override final
Return extra clusters that can be added to make supercluster.
bool matchesVtxTrack(const std::vector< const xAOD::TrackParticle * > &seedVertexTracks, const egammaRec *egRec) const
Does the cluster match a conversion vertex track with the seed?
bool matchesVtx(const std::vector< const xAOD::Vertex * > &seedVertices, const std::vector< xAOD::EgammaParameters::ConversionType > &seedVertexType, const egammaRec *egRec) const
Does the cluster share conversion vertex?
virtual xAOD::EgammaParameters::EgammaType getEgammaRecType(const egammaRec *egRec) const override final
photonSuperClusterBuilder(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< bool > m_doConversions
private member flag to do the conversion building and matching
Gaudi::Property< bool > m_useOnlySi
use only vertices/tracks with silicon tracks
Gaudi::Property< bool > m_addClustersMatchingVtxTracks
add the topoclusters matching conversion vertex tracks
ToolHandle< IEMConversionBuilder > m_conversionBuilder
Tool to retrieve the conversions.
Gaudi::Property< bool > m_useOnlyLeadingVertex
use only the leading vertex for matching
virtual StatusCode initialize() override final
should be called by the derived class in the initialize phase
DataVector< egammaRec > EgammaRecContainer
The container is a simple typedef for now.
xAOD::EgammaParameters::ConversionType conversionType(const xAOD::Photon *ph)
return the photon conversion type (see EgammaEnums)
@ singleSi
one track only, with Si hits
@ doubleSi
two tracks, both with Si hits
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.