ATLAS Offline Software
PhotonxAODHelpers.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include "xAODEgamma/Photon.h"
9 #include "xAODTracking/Vertex.h"
10 
11 
12 #include<cmath>
13 
14 // ==================================================================
15 
16 bool xAOD::EgammaHelpers::isConvertedPhoton(const xAOD::Photon *ph, bool excludeTRT) {
17  if (!ph) return false;
18  return EgammaDetails::isConvertedPhoton(excludeTRT, ph->eta(), ph->nVertices(), conversionType(ph));
19 }
20 
23  return conversionType(ph->vertex());
24 }
25 
28 
29  const TrackParticle *trk1 = ( vx->nTrackParticles() ? vx->trackParticle(0) : nullptr );
30  const TrackParticle *trk2 = ( vx->nTrackParticles() > 1 ? vx->trackParticle(1) : nullptr );
31  uint8_t nSiHits1 = numberOfSiHits(trk1);
32  uint8_t nSiHits2 = numberOfSiHits(trk2);
33 
34  return EgammaDetails::conversionType (trk1 != nullptr, trk2 != nullptr, nSiHits1, nSiHits2);
35 }
36 
37 // ==================================================================
38 
40  if (!ph || !ph->vertex()) {return 0;}
41  return numberOfSiTracks(ph->vertex());
42 }
43 
45  if (!vx) return 0;
46  return numberOfSiTracks(conversionType(vx));
47 }
48 
50  if (convType == xAOD::EgammaParameters::doubleSi) {return 2;}
51  if (convType == xAOD::EgammaParameters::singleSi ||
52  convType == xAOD::EgammaParameters::doubleSiTRT) {return 1;}
53  return 0;
54 }
55 
56 // ==================================================================
57 
59  if (!vx) return 9999.;
60  return sqrt( vx->x()*vx->x() + vx->y()*vx->y() );
61 }
62 
64  if (!ph || !ph->vertex()) return 9999.;
65  return conversionRadius(ph->vertex());
66 }
67 
68 // ==================================================================
69 
71  if (!photon || !photon->vertex()) return Amg::Vector3D(0., 0., 0.);
72  return momentumAtVertex(*photon->vertex(), debug);
73 }
74 
75 
77 
78  static const SG::AuxElement::Accessor<float> accPx("px");
79  static const SG::AuxElement::Accessor<float> accPy("py");
80  static const SG::AuxElement::Accessor<float> accPz("pz");
81 
82  if (accPx.isAvailable(vertex) &&
83  accPy.isAvailable(vertex) &&
84  accPz.isAvailable(vertex))
85  {
86  return Amg::Vector3D(accPx(vertex),
87  accPy(vertex),
88  accPz(vertex));
89  }
90  if (debug){
91  std::cout << "Vertex not decorated with momentum" << std::endl;
92  }
93  return Amg::Vector3D(0., 0., 0.);
94 }
95 
96 // ==================================================================
97 std::set<const xAOD::TrackParticle*> xAOD::EgammaHelpers::getTrackParticles(const xAOD::Photon* ph,
98  bool useBremAssoc /* = true */){
99 
100  std::set<const xAOD::TrackParticle*> tps;
101  if (!ph) return tps;
102  for (unsigned int ivx = 0; ivx < ph->nVertices(); ++ivx)
103  {
104  const xAOD::Vertex* vx = ph->vertex(ivx);
105  for (unsigned int i=0; vx && i < vx->nTrackParticles(); ++i){
106  const xAOD::TrackParticle *tp = vx->trackParticle(i);
107  tps.insert( useBremAssoc ? xAOD::EgammaHelpers::getOriginalTrackParticleFromGSF(tp) : tp );
108  }
109  }
110  return tps;
111 }
112 // ==================================================================
113 std::vector<const xAOD::TrackParticle*> xAOD::EgammaHelpers::getTrackParticlesVec(const xAOD::Photon* ph,
114  bool useBremAssoc /* = true */){
115  std::vector<const xAOD::TrackParticle*> tps;
116  if (!ph) return tps;
117  for (unsigned int ivx = 0; ivx < ph->nVertices(); ++ivx)
118  {
119  const xAOD::Vertex* vx = ph->vertex(ivx);
120  for (unsigned int i=0; vx && i < vx->nTrackParticles(); ++i){
121  const xAOD::TrackParticle *tp = vx->trackParticle(i);
122  tps.push_back( useBremAssoc ? xAOD::EgammaHelpers::getOriginalTrackParticleFromGSF(tp) : tp );
123  }
124  }
125  return tps;
126 }
xAOD::EgammaParameters::unconverted
@ unconverted
unconverted photon
Definition: EgammaEnums.h:270
xAOD::Photon_v1::nVertices
size_t nVertices() const
Return the number xAOD::Vertex/vertices that match the photon candidate.
xAOD::Vertex_v1::x
float x() const
Returns the x position.
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:558
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
ElectronxAODHelpers.h
ParticleTest.tp
tp
Definition: ParticleTest.py:25
xAOD::EgammaHelpers::getTrackParticles
std::set< const xAOD::TrackParticle * > getTrackParticles(const xAOD::Egamma *eg, bool useBremAssoc=true, bool allParticles=true)
Return a list of all or only the best TrackParticle associated to the object.
Definition: EgammaxAODHelpers.cxx:120
xAOD::EgammaDetails::isConvertedPhoton
bool isConvertedPhoton(const bool excludeTRT, const float eta, const std::size_t nVertices, const ConversionType conversionType)
is the object a converted photon
Definition: EgammaDetails.h:59
xAOD::EgammaParameters::ConversionType
ConversionType
Definition: EgammaEnums.h:268
xAOD::EgammaHelpers::getTrackParticlesVec
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.
Definition: EgammaxAODHelpers.cxx:141
xAOD::EgammaDetails::conversionType
ConversionType conversionType(const bool hasTrk1, const bool hasTrk2, const std::uint8_t nSiHits1, const std::uint8_t nSiHits2)
return the photon conversion type (see EgammaEnums)
Definition: EgammaDetails.h:40
xAOD::EgammaHelpers::numberOfSiTracks
std::size_t numberOfSiTracks(const xAOD::Photon *eg)
return the number of Si tracks in the conversion
Definition: PhotonxAODHelpers.cxx:39
xAOD::EgammaHelpers::isConvertedPhoton
bool isConvertedPhoton(const xAOD::Egamma *eg, bool excludeTRT=false)
is the object a converted photon
Definition: EgammaxAODHelpers.cxx:25
lumiFormat.i
int i
Definition: lumiFormat.py:85
Photon.h
xAOD::EgammaHelpers::momentumAtVertex
Amg::Vector3D momentumAtVertex(const xAOD::Photon *, bool debug=false)
return the momentum at the vertex (which can be 0)
Definition: PhotonxAODHelpers.cxx:70
xAOD::EgammaParameters::doubleSi
@ doubleSi
two tracks, both with Si hits
Definition: EgammaEnums.h:279
PhotonxAODHelpers.h
xAOD::Vertex_v1::trackParticle
const TrackParticle * trackParticle(size_t i) const
Get the pointer to a given track that was used in vertex reco.
Definition: Vertex_v1.cxx:249
Vertex.h
xAOD::EgammaParameters::doubleSiTRT
@ doubleSiTRT
two tracks, only one with Si hits
Definition: EgammaEnums.h:285
xAOD::EgammaParameters::singleSi
@ singleSi
one track only, with Si hits
Definition: EgammaEnums.h:273
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
xAOD::EgammaHelpers::conversionRadius
float conversionRadius(const xAOD::Vertex *vx)
return the conversion radius or 9999.
Definition: PhotonxAODHelpers.cxx:58
xAOD::EgammaHelpers::getOriginalTrackParticleFromGSF
const xAOD::TrackParticle * getOriginalTrackParticleFromGSF(const xAOD::TrackParticle *trkPar)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the GSF Track Particle...
Definition: ElectronxAODHelpers.cxx:22
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
xAOD::EgammaHelpers::numberOfSiHits
std::size_t numberOfSiHits(const xAOD::TrackParticle *tp)
return the number of Si hits in the track particle
Definition: ElectronxAODHelpers.cxx:66
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:200
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
xAOD::Photon_v1
Definition: Photon_v1.h:37
xAOD::Vertex_v1::y
float y() const
Returns the y position.
xAOD::EgammaHelpers::conversionType
xAOD::EgammaParameters::ConversionType conversionType(const xAOD::Photon *ph)
return the photon conversion type (see EgammaEnums)
Definition: PhotonxAODHelpers.cxx:21
SG::ConstAccessor< T, AuxAllocator_t< T > >::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
xAOD::Egamma_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: Egamma_v1.cxx:70
xAOD::EgammaParameters::NumberOfVertexConversionTypes
@ NumberOfVertexConversionTypes
maximum number of types
Definition: EgammaEnums.h:288
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
xAOD::Photon_v1::vertex
const xAOD::Vertex * vertex(size_t index=0) const
Pointer to the xAOD::Vertex/es that match the photon candidate.
Definition: Photon_v1.cxx:46
EgammaDetails.h