Major bugfix in AliL3Compress::WriteRestoredData(). Also added naming conventions...
[u/mrichter/AliRoot.git] / HLT / comp / AliL3ModelTrack.cxx
1 //$Id$
2
3 // Author: Anders Vestbo <mailto:vestbo$fi.uib.no>
4 //*-- Copyright &copy ASV
5
6 #include <stream.h>
7 #include <string.h>
8 #include <math.h>
9
10 #include "AliL3ModelTrack.h"
11 #include "AliL3Transform.h"
12
13 ClassImp(AliL3ModelTrack)
14
15 AliL3ModelTrack::AliL3ModelTrack()
16 {
17   fNClusters = 0;
18   fClusters = 0;
19   fOverlap = 0;
20   fPad=0;
21   fTime=0;
22   fClusterCharge=0;
23   fTrackModel=0;
24 }
25
26
27 AliL3ModelTrack::~AliL3ModelTrack()
28 {
29   if(fClusters)
30     delete [] fClusters;
31   if(fPad)
32     delete [] fPad;
33   if(fTime)
34     delete [] fTime;
35   if(fOverlap)
36     delete [] fOverlap;
37   if(fTrackModel)
38     delete fTrackModel;
39 }
40
41 void AliL3ModelTrack::Init(Int_t slice,Int_t patch)
42 {
43   fNClusters = 0;
44   fSlice=slice;
45   fPatch=patch;
46   Int_t nrows = NumRows[patch];
47   fClusters = new AliL3ClusterModel[nrows];
48   fPad = new Float_t[nrows];
49   fTime = new Float_t[nrows];
50   fTrackModel = new AliL3TrackModel;
51   fOverlap = new Int_t[nrows];
52   
53   memset(fClusters,0,nrows*sizeof(AliL3ClusterModel));
54   memset(fPad,0,nrows*sizeof(Float_t));
55   memset(fTime,0,nrows*sizeof(Float_t));
56   memset(fTrackModel,0,sizeof(AliL3TrackModel));
57   for(Int_t i=0; i<nrows; i++)
58     fOverlap[i]=-1;
59
60   fClusterCharge = 260;
61   AliL3Transform transform;
62   
63   fXYResidualQ = 0.1/transform.GetPadPitchWidth(patch);
64   fZResidualQ = 0.1/transform.GetPadPitchWidth(patch);
65   
66
67   fXYWidthQ = 0.01;
68   fZWidthQ = 0.01;
69 }
70
71
72 void AliL3ModelTrack::SetCluster(Int_t row,Float_t fpad,Float_t ftime,Float_t charge,Float_t sigmaY2,Float_t sigmaZ2)
73 {
74   Int_t index = row - NRows[fPatch][0];
75   if(index != fNClusters)
76     cout<<"AliL3ModelTrack::SetCluster() : Mismatch ; index: "<<index<<" nclusters "<<fNClusters<<endl;
77   
78   if(index < 0 || index > NumRows[fPatch])
79     {
80       cerr<<"AliL3ModelTrack::SetCluster() : Wrong index: "<<index<<" row "<<row<<endl;
81       return;
82     }
83   AliL3ClusterModel *cl = GetClusterModel(row);
84   if(!charge)
85     cl->fPresent = kFALSE;
86   else
87     {
88       cl->fPresent = kTRUE;
89       cl->fDTime = (ftime - GetTimeHit(row))/fXYResidualQ;
90       cl->fDPad = (fpad - GetPadHit(row))/fZResidualQ;
91       cl->fDCharge = charge - fClusterCharge;
92       cl->fDSigmaY2 = sigmaY2/fXYWidthQ;
93       cl->fDSigmaZ2 = sigmaZ2/fZWidthQ;
94     }
95   
96   fNClusters++;
97 }
98
99
100 void AliL3ModelTrack::FillModel()
101 {
102   //Fill the track structure
103   
104   if(!fTrackModel)
105     {
106       cerr<<"AliL3ModelTrack::FillModel() : No trackmodel "<<endl;
107       return;
108     }
109   fTrackModel->fKappa = GetKappa();
110   fTrackModel->fFirstPointX = GetFirstPointX();
111   fTrackModel->fFirstPointY = GetFirstPointY();
112   fTrackModel->fFirstPointZ = GetFirstPointZ();
113   fTrackModel->fTgl = GetTgl();
114   fTrackModel->fPsi = GetPsi();
115   fTrackModel->fLength = (Short_t)GetLength();
116   fTrackModel->fClusterCharge = fClusterCharge;
117   fTrackModel->fNClusters = fNClusters;
118
119 }
120
121 void AliL3ModelTrack::FillTrack()
122 {
123   //Fill the track parameters from the structure.
124   
125   if(!fTrackModel)
126     {
127       cerr<<"AliL3ModelTrack::FillTrack() : No data!!"<<endl;
128       return;
129     }
130   SetKappa(fTrackModel->fKappa);
131   SetCharge((-1*(Int_t)copysign(1.,GetKappa())));
132   SetFirstPoint(fTrackModel->fFirstPointX,fTrackModel->fFirstPointY,fTrackModel->fFirstPointZ);
133   SetTgl(fTrackModel->fTgl);
134   SetPsi(fTrackModel->fPsi);
135   SetLength(fTrackModel->fLength);
136   fClusterCharge=fTrackModel->fClusterCharge;
137   fNClusters = fTrackModel->fNClusters;
138   SetPt((BFACT*BField)/fabs(GetKappa()));
139   
140   CalculateHelix();
141   
142   AliL3Transform transform;
143   Float_t hit[3];
144   Int_t sector,row;
145   for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
146     {
147       AliL3ClusterModel *cl = GetClusterModel(i);
148       if(!cl) continue;
149       GetCrossingPoint(i,hit);
150       transform.Slice2Sector(fSlice,i,sector,row);
151       transform.Local2Raw(hit,sector,row);
152       SetPadHit(i,hit[1]);
153       SetTimeHit(i,hit[2]);
154     }
155 }
156
157 void AliL3ModelTrack::SetPadHit(Int_t row,Float_t pad)
158 {
159   Int_t index = row-NRows[fPatch][0];
160   if(index < 0 || index > NumRows[fPatch])
161     {
162       cerr<<"AliL3ModelTrack::SetPadHit() : Wrong index: "<<index<<endl;
163       return;
164     }
165   fPad[index]=pad;
166   
167 }
168
169 void AliL3ModelTrack::SetTimeHit(Int_t row,Float_t time)
170 {
171   Int_t index = row-NRows[fPatch][0];
172   if(index < 0 || index > NumRows[fPatch])
173     {
174       cerr<<"AliL3ModelTrack::SetTimeHit() : Wrong index: "<<index<<endl;
175       return;
176     }
177   fTime[index]=time;
178 }
179
180 void AliL3ModelTrack::SetOverlap(Int_t row,Int_t id)
181 {
182   Int_t index = row-NRows[fPatch][0];
183   if(index < 0 || index > NumRows[fPatch])
184     {
185       cerr<<"AliL3ModelTrack::SetOverlap() : Wrong index: "<<index<<endl;
186       return;
187     }
188   fOverlap[index]=id;
189 }
190
191 Bool_t AliL3ModelTrack::GetPad(Int_t row,Float_t &pad)
192 {
193   //(ftime - GetTimeHit(fNClusters))/fXYResidualQ;
194   //(fpad - GetPadHit(fNClusters))/fZResidualQ;
195
196   AliL3ClusterModel *cl = GetClusterModel(row);
197   pad = cl->fDPad*fXYResidualQ + GetPadHit(row);
198
199   return (Bool_t)cl->fPresent;
200 }
201
202 Bool_t AliL3ModelTrack::GetTime(Int_t row,Float_t &time)
203 {
204   AliL3ClusterModel *cl = GetClusterModel(row);
205   time = cl->fDTime*fZResidualQ + GetTimeHit(row);
206
207   return (Bool_t)cl->fPresent;
208 }
209
210 Bool_t AliL3ModelTrack::GetClusterCharge(Int_t row,Int_t &charge)
211 {
212   AliL3ClusterModel *cl = GetClusterModel(row);
213   charge = (Int_t)cl->fDCharge + fClusterCharge;
214   
215   return (Bool_t)cl->fPresent;
216 }
217
218 Bool_t AliL3ModelTrack::GetXYWidth(Int_t row,Float_t &width)
219 {
220   AliL3ClusterModel *cl = GetClusterModel(row);
221   width = cl->fDSigmaY2*fXYWidthQ;
222   
223   return (Bool_t)cl->fPresent;
224 }
225
226 Bool_t AliL3ModelTrack::GetZWidth(Int_t row,Float_t &width)
227 {
228   AliL3ClusterModel *cl = GetClusterModel(row);
229   width = cl->fDSigmaZ2*fZWidthQ;
230   
231   return (Bool_t)cl->fPresent;
232 }
233
234 Bool_t AliL3ModelTrack::GetPadResidual(Int_t row,Float_t &res)
235 {
236   res = fClusters[row].fDPad;
237   return fClusters[row].fPresent;
238 }
239
240 Bool_t AliL3ModelTrack::GetTimeResidual(Int_t row,Float_t &res)
241 {
242   res = fClusters[row].fDTime;
243   return fClusters[row].fPresent;
244 }
245
246 Float_t AliL3ModelTrack::GetPadHit(Int_t row)
247 {
248   Int_t index = row-NRows[fPatch][0];
249   if(index < 0 || index > NumRows[fPatch])
250     {
251       cerr<<"AliL3ModelTrack::GetPadHit() : Wrong index: "<<index<<" row "<<row<<endl;
252       return 0;
253     }
254   return fPad[index];
255 }
256
257 Float_t AliL3ModelTrack::GetTimeHit(Int_t row)
258 {
259   Int_t index = row-NRows[fPatch][0];
260   if(index < 0 || index > NumRows[fPatch])
261     {
262       cerr<<"AliL3ModelTrack::GetTimeHit() : Wrong index: "<<index<<" row "<<row<<endl;
263       return 0;
264     }
265   return fTime[index];
266 }
267
268 Int_t AliL3ModelTrack::GetOverlap(Int_t row)
269 {
270   Int_t index = row-NRows[fPatch][0];
271   if(index < 0 || index > NumRows[fPatch])
272     {
273       cerr<<"AliL3ModelTrack::GetOverlap() : Wrong index: "<<index<<endl;
274       return 0;
275     }
276   return fOverlap[index];
277 }
278
279 AliL3ClusterModel *AliL3ModelTrack::GetClusterModel(Int_t row)
280 {
281   if(!fClusters) return 0; 
282   Int_t index = row-NRows[fPatch][0];
283   if(index < 0 || index > NumRows[fPatch])
284     {
285       cerr<<"AliL3ModelTrack::GetClusterModel() : Wrong index: "<<index<<endl;
286       return 0;
287     }
288   return &fClusters[index];
289 }
290
291 void AliL3ModelTrack::Print()
292 {
293   //Print info
294
295   cout<<"---------------------"<<endl;
296   cout<<"First point "<<GetFirstPointX()<<" "<<GetFirstPointY()<<" "<<GetFirstPointZ()<<endl;
297   cout<<"Last point "<<GetLastPointX()<<" "<<GetLastPointY()<<" "<<GetLastPointZ()<<endl;
298   cout<<"Pt "<<GetPt()<<" kappa "<<GetKappa()<<" tgl "<<GetTgl()<<" psi "<<GetPsi()<<" charge "<<GetCharge()<<endl;
299   cout<<"Center "<<GetCenterX()<<" "<<GetCenterY()<<endl<<endl;
300   cout<<"NHits "<<GetNClusters()<<endl;
301   cout<<"Clusters:"<<endl;
302
303   for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
304     {
305       AliL3ClusterModel *cl = GetClusterModel(i);
306       
307       if(!cl->fPresent)
308         cout<<i<<" Empty"<<" Padcrossing "<<GetPadHit(i)<<" Timecrossing "<<GetTimeHit(i)<<" ";
309       else
310         {
311           cout<<i<<" Dpad "<<cl->fDPad<<" Dtime "<<cl->fDTime<<" Dcharge "<<cl->fDCharge;
312           cout<<" Padcrossing "<<GetPadHit(i)<<" Timecrossing "<<GetTimeHit(i)<<" ";
313         }
314       cout<<"Overlapping index "<<GetOverlap(i)<<endl;
315     }
316 }
317
318 //----------Code below taken from AliTPCTracker.cxx-----------------------
319 //Functions that give the expected cluster errors based on track parameters.
320 Double_t AliL3ModelTrack::GetParSigmaY2(Double_t r)//, Double_t tgl, Double_t pt)
321 {
322   
323   //
324   // Parametrised error of the cluster reconstruction (pad direction)   
325   //
326   // Sigma rphi
327   
328   Double_t tgl = GetTgl();
329   Double_t pt = GetPt();
330   
331   const Float_t kArphi=0.41818e-2;
332   const Float_t kBrphi=0.17460e-4;
333   const Float_t kCrphi=0.30993e-2;
334   const Float_t kDrphi=0.41061e-3;
335   
336   pt=fabs(pt)*1000.;
337   Double_t x=r/pt;
338   tgl=fabs(tgl);
339   Double_t s=kArphi - kBrphi*r*tgl + kCrphi*x*x + kDrphi*x;
340   if (s<0.4e-3) s=0.4e-3;
341   s*=1.3; //Iouri Belikov
342
343   return s;
344 }
345
346 Double_t AliL3ModelTrack::GetParSigmaZ2(Double_t r)//, Double_t tgl) 
347 {
348   //
349   // Parametrised error of the cluster reconstruction (drift direction)
350   //
351   // Sigma z
352   
353   Double_t tgl = GetTgl();
354
355   const Float_t kAz=0.39614e-2;
356   const Float_t kBz=0.22443e-4;
357   const Float_t kCz=0.51504e-1;
358   
359
360   tgl=fabs(tgl);
361   Double_t s=kAz - kBz*r*tgl + kCz*tgl*tgl;
362   if (s<0.4e-3) s=0.4e-3;
363   s*=1.3; //Iouri Belikov
364
365   return s;
366 }