Fixes for coverity.
[u/mrichter/AliRoot.git] / STEER / STEER / AliRelAlignerKalman.h
... / ...
CommitLineData
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
16#include <TMath.h>
17#include <TVectorD.h>
18#include <TMatrix.h>
19
20class TObject;
21class AliExternalTrackParam;
22class AliESDEvent;
23class AliESDtrack;
24class TArrayI;
25class TObjArray;
26
27class AliRelAlignerKalman : public TObject {
28
29public:
30 AliRelAlignerKalman();
31 virtual ~AliRelAlignerKalman();
32 AliRelAlignerKalman& operator= (const AliRelAlignerKalman& a );
33 AliRelAlignerKalman(const AliRelAlignerKalman& a);
34
35 //User methods:
36 Bool_t AddCosmicEvent( const AliESDEvent* pEvent );
37 Bool_t AddTrackParams( const AliExternalTrackParam* p1, const AliExternalTrackParam* p2 );
38
39 void Print(Option_t* option="") const;
40
41 Double_t GetPsi() const {return (*fPX)(0);}
42 Double_t GetTheta() const {return (*fPX)(1);}
43 Double_t GetPhi() const {return (*fPX)(2);}
44 Double_t GetX() const {return (*fPX)(3);}
45 Double_t GetY() const {return (*fPX)(4);}
46 Double_t GetZ() const {return (*fPX)(5);}
47 Double_t GetTPCvdCorr() const {return (*fPX)(6);}
48 Double_t GetTPCt0() const {return (*fPX)(7);}
49 Double_t GetTPCvdY() const {if (fgkNSystemParams>8) return (*fPX)(8); else return 0.0;}
50 Double_t GetPsiErr() const {return TMath::Sqrt((*fPXcov)(0,0));}
51 Double_t GetThetaErr() const {return TMath::Sqrt((*fPXcov)(1,1));}
52 Double_t GetPhiErr() const {return TMath::Sqrt((*fPXcov)(2,2));}
53 Double_t GetXErr() const {return TMath::Sqrt((*fPXcov)(3,3));}
54 Double_t GetYErr() const {return TMath::Sqrt((*fPXcov)(4,4));}
55 Double_t GetZErr() const {return TMath::Sqrt((*fPXcov)(5,5));}
56 Double_t GetTPCvdCorrErr() const {return TMath::Sqrt((*fPXcov)(6,6));}
57 Double_t GetTPCt0Err() const {return TMath::Sqrt((*fPXcov)(7,7));}
58 Double_t GetTPCvdYErr() const {if (fgkNSystemParams>8) return TMath::Sqrt((*fPXcov)(8,8)); else return 0.0;}
59 void GetMeasurement( TVectorD& mes ) const { mes = *fPMeasurement; }
60 TVectorD* GetMeasurement() { return fPMeasurement; }
61 void GetMeasurementCov( TMatrixDSym& cov ) const { cov = *fPMeasurementCov; }
62 void SetMeasurement( const TVectorD& mes ) {*fPMeasurement = mes;}
63 void SetMeasurementCov( const TMatrixDSym& cov ) {*fPMeasurementCov = cov;}
64 TMatrixDSym* GetMeasurementCov() const { return fPMeasurementCov; }
65 void GetState( TVectorD& state ) const { state = *fPX; }
66 TVectorD* GetState() const { return fPX; }
67 void GetStateCov ( TMatrixDSym& cov ) const { cov = *fPXcov; }
68 void SetState( const TVectorD& param ) {*fPX = param;}
69 void SetStateCov (const TMatrixDSym& cov ) {*fPXcov = cov;}
70 TMatrixDSym* GetStateCov() const { return fPXcov; }
71 void GetSeed( TVectorD& seed, TMatrixDSym& seedCov ) const { seed = *fPX; seedCov = *fPXcov; }
72 void SetSeed( const TVectorD& seed, const TMatrixDSym& seedCov ) {*fPX = seed; *fPXcov = seedCov; }
73 Bool_t Merge( const AliRelAlignerKalman* al );
74 Long64_t Merge( TCollection* list );
75
76 //Expert methods:
77 Bool_t AddESDevent( const AliESDEvent* pEvent );
78 Bool_t AddESDtrack( const AliESDtrack* pTrack );
79 void SetMagField( const Double_t f ) { fMagField=f; }
80 Double_t GetMagField() const { return fMagField; }
81 Bool_t FindCosmicTrackletNumbersInEvent( TArrayI& outITStracksTArr, TArrayI& outTPCtracksTArr, const AliESDEvent* pEvent );
82 Int_t FindMatchingTracks(TObjArray& arrITS, TObjArray& arrTPC, AliESDEvent* pESD);
83 Bool_t Update();
84 void PrintCorrelationMatrix();
85 //void PrintCovarianceCorrection();
86 void PrintSystemMatrix();
87 Int_t CheckCovariance(); // check covariance matrix
88 void Reset();
89 void ResetCovariance( const Double_t number=0. );
90 void ResetTPCparamsCovariance( const Double_t number=0. );
91 Double_t* GetStateArr() const { return fPX->GetMatrixArray(); }
92 Double_t* GetStateCovArr() const { return fPXcov->GetMatrixArray(); }
93 Double_t* GetMeasurementArr() const { return fPMeasurement->GetMatrixArray(); }
94 Double_t* GetMeasurementCovArr() const { return fPMeasurementCov->GetMatrixArray(); }
95 TMatrixD* GetH() const { return fPH; }
96 TVectorD* GetMeasurementPrediction() const {return fPMeasurementPrediction;}
97 const Double_t* GetDeltaArr() const {return fDelta;}
98 void SetNumericalParanoia( const Bool_t mode=kFALSE ) { fNumericalParanoia=mode; }
99 void SetCorrectionMode( const Bool_t mode=kTRUE ) { fCorrectionMode=mode; }
100 void SetOutRejSigma( const Double_t a=2. ) { fOutRejSigmas = a; }
101 void SetRejectOutliers( const Bool_t r=kTRUE ) {fRejectOutliers = r;}
102 void SetRejectOutliersSigma2Median( const Bool_t b=kTRUE );
103 void SetOutRejSigma2Median( const Double_t s ) {fOutRejSigma2Median = s;}
104 Bool_t SetTrackParams( const AliExternalTrackParam* exparam1, const AliExternalTrackParam* exparam2 );
105 const AliExternalTrackParam* GetTrackParams1() const {return fPTrackParam1;}
106 const AliExternalTrackParam* GetTrackParams2() const {return fPTrackParam2;}
107 void SetMinPointsVol1( const Int_t min ) {fMinPointsVol1=min;}
108 void SetMinPointsVol2( const Int_t min ) {fMinPointsVol2=min;}
109 void SetRequireMatchInTPC( const Bool_t s=kTRUE ) {fRequireMatchInTPC = s;}
110 void SetQ( const Double_t Q = 1e-10 ) { fQ = Q; }
111 void SetMaxMatchingDistance( const Double_t m ) {fMaxMatchingDistance=m;}
112 void SetMaxMatchingAngle( const Double_t m ) {fMaxMatchingAngle=m;}
113 void SetTPCvd( const Float_t v ) {fTPCvd=v;}
114 void SetTPCZLengthA( const Double_t l ) {fTPCZLengthA=l;}
115 void SetTPCZLengthC( const Double_t l ) {fTPCZLengthC=l;}
116 Bool_t CorrectTrack( AliExternalTrackParam* tr, const TVectorD& misalignment ) const;
117 Bool_t MisalignTrack( AliExternalTrackParam* tr, const TVectorD& misalignment ) const;
118 static void Angles( TVectorD &angles, const TMatrixD &rotmat );
119 static void RotMat( TMatrixD& R, const TVectorD& angles );
120 static void TMatrixDSymFromTMatrixD( TMatrixDSym& matsym, const TMatrixD& mat );
121 Bool_t IsPositiveDefinite( const TMatrixD& mat ) const;
122 void SetTimeStamp( const UInt_t ts ) { fTimeStamp = ts; }
123 UInt_t GetTimeStamp() const {return fTimeStamp;}
124 void SetRunNumber( const Int_t rn ) { fRunNumber = rn; }
125 Int_t GetRunNumber() const {return fRunNumber;}
126 Int_t Compare(const TObject *obj) const;
127 Bool_t IsSortable() const { return kTRUE; }
128 Int_t GetNTracks() const {return fNTracks;}
129 Int_t GetNUpdates() const {return fNUpdates;}
130 Int_t GetNOutliers() const {return fNOutliers;}
131 Int_t GetNOutliersSigma2Median() const {return fNOutliersSigma2Median;}
132 Int_t GetNMerges() const {return fNMerges;}
133 Int_t GetNMergesFailed() const {return fNMergesFailed;}
134 void SetPoint2Track( Bool_t o );
135
136protected:
137 Bool_t UpdateEstimateKalman();
138 Bool_t PrepareMeasurement();
139 Bool_t PrepareSystemMatrix();
140 Bool_t PreparePrediction();
141 Bool_t PredictMeasurement( TVectorD& z, const TVectorD& x );
142 Bool_t IsOutlier( const TVectorD& update, const TMatrixDSym& covmatrix );
143 Bool_t IsOutlierSigma2Median( const AliExternalTrackParam* pITS, const AliExternalTrackParam* pTPC );
144
145private:
146 static const Int_t fgkNSystemParams=9; //how many fit parameters
147 static const Int_t fgkNtracksSigma2Median=500; //how many sets for median and rms
148
149 //Track parameters
150 AliExternalTrackParam* fPTrackParam1; //!local track parameters
151 AliExternalTrackParam* fPTrackParam2; //!local track parameters
152 Double_t fMagField; //magnetic field
153
154 //Kalman filter related stuff
155 Int_t fNMeasurementParams; //how many measurables
156 TVectorD* fPX; //System (fit) parameters (phi, theta, psi, x, y, z, driftcorr, driftoffset )
157 TMatrixDSym* fPXcov; //covariance matrix of system parameters
158 TMatrixD* fPH; //!System measurement matrix
159 Double_t fQ; //!measure for system noise
160 TVectorD* fPMeasurement; //!the measurement vec for Kalman filter (theta,phi,x,z)
161 TMatrixDSym* fPMeasurementCov; //!measurement vec cvariance
162 TVectorD* fPMeasurementPrediction; //!prediction of the measurement
163 Double_t fOutRejSigmas; //number of sigmas for outlier rejection
164 Double_t fOutRejSigma2Median; //nsigmas to median of input residual distribution
165 Double_t fDelta[fgkNSystemParams]; //array with differentials for calculating derivatives for every parameter(see PrepareSystemMatrix())
166 Double_t* fResArrSigma2Median[4]; //!holds residuals for median based outlier removal
167
168 //Control
169 Bool_t fYZOnly; //whether to consider only yz without directions.
170 Bool_t fNumericalParanoia; //whether to perform additional checks for numerical stability
171 Bool_t fRejectOutliers; //whether to do outlier rejection in the Kalman filter
172 Bool_t fRejectOutliersSigma2Median; //whether to reject input based on distance to median
173 Bool_t fRequireMatchInTPC; //when looking for a cosmic in event, require that TPC has 2 matching segments
174 Bool_t fCuts; //track cuts?
175 Int_t fMinPointsVol1; //mininum number of points in volume 1
176 Int_t fMinPointsVol2; //mininum number of points in volume 2
177 Double_t fMinPt; //min momentum of track for track cuts
178 Double_t fMaxPt; //max momentum of track for track cuts
179 Double_t fMaxMatchingAngle; //cuts
180 Double_t fMaxMatchingDistance; //cuts
181 Bool_t fCorrectionMode; //calculate corrective transform for TPC (or monitor actual TPC misal params)
182
183 //Counters
184 Int_t fNTracks; //number of processed tracks
185 Int_t fNUpdates; //number of successful Kalman updates
186 Int_t fNOutliers; //number of outliers
187 Int_t fNOutliersSigma2Median; //number of rejected inputs
188 Int_t fNMatchedCosmics; //number of cosmic events with matching tracklets (good cosmics)
189 Int_t fNMatchedTPCtracklets;//number of cosmic events with 2 matching TPC tracklets
190 Int_t fNProcessedEvents; //number of processed events
191 UInt_t fTimeStamp; //time stamp
192 Int_t fRunNumber; //run number
193 Int_t fNMerges; //how many succesful merges
194 Int_t fNMergesFailed; //how many merges failed
195
196 //TPC stuff
197 Double_t fTPCvd; //TPC drift velocity
198 Double_t fTPCZLengthA; //TPC length side A
199 Double_t fTPCZLengthC; //TPC length side C
200
201 ClassDef(AliRelAlignerKalman,4) //AliRelAlignerKalman class
202};
203
204#endif
205
206