Task for offline calibration CALIBRATION_EMD runs
[u/mrichter/AliRoot.git] / STEER / AliRelAlignerKalman.h
CommitLineData
043badeb 1#ifndef ALIRELALIGNERKALMAN_H
2#define ALIRELALIGNERKALMAN_H
3
4/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
6
7///////////////////////////////////////////////////////////////////////////////
8//
9// Relative alignment of two tracking volumes (default ITS and TPC)
10// (see AliRelAlignerKalman.cxx for details)
11//
12// Origin: Mikolaj Krzewicki, Nikhef, Mikolaj.Krzewicki@cern.ch
13//
14//////////////////////////////////////////////////////////////////////////////
15
782e5230 16#include <TMath.h>
55d5da9e 17#include <TObject.h>
18#include <TVectorD.h>
782e5230 19#include <TMatrix.h>
55d5da9e 20
21class AliExternalTrackParam;
22class AliESDEvent;
23class AliESDtrack;
043badeb 24
044eb03e 25class AliRelAlignerKalman : public TObject {
043badeb 26
27public:
28 AliRelAlignerKalman();
044eb03e 29 virtual ~AliRelAlignerKalman();
30 AliRelAlignerKalman& operator= (const AliRelAlignerKalman& a );
31 AliRelAlignerKalman(const AliRelAlignerKalman& a);
043badeb 32
33 //User methods:
55d5da9e 34 Bool_t AddCosmicEvent( const AliESDEvent* pEvent );
18f65700 35 Bool_t AddTrackParams( const AliExternalTrackParam* p1, const AliExternalTrackParam* p2 );
043badeb 36
044eb03e 37 void Print(Option_t* option="") const;
043badeb 38
55d5da9e 39 Double_t GetPsi() const {return (*fPX)(0);}
40 Double_t GetTheta() const {return (*fPX)(1);}
41 Double_t GetPhi() const {return (*fPX)(2);}
42 Double_t GetX() const {return (*fPX)(3);}
43 Double_t GetY() const {return (*fPX)(4);}
44 Double_t GetZ() const {return (*fPX)(5);}
45 Double_t GetTPCvdCorr() const {return (*fPX)(6);}
3ebfbf52 46 Double_t GetTPCt0() const {return (*fPX)(7);}
47 Double_t GetTPCvdY() const {if (fgkNSystemParams>8) return (*fPX)(8); else return 0.0;}
55d5da9e 48 Double_t GetPsiErr() const {return TMath::Sqrt((*fPXcov)(0,0));}
49 Double_t GetThetaErr() const {return TMath::Sqrt((*fPXcov)(1,1));}
50 Double_t GetPhiErr() const {return TMath::Sqrt((*fPXcov)(2,2));}
51 Double_t GetXErr() const {return TMath::Sqrt((*fPXcov)(3,3));}
52 Double_t GetYErr() const {return TMath::Sqrt((*fPXcov)(4,4));}
53 Double_t GetZErr() const {return TMath::Sqrt((*fPXcov)(5,5));}
54 Double_t GetTPCvdCorrErr() const {return TMath::Sqrt((*fPXcov)(6,6));}
3ebfbf52 55 Double_t GetTPCt0Err() const {return TMath::Sqrt((*fPXcov)(7,7));}
56 Double_t GetTPCvdYErr() const {if (fgkNSystemParams>8) return TMath::Sqrt((*fPXcov)(8,8)); else return 0.0;}
55d5da9e 57 void GetMeasurement( TVectorD& mes ) const { mes = *fPMeasurement; }
3ebfbf52 58 TVectorD* GetMeasurement() { return fPMeasurement; }
55d5da9e 59 void GetMeasurementCov( TMatrixDSym& cov ) const { cov = *fPMeasurementCov; }
043badeb 60 void SetMeasurement( const TVectorD& mes ) {*fPMeasurement = mes;}
044eb03e 61 void SetMeasurementCov( const TMatrixDSym& cov ) {*fPMeasurementCov = cov;}
3ebfbf52 62 TMatrixDSym* GetMeasurementCov() const { return fPMeasurementCov; }
63 void GetState( TVectorD& state ) const { state = *fPX; }
64 TVectorD* GetState() const { return fPX; }
65 void GetStateCov ( TMatrixDSym& cov ) const { cov = *fPXcov; }
043badeb 66 void SetState( const TVectorD& param ) {*fPX = param;}
67 void SetStateCov (const TMatrixDSym& cov ) {*fPXcov = cov;}
3ebfbf52 68 TMatrixDSym* GetStateCov() const { return fPXcov; }
69 void GetSeed( TVectorD& seed, TMatrixDSym& seedCov ) const { seed = *fPX; seedCov = *fPXcov; }
043badeb 70 void SetSeed( const TVectorD& seed, const TMatrixDSym& seedCov ) {*fPX = seed; *fPXcov = seedCov; }
a80268df 71 Bool_t Merge( const AliRelAlignerKalman* al );
044eb03e 72
73 //Expert methods:
3ebfbf52 74 Bool_t AddESDevent( const AliESDEvent* pEvent );
75 Bool_t AddESDtrack( const AliESDtrack* pTrack );
76 void SetMagField( const Double_t f ) { fMagField=f; }
77 Double_t GetMagField() const { return fMagField; }
c3b5bfc1 78 Bool_t FindCosmicTrackletNumbersInEvent( TArrayI& outITStracksTArr, TArrayI& outTPCtracksTArr, const AliESDEvent* pEvent );
043badeb 79 Bool_t Update();
044eb03e 80 void SetRefSurface( const Double_t x, const Double_t alpha );
044eb03e 81 void PrintCorrelationMatrix();
3ebfbf52 82 //void PrintCovarianceCorrection();
044eb03e 83 void PrintSystemMatrix();
55d5da9e 84 void Reset();
c3b5bfc1 85 void ResetCovariance( const Double_t number=0. );
55d5da9e 86 void ResetTPCparamsCovariance( const Double_t number=0. );
87 Double_t* GetStateArr() const { return fPX->GetMatrixArray(); }
88 Double_t* GetStateCovArr() const { return fPXcov->GetMatrixArray(); }
89 Double_t* GetMeasurementArr() const { return fPMeasurement->GetMatrixArray(); }
90 Double_t* GetMeasurementCovArr() const { return fPMeasurementCov->GetMatrixArray(); }
3ebfbf52 91 TMatrixD* GetH() const { return fPH; }
55d5da9e 92 const Double_t* GetDeltaArr() const {return fDelta;}
3ebfbf52 93 void SetNumericalParanoia( const Bool_t mode=kFALSE ) { fNumericalParanoia=mode; }
94 void SetCorrectionMode( const Bool_t mode=kTRUE ) { fCorrectionMode=mode; }
044eb03e 95 void SetOutRejSigma( const Double_t a=2. ) { fOutRejSigmas = a; }
96 void SetRejectOutliers( const Bool_t r=kTRUE ) {fRejectOutliers = r;}
3ebfbf52 97 Bool_t SetTrackParams( const AliExternalTrackParam* exparam1, const AliExternalTrackParam* exparam2 );
98 const AliExternalTrackParam* GetTrackParams1() const {return fPTrackParamArr1;}
99 const AliExternalTrackParam* GetTrackParams2() const {return fPTrackParamArr2;}
c3b5bfc1 100 void SetMinPointsVol1( const Int_t min ) {fMinPointsVol1=min;}
101 void SetMinPointsVol2( const Int_t min ) {fMinPointsVol2=min;}
102 void SetRequireMatchInTPC( const Bool_t s=kTRUE ) {fRequireMatchInTPC = s;}
044eb03e 103 void SetQ( const Double_t Q = 1e-10 ) { fQ = Q; }
c3b5bfc1 104 void SetMaxMatchingDistance( const Double_t m ) {fMaxMatchingDistance=m;}
105 void SetMaxMatchingAngle( const Double_t m ) {fMaxMatchingAngle=m;}
55d5da9e 106 void SetTPCvd( const Float_t v ) {fTPCvd=v;}
107 void SetTPCZLengthA( const Double_t l ) {fTPCZLengthA=l;}
108 void SetTPCZLengthC( const Double_t l ) {fTPCZLengthC=l;}
3ebfbf52 109 Bool_t CorrectTrack( AliExternalTrackParam* tr, const TVectorD& misalignment ) const;
110 Bool_t MisalignTrack( AliExternalTrackParam* tr, const TVectorD& misalignment ) const;
044eb03e 111 static void Angles( TVectorD &angles, const TMatrixD &rotmat );
112 static void RotMat( TMatrixD& R, const TVectorD& angles );
55d5da9e 113 static void TMatrixDSymFromTMatrixD( TMatrixDSym& matsym, const TMatrixD& mat );
3ebfbf52 114 Bool_t IsPositiveDefinite( const TMatrixD& mat ) const;
a80268df 115 void SetTimeStamp( const UInt_t ts ) { fTimeStamp = ts; }
116 UInt_t GetTimeStamp() const {return fTimeStamp;}
043badeb 117
118protected:
043badeb 119 Bool_t UpdateEstimateKalman();
044eb03e 120 Bool_t PrepareMeasurement();
121 Bool_t PrepareSystemMatrix();
a80268df 122 Bool_t PreparePrediction();
043badeb 123 Bool_t PredictMeasurement( TVectorD& z, const TVectorD& x );
044eb03e 124 Bool_t IsOutlier( const TVectorD& update, const TMatrixDSym& covmatrix );
043badeb 125
126private:
3ebfbf52 127 static const Int_t fgkNTracksPerMeasurement=1; //how many tracks for one update
128 static const Int_t fgkNMeasurementParams=4; //how many measurables
129 static const Int_t fgkNSystemParams=9; //how many fit parameters
043badeb 130
044eb03e 131 //Track parameters
3ebfbf52 132 Double_t fAlpha; //!rotation angle between the local and global coordinate system like in AliExternalTrackParam
133 Double_t fLocalX; //!local x coordinate of reference plane = r(global)
134 AliExternalTrackParam* fPTrackParamArr1; //!local track parameters
135 AliExternalTrackParam* fPTrackParamArr2; //!local track parameters
a80268df 136 Double_t fMagField; //!magnetic field
044eb03e 137
043badeb 138 //Kalman filter related stuff
043badeb 139 TVectorD* fPX; //System (fit) parameters (phi, theta, psi, x, y, z, driftcorr, driftoffset )
140 TMatrixDSym* fPXcov; //covariance matrix of system parameters
3ebfbf52 141 TMatrixD* fPH; //!System measurement matrix
142 Double_t fQ; //!measure for system noise
143 TVectorD* fPMeasurement; //!the measurement vec for Kalman filter (theta,phi,x,z)
144 TMatrixDSym* fPMeasurementCov; //!measurement vec cvariance
a80268df 145 TVectorD* fPMeasurementPrediction; //!prediction of the measurement
043badeb 146 Double_t fOutRejSigmas; //number of sigmas for outlier rejection
3ebfbf52 147 Double_t* fDelta; //array with differentials for calculating derivatives for every parameter(see PrepareSystemMatrix())
044eb03e 148
149 //Control
a80268df 150 Bool_t fNumericalParanoia; //!whether to perform additional checks for numerical stability
151 Bool_t fRejectOutliers; //!whether to do outlier rejection in the Kalman filter
152 Bool_t fRequireMatchInTPC; //!when looking for a cosmic in event, require that TPC has 2 matching segments
153 Bool_t fCuts; //!track cuts?
154 Int_t fMinPointsVol1; //!mininum number of points in volume 1
155 Int_t fMinPointsVol2; //!mininum number of points in volume 2
156 Double_t fMinMom; //!min momentum of track for track cuts
157 Double_t fMaxMom; //!max momentum of track for track cuts
158 Double_t fMaxMatchingAngle; //!cuts
159 Double_t fMaxMatchingDistance; //!cuts
55d5da9e 160 Bool_t fCorrectionMode; //calculate corrective transform for TPC (or monitor actual TPC misal params)
782e5230 161
044eb03e 162 //Counters
163 Int_t fNTracks; //number of processed tracks
164 Int_t fNUpdates; //number of successful Kalman updates
165 Int_t fNOutliers; //number of outliers
55d5da9e 166 Int_t fNMatchedCosmics; //number of cosmic events with matching tracklets (good cosmics)
167 Int_t fNMatchedTPCtracklets;//number of cosmic events with 2 matching TPC tracklets
044eb03e 168 Int_t fNProcessedEvents; //number of processed events
a80268df 169 Int_t fTrackInBuffer; //!number of tracks in buffer
170 UInt_t fTimeStamp;
55d5da9e 171
172 //TPC stuff
173 Double_t fTPCvd; //TPC drift velocity
174 Double_t fTPCZLengthA; //TPC length side A
175 Double_t fTPCZLengthC; //TPC length side C
043badeb 176
3ebfbf52 177 ClassDef(AliRelAlignerKalman,1) //AliRelAlignerKalman class
043badeb 178};
179
180#endif
044eb03e 181