File indexing completed on 2025-08-05 08:18:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include "SpacepointMeasurement.h"
0021
0022 #include "Exception.h"
0023 #include "RKTrackRep.h"
0024 #include "Tools.h"
0025 #include "HMatrixUV.h"
0026 #include "MeasurementOnPlane.h"
0027
0028 #include <cassert>
0029 #include <TBuffer.h>
0030
0031 namespace genfit {
0032
0033 SpacepointMeasurement::SpacepointMeasurement(int nDim)
0034 : AbsMeasurement(nDim), weightedPlaneContruction_(true), G_(3), cutCov_(true)
0035 {
0036 assert(nDim >= 3);
0037
0038
0039 }
0040
0041 SpacepointMeasurement::SpacepointMeasurement(const TVectorD& rawHitCoords, const TMatrixDSym& rawHitCov, int detId, int hitId, TrackPoint* trackPoint,
0042 bool weightedPlaneContruction, bool cutCov)
0043 : AbsMeasurement(rawHitCoords, rawHitCov, detId, hitId, trackPoint),
0044 weightedPlaneContruction_(weightedPlaneContruction), cutCov_(cutCov)
0045 {
0046 assert(rawHitCoords_.GetNrows() >= 3);
0047
0048 if (weightedPlaneContruction_)
0049 this->initG();
0050 }
0051
0052
0053 SharedPlanePtr SpacepointMeasurement::constructPlane(const StateOnPlane& state) const {
0054
0055
0056 StateOnPlane st(state);
0057
0058 const TVector3 point(rawHitCoords_(0), rawHitCoords_(1), rawHitCoords_(2));
0059
0060 if (weightedPlaneContruction_)
0061 st.extrapolateToPoint(point, G_);
0062 else
0063 st.extrapolateToPoint(point);
0064
0065 return st.getPlane();
0066 }
0067
0068
0069 std::vector<MeasurementOnPlane*> SpacepointMeasurement::constructMeasurementsOnPlane(const StateOnPlane& state) const
0070 {
0071 MeasurementOnPlane* mop = new MeasurementOnPlane(TVectorD(2),
0072 TMatrixDSym(3),
0073 state.getPlane(), state.getRep(), constructHMatrix(state.getRep()));
0074
0075 TVectorD& m = mop->getState();
0076 TMatrixDSym& V = mop->getCov();
0077
0078 const TVector3& o(state.getPlane()->getO());
0079 const TVector3& u(state.getPlane()->getU());
0080 const TVector3& v(state.getPlane()->getV());
0081
0082
0083 m(0) = (rawHitCoords_(0)-o.X()) * u.X() +
0084 (rawHitCoords_(1)-o.Y()) * u.Y() +
0085 (rawHitCoords_(2)-o.Z()) * u.Z();
0086
0087 m(1) = (rawHitCoords_(0)-o.X()) * v.X() +
0088 (rawHitCoords_(1)-o.Y()) * v.Y() +
0089 (rawHitCoords_(2)-o.Z()) * v.Z();
0090
0091
0092
0093
0094 V = rawHitCov_;
0095
0096
0097 TMatrixD jac(3,2);
0098 jac(0,0) = u.X();
0099 jac(1,0) = u.Y();
0100 jac(2,0) = u.Z();
0101 jac(0,1) = v.X();
0102 jac(1,1) = v.Y();
0103 jac(2,1) = v.Z();
0104
0105 if (cutCov_) {
0106 tools::invertMatrix(V);
0107 V.SimilarityT(jac);
0108 tools::invertMatrix(V);
0109 }
0110 else {
0111 V.SimilarityT(jac);
0112 }
0113
0114 std::vector<MeasurementOnPlane*> retVal;
0115 retVal.push_back(mop);
0116 return retVal;
0117 }
0118
0119
0120 const AbsHMatrix* SpacepointMeasurement::constructHMatrix(const AbsTrackRep* rep) const {
0121 if (dynamic_cast<const RKTrackRep*>(rep) == nullptr) {
0122 Exception exc("SpacepointMeasurement default implementation can only handle state vectors of type RKTrackRep!", __LINE__,__FILE__);
0123 throw exc;
0124 }
0125
0126 return new HMatrixUV();
0127 }
0128
0129
0130 void SpacepointMeasurement::initG() {
0131 rawHitCov_.GetSub(0, 2, G_);
0132 tools::invertMatrix(G_);
0133 }
0134
0135
0136
0137 void SpacepointMeasurement::Streamer(TBuffer &R__b)
0138 {
0139
0140
0141 if (R__b.IsReading()) {
0142 R__b.ReadClassBuffer(genfit::SpacepointMeasurement::Class(),this);
0143
0144 if (weightedPlaneContruction_)
0145 this->initG();
0146 } else {
0147 R__b.WriteClassBuffer(genfit::SpacepointMeasurement::Class(),this);
0148 }
0149 }
0150
0151
0152 }