]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCConfMapTrack.cxx
- workaround for copying and merging of ESDs: The HLTOUT contains ESDs for every...
[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()
71 {
72   //deconstructor
73 }
74
75 void AliHLTTPCConfMapTrack::DeleteCandidate()
76 {
77   //Deletes this track by resetting all its parameters. Does not delete
78   //the object itself.
79
80   AliHLTTPCConfMapPoint *curHit = (AliHLTTPCConfMapPoint*)fFirstHit;
81   AliHLTTPCConfMapPoint *nextHit;
82   
83   while(curHit != 0)
84     {
85       nextHit = (AliHLTTPCConfMapPoint*)curHit->GetNextTrackHit();
86       curHit->SetNextTrackHit(0);
87       curHit = nextHit;
88     }
89   
90   UInt_t *hit_numbers = GetHitNumbers();
91   for(Int_t i=0; i<GetNHits(); i++)
92     {
93       //fHitNumbers[i] = 0;
94       hit_numbers[i]=0;
95     }
96     
97   SetRadius(0.);
98   SetCenterX(0.);
99   SetCenterY(0.);
100   
101   ComesFromMainVertex(false);
102
103   SetNHits(0);
104   SetCharge(0);
105   fChiSq[0] = 0.;
106   fChiSq[1] = 0.;
107 }
108
109
110 void AliHLTTPCConfMapTrack::SetProperties(Bool_t usage)
111 {
112   //Set the hits to this track to 'usage'
113   for(StartLoop(); LoopDone(); GetNextHit())
114     {
115       AliHLTTPCConfMapPoint *p = (AliHLTTPCConfMapPoint*)fCurrentHit;
116       p->SetUsage(usage);
117     }
118   return;
119 }
120
121 void AliHLTTPCConfMapTrack::Reset()
122 {
123   //Resets the fit parameters of this track.
124
125   //xy-plane
126   fs11Xy   = 0;
127   fs12Xy   = 0;
128   fs22Xy   = 0;
129   fg1Xy    = 0;
130   fg2Xy    = 0;
131   fChiSq[0]  = 0.;
132     
133   //sz-plane
134   fs11Sz = 0;
135   fs12Sz = 0;
136   fs22Sz = 0;
137   fg1Sz  = 0;
138   fg2Sz  = 0;
139   fChiSq[1] = 0; 
140   SetLength(0);
141   SetNHits(0);
142 }
143
144 void AliHLTTPCConfMapTrack::UpdateParam(AliHLTTPCConfMapPoint *thisHit)
145 {
146   //Function to update fit parameters of track
147   //Also, it updates the hit pointers.
148   
149
150   //Increment the number of hits assigned to this track:
151
152   //fNHits++;
153   Int_t nhits = GetNHits();
154   nhits++;
155   SetNHits(nhits); //SetNHits(nhits++);
156
157   //Set the hit pointers:
158   //if(fNHits == 1)
159   if(GetNHits()==1)  
160     fFirstHit = thisHit;
161   else
162     ((AliHLTTPCConfMapPoint*)fLastHit)->SetNextTrackHit(thisHit);
163   fLastHit = thisHit;
164
165   
166   fs11Xy = fs11Xy + thisHit->GetXYWeight() ;
167   fs12Xy = fs12Xy + thisHit->GetXYWeight() * thisHit->GetXprime() ;
168   fs22Xy = fs22Xy + thisHit->GetXYWeight() * pow((thisHit->GetXprime()),2) ;
169   fg1Xy  = fg1Xy  + thisHit->GetXYWeight() * thisHit->GetYprime() ;
170   fg2Xy  = fg2Xy  + thisHit->GetXYWeight() * thisHit->GetXprime() * thisHit->GetYprime() ;
171     
172   fddXy  = fs11Xy * fs22Xy - pow((fs12Xy),2) ;
173   if ( fddXy != 0 ) 
174     {
175       fa1Xy  = ( fg1Xy * fs22Xy - fg2Xy * fs12Xy ) / fddXy ;
176       fa2Xy  = ( fg2Xy * fs11Xy - fg1Xy * fs12Xy ) / fddXy ;
177     }
178
179   //     Now in the sz plane
180   fs11Sz = fs11Sz + thisHit->GetZWeight() ;
181   fs12Sz = fs12Sz + thisHit->GetZWeight() * thisHit->GetS() ;
182   fs22Sz = fs22Sz + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetS() ;
183   fg1Sz  = fg1Sz  + thisHit->GetZWeight() * thisHit->GetZ() ;
184   fg2Sz  = fg2Sz  + thisHit->GetZWeight() * thisHit->GetS() * thisHit->GetZ() ;
185   
186         
187   fddSz  = fs11Sz * fs22Sz -  fs12Sz * fs12Sz ;
188   if ( fddSz != 0 ) {
189     fa1Sz  = ( fg1Sz * fs22Sz - fg2Sz * fs12Sz ) / fddSz ;
190     fa2Sz  = ( fg2Sz * fs11Sz - fg1Sz * fs12Sz ) / fddSz ;
191   }
192 }
193
194
195 void AliHLTTPCConfMapTrack::Fill(AliHLTTPCVertex *vertex,Double_t max_Dca)
196 {
197     //Fill track variables with or without fit.
198     
199     // for straight line fit
200     if (AliHLTTPCTransform::GetBFieldValue() == 0.0 ){
201
202         SetRadius(0.);  
203         SetPt(0.);
204         
205         //go for fit of straight line in real space
206         AliHLTTPCConfMapFit *fit = new AliHLTTPCConfMapFit(this,vertex);
207     /* Matthias 13.12.2006
208      * the global variable AliHLTTPCS::fgDoVertexFit has never been used so far
209      * and has always been kTRUE.
210      * In order to remove the AliHLTTPC class (which is the old steering class for
211      * HLT (TPC) tracking) from the compilation, this function can not be activated
212      * again. We have to think about a more elegant way to specify the parameters
213      * anyway. 
214         ComesFromMainVertex(AliHLTTPC::DoVertexFit());
215      */
216         ComesFromMainVertex(kTRUE);
217         fit->FitStraightLine();
218             
219         AliHLTTPCConfMapPoint *fHit = (AliHLTTPCConfMapPoint*)fFirstHit;
220         SetLastPoint(fHit->GetX(),fHit->GetY(),fHit->GetZ());
221         
222         UpdateToFirstPoint();
223         
224         delete fit;
225         
226     }
227     // for helix fit
228     else { 
229       //fRadius = sqrt(fa2Xy*fa2Xy+1)/(2*fabs(fa1Xy));
230       Double_t radius = sqrt(fa2Xy*fa2Xy+1)/(2*fabs(fa1Xy));
231       SetRadius(radius);
232       
233       //fPt = (Double_t)(AliHLTTPCTransform::GetBFieldValue() * fRadius);
234       Double_t pt = (Double_t)(AliHLTTPCTransform::GetBFieldValue() * GetRadius());
235       SetPt(pt);
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