File indexing completed on 2024-04-06 12:05:21
0001 #ifndef DataFormats_TrackingRecHit_interface_KfComponentsHolder_h_
0002 #define DataFormats_TrackingRecHit_interface_KfComponentsHolder_h_
0003
0004 #include "DataFormats/CLHEP/interface/AlgebraicObjects.h"
0005 #include "DataFormats/Math/interface/ProjectMatrix.h"
0006 #include <cstdint>
0007 #include <cassert>
0008
0009 class TrackingRecHit;
0010
0011
0012
0013 class KfComponentsHolder {
0014 public:
0015 KfComponentsHolder() {
0016 #ifdef Debug_KfComponentsHolder
0017 size_ = 0;
0018 #endif
0019 }
0020
0021 template <unsigned int D>
0022 void setup(typename AlgebraicROOTObject<D>::Vector *params,
0023 typename AlgebraicROOTObject<D, D>::SymMatrix *errors,
0024 ProjectMatrix<double, 5, D> *projFunc,
0025 typename AlgebraicROOTObject<D>::Vector *measuredParams,
0026 typename AlgebraicROOTObject<D, D>::SymMatrix *measuredErrors,
0027 const AlgebraicVector5 &tsosLocalParameters,
0028 const AlgebraicSymMatrix55 &tsosLocalErrors);
0029
0030 template <unsigned int D>
0031 typename AlgebraicROOTObject<D>::Vector ¶ms() {
0032 #ifdef Debug_KfComponentsHolder
0033 assert(size_ == D);
0034 #endif
0035 return *reinterpret_cast<typename AlgebraicROOTObject<D>::Vector *>(params_);
0036 }
0037
0038 template <unsigned int D>
0039 typename AlgebraicROOTObject<D, D>::SymMatrix &errors() {
0040 #ifdef Debug_KfComponentsHolder
0041 assert(size_ == D);
0042 #endif
0043 return *reinterpret_cast<typename AlgebraicROOTObject<D, D>::SymMatrix *>(errors_);
0044 }
0045
0046 template <unsigned int D>
0047 typename AlgebraicROOTObject<D, 5>::Matrix projection() {
0048 #ifdef Debug_KfComponentsHolder
0049 assert(size_ == D);
0050 #endif
0051 return this->projFunc<D>().matrix();
0052
0053 }
0054
0055 template <unsigned int D>
0056 ProjectMatrix<double, 5, D> &projFunc() {
0057 #ifdef Debug_KfComponentsHolder
0058 assert(size_ == D);
0059 #endif
0060 return *reinterpret_cast<ProjectMatrix<double, 5, D> *>(projFunc_);
0061 }
0062
0063
0064 void genericFill(const TrackingRecHit &hit);
0065
0066 template <unsigned int D>
0067 typename AlgebraicROOTObject<D>::Vector &measuredParams() {
0068 #ifdef Debug_KfComponentsHolder
0069 assert(size_ == D);
0070 #endif
0071 return *reinterpret_cast<typename AlgebraicROOTObject<D>::Vector *>(measuredParams_);
0072 }
0073
0074 template <unsigned int D>
0075 typename AlgebraicROOTObject<D, D>::SymMatrix &measuredErrors() {
0076 #ifdef Debug_KfComponentsHolder
0077 assert(size_ == D);
0078 #endif
0079 return *reinterpret_cast<typename AlgebraicROOTObject<D, D>::SymMatrix *>(measuredErrors_);
0080 }
0081
0082 const AlgebraicVector5 &tsosLocalParameters() const { return *tsosLocalParameters_; }
0083 const AlgebraicSymMatrix55 &tsosLocalErrors() const { return *tsosLocalErrors_; }
0084
0085 template <unsigned int D>
0086 void dump();
0087
0088 private:
0089 #ifdef Debug_KfComponentsHolder
0090 uint16_t size_;
0091 #endif
0092 void *params_, *errors_, *projFunc_, *measuredParams_, *measuredErrors_;
0093 const AlgebraicVector5 *tsosLocalParameters_;
0094 const AlgebraicSymMatrix55 *tsosLocalErrors_;
0095
0096 template <unsigned int D>
0097 void genericFill_(const TrackingRecHit &hit);
0098 };
0099
0100 template <unsigned int D>
0101 void KfComponentsHolder::setup(typename AlgebraicROOTObject<D>::Vector *params,
0102 typename AlgebraicROOTObject<D, D>::SymMatrix *errors,
0103 ProjectMatrix<double, 5, D> *projFunc,
0104 typename AlgebraicROOTObject<D>::Vector *measuredParams,
0105 typename AlgebraicROOTObject<D, D>::SymMatrix *measuredErrors,
0106 const AlgebraicVector5 &tsosLocalParameters,
0107 const AlgebraicSymMatrix55 &tsosLocalErrors) {
0108 #ifdef Debug_KfComponentsHolder
0109 assert(size_ == 0);
0110 size_ = D;
0111 #endif
0112 params_ = params;
0113 errors_ = errors;
0114 projFunc_ = projFunc;
0115 measuredParams_ = measuredParams;
0116 measuredErrors_ = measuredErrors;
0117 tsosLocalParameters_ = &tsosLocalParameters;
0118 tsosLocalErrors_ = &tsosLocalErrors;
0119 }
0120
0121 template <unsigned int D>
0122 void KfComponentsHolder::dump() {
0123 using namespace std;
0124 cout << "Params my: " << params<D>() << endl;
0125 cout << " tsos: " << tsosLocalParameters() << endl;
0126 cout << " meas: " << measuredParams<D>() << endl;
0127 cout << "Errors my:\n" << errors<D>() << endl;
0128 cout << " tsos:\n" << tsosLocalErrors() << endl;
0129 cout << " meas:\n" << measuredErrors<D>() << endl;
0130 cout << "Projection:\n" << projection<D>() << endl;
0131 }
0132
0133 #ifdef Debug_KfComponentsHolder
0134
0135 #undef Debug_KfComponentsHolder
0136 #endif
0137
0138 #endif