Adding Cluster and KalmanTrack classes from J.Belikov
[u/mrichter/AliRoot.git] / STEER / AliKalmanTrack.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 //-------------------------------------------------------------------------
17 //                Implementation of the AliKalmanTrack class
18 //
19 //        Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
20 //-------------------------------------------------------------------------
21
22 #include "AliKalmanTrack.h"
23 #include "AliCluster.h"
24 #include <TMath.h>
25 #include <iostream.h>
26
27 ClassImp(AliKalmanTrack)
28
29 //_____________________________________________________________________________
30 AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack& t) {
31   //-----------------------------------------------------------------
32   // This is a copy constructor.
33   //-----------------------------------------------------------------
34   fLab=t.fLab;
35
36   fP0=t.fP0; fP1=t.fP1; fP2=t.fP2; fP3=t.fP3; fP4=t.fP4;
37
38   fC00=t.fC00;
39   fC10=t.fC10;  fC11=t.fC11;
40   fC20=t.fC20;  fC21=t.fC21;  fC22=t.fC22;
41   fC30=t.fC30;  fC31=t.fC31;  fC32=t.fC32;  fC33=t.fC33;
42   fC40=t.fC40;  fC41=t.fC41;  fC42=t.fC42;  fC43=t.fC43;  fC44=t.fC44;
43
44   fChi2=t.fChi2;
45   fN=t.fN;
46 }
47
48 //_____________________________________________________________________________
49 Int_t AliKalmanTrack::Compare(TObject *o) {
50   //-----------------------------------------------------------------
51   // This function compares tracks according to the their curvature
52   //-----------------------------------------------------------------
53   AliKalmanTrack *t=(AliKalmanTrack*)o;
54   Double_t co=TMath::Abs(t->GetPt());
55   Double_t c =TMath::Abs(GetPt());
56   if (c<co) return 1;
57   else if (c>co) return -1;
58   return 0;
59 }
60
61 //_____________________________________________________________________________
62 Double_t AliKalmanTrack::GetPredictedChi2(const AliCluster *c) const 
63 {
64   //-----------------------------------------------------------------
65   // This function calculates a predicted chi2 increment.
66   //-----------------------------------------------------------------
67   Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
68   r00+=fC00; r01+=fC10; r11+=fC11;
69
70   Double_t det=r00*r11 - r01*r01;
71   if (TMath::Abs(det) < 1.e-10) {
72     if (fN>4) cerr<<fN<<" AliKalmanTrack warning: Singular matrix !\n";
73     return 1e10;
74   }
75   Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
76   
77   Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
78   
79   return (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
80 }
81
82 //_____________________________________________________________________________
83 void AliKalmanTrack::GetCovariance(Double_t cc[15]) const {
84   // return covariance maxtrix
85   cc[0 ]=fC00;
86   cc[1 ]=fC10;  cc[2 ]=fC11;
87   cc[3 ]=fC20;  cc[4 ]=fC21;  cc[5 ]=fC22;
88   cc[6 ]=fC30;  cc[7 ]=fC31;  cc[8 ]=fC32;  cc[9 ]=fC33;
89   cc[10]=fC40;  cc[11]=fC41;  cc[12]=fC42;  cc[13]=fC43;  cc[14]=fC44;
90 }
91
92 //____________________________________________________________________________
93 void AliKalmanTrack::Streamer(TBuffer &R__b)
94 {
95   //-----------------------------------------------------
96   // This is AliKalmanTrack streamer.
97   //-----------------------------------------------------
98    if (R__b.IsReading()) {
99       Version_t R__v = R__b.ReadVersion(); if (R__v) { }
100       TObject::Streamer(R__b);
101       R__b >> fLab;
102       R__b >> fP0;
103       R__b >> fP1;
104       R__b >> fP2;
105       R__b >> fP3;
106       R__b >> fP4;
107       R__b >> fC00;
108       R__b >> fC10;
109       R__b >> fC11;
110       R__b >> fC20;
111       R__b >> fC21;
112       R__b >> fC22;
113       R__b >> fC30;
114       R__b >> fC31;
115       R__b >> fC32;
116       R__b >> fC33;
117       R__b >> fC40;
118       R__b >> fC41;
119       R__b >> fC42;
120       R__b >> fC43;
121       R__b >> fC44;
122       R__b >> fChi2;
123       R__b >> fN;
124    } else {
125       R__b.WriteVersion(AliKalmanTrack::IsA());
126       TObject::Streamer(R__b);
127       R__b << fLab;
128       R__b << fP0;
129       R__b << fP1;
130       R__b << fP2;
131       R__b << fP3;
132       R__b << fP4;
133       R__b << fC00;
134       R__b << fC10;
135       R__b << fC11;
136       R__b << fC20;
137       R__b << fC21;
138       R__b << fC22;
139       R__b << fC30;
140       R__b << fC31;
141       R__b << fC32;
142       R__b << fC33;
143       R__b << fC40;
144       R__b << fC41;
145       R__b << fC42;
146       R__b << fC43;
147       R__b << fC44;
148       R__b << fChi2;
149       R__b << fN;
150    }
151 }
152
153