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