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