File indexing completed on 2025-09-13 08:54:45
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 <edm4hep/MCParticle.h>
0013 #include <edm4hep/MCParticle.h>
0014 #include <cmath>
0015 #include <cstdint>
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
0033 namespace edm4hep {
0034
0035
0036
0037
0038
0039
0040 class MutableSimTrackerHit {
0041
0042 friend class SimTrackerHitCollection;
0043 friend class SimTrackerHitMutableCollectionIterator;
0044 friend class SimTrackerHit;
0045
0046 public:
0047 using object_type = SimTrackerHit;
0048 using collection_type = SimTrackerHitCollection;
0049
0050
0051 MutableSimTrackerHit();
0052
0053
0054 MutableSimTrackerHit(const std::uint64_t cellID, const float eDep, const float time, const float pathLength, const std::int32_t quality, const edm4hep::Vector3d& position, const edm4hep::Vector3f& momentum);
0055
0056
0057 MutableSimTrackerHit(const MutableSimTrackerHit& other) = default;
0058
0059
0060 MutableSimTrackerHit& operator=(MutableSimTrackerHit other) &;
0061 MutableSimTrackerHit& operator=(MutableSimTrackerHit other) && = delete;
0062
0063
0064
0065 MutableSimTrackerHit clone(bool cloneRelations=true) const;
0066
0067
0068 ~MutableSimTrackerHit() = default;
0069
0070
0071 public:
0072
0073
0074 std::uint64_t getCellID() const;
0075
0076
0077 float getEDep() const;
0078
0079
0080 float getTime() const;
0081
0082
0083 float getPathLength() const;
0084
0085
0086 std::int32_t getQuality() const;
0087
0088
0089 const edm4hep::Vector3d& getPosition() const;
0090
0091
0092 const edm4hep::Vector3f& getMomentum() const;
0093
0094
0095
0096 const edm4hep::MCParticle getParticle() const;
0097
0098
0099 void setCellID(const std::uint64_t cellID);
0100
0101 std::uint64_t& getCellID();
0102
0103 [[deprecated("use getCellID instead")]]
0104 std::uint64_t& cellID();
0105
0106
0107 void setEDep(const float eDep);
0108
0109 float& getEDep();
0110
0111 [[deprecated("use getEDep instead")]]
0112 float& eDep();
0113
0114
0115 void setTime(const float time);
0116
0117 float& getTime();
0118
0119 [[deprecated("use getTime instead")]]
0120 float& time();
0121
0122
0123 void setPathLength(const float pathLength);
0124
0125 float& getPathLength();
0126
0127 [[deprecated("use getPathLength instead")]]
0128 float& pathLength();
0129
0130
0131 void setQuality(const std::int32_t quality);
0132
0133 std::int32_t& getQuality();
0134
0135 [[deprecated("use getQuality instead")]]
0136 std::int32_t& quality();
0137
0138
0139 void setPosition(const edm4hep::Vector3d& position);
0140
0141 edm4hep::Vector3d& getPosition();
0142
0143 [[deprecated("use getPosition instead")]]
0144 edm4hep::Vector3d& position();
0145
0146
0147 void setMomentum(const edm4hep::Vector3f& momentum);
0148
0149 edm4hep::Vector3f& getMomentum();
0150
0151 [[deprecated("use getMomentum instead")]]
0152 edm4hep::Vector3f& momentum();
0153
0154
0155
0156 void setParticle(const edm4hep::MCParticle& value);
0157
0158
0159 static const int BITOverlay = 31;
0160 static const int BITProducedBySecondary = 30;
0161 bool isOverlay() const { return getQuality() & (1 << BITOverlay) ; }
0162 bool isProducedBySecondary() const { return getQuality() & (1 << BITProducedBySecondary) ; }
0163 double x() const {return getPosition()[0];}
0164 double y() const {return getPosition()[1];}
0165 double z() const {return getPosition()[2];}
0166 double rho() const {return sqrt(x()*x() + y()*y());}
0167 [[deprecated("use getParticle instead")]] edm4hep::MCParticle getMCParticle() const { return getParticle(); }
0168
0169
0170 int32_t set_bit(int32_t val, int num, bool bitval){ return (val & ~(1<<num)) | (bitval << num); }
0171 void setOverlay(bool val) { setQuality( set_bit( getQuality() , BITOverlay , val ) ) ; }
0172 void setProducedBySecondary(bool val) { setQuality( set_bit( getQuality() , BITProducedBySecondary , val ) ) ; }
0173 [[deprecated("use setParticle instead")]] void setMCParticle(edm4hep::MCParticle particle) { setParticle(std::move(particle)); }
0174
0175
0176
0177 bool isAvailable() const;
0178
0179 void unlink() { m_obj = podio::utils::MaybeSharedPtr<SimTrackerHitObj>{nullptr}; }
0180
0181 bool operator==(const MutableSimTrackerHit& other) const { return m_obj == other.m_obj; }
0182 bool operator==(const SimTrackerHit& other) const;
0183
0184 bool operator!=(const MutableSimTrackerHit& other) const { return !(*this == other); }
0185 bool operator!=(const SimTrackerHit& other) const { return !(*this == other); }
0186
0187
0188 bool operator<(const MutableSimTrackerHit& other) const { return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other); }
0189
0190 podio::ObjectID id() const { return getObjectID(); }
0191
0192 const podio::ObjectID getObjectID() const;
0193
0194 friend std::hash<MutableSimTrackerHit>;
0195
0196 friend void swap(MutableSimTrackerHit& a, MutableSimTrackerHit& b) {
0197 using std::swap;
0198 swap(a.m_obj, b.m_obj);
0199 }
0200
0201 private:
0202
0203 explicit MutableSimTrackerHit(podio::utils::MaybeSharedPtr<SimTrackerHitObj> obj);
0204
0205 podio::utils::MaybeSharedPtr<SimTrackerHitObj> m_obj{nullptr};
0206 };
0207
0208 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0209 void to_json(nlohmann::json& j, const MutableSimTrackerHit& value);
0210 #endif
0211
0212
0213 }
0214
0215
0216
0217 template<>
0218 struct std::hash<edm4hep::MutableSimTrackerHit> {
0219 std::size_t operator()(const edm4hep::MutableSimTrackerHit& obj) const {
0220 return std::hash<edm4hep::SimTrackerHitObj*>{}(obj.m_obj.get());
0221 }
0222 };
0223
0224
0225 #endif