File indexing completed on 2026-09-09 09:06:19
0001
0002
0003 #ifndef EDM4HEP_MutableVertex_H
0004 #define EDM4HEP_MutableVertex_H
0005
0006 #include "edm4hep/VertexObj.h"
0007
0008 #include "edm4hep/Vertex.h"
0009
0010 #include "edm4hep/CovMatrix3f.h"
0011 #include "edm4hep/ReconstructedParticle.h"
0012 #include "edm4hep/Vector3f.h"
0013 #include "podio/RelationRange.h"
0014 #include <cstdint>
0015 #include <edm4hep/Constants.h>
0016 #include <edm4hep/utils/bit_utils.h>
0017 #include <vector>
0018
0019 #include "podio/utilities/MaybeSharedPtr.h"
0020
0021 #include <cstdint>
0022
0023 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0024 #include "nlohmann/json_fwd.hpp"
0025 #endif
0026
0027
0028 namespace edm4hep {
0029 class VertexCollection;
0030 }
0031
0032 namespace edm4hep {
0033
0034
0035
0036
0037
0038 class MutableVertex {
0039
0040 friend class VertexCollection;
0041 friend class VertexMutableCollectionIterator;
0042 friend class Vertex;
0043
0044 public:
0045 using object_type = Vertex;
0046 using collection_type = VertexCollection;
0047
0048
0049 MutableVertex() = default;
0050
0051
0052 MutableVertex(const std::uint32_t type, const float chi2, const std::int32_t ndf, const edm4hep::Vector3f& position,
0053 const edm4hep::CovMatrix3f& covMatrix, const std::int32_t algorithmType);
0054
0055
0056 MutableVertex(const MutableVertex& other) = default;
0057
0058
0059 MutableVertex& operator=(MutableVertex other) &;
0060 MutableVertex&
0061 operator=(MutableVertex other) && = delete;
0062
0063
0064
0065 MutableVertex clone(bool cloneRelations = true) const;
0066
0067
0068 ~MutableVertex() = default;
0069
0070 public:
0071
0072 std::uint32_t getType() const;
0073
0074
0075 float getChi2() const;
0076
0077
0078 std::int32_t getNdf() const;
0079
0080
0081 const edm4hep::Vector3f& getPosition() const;
0082
0083
0084 const edm4hep::CovMatrix3f& getCovMatrix() const;
0085
0086
0087 std::int32_t getAlgorithmType() const;
0088
0089
0090 void setType(const std::uint32_t type);
0091
0092 std::uint32_t& getType();
0093
0094
0095 void setChi2(const float chi2);
0096
0097 float& getChi2();
0098
0099
0100 void setNdf(const std::int32_t ndf);
0101
0102 std::int32_t& getNdf();
0103
0104
0105 void setPosition(const edm4hep::Vector3f& position);
0106
0107 edm4hep::Vector3f& getPosition();
0108
0109
0110 void setCovMatrix(const edm4hep::CovMatrix3f& covMatrix);
0111
0112 edm4hep::CovMatrix3f& getCovMatrix();
0113
0114
0115 void setAlgorithmType(const std::int32_t algorithmType);
0116
0117 std::int32_t& getAlgorithmType();
0118
0119 void addToParticles(const edm4hep::ReconstructedParticle&);
0120 std::size_t particles_size() const;
0121 edm4hep::ReconstructedParticle getParticles(std::size_t) const;
0122 std::vector<edm4hep::ReconstructedParticle>::const_iterator particles_begin() const;
0123 std::vector<edm4hep::ReconstructedParticle>::const_iterator particles_end() const;
0124 podio::RelationRange<edm4hep::ReconstructedParticle> getParticles() const;
0125 void addToParameters(const float&);
0126 std::size_t parameters_size() const;
0127 float getParameters(std::size_t) const;
0128 std::vector<float>::const_iterator parameters_begin() const;
0129 std::vector<float>::const_iterator parameters_end() const;
0130 podio::RelationRange<float> getParameters() const;
0131
0132
0133 float getCovMatrix(edm4hep::Cartesian dimI, edm4hep::Cartesian dimJ) const {
0134 return getCovMatrix().getValue(dimI, dimJ);
0135 }
0136
0137 static constexpr int BITPrimaryVertex = 1;
0138 static constexpr int BITSecondaryVertex = 2;
0139 static constexpr int BITTertiaryVertex = 3;
0140
0141
0142 bool isPrimary() const { return utils::checkBit(getType(), BITPrimaryVertex); }
0143
0144 bool isSecondary() const { return utils::checkBit(getType(), BITSecondaryVertex); }
0145
0146 bool isTertiary() const { return utils::checkBit(getType(), BITTertiaryVertex); }
0147
0148
0149 void setCovMatrix(float value, edm4hep::Cartesian dimI, edm4hep::Cartesian dimJ) {
0150 getCovMatrix().setValue(value, dimI, dimJ);
0151 }
0152
0153
0154 void setPrimary(bool value = true) { setType(utils::setBit(getType(), BITPrimaryVertex, value)); }
0155
0156 void setSecondary(bool value = true) { setType(utils::setBit(getType(), BITSecondaryVertex, value)); }
0157
0158 void setTertiary(bool value = true) { setType(utils::setBit(getType(), BITTertiaryVertex, value)); }
0159
0160
0161 bool isAvailable() const;
0162
0163 void unlink() { m_obj = podio::utils::MaybeSharedPtr<VertexObj>{nullptr}; }
0164
0165 constexpr bool operator==(const MutableVertex& other) const { return m_obj == other.m_obj; }
0166 bool operator==(const Vertex& other) const;
0167
0168 constexpr bool operator!=(const MutableVertex& other) const { return !(*this == other); }
0169 bool operator!=(const Vertex& other) const { return !(*this == other); }
0170
0171
0172 bool operator<(const MutableVertex& other) const {
0173 return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other);
0174 }
0175
0176 podio::ObjectID id() const { return getObjectID(); }
0177
0178 const podio::ObjectID getObjectID() const;
0179
0180 friend std::hash<MutableVertex>;
0181
0182 friend void swap(MutableVertex& a, MutableVertex& b) {
0183 using std::swap;
0184 swap(a.m_obj, b.m_obj);
0185 }
0186
0187 private:
0188
0189 explicit MutableVertex(podio::utils::MaybeSharedPtr<VertexObj> obj);
0190
0191 podio::utils::MaybeSharedPtr<VertexObj> m_obj{new VertexObj{}, podio::utils::MarkOwned};
0192 };
0193
0194 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0195 void to_json(nlohmann::json& j, const MutableVertex& value);
0196 #endif
0197
0198 }
0199
0200 template <>
0201 struct std::hash<edm4hep::MutableVertex> {
0202 std::size_t operator()(const edm4hep::MutableVertex& obj) const {
0203 return std::hash<edm4hep::VertexObj*>{}(obj.m_obj.get());
0204 }
0205 };
0206
0207 #endif