ATLAS Offline Software
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 
11 #include "xAODEgamma/EgammaEnums.h"
15 #include "xAODTracking/Vertex.h"
16 
17 #include "StoreGate/ReadHandle.h"
18 #include "StoreGate/WriteHandle.h"
19 
20 #include <cmath>
21 #include <memory>
22 
24  ISvcLocator* pSvcLocator)
25  : egammaSuperClusterBuilderBase(name, pSvcLocator)
26 {
27 }
28 
31 {
32  ATH_MSG_DEBUG(" Initializing photonSuperClusterBuilder");
33 
34  // retrieve conversion builder
35  if (m_doConversions) {
36  ATH_CHECK(m_conversionBuilder.retrieve());
37  }
38 
40 }
41 
42 
45  if (egRec->getNumberOfVertices() > 0) {
47  }
48  else {
50  }
51 }
52 
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
72 std::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 ||
101  convType == xAOD::EgammaParameters::singleSi ||
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;
142  } else if (m_addClustersMatchingVtxTracks &&
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 
161 bool
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 
187 bool
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 }
xAOD::EgammaParameters::convertedPhoton
@ convertedPhoton
Definition: EgammaEnums.h:20
photonSuperClusterBuilder::getEgammaRecType
virtual xAOD::EgammaParameters::EgammaType getEgammaRecType(const egammaRec *egRec) const override final
Definition: photonSuperClusterBuilder.cxx:44
egammaRec::getNumberOfVertices
size_t getNumberOfVertices() const
Return the number xAOD::Vertex/vertices that match the photon candidate.
photonSuperClusterBuilder::matchesVtx
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?
Definition: photonSuperClusterBuilder.cxx:162
egammaSuperClusterBuilderBase::initialize
virtual StatusCode initialize() override
should be called by the derived class in the initialize phase
Definition: egammaSuperClusterBuilderBase.cxx:211
ParticleTest.tp
tp
Definition: ParticleTest.py:25
xAOD::CaloCluster_v1::et
double et() const
Definition: CaloCluster_v1.h:856
photonSuperClusterBuilder::photonSuperClusterBuilder
photonSuperClusterBuilder(const std::string &name, ISvcLocator *pSvcLocator)
Definition: photonSuperClusterBuilder.cxx:23
photonSuperClusterBuilder::initialize
virtual StatusCode initialize() override final
should be called by the derived class in the initialize phase
Definition: photonSuperClusterBuilder.cxx:30
CaloClusterAuxContainer.h
photonSuperClusterBuilder::m_conversionBuilder
ToolHandle< IEMConversionBuilder > m_conversionBuilder
Tool to retrieve the conversions.
Definition: photonSuperClusterBuilder.h:128
photonSuperClusterBuilder::redoMatching
virtual StatusCode redoMatching(const EventContext &ctx, SG::WriteHandle< EgammaRecContainer > &newEgammaRecs) const final override
Definition: photonSuperClusterBuilder.cxx:54
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
xAOD::EgammaParameters::EgammaType
EgammaType
Definition: EgammaEnums.h:17
WriteHandle.h
Handle class for recording to StoreGate.
photonSuperClusterBuilder::m_useOnlyLeadingVertex
Gaudi::Property< bool > m_useOnlyLeadingVertex
use only the leading vertex for matching
Definition: photonSuperClusterBuilder.h:153
egammaSuperClusterBuilderBase::matchesInWindow
bool matchesInWindow(const xAOD::CaloCluster *ref, const xAOD::CaloCluster *clus) const
Is clus in window center around ref?
Definition: egammaSuperClusterBuilderBase.cxx:409
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
EgammaxAODHelpers.h
photonSuperClusterBuilder::searchForSecondaryClusters
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.
Definition: photonSuperClusterBuilder.cxx:73
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
photonSuperClusterBuilder::m_useOnlySi
Gaudi::Property< bool > m_useOnlySi
use only vertices/tracks with silicon tracks
Definition: photonSuperClusterBuilder.h:161
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloCluster.h
photonSuperClusterBuilder::m_doConversions
Gaudi::Property< bool > m_doConversions
private member flag to do the conversion building and matching
Definition: photonSuperClusterBuilder.h:186
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::EgammaParameters::doubleSi
@ doubleSi
two tracks, both with Si hits
Definition: EgammaEnums.h:279
PhotonxAODHelpers.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
egammaRec::getNumberOfTrackParticles
size_t getNumberOfTrackParticles() const
Return the number xAOD::TrackParticles that match the electron candidate.
egammaRec::trackParticle
const xAOD::TrackParticle * trackParticle(size_t index=0) const
Pointer to the xAOD::TrackParticle/s that match the electron candidate.
Definition: egammaRec.cxx:31
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Vertex.h
xAOD::EgammaParameters::singleSi
@ singleSi
one track only, with Si hits
Definition: EgammaEnums.h:273
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
photonSuperClusterBuilder::matchesVtxTrack
bool matchesVtxTrack(const std::vector< const xAOD::TrackParticle * > &seedVertexTracks, const egammaRec *egRec) const
Does the cluster match a conversion vertex track with the seed?
Definition: photonSuperClusterBuilder.cxx:188
photonSuperClusterBuilder::m_addClustersMatchingVtx
Gaudi::Property< bool > m_addClustersMatchingVtx
add the topoclusters matching conversion vertex
Definition: photonSuperClusterBuilder.h:145
CaloClusterStoreHelper.h
TrackParticle.h
EgammaEnums.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
egammaRec::vertex
const xAOD::Vertex * vertex(size_t index=0) const
Pointer to the xAOD::Vertex/es that match the photon candidate.
Definition: egammaRec.cxx:54
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
egammaSuperClusterBuilderBase
Base class for electronSuperClusterBuilder photonSuperClusterBuilder egammaSuperClusterBuilder This c...
Definition: egammaSuperClusterBuilderBase.h:47
xAOD::EgammaHelpers::conversionType
xAOD::EgammaParameters::ConversionType conversionType(const xAOD::Photon *ph)
return the photon conversion type (see EgammaEnums)
Definition: PhotonxAODHelpers.cxx:26
egammaRec
Definition: egammaRec.h:31
photonSuperClusterBuilder::m_addClustersMatchingVtxTracks
Gaudi::Property< bool > m_addClustersMatchingVtxTracks
add the topoclusters matching conversion vertex tracks
Definition: photonSuperClusterBuilder.h:170
ReadHandle.h
Handle class for reading from StoreGate.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
photonSuperClusterBuilder.h
xAOD::EgammaParameters::unconvertedPhoton
@ unconvertedPhoton
Definition: EgammaEnums.h:19
photonSuperClusterBuilder::m_useOnlyLeadingTrack
Gaudi::Property< bool > m_useOnlyLeadingTrack
use only the leading track for matching
Definition: photonSuperClusterBuilder.h:178