]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCConfMapTrack.cxx
cleanup (Gaute)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCConfMapTrack.cxx
1 // @(#) $Id$
2 // Original: AliHLTConfMapTrack.cxx,v 1.16 2005/06/14 10:55:21 cvetan 
3
4 /**************************************************************************
5  * This file is property of and copyright by the ALICE HLT Project        * 
6  * ALICE Experiment at CERN, All rights reserved.                         *
7  *                                                                        *
8  * Primary Authors: Anders Vestbo, maintained by                          *
9  *                  Matthias Richter <Matthias.Richter@ift.uib.no>        *
10  *                  for The ALICE HLT Project.                            *
11  *                                                                        *
12  * Permission to use, copy, modify and distribute this software and its   *
13  * documentation strictly for non-commercial purposes is hereby granted   *
14  * without fee, provided that the above copyright notice appears in all   *
15  * copies and that both the copyright notice and this permission notice   *
16  * appear in the supporting documentation. The authors make no claims     *
17  * about the suitability of this software for any purpose. It is          *
18  * provided "as is" without express or implied warranty.                  *
19  **************************************************************************/
20
21 /** @file   AliHLTTPCConfMapTrack.cxx
22     @author Anders Vestbo, maintained by Matthias Richter
23     @date   
24     @brief  Track class for conformal mapper
25 */
26
27 #include "AliHLTTPCRootTypes.h"
28 #include "AliHLTTPCLogging.h"
29 #include "AliHLTTPCVertex.h"
30 #include "AliHLTTPCConfMapPoint.h"
31 #include "AliHLTTPCConfMapFit.h"
32 #include "AliHLTTPCConfMapTrack.h"
33 #include "AliHLTTPCTransform.h"
34 //#include "AliHLTTPC.h"
35
36 #if __GNUC__ >= 3
37 using namespace std;
38 #endif
39
40 ClassImp(AliHLTTPCConfMapTrack)
41
42
43 AliHLTTPCConfMapTrack::AliHLTTPCConfMapTrack()
44   :
45   fCurrentHit(0),
46   fLastHit(0),
47   fFirstHit(0),
48   fs11Xy(0),
49   fs12Xy(0),
50   fs22Xy(0),
51   fg1Xy(0),
52   fg2Xy(0),
53   fs11Sz(0),
54   fs12Sz(0),
55   fs22Sz(0),
56   fg1Sz(0),
57   fg2Sz(0),
58   fddXy(0),
59   fa1Xy(0),
60   fa2Xy(0),
61   fddSz(0),
62   fa1Sz(0),
63   fa2Sz(0)
64 {
65   //Constructor
66   fChiSq[0] = 0.;
67   fChiSq[1] = 0.;
68 }
69
70 AliHLTTPCConfMapTrack::AliHLTTPCConfMapTrack(const AliHLTTPCConfMapTrack&)
71   :
72   fCurrentHit(0),
73   fLastHit(0),
74   fFirstHit(0),
75   fs11Xy(0),
76   fs12Xy(0),
77   fs22Xy(0),
78   fg1Xy(0),
79   fg2Xy(0),
80   fs11Sz(0),
81   fs12Sz(0),
82   fs22Sz(0),
83   fg1Sz(0),
84   fg2Sz(0),
85   fddXy(0),
86   fa1Xy(0),
87   fa2Xy(0),
88   fddSz(0),
89   fa1Sz(0),
90   fa2Sz(0)
91 {
92   // dummy copy constructor
93   //HLTFatal("copy constructor untested");
94 }
95
96 AliHLTTPCConfMapTrack& AliHLTTPCConfMapTrack::operator=(const AliHLTTPCConfMapTrack&)
97
98   // dummy assignment operator
99   //HLTFatal("assignment operator untested");
100   return *this;
101 }
102
103 AliHLTTPCConfMapTrack::~AliHLTTPCConfMapTrack()
104 {
105   //deconstructor
106 }
107
108 void AliHLTTPCConfMapTrack::DeleteCandidate()
109 {
110   //Deletes this track by resetting all its parameters. Does not delete
111   //the object itself.
112
113   AliHLTTPCConfMapPoint *curHit = (AliHLTTPCConfMapPoint*)fFirstHit;
114   AliHLTTPCConfMapPoint *nextHit;
115   
116   while(curHit != 0)
117     {
118       nextHit = (AliHLTTPCConfMapPoint*)curHit->GetNextTrackHit();
119       curHit->SetNextTrackHit(0);
120       curHit = nextHit;
121     }
122   
123   UInt_t *hit_numbers = GetHitNumbers();
124   for(Int_t i=0; i<GetNHits(); i++)
125     {
126       //fHitNumbers[i] = 0;
127       hit_numbers[i]=0;
128     }
129     
130   SetRadius(0.);
131   SetCenterX(0.);
132   SetCenterY(0.);
133   
134   ComesFromMainVertex(false);
135
136   SetNHits(0);
137   SetCharge(0);
138   fChiSq[0] = 0.;
139   fChiSq[1] = 0.;
140 }
141
142
143 void AliHLTTPCConfMapTrack::SetProperties(Bool_t usage)
144 {
145   //Set the hits to this track to 'usage'
146   for(StartLoop(); LoopDone(); GetNextHit())
147     {
148       AliHLTTPCConfMapPoint *p = (AliHLTTPCConfMapPoint*)fCurrentHit;
149       p->SetUsage(usage);
150     }
151   return;
152 }
153
154 void AliHLTTPCConfMapTrack::Reset()
155 {
156   //Resets the fit parameters of this track.
157
158   //xy-plane
159   fs11Xy   = 0;
160   fs12Xy   = 0;
161   fs22Xy   = 0;
162   fg1Xy    = 0;
163   fg2Xy    = 0;
164   fChiSq[0]  = 0.;
165     
166   //sz-plane
167   fs11Sz = 0;
168   fs12Sz = 0;
169   fs22Sz = 0;
170   fg1Sz  = 0;
171   fg2Sz  = 0;
172   fChiSq[1] = 0; 
173   SetLength(0);
174   SetNHits(0);
175 }
176
177 void AliHLTTPCConfMapTrack::UpdateParam(AliHLTTPCConfMapPoint *thisHit)
178 {
179   //Function to update fit parameters of track
180   //Also, it updates the hit pointers.
181   
182
183   //Increment the number of hits assigned to this track:
184
185   //fNHits++;
186   Int_t nhits = GetNHits();
187   nhits++;
188   SetNHits(nhits); //SetNHits(nhits++);
189
190   //Set the hit pointers:
191   //if(fNHits == 1)
192   if(GetNHits()==1)  
193     fFirstHit = thisHit;
194   else
195     ((AliHLTTPCConfMapPoint*)fLastHit)->SetNextTrackHit(thisHit);
196   fLastHit = thisHit;
197
198   
199   fs11Xy = fs11Xy + thisHit->GetXYWeight() ;
200   fs12Xy = fs12Xy + thisHit->GetXYWeight() * thisHit->GetXprime() ;
201   fs22Xy = fs22Xy + thisHit->GetXYWeight() * pow((thisHit->GetXprime()),2) ;
202   fg1Xy  = fg1Xy  + thisHit->GetXYWeight() * thisHit->GetYprime() ;
203   fg2Xy  = fg2Xy  + thisHit->GetXYWeight() * thisHit->GetXprime() * thisHit->GetYprime() ;
204     
205   fddXy  = fs11Xy * fs22Xy - pow((fs12Xy),2) ;
206   if ( fddXy != 0 ) 
207     {
208       fa1Xy  = ( fg1Xy * fs22Xy - fg2Xy * fs12Xy ) / fddXy ;
209       fa2Xy  = ( fg2Xy * fs11Xy - fg1Xy * fs12Xy ) / fddXy ;
210     }
211
212   //     Now in the sz plane
213   fs11Sz = fs11Sz + thisHit->GetZWeight() ;
214   fs12Sz = fs12Sz + thisHit->GetZWeight() * thisHit->GetS() ;
215   fs22Sz = fs22Sz + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetS() ;
216   fg1Sz  = fg1Sz  + thisHit->GetZWeight() * thisHit->GetZ() ;
217   fg2Sz  = fg2Sz  + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetZ() ;
218   
219         
220   fddSz  = fs11Sz * fs22Sz -  fs12Sz * fs12Sz ;
221   if ( fddSz != 0 ) {
222     fa1Sz  = ( fg1Sz * fs22Sz - fg2Sz * fs12Sz ) / fddSz ;
223     fa2Sz  = ( fg2Sz * fs11Sz - fg1Sz * fs12Sz ) / fddSz ;
224   }
225 }
226
227
228 void AliHLTTPCConfMapTrack::Fill(AliHLTTPCVertex *vertex,Double_t max_Dca)
229 {
230     //Fill track variables with or without fit.
231     
232     // for straight line fit
233     if (AliHLTTPCTransform::GetBFieldValue() == 0.0 ){
234
235         SetRadius(0.);  
236         SetPt(0.);
237         
238         //go for fit of straight line in real space
239         AliHLTTPCConfMapFit *fit = new AliHLTTPCConfMapFit(this,vertex);
240     /* Matthias 13.12.2006
241      * the global variable AliHLTTPCS::fgDoVertexFit has never been used so far
242      * and has always been kTRUE.
243      * In order to remove the AliHLTTPC class (which is the old steering class for
244      * HLT (TPC) tracking) from the compilation, this function can not be activated
245      * again. We have to think about a more elegant way to specify the parameters
246      * anyway. 
247         ComesFromMainVertex(AliHLTTPC::DoVertexFit());
248      */
249         ComesFromMainVertex(kTRUE);
250         fit->FitStraightLine();
251             
252         AliHLTTPCConfMapPoint *fHit = (AliHLTTPCConfMapPoint*)fFirstHit;
253         SetLastPoint(fHit->GetX(),fHit->GetY(),fHit->GetZ());
254         
255         UpdateToFirstPoint();
256         
257         delete fit;
258         
259     }
260     // for helix fit
261     else { 
262       //fRadius = sqrt(fa2Xy*fa2Xy+1)/(2*fabs(fa1Xy));
263       Double_t radius = sqrt(fa2Xy*fa2Xy+1)/(2*fabs(fa1Xy));
264       SetRadius(radius);
265       
266       //fPt = (Double_t)(AliHLTTPCTransform::GetBFieldValue() * fRadius);
267       Double_t pt = (Double_t)(AliHLTTPCTransform::GetBFieldValue() * GetRadius());
268       SetPt(pt);
269       
270       if(GetPt() > max_Dca) //go for fit of helix in real space
271         {
272           AliHLTTPCConfMapFit *fit = new AliHLTTPCConfMapFit(this,vertex);
273     /* Matthias 13.12.2006
274      * the global variable AliHLTTPCS::fgDoVertexFit has never been used so far
275      * and has always been kTRUE.
276      * In order to remove the AliHLTTPC class (which is the old steering class for
277      * HLT (TPC) tracking) from the compilation, this function can not be activated
278      * again. We have to think about a more elegant way to specify the parameters
279      * anyway. 
280             ComesFromMainVertex(AliHLTTPC::DoVertexFit());
281      */
282           ComesFromMainVertex(kTRUE);
283           fit->FitHelix();
284           
285           //AliHLTTPCConfMapPoint *lHit = (AliHLTTPCConfMapPoint*)fLastHit;
286           AliHLTTPCConfMapPoint *fHit = (AliHLTTPCConfMapPoint*)fFirstHit;
287           SetLastPoint(fHit->GetX(),fHit->GetY(),fHit->GetZ());
288           
289           UpdateToFirstPoint();
290           
291           delete fit;
292         }
293       else if(GetPt() == 0) 
294         {
295           LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapTrack::Fill","Tracks")<<AliHLTTPCLog::kDec<<
296             "Found track with Pt=0!!!"<<ENDLOG;
297         }
298       else
299         {
300           LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapTrack::Fill","Tracks")<<AliHLTTPCLog::kDec<<
301             "Track with pt<max_Dca :"<<GetPt()<<ENDLOG;
302         }
303     }
304 }
305
306 Int_t AliHLTTPCConfMapTrack::GetMCLabel()
307 {
308   //For evaluation study.
309   //Returns the MCtrackID of the belonging clusters.
310   //If MCLabel < 0, means that track is fake.
311
312   return 0;
313   /*
314   Int_t num_of_clusters = GetNumberOfPoints();
315   S *s=new S[num_of_clusters];
316   Int_t i;
317   for (i=0; i<num_of_clusters; i++) s[i].lab=s[i].max=0;
318   
319   Int_t lab=123456789;
320   for (i=0; i<num_of_clusters; i++) {
321     AliHLTTPCConfMapPoint *c=(AliHLTTPCConfMapPoint*)fPoints->UncheckedAt(i);
322     lab=fabs(c->fMCTrackID[0]);
323     Int_t j;
324     for (j=0; j<num_of_clusters; j++)
325       if (s[j].lab==lab || s[j].max==0) break;
326     s[j].lab=lab;
327     s[j].max++;
328   }
329   
330   Int_t max=0;
331   for (i=0; i<num_of_clusters; i++) 
332     if (s[i].max>max) {max=s[i].max; lab=s[i].lab;}
333     
334   delete[] s;
335   
336   for (i=0; i<num_of_clusters; i++) {
337     AliHLTTPCConfMapPoint *c=(AliHLTTPCConfMapPoint*)fPoints->UncheckedAt(i);
338     if (fabs(c->fMCTrackID[1]) == lab ||
339         fabs(c->fMCTrackID[2]) == lab ) max++;
340   }
341   
342   //check if more than 10% of the clusters are incorrectly assigned (fake track):
343   
344   if (1.-Float_t(max)/num_of_clusters > 0.10) 
345     {
346       return -lab;
347     }
348   Int_t tail=Int_t(0.08*174);
349   if (num_of_clusters < tail) return lab;
350   
351   max=0;
352   for (i=1; i<=tail; i++) {
353     AliHLTTPCConfMapPoint *c = (AliHLTTPCConfMapPoint*)fPoints->UncheckedAt(num_of_clusters-i);
354     if (lab == fabs(c->fMCTrackID[0]) ||
355         lab == fabs(c->fMCTrackID[1]) ||
356         lab == fabs(c->fMCTrackID[2])) max++;
357   }
358   if (max < Int_t(0.5*tail)) 
359     {
360       //printf("Wrong innermost clusters\n");
361       return -lab;
362     }
363   return lab;
364   */
365 }
366