File indexing completed on 2026-12-03 10:42:24
0001
0002
0003 #ifndef EDM4HEP_SimTrackerHit_H
0004 #define EDM4HEP_SimTrackerHit_H
0005
0006 #include "edm4hep/SimTrackerHitObj.h"
0007
0008 #include "edm4hep/Vector3d.h"
0009 #include "edm4hep/Vector3f.h"
0010 #include <cmath>
0011 #include <cstdint>
0012 #include <edm4hep/MCParticle.h>
0013 #include <edm4hep/utils/bit_utils.h>
0014
0015 #include "podio/detail/OrderKey.h"
0016 #include "podio/utilities/MaybeSharedPtr.h"
0017
0018 #include <cstdint>
0019 #include <ostream>
0020
0021 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0022 #include "nlohmann/json_fwd.hpp"
0023 #endif
0024
0025
0026 namespace edm4hep {
0027 class SimTrackerHitCollection;
0028 class MCParticle;
0029 class MutableMCParticle;
0030 }
0031
0032 namespace podio::detail {
0033
0034 OrderKey getOrderKey(const edm4hep::SimTrackerHit& obj);
0035 };
0036
0037 namespace edm4hep {
0038
0039 class MutableSimTrackerHit;
0040 class SimTrackerHitCollection;
0041 class SimTrackerHitCollectionData;
0042
0043
0044
0045
0046
0047 class SimTrackerHit {
0048
0049 friend class MutableSimTrackerHit;
0050 friend class SimTrackerHitCollection;
0051 friend class edm4hep::SimTrackerHitCollectionData;
0052 friend class SimTrackerHitCollectionIterator;
0053 friend podio::detail::OrderKey podio::detail::getOrderKey(const SimTrackerHit& obj);
0054
0055 public:
0056 using mutable_type = MutableSimTrackerHit;
0057 using collection_type = SimTrackerHitCollection;
0058
0059
0060 SimTrackerHit() = default;
0061
0062
0063 SimTrackerHit(const std::uint64_t cellID, const float eDep, const float time, const float pathLength,
0064 const std::int32_t quality, const edm4hep::Vector3d& position, const edm4hep::Vector3f& momentum);
0065
0066
0067 SimTrackerHit(const SimTrackerHit& other) noexcept = default;
0068
0069
0070 SimTrackerHit(SimTrackerHit&& other) noexcept = default;
0071
0072
0073 SimTrackerHit& operator=(SimTrackerHit other) &;
0074 SimTrackerHit&
0075 operator=(SimTrackerHit other) && = delete;
0076
0077
0078
0079 MutableSimTrackerHit clone(bool cloneRelations = true) const;
0080
0081
0082 ~SimTrackerHit() = default;
0083
0084
0085 SimTrackerHit(const MutableSimTrackerHit& other);
0086
0087 static SimTrackerHit makeEmpty();
0088
0089 public:
0090 static constexpr std::string_view typeName = "edm4hep::SimTrackerHit";
0091
0092
0093 std::uint64_t getCellID() const;
0094
0095
0096 float getEDep() const;
0097
0098
0099 float getTime() const;
0100
0101
0102 float getPathLength() const;
0103
0104
0105 std::int32_t getQuality() const;
0106
0107
0108 const edm4hep::Vector3d& getPosition() const;
0109
0110
0111 const edm4hep::Vector3f& getMomentum() const;
0112
0113
0114 const edm4hep::MCParticle getParticle() const;
0115
0116 static constexpr int BITOverlay = 31;
0117 static constexpr int BITProducedBySecondary = 30;
0118 bool isOverlay() const { return getQuality() & (1 << BITOverlay); }
0119 bool isProducedBySecondary() const { return getQuality() & (1 << BITProducedBySecondary); }
0120 double x() const { return getPosition()[0]; }
0121 double y() const { return getPosition()[1]; }
0122 double z() const { return getPosition()[2]; }
0123 double rho() const { return std::hypot(x(), y()); }
0124
0125
0126 bool isAvailable() const;
0127
0128 void unlink() { m_obj = podio::utils::MaybeSharedPtr<SimTrackerHitObj>{nullptr}; }
0129
0130 constexpr bool operator==(const SimTrackerHit& other) const { return m_obj == other.m_obj; }
0131 bool operator==(const MutableSimTrackerHit& other) const;
0132
0133 constexpr bool operator!=(const SimTrackerHit& other) const { return !(*this == other); }
0134 bool operator!=(const MutableSimTrackerHit& other) const { return !(*this == other); }
0135
0136
0137 bool operator<(const SimTrackerHit& other) const {
0138 return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other);
0139 }
0140
0141 podio::ObjectID id() const { return getObjectID(); }
0142
0143 const podio::ObjectID getObjectID() const;
0144
0145 friend std::hash<SimTrackerHit>;
0146
0147 friend void swap(SimTrackerHit& a, SimTrackerHit& b) {
0148 using std::swap;
0149 swap(a.m_obj, b.m_obj);
0150 }
0151
0152 private:
0153
0154 explicit SimTrackerHit(podio::utils::MaybeSharedPtr<SimTrackerHitObj> obj);
0155 SimTrackerHit(SimTrackerHitObj* obj);
0156
0157 podio::utils::MaybeSharedPtr<SimTrackerHitObj> m_obj{new SimTrackerHitObj{}, podio::utils::MarkOwned};
0158 };
0159
0160 std::ostream& operator<<(std::ostream& o, const SimTrackerHit& value);
0161
0162 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0163 void to_json(nlohmann::json& j, const SimTrackerHit& value);
0164 #endif
0165
0166 }
0167
0168 template <>
0169 struct std::hash<edm4hep::SimTrackerHit> {
0170 std::size_t operator()(const edm4hep::SimTrackerHit& obj) const {
0171 return std::hash<edm4hep::SimTrackerHitObj*>{}(obj.m_obj.get());
0172 }
0173 };
0174
0175
0176
0177
0178 #if defined(__clang__)
0179 #pragma clang diagnostic push
0180 #pragma clang diagnostic ignored "-Wunknown-warning-option"
0181 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
0182 #pragma clang diagnostic ignored "-Wdeprecated"
0183 constexpr std::string_view edm4hep::SimTrackerHit::typeName;
0184 #pragma clang diagnostic pop
0185 #elif defined(__GNUC__)
0186 #pragma GCC diagnostic push
0187 #pragma GCC diagnostic ignored "-Wdeprecated"
0188 constexpr std::string_view edm4hep::SimTrackerHit::typeName;
0189 #pragma GCC diagnostic pop
0190 #endif
0191
0192 #endif