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 **************************************************************************/
18 Revision 1.2 2000/10/06 16:49:46 cblume
21 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
22 Replace include files by forward declarations
24 Revision 1.1.2.1 2000/09/22 14:47:52 cblume
37 #include "AliTRDgeometry.h"
38 #include "AliTRDrecPoint.h"
39 #include "AliTRDcluster.h"
40 #include "AliTRDtrack.h"
41 #include "AliTRDtrackingSector.h"
42 #include "AliTRDtimeBin.h"
44 #include "AliTRDtracker.h"
46 ClassImp(AliTRDtracker)
48 //____________________________________________________________________
49 AliTRDtracker::AliTRDtracker()
52 // Default constructor
68 //____________________________________________________________________
69 AliTRDtracker::AliTRDtracker(const Text_t* name, const Text_t* title)
77 fClusters = new TObjArray(2000);
79 fSeeds = new TObjArray(20000);
81 fTracks = new TObjArray(10000);
86 //___________________________________________________________________
87 AliTRDtracker::~AliTRDtracker()
100 //_____________________________________________________________________
101 static Double_t SigmaY2trd(Double_t r, Double_t tgl, Double_t pt)
103 // Parametrised "expected" error of the cluster reconstruction in Y
109 //_____________________________________________________________________
110 static Double_t SigmaZ2trd(Double_t r, Double_t tgl)
112 // Parametrised "expected" error of the cluster reconstruction in Z
114 AliTRD *TRD = (AliTRD*) gAlice->GetDetector("TRD");
115 AliTRDgeometry *fGeom;
116 fGeom = TRD->GetGeometry();
117 Double_t s, pad = fGeom->GetRowPadSize();
122 //_____________________________________________________________________
123 inline Double_t f1trd(Double_t x1,Double_t y1,
124 Double_t x2,Double_t y2,
125 Double_t x3,Double_t y3)
127 // Initial approximation of the track curvature
128 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
130 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
131 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
132 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
133 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
134 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
136 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
138 return -xr*yr/sqrt(xr*xr+yr*yr);
141 //_____________________________________________________________________
142 inline Double_t f2trd(Double_t x1,Double_t y1,
143 Double_t x2,Double_t y2,
144 Double_t x3,Double_t y3)
146 // Initial approximation of the track curvature times center of curvature
147 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
149 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
150 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
151 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
152 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
153 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
155 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
157 return -a/(d*y1-b)*xr/sqrt(xr*xr+yr*yr);
160 //_____________________________________________________________________
161 inline Double_t f3trd(Double_t x1,Double_t y1,
162 Double_t x2,Double_t y2,
163 Double_t z1,Double_t z2)
165 // Initial approximation of the tangent of the track dip angle
166 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
168 return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
172 //___________________________________________________________________
174 static Int_t FindProlongation(AliTRDseed& t, AliTRDtrackingSector *sec,
177 // Starting from current position on track=t this function tries
178 // to extrapolate the track up to timeBin=rf and to confirm prolongation
179 // if a close cluster is found. *sec is a pointer to allocated
180 // array of sectors, in which the initial sector has index=s.
182 const Int_t TIME_BINS_TO_SKIP=Int_t(0.2*sec->GetNtimeBins());
183 const Double_t MAX_CHI2=12.;
184 Int_t try_again=TIME_BINS_TO_SKIP;
186 Double_t alpha=AliTRDgeometry::GetAlpha();
188 Int_t ns=Int_t(2*TMath::Pi()/alpha+0.5);
190 for (Int_t nr=sec->GetTimeBinNumber(t.GetX())-1; nr>=rf; nr--) {
191 Double_t x=sec->GetX(nr), ymax=sec->GetMaxY(nr);
192 if (!t.PropagateTo(x)) {
193 cerr<<"Can't propagate to x = "<<x<<endl;
200 Double_t max_chi2=MAX_CHI2;
201 // const AliTRDtimeBin& time_bin=sec[s][nr];
202 AliTRDtimeBin& time_bin=sec[s][nr];
203 Double_t sy2=SigmaY2trd(t.GetX(),t.GetTgl(),t.GetPt());
204 Double_t sz2=SigmaZ2trd(t.GetX(),t.GetTgl());
205 Double_t road=5.*sqrt(t.GetSigmaY2() + sy2), y=t.GetY(), z=t.GetZ();
208 if (t.GetNclusters() > 4) {
209 cerr<<t.GetNclusters()<<" FindProlongation: Road is too wide !\n";
215 for (Int_t i=time_bin.Find(y-road); i<time_bin; i++) {
216 AliTRDcluster* c=(AliTRDcluster*)(time_bin[i]);
217 if (c->GetY() > y+road) break;
218 if (c->IsUsed() > 0) continue;
220 if((c->GetZ()-z)*(c->GetZ()-z) > 25. + sz2) continue;
222 Double_t chi2=t.GetPredictedChi2(c);
224 if (chi2 > max_chi2) continue;
227 index=time_bin.GetIndex(i);
232 // Float_t l=sec->GetPitch();
233 // t.SetSampledEdx(cl->fQ/l,Int_t(t));
235 t.Update(cl,max_chi2,index);
237 try_again=TIME_BINS_TO_SKIP;
239 if (try_again==0) break;
241 cerr<<"y > ymax: "<<y<<" > "<<ymax<<endl;
243 if (!t.Rotate(alpha)) {
244 cerr<<"Failed to rotate, alpha = "<<alpha<<endl;
247 } else if (y <-ymax) {
248 cerr<<"y < -ymax: "<<y<<" < "<<-ymax<<endl;
250 if (!t.Rotate(-alpha)) {
251 cerr<<"Failed to rotate, alpha = "<<alpha<<endl;
264 //_____________________________________________________________________________
265 void AliTRDtracker::GetEvent(const Char_t *name, Int_t nEvent)
267 // Opens a ROOT-file with TRD-clusters and reads in the cluster-tree
270 // Connect the AliRoot file containing Geometry, Kine, and Hits
271 fInputFile = (TFile*) gROOT->GetListOfFiles()->FindObject(name);
273 printf("AliTRDtracker::Open -- ");
274 printf("Open the ALIROOT-file %s.\n",name);
275 fInputFile = new TFile(name,"UPDATE");
278 printf("AliTRDtracker::Open -- ");
279 printf("%s is already open.\n",name);
282 // Get AliRun object from file or create it if not on file
284 gAlice = (AliRun*) fInputFile->Get("gAlice");
286 printf("AliTRDtracker::GetEvent -- ");
287 printf("AliRun object found on file.\n");
290 printf("AliTRDtracker::GetEvent -- ");
291 printf("Could not find AliRun object.\n");
297 // Import the Trees for the event nEvent in the file
298 Int_t nparticles = gAlice->GetEvent(fEvent);
299 cerr<<"nparticles = "<<nparticles<<endl;
301 if (nparticles <= 0) {
302 printf("AliTRDtracker::GetEvent -- ");
303 printf("No entries in the trees for event %d.\n",fEvent);
306 AliTRD *TRD = (AliTRD*) gAlice->GetDetector("TRD");
307 fGeom = TRD->GetGeometry();
310 sprintf(treeName,"TRDrecPoints%d", nEvent);
312 TTree *tree=(TTree*)fInputFile->Get(treeName);
313 TBranch *branch=tree->GetBranch("TRDrecPoints");
314 Int_t nentr = (Int_t) tree->GetEntries();
315 printf("found %d entries in %s tree.\n",nentr,treeName);
317 for (Int_t i=0; i<nentr; i++) {
318 TObjArray *ioArray = new TObjArray(400);
319 branch->SetAddress(&ioArray);
321 Int_t npoints = ioArray->GetEntriesFast();
322 printf("Read %d rec. points from entry %d \n", npoints, i);
323 for(Int_t j=0; j<npoints; j++) {
324 AliTRDrecPoint *p=(AliTRDrecPoint*)ioArray->UncheckedAt(j);
325 AliTRDcluster *c = new AliTRDcluster(p);
326 fClusters->AddLast(c);
333 //_____________________________________________________________________________
334 void AliTRDtracker::SetUpSectors(AliTRDtrackingSector *sec)
336 // Fills clusters into TRD tracking_sectors
337 // Note that the numbering scheme for the TRD tracking_sectors
338 // differs from that of TRD sectors
340 for (Int_t i=0; i<AliTRDgeometry::Nsect(); i++) sec[i].SetUp();
342 // Sort clusters into AliTRDtimeBin's within AliTRDtrackSector's
344 cerr<<"MakeSeeds: sorting clusters"<<endl;
346 Int_t ncl=fClusters->GetEntriesFast();
349 printf("\r %d left",ncl);
350 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(ncl);
351 Int_t detector=c->GetDetector(), local_time_bin=c->GetLocalTimeBin();
352 Int_t sector=fGeom->GetSector(detector);
354 Int_t tracking_sector=sector;
355 if(sector > 0) tracking_sector = AliTRDgeometry::Nsect() - sector;
357 Int_t tb=sec[sector].GetTimeBin(detector,local_time_bin);
359 sec[tracking_sector][tb].InsertCluster(c,index);
365 //_____________________________________________________________________________
366 void AliTRDtracker::MakeSeeds(Int_t inner, Int_t outer)
368 // Creates track seeds using clusters in timeBins=i1,i2
370 Int_t i2 = inner, i1=outer;
372 if (!fClusters) return;
374 AliTRDtrackingSector fTrSec[AliTRDgeometry::Nsect()];
375 SetUpSectors(fTrSec);
379 Double_t x[5], c[15];
380 Int_t max_sec=AliTRDgeometry::Nsect();
382 Double_t alpha=AliTRDgeometry::GetAlpha();
383 Double_t shift=AliTRDgeometry::GetAlpha()/2.;
384 Double_t cs=cos(alpha), sn=sin(alpha);
386 Double_t x1 =fTrSec[0].GetX(i1);
387 Double_t xx2=fTrSec[0].GetX(i2);
389 for (Int_t ns=0; ns<max_sec; ns++) {
391 Int_t nl=fTrSec[(ns-1+max_sec)%max_sec][i2];
392 Int_t nm=fTrSec[ns][i2];
393 Int_t nu=fTrSec[(ns+1)%max_sec][i2];
395 AliTRDtimeBin& r1=fTrSec[ns][i1];
397 for (Int_t is=0; is < r1; is++) {
398 Double_t y1=r1[is]->GetY(), z1=r1[is]->GetZ();
400 for (Int_t js=0; js < nl+nm+nu; js++) {
401 const AliTRDcluster *cl;
403 Double_t x3=0.,y3=0.;
406 AliTRDtimeBin& r2=fTrSec[(ns-1+max_sec)%max_sec][i2];
408 y2=cl->GetY(); z2=cl->GetZ();
415 AliTRDtimeBin& r2=fTrSec[ns][i2];
417 x2=xx2; y2=cl->GetY(); z2=cl->GetZ();
419 AliTRDtimeBin& r2=fTrSec[(ns+1)%max_sec][i2];
421 y2=cl->GetY(); z2=cl->GetZ();
428 Double_t zz=z1 - z1/x1*(x1-x2);
430 if (TMath::Abs(zz-z2)>30.) continue;
432 Double_t d=(x2-x1)*(0.-y2)-(0.-x2)*(y2-y1);
433 if (d==0.) {cerr<<"TRD MakeSeeds: Straight seed !\n"; continue;}
437 x[2]=f1trd(x1,y1,x2,y2,x3,y3);
439 if (TMath::Abs(x[2]) >= 0.01) continue;
441 x[3]=f2trd(x1,y1,x2,y2,x3,y3);
443 if (TMath::Abs(x[2]*x1-x[3]) >= 0.99999) continue;
445 x[4]=f3trd(x1,y1,x2,y2,z1,z2);
447 if (TMath::Abs(x[4]) > 1.2) continue;
449 Double_t a=asin(x[3]);
450 Double_t zv=z1 - x[4]/x[2]*(a+asin(x[2]*x1-x[3]));
451 if (TMath::Abs(zv)>200.) continue;
453 Double_t sy1=r1[is]->GetSigmaY2(), sz1=r1[is]->GetSigmaZ2()*12;
454 Double_t sy2=cl->GetSigmaY2(), sz2=cl->GetSigmaZ2()*12;
455 Double_t sy3=100*0.025, sy=0.1, sz=0.1;
457 Double_t f20=(f1trd(x1,y1+sy,x2,y2,x3,y3)-x[2])/sy;
458 Double_t f22=(f1trd(x1,y1,x2,y2+sy,x3,y3)-x[2])/sy;
459 Double_t f24=(f1trd(x1,y1,x2,y2,x3,y3+sy)-x[2])/sy;
460 Double_t f30=(f2trd(x1,y1+sy,x2,y2,x3,y3)-x[3])/sy;
461 Double_t f32=(f2trd(x1,y1,x2,y2+sy,x3,y3)-x[3])/sy;
462 Double_t f34=(f2trd(x1,y1,x2,y2,x3,y3+sy)-x[3])/sy;
463 Double_t f40=(f3trd(x1,y1+sy,x2,y2,z1,z2)-x[4])/sy;
464 Double_t f41=(f3trd(x1,y1,x2,y2,z1+sz,z2)-x[4])/sz;
465 Double_t f42=(f3trd(x1,y1,x2,y2+sy,z1,z2)-x[4])/sy;
466 Double_t f43=(f3trd(x1,y1,x2,y2,z1,z2+sz)-x[4])/sz;
470 c[3]=f20*sy1; c[4]=0.; c[5]=f20*sy1*f20+f22*sy2*f22+f24*sy3*f24;
471 c[6]=f30*sy1; c[7]=0.; c[8]=f30*sy1*f20+f32*sy2*f22+f34*sy3*f24;
472 c[9]=f30*sy1*f30+f32*sy2*f32+f34*sy3*f34;
473 c[10]=f40*sy1; c[11]=f41*sz1; c[12]=f40*sy1*f20+f42*sy2*f22;
474 c[13]=f40*sy1*f30+f42*sy2*f32;
475 c[14]=f40*sy1*f40+f41*sz1*f41+f42*sy2*f42+f43*sz2*f43;
477 UInt_t index=r1.GetIndex(is);
478 AliTRDseed *track=new AliTRDseed(index, x, c, x1, ns*alpha+shift);
480 // Float_t l=fTrSec->GetPitch();
481 // track->SetSampledEdx(r1[is]->fQ/l,0);
483 Int_t rc=FindProlongation(*track,fTrSec,ns,i2);
485 if ((rc < 0) || (track->GetNclusters() < (i1-i2)/2) ) delete track;
487 fSeeds->AddLast(track); fNseeds++;
488 cerr<<"found seed "<<fNseeds<<endl;
499 //___________________________________________________________________
500 void AliTRDtracker::FindTracks()
502 if (!fClusters) return;
504 AliTRDtrackingSector fTrSec[AliTRDgeometry::Nsect()];
505 SetUpSectors(fTrSec);
509 Int_t num_of_time_bins = fTrSec[0].GetNtimeBins();
510 Int_t nseed=fSeeds->GetEntriesFast();
513 for (Int_t i=0; i<nseed; i++) {
514 cerr<<"FindTracks: seed "<<i+1<<" out of "<<nseed<<endl;
516 AliTRDseed& t=*((AliTRDseed*)fSeeds->UncheckedAt(i));
518 nSeedClusters = t.GetNclusters();
519 Double_t alpha=AliTRDgeometry::GetAlpha();
521 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
522 if (alpha < 0. ) alpha += 2.*TMath::Pi();
523 Int_t ns=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::Nsect();
525 if (FindProlongation(t,fTrSec,ns)) {
526 cerr<<"No of clusters in the track = "<<t.GetNclusters()<<endl;
527 if ((t.GetNclusters() >= Int_t(0.3*num_of_time_bins)) &&
528 ((t.GetNclusters()-nSeedClusters)>60)) {
530 Int_t label = GetTrackLabel(t);
533 fTracks->AddLast(pt); fNtracks++;
535 cerr<<"found track "<<fNtracks<<endl;
541 //__________________________________________________________________
542 void AliTRDtracker::UseClusters(AliTRDseed t) {
543 Int_t ncl=t.GetNclusters();
544 for (Int_t i=0; i<ncl; i++) {
545 Int_t index = t.GetClusterIndex(i);
546 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
551 //__________________________________________________________________
552 Int_t AliTRDtracker::GetTrackLabel(AliTRDseed t) {
554 Int_t label=123456789, index, i, j;
555 Int_t ncl=t.GetNclusters();
556 const Int_t range=300;
560 for (i=0; i<range; i++) {
566 for (i=0; i<ncl; i++) {
567 index=t.GetClusterIndex(i);
568 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
569 t0=c->GetTrackIndex(0);
570 t1=c->GetTrackIndex(1);
571 t2=c->GetTrackIndex(2);
574 for (i=0; i<ncl; i++) {
575 index=t.GetClusterIndex(i);
576 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
577 for (Int_t k=0; k<3; k++) {
578 label=c->GetTrackIndex(k);
579 label_added=false; j=0;
581 while ( (!label_added) && ( j < range ) ) {
582 if (s[j][0]==label || s[j][1]==0) {
597 for (i=0; i<range; i++) {
599 max=s[i][1]; label=s[i][0];
602 if(max > ncl/2) return label;
606 //___________________________________________________________________
608 Int_t AliTRDtracker::WriteTracks() {
610 TDirectory *savedir=gDirectory;
612 TFile *out=TFile::Open("AliTRDtracks.root","RECREATE");
614 TTree tracktree("TreeT","Tree with TRD tracks");
616 AliTRDtrack *iotrack=0;
617 tracktree.Branch("tracks","AliTRDtrack",&iotrack,32000,0);
619 Int_t ntracks=fTracks->GetEntriesFast();
621 for (Int_t i=0; i<ntracks; i++) {
622 AliTRDtrack *pt=(AliTRDtrack*)fTracks->UncheckedAt(i);
625 cerr<<"WriteTracks: put track "<<i<<" in the tree"<<endl;
633 cerr<<"WriteTracks: done"<<endl;
639 //_____________________________________________________________________________
640 void AliTRDtracker::ReadClusters(TObjArray *array, const Char_t *filename, Int_t nEvent = 0, Int_t option = 1)
643 // Reads AliTRDclusters (option >= 0) or AliTRDrecPoints (option < 0)
644 // from the file. The names of the cluster tree and branches
645 // should match the ones used in AliTRDclusterizer::WriteClusters()
648 TDirectory *savedir=gDirectory;
650 TFile *file = TFile::Open(filename);
651 if (!file->IsOpen()) {printf("Can't open file %s !\n",filename); return;}
654 sprintf(treeName,"TRDrecPoints%d", nEvent);
656 TTree *tree=(TTree*)file->Get(treeName);
657 TBranch *branch=tree->GetBranch("TRDrecPoints");
658 Int_t nentr = (Int_t) tree->GetEntries();
659 printf("found %d entries in %s tree.\n",nentr,treeName);
661 for (Int_t i=0; i<nentr; i++) {
662 TObjArray *ioArray = new TObjArray(400);
663 branch->SetAddress(&ioArray);
665 Int_t npoints = ioArray->GetEntriesFast();
666 printf("Read %d rec. points from entry %d \n", npoints, i);
667 for(Int_t j=0; j<npoints; j++) {
668 AliTRDrecPoint *p=(AliTRDrecPoint*)ioArray->UncheckedAt(j);
669 AliTRDcluster *c = new AliTRDcluster(p);
670 if( option >= 0) array->AddLast(c);
671 else array->AddLast(p);