]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/src/AliL3ConfMapTrack.cxx
Changes done to make the Cluser Finder calculate the errors in Pad and Time direction...
[u/mrichter/AliRoot.git] / HLT / src / AliL3ConfMapTrack.cxx
1 //$Id$
2
3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>
4 //*-- Copyright &copy ASV 
5
6 #include "AliL3RootTypes.h"
7 #include "AliL3Logging.h"
8 #include "AliL3Vertex.h"
9 #include "AliL3ConfMapPoint.h"
10 #include "AliL3ConfMapFit.h"
11 #include "AliL3ConfMapTrack.h"
12 #include "AliL3Transform.h"
13 #include <math.h>
14
15 //_____________________________________________________________
16 // AliL3ConfMapTrack
17 //
18 // Track class for conformal mapper
19
20 ClassImp(AliL3ConfMapTrack)
21
22
23 AliL3ConfMapTrack::AliL3ConfMapTrack()
24 {
25   //Constructor
26
27   fChiSq[0] = 0.;
28   fChiSq[1] = 0.;
29 }
30
31 AliL3ConfMapTrack::~AliL3ConfMapTrack()
32 {
33
34 }
35
36 void AliL3ConfMapTrack::DeleteCandidate()
37 {
38   //Deletes this track by resetting all its parameters. Does not delete
39   //the object itself.
40
41   AliL3ConfMapPoint *curHit = (AliL3ConfMapPoint*)firstHit;
42   AliL3ConfMapPoint *nextHit;
43   
44   while(curHit != 0)
45     {
46       nextHit = (AliL3ConfMapPoint*)curHit->nextTrackHit;
47       curHit->nextTrackHit = 0;
48       curHit = nextHit;
49     }
50   
51   UInt_t *hit_numbers = GetHitNumbers();
52   for(Int_t i=0; i<GetNHits(); i++)
53     {
54       //fHitNumbers[i] = 0;
55       hit_numbers[i]=0;
56     }
57     
58   SetRadius(0.);
59   SetCenterX(0.);
60   SetCenterY(0.);
61   
62   ComesFromMainVertex(false);
63
64   SetNHits(0);
65   SetCharge(0);
66   fChiSq[0] = 0.;
67   fChiSq[1] = 0.;
68 }
69
70
71 void AliL3ConfMapTrack::SetProperties(Bool_t usage)
72 {
73   //Set the hits to this track to 'usage'
74   
75   for(StartLoop(); LoopDone(); GetNextHit())
76     {
77       AliL3ConfMapPoint *p = (AliL3ConfMapPoint*)currentHit;
78       p->SetUsage(usage);
79     }
80   return;
81 }
82
83 void AliL3ConfMapTrack::Reset()
84 {
85   //Resets the fit parameters of this track.
86
87   //xy-plane
88   s11Xy   = 0;
89   s12Xy   = 0;
90   s22Xy   = 0;
91   g1Xy    = 0;
92   g2Xy    = 0;
93   fChiSq[0]  = 0.;
94     
95   //sz-plane
96   s11Sz = 0;
97   s12Sz = 0;
98   s22Sz = 0;
99   g1Sz  = 0;
100   g2Sz  = 0;
101   fChiSq[1] = 0; 
102   SetLength(0);
103   SetNHits(0);
104 }
105
106 void AliL3ConfMapTrack::UpdateParam(AliL3ConfMapPoint *thisHit)
107 {
108   //Function to update fit parameters of track
109   //Also, it updates the hit pointers.
110   
111
112   //Increment the number of hits assigned to this track:
113
114   //fNHits++;
115   Int_t nhits = GetNHits();
116   nhits++;
117   SetNHits(nhits); //SetNHits(nhits++);
118
119   //Set the hit pointers:
120   //if(fNHits == 1)
121   if(GetNHits()==1)  
122     firstHit = thisHit;
123   else
124     ((AliL3ConfMapPoint*)lastHit)->nextTrackHit = thisHit;
125   lastHit = thisHit;
126
127   
128   s11Xy = s11Xy + thisHit->GetXYWeight() ;
129   s12Xy = s12Xy + thisHit->GetXYWeight() * thisHit->GetXprime() ;
130   s22Xy = s22Xy + thisHit->GetXYWeight() * pow((thisHit->GetXprime()),2) ;
131   g1Xy  = g1Xy  + thisHit->GetXYWeight() * thisHit->GetYprime() ;
132   g2Xy  = g2Xy  + thisHit->GetXYWeight() * thisHit->GetXprime() * thisHit->GetYprime() ;
133     
134   ddXy  = s11Xy * s22Xy - pow((s12Xy),2) ;
135   if ( ddXy != 0 ) 
136     {
137       a1Xy  = ( g1Xy * s22Xy - g2Xy * s12Xy ) / ddXy ;
138       a2Xy  = ( g2Xy * s11Xy - g1Xy * s12Xy ) / ddXy ;
139     }
140
141   //     Now in the sz plane
142   s11Sz = s11Sz + thisHit->GetZWeight() ;
143   s12Sz = s12Sz + thisHit->GetZWeight() * thisHit->GetS() ;
144   s22Sz = s22Sz + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetS() ;
145   g1Sz  = g1Sz  + thisHit->GetZWeight() * thisHit->GetZ() ;
146   g2Sz  = g2Sz  + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetZ() ;
147   
148         
149   ddSz  = s11Sz * s22Sz -  s12Sz * s12Sz ;
150   if ( ddSz != 0 ) {
151     a1Sz  = ( g1Sz * s22Sz - g2Sz * s12Sz ) / ddSz ;
152     a2Sz  = ( g2Sz * s11Sz - g1Sz * s12Sz ) / ddSz ;
153   }
154 }
155
156
157 void AliL3ConfMapTrack::Fill(AliL3Vertex *vertex,Double_t max_Dca)
158 {
159   //Fill track variables with or without fit.
160   
161   //fRadius = sqrt(a2Xy*a2Xy+1)/(2*fabs(a1Xy));
162   Double_t radius = sqrt(a2Xy*a2Xy+1)/(2*fabs(a1Xy));
163   SetRadius(radius);
164
165   //fPt = (Double_t)(BFACT * AliL3Transform::GetBField() * fRadius);
166   Double_t pt = (Double_t)(BFACT * AliL3Transform::GetBField() * GetRadius());
167   SetPt(pt);
168
169   if(GetPt() > max_Dca) //go for fit of helix in real space
170     {
171       AliL3ConfMapFit *fit = new AliL3ConfMapFit(this,vertex);
172       fit->FitHelix();
173       UpdateToFirstPoint();
174       
175       delete fit;
176     }
177   else if(GetPt() == 0)
178     LOG(AliL3Log::kError,"AliL3ConfMapTrack::Fill","Tracks")<<AliL3Log::kDec<<
179       "Found track with Pt=0!!!"<<ENDLOG;
180   else
181     {
182       LOG(AliL3Log::kError,"AliL3ConfMapTrack::Fill","Tracks")<<AliL3Log::kDec<<
183         "Track with pt<max_Dca :"<<GetPt()<<ENDLOG;
184     }
185 }
186
187 void AliL3ConfMapTrack::UpdateToFirstPoint()
188 {
189   //Update track parameters to the innermost point on the track.
190   //Basically it justs calculates the intersection of the track, and a cylinder
191   //with radius = r(innermost point). Then the parameters are updated to this point.
192   //Should be called after the helixfit (in FillTracks).
193   
194   //AliL3ConfMapPoint *lHit = (AliL3ConfMapPoint*)fPoints->Last();
195   AliL3ConfMapPoint *lHit = (AliL3ConfMapPoint*)lastHit;
196   Double_t radius = sqrt(lHit->GetX()*lHit->GetX()+lHit->GetY()*lHit->GetY());
197   
198   //Get the track parameters
199   
200   Double_t tPhi0 = GetPsi() + GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
201   Double_t x0    = GetR0() * cos(GetPhi0()) ;
202   Double_t y0    = GetR0() * sin(GetPhi0()) ;
203   Double_t rc    = fabs(GetPt()) / ( BFACT * AliL3Transform::GetBField() )  ;
204   Double_t xc    = x0 - rc * cos(tPhi0) ;
205   Double_t yc    = y0 - rc * sin(tPhi0) ;
206   
207   //Check helix and cylinder intersect
208   
209   Double_t fac1 = xc*xc + yc*yc ;
210   Double_t sfac = sqrt( fac1 ) ;
211     
212   if ( fabs(sfac-rc) > radius || fabs(sfac+rc) < radius ) {
213     LOG(AliL3Log::kError,"AliL3ConfMapTrack::UpdateToLastPoint","Tracks")<<AliL3Log::kDec<<
214       "Track does not intersect"<<ENDLOG;
215     return;
216   }
217   
218   //Find intersection
219   
220   Double_t fac2   = ( radius*radius + fac1 - rc*rc) / (2.00 * radius * sfac ) ;
221   Double_t phi    = atan2(yc,xc) + GetCharge()*acos(fac2) ;
222   Double_t td     = atan2(radius*sin(phi) - yc,radius*cos(phi) - xc) ;
223   
224   //Intersection in z
225   
226   if ( td < 0 ) td = td + 2. * pi ;
227   Double_t deltat = fmod((-GetCharge()*td + GetCharge()*tPhi0),2*pi) ;
228   if ( deltat < 0.      ) deltat += 2. * pi ;
229   if ( deltat > 2.*pi ) deltat -= 2. * pi ;
230   Double_t z = GetZ0() + rc * GetTgl() * deltat ;
231  
232   
233   Double_t xExtra = radius * cos(phi) ;
234   Double_t yExtra = radius * sin(phi) ;
235   
236   Double_t tPhi = atan2(yExtra-yc,xExtra-xc);
237   
238   //if ( tPhi < 0 ) tPhi += 2. * M_PI ;
239   
240   Double_t tPsi = tPhi - GetCharge() * 0.5 * pi / fabs(GetCharge()) ;
241   if ( tPsi > 2. * pi ) tPsi -= 2. * pi ;
242   if ( tPsi < 0.        ) tPsi += 2. * pi ;
243   
244   //And finally, update the track parameters
245   
246   SetCenterX(xc);
247   SetCenterY(yc);
248   SetR0(radius);
249   SetPhi0(phi);
250   SetZ0(z);
251   SetPsi(tPsi);
252 }
253
254 Int_t AliL3ConfMapTrack::GetMCLabel()
255 {
256   //For evaluation study.
257   //Returns the MCtrackID of the belonging clusters.
258   //If MCLabel < 0, means that track is fake.
259
260   return 0;
261   /*
262   Int_t num_of_clusters = GetNumberOfPoints();
263   S *s=new S[num_of_clusters];
264   Int_t i;
265   for (i=0; i<num_of_clusters; i++) s[i].lab=s[i].max=0;
266   
267   Int_t lab=123456789;
268   for (i=0; i<num_of_clusters; i++) {
269     AliL3ConfMapPoint *c=(AliL3ConfMapPoint*)fPoints->UncheckedAt(i);
270     lab=fabs(c->fMCTrackID[0]);
271     Int_t j;
272     for (j=0; j<num_of_clusters; j++)
273       if (s[j].lab==lab || s[j].max==0) break;
274     s[j].lab=lab;
275     s[j].max++;
276   }
277   
278   Int_t max=0;
279   for (i=0; i<num_of_clusters; i++) 
280     if (s[i].max>max) {max=s[i].max; lab=s[i].lab;}
281     
282   delete[] s;
283   
284   for (i=0; i<num_of_clusters; i++) {
285     AliL3ConfMapPoint *c=(AliL3ConfMapPoint*)fPoints->UncheckedAt(i);
286     if (fabs(c->fMCTrackID[1]) == lab ||
287         fabs(c->fMCTrackID[2]) == lab ) max++;
288   }
289   
290   //check if more than 10% of the clusters are incorrectly assigned (fake track):
291   
292   if (1.-Float_t(max)/num_of_clusters > 0.10) 
293     {
294       return -lab;
295     }
296   Int_t tail=Int_t(0.08*174);
297   if (num_of_clusters < tail) return lab;
298   
299   max=0;
300   for (i=1; i<=tail; i++) {
301     AliL3ConfMapPoint *c = (AliL3ConfMapPoint*)fPoints->UncheckedAt(num_of_clusters-i);
302     if (lab == fabs(c->fMCTrackID[0]) ||
303         lab == fabs(c->fMCTrackID[1]) ||
304         lab == fabs(c->fMCTrackID[2])) max++;
305   }
306   if (max < Int_t(0.5*tail)) 
307     {
308       //printf("Wrong innermost clusters\n");
309       return -lab;
310     }
311   return lab;
312   */
313 }
314