ATLAS Offline Software
EgammaHelpers.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 #ifndef COLUMNAR_EGAMMA_EGAMMA_HELPERS_H
9 #define COLUMNAR_EGAMMA_EGAMMA_HELPERS_H
10 
15 
16 namespace columnar
17 {
18  namespace EgammaHelpers
19  {
26 
27 
28 
29  // not sure if this should live here, since it draws in a dependency
30  // on ColumnarTracking/xAODTracking, but let's keep it here for now
31  template<ContainerIdConcept CI = ContainerId::egamma,typename CM=ColumnarModeDefault>
33  {
40 
41  public:
43  : m_etaAcc (columnarTool, "eta"),
44  m_vertexLinksAcc (columnarTool, "vertexLinks"),
45  m_trackParticleLinksAcc (columnarTool, "trackParticleLinks", {.isOptional = true}),
46  m_numberOfPixelHitsAcc (columnarTool, "numberOfPixelHits"),
47  m_numberOfSCTHitsAcc (columnarTool, "numberOfSCTHits")
48  {
49  if constexpr (!CM::isXAOD)
50  resetAccessor (m_objectTypeAcc, columnarTool, "objectType", {.isOptional = true});
51  }
52 
60  std::pair<bool,unsigned> operator () (ObjectId<CI,CM> photon, bool excludeTRT) const
61  {
62  // While the accessor is generally meant to be used with
63  // photons, sometimes electrons are passed as photons for
64  // performance studies, etc. In xAOD mode we can just check
65  // `IParticle::type()`, while in columnar mode we need the user
66  // to pass that in as an extra column. Having an extra column
67  // for that feels like a bit of an overkill, but it is optional
68  // here, and we can revisit it later if it becomes an issue.
70  if constexpr (CM::isXAOD)
71  {
72  type = photon.getXAODObjectNoexcept().type();
73  } else
74  {
75  if (m_objectTypeAcc.isAvailable(photon))
77  }
78  if (type != xAOD::Type::Photon)
79  return std::make_pair (false, 0x0);
80 
81  const auto vertices = m_vertexLinksAcc(photon);
82  if (vertices.size() == 0) return std::make_pair (false, 0x0);
83  if (!vertices[0].has_value())
84  return std::make_pair (false, 0x1);
85 
86  unsigned missingLinks = 0x0;
87 
88  auto vertex = vertices[0].value();
89  bool hasTrk1 = false;
90  bool hasTrk2 = false;
91  std::uint8_t nSiHits1 = 0;
92  std::uint8_t nSiHits2 = 0;
93  if (m_trackParticleLinksAcc.isAvailable(vertex)) {
94  const auto tracks = m_trackParticleLinksAcc(vertex);
95  if (tracks.size() > 0) {
96  if (tracks[0].has_value()) {
97  hasTrk1 = true;
98  nSiHits1 += m_numberOfPixelHitsAcc(tracks[0].value());
99  nSiHits1 += m_numberOfSCTHitsAcc(tracks[0].value());
100  } else missingLinks |= 0x2;
101  }
102  if (tracks.size() > 1) {
103  if (tracks[1].has_value()) {
104  hasTrk2 = true;
105  nSiHits2 += m_numberOfPixelHitsAcc(tracks[1].value());
106  nSiHits2 += m_numberOfSCTHitsAcc(tracks[1].value());
107  } else missingLinks |= 0x4;
108  }
109  }
110 
111  auto conversionType = xAOD::EgammaDetails::conversionType(hasTrk1, hasTrk2, nSiHits1, nSiHits2);
112  return std::make_pair (xAOD::EgammaDetails::isConvertedPhoton (excludeTRT, photon(m_etaAcc), vertices.size(), conversionType), missingLinks);
113  }
114  };
115  }
116 }
117 
118 #endif
columnar::EgammaHelpers::IsConvertedPhotonAccessor::m_trackParticleLinksAcc
VertexAccessor< std::vector< OptObjectId< ContainerId::track, CM > >, CM > m_trackParticleLinksAcc
Definition: EgammaHelpers.h:36
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:215
columnar::EgammaHelpers::IsConvertedPhotonAccessor::IsConvertedPhotonAccessor
IsConvertedPhotonAccessor(ColumnarTool< CM > &columnarTool)
Definition: EgammaHelpers.h:42
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:553
ObjectType
ObjectType
Definition: BaseObject.h:11
TrackDef.h
athena.value
value
Definition: athena.py:124
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
EgammaDef.h
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
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
columnar::ColumnarModeXAOD::isXAOD
static constexpr bool isXAOD
Whether this is the xAOD mode.
Definition: ColumnarDef.h:20
columnar::EgammaHelpers::IsConvertedPhotonAccessor::m_etaAcc
ColumnAccessor< CI, float, CM > m_etaAcc
Definition: EgammaHelpers.h:34
ColumnAccessor.h
columnar::final
CM final
Definition: ColumnAccessor.h:106
columnar::EgammaHelpers::IsConvertedPhotonAccessor::m_numberOfSCTHitsAcc
TrackAccessor< std::uint8_t, CM > m_numberOfSCTHitsAcc
Definition: EgammaHelpers.h:38
columnar::EgammaHelpers::IsConvertedPhotonAccessor
Definition: EgammaHelpers.h:33
columnar::ObjectId
a class representing a single object (electron, muons, etc.)
Definition: ContainerId.h:178
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
columnar::EgammaHelpers::IsConvertedPhotonAccessor::operator()
std::pair< bool, unsigned > operator()(ObjectId< CI, CM > photon, bool excludeTRT) const
return whether the photon is converted, and a bitmask of missing links
Definition: EgammaHelpers.h:60
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:200
columnar
Definition: ClusterDef.h:16
columnar::ColumnarTool
the base class for all columnar components
Definition: ColumnAccessorDataArray.h:17
columnar::ColumnarModeXAOD
Definition: ColumnarDef.h:18
columnar::AccessorTemplate
the raw column accessor template class
Definition: ColumnAccessor.h:81
columnar::EgammaHelpers::IsConvertedPhotonAccessor::m_objectTypeAcc
ColumnAccessor< CI, RetypeColumn< xAOD::Type::ObjectType, std::uint16_t >, CM > m_objectTypeAcc
Definition: EgammaHelpers.h:39
columnar::resetAccessor
void resetAccessor(AccessorTemplate< CI, CT, CAM, CM > &accessor, ColumnarTool< CM > &columnBase, const std::string &name, ColumnInfo &&info={})
reset a column accessor to point to a new column
Definition: ColumnAccessor.h:252
columnar::EgammaHelpers::IsConvertedPhotonAccessor::m_vertexLinksAcc
ColumnAccessor< CI, std::vector< OptObjectId< ContainerId::vertex, CM > >, CM > m_vertexLinksAcc
Definition: EgammaHelpers.h:35
columnar::EgammaHelpers::IsConvertedPhotonAccessor::m_numberOfPixelHitsAcc
TrackAccessor< std::uint8_t, CM > m_numberOfPixelHitsAcc
Definition: EgammaHelpers.h:37
EgammaDetails.h