]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCConfMapTrack.cxx
- coverity fix 10181
[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
35 #if __GNUC__ >= 3
36 using namespace std;
37 #endif
38
39 ClassImp(AliHLTTPCConfMapTrack)
40
41
42 AliHLTTPCConfMapTrack::AliHLTTPCConfMapTrack()
43   :
44   fCurrentHit(0),
45   fLastHit(0),
46   fFirstHit(0),
47   fs11Xy(0),
48   fs12Xy(0),
49   fs22Xy(0),
50   fg1Xy(0),
51   fg2Xy(0),
52   fs11Sz(0),
53   fs12Sz(0),
54   fs22Sz(0),
55   fg1Sz(0),
56   fg2Sz(0),
57   fddXy(0),
58   fa1Xy(0),
59   fa2Xy(0),
60   fddSz(0),
61   fa1Sz(0),
62   fa2Sz(0)
63 {
64   //Constructor
65   fChiSq[0] = 0.;
66   fChiSq[1] = 0.;
67 }
68
69 AliHLTTPCConfMapTrack::~AliHLTTPCConfMapTrack()
70 {
71   //deconstructor
72 }
73
74 void AliHLTTPCConfMapTrack::DeleteCandidate()
75 {
76   //Deletes this track by resetting all its parameters. Does not delete
77   //the object itself.
78
79   AliHLTTPCConfMapPoint *curHit = (AliHLTTPCConfMapPoint*)fFirstHit;
80   AliHLTTPCConfMapPoint *nextHit;
81   
82   while(curHit != 0)
83     {
84       nextHit = (AliHLTTPCConfMapPoint*)curHit->GetNextTrackHit();
85       curHit->SetNextTrackHit(0);
86       curHit = nextHit;
87     }
88   
89   UInt_t *hit_numbers = GetHitNumbers();
90   for(Int_t i=0; i<GetNHits(); i++)
91     {
92       //fHitNumbers[i] = 0;
93       hit_numbers[i]=0;
94     }
95     
96   SetRadius(0.);
97   SetCenterX(0.);
98   SetCenterY(0.);
99   
100   ComesFromMainVertex(false);
101
102   SetNHits(0);
103   SetCharge(0);
104   fChiSq[0] = 0.;
105   fChiSq[1] = 0.;
106 }
107
108
109 void AliHLTTPCConfMapTrack::SetProperties(Bool_t usage)
110 {
111   //Set the hits to this track to 'usage'
112   for(StartLoop(); LoopDone(); GetNextHit())
113     {
114       AliHLTTPCConfMapPoint *p = (AliHLTTPCConfMapPoint*)fCurrentHit;
115       p->SetUsage(usage);
116     }
117   return;
118 }
119
120 void AliHLTTPCConfMapTrack::Reset()
121 {
122   //Resets the fit parameters of this track.
123
124   //xy-plane
125   fs11Xy   = 0;
126   fs12Xy   = 0;
127   fs22Xy   = 0;
128   fg1Xy    = 0;
129   fg2Xy    = 0;
130   fChiSq[0]  = 0.;
131     
132   //sz-plane
133   fs11Sz = 0;
134   fs12Sz = 0;
135   fs22Sz = 0;
136   fg1Sz  = 0;
137   fg2Sz  = 0;
138   fChiSq[1] = 0; 
139   SetLength(0);
140   SetNHits(0);
141 }
142
143 void AliHLTTPCConfMapTrack::UpdateParam(AliHLTTPCConfMapPoint *thisHit)
144 {
145   //Function to update fit parameters of track
146   //Also, it updates the hit pointers.
147   
148
149   //Increment the number of hits assigned to this track:
150
151   //fNHits++;
152   Int_t nhits = GetNHits();
153   nhits++;
154   SetNHits(nhits); //SetNHits(nhits++);
155
156   //Set the hit pointers:
157   //if(fNHits == 1)
158   if(GetNHits()==1)  
159     fFirstHit = thisHit;
160   else
161     ((AliHLTTPCConfMapPoint*)fLastHit)->SetNextTrackHit(thisHit);
162   fLastHit = thisHit;
163
164   
165   fs11Xy = fs11Xy + thisHit->GetXYWeight() ;
166   fs12Xy = fs12Xy + thisHit->GetXYWeight() * thisHit->GetXprime() ;
167   fs22Xy = fs22Xy + thisHit->GetXYWeight() * pow((thisHit->GetXprime()),2) ;
168   fg1Xy  = fg1Xy  + thisHit->GetXYWeight() * thisHit->GetYprime() ;
169   fg2Xy  = fg2Xy  + thisHit->GetXYWeight() * thisHit->GetXprime() * thisHit->GetYprime() ;
170     
171   fddXy  = fs11Xy * fs22Xy - pow((fs12Xy),2) ;
172   if ( fddXy != 0 ) 
173     {
174       fa1Xy  = ( fg1Xy * fs22Xy - fg2Xy * fs12Xy ) / fddXy ;
175       fa2Xy  = ( fg2Xy * fs11Xy - fg1Xy * fs12Xy ) / fddXy ;
176     }
177
178   //     Now in the sz plane
179   fs11Sz = fs11Sz + thisHit->GetZWeight() ;
180   fs12Sz = fs12Sz + thisHit->GetZWeight() * thisHit->GetS() ;
181   fs22Sz = fs22Sz + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetS() ;
182   fg1Sz  = fg1Sz  + thisHit->GetZWeight() * thisHit->GetZ() ;
183   fg2Sz  = fg2Sz  + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetZ() ;
184   
185         
186   fddSz  = fs11Sz * fs22Sz -  fs12Sz * fs12Sz ;
187   if ( fddSz != 0 ) {
188     fa1Sz  = ( fg1Sz * fs22Sz - fg2Sz * fs12Sz ) / fddSz ;
189     fa2Sz  = ( fg2Sz * fs11Sz - fg1Sz * fs12Sz ) / fddSz ;
190   }
191 }
192
193
194 void AliHLTTPCConfMapTrack::Fill(AliHLTTPCVertex *vertex,Double_t max_Dca)
195 {
196     //Fill track variables with or without fit.
197     
198     // for straight line fit
199     if (AliHLTTPCTransform::GetBFieldValue() == 0.0 ){
200
201         SetRadius(0.);  
202         SetPt(0.);
203         
204         //go for fit of straight line in real space
205         AliHLTTPCConfMapFit *fit = new AliHLTTPCConfMapFit(this,vertex);
206     /* Matthias 13.12.2006
207      * the global variable AliHLTTPCS::fgDoVertexFit has never been used so far
208      * and has always been kTRUE.
209      * In order to remove the AliHLTTPC class (which is the old steering class for
210      * HLT (TPC) tracking) from the compilation, this function can not be activated
211      * again. We have to think about a more elegant way to specify the parameters
212      * anyway. 
213         ComesFromMainVertex(AliHLTTPC::DoVertexFit());
214      */
215         ComesFromMainVertex(kTRUE);
216         fit->FitStraightLine();
217             
218         AliHLTTPCConfMapPoint *fHit = (AliHLTTPCConfMapPoint*)fFirstHit;
219         SetLastPoint(fHit->GetX(),fHit->GetY(),fHit->GetZ());
220         
221         UpdateToFirstPoint();
222         
223         delete fit;
224         
225     }
226     // for helix fit
227     else { 
228       //fRadius = sqrt(fa2Xy*fa2Xy+1)/(2*fabs(fa1Xy));
229       Double_t radius = sqrt(fa2Xy*fa2Xy+1)/(2*fabs(fa1Xy));
230       SetRadius(radius);
231       
232       //fPt = (Double_t)(AliHLTTPCTransform::GetBFieldValue() * fRadius);
233       Double_t pt = (Double_t)(AliHLTTPCTransform::GetBFieldValue() * GetRadius());
234       SetPt(pt);
235       //Set Error here?????
236       
237       if(GetPt() > max_Dca) //go for fit of helix in real space
238         {
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->FitHelix();
251           
252           //AliHLTTPCConfMapPoint *lHit = (AliHLTTPCConfMapPoint*)fLastHit;
253           AliHLTTPCConfMapPoint *fHit = (AliHLTTPCConfMapPoint*)fFirstHit;
254           SetLastPoint(fHit->GetX(),fHit->GetY(),fHit->GetZ());
255           
256           UpdateToFirstPoint();
257           
258           delete fit;
259         }
260       else if(GetPt() == 0) 
261         {
262           LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapTrack::Fill","Tracks")<<AliHLTTPCLog::kDec<<
263             "Found track with Pt=0!!!"<<ENDLOG;
264         }
265       else
266         {
267           LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapTrack::Fill","Tracks")<<AliHLTTPCLog::kDec<<
268             "Track with pt<max_Dca :"<<GetPt()<<ENDLOG;
269         }
270     }
271 }
272
273 Int_t AliHLTTPCConfMapTrack::GetMCLabel()
274 {
275   //For evaluation study.
276   //Returns the MCtrackID of the belonging clusters.
277   //If MCLabel < 0, means that track is fake.
278
279   return 0;
280   /*
281   Int_t num_of_clusters = GetNumberOfPoints();
282   S *s=new S[num_of_clusters];
283   Int_t i;
284   for (i=0; i<num_of_clusters; i++) s[i].lab=s[i].max=0;
285   
286   Int_t lab=123456789;
287   for (i=0; i<num_of_clusters; i++) {
288     AliHLTTPCConfMapPoint *c=(AliHLTTPCConfMapPoint*)fPoints->UncheckedAt(i);
289     lab=fabs(c->fMCTrackID[0]);
290     Int_t j;
291     for (j=0; j<num_of_clusters; j++)
292       if (s[j].lab==lab || s[j].max==0) break;
293     s[j].lab=lab;
294     s[j].max++;
295   }
296   
297   Int_t max=0;
298   for (i=0; i<num_of_clusters; i++) 
299     if (s[i].max>max) {max=s[i].max; lab=s[i].lab;}
300     
301   delete[] s;
302   
303   for (i=0; i<num_of_clusters; i++) {
304     AliHLTTPCConfMapPoint *c=(AliHLTTPCConfMapPoint*)fPoints->UncheckedAt(i);
305     if (fabs(c->fMCTrackID[1]) == lab ||
306         fabs(c->fMCTrackID[2]) == lab ) max++;
307   }
308   
309   //check if more than 10% of the clusters are incorrectly assigned (fake track):
310   
311   if (1.-Float_t(max)/num_of_clusters > 0.10) 
312     {
313       return -lab;
314     }
315   Int_t tail=Int_t(0.08*174);
316   if (num_of_clusters < tail) return lab;
317   
318   max=0;
319   for (i=1; i<=tail; i++) {
320     AliHLTTPCConfMapPoint *c = (AliHLTTPCConfMapPoint*)fPoints->UncheckedAt(num_of_clusters-i);
321     if (lab == fabs(c->fMCTrackID[0]) ||
322         lab == fabs(c->fMCTrackID[1]) ||
323         lab == fabs(c->fMCTrackID[2])) max++;
324   }
325   if (max < Int_t(0.5*tail)) 
326     {
327       //printf("Wrong innermost clusters\n");
328       return -lab;
329     }
330   return lab;
331   */
332 }
333