File indexing completed on 2025-07-01 08:35:26
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
0014 #include "podio/detail/OrderKey.h"
0015 #include "podio/utilities/MaybeSharedPtr.h"
0016
0017 #include <cstdint>
0018 #include <ostream>
0019
0020 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0021 #include "nlohmann/json_fwd.hpp"
0022 #endif
0023
0024
0025 namespace edm4hep {
0026 class SimTrackerHitCollection;
0027 class MCParticle;
0028 class MutableMCParticle;
0029 }
0030
0031 namespace podio::detail {
0032
0033 OrderKey getOrderKey(const edm4hep::SimTrackerHit& obj);
0034 };
0035
0036 namespace edm4hep {
0037
0038 class MutableSimTrackerHit;
0039 class SimTrackerHitCollection;
0040 class SimTrackerHitCollectionData;
0041
0042
0043
0044
0045
0046 class SimTrackerHit {
0047
0048 friend class MutableSimTrackerHit;
0049 friend class SimTrackerHitCollection;
0050 friend class edm4hep::SimTrackerHitCollectionData;
0051 friend class SimTrackerHitCollectionIterator;
0052 friend podio::detail::OrderKey podio::detail::getOrderKey(const SimTrackerHit& obj);
0053
0054 public:
0055 using mutable_type = MutableSimTrackerHit;
0056 using collection_type = SimTrackerHitCollection;
0057
0058
0059 SimTrackerHit();
0060
0061
0062 SimTrackerHit(std::uint64_t cellID, float eDep, float time, float pathLength, std::int32_t quality,
0063 edm4hep::Vector3d position, edm4hep::Vector3f momentum);
0064
0065
0066 SimTrackerHit(const SimTrackerHit& other) = default;
0067
0068
0069 SimTrackerHit& operator=(SimTrackerHit other);
0070
0071
0072
0073 MutableSimTrackerHit clone(bool cloneRelations = true) const;
0074
0075
0076 ~SimTrackerHit() = default;
0077
0078
0079 SimTrackerHit(const MutableSimTrackerHit& other);
0080
0081 static SimTrackerHit makeEmpty();
0082
0083 public:
0084 static constexpr auto typeName = "edm4hep::SimTrackerHit";
0085
0086
0087 std::uint64_t getCellID() const;
0088
0089
0090 float getEDep() const;
0091
0092
0093 float getTime() const;
0094
0095
0096 float getPathLength() const;
0097
0098
0099 std::int32_t getQuality() const;
0100
0101
0102 const edm4hep::Vector3d& getPosition() const;
0103
0104
0105 const edm4hep::Vector3f& getMomentum() const;
0106
0107
0108 const edm4hep::MCParticle getParticle() const;
0109
0110 static const int BITOverlay = 31;
0111 static const int BITProducedBySecondary = 30;
0112 bool isOverlay() const {
0113 return getQuality() & (1 << BITOverlay);
0114 }
0115 bool isProducedBySecondary() const {
0116 return getQuality() & (1 << BITProducedBySecondary);
0117 }
0118 double x() const {
0119 return getPosition()[0];
0120 }
0121 double y() const {
0122 return getPosition()[1];
0123 }
0124 double z() const {
0125 return getPosition()[2];
0126 }
0127 double rho() const {
0128 return sqrt(x() * x() + y() * y());
0129 }
0130 [[deprecated("use getParticle instead")]] edm4hep::MCParticle getMCParticle() const {
0131 return getParticle();
0132 }
0133
0134
0135 bool isAvailable() const;
0136
0137 void unlink() {
0138 m_obj = podio::utils::MaybeSharedPtr<SimTrackerHitObj>{nullptr};
0139 }
0140
0141 bool operator==(const SimTrackerHit& other) const {
0142 return m_obj == other.m_obj;
0143 }
0144 bool operator==(const MutableSimTrackerHit& other) const;
0145
0146 bool operator!=(const SimTrackerHit& other) const {
0147 return !(*this == other);
0148 }
0149 bool operator!=(const MutableSimTrackerHit& other) const {
0150 return !(*this == other);
0151 }
0152
0153
0154 bool operator<(const SimTrackerHit& other) const {
0155 return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other);
0156 }
0157
0158 podio::ObjectID id() const {
0159 return getObjectID();
0160 }
0161
0162 const podio::ObjectID getObjectID() const;
0163
0164 friend void swap(SimTrackerHit& a, SimTrackerHit& b) {
0165 using std::swap;
0166 swap(a.m_obj, b.m_obj);
0167 }
0168
0169 private:
0170
0171 explicit SimTrackerHit(podio::utils::MaybeSharedPtr<SimTrackerHitObj> obj);
0172 SimTrackerHit(SimTrackerHitObj* obj);
0173
0174 podio::utils::MaybeSharedPtr<SimTrackerHitObj> m_obj{nullptr};
0175 };
0176
0177 std::ostream& operator<<(std::ostream& o, const SimTrackerHit& value);
0178
0179 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0180 void to_json(nlohmann::json& j, const SimTrackerHit& value);
0181 #endif
0182
0183 }
0184
0185 #endif