//*--- Author: Erik Krebs #include "TMatrixD.h" #include "TMath.h" #include "TVector3.h" #include "hkalplane.h" #include "hkaltrackstate.h" #include using namespace std; ClassImp(HKalTrackState) //_HADES_CLASS_DESCRIPTION /////////////////////////////////////////////////////////////////////////////// // // Class: HKalTrackState // // The state of the particle track at a given site k can be described by a vector // a_k containing a set of track parameters: // 1. x0: x position // 2. y0: y position // 3. tx: p_x / p_z // 4. ty: p_y / p_z // 5. qp: particle charage in elementary charges divided by // magnitude of momentum in MeV/c // // The class also stores the matrices needed for the Kalman filter: // 1. propagator: F_k = @f_k(a_k) / @a_k // 2. projector : H_k = @h_k(a_k) / @a^(k-1)_k // 3. covariance // 4. process noise // where f_k(a_k) is the propagator function that propagates the track to // the next site and h_k(a_k) projects the track state onto a measurement vector. // //----------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////// // ----------------------------------- // Ctors and Dtor // ----------------------------------- HKalTrackState::HKalTrackState(Kalman::kalFilterTypes stateType, Int_t measDim, Int_t stateDim) : TObject(), fPropagator(stateDim, stateDim), fProjector(measDim, stateDim), fCovariance(stateDim, stateDim), fProcessNoise(stateDim, stateDim), stateVec(stateDim) { // Create state with dummy state vector and matrices. // stateType: state is either for the prediction, filtering, smoothing or inverse filtering step in the Kalman filter // measDim: dimension of measurement vector // stateDim: dimension of state vector. type = stateType; fPropagator.UnitMatrix(); fProjector.UnitMatrix(); fCovariance.UnitMatrix(); } HKalTrackState::HKalTrackState(Kalman::kalFilterTypes stateType, const TVectorD &sv, Int_t measDim) : TObject(), fPropagator(sv.GetNrows(), sv.GetNrows()), fProjector(measDim, sv.GetNrows()), fCovariance(sv.GetNrows(), sv.GetNrows()), fProcessNoise(sv.GetNrows(), sv.GetNrows()), stateVec(sv) { // Create a state with dummy matrices and sets the state vector equal to function // parameter sv. // stateType: state is either for the prediction, filtering, smoothing or inverse filtering step in the Kalman filter // sv: state vector. // measDim: dimension of measurement vector. type = stateType; fPropagator.UnitMatrix(); fProjector.UnitMatrix(); fCovariance.UnitMatrix(); } HKalTrackState::~HKalTrackState() { } // ----------------------------------- // Implementation of public methods // ----------------------------------- void HKalTrackState::calcMeasVec(TVectorD &projMeasVec) const { // Calculates a measurement vector from this state. // projMeasVec: return value. #ifdef kalDebug if(projMeasVec.GetNrows() != getMeasDim()) { Warning("calcMeasVec", Form("Needed to resize TVectorD. Dimension of measurement vector (%i) does not match that of function parameter (%i).", getMeasDim(), projMeasVec.GetNrows())); projMeasVec.ResizeTo(getMeasDim()); } #endif projMeasVec(0) = stateVec(kIdxX0); projMeasVec(1) = stateVec(kIdxY0); } void HKalTrackState::calcDir(TVector3 &dir) const { // Calculates a direction unit vector from this state. // dir: track direction (return value). calcDir(dir, stateVec); } void HKalTrackState::calcDir(TVector3 &dir, const TVectorD &sv) { // Calculates a direction unit vector from a state vector given by function // parameter sv. // dir: track direction (return value) // sv: state vector to calculate direction from. Double_t tanx = sv(kIdxTanPhi); Double_t tany = sv(kIdxTanTheta); Double_t qp = sv(kIdxQP); dir.SetZ( 1./(TMath::Abs(qp) * TMath::Sqrt(tanx*tanx + tany*tany + 1)) ); dir.SetX(tanx * dir.Z()); dir.SetY(tany * dir.Z()); dir = dir.Unit(); } void HKalTrackState::calcMomVec(TVector3 &dir) const { // Calculates the momentum vector from this state. // dir: track momentum (return value). calcMomVec(dir, stateVec); } void HKalTrackState::calcMomVec(TVector3 &dir, const TVectorD &sv) { // Calculates momentum vector from a state vector given by function // parameter sv. // dir: track momentum (return value) // sv: state vector to calculate direction from. Double_t tanx = sv(kIdxTanPhi); Double_t tany = sv(kIdxTanTheta); Double_t qp = sv(kIdxQP); dir.SetZ( 1./(TMath::Abs(qp) * TMath::Sqrt(tanx*tanx + tany*tany + 1)) ); dir.SetX(tanx * dir.Z()); dir.SetY(tany * dir.Z()); } void HKalTrackState::calcPosAtPlane(TVector3 &pos, const HKalPlane &plane) const { // Calculate the track position as a three dimensional vector from this state. // Only two coordinates are stored in the state vector. The z-coordinate is // calculated by going in z-direction and find the intersection with a plane. // pos: track position (return value). // plane: the plane the track is on. calcPosAtPlane(pos, plane, stateVec); } void HKalTrackState::calcPosAtPlane(TVector3 &pos, const HKalPlane &plane, const TVectorD &sv) { // Calculate the track position as a three dimensional vector from the state // given by function parameter sv. // Only two coordinates are stored in the state vector. The z-coordinate is // calculated by going in z-direction and find the intersection with a plane. // pos: track position (return value). // plane: the plane the track is on. TVector3 posFrom; posFrom.SetX(sv(kIdxX0)); posFrom.SetY(sv(kIdxY0)); posFrom.SetZ(0.); TVector3 dir(0., 0., 1.); plane.findIntersection(pos, posFrom, dir); } void HKalTrackState::calcPosAndDirAtPlane(TVector3 &pos, TVector3 &dir, const HKalPlane &plane) const { // Calculate the track position and direction as three dimensional vectors // from this state. // pos: track position (return value) // dir: track direction (return value) // plane: the plane the track is on calcPosAtPlane(pos, plane); calcDir(dir); } void HKalTrackState::calcStateVec(TVectorD &sv, Double_t qp, const TVector3 &pos, const TVector3 &dir) { // Return the state vector from a position, direction and momentum. // sv: the state vector (return value) // qp: particle charage in elementary charges divided by magnitude of momentum in MeV/c // pos: track position // dir: track direction. #ifdef kalDebug Int_t retDim = sv.GetNrows(); Int_t stateDim = 5; if(retDim != stateDim) { sv.ResizeTo(stateDim); cout<<"Needed to resize TVectorD. Dimension of function parameter ("<