1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //-------------------------------------------------------------------------
17 // Implementation of the ITS tracker class
18 // It reads AliITSclusterV2 clusters and creates AliITStrackV2 tracks
19 // and fills with them the ESD
20 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
21 // dEdx analysis by: Boris Batyunya, JINR, Boris.Batiounia@cern.ch
22 //-------------------------------------------------------------------------
28 #include "AliITSgeom.h"
29 #include "AliITSRecPoint.h"
30 #include "AliTPCtrack.h"
32 #include "AliITSclusterV2.h"
33 #include "AliITStrackerV2.h"
35 ClassImp(AliITStrackerV2)
37 AliITStrackerV2::AliITSlayer AliITStrackerV2::fgLayers[kMaxLayer]; // ITS layers
39 AliITStrackerV2::AliITStrackerV2(const AliITSgeom *geom) : AliTracker() {
40 //--------------------------------------------------------------------
41 //This is the AliITStrackerV2 constructor
42 //--------------------------------------------------------------------
43 AliITSgeom *g=(AliITSgeom*)geom;
47 for (i=1; i<kMaxLayer+1; i++) {
48 Int_t nlad=g->GetNladders(i);
49 Int_t ndet=g->GetNdetectors(i);
51 g->GetTrans(i,1,1,x,y,z);
52 Double_t r=TMath::Sqrt(x*x + y*y);
53 Double_t poff=TMath::ATan2(y,x);
56 g->GetTrans(i,1,2,x,y,z);
57 r += TMath::Sqrt(x*x + y*y);
58 g->GetTrans(i,2,1,x,y,z);
59 r += TMath::Sqrt(x*x + y*y);
60 g->GetTrans(i,2,2,x,y,z);
61 r += TMath::Sqrt(x*x + y*y);
64 new (fgLayers+i-1) AliITSlayer(r,poff,zoff,nlad,ndet);
66 for (Int_t j=1; j<nlad+1; j++) {
67 for (Int_t k=1; k<ndet+1; k++) { //Fill this layer with detectors
68 Float_t x,y,zshift; g->GetTrans(i,j,k,x,y,zshift);
69 Double_t rot[9]; g->GetRotMatrix(i,j,k,rot);
71 Double_t phi=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
73 if (i==1) phi+=TMath::Pi();
74 Double_t cp=TMath::Cos(phi), sp=TMath::Sin(phi);
77 AliITSdetector &det=fgLayers[i-1].GetDetector((j-1)*ndet + k-1);
78 new(&det) AliITSdetector(r,phi);
87 fConstraint[0]=1; fConstraint[1]=0;
89 Double_t xyz[]={kXV,kYV,kZV}, ers[]={kSigmaXV,kSigmaYV,kSigmaZV};
92 for (Int_t i=0; i<kMaxLayer; i++) fLayersNotToSkip[i]=kLayersNotToSkip[i];
93 fLastLayerToTrackTo=kLastLayerToTrackTo;
97 void AliITStrackerV2::SetLayersNotToSkip(Int_t *l) {
98 //--------------------------------------------------------------------
99 //This function set masks of the layers which must be not skipped
100 //--------------------------------------------------------------------
101 for (Int_t i=0; i<kMaxLayer; i++) fLayersNotToSkip[i]=l[i];
104 Int_t AliITStrackerV2::LoadClusters(TTree *cTree) {
105 //--------------------------------------------------------------------
106 //This function loads ITS clusters
107 //--------------------------------------------------------------------
108 TBranch *branch=cTree->GetBranch("Clusters");
110 Error("LoadClusters"," can't get the branch !\n");
114 TClonesArray dummy("AliITSclusterV2",10000), *clusters=&dummy;
115 branch->SetAddress(&clusters);
118 for (Int_t i=0; i<kMaxLayer; i++) {
119 Int_t ndet=fgLayers[i].GetNdetectors();
120 Int_t jmax = j + fgLayers[i].GetNladders()*ndet;
121 for (; j<jmax; j++) {
122 if (!cTree->GetEvent(j)) continue;
123 Int_t ncl=clusters->GetEntriesFast();
125 AliITSclusterV2 *c=(AliITSclusterV2*)clusters->UncheckedAt(ncl);
126 fgLayers[i].InsertCluster(new AliITSclusterV2(*c));
130 fgLayers[i].ResetRoad(); //road defined by the cluster density
136 void AliITStrackerV2::UnloadClusters() {
137 //--------------------------------------------------------------------
138 //This function unloads ITS clusters
139 //--------------------------------------------------------------------
140 for (Int_t i=0; i<kMaxLayer; i++) fgLayers[i].ResetClusters();
143 static Int_t CorrectForDeadZoneMaterial(AliITStrackV2 *t) {
144 //--------------------------------------------------------------------
145 // Correction for the material between the TPC and the ITS
146 // (should it belong to the TPC code ?)
147 //--------------------------------------------------------------------
148 Double_t riw=80., diw=0.0053, x0iw=30; // TPC inner wall ?
149 Double_t rcd=61., dcd=0.0053, x0cd=30; // TPC "central drum" ?
150 Double_t yr=12.8, dr=0.03; // rods ?
151 Double_t zm=0.2, dm=0.40; // membrane
152 //Double_t rr=52., dr=0.19, x0r=24., yyr=7.77; //rails
153 Double_t rs=50., ds=0.001; // something belonging to the ITS (screen ?)
155 if (t->GetX() > riw) {
156 if (!t->PropagateTo(riw,diw,x0iw)) return 1;
157 if (TMath::Abs(t->GetY())>yr) t->CorrectForMaterial(dr);
158 if (TMath::Abs(t->GetZ())<zm) t->CorrectForMaterial(dm);
159 if (!t->PropagateTo(rcd,dcd,x0cd)) return 1;
160 //Double_t x,y,z; t->GetGlobalXYZat(rr,x,y,z);
161 //if (TMath::Abs(y)<yyr) t->PropagateTo(rr,dr,x0r);
162 if (!t->PropagateTo(rs,ds)) return 1;
163 } else if (t->GetX() < rs) {
164 if (!t->PropagateTo(rs,-ds)) return 1;
165 //Double_t x,y,z; t->GetGlobalXYZat(rr,x,y,z);
166 //if (TMath::Abs(y)<yyr) t->PropagateTo(rr,-dr,x0r);
167 if (!t->PropagateTo(rcd,-dcd,x0cd)) return 1;
168 if (!t->PropagateTo(riw+0.001,-diw,x0iw)) return 1;
170 ::Error("CorrectForDeadZoneMaterial","track is already in the dead zone !");
177 Int_t AliITStrackerV2::Clusters2Tracks(AliESD *event) {
178 //--------------------------------------------------------------------
179 // This functions reconstructs ITS tracks
180 // The clusters must be already loaded !
181 //--------------------------------------------------------------------
182 TObjArray itsTracks(15000);
184 {/* Read ESD tracks */
185 Int_t nentr=event->GetNumberOfTracks();
186 Info("Clusters2Tracks", "Number of ESD tracks: %d\n", nentr);
188 AliESDtrack *esd=event->GetTrack(nentr);
190 if ((esd->GetStatus()&AliESDtrack::kTPCin)==0) continue;
191 if (esd->GetStatus()&AliESDtrack::kTPCout) continue;
192 if (esd->GetStatus()&AliESDtrack::kITSin) continue;
196 t=new AliITStrackV2(*esd);
197 } catch (const Char_t *msg) {
198 Warning("Clusters2Tracks",msg);
202 if (TMath::Abs(t->GetD())>4) {
207 if (CorrectForDeadZoneMaterial(t)!=0) {
208 Warning("Clusters2Tracks",
209 "failed to correct for the material in the dead zone !\n");
213 itsTracks.AddLast(t);
215 } /* End Read ESD tracks */
218 Int_t nentr=itsTracks.GetEntriesFast();
221 for (fPass=0; fPass<2; fPass++) {
222 Int_t &constraint=fConstraint[fPass]; if (constraint<0) continue;
223 for (Int_t i=0; i<nentr; i++) {
224 AliITStrackV2 *t=(AliITStrackV2*)itsTracks.UncheckedAt(i);
225 if (t==0) continue; //this track has been already tracked
226 Int_t tpcLabel=t->GetLabel(); //save the TPC track label
228 ResetTrackToFollow(*t);
231 for (FollowProlongation(); fI<kMaxLayer; fI++) {
232 while (TakeNextProlongation()) FollowProlongation();
235 if (fBestTrack.GetNumberOfClusters() == 0) continue;
237 if (fConstraint[fPass]) {
238 ResetTrackToFollow(*t);
239 if (!RefitAt(3.7, &fTrackToFollow, &fBestTrack)) continue;
243 fBestTrack.SetLabel(tpcLabel);
244 fBestTrack.CookdEdx();
245 CookLabel(&fBestTrack,0.); //For comparison only
246 fBestTrack.UpdateESDtrack(AliESDtrack::kITSin);
247 UseClusters(&fBestTrack);
248 delete itsTracks.RemoveAt(i);
255 Info("Clusters2Tracks","Number of prolonged tracks: %d\n",ntrk);
260 Int_t AliITStrackerV2::Clusters2Tracks(TTree *tpcTree, TTree *itsTree) {
261 //--------------------------------------------------------------------
262 // This functions reconstructs ITS tracks
263 // The clusters must be already loaded !
264 //--------------------------------------------------------------------
265 Int_t nentr=0; TObjArray itsTracks(15000);
267 Warning("Clusters2Tracks(TTree *, TTree *)",
268 "Will be removed soon ! Use Clusters2Tracks(AliESD *) instead.");
270 {/* Read TPC tracks */
271 AliTPCtrack *itrack=new AliTPCtrack;
272 TBranch *branch=tpcTree->GetBranch("tracks");
274 Error("Clusters2Tracks","Can't get the branch !");
277 tpcTree->SetBranchAddress("tracks",&itrack);
278 nentr=(Int_t)tpcTree->GetEntries();
280 Info("Clusters2Tracks","Number of TPC tracks: %d\n",nentr);
282 for (Int_t i=0; i<nentr; i++) {
283 tpcTree->GetEvent(i);
286 t=new AliITStrackV2(*itrack);
287 } catch (const Char_t *msg) {
288 Warning("Clusters2Tracks",msg);
292 if (TMath::Abs(t->GetD())>4) {
297 if (CorrectForDeadZoneMaterial(t)!=0) {
298 Warning("Clusters2Tracks",
299 "failed to correct for the material in the dead zone !\n");
304 itsTracks.AddLast(t);
309 nentr=itsTracks.GetEntriesFast();
312 AliITStrackV2 *otrack=&fBestTrack;
313 TBranch *branch=itsTree->GetBranch("tracks");
314 if (!branch) itsTree->Branch("tracks","AliITStrackV2",&otrack,32000,3);
315 else branch->SetAddress(&otrack);
317 for (fPass=0; fPass<2; fPass++) {
318 Int_t &constraint=fConstraint[fPass]; if (constraint<0) continue;
319 for (Int_t i=0; i<nentr; i++) {
320 AliITStrackV2 *t=(AliITStrackV2*)itsTracks.UncheckedAt(i);
321 if (t==0) continue; //this track has been already tracked
322 Int_t tpcLabel=t->GetLabel(); //save the TPC track label
324 ResetTrackToFollow(*t);
327 for (FollowProlongation(); fI<kMaxLayer; fI++) {
328 while (TakeNextProlongation()) FollowProlongation();
331 if (fBestTrack.GetNumberOfClusters() == 0) continue;
333 if (fConstraint[fPass]) {
334 ResetTrackToFollow(*t);
335 if (!RefitAt(3.7, &fTrackToFollow, &fBestTrack)) continue;
339 fBestTrack.SetLabel(tpcLabel);
340 fBestTrack.CookdEdx();
341 CookLabel(&fBestTrack,0.); //For comparison only
343 UseClusters(&fBestTrack);
344 delete itsTracks.RemoveAt(i);
348 nentr=(Int_t)itsTree->GetEntries();
349 Info("Clusters2Tracks","Number of prolonged tracks: %d\n",nentr);
356 Int_t AliITStrackerV2::PropagateBack(AliESD *event) {
357 //--------------------------------------------------------------------
358 // This functions propagates reconstructed ITS tracks back
359 // The clusters must be loaded !
360 //--------------------------------------------------------------------
361 Int_t nentr=event->GetNumberOfTracks();
362 Info("PropagateBack", "Number of ESD tracks: %d\n", nentr);
365 for (Int_t i=0; i<nentr; i++) {
366 AliESDtrack *esd=event->GetTrack(i);
368 if ((esd->GetStatus()&AliESDtrack::kITSin)==0) continue;
369 if (esd->GetStatus()&AliESDtrack::kITSout) continue;
373 t=new AliITStrackV2(*esd);
374 } catch (const Char_t *msg) {
375 Warning("PropagateBack",msg);
380 ResetTrackToFollow(*t);
382 // propagete to vertex [SR, GSI 17.02.2003]
383 // Start Time measurement [SR, GSI 17.02.2003], corrected by I.Belikov
384 if (fTrackToFollow.PropagateTo(3.,0.0028,65.19)) {
385 if (fTrackToFollow.PropagateToVertex()) {
386 fTrackToFollow.StartTimeIntegral();
388 fTrackToFollow.PropagateTo(3.,-0.0028,65.19);
391 fTrackToFollow.ResetCovariance(); fTrackToFollow.ResetClusters();
392 if (RefitAt(49.,&fTrackToFollow,t)) {
393 if (CorrectForDeadZoneMaterial(&fTrackToFollow)!=0) {
394 Warning("PropagateBack",
395 "failed to correct for the material in the dead zone !\n");
399 fTrackToFollow.SetLabel(t->GetLabel());
400 //fTrackToFollow.CookdEdx();
401 CookLabel(&fTrackToFollow,0.); //For comparison only
402 fTrackToFollow.UpdateESDtrack(AliESDtrack::kITSout);
403 UseClusters(&fTrackToFollow);
409 Info("PropagateBack","Number of back propagated ITS tracks: %d\n",ntrk);
414 Int_t AliITStrackerV2::RefitInward(AliESD *event) {
415 //--------------------------------------------------------------------
416 // This functions refits ITS tracks using the
417 // "inward propagated" TPC tracks
418 // The clusters must be loaded !
419 //--------------------------------------------------------------------
420 Int_t nentr=event->GetNumberOfTracks();
421 Info("RefitInward", "Number of ESD tracks: %d\n", nentr);
424 for (Int_t i=0; i<nentr; i++) {
425 AliESDtrack *esd=event->GetTrack(i);
427 if ((esd->GetStatus()&AliESDtrack::kITSout) == 0) continue;
428 if (esd->GetStatus()&AliESDtrack::kITSrefit) continue;
429 if (esd->GetStatus()&AliESDtrack::kTPCout)
430 if ((esd->GetStatus()&AliESDtrack::kTPCrefit)==0) continue;
434 t=new AliITStrackV2(*esd);
435 } catch (const Char_t *msg) {
436 Warning("RefitInward",msg);
441 if (CorrectForDeadZoneMaterial(t)!=0) {
442 Warning("RefitInward",
443 "failed to correct for the material in the dead zone !\n");
448 ResetTrackToFollow(*t);
449 fTrackToFollow.ResetClusters();
452 if (RefitAt(3.7, &fTrackToFollow, t)) {
453 fTrackToFollow.SetLabel(t->GetLabel());
454 fTrackToFollow.CookdEdx();
455 CookLabel(&fTrackToFollow,0.); //For comparison only
457 if (fTrackToFollow.PropagateTo(3.,0.0028,65.19)) {//The beam pipe
458 Double_t a=fTrackToFollow.GetAlpha();
459 Double_t cs=TMath::Cos(a),sn=TMath::Sin(a);
460 Double_t xv= GetX()*cs + GetY()*sn;
461 Double_t yv=-GetX()*sn + GetY()*cs;
463 Double_t c=fTrackToFollow.GetC(), snp=fTrackToFollow.GetSnp();
464 Double_t x=fTrackToFollow.GetX(), y=fTrackToFollow.GetY();
465 Double_t tgfv=-(c*(x-xv)-snp)/(c*(y-yv) + TMath::Sqrt(1.-snp*snp));
466 Double_t fv=TMath::ATan(tgfv);
468 cs=TMath::Cos(fv); sn=TMath::Sin(fv);
470 yv=-xv*sn + yv*cs; xv=x;
472 if (fTrackToFollow.Propagate(fv+a,xv)) {
473 fTrackToFollow.UpdateESDtrack(AliESDtrack::kITSrefit);
474 UseClusters(&fTrackToFollow);
476 AliITSclusterV2 c; c.SetY(yv); c.SetZ(GetZ());
477 c.SetSigmaY2(GetSigmaY()*GetSigmaY());
478 c.SetSigmaZ2(GetSigmaZ()*GetSigmaZ());
479 Double_t chi2=fTrackToFollow.GetPredictedChi2(&c);
481 if (fTrackToFollow.Update(&c,-chi2,0))
482 fTrackToFollow.SetConstrainedESDtrack(chi2);
491 Info("RefitInward","Number of refitted tracks: %d\n",ntrk);
496 AliCluster *AliITStrackerV2::GetCluster(Int_t index) const {
497 //--------------------------------------------------------------------
498 // Return pointer to a given cluster
499 //--------------------------------------------------------------------
500 Int_t l=(index & 0xf0000000) >> 28;
501 Int_t c=(index & 0x0fffffff) >> 00;
502 return fgLayers[l].GetCluster(c);
506 void AliITStrackerV2::FollowProlongation() {
507 //--------------------------------------------------------------------
508 //This function finds a track prolongation
509 //--------------------------------------------------------------------
510 while (fI>fLastLayerToTrackTo) {
513 AliITSlayer &layer=fgLayers[i];
514 AliITStrackV2 &track=fTracks[i];
516 Double_t r=layer.GetR();
519 Double_t rs=0.5*(fgLayers[i+1].GetR() + r);
520 Double_t d=0.0034, x0=38.6;
521 if (i==1) {rs=9.; d=0.0097; x0=42;}
522 if (!fTrackToFollow.PropagateTo(rs,d,x0)) {
523 //Warning("FollowProlongation","propagation failed !\n");
530 if (!fTrackToFollow.GetGlobalXYZat(r,x,y,z)) {
531 //Warning("FollowProlongation","failed to estimate track !\n");
534 Double_t phi=TMath::ATan2(y,x);
536 Int_t idet=layer.FindDetectorIndex(phi,z);
538 //Warning("FollowProlongation","failed to find a detector !\n");
542 //propagate to the intersection
543 const AliITSdetector &det=layer.GetDetector(idet);
545 if (!fTrackToFollow.Propagate(phi,det.GetR())) {
546 //Warning("FollowProlongation","propagation failed !\n");
549 fTrackToFollow.SetDetectorIndex(idet);
551 //Select possible prolongations and store the current track estimation
552 track.~AliITStrackV2(); new(&track) AliITStrackV2(fTrackToFollow);
553 Double_t dz=7*TMath::Sqrt(track.GetSigmaZ2() + kSigmaZ2[i]);
554 Double_t dy=7*TMath::Sqrt(track.GetSigmaY2() + kSigmaY2[i]);
555 Double_t road=layer.GetRoad();
556 if (dz*dy>road*road) {
557 Double_t dd=TMath::Sqrt(dz*dy), scz=dz/dd, scy=dy/dd;
558 dz=road*scz; dy=road*scy;
561 //Double_t dz=4*TMath::Sqrt(track.GetSigmaZ2() + kSigmaZ2[i]);
562 if (dz < 0.5*TMath::Abs(track.GetTgl())) dz=0.5*TMath::Abs(track.GetTgl());
564 //Warning("FollowProlongation","too broad road in Z !\n");
568 if (TMath::Abs(fTrackToFollow.GetZ()-GetZ()) > r+dz) return;
570 //Double_t dy=4*TMath::Sqrt(track.GetSigmaY2() + kSigmaY2[i]);
571 if (dy < 0.5*TMath::Abs(track.GetSnp())) dy=0.5*TMath::Abs(track.GetSnp());
573 //Warning("FollowProlongation","too broad road in Y !\n");
577 Double_t zmin=track.GetZ() - dz;
578 Double_t zmax=track.GetZ() + dz;
579 Double_t ymin=track.GetY() + r*phi - dy;
580 Double_t ymax=track.GetY() + r*phi + dy;
581 layer.SelectClusters(zmin,zmax,ymin,ymax);
584 //take another prolongation
585 if (!TakeNextProlongation())
586 if (fLayersNotToSkip[fI]) return;
590 //deal with the best track
591 Int_t ncl=fTrackToFollow.GetNumberOfClusters();
592 Int_t nclb=fBestTrack.GetNumberOfClusters();
595 Double_t chi2=fTrackToFollow.GetChi2();
596 if (chi2/ncl < kChi2PerCluster) {
597 if (ncl > nclb || chi2 < fBestTrack.GetChi2()) {
605 Int_t AliITStrackerV2::TakeNextProlongation() {
606 //--------------------------------------------------------------------
607 // This function takes another track prolongation
609 // dEdx analysis by: Boris Batyunya, JINR, Boris.Batiounia@cern.ch
610 //--------------------------------------------------------------------
611 AliITSlayer &layer=fgLayers[fI];
612 ResetTrackToFollow(fTracks[fI]);
614 Double_t dz=7*TMath::Sqrt(fTrackToFollow.GetSigmaZ2() + kSigmaZ2[fI]);
615 Double_t dy=7*TMath::Sqrt(fTrackToFollow.GetSigmaY2() + kSigmaY2[fI]);
616 Double_t road=layer.GetRoad();
617 if (dz*dy>road*road) {
618 Double_t dd=TMath::Sqrt(dz*dy), scz=dz/dd, scy=dy/dd;
619 dz=road*scz; dy=road*scy;
622 const AliITSclusterV2 *c=0; Int_t ci=-1;
623 Double_t chi2=12345.;
624 while ((c=layer.GetNextCluster(ci))!=0) {
625 Int_t idet=c->GetDetectorIndex();
627 if (fTrackToFollow.GetDetectorIndex()!=idet) {
628 const AliITSdetector &det=layer.GetDetector(idet);
629 ResetTrackToFollow(fTracks[fI]);
630 if (!fTrackToFollow.Propagate(det.GetPhi(),det.GetR())) {
631 //Warning("TakeNextProlongation","propagation failed !\n");
634 fTrackToFollow.SetDetectorIndex(idet);
635 if (TMath::Abs(fTrackToFollow.GetZ()-GetZ())>layer.GetR()+dz) continue;
638 if (TMath::Abs(fTrackToFollow.GetZ() - c->GetZ()) > dz) continue;
639 if (TMath::Abs(fTrackToFollow.GetY() - c->GetY()) > dy) continue;
641 chi2=fTrackToFollow.GetPredictedChi2(c); if (chi2<kMaxChi2) break;
644 if (chi2>=kMaxChi2) return 0;
647 if (!fTrackToFollow.Update(c,chi2,(fI<<28)+ci)) {
648 //Warning("TakeNextProlongation","filtering failed !\n");
652 if (fTrackToFollow.GetNumberOfClusters()>1)
653 if (TMath::Abs(fTrackToFollow.GetD())>4) return 0;
656 SetSampledEdx(c->GetQ(),fTrackToFollow.GetNumberOfClusters()-1); //b.b.
660 Double_t d=layer.GetThickness(fTrackToFollow.GetY(),fTrackToFollow.GetZ(),x0);
661 fTrackToFollow.CorrectForMaterial(d,x0);
664 if (fConstraint[fPass]) {
665 Double_t d=GetEffectiveThickness(0,0); //Think of this !!!!
666 Double_t xyz[]={GetX(),GetY(),GetZ()};
667 Double_t ers[]={GetSigmaX(),GetSigmaY(),GetSigmaZ()};
668 fTrackToFollow.Improve(d,xyz,ers);
675 AliITStrackerV2::AliITSlayer::AliITSlayer() {
676 //--------------------------------------------------------------------
677 //default AliITSlayer constructor
678 //--------------------------------------------------------------------
683 AliITStrackerV2::AliITSlayer::
684 AliITSlayer(Double_t r,Double_t p,Double_t z,Int_t nl,Int_t nd) {
685 //--------------------------------------------------------------------
686 //main AliITSlayer constructor
687 //--------------------------------------------------------------------
688 fR=r; fPhiOffset=p; fZOffset=z;
689 fNladders=nl; fNdetectors=nd;
690 fDetectors=new AliITSdetector[fNladders*fNdetectors];
695 fRoad=2*fR*TMath::Sqrt(3.14/1.);//assuming that there's only one cluster
698 AliITStrackerV2::AliITSlayer::~AliITSlayer() {
699 //--------------------------------------------------------------------
700 // AliITSlayer destructor
701 //--------------------------------------------------------------------
703 for (Int_t i=0; i<fN; i++) delete fClusters[i];
706 void AliITStrackerV2::AliITSlayer::ResetClusters() {
707 //--------------------------------------------------------------------
708 // This function removes loaded clusters
709 //--------------------------------------------------------------------
710 for (Int_t i=0; i<fN; i++) delete fClusters[i];
715 void AliITStrackerV2::AliITSlayer::ResetRoad() {
716 //--------------------------------------------------------------------
717 // This function calculates the road defined by the cluster density
718 //--------------------------------------------------------------------
720 for (Int_t i=0; i<fN; i++) {
721 if (TMath::Abs(fClusters[i]->GetZ())<fR) n++;
723 if (n>1) fRoad=2*fR*TMath::Sqrt(3.14/n);
726 Int_t AliITStrackerV2::AliITSlayer::InsertCluster(AliITSclusterV2 *c) {
727 //--------------------------------------------------------------------
728 //This function adds a cluster to this layer
729 //--------------------------------------------------------------------
730 if (fN==kMaxClusterPerLayer) {
731 ::Error("InsertCluster","Too many clusters !\n");
735 if (fN==0) {fClusters[fN++]=c; return 0;}
736 Int_t i=FindClusterIndex(c->GetZ());
737 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliITSclusterV2*));
738 fClusters[i]=c; fN++;
743 Int_t AliITStrackerV2::AliITSlayer::FindClusterIndex(Double_t z) const {
744 //--------------------------------------------------------------------
745 // This function returns the index of the nearest cluster
746 //--------------------------------------------------------------------
748 if (z <= fClusters[0]->GetZ()) return 0;
749 if (z > fClusters[fN-1]->GetZ()) return fN;
750 Int_t b=0, e=fN-1, m=(b+e)/2;
751 for (; b<e; m=(b+e)/2) {
752 if (z > fClusters[m]->GetZ()) b=m+1;
758 void AliITStrackerV2::AliITSlayer::
759 SelectClusters(Double_t zmin,Double_t zmax,Double_t ymin, Double_t ymax) {
760 //--------------------------------------------------------------------
761 // This function sets the "window"
762 //--------------------------------------------------------------------
763 fI=FindClusterIndex(zmin); fZmax=zmax;
764 Double_t circle=2*TMath::Pi()*fR;
765 if (ymax>circle) { ymax-=circle; ymin-=circle; }
766 fYmin=ymin; fYmax=ymax;
769 const AliITSclusterV2 *AliITStrackerV2::AliITSlayer::GetNextCluster(Int_t &ci){
770 //--------------------------------------------------------------------
771 // This function returns clusters within the "window"
772 //--------------------------------------------------------------------
773 const AliITSclusterV2 *cluster=0;
774 for (Int_t i=fI; i<fN; i++) {
775 const AliITSclusterV2 *c=fClusters[i];
776 if (c->GetZ() > fZmax) break;
777 if (c->IsUsed()) continue;
778 const AliITSdetector &det=GetDetector(c->GetDetectorIndex());
779 Double_t y=fR*det.GetPhi() + c->GetY();
781 if (y>2.*fR*TMath::Pi()) y -= 2*fR*TMath::Pi();
782 if (y>1.*fR*TMath::Pi() && fYmax<y) y -= 2*fR*TMath::Pi();
784 if (y<fYmin) continue;
785 if (y>fYmax) continue;
794 Int_t AliITStrackerV2::AliITSlayer::
795 FindDetectorIndex(Double_t phi, Double_t z) const {
796 //--------------------------------------------------------------------
797 //This function finds the detector crossed by the track
798 //--------------------------------------------------------------------
799 Double_t dphi=-(phi-fPhiOffset);
800 if (dphi < 0) dphi += 2*TMath::Pi();
801 else if (dphi >= 2*TMath::Pi()) dphi -= 2*TMath::Pi();
802 Int_t np=Int_t(dphi*fNladders*0.5/TMath::Pi()+0.5);
803 if (np>=fNladders) np-=fNladders;
804 if (np<0) np+=fNladders;
806 Double_t dz=fZOffset-z;
807 Int_t nz=Int_t(dz*(fNdetectors-1)*0.5/fZOffset+0.5);
808 if (nz>=fNdetectors) return -1;
811 return np*fNdetectors + nz;
815 AliITStrackerV2::AliITSlayer::GetThickness(Double_t y,Double_t z,Double_t &x0)
817 //--------------------------------------------------------------------
818 //This function returns the layer thickness at this point (units X0)
819 //--------------------------------------------------------------------
823 if (43<fR&&fR<45) { //SSD2
826 if (TMath::Abs(y-0.00)>3.40) d+=dd;
827 if (TMath::Abs(y-1.90)<0.45) {d+=(0.013-0.0034);}
828 if (TMath::Abs(y+1.90)<0.45) {d+=(0.013-0.0034);}
829 for (Int_t i=0; i<12; i++) {
830 if (TMath::Abs(z-3.9*(i+0.5))<0.15) {
831 if (TMath::Abs(y-0.00)>3.40) d+=dd;
835 if (TMath::Abs(z+3.9*(i+0.5))<0.15) {
836 if (TMath::Abs(y-0.00)>3.40) d+=dd;
840 if (TMath::Abs(z-3.4-3.9*i)<0.50) {d+=(0.016-0.0034); break;}
841 if (TMath::Abs(z+0.5+3.9*i)<0.50) {d+=(0.016-0.0034); break;}
844 if (37<fR&&fR<41) { //SSD1
847 if (TMath::Abs(y-0.00)>3.40) d+=dd;
848 if (TMath::Abs(y-1.90)<0.45) {d+=(0.013-0.0034);}
849 if (TMath::Abs(y+1.90)<0.45) {d+=(0.013-0.0034);}
850 for (Int_t i=0; i<11; i++) {
851 if (TMath::Abs(z-3.9*i)<0.15) {
852 if (TMath::Abs(y-0.00)>3.40) d+=dd;
856 if (TMath::Abs(z+3.9*i)<0.15) {
857 if (TMath::Abs(y-0.00)>3.40) d+=dd;
861 if (TMath::Abs(z-1.85-3.9*i)<0.50) {d+=(0.016-0.0034); break;}
862 if (TMath::Abs(z+2.05+3.9*i)<0.50) {d+=(0.016-0.0034); break;}
865 if (13<fR&&fR<26) { //SDD
868 if (TMath::Abs(y-0.00)>3.30) d+=dd;
870 if (TMath::Abs(y-1.80)<0.55) {
872 for (Int_t j=0; j<20; j++) {
873 if (TMath::Abs(z+0.7+1.47*j)<0.12) {d+=0.08; x0=9.; break;}
874 if (TMath::Abs(z-0.7-1.47*j)<0.12) {d+=0.08; x0=9.; break;}
877 if (TMath::Abs(y+1.80)<0.55) {
879 for (Int_t j=0; j<20; j++) {
880 if (TMath::Abs(z-0.7-1.47*j)<0.12) {d+=0.08; x0=9.; break;}
881 if (TMath::Abs(z+0.7+1.47*j)<0.12) {d+=0.08; x0=9.; break;}
885 for (Int_t i=0; i<4; i++) {
886 if (TMath::Abs(z-7.3*i)<0.60) {
888 if (TMath::Abs(y-0.00)>3.30) d+=dd;
891 if (TMath::Abs(z+7.3*i)<0.60) {
893 if (TMath::Abs(y-0.00)>3.30) d+=dd;
898 if (6<fR&&fR<8) { //SPD2
899 Double_t dd=0.0063; x0=21.5;
901 if (TMath::Abs(y-3.08)>0.5) d+=dd;
902 //if (TMath::Abs(y-3.08)>0.45) d+=dd;
903 if (TMath::Abs(y-3.03)<0.10) {d+=0.014;}
905 if (3<fR&&fR<5) { //SPD1
906 Double_t dd=0.0063; x0=21.5;
908 if (TMath::Abs(y+0.21)>0.6) d+=dd;
909 //if (TMath::Abs(y+0.21)>0.45) d+=dd;
910 if (TMath::Abs(y+0.10)<0.10) {d+=0.014;}
916 Double_t AliITStrackerV2::GetEffectiveThickness(Double_t y,Double_t z) const
918 //--------------------------------------------------------------------
919 //Returns the thickness between the current layer and the vertex (units X0)
920 //--------------------------------------------------------------------
921 Double_t d=0.0028*3*3; //beam pipe
924 Double_t xn=fgLayers[fI].GetR();
925 for (Int_t i=0; i<fI; i++) {
926 Double_t xi=fgLayers[i].GetR();
927 d+=fgLayers[i].GetThickness(y,z,x0)*xi*xi;
936 Double_t xi=0.5*(fgLayers[3].GetR()+fgLayers[4].GetR());
943 Int_t AliITStrackerV2::AliITSlayer::InRoad() const {
944 //--------------------------------------------------------------------
945 // This function returns number of clusters within the "window"
946 //--------------------------------------------------------------------
948 for (Int_t i=fI; i<fN; i++) {
949 const AliITSclusterV2 *c=fClusters[i];
950 if (c->GetZ() > fZmax) break;
951 if (c->IsUsed()) continue;
952 const AliITSdetector &det=GetDetector(c->GetDetectorIndex());
953 Double_t y=fR*det.GetPhi() + c->GetY();
955 if (y>2.*fR*TMath::Pi()) y -= 2*fR*TMath::Pi();
956 if (y>1.*fR*TMath::Pi() && fYmax<y) y -= 2*fR*TMath::Pi();
958 if (y<fYmin) continue;
959 if (y>fYmax) continue;
966 AliITStrackerV2::RefitAt(Double_t xx,AliITStrackV2 *t,const AliITStrackV2 *c) {
967 //--------------------------------------------------------------------
968 // This function refits the track "t" at the position "x" using
969 // the clusters from "c"
970 //--------------------------------------------------------------------
971 Int_t index[kMaxLayer];
973 for (k=0; k<kMaxLayer; k++) index[k]=-1;
974 Int_t nc=c->GetNumberOfClusters();
975 for (k=0; k<nc; k++) {
976 Int_t idx=c->GetClusterIndex(k),nl=(idx&0xf0000000)>>28;
980 Int_t from, to, step;
981 if (xx > t->GetX()) {
982 from=0; to=kMaxLayer;
985 from=kMaxLayer-1; to=-1;
989 for (Int_t i=from; i != to; i += step) {
990 AliITSlayer &layer=fgLayers[i];
991 Double_t r=layer.GetR();
994 Double_t hI=i-0.5*step;
995 if (TMath::Abs(hI-1.5)<0.01 || TMath::Abs(hI-3.5)<0.01) {
996 Double_t rs=0.5*(fgLayers[i-step].GetR() + r);
997 Double_t d=0.0034, x0=38.6;
998 if (TMath::Abs(hI-1.5)<0.01) {rs=9.; d=0.0097; x0=42;}
999 if (!t->PropagateTo(rs,-step*d,x0)) {
1005 // remember old position [SR, GSI 18.02.2003]
1006 Double_t oldX=0., oldY=0., oldZ=0.;
1007 if (t->IsStartedTimeIntegral() && step==1) {
1008 t->GetGlobalXYZat(t->GetX(),oldX,oldY,oldZ);
1013 if (!t->GetGlobalXYZat(r,x,y,z)) {
1016 Double_t phi=TMath::ATan2(y,x);
1017 Int_t idet=layer.FindDetectorIndex(phi,z);
1021 const AliITSdetector &det=layer.GetDetector(idet);
1023 if (!t->Propagate(phi,det.GetR())) {
1026 t->SetDetectorIndex(idet);
1028 const AliITSclusterV2 *cl=0;
1029 Double_t maxchi2=kMaxChi2;
1033 const AliITSclusterV2 *c=(AliITSclusterV2 *)GetCluster(idx);
1034 if (idet != c->GetDetectorIndex()) {
1035 idet=c->GetDetectorIndex();
1036 const AliITSdetector &det=layer.GetDetector(idet);
1037 if (!t->Propagate(det.GetPhi(),det.GetR())) {
1040 t->SetDetectorIndex(idet);
1042 Double_t chi2=t->GetPredictedChi2(c);
1052 if (t->GetNumberOfClusters()>2) {
1053 Double_t dz=4*TMath::Sqrt(t->GetSigmaZ2()+kSigmaZ2[i]);
1054 Double_t dy=4*TMath::Sqrt(t->GetSigmaY2()+kSigmaY2[i]);
1055 Double_t zmin=t->GetZ() - dz;
1056 Double_t zmax=t->GetZ() + dz;
1057 Double_t ymin=t->GetY() + phi*r - dy;
1058 Double_t ymax=t->GetY() + phi*r + dy;
1059 layer.SelectClusters(zmin,zmax,ymin,ymax);
1061 const AliITSclusterV2 *c=0; Int_t ci=-1;
1062 while ((c=layer.GetNextCluster(ci))!=0) {
1063 if (idet != c->GetDetectorIndex()) continue;
1064 Double_t chi2=t->GetPredictedChi2(c);
1065 if (chi2<maxchi2) { cl=c; maxchi2=chi2; idx=ci; }
1070 if (!t->Update(cl,maxchi2,idx)) {
1073 t->SetSampledEdx(cl->GetQ(),t->GetNumberOfClusters()-1);
1078 Double_t d=layer.GetThickness(t->GetY(),t->GetZ(),x0);
1079 t->CorrectForMaterial(-step*d,x0);
1082 // track time update [SR, GSI 17.02.2003]
1083 if (t->IsStartedTimeIntegral() && step==1) {
1084 Double_t newX, newY, newZ;
1085 t->GetGlobalXYZat(t->GetX(),newX,newY,newZ);
1086 Double_t dL2 = (oldX-newX)*(oldX-newX) + (oldY-newY)*(oldY-newY) +
1087 (oldZ-newZ)*(oldZ-newZ);
1088 t->AddTimeStep(TMath::Sqrt(dL2));
1094 if (!t->PropagateTo(xx,0.,0.)) return kFALSE;
1098 void AliITStrackerV2::UseClusters(const AliKalmanTrack *t, Int_t from) const {
1099 //--------------------------------------------------------------------
1100 // This function marks clusters assigned to the track
1101 //--------------------------------------------------------------------
1102 AliTracker::UseClusters(t,from);
1104 AliITSclusterV2 *c=(AliITSclusterV2 *)GetCluster(t->GetClusterIndex(0));
1105 //if (c->GetQ()>2) c->Use();
1106 if (c->GetSigmaZ2()>0.1) c->Use();
1107 c=(AliITSclusterV2 *)GetCluster(t->GetClusterIndex(1));
1108 //if (c->GetQ()>2) c->Use();
1109 if (c->GetSigmaZ2()>0.1) c->Use();