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