ATLAS Offline Software
PhotonxAODHelpers.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "xAODEgamma/Photon.h"
8 #include "xAODTracking/Vertex.h"
9 
10 
11 #include<cmath>
12 
13 // ==================================================================
14 
15 bool xAOD::EgammaHelpers::isConvertedPhoton(const xAOD::Photon *ph, bool excludeTRT) {
16  const bool hasVertices = ph && (ph->nVertices() > 0);
17  if (excludeTRT) {
18  // special case for Run3: consider unconv if TRT Conv in the barrel
21  const bool isTRTConv = (conversionType == singleTRT) || (conversionType == doubleTRT);
22  return hasVertices && (std::abs(ph->eta()) > 0.8 || !isTRTConv);
23  }
24  return hasVertices;
25 }
26 
29  return conversionType(ph->vertex());
30 }
31 
34 
35  const TrackParticle *trk1 = ( vx->nTrackParticles() ? vx->trackParticle(0) : nullptr );
36  const TrackParticle *trk2 = ( vx->nTrackParticles() > 1 ? vx->trackParticle(1) : nullptr );
37  uint8_t nSiHits1 = numberOfSiHits(trk1);
38  uint8_t nSiHits2 = numberOfSiHits(trk2);
39 
40  if (!trk1) {return xAOD::EgammaParameters::unconverted;}
41 
42  if (!trk2)
44 
45  if (nSiHits1 && nSiHits2){
47  }
48  if (nSiHits1 || nSiHits2){
50  }
51  else{
53  }
54 }
55 
56 // ==================================================================
57 
59  if (!ph || !ph->vertex()) {return 0;}
60  return numberOfSiTracks(ph->vertex());
61 }
62 
64  if (!vx) return 0;
65  return numberOfSiTracks(conversionType(vx));
66 }
67 
69  if (convType == xAOD::EgammaParameters::doubleSi) {return 2;}
70  if (convType == xAOD::EgammaParameters::singleSi ||
71  convType == xAOD::EgammaParameters::doubleSiTRT) {return 1;}
72  return 0;
73 }
74 
75 // ==================================================================
76 
78  if (!vx) return 9999.;
79  return sqrt( vx->x()*vx->x() + vx->y()*vx->y() );
80 }
81 
83  if (!ph || !ph->vertex()) return 9999.;
84  return conversionRadius(ph->vertex());
85 }
86 
87 // ==================================================================
88 
90  if (!photon || !photon->vertex()) return Amg::Vector3D(0., 0., 0.);
91  return momentumAtVertex(*photon->vertex(), debug);
92 }
93 
94 
96 
97  static const SG::AuxElement::Accessor<float> accPx("px");
98  static const SG::AuxElement::Accessor<float> accPy("py");
99  static const SG::AuxElement::Accessor<float> accPz("pz");
100 
101  if (accPx.isAvailable(vertex) &&
102  accPy.isAvailable(vertex) &&
103  accPz.isAvailable(vertex))
104  {
105  return Amg::Vector3D(accPx(vertex),
106  accPy(vertex),
107  accPz(vertex));
108  }
109  if (debug){
110  std::cout << "Vertex not decorated with momentum" << std::endl;
111  }
112  return Amg::Vector3D(0., 0., 0.);
113 }
114 
115 // ==================================================================
116 std::set<const xAOD::TrackParticle*> xAOD::EgammaHelpers::getTrackParticles(const xAOD::Photon* ph,
117  bool useBremAssoc /* = true */){
118 
119  std::set<const xAOD::TrackParticle*> tps;
120  if (!ph) return tps;
121  for (unsigned int ivx = 0; ivx < ph->nVertices(); ++ivx)
122  {
123  const xAOD::Vertex* vx = ph->vertex(ivx);
124  for (unsigned int i=0; vx && i < vx->nTrackParticles(); ++i){
125  const xAOD::TrackParticle *tp = vx->trackParticle(i);
126  tps.insert( useBremAssoc ? xAOD::EgammaHelpers::getOriginalTrackParticleFromGSF(tp) : tp );
127  }
128  }
129  return tps;
130 }
131 // ==================================================================
132 std::vector<const xAOD::TrackParticle*> xAOD::EgammaHelpers::getTrackParticlesVec(const xAOD::Photon* ph,
133  bool useBremAssoc /* = true */){
134  std::vector<const xAOD::TrackParticle*> tps;
135  if (!ph) return tps;
136  for (unsigned int ivx = 0; ivx < ph->nVertices(); ++ivx)
137  {
138  const xAOD::Vertex* vx = ph->vertex(ivx);
139  for (unsigned int i=0; vx && i < vx->nTrackParticles(); ++i){
140  const xAOD::TrackParticle *tp = vx->trackParticle(i);
141  tps.push_back( useBremAssoc ? xAOD::EgammaHelpers::getOriginalTrackParticleFromGSF(tp) : tp );
142  }
143  }
144  return tps;
145 }
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:557
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::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::EgammaHelpers::numberOfSiTracks
std::size_t numberOfSiTracks(const xAOD::Photon *eg)
return the number of Si tracks in the conversion
Definition: PhotonxAODHelpers.cxx:58
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:89
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::singleTRT
@ singleTRT
one track only, no Si hits (TRT only)
Definition: EgammaEnums.h:276
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:77
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:27
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::doubleTRT
@ doubleTRT
two tracks, none with Si hits (TRT only)
Definition: EgammaEnums.h:282
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