File indexing completed on 2025-06-30 08:34:23
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();
0050
0051
0052 MutableVertex(std::uint32_t type, float chi2, std::int32_t ndf, edm4hep::Vector3f position,
0053 edm4hep::CovMatrix3f covMatrix, std::int32_t algorithmType);
0054
0055
0056 MutableVertex(const MutableVertex& other) = default;
0057
0058
0059 MutableVertex& operator=(MutableVertex other);
0060
0061
0062
0063 MutableVertex clone(bool cloneRelations = true) const;
0064
0065
0066 ~MutableVertex() = default;
0067
0068 public:
0069
0070 std::uint32_t getType() const;
0071
0072
0073 float getChi2() const;
0074
0075
0076 std::int32_t getNdf() const;
0077
0078
0079 const edm4hep::Vector3f& getPosition() const;
0080
0081
0082 const edm4hep::CovMatrix3f& getCovMatrix() const;
0083
0084
0085 std::int32_t getAlgorithmType() const;
0086
0087
0088 void setType(std::uint32_t value);
0089
0090 std::uint32_t& getType();
0091
0092 [[deprecated("use getType instead")]] std::uint32_t& type();
0093
0094
0095 void setChi2(float value);
0096
0097 float& getChi2();
0098
0099 [[deprecated("use getChi2 instead")]] float& chi2();
0100
0101
0102 void setNdf(std::int32_t value);
0103
0104 std::int32_t& getNdf();
0105
0106 [[deprecated("use getNdf instead")]] std::int32_t& ndf();
0107
0108
0109 void setPosition(edm4hep::Vector3f value);
0110
0111 edm4hep::Vector3f& getPosition();
0112
0113 [[deprecated("use getPosition instead")]] edm4hep::Vector3f& position();
0114
0115
0116 void setCovMatrix(edm4hep::CovMatrix3f value);
0117
0118 edm4hep::CovMatrix3f& getCovMatrix();
0119
0120 [[deprecated("use getCovMatrix instead")]] edm4hep::CovMatrix3f& covMatrix();
0121
0122
0123 void setAlgorithmType(std::int32_t value);
0124
0125 std::int32_t& getAlgorithmType();
0126
0127 [[deprecated("use getAlgorithmType instead")]] std::int32_t& algorithmType();
0128
0129 void addToParticles(const edm4hep::ReconstructedParticle&);
0130 std::size_t particles_size() const;
0131 edm4hep::ReconstructedParticle getParticles(std::size_t) const;
0132 std::vector<edm4hep::ReconstructedParticle>::const_iterator particles_begin() const;
0133 std::vector<edm4hep::ReconstructedParticle>::const_iterator particles_end() const;
0134 podio::RelationRange<edm4hep::ReconstructedParticle> getParticles() const;
0135 void addToParameters(const float&);
0136 std::size_t parameters_size() const;
0137 float getParameters(std::size_t) const;
0138 std::vector<float>::const_iterator parameters_begin() const;
0139 std::vector<float>::const_iterator parameters_end() const;
0140 podio::RelationRange<float> getParameters() const;
0141
0142
0143 float getCovMatrix(edm4hep::Cartesian dimI, edm4hep::Cartesian dimJ) const {
0144 return getCovMatrix().getValue(dimI, dimJ);
0145 }
0146
0147 static constexpr int BITPrimaryVertex = 1;
0148 static constexpr int BITSecondaryVertex = 2;
0149 static constexpr int BITTertiaryVertex = 2;
0150
0151
0152 bool isPrimary() const {
0153 return utils::checkBit(getType(), BITPrimaryVertex);
0154 }
0155
0156 bool isSecondary() const {
0157 return utils::checkBit(getType(), BITSecondaryVertex);
0158 }
0159
0160 bool isTertiary() const {
0161 return utils::checkBit(getType(), BITTertiaryVertex);
0162 }
0163
0164
0165 void setCovMatrix(float value, edm4hep::Cartesian dimI, edm4hep::Cartesian dimJ) {
0166 getCovMatrix().setValue(value, dimI, dimJ);
0167 }
0168
0169
0170 void setPrimary(bool value = true) {
0171 setType(utils::setBit(getType(), BITPrimaryVertex, value));
0172 }
0173
0174 void setSecondary(bool value = true) {
0175 setType(utils::setBit(getType(), BITSecondaryVertex, value));
0176 }
0177
0178 void setTertiary(bool value = true) {
0179 setType(utils::setBit(getType(), BITTertiaryVertex, value));
0180 }
0181
0182
0183 bool isAvailable() const;
0184
0185 void unlink() {
0186 m_obj = podio::utils::MaybeSharedPtr<VertexObj>{nullptr};
0187 }
0188
0189 bool operator==(const MutableVertex& other) const {
0190 return m_obj == other.m_obj;
0191 }
0192 bool operator==(const Vertex& other) const;
0193
0194 bool operator!=(const MutableVertex& other) const {
0195 return !(*this == other);
0196 }
0197 bool operator!=(const Vertex& other) const {
0198 return !(*this == other);
0199 }
0200
0201
0202 bool operator<(const MutableVertex& other) const {
0203 return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other);
0204 }
0205
0206 podio::ObjectID id() const {
0207 return getObjectID();
0208 }
0209
0210 const podio::ObjectID getObjectID() const;
0211
0212 friend void swap(MutableVertex& a, MutableVertex& b) {
0213 using std::swap;
0214 swap(a.m_obj, b.m_obj);
0215 }
0216
0217 private:
0218
0219 explicit MutableVertex(podio::utils::MaybeSharedPtr<VertexObj> obj);
0220
0221 podio::utils::MaybeSharedPtr<VertexObj> m_obj{nullptr};
0222 };
0223
0224 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0225 void to_json(nlohmann::json& j, const MutableVertex& value);
0226 #endif
0227
0228 }
0229
0230 #endif