File indexing completed on 2025-12-17 09:20:48
0001 #ifndef WEIGHTED_TRACK_H
0002 #define WEIGHTED_TRACK_H
0003
0004 #include <phool/PHObject.h>
0005 #include <trackbase/TrkrDefs.h>
0006 #include <Eigen/Dense>
0007
0008 #ifdef __clang__
0009 #pragma GCC diagnostic push
0010 #pragma GCC diagnostic ignored "-Wundefined-internal"
0011 #include <Eigen/Geometry>
0012 #pragma GCC diagnostic pop
0013 #else
0014 #include <Eigen/Geometry>
0015 #endif
0016
0017 #include <Math/Minimizer.h>
0018
0019 #include <iostream>
0020 #include <utility>
0021 #include <vector>
0022
0023 class ClusterFitPoint : public PHObject {
0024 public:
0025 ClusterFitPoint() = default;
0026 virtual ~ClusterFitPoint() = default;
0027
0028 PHObject* CloneMe() const override { return new ClusterFitPoint(*this); }
0029
0030
0031 TrkrDefs::cluskey cluster_key{};
0032
0033 Eigen::Vector3d cluster_position = Eigen::Vector3d::Zero();
0034
0035 Eigen::Vector2d cluster_errors = Eigen::Vector2d::Ones();
0036
0037
0038 Eigen::Affine3d sensor_local_to_global_transform = Eigen::Affine3d::Identity();
0039
0040
0041 Eigen::Vector2d get_residuals (Eigen::Vector3d const& ) const;
0042 Eigen::Vector2d get_weighted_residuals (Eigen::Vector3d const& ) const;
0043
0044 private:
0045 ClassDefOverride(ClusterFitPoint, 1)
0046 };
0047
0048 class WeightedTrack : public PHObject, private std::vector<ClusterFitPoint> {
0049 public:
0050 virtual ~WeightedTrack() = default;
0051
0052
0053 virtual PHObject* CloneMe() const override = 0;
0054
0055
0056
0057
0058 virtual void set_parameters (double const* ) = 0;
0059
0060 virtual void get_parameters (double* ) const = 0;
0061
0062 virtual std::size_t get_n_parameters () const = 0;
0063
0064 virtual void configure_minimizer (ROOT::Math::Minimizer& ) = 0;
0065
0066
0067
0068 virtual Eigen::Vector3d get_partial_derivative (int , double ) const = 0;
0069
0070
0071 virtual Eigen::Vector3d get_position_at_path_length (double ) const = 0;
0072
0073 virtual Eigen::Vector3d get_slope_at_path_length (double ) const = 0;
0074
0075
0076
0077 virtual double get_path_length_of_intersection (Eigen::Affine3d const& ) const = 0;
0078
0079 virtual double get_path_length_of_pca (Eigen::Vector3d const& ) const = 0;
0080
0081
0082
0083
0084 Eigen::Vector3d get_intersection (Eigen::Affine3d const& plane) const { return get_position_at_path_length(get_path_length_of_intersection(plane)); }
0085
0086 Eigen::Vector3d get_pca (Eigen::Vector3d const& point) const { return get_position_at_path_length(get_path_length_of_pca(point)); }
0087
0088
0089 double get_squared_error (double const*);
0090
0091
0092 Eigen::Matrix<double, 2, 3> get_projection (Eigen::Affine3d const& ) const;
0093
0094 Eigen::Vector2d get_residual_derivative (int , Eigen::Affine3d const& ) const;
0095
0096
0097 void use_vertex (bool use = true) { m_use_vertex = use; }
0098
0099 Eigen::Vector3d get_vertex_position () { return m_vertex_position; }
0100
0101 Eigen::Matrix3d get_vertex_covariance () { return m_vertex_covariance; }
0102
0103 void get_vertex_position (Eigen::Vector3d&& vertex) { m_vertex_position = std::forward<Eigen::Vector3d>(vertex); }
0104
0105 void set_vertex_covariance (Eigen::Matrix3d&& covariance) { m_vertex_covariance = std::forward<Eigen::Matrix3d>(covariance); }
0106
0107 double& vertex_position (std::size_t i) { return m_vertex_position(i); }
0108
0109 double& vertex_covariance (std::size_t i, std::size_t j) { return m_vertex_covariance(i, j); }
0110
0111
0112
0113 using std::vector<ClusterFitPoint>::value_type;
0114 using std::vector<ClusterFitPoint>::allocator_type;
0115 using std::vector<ClusterFitPoint>::size_type;
0116 using std::vector<ClusterFitPoint>::difference_type;
0117 using std::vector<ClusterFitPoint>::reference;
0118 using std::vector<ClusterFitPoint>::const_reference;
0119 using std::vector<ClusterFitPoint>::pointer;
0120 using std::vector<ClusterFitPoint>::const_pointer;
0121 using std::vector<ClusterFitPoint>::iterator;
0122 using std::vector<ClusterFitPoint>::const_iterator;
0123 using std::vector<ClusterFitPoint>::reverse_iterator;
0124 using std::vector<ClusterFitPoint>::const_reverse_iterator;
0125
0126
0127 using std::vector<ClusterFitPoint>::at;
0128 using std::vector<ClusterFitPoint>::operator[];
0129 using std::vector<ClusterFitPoint>::front;
0130 using std::vector<ClusterFitPoint>::back;
0131 using std::vector<ClusterFitPoint>::data;
0132
0133
0134 using std::vector<ClusterFitPoint>::begin;
0135 using std::vector<ClusterFitPoint>::cbegin;
0136 using std::vector<ClusterFitPoint>::end;
0137 using std::vector<ClusterFitPoint>::cend;
0138 using std::vector<ClusterFitPoint>::rbegin;
0139 using std::vector<ClusterFitPoint>::crbegin;
0140 using std::vector<ClusterFitPoint>::rend;
0141 using std::vector<ClusterFitPoint>::crend;
0142
0143
0144 using std::vector<ClusterFitPoint>::empty;
0145 using std::vector<ClusterFitPoint>::size;
0146 using std::vector<ClusterFitPoint>::max_size;
0147 using std::vector<ClusterFitPoint>::reserve;
0148 using std::vector<ClusterFitPoint>::capacity;
0149 using std::vector<ClusterFitPoint>::shrink_to_fit;
0150
0151
0152 using std::vector<ClusterFitPoint>::clear;
0153 using std::vector<ClusterFitPoint>::insert;
0154
0155 using std::vector<ClusterFitPoint>::emplace;
0156 using std::vector<ClusterFitPoint>::erase;
0157 using std::vector<ClusterFitPoint>::push_back;
0158 using std::vector<ClusterFitPoint>::emplace_back;
0159
0160 using std::vector<ClusterFitPoint>::pop_back;
0161 using std::vector<ClusterFitPoint>::resize;
0162 using std::vector<ClusterFitPoint>::swap;
0163
0164 protected:
0165 WeightedTrack() = default;
0166
0167 private:
0168 bool m_use_vertex{false};
0169 Eigen::Vector3d m_vertex_position = Eigen::Vector3d::Zero();
0170 Eigen::Matrix3d m_vertex_covariance = Eigen::Matrix3d::Identity();
0171
0172 ClassDefOverride(WeightedTrack, 1)
0173 };
0174
0175 #endif