]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITStrackerV2.cxx
Updated ZDC geometry
[u/mrichter/AliRoot.git] / ITS / AliITStrackerV2.cxx
CommitLineData
006b5f7f 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16//-------------------------------------------------------------------------
17// Implementation of the ITS tracker class
18856a77 18// It reads AliITSclusterV2 clusters and creates AliITStrackV2 tracks
19// and fills with them the ESD
006b5f7f 20// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
a9a2d814 21// dEdx analysis by: Boris Batyunya, JINR, Boris.Batiounia@cern.ch
006b5f7f 22//-------------------------------------------------------------------------
1f9a65c4 23
9c369bfe 24#include <new>
25
006b5f7f 26#include <TFile.h>
27#include <TTree.h>
28#include <TRandom.h>
006b5f7f 29
30#include "AliITSgeom.h"
31#include "AliITSRecPoint.h"
c630aafd 32#include "AliESD.h"
006b5f7f 33#include "AliITSclusterV2.h"
34#include "AliITStrackerV2.h"
35
8676d691 36ClassImp(AliITStrackerV2)
006b5f7f 37
18856a77 38AliITStrackerV2::AliITSlayer AliITStrackerV2::fgLayers[kMaxLayer]; // ITS layers
006b5f7f 39
c630aafd 40AliITStrackerV2::AliITStrackerV2(const AliITSgeom *geom) : AliTracker() {
006b5f7f 41 //--------------------------------------------------------------------
61ab8ea8 42 //This is the AliITStrackerV2 constructor
006b5f7f 43 //--------------------------------------------------------------------
006b5f7f 44 AliITSgeom *g=(AliITSgeom*)geom;
45
46 Float_t x,y,z;
47 Int_t i;
c630aafd 48 for (i=1; i<kMaxLayer+1; i++) {
006b5f7f 49 Int_t nlad=g->GetNladders(i);
50 Int_t ndet=g->GetNdetectors(i);
51
52 g->GetTrans(i,1,1,x,y,z);
53 Double_t r=TMath::Sqrt(x*x + y*y);
54 Double_t poff=TMath::ATan2(y,x);
55 Double_t zoff=z;
56
57 g->GetTrans(i,1,2,x,y,z);
58 r += TMath::Sqrt(x*x + y*y);
59 g->GetTrans(i,2,1,x,y,z);
60 r += TMath::Sqrt(x*x + y*y);
61 g->GetTrans(i,2,2,x,y,z);
62 r += TMath::Sqrt(x*x + y*y);
63 r*=0.25;
64
18856a77 65 new (fgLayers+i-1) AliITSlayer(r,poff,zoff,nlad,ndet);
006b5f7f 66
67 for (Int_t j=1; j<nlad+1; j++) {
68 for (Int_t k=1; k<ndet+1; k++) { //Fill this layer with detectors
69 Float_t x,y,zshift; g->GetTrans(i,j,k,x,y,zshift);
70 Double_t rot[9]; g->GetRotMatrix(i,j,k,rot);
71
f363d377 72 Double_t phi=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
73 phi+=TMath::Pi()/2;
74 if (i==1) phi+=TMath::Pi();
75 Double_t cp=TMath::Cos(phi), sp=TMath::Sin(phi);
76 Double_t r=x*cp+y*sp;
006b5f7f 77
18856a77 78 AliITSdetector &det=fgLayers[i-1].GetDetector((j-1)*ndet + k-1);
006b5f7f 79 new(&det) AliITSdetector(r,phi);
80 }
81 }
c630aafd 82
006b5f7f 83 }
84
61ab8ea8 85 fI=kMaxLayer;
743a19f2 86
61ab8ea8 87 fPass=0;
15dd636f 88 fConstraint[0]=1; fConstraint[1]=0;//-1;
8676d691 89
90 Double_t xyz[]={kXV,kYV,kZV}, ers[]={kSigmaXV,kSigmaYV,kSigmaZV};
91 SetVertex(xyz,ers);
c0dd5278 92
93 for (Int_t i=0; i<kMaxLayer; i++) fLayersNotToSkip[i]=kLayersNotToSkip[i];
94 fLastLayerToTrackTo=kLastLayerToTrackTo;
95
96}
97
98void AliITStrackerV2::SetLayersNotToSkip(Int_t *l) {
99 //--------------------------------------------------------------------
100 //This function set masks of the layers which must be not skipped
101 //--------------------------------------------------------------------
102 for (Int_t i=0; i<kMaxLayer; i++) fLayersNotToSkip[i]=l[i];
61ab8ea8 103}
006b5f7f 104
c630aafd 105Int_t AliITStrackerV2::LoadClusters(TTree *cTree) {
61ab8ea8 106 //--------------------------------------------------------------------
107 //This function loads ITS clusters
108 //--------------------------------------------------------------------
61ab8ea8 109 TBranch *branch=cTree->GetBranch("Clusters");
110 if (!branch) {
c630aafd 111 Error("LoadClusters"," can't get the branch !\n");
8676d691 112 return 1;
61ab8ea8 113 }
006b5f7f 114
61ab8ea8 115 TClonesArray dummy("AliITSclusterV2",10000), *clusters=&dummy;
116 branch->SetAddress(&clusters);
006b5f7f 117
61ab8ea8 118 Int_t j=0;
119 for (Int_t i=0; i<kMaxLayer; i++) {
18856a77 120 Int_t ndet=fgLayers[i].GetNdetectors();
121 Int_t jmax = j + fgLayers[i].GetNladders()*ndet;
61ab8ea8 122 for (; j<jmax; j++) {
123 if (!cTree->GetEvent(j)) continue;
124 Int_t ncl=clusters->GetEntriesFast();
125 while (ncl--) {
126 AliITSclusterV2 *c=(AliITSclusterV2*)clusters->UncheckedAt(ncl);
18856a77 127 fgLayers[i].InsertCluster(new AliITSclusterV2(*c));
61ab8ea8 128 }
129 clusters->Delete();
130 }
18856a77 131 fgLayers[i].ResetRoad(); //road defined by the cluster density
006b5f7f 132 }
c630aafd 133
8676d691 134 return 0;
61ab8ea8 135}
006b5f7f 136
61ab8ea8 137void AliITStrackerV2::UnloadClusters() {
138 //--------------------------------------------------------------------
139 //This function unloads ITS clusters
140 //--------------------------------------------------------------------
18856a77 141 for (Int_t i=0; i<kMaxLayer; i++) fgLayers[i].ResetClusters();
006b5f7f 142}
143
880f41b9 144static Int_t CorrectForDeadZoneMaterial(AliITStrackV2 *t) {
145 //--------------------------------------------------------------------
146 // Correction for the material between the TPC and the ITS
147 // (should it belong to the TPC code ?)
148 //--------------------------------------------------------------------
149 Double_t riw=80., diw=0.0053, x0iw=30; // TPC inner wall ?
150 Double_t rcd=61., dcd=0.0053, x0cd=30; // TPC "central drum" ?
151 Double_t yr=12.8, dr=0.03; // rods ?
152 Double_t zm=0.2, dm=0.40; // membrane
153 //Double_t rr=52., dr=0.19, x0r=24., yyr=7.77; //rails
154 Double_t rs=50., ds=0.001; // something belonging to the ITS (screen ?)
155
156 if (t->GetX() > riw) {
157 if (!t->PropagateTo(riw,diw,x0iw)) return 1;
158 if (TMath::Abs(t->GetY())>yr) t->CorrectForMaterial(dr);
159 if (TMath::Abs(t->GetZ())<zm) t->CorrectForMaterial(dm);
160 if (!t->PropagateTo(rcd,dcd,x0cd)) return 1;
161 //Double_t x,y,z; t->GetGlobalXYZat(rr,x,y,z);
162 //if (TMath::Abs(y)<yyr) t->PropagateTo(rr,dr,x0r);
163 if (!t->PropagateTo(rs,ds)) return 1;
164 } else if (t->GetX() < rs) {
165 if (!t->PropagateTo(rs,-ds)) return 1;
166 //Double_t x,y,z; t->GetGlobalXYZat(rr,x,y,z);
167 //if (TMath::Abs(y)<yyr) t->PropagateTo(rr,-dr,x0r);
168 if (!t->PropagateTo(rcd,-dcd,x0cd)) return 1;
ba1a3e1a 169 if (!t->PropagateTo(riw+0.001,-diw,x0iw)) return 1;
880f41b9 170 } else {
171 ::Error("CorrectForDeadZoneMaterial","track is already in the dead zone !");
172 return 1;
173 }
174
175 return 0;
176}
177
c630aafd 178Int_t AliITStrackerV2::Clusters2Tracks(AliESD *event) {
006b5f7f 179 //--------------------------------------------------------------------
c630aafd 180 // This functions reconstructs ITS tracks
181 // The clusters must be already loaded !
006b5f7f 182 //--------------------------------------------------------------------
c630aafd 183 TObjArray itsTracks(15000);
006b5f7f 184
c630aafd 185 {/* Read ESD tracks */
186 Int_t nentr=event->GetNumberOfTracks();
187 Info("Clusters2Tracks", "Number of ESD tracks: %d\n", nentr);
188 while (nentr--) {
189 AliESDtrack *esd=event->GetTrack(nentr);
190
ba1a3e1a 191 if ((esd->GetStatus()&AliESDtrack::kTPCin)==0) continue;
192 if (esd->GetStatus()&AliESDtrack::kTPCout) continue;
193 if (esd->GetStatus()&AliESDtrack::kITSin) continue;
c630aafd 194
195 AliITStrackV2 *t=0;
196 try {
197 t=new AliITStrackV2(*esd);
198 } catch (const Char_t *msg) {
199 Warning("Clusters2Tracks",msg);
200 delete t;
201 continue;
202 }
15dd636f 203 if (TMath::Abs(t->GetD())>4) {
ebd8369c 204 delete t;
205 continue;
206 }
006b5f7f 207
c630aafd 208 if (CorrectForDeadZoneMaterial(t)!=0) {
209 Warning("Clusters2Tracks",
210 "failed to correct for the material in the dead zone !\n");
211 delete t;
212 continue;
213 }
214 itsTracks.AddLast(t);
215 }
216 } /* End Read ESD tracks */
217
218 itsTracks.Sort();
219 Int_t nentr=itsTracks.GetEntriesFast();
15dd636f 220
c630aafd 221 Int_t ntrk=0;
222 for (fPass=0; fPass<2; fPass++) {
223 Int_t &constraint=fConstraint[fPass]; if (constraint<0) continue;
224 for (Int_t i=0; i<nentr; i++) {
225 AliITStrackV2 *t=(AliITStrackV2*)itsTracks.UncheckedAt(i);
15dd636f 226 if (t==0) continue; //this track has been already tracked
c630aafd 227 Int_t tpcLabel=t->GetLabel(); //save the TPC track label
228
229 ResetTrackToFollow(*t);
230 ResetBestTrack();
231
232 for (FollowProlongation(); fI<kMaxLayer; fI++) {
15dd636f 233 while (TakeNextProlongation()) FollowProlongation();
c630aafd 234 }
235
de5d3595 236 if (fBestTrack.GetNumberOfClusters() == 0) continue;
15dd636f 237
c630aafd 238 if (fConstraint[fPass]) {
15dd636f 239 ResetTrackToFollow(*t);
240 if (!RefitAt(3.7, &fTrackToFollow, &fBestTrack)) continue;
241 ResetBestTrack();
242 }
243
c630aafd 244 fBestTrack.SetLabel(tpcLabel);
245 fBestTrack.CookdEdx();
246 CookLabel(&fBestTrack,0.); //For comparison only
247 fBestTrack.UpdateESDtrack(AliESDtrack::kITSin);
15dd636f 248 UseClusters(&fBestTrack);
c630aafd 249 delete itsTracks.RemoveAt(i);
250 ntrk++;
251 }
252 }
babd135a 253
c630aafd 254 itsTracks.Delete();
2257f27e 255
c630aafd 256 Info("Clusters2Tracks","Number of prolonged tracks: %d\n",ntrk);
257
258 return 0;
259}
260
c630aafd 261Int_t AliITStrackerV2::PropagateBack(AliESD *event) {
262 //--------------------------------------------------------------------
263 // This functions propagates reconstructed ITS tracks back
264 // The clusters must be loaded !
265 //--------------------------------------------------------------------
266 Int_t nentr=event->GetNumberOfTracks();
267 Info("PropagateBack", "Number of ESD tracks: %d\n", nentr);
268
269 Int_t ntrk=0;
270 for (Int_t i=0; i<nentr; i++) {
271 AliESDtrack *esd=event->GetTrack(i);
272
ba1a3e1a 273 if ((esd->GetStatus()&AliESDtrack::kITSin)==0) continue;
274 if (esd->GetStatus()&AliESDtrack::kITSout) continue;
c630aafd 275
276 AliITStrackV2 *t=0;
277 try {
278 t=new AliITStrackV2(*esd);
279 } catch (const Char_t *msg) {
280 Warning("PropagateBack",msg);
281 delete t;
282 continue;
283 }
284
285 ResetTrackToFollow(*t);
286
287 // propagete to vertex [SR, GSI 17.02.2003]
a9459f9c 288 // Start Time measurement [SR, GSI 17.02.2003], corrected by I.Belikov
289 if (fTrackToFollow.PropagateTo(3.,0.0028,65.19)) {
290 if (fTrackToFollow.PropagateToVertex()) {
291 fTrackToFollow.StartTimeIntegral();
292 }
293 fTrackToFollow.PropagateTo(3.,-0.0028,65.19);
294 }
c630aafd 295
296 fTrackToFollow.ResetCovariance(); fTrackToFollow.ResetClusters();
297 if (RefitAt(49.,&fTrackToFollow,t)) {
298 if (CorrectForDeadZoneMaterial(&fTrackToFollow)!=0) {
299 Warning("PropagateBack",
300 "failed to correct for the material in the dead zone !\n");
301 delete t;
302 continue;
303 }
304 fTrackToFollow.SetLabel(t->GetLabel());
ba1a3e1a 305 //fTrackToFollow.CookdEdx();
c630aafd 306 CookLabel(&fTrackToFollow,0.); //For comparison only
307 fTrackToFollow.UpdateESDtrack(AliESDtrack::kITSout);
15dd636f 308 UseClusters(&fTrackToFollow);
c630aafd 309 ntrk++;
310 }
311 delete t;
312 }
313
314 Info("PropagateBack","Number of back propagated ITS tracks: %d\n",ntrk);
61ab8ea8 315
83d73500 316 return 0;
317}
318
c630aafd 319Int_t AliITStrackerV2::RefitInward(AliESD *event) {
83d73500 320 //--------------------------------------------------------------------
321 // This functions refits ITS tracks using the
322 // "inward propagated" TPC tracks
c630aafd 323 // The clusters must be loaded !
83d73500 324 //--------------------------------------------------------------------
c630aafd 325 Int_t nentr=event->GetNumberOfTracks();
326 Info("RefitInward", "Number of ESD tracks: %d\n", nentr);
327
328 Int_t ntrk=0;
329 for (Int_t i=0; i<nentr; i++) {
330 AliESDtrack *esd=event->GetTrack(i);
331
ba1a3e1a 332 if ((esd->GetStatus()&AliESDtrack::kITSout) == 0) continue;
333 if (esd->GetStatus()&AliESDtrack::kITSrefit) continue;
334 if (esd->GetStatus()&AliESDtrack::kTPCout)
15dd636f 335 if ((esd->GetStatus()&AliESDtrack::kTPCrefit)==0) continue;
c630aafd 336
337 AliITStrackV2 *t=0;
338 try {
339 t=new AliITStrackV2(*esd);
340 } catch (const Char_t *msg) {
341 Warning("RefitInward",msg);
342 delete t;
343 continue;
344 }
345
346 if (CorrectForDeadZoneMaterial(t)!=0) {
347 Warning("RefitInward",
348 "failed to correct for the material in the dead zone !\n");
349 delete t;
350 continue;
351 }
352
353 ResetTrackToFollow(*t);
354 fTrackToFollow.ResetClusters();
355
356 //Refitting...
357 if (RefitAt(3.7, &fTrackToFollow, t)) {
358 fTrackToFollow.SetLabel(t->GetLabel());
359 fTrackToFollow.CookdEdx();
15dd636f 360 CookLabel(&fTrackToFollow,0.); //For comparison only
18856a77 361
67c3dcbe 362 if (fTrackToFollow.PropagateTo(3.,0.0028,65.19)) {//The beam pipe
363 Double_t a=fTrackToFollow.GetAlpha();
364 Double_t cs=TMath::Cos(a),sn=TMath::Sin(a);
365 Double_t xv= GetX()*cs + GetY()*sn;
366 Double_t yv=-GetX()*sn + GetY()*cs;
367
368 Double_t c=fTrackToFollow.GetC(), snp=fTrackToFollow.GetSnp();
369 Double_t x=fTrackToFollow.GetX(), y=fTrackToFollow.GetY();
370 Double_t tgfv=-(c*(x-xv)-snp)/(c*(y-yv) + TMath::Sqrt(1.-snp*snp));
371 Double_t fv=TMath::ATan(tgfv);
372
373 cs=TMath::Cos(fv); sn=TMath::Sin(fv);
374 x = xv*cs + yv*sn;
375 yv=-xv*sn + yv*cs; xv=x;
376
377 if (fTrackToFollow.Propagate(fv+a,xv)) {
df02fd67 378 fTrackToFollow.UpdateESDtrack(AliESDtrack::kITSrefit);
399fb957 379 Float_t d=fTrackToFollow.GetD(GetX(),GetY());
380 Float_t z=fTrackToFollow.GetZ()-GetZ();
381 fTrackToFollow.GetESDtrack()->SetImpactParameters(d,z);
15dd636f 382 UseClusters(&fTrackToFollow);
67c3dcbe 383 {
384 AliITSclusterV2 c; c.SetY(yv); c.SetZ(GetZ());
385 c.SetSigmaY2(GetSigmaY()*GetSigmaY());
386 c.SetSigmaZ2(GetSigmaZ()*GetSigmaZ());
387 Double_t chi2=fTrackToFollow.GetPredictedChi2(&c);
388 if (chi2<kMaxChi2)
389 if (fTrackToFollow.Update(&c,-chi2,0))
390 fTrackToFollow.SetConstrainedESDtrack(chi2);
391 }
df02fd67 392 ntrk++;
393 }
67c3dcbe 394 }
c630aafd 395 }
396 delete t;
397 }
398
399 Info("RefitInward","Number of refitted tracks: %d\n",ntrk);
83d73500 400
c630aafd 401 return 0;
402}
83d73500 403
006b5f7f 404AliCluster *AliITStrackerV2::GetCluster(Int_t index) const {
405 //--------------------------------------------------------------------
406 // Return pointer to a given cluster
407 //--------------------------------------------------------------------
408 Int_t l=(index & 0xf0000000) >> 28;
409 Int_t c=(index & 0x0fffffff) >> 00;
18856a77 410 return fgLayers[l].GetCluster(c);
006b5f7f 411}
412
413
414void AliITStrackerV2::FollowProlongation() {
415 //--------------------------------------------------------------------
416 //This function finds a track prolongation
417 //--------------------------------------------------------------------
c0dd5278 418 while (fI>fLastLayerToTrackTo) {
a9a2d814 419 Int_t i=fI-1;
8676d691 420
18856a77 421 AliITSlayer &layer=fgLayers[i];
a9a2d814 422 AliITStrackV2 &track=fTracks[i];
006b5f7f 423
14825d5a 424 Double_t r=layer.GetR();
61ab8ea8 425
a9a2d814 426 if (i==3 || i==1) {
18856a77 427 Double_t rs=0.5*(fgLayers[i+1].GetR() + r);
61ab8ea8 428 Double_t d=0.0034, x0=38.6;
429 if (i==1) {rs=9.; d=0.0097; x0=42;}
430 if (!fTrackToFollow.PropagateTo(rs,d,x0)) {
8676d691 431 //Warning("FollowProlongation","propagation failed !\n");
c0dd5278 432 return;
a9a2d814 433 }
006b5f7f 434 }
435
436 //find intersection
437 Double_t x,y,z;
14825d5a 438 if (!fTrackToFollow.GetGlobalXYZat(r,x,y,z)) {
8676d691 439 //Warning("FollowProlongation","failed to estimate track !\n");
c0dd5278 440 return;
006b5f7f 441 }
442 Double_t phi=TMath::ATan2(y,x);
f363d377 443
006b5f7f 444 Int_t idet=layer.FindDetectorIndex(phi,z);
445 if (idet<0) {
8676d691 446 //Warning("FollowProlongation","failed to find a detector !\n");
c0dd5278 447 return;
006b5f7f 448 }
449
450 //propagate to the intersection
451 const AliITSdetector &det=layer.GetDetector(idet);
14825d5a 452 phi=det.GetPhi();
a9a2d814 453 if (!fTrackToFollow.Propagate(phi,det.GetR())) {
8676d691 454 //Warning("FollowProlongation","propagation failed !\n");
c0dd5278 455 return;
006b5f7f 456 }
457 fTrackToFollow.SetDetectorIndex(idet);
458
459 //Select possible prolongations and store the current track estimation
460 track.~AliITStrackV2(); new(&track) AliITStrackV2(fTrackToFollow);
8676d691 461 Double_t dz=7*TMath::Sqrt(track.GetSigmaZ2() + kSigmaZ2[i]);
462 Double_t dy=7*TMath::Sqrt(track.GetSigmaY2() + kSigmaY2[i]);
463 Double_t road=layer.GetRoad();
464 if (dz*dy>road*road) {
465 Double_t dd=TMath::Sqrt(dz*dy), scz=dz/dd, scy=dy/dd;
466 dz=road*scz; dy=road*scy;
467 }
b87bd7cd 468
469 //Double_t dz=4*TMath::Sqrt(track.GetSigmaZ2() + kSigmaZ2[i]);
14825d5a 470 if (dz < 0.5*TMath::Abs(track.GetTgl())) dz=0.5*TMath::Abs(track.GetTgl());
7f6ddf58 471 if (dz > kMaxRoad) {
8676d691 472 //Warning("FollowProlongation","too broad road in Z !\n");
c0dd5278 473 return;
006b5f7f 474 }
a9a2d814 475
15dd636f 476 if (TMath::Abs(fTrackToFollow.GetZ()-GetZ()) > r+dz) return;
a9a2d814 477
b87bd7cd 478 //Double_t dy=4*TMath::Sqrt(track.GetSigmaY2() + kSigmaY2[i]);
14825d5a 479 if (dy < 0.5*TMath::Abs(track.GetSnp())) dy=0.5*TMath::Abs(track.GetSnp());
7f6ddf58 480 if (dy > kMaxRoad) {
8676d691 481 //Warning("FollowProlongation","too broad road in Y !\n");
c0dd5278 482 return;
006b5f7f 483 }
a9a2d814 484
7f6ddf58 485 Double_t zmin=track.GetZ() - dz;
006b5f7f 486 Double_t zmax=track.GetZ() + dz;
14825d5a 487 Double_t ymin=track.GetY() + r*phi - dy;
488 Double_t ymax=track.GetY() + r*phi + dy;
a9a2d814 489 layer.SelectClusters(zmin,zmax,ymin,ymax);
490 fI--;
006b5f7f 491
006b5f7f 492 //take another prolongation
15dd636f 493 if (!TakeNextProlongation())
494 if (fLayersNotToSkip[fI]) return;
495
006b5f7f 496 }
497
498 //deal with the best track
499 Int_t ncl=fTrackToFollow.GetNumberOfClusters();
500 Int_t nclb=fBestTrack.GetNumberOfClusters();
15dd636f 501 if (ncl)
502 if (ncl >= nclb) {
503 Double_t chi2=fTrackToFollow.GetChi2();
504 if (chi2/ncl < kChi2PerCluster) {
505 if (ncl > nclb || chi2 < fBestTrack.GetChi2()) {
506 ResetBestTrack();
006b5f7f 507 }
15dd636f 508 }
006b5f7f 509 }
15dd636f 510
006b5f7f 511}
512
006b5f7f 513Int_t AliITStrackerV2::TakeNextProlongation() {
514 //--------------------------------------------------------------------
a9a2d814 515 // This function takes another track prolongation
516 //
517 // dEdx analysis by: Boris Batyunya, JINR, Boris.Batiounia@cern.ch
006b5f7f 518 //--------------------------------------------------------------------
18856a77 519 AliITSlayer &layer=fgLayers[fI];
4ab260d6 520 ResetTrackToFollow(fTracks[fI]);
006b5f7f 521
b87bd7cd 522 Double_t dz=7*TMath::Sqrt(fTrackToFollow.GetSigmaZ2() + kSigmaZ2[fI]);
523 Double_t dy=7*TMath::Sqrt(fTrackToFollow.GetSigmaY2() + kSigmaY2[fI]);
8676d691 524 Double_t road=layer.GetRoad();
525 if (dz*dy>road*road) {
526 Double_t dd=TMath::Sqrt(dz*dy), scz=dz/dd, scy=dy/dd;
527 dz=road*scz; dy=road*scy;
528 }
006b5f7f 529
530 const AliITSclusterV2 *c=0; Int_t ci=-1;
531 Double_t chi2=12345.;
532 while ((c=layer.GetNextCluster(ci))!=0) {
006b5f7f 533 Int_t idet=c->GetDetectorIndex();
15dd636f 534
4ab260d6 535 if (fTrackToFollow.GetDetectorIndex()!=idet) {
006b5f7f 536 const AliITSdetector &det=layer.GetDetector(idet);
4ab260d6 537 ResetTrackToFollow(fTracks[fI]);
538 if (!fTrackToFollow.Propagate(det.GetPhi(),det.GetR())) {
8676d691 539 //Warning("TakeNextProlongation","propagation failed !\n");
006b5f7f 540 continue;
541 }
4ab260d6 542 fTrackToFollow.SetDetectorIndex(idet);
543 if (TMath::Abs(fTrackToFollow.GetZ()-GetZ())>layer.GetR()+dz) continue;
006b5f7f 544 }
545
4ab260d6 546 if (TMath::Abs(fTrackToFollow.GetZ() - c->GetZ()) > dz) continue;
547 if (TMath::Abs(fTrackToFollow.GetY() - c->GetY()) > dy) continue;
006b5f7f 548
4ab260d6 549 chi2=fTrackToFollow.GetPredictedChi2(c); if (chi2<kMaxChi2) break;
006b5f7f 550 }
551
006b5f7f 552 if (chi2>=kMaxChi2) return 0;
553 if (!c) return 0;
554
006b5f7f 555 if (!fTrackToFollow.Update(c,chi2,(fI<<28)+ci)) {
8676d691 556 //Warning("TakeNextProlongation","filtering failed !\n");
006b5f7f 557 return 0;
558 }
15dd636f 559
4ab260d6 560 if (fTrackToFollow.GetNumberOfClusters()>1)
561 if (TMath::Abs(fTrackToFollow.GetD())>4) return 0;
562
a9a2d814 563 fTrackToFollow.
564 SetSampledEdx(c->GetQ(),fTrackToFollow.GetNumberOfClusters()-1); //b.b.
565
566 {
880f41b9 567 Double_t x0;
61ab8ea8 568 Double_t d=layer.GetThickness(fTrackToFollow.GetY(),fTrackToFollow.GetZ(),x0);
880f41b9 569 fTrackToFollow.CorrectForMaterial(d,x0);
a9a2d814 570 }
4ab260d6 571
a9a2d814 572 if (fConstraint[fPass]) {
4ab260d6 573 Double_t d=GetEffectiveThickness(0,0); //Think of this !!!!
8676d691 574 Double_t xyz[]={GetX(),GetY(),GetZ()};
575 Double_t ers[]={GetSigmaX(),GetSigmaY(),GetSigmaZ()};
576 fTrackToFollow.Improve(d,xyz,ers);
a9a2d814 577 }
006b5f7f 578
006b5f7f 579 return 1;
580}
581
582
006b5f7f 583AliITStrackerV2::AliITSlayer::AliITSlayer() {
584 //--------------------------------------------------------------------
585 //default AliITSlayer constructor
586 //--------------------------------------------------------------------
587 fN=0;
588 fDetectors=0;
589}
590
591AliITStrackerV2::AliITSlayer::
592AliITSlayer(Double_t r,Double_t p,Double_t z,Int_t nl,Int_t nd) {
593 //--------------------------------------------------------------------
594 //main AliITSlayer constructor
595 //--------------------------------------------------------------------
596 fR=r; fPhiOffset=p; fZOffset=z;
597 fNladders=nl; fNdetectors=nd;
598 fDetectors=new AliITSdetector[fNladders*fNdetectors];
599
600 fN=0;
601 fI=0;
b87bd7cd 602
603 fRoad=2*fR*TMath::Sqrt(3.14/1.);//assuming that there's only one cluster
006b5f7f 604}
605
606AliITStrackerV2::AliITSlayer::~AliITSlayer() {
607 //--------------------------------------------------------------------
608 // AliITSlayer destructor
609 //--------------------------------------------------------------------
610 delete[] fDetectors;
611 for (Int_t i=0; i<fN; i++) delete fClusters[i];
612}
613
61ab8ea8 614void AliITStrackerV2::AliITSlayer::ResetClusters() {
615 //--------------------------------------------------------------------
616 // This function removes loaded clusters
617 //--------------------------------------------------------------------
618 for (Int_t i=0; i<fN; i++) delete fClusters[i];
619 fN=0;
620 fI=0;
621}
622
b87bd7cd 623void AliITStrackerV2::AliITSlayer::ResetRoad() {
624 //--------------------------------------------------------------------
625 // This function calculates the road defined by the cluster density
626 //--------------------------------------------------------------------
627 Int_t n=0;
628 for (Int_t i=0; i<fN; i++) {
629 if (TMath::Abs(fClusters[i]->GetZ())<fR) n++;
630 }
631 if (n>1) fRoad=2*fR*TMath::Sqrt(3.14/n);
632}
633
006b5f7f 634Int_t AliITStrackerV2::AliITSlayer::InsertCluster(AliITSclusterV2 *c) {
635 //--------------------------------------------------------------------
636 //This function adds a cluster to this layer
637 //--------------------------------------------------------------------
638 if (fN==kMaxClusterPerLayer) {
8676d691 639 ::Error("InsertCluster","Too many clusters !\n");
640 return 1;
006b5f7f 641 }
642
643 if (fN==0) {fClusters[fN++]=c; return 0;}
644 Int_t i=FindClusterIndex(c->GetZ());
645 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliITSclusterV2*));
646 fClusters[i]=c; fN++;
647
648 return 0;
649}
650
651Int_t AliITStrackerV2::AliITSlayer::FindClusterIndex(Double_t z) const {
652 //--------------------------------------------------------------------
653 // This function returns the index of the nearest cluster
654 //--------------------------------------------------------------------
655 if (fN==0) return 0;
656 if (z <= fClusters[0]->GetZ()) return 0;
657 if (z > fClusters[fN-1]->GetZ()) return fN;
658 Int_t b=0, e=fN-1, m=(b+e)/2;
659 for (; b<e; m=(b+e)/2) {
660 if (z > fClusters[m]->GetZ()) b=m+1;
661 else e=m;
662 }
663 return m;
664}
665
666void AliITStrackerV2::AliITSlayer::
667SelectClusters(Double_t zmin,Double_t zmax,Double_t ymin, Double_t ymax) {
668 //--------------------------------------------------------------------
669 // This function sets the "window"
670 //--------------------------------------------------------------------
671 fI=FindClusterIndex(zmin); fZmax=zmax;
14825d5a 672 Double_t circle=2*TMath::Pi()*fR;
673 if (ymax>circle) { ymax-=circle; ymin-=circle; }
006b5f7f 674 fYmin=ymin; fYmax=ymax;
675}
676
677const AliITSclusterV2 *AliITStrackerV2::AliITSlayer::GetNextCluster(Int_t &ci){
678 //--------------------------------------------------------------------
679 // This function returns clusters within the "window"
680 //--------------------------------------------------------------------
681 const AliITSclusterV2 *cluster=0;
682 for (Int_t i=fI; i<fN; i++) {
683 const AliITSclusterV2 *c=fClusters[i];
684 if (c->GetZ() > fZmax) break;
15dd636f 685 if (c->IsUsed()) continue;
006b5f7f 686 const AliITSdetector &det=GetDetector(c->GetDetectorIndex());
687 Double_t y=fR*det.GetPhi() + c->GetY();
688
689 if (y>2.*fR*TMath::Pi()) y -= 2*fR*TMath::Pi();
690 if (y>1.*fR*TMath::Pi() && fYmax<y) y -= 2*fR*TMath::Pi();
691
692 if (y<fYmin) continue;
693 if (y>fYmax) continue;
694 cluster=c; ci=i;
695 fI=i+1;
696 break;
697 }
7f6ddf58 698
006b5f7f 699 return cluster;
700}
701
702Int_t AliITStrackerV2::AliITSlayer::
703FindDetectorIndex(Double_t phi, Double_t z) const {
704 //--------------------------------------------------------------------
705 //This function finds the detector crossed by the track
706 //--------------------------------------------------------------------
f363d377 707 Double_t dphi=-(phi-fPhiOffset);
006b5f7f 708 if (dphi < 0) dphi += 2*TMath::Pi();
709 else if (dphi >= 2*TMath::Pi()) dphi -= 2*TMath::Pi();
710 Int_t np=Int_t(dphi*fNladders*0.5/TMath::Pi()+0.5);
3e3e8427 711 if (np>=fNladders) np-=fNladders;
712 if (np<0) np+=fNladders;
006b5f7f 713
714 Double_t dz=fZOffset-z;
715 Int_t nz=Int_t(dz*(fNdetectors-1)*0.5/fZOffset+0.5);
3e3e8427 716 if (nz>=fNdetectors) return -1;
717 if (nz<0) return -1;
006b5f7f 718
006b5f7f 719 return np*fNdetectors + nz;
720}
721
722Double_t
61ab8ea8 723AliITStrackerV2::AliITSlayer::GetThickness(Double_t y,Double_t z,Double_t &x0)
724const {
a9a2d814 725 //--------------------------------------------------------------------
726 //This function returns the layer thickness at this point (units X0)
727 //--------------------------------------------------------------------
728 Double_t d=0.0085;
61ab8ea8 729 x0=21.82;
a9a2d814 730
731 if (43<fR&&fR<45) { //SSD2
61ab8ea8 732 Double_t dd=0.0034;
733 d=dd;
734 if (TMath::Abs(y-0.00)>3.40) d+=dd;
735 if (TMath::Abs(y-1.90)<0.45) {d+=(0.013-0.0034);}
736 if (TMath::Abs(y+1.90)<0.45) {d+=(0.013-0.0034);}
a9a2d814 737 for (Int_t i=0; i<12; i++) {
61ab8ea8 738 if (TMath::Abs(z-3.9*(i+0.5))<0.15) {
739 if (TMath::Abs(y-0.00)>3.40) d+=dd;
740 d+=0.0034;
741 break;
742 }
743 if (TMath::Abs(z+3.9*(i+0.5))<0.15) {
744 if (TMath::Abs(y-0.00)>3.40) d+=dd;
745 d+=0.0034;
746 break;
747 }
748 if (TMath::Abs(z-3.4-3.9*i)<0.50) {d+=(0.016-0.0034); break;}
749 if (TMath::Abs(z+0.5+3.9*i)<0.50) {d+=(0.016-0.0034); break;}
a9a2d814 750 }
751 } else
752 if (37<fR&&fR<41) { //SSD1
61ab8ea8 753 Double_t dd=0.0034;
754 d=dd;
755 if (TMath::Abs(y-0.00)>3.40) d+=dd;
756 if (TMath::Abs(y-1.90)<0.45) {d+=(0.013-0.0034);}
757 if (TMath::Abs(y+1.90)<0.45) {d+=(0.013-0.0034);}
a9a2d814 758 for (Int_t i=0; i<11; i++) {
61ab8ea8 759 if (TMath::Abs(z-3.9*i)<0.15) {
760 if (TMath::Abs(y-0.00)>3.40) d+=dd;
761 d+=dd;
762 break;
763 }
764 if (TMath::Abs(z+3.9*i)<0.15) {
765 if (TMath::Abs(y-0.00)>3.40) d+=dd;
766 d+=dd;
767 break;
768 }
769 if (TMath::Abs(z-1.85-3.9*i)<0.50) {d+=(0.016-0.0034); break;}
770 if (TMath::Abs(z+2.05+3.9*i)<0.50) {d+=(0.016-0.0034); break;}
a9a2d814 771 }
772 } else
773 if (13<fR&&fR<26) { //SDD
61ab8ea8 774 Double_t dd=0.0033;
775 d=dd;
776 if (TMath::Abs(y-0.00)>3.30) d+=dd;
777
778 if (TMath::Abs(y-1.80)<0.55) {
779 d+=0.016;
780 for (Int_t j=0; j<20; j++) {
781 if (TMath::Abs(z+0.7+1.47*j)<0.12) {d+=0.08; x0=9.; break;}
782 if (TMath::Abs(z-0.7-1.47*j)<0.12) {d+=0.08; x0=9.; break;}
783 }
784 }
785 if (TMath::Abs(y+1.80)<0.55) {
786 d+=0.016;
787 for (Int_t j=0; j<20; j++) {
788 if (TMath::Abs(z-0.7-1.47*j)<0.12) {d+=0.08; x0=9.; break;}
789 if (TMath::Abs(z+0.7+1.47*j)<0.12) {d+=0.08; x0=9.; break;}
790 }
791 }
792
793 for (Int_t i=0; i<4; i++) {
794 if (TMath::Abs(z-7.3*i)<0.60) {
795 d+=dd;
796 if (TMath::Abs(y-0.00)>3.30) d+=dd;
797 break;
798 }
799 if (TMath::Abs(z+7.3*i)<0.60) {
800 d+=dd;
801 if (TMath::Abs(y-0.00)>3.30) d+=dd;
802 break;
803 }
a9a2d814 804 }
805 } else
806 if (6<fR&&fR<8) { //SPD2
61ab8ea8 807 Double_t dd=0.0063; x0=21.5;
808 d=dd;
809 if (TMath::Abs(y-3.08)>0.5) d+=dd;
810 //if (TMath::Abs(y-3.08)>0.45) d+=dd;
811 if (TMath::Abs(y-3.03)<0.10) {d+=0.014;}
a9a2d814 812 } else
813 if (3<fR&&fR<5) { //SPD1
61ab8ea8 814 Double_t dd=0.0063; x0=21.5;
815 d=dd;
816 if (TMath::Abs(y+0.21)>0.6) d+=dd;
817 //if (TMath::Abs(y+0.21)>0.45) d+=dd;
818 if (TMath::Abs(y+0.10)<0.10) {d+=0.014;}
a9a2d814 819 }
820
a9a2d814 821 return d;
822}
006b5f7f 823
a9a2d814 824Double_t AliITStrackerV2::GetEffectiveThickness(Double_t y,Double_t z) const
006b5f7f 825{
826 //--------------------------------------------------------------------
a9a2d814 827 //Returns the thickness between the current layer and the vertex (units X0)
006b5f7f 828 //--------------------------------------------------------------------
61ab8ea8 829 Double_t d=0.0028*3*3; //beam pipe
830 Double_t x0=0;
006b5f7f 831
18856a77 832 Double_t xn=fgLayers[fI].GetR();
006b5f7f 833 for (Int_t i=0; i<fI; i++) {
18856a77 834 Double_t xi=fgLayers[i].GetR();
835 d+=fgLayers[i].GetThickness(y,z,x0)*xi*xi;
006b5f7f 836 }
837
838 if (fI>1) {
61ab8ea8 839 Double_t xi=9.;
840 d+=0.0097*xi*xi;
006b5f7f 841 }
842
843 if (fI>3) {
18856a77 844 Double_t xi=0.5*(fgLayers[3].GetR()+fgLayers[4].GetR());
61ab8ea8 845 d+=0.0034*xi*xi;
006b5f7f 846 }
61ab8ea8 847
006b5f7f 848 return d/(xn*xn);
849}
850
006b5f7f 851Int_t AliITStrackerV2::AliITSlayer::InRoad() const {
852 //--------------------------------------------------------------------
853 // This function returns number of clusters within the "window"
854 //--------------------------------------------------------------------
855 Int_t ncl=0;
856 for (Int_t i=fI; i<fN; i++) {
857 const AliITSclusterV2 *c=fClusters[i];
858 if (c->GetZ() > fZmax) break;
a9a2d814 859 if (c->IsUsed()) continue;
006b5f7f 860 const AliITSdetector &det=GetDetector(c->GetDetectorIndex());
861 Double_t y=fR*det.GetPhi() + c->GetY();
862
863 if (y>2.*fR*TMath::Pi()) y -= 2*fR*TMath::Pi();
864 if (y>1.*fR*TMath::Pi() && fYmax<y) y -= 2*fR*TMath::Pi();
865
866 if (y<fYmin) continue;
867 if (y>fYmax) continue;
868 ncl++;
869 }
870 return ncl;
871}
872
880f41b9 873Bool_t
c630aafd 874AliITStrackerV2::RefitAt(Double_t xx,AliITStrackV2 *t,const AliITStrackV2 *c) {
4ab260d6 875 //--------------------------------------------------------------------
c630aafd 876 // This function refits the track "t" at the position "x" using
877 // the clusters from "c"
4ab260d6 878 //--------------------------------------------------------------------
880f41b9 879 Int_t index[kMaxLayer];
880 Int_t k;
881 for (k=0; k<kMaxLayer; k++) index[k]=-1;
c630aafd 882 Int_t nc=c->GetNumberOfClusters();
880f41b9 883 for (k=0; k<nc; k++) {
c630aafd 884 Int_t idx=c->GetClusterIndex(k),nl=(idx&0xf0000000)>>28;
880f41b9 885 index[nl]=idx;
886 }
880f41b9 887
4ab260d6 888 Int_t from, to, step;
ee34184f 889 if (xx > t->GetX()) {
4ab260d6 890 from=0; to=kMaxLayer;
891 step=+1;
892 } else {
893 from=kMaxLayer-1; to=-1;
894 step=-1;
895 }
896
897 for (Int_t i=from; i != to; i += step) {
18856a77 898 AliITSlayer &layer=fgLayers[i];
4ab260d6 899 Double_t r=layer.GetR();
900
901 {
902 Double_t hI=i-0.5*step;
880f41b9 903 if (TMath::Abs(hI-1.5)<0.01 || TMath::Abs(hI-3.5)<0.01) {
18856a77 904 Double_t rs=0.5*(fgLayers[i-step].GetR() + r);
61ab8ea8 905 Double_t d=0.0034, x0=38.6;
880f41b9 906 if (TMath::Abs(hI-1.5)<0.01) {rs=9.; d=0.0097; x0=42;}
907 if (!t->PropagateTo(rs,-step*d,x0)) {
4ab260d6 908 return kFALSE;
909 }
910 }
911 }
912
880f41b9 913 // remember old position [SR, GSI 18.02.2003]
914 Double_t oldX=0., oldY=0., oldZ=0.;
915 if (t->IsStartedTimeIntegral() && step==1) {
916 t->GetGlobalXYZat(t->GetX(),oldX,oldY,oldZ);
917 }
918 //
919
4ab260d6 920 Double_t x,y,z;
921 if (!t->GetGlobalXYZat(r,x,y,z)) {
922 return kFALSE;
923 }
924 Double_t phi=TMath::ATan2(y,x);
925 Int_t idet=layer.FindDetectorIndex(phi,z);
926 if (idet<0) {
927 return kFALSE;
928 }
929 const AliITSdetector &det=layer.GetDetector(idet);
930 phi=det.GetPhi();
931 if (!t->Propagate(phi,det.GetR())) {
932 return kFALSE;
933 }
934 t->SetDetectorIndex(idet);
935
936 const AliITSclusterV2 *cl=0;
937 Double_t maxchi2=kMaxChi2;
938
939 Int_t idx=index[i];
940 if (idx>0) {
941 const AliITSclusterV2 *c=(AliITSclusterV2 *)GetCluster(idx);
942 if (idet != c->GetDetectorIndex()) {
943 idet=c->GetDetectorIndex();
944 const AliITSdetector &det=layer.GetDetector(idet);
945 if (!t->Propagate(det.GetPhi(),det.GetR())) {
946 return kFALSE;
947 }
948 t->SetDetectorIndex(idet);
949 }
950 Double_t chi2=t->GetPredictedChi2(c);
c630aafd 951 if (chi2<maxchi2) {
952 cl=c;
953 maxchi2=chi2;
954 } else {
955 return kFALSE;
956 }
4ab260d6 957 }
4ab260d6 958 /*
959 if (cl==0)
960 if (t->GetNumberOfClusters()>2) {
961 Double_t dz=4*TMath::Sqrt(t->GetSigmaZ2()+kSigmaZ2[i]);
962 Double_t dy=4*TMath::Sqrt(t->GetSigmaY2()+kSigmaY2[i]);
963 Double_t zmin=t->GetZ() - dz;
964 Double_t zmax=t->GetZ() + dz;
965 Double_t ymin=t->GetY() + phi*r - dy;
966 Double_t ymax=t->GetY() + phi*r + dy;
967 layer.SelectClusters(zmin,zmax,ymin,ymax);
968
969 const AliITSclusterV2 *c=0; Int_t ci=-1;
970 while ((c=layer.GetNextCluster(ci))!=0) {
971 if (idet != c->GetDetectorIndex()) continue;
972 Double_t chi2=t->GetPredictedChi2(c);
973 if (chi2<maxchi2) { cl=c; maxchi2=chi2; idx=ci; }
974 }
975 }
976 */
4ab260d6 977 if (cl) {
978 if (!t->Update(cl,maxchi2,idx)) {
979 return kFALSE;
980 }
880f41b9 981 t->SetSampledEdx(cl->GetQ(),t->GetNumberOfClusters()-1);
4ab260d6 982 }
983
984 {
61ab8ea8 985 Double_t x0;
986 Double_t d=layer.GetThickness(t->GetY(),t->GetZ(),x0);
987 t->CorrectForMaterial(-step*d,x0);
4ab260d6 988 }
880f41b9 989
990 // track time update [SR, GSI 17.02.2003]
991 if (t->IsStartedTimeIntegral() && step==1) {
992 Double_t newX, newY, newZ;
993 t->GetGlobalXYZat(t->GetX(),newX,newY,newZ);
994 Double_t dL2 = (oldX-newX)*(oldX-newX) + (oldY-newY)*(oldY-newY) +
995 (oldZ-newZ)*(oldZ-newZ);
996 t->AddTimeStep(TMath::Sqrt(dL2));
997 }
998 //
4ab260d6 999
1000 }
1001
ee34184f 1002 if (!t->PropagateTo(xx,0.,0.)) return kFALSE;
4ab260d6 1003 return kTRUE;
1004}
1005
b87bd7cd 1006void AliITStrackerV2::UseClusters(const AliKalmanTrack *t, Int_t from) const {
1007 //--------------------------------------------------------------------
1008 // This function marks clusters assigned to the track
1009 //--------------------------------------------------------------------
1010 AliTracker::UseClusters(t,from);
880f41b9 1011
b87bd7cd 1012 AliITSclusterV2 *c=(AliITSclusterV2 *)GetCluster(t->GetClusterIndex(0));
1013 //if (c->GetQ()>2) c->Use();
1014 if (c->GetSigmaZ2()>0.1) c->Use();
1015 c=(AliITSclusterV2 *)GetCluster(t->GetClusterIndex(1));
1016 //if (c->GetQ()>2) c->Use();
1017 if (c->GetSigmaZ2()>0.1) c->Use();
880f41b9 1018
b87bd7cd 1019}