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
0021
0022
0023 #include "WireMeasurement.h"
0024 #include "IO.h"
0025
0026 #include <cmath>
0027 #include <algorithm>
0028
0029 #include <Exception.h>
0030 #include <RKTrackRep.h>
0031 #include <HMatrixU.h>
0032
0033 #include <cassert>
0034
0035
0036 namespace genfit {
0037
0038
0039 WireMeasurement::WireMeasurement(int nDim)
0040 : AbsMeasurement(nDim), maxDistance_(2), leftRight_(0)
0041 {
0042 assert(nDim >= 7);
0043 }
0044
0045 WireMeasurement::WireMeasurement(const TVectorD& rawHitCoords, const TMatrixDSym& rawHitCov, int detId, int hitId, TrackPoint* trackPoint)
0046 : AbsMeasurement(rawHitCoords, rawHitCov, detId, hitId, trackPoint), maxDistance_(2), leftRight_(0)
0047 {
0048 assert(rawHitCoords_.GetNrows() >= 7);
0049 }
0050
0051 SharedPlanePtr WireMeasurement::constructPlane(const StateOnPlane& state) const {
0052
0053
0054 StateOnPlane st(state);
0055
0056 TVector3 wire1(rawHitCoords_(0), rawHitCoords_(1), rawHitCoords_(2));
0057 TVector3 wire2(rawHitCoords_(3), rawHitCoords_(4), rawHitCoords_(5));
0058
0059
0060 TVector3 wireDirection = wire2 - wire1;
0061 wireDirection.SetMag(1.);
0062
0063
0064 const AbsTrackRep* rep = state.getRep();
0065 rep->extrapolateToLine(st, wire1, wireDirection);
0066 const TVector3& poca = rep->getPos(st);
0067 TVector3 dirInPoca = rep->getMom(st);
0068 dirInPoca.SetMag(1.);
0069 const TVector3& pocaOnWire = wire1 + wireDirection.Dot(poca - wire1)*wireDirection;
0070
0071
0072 if (fabs(wireDirection.Angle(dirInPoca)) < 0.01){
0073 Exception exc("WireMeasurement::detPlane(): Cannot construct detector plane, direction is parallel to wire", __LINE__,__FILE__);
0074 throw exc;
0075 }
0076
0077
0078 TVector3 U = dirInPoca.Cross(wireDirection);
0079
0080
0081 return SharedPlanePtr(new DetPlane(pocaOnWire, U, wireDirection));
0082 }
0083
0084
0085 std::vector<MeasurementOnPlane*> WireMeasurement::constructMeasurementsOnPlane(const StateOnPlane& state) const
0086 {
0087 double mR = rawHitCoords_(6);
0088 double mL = -mR;
0089 double V = rawHitCov_(6,6);
0090
0091 MeasurementOnPlane* mopL = new MeasurementOnPlane(TVectorD(1, &mL),
0092 TMatrixDSym(1, &V),
0093 state.getPlane(), state.getRep(), constructHMatrix(state.getRep()));
0094
0095 MeasurementOnPlane* mopR = new MeasurementOnPlane(TVectorD(1, &mR),
0096 TMatrixDSym(1, &V),
0097 state.getPlane(), state.getRep(), constructHMatrix(state.getRep()));
0098
0099
0100 if (leftRight_ < 0) {
0101 mopL->setWeight(1);
0102 mopR->setWeight(0);
0103 }
0104 else if (leftRight_ > 0) {
0105 mopL->setWeight(0);
0106 mopR->setWeight(1);
0107 }
0108 else {
0109 double val = 0.5 * pow(std::max(0., 1 - mR/maxDistance_), 2.);
0110 mopL->setWeight(val);
0111 mopR->setWeight(val);
0112 }
0113
0114 std::vector<MeasurementOnPlane*> retVal;
0115 retVal.push_back(mopL);
0116 retVal.push_back(mopR);
0117 return retVal;
0118 }
0119
0120 const AbsHMatrix* WireMeasurement::constructHMatrix(const AbsTrackRep* rep) const {
0121 if (dynamic_cast<const RKTrackRep*>(rep) == nullptr) {
0122 Exception exc("WireMeasurement default implementation can only handle state vectors of type RKTrackRep!", __LINE__,__FILE__);
0123 throw exc;
0124 }
0125
0126 return new HMatrixU();
0127 }
0128
0129 void WireMeasurement::setLeftRightResolution(int lr) {
0130 if (lr==0) leftRight_ = 0;
0131 else if (lr<0) leftRight_ = -1;
0132 else leftRight_ = 1;
0133 }
0134
0135
0136 }
0137