File indexing completed on 2026-09-25 09:10:23
0001
0002
0003 #ifndef EDM4HEP_MutableCluster_H
0004 #define EDM4HEP_MutableCluster_H
0005
0006 #include "edm4hep/ClusterObj.h"
0007
0008 #include "edm4hep/Cluster.h"
0009
0010 #include "edm4hep/CalorimeterHit.h"
0011 #include "edm4hep/CovMatrix3f.h"
0012 #include "edm4hep/Vector3f.h"
0013 #include "podio/RelationRange.h"
0014 #include <cstdint>
0015 #include <edm4hep/Constants.h>
0016 #include <vector>
0017
0018 #include "podio/utilities/MaybeSharedPtr.h"
0019
0020 #include <cstdint>
0021
0022 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0023 #include "nlohmann/json_fwd.hpp"
0024 #endif
0025
0026
0027 namespace edm4hep {
0028 class ClusterCollection;
0029 }
0030
0031 namespace edm4hep {
0032
0033
0034
0035
0036
0037 class MutableCluster {
0038
0039 friend class ClusterCollection;
0040 friend class ClusterMutableCollectionIterator;
0041 friend class Cluster;
0042
0043 public:
0044 using object_type = Cluster;
0045 using collection_type = ClusterCollection;
0046
0047
0048 MutableCluster() = default;
0049
0050
0051 MutableCluster(const std::int32_t type, const float energy, const float energyError,
0052 const edm4hep::Vector3f& position, const edm4hep::CovMatrix3f& positionError, const float iTheta,
0053 const float iPhi, const edm4hep::Vector3f& directionError);
0054
0055
0056 MutableCluster(const MutableCluster& other) = default;
0057
0058
0059 MutableCluster& operator=(MutableCluster other) &;
0060 MutableCluster&
0061 operator=(MutableCluster other) && = delete;
0062
0063
0064
0065 MutableCluster clone(bool cloneRelations = true) const;
0066
0067
0068 ~MutableCluster() = default;
0069
0070 public:
0071
0072 std::int32_t getType() const;
0073
0074
0075 float getEnergy() const;
0076
0077
0078 float getEnergyError() const;
0079
0080
0081 const edm4hep::Vector3f& getPosition() const;
0082
0083
0084 const edm4hep::CovMatrix3f& getPositionError() const;
0085
0086
0087
0088 float getITheta() const;
0089
0090
0091
0092 float getIPhi() const;
0093
0094
0095 const edm4hep::Vector3f& getDirectionError() const;
0096
0097
0098 void setType(const std::int32_t type);
0099
0100 std::int32_t& getType();
0101
0102
0103 void setEnergy(const float energy);
0104
0105 float& getEnergy();
0106
0107
0108 void setEnergyError(const float energyError);
0109
0110 float& getEnergyError();
0111
0112
0113 void setPosition(const edm4hep::Vector3f& position);
0114
0115 edm4hep::Vector3f& getPosition();
0116
0117
0118 void setPositionError(const edm4hep::CovMatrix3f& positionError);
0119
0120 edm4hep::CovMatrix3f& getPositionError();
0121
0122
0123
0124 void setITheta(const float iTheta);
0125
0126
0127 float& getITheta();
0128
0129
0130
0131 void setIPhi(const float iPhi);
0132
0133
0134 float& getIPhi();
0135
0136
0137 void setDirectionError(const edm4hep::Vector3f& directionError);
0138
0139 edm4hep::Vector3f& getDirectionError();
0140
0141 void addToClusters(const edm4hep::Cluster&);
0142 std::size_t clusters_size() const;
0143 edm4hep::Cluster getClusters(std::size_t) const;
0144 std::vector<edm4hep::Cluster>::const_iterator clusters_begin() const;
0145 std::vector<edm4hep::Cluster>::const_iterator clusters_end() const;
0146 podio::RelationRange<edm4hep::Cluster> getClusters() const;
0147 void addToHits(const edm4hep::CalorimeterHit&);
0148 std::size_t hits_size() const;
0149 edm4hep::CalorimeterHit getHits(std::size_t) const;
0150 std::vector<edm4hep::CalorimeterHit>::const_iterator hits_begin() const;
0151 std::vector<edm4hep::CalorimeterHit>::const_iterator hits_end() const;
0152 podio::RelationRange<edm4hep::CalorimeterHit> getHits() const;
0153 void addToShapeParameters(const float&);
0154 std::size_t shapeParameters_size() const;
0155 float getShapeParameters(std::size_t) const;
0156 std::vector<float>::const_iterator shapeParameters_begin() const;
0157 std::vector<float>::const_iterator shapeParameters_end() const;
0158 podio::RelationRange<float> getShapeParameters() const;
0159 void addToSubdetectorEnergies(const float&);
0160 std::size_t subdetectorEnergies_size() const;
0161 float getSubdetectorEnergies(std::size_t) const;
0162 std::vector<float>::const_iterator subdetectorEnergies_begin() const;
0163 std::vector<float>::const_iterator subdetectorEnergies_end() const;
0164 podio::RelationRange<float> getSubdetectorEnergies() const;
0165
0166
0167 float getPositionError(edm4hep::Cartesian dimI, edm4hep::Cartesian dimJ) const {
0168 return getPositionError().getValue(dimI, dimJ);
0169 }
0170
0171
0172 [[deprecated("Use getIPhi instead")]] float getPhi() const { return getIPhi(); }
0173
0174
0175 void setPositionError(float value, edm4hep::Cartesian dimI, edm4hep::Cartesian dimJ) {
0176 return getPositionError().setValue(value, dimI, dimJ);
0177 }
0178
0179
0180 [[deprecated("Use setIPhi instead")]] void setPhi(float value) { setIPhi(value); }
0181
0182
0183 bool isAvailable() const;
0184
0185 void unlink() { m_obj = podio::utils::MaybeSharedPtr<ClusterObj>{nullptr}; }
0186
0187 constexpr bool operator==(const MutableCluster& other) const { return m_obj == other.m_obj; }
0188 bool operator==(const Cluster& other) const;
0189
0190 constexpr bool operator!=(const MutableCluster& other) const { return !(*this == other); }
0191 bool operator!=(const Cluster& other) const { return !(*this == other); }
0192
0193
0194 bool operator<(const MutableCluster& other) const {
0195 return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other);
0196 }
0197
0198 podio::ObjectID id() const { return getObjectID(); }
0199
0200 const podio::ObjectID getObjectID() const;
0201
0202 friend std::hash<MutableCluster>;
0203
0204 friend void swap(MutableCluster& a, MutableCluster& b) {
0205 using std::swap;
0206 swap(a.m_obj, b.m_obj);
0207 }
0208
0209 private:
0210
0211 explicit MutableCluster(podio::utils::MaybeSharedPtr<ClusterObj> obj);
0212
0213 podio::utils::MaybeSharedPtr<ClusterObj> m_obj{new ClusterObj{}, podio::utils::MarkOwned};
0214 };
0215
0216 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0217 void to_json(nlohmann::json& j, const MutableCluster& value);
0218 #endif
0219
0220 }
0221
0222 template <>
0223 struct std::hash<edm4hep::MutableCluster> {
0224 std::size_t operator()(const edm4hep::MutableCluster& obj) const {
0225 return std::hash<edm4hep::ClusterObj*>{}(obj.m_obj.get());
0226 }
0227 };
0228
0229 #endif