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