]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDtracker.cxx
Class to generate combinations for merging
[u/mrichter/AliRoot.git] / TRD / AliTRDtracker.cxx
CommitLineData
46d29e70 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$Log$
3ab6f951 18Revision 1.12 2001/05/28 17:07:58 hristov
19Last minute changes; ExB correction in AliTRDclusterizerV1; taking into account of material in G10 TEC frames and material between TEC planes (C.Blume,S.Sedykh)
20
71d9fa7b 21Revision 1.8 2000/12/20 13:00:44 cblume
22Modifications for the HP-compiler
23
d1b06c24 24Revision 1.7 2000/12/08 16:07:02 cblume
25Update of the tracking by Sergei
26
bbf92647 27Revision 1.6 2000/11/30 17:38:08 cblume
28Changes to get in line with new STEER and EVGEN
29
1819f4bb 30Revision 1.5 2000/11/14 14:40:27 cblume
31Correction for the Sun compiler (kTRUE and kFALSE)
32
57527628 33Revision 1.4 2000/11/10 14:57:52 cblume
34Changes in the geometry constants for the DEC compiler
35
dd56b762 36Revision 1.3 2000/10/15 23:40:01 cblume
37Remove AliTRDconst
38
0e9c2ad5 39Revision 1.2 2000/10/06 16:49:46 cblume
40Made Getters const
41
46d29e70 42Revision 1.1.2.2 2000/10/04 16:34:58 cblume
43Replace include files by forward declarations
44
45Revision 1.1.2.1 2000/09/22 14:47:52 cblume
46Add the tracking code
47
48*/
bbf92647 49
1819f4bb 50#include <iostream.h>
46d29e70 51
52#include <TFile.h>
53#include <TROOT.h>
54#include <TBranch.h>
55#include <TTree.h>
56
57#include "AliRun.h"
46d29e70 58#include "AliTRD.h"
46d29e70 59#include "AliTRDgeometry.h"
60#include "AliTRDrecPoint.h"
61#include "AliTRDcluster.h"
62#include "AliTRDtrack.h"
63#include "AliTRDtrackingSector.h"
64#include "AliTRDtimeBin.h"
65
66#include "AliTRDtracker.h"
67
68ClassImp(AliTRDtracker)
69
a819a5f7 70 const Float_t AliTRDtracker::fSeedDepth = 0.5;
71 const Float_t AliTRDtracker::fSeedStep = 0.05;
72 const Float_t AliTRDtracker::fSeedGap = 0.25;
73
74 const Float_t AliTRDtracker::fMaxSeedDeltaZ12 = 40.;
75 const Float_t AliTRDtracker::fMaxSeedDeltaZ = 25.;
76 const Float_t AliTRDtracker::fMaxSeedC = 0.0052;
77 const Float_t AliTRDtracker::fMaxSeedTan = 1.2;
78 const Float_t AliTRDtracker::fMaxSeedVertexZ = 150.;
bbf92647 79
a819a5f7 80 const Double_t AliTRDtracker::fSeedErrorSY = 0.2;
81 const Double_t AliTRDtracker::fSeedErrorSY3 = 2.5;
82 const Double_t AliTRDtracker::fSeedErrorSZ = 0.1;
bbf92647 83
a819a5f7 84 const Float_t AliTRDtracker::fMinClustersInSeed = 0.7;
bbf92647 85
a819a5f7 86 const Float_t AliTRDtracker::fMinClustersInTrack = 0.5;
87 const Float_t AliTRDtracker::fSkipDepth = 0.05;
88 const Float_t AliTRDtracker::fLabelFraction = 0.5;
89 const Float_t AliTRDtracker::fWideRoad = 20.;
90
91 const Double_t AliTRDtracker::fMaxChi2 = 24.;
bbf92647 92
46d29e70 93//____________________________________________________________________
94AliTRDtracker::AliTRDtracker()
95{
96 //
97 // Default constructor
98 //
99
46d29e70 100 fEvent = 0;
46d29e70 101 fGeom = NULL;
bbf92647 102
46d29e70 103 fNclusters = 0;
104 fClusters = NULL;
105 fNseeds = 0;
106 fSeeds = NULL;
107 fNtracks = 0;
108 fTracks = NULL;
109
a819a5f7 110 fSY2corr = 0.025;
46d29e70 111}
112
113//____________________________________________________________________
114AliTRDtracker::AliTRDtracker(const Text_t* name, const Text_t* title)
115 :TNamed(name, title)
116{
46d29e70 117 fEvent = 0;
46d29e70 118 fGeom = NULL;
bbf92647 119
46d29e70 120 fNclusters = 0;
121 fClusters = new TObjArray(2000);
122 fNseeds = 0;
123 fSeeds = new TObjArray(20000);
124 fNtracks = 0;
125 fTracks = new TObjArray(10000);
126
a819a5f7 127 fSY2corr = 0.025;
46d29e70 128}
129
46d29e70 130//___________________________________________________________________
131AliTRDtracker::~AliTRDtracker()
132{
46d29e70 133 delete fClusters;
134 delete fTracks;
135 delete fSeeds;
136 delete fGeom;
137}
138
bbf92647 139//___________________________________________________________________
a819a5f7 140void AliTRDtracker::Clusters2Tracks(TH1F *hs, TH1F *hd)
bbf92647 141{
3ab6f951 142 Int_t i;
143
bbf92647 144 Int_t inner, outer;
145 Int_t fTotalNofTimeBins = fGeom->GetTimeMax() * AliTRDgeometry::Nplan();
a819a5f7 146 Int_t nSteps = (Int_t) (fSeedDepth / fSeedStep);
147 Int_t gap = (Int_t) (fTotalNofTimeBins * fSeedGap);
148 Int_t step = (Int_t) (fTotalNofTimeBins * fSeedStep);
149
150
151 // nSteps = 1;
152
153 if (!fClusters) return;
154
155 AliTRDtrackingSector fTrSec[AliTRDgeometry::kNsect];
156 SetUpSectors(fTrSec);
157
158 // make a first turn looking for seed ends in the same (n,n)
159 // and in the adjacent sectors (n,n+1)
bbf92647 160
3ab6f951 161 for(i=0; i<nSteps; i++) {
bbf92647 162 printf("step %d out of %d \n", i+1, nSteps);
a819a5f7 163 outer=fTotalNofTimeBins-1-i*step; inner=outer-gap;
164 MakeSeeds(inner,outer, fTrSec, 1, hs, hd);
165 FindTracks(fTrSec, hs, hd);
bbf92647 166 }
a819a5f7 167
168 // make a second turn looking for seed ends in next-to-adjacent
169 // sectors (n,n+2)
170
3ab6f951 171 for(i=0; i<nSteps; i++) {
a819a5f7 172 printf("step %d out of %d \n", i+1, nSteps);
173 outer=fTotalNofTimeBins-1-i*step; inner=outer-gap;
174 MakeSeeds(inner, outer, fTrSec, 2, hs, hd);
175 FindTracks(fTrSec,hs,hd);
176 }
177
bbf92647 178}
46d29e70 179
180//_____________________________________________________________________
bbf92647 181Double_t AliTRDtracker::ExpectedSigmaY2(Double_t r, Double_t tgl, Double_t pt)
46d29e70 182{
183 // Parametrised "expected" error of the cluster reconstruction in Y
184
a819a5f7 185 Double_t s = 0.08 * 0.08;
46d29e70 186 return s;
187}
188
189//_____________________________________________________________________
bbf92647 190Double_t AliTRDtracker::ExpectedSigmaZ2(Double_t r, Double_t tgl)
46d29e70 191{
192 // Parametrised "expected" error of the cluster reconstruction in Z
193
a819a5f7 194 Double_t s = 6 * 6 /12.;
46d29e70 195 return s;
196}
197
198//_____________________________________________________________________
bdbd0f7a 199Double_t f1trd(Double_t x1,Double_t y1,
a819a5f7 200 Double_t x2,Double_t y2,
201 Double_t x3,Double_t y3)
46d29e70 202{
203 // Initial approximation of the track curvature
204 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
205
206 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
207 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
208 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
209 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
210 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
211
212 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
213
214 return -xr*yr/sqrt(xr*xr+yr*yr);
215}
216
217//_____________________________________________________________________
bdbd0f7a 218Double_t f2trd(Double_t x1,Double_t y1,
a819a5f7 219 Double_t x2,Double_t y2,
220 Double_t x3,Double_t y3)
46d29e70 221{
222 // Initial approximation of the track curvature times center of curvature
223 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
224
225 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
226 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
227 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
228 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
229 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
230
231 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
232
233 return -a/(d*y1-b)*xr/sqrt(xr*xr+yr*yr);
234}
235
236//_____________________________________________________________________
bdbd0f7a 237Double_t f3trd(Double_t x1,Double_t y1,
a819a5f7 238 Double_t x2,Double_t y2,
239 Double_t z1,Double_t z2)
46d29e70 240{
241 // Initial approximation of the tangent of the track dip angle
242 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
243
244 return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
245}
246
247
248//___________________________________________________________________
249
bbf92647 250Int_t AliTRDtracker::FindProlongation(AliTRDtrack& t, AliTRDtrackingSector *sec,
a819a5f7 251 Int_t s, Int_t rf, Int_t matched_index,
252 TH1F *hs, TH1F *hd)
46d29e70 253{
254 // Starting from current position on track=t this function tries
255 // to extrapolate the track up to timeBin=rf and to confirm prolongation
256 // if a close cluster is found. *sec is a pointer to allocated
257 // array of sectors, in which the initial sector has index=s.
258
a819a5f7 259
260 // TH1F *hsame = hs;
261 // TH1F *hdiff = hd;
262
263 // Bool_t good_match;
264
bbf92647 265 const Int_t TIME_BINS_TO_SKIP=Int_t(fSkipDepth*sec->GetNtimeBins());
46d29e70 266 Int_t try_again=TIME_BINS_TO_SKIP;
267
0e9c2ad5 268 Double_t alpha=AliTRDgeometry::GetAlpha();
46d29e70 269
270 Int_t ns=Int_t(2*TMath::Pi()/alpha+0.5);
271
a819a5f7 272 Double_t x0, rho;
273
46d29e70 274 for (Int_t nr=sec->GetTimeBinNumber(t.GetX())-1; nr>=rf; nr--) {
a819a5f7 275
276 Double_t x=sec->GetX(nr);
277 Double_t ymax=x*TMath::Tan(0.5*alpha);
278
279 rho = 0.00295; x0 = 11.09; // TEC
280 if(sec->TECframe(nr,t.GetY(),t.GetZ())) {
281 rho = 1.7; x0 = 33.0; // G10 frame
282 }
283 if(TMath::Abs(x - t.GetX()) > 3) {
284 rho = 0.0559; x0 = 55.6; // radiator
285 }
286 if (!t.PropagateTo(x,x0,rho,0.139)) {
46d29e70 287 cerr<<"Can't propagate to x = "<<x<<endl;
288 return 0;
289 }
290
46d29e70 291 AliTRDtimeBin& time_bin=sec[s][nr];
bbf92647 292 Double_t sy2=ExpectedSigmaY2(t.GetX(),t.GetTgl(),t.GetPt());
293 Double_t sz2=ExpectedSigmaZ2(t.GetX(),t.GetTgl());
a819a5f7 294 Double_t road=25.*sqrt(t.GetSigmaY2() + sy2), y=t.GetY(), z=t.GetZ();
46d29e70 295
bbf92647 296 if (road>fWideRoad) {
46d29e70 297 if (t.GetNclusters() > 4) {
298 cerr<<t.GetNclusters()<<" FindProlongation: Road is too wide !\n";
299 }
300 return 0;
301 }
302
a819a5f7 303 AliTRDcluster *cl=0;
304 UInt_t index=0;
305 // Int_t ncl = 0;
306
307 Double_t max_chi2=fMaxChi2;
308
46d29e70 309 if (time_bin) {
a819a5f7 310
46d29e70 311 for (Int_t i=time_bin.Find(y-road); i<time_bin; i++) {
312 AliTRDcluster* c=(AliTRDcluster*)(time_bin[i]);
a819a5f7 313
314 // good_match = kFALSE;
315 // if((c->GetTrackIndex(0) == matched_index) ||
316 // (c->GetTrackIndex(1) == matched_index) ||
317 // (c->GetTrackIndex(2) == matched_index)) good_match = kTRUE;
318 // if(hsame) hsame->Fill(TMath::Abs(c->GetY()-y)/road);
319 // if(hdiff) hdiff->Fill(road);
320
46d29e70 321 if (c->GetY() > y+road) break;
322 if (c->IsUsed() > 0) continue;
323
a819a5f7 324 // if(good_match) hsame->Fill(TMath::Abs(c->GetZ()-z));
325 // else hdiff->Fill(TMath::Abs(c->GetZ()-z));
326
327 // if(!good_match) continue;
328
329 if((c->GetZ()-z)*(c->GetZ()-z) > 3 * 12 * sz2) continue;
46d29e70 330
331 Double_t chi2=t.GetPredictedChi2(c);
332
a819a5f7 333 // if((c->GetTrackIndex(0) == matched_index) ||
334 // (c->GetTrackIndex(1) == matched_index) ||
335 // (c->GetTrackIndex(2) == matched_index))
336 // hdiff->Fill(chi2);
337
338 // ncl++;
339
46d29e70 340 if (chi2 > max_chi2) continue;
341 max_chi2=chi2;
342 cl=c;
343 index=time_bin.GetIndex(i);
344 }
a819a5f7 345
346 if(!cl) {
347
348 for (Int_t i=time_bin.Find(y-road); i<time_bin; i++) {
349 AliTRDcluster* c=(AliTRDcluster*)(time_bin[i]);
350
351 if (c->GetY() > y+road) break;
352 if (c->IsUsed() > 0) continue;
353 if((c->GetZ()-z)*(c->GetZ()-z) > 3.25 * 12 * sz2) continue;
354
355 Double_t chi2=t.GetPredictedChi2(c);
356
357 // ncl++;
358
359 if (chi2 > max_chi2) continue;
360 max_chi2=chi2;
361 cl=c;
362 index=time_bin.GetIndex(i);
363 }
364 }
365
46d29e70 366 }
a819a5f7 367
46d29e70 368 if (cl) {
369
46d29e70 370 t.Update(cl,max_chi2,index);
371
372 try_again=TIME_BINS_TO_SKIP;
373 } else {
374 if (try_again==0) break;
375 if (y > ymax) {
a819a5f7 376 // cerr<<"y > ymax: "<<y<<" > "<<ymax<<endl;
46d29e70 377 s = (s+1) % ns;
378 if (!t.Rotate(alpha)) {
379 cerr<<"Failed to rotate, alpha = "<<alpha<<endl;
380 return 0;
381 }
382 } else if (y <-ymax) {
a819a5f7 383 // cerr<<"y < -ymax: "<<y<<" < "<<-ymax<<endl;
46d29e70 384 s = (s-1+ns) % ns;
385 if (!t.Rotate(-alpha)) {
386 cerr<<"Failed to rotate, alpha = "<<alpha<<endl;
387 return 0;
388 }
389 }
a819a5f7 390 if(!sec->TECframe(nr,y,z)) try_again--;
46d29e70 391 }
392 }
393
394 return 1;
395}
396
397
398
399//_____________________________________________________________________________
bbf92647 400void AliTRDtracker::GetEvent(const Char_t *hitfile, const Char_t *clusterfile)
46d29e70 401{
a819a5f7 402 // Opens a ROOT-file with TRD-clusters and reads the cluster-tree in
46d29e70 403
bbf92647 404 ReadClusters(fClusters, clusterfile);
405
406 // get geometry from the file with hits
407
408 TFile *fInputFile = (TFile*) gROOT->GetListOfFiles()->FindObject(hitfile);
46d29e70 409 if (!fInputFile) {
410 printf("AliTRDtracker::Open -- ");
bbf92647 411 printf("Open the ALIROOT-file %s.\n",hitfile);
a819a5f7 412 fInputFile = new TFile(hitfile,"UPDATE");
46d29e70 413 }
414 else {
415 printf("AliTRDtracker::Open -- ");
bbf92647 416 printf("%s is already open.\n",hitfile);
46d29e70 417 }
418
419 // Get AliRun object from file or create it if not on file
46d29e70 420
bbf92647 421 gAlice = (AliRun*) fInputFile->Get("gAlice");
422 if (gAlice) {
423 printf("AliTRDtracker::GetEvent -- ");
424 printf("AliRun object found on file.\n");
425 }
426 else {
427 printf("AliTRDtracker::GetEvent -- ");
428 printf("Could not find AliRun object.\n");
429 }
46d29e70 430
a819a5f7 431 /*
46d29e70 432 // Import the Trees for the event nEvent in the file
433 Int_t nparticles = gAlice->GetEvent(fEvent);
434 cerr<<"nparticles = "<<nparticles<<endl;
435
436 if (nparticles <= 0) {
437 printf("AliTRDtracker::GetEvent -- ");
438 printf("No entries in the trees for event %d.\n",fEvent);
439 }
a819a5f7 440 */
46d29e70 441
442 AliTRD *TRD = (AliTRD*) gAlice->GetDetector("TRD");
443 fGeom = TRD->GetGeometry();
444
46d29e70 445}
446
447
448//_____________________________________________________________________________
449void AliTRDtracker::SetUpSectors(AliTRDtrackingSector *sec)
450{
451 // Fills clusters into TRD tracking_sectors
452 // Note that the numbering scheme for the TRD tracking_sectors
453 // differs from that of TRD sectors
454
bbf92647 455 for (Int_t i=0; i<AliTRDgeometry::Nsect(); i++) sec[i].SetUp();
46d29e70 456
457 // Sort clusters into AliTRDtimeBin's within AliTRDtrackSector's
458
a819a5f7 459 cerr<<"SetUpSectors: sorting clusters"<<endl;
46d29e70 460
461 Int_t ncl=fClusters->GetEntriesFast();
462 UInt_t index;
463 while (ncl--) {
a819a5f7 464 printf("\r %d left ",ncl);
46d29e70 465 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(ncl);
466 Int_t detector=c->GetDetector(), local_time_bin=c->GetLocalTimeBin();
467 Int_t sector=fGeom->GetSector(detector);
468
a819a5f7 469 Int_t tracking_sector = AliTRDgeometry::kNsect - sector - 1;
46d29e70 470
471 Int_t tb=sec[sector].GetTimeBin(detector,local_time_bin);
472 index=ncl;
473 sec[tracking_sector][tb].InsertCluster(c,index);
a819a5f7 474
46d29e70 475 }
476 printf("\r\n");
477}
478
479
480//_____________________________________________________________________________
a819a5f7 481void AliTRDtracker::MakeSeeds(Int_t inner, Int_t outer,
482 AliTRDtrackingSector* fTrSec, Int_t turn,
483 TH1F *hs, TH1F *hd)
46d29e70 484{
485 // Creates track seeds using clusters in timeBins=i1,i2
486
bbf92647 487 Int_t i2 = inner, i1 = outer;
a819a5f7 488 Int_t ti[3], to[3];
489 Int_t nprim = 85600/2;
46d29e70 490
46d29e70 491
a819a5f7 492 TH1F *hsame = hs;
493 TH1F *hdiff = hd;
494 Bool_t match = false;
495 Int_t matched_index;
46d29e70 496
497 // find seeds
498
499 Double_t x[5], c[15];
dd56b762 500 Int_t max_sec=AliTRDgeometry::kNsect;
46d29e70 501
0e9c2ad5 502 Double_t alpha=AliTRDgeometry::GetAlpha();
503 Double_t shift=AliTRDgeometry::GetAlpha()/2.;
46d29e70 504 Double_t cs=cos(alpha), sn=sin(alpha);
a819a5f7 505 Double_t cs2=cos(2.*alpha), sn2=sin(2.*alpha);
46d29e70 506
507 Double_t x1 =fTrSec[0].GetX(i1);
508 Double_t xx2=fTrSec[0].GetX(i2);
509
a819a5f7 510
511 printf("\n");
512
513 if((turn != 1)&&(turn != 2)) {
514 printf("*** Error in MakeSeeds: unexpected turn = %d \n", turn);
515 return;
516 }
517
518
46d29e70 519 for (Int_t ns=0; ns<max_sec; ns++) {
520
a819a5f7 521 printf("\n MakeSeeds: sector %d \n", ns);
522
523 Int_t nl2=fTrSec[(ns-2+max_sec)%max_sec][i2];
46d29e70 524 Int_t nl=fTrSec[(ns-1+max_sec)%max_sec][i2];
525 Int_t nm=fTrSec[ns][i2];
526 Int_t nu=fTrSec[(ns+1)%max_sec][i2];
a819a5f7 527 Int_t nu2=fTrSec[(ns+2)%max_sec][i2];
46d29e70 528
529 AliTRDtimeBin& r1=fTrSec[ns][i1];
530
531 for (Int_t is=0; is < r1; is++) {
532 Double_t y1=r1[is]->GetY(), z1=r1[is]->GetZ();
a819a5f7 533 for(Int_t ii=0; ii<3; ii++) to[ii] = r1[is]->GetTrackIndex(ii);
46d29e70 534
a819a5f7 535 for (Int_t js=0; js < nl2+nl+nm+nu+nu2; js++) {
536
46d29e70 537 const AliTRDcluster *cl;
a819a5f7 538 Double_t x2, y2, z2;
539 Double_t x3=0., y3=0.;
46d29e70 540
a819a5f7 541 if (js<nl2) {
542 if(turn != 2) continue;
543 AliTRDtimeBin& r2=fTrSec[(ns-2+max_sec)%max_sec][i2];
544 cl=r2[js];
545 y2=cl->GetY(); z2=cl->GetZ();
546 for(Int_t ii=0; ii<3; ii++) ti[ii] = cl->GetTrackIndex(ii);
547
548 x2= xx2*cs2+y2*sn2;
549 y2=-xx2*sn2+y2*cs2;
550 }
551 else if (js<nl2+nl) {
552 if(turn != 1) continue;
46d29e70 553 AliTRDtimeBin& r2=fTrSec[(ns-1+max_sec)%max_sec][i2];
a819a5f7 554 cl=r2[js-nl2];
46d29e70 555 y2=cl->GetY(); z2=cl->GetZ();
a819a5f7 556 for(Int_t ii=0; ii<3; ii++) ti[ii] = cl->GetTrackIndex(ii);
46d29e70 557
a819a5f7 558 x2= xx2*cs+y2*sn;
559 y2=-xx2*sn+y2*cs;
46d29e70 560
a819a5f7 561 }
562 else if (js<nl2+nl+nm) {
563 if(turn != 1) continue;
564 AliTRDtimeBin& r2=fTrSec[ns][i2];
565 cl=r2[js-nl2-nl];
566 x2=xx2; y2=cl->GetY(); z2=cl->GetZ();
567 for(Int_t ii=0; ii<3; ii++) ti[ii] = cl->GetTrackIndex(ii);
568 }
569 else if (js<nl2+nl+nm+nu) {
570 if(turn != 1) continue;
571 AliTRDtimeBin& r2=fTrSec[(ns+1)%max_sec][i2];
572 cl=r2[js-nl2-nl-nm];
573 y2=cl->GetY(); z2=cl->GetZ();
574 for(Int_t ii=0; ii<3; ii++) ti[ii] = cl->GetTrackIndex(ii);
46d29e70 575
a819a5f7 576 x2=xx2*cs-y2*sn;
577 y2=xx2*sn+y2*cs;
46d29e70 578
a819a5f7 579 }
580 else {
581 if(turn != 2) continue;
582 AliTRDtimeBin& r2=fTrSec[(ns+2)%max_sec][i2];
583 cl=r2[js-nl2-nl-nm-nu];
584 y2=cl->GetY(); z2=cl->GetZ();
585 for(Int_t ii=0; ii<3; ii++) ti[ii] = cl->GetTrackIndex(ii);
586
587 x2=xx2*cs2-y2*sn2;
588 y2=xx2*sn2+y2*cs2;
589 }
590
46d29e70 591
a819a5f7 592 match = false;
593 matched_index = -1;
594 for (Int_t ii=0; ii<3; ii++) {
595 // cerr<<"ti["<<ii<<"] = "<<ti[ii]<<"; to["<<ii<<"] = "<<to[ii]<<endl;
596 if(ti[ii] < 0) continue;
597 if(ti[ii] >= nprim) continue;
598 for (Int_t kk=0; kk<3; kk++) {
599 if(to[kk] < 0) continue;
600 if(to[kk] >= nprim) continue;
601 if(ti[ii] == to[kk]) {
602 //cerr<<"ti["<<ii<<"] = "<<ti[ii]<<" = "<<to[kk]<<" = to["<<kk<<"]"<<endl;
603 matched_index = ti[ii];
604 match = true;
605 }
606 }
607 }
46d29e70 608
a819a5f7 609 if(TMath::Abs(z1-z2) > fMaxSeedDeltaZ12) continue;
610
611 Double_t zz=z1 - z1/x1*(x1-x2);
612
bbf92647 613 if (TMath::Abs(zz-z2)>fMaxSeedDeltaZ) continue;
46d29e70 614
615 Double_t d=(x2-x1)*(0.-y2)-(0.-x2)*(y2-y1);
616 if (d==0.) {cerr<<"TRD MakeSeeds: Straight seed !\n"; continue;}
617
618 x[0]=y1;
619 x[1]=z1;
620 x[2]=f1trd(x1,y1,x2,y2,x3,y3);
621
a819a5f7 622 if (TMath::Abs(x[2]) > fMaxSeedC) continue;
46d29e70 623
624 x[3]=f2trd(x1,y1,x2,y2,x3,y3);
625
626 if (TMath::Abs(x[2]*x1-x[3]) >= 0.99999) continue;
627
628 x[4]=f3trd(x1,y1,x2,y2,z1,z2);
629
bbf92647 630 if (TMath::Abs(x[4]) > fMaxSeedTan) continue;
46d29e70 631
632 Double_t a=asin(x[3]);
633 Double_t zv=z1 - x[4]/x[2]*(a+asin(x[2]*x1-x[3]));
a819a5f7 634
bbf92647 635 if (TMath::Abs(zv)>fMaxSeedVertexZ) continue;
46d29e70 636
bbf92647 637 Double_t sy1=r1[is]->GetSigmaY2(), sz1=r1[is]->GetSigmaZ2();
638 Double_t sy2=cl->GetSigmaY2(), sz2=cl->GetSigmaZ2();
639 Double_t sy3=fSeedErrorSY3, sy=fSeedErrorSY, sz=fSeedErrorSZ;
46d29e70 640
641 Double_t f20=(f1trd(x1,y1+sy,x2,y2,x3,y3)-x[2])/sy;
642 Double_t f22=(f1trd(x1,y1,x2,y2+sy,x3,y3)-x[2])/sy;
643 Double_t f24=(f1trd(x1,y1,x2,y2,x3,y3+sy)-x[2])/sy;
644 Double_t f30=(f2trd(x1,y1+sy,x2,y2,x3,y3)-x[3])/sy;
645 Double_t f32=(f2trd(x1,y1,x2,y2+sy,x3,y3)-x[3])/sy;
646 Double_t f34=(f2trd(x1,y1,x2,y2,x3,y3+sy)-x[3])/sy;
647 Double_t f40=(f3trd(x1,y1+sy,x2,y2,z1,z2)-x[4])/sy;
648 Double_t f41=(f3trd(x1,y1,x2,y2,z1+sz,z2)-x[4])/sz;
649 Double_t f42=(f3trd(x1,y1,x2,y2+sy,z1,z2)-x[4])/sy;
650 Double_t f43=(f3trd(x1,y1,x2,y2,z1,z2+sz)-x[4])/sz;
651
652 c[0]=sy1;
653 c[1]=0.; c[2]=sz1;
654 c[3]=f20*sy1; c[4]=0.; c[5]=f20*sy1*f20+f22*sy2*f22+f24*sy3*f24;
655 c[6]=f30*sy1; c[7]=0.; c[8]=f30*sy1*f20+f32*sy2*f22+f34*sy3*f24;
656 c[9]=f30*sy1*f30+f32*sy2*f32+f34*sy3*f34;
657 c[10]=f40*sy1; c[11]=f41*sz1; c[12]=f40*sy1*f20+f42*sy2*f22;
658 c[13]=f40*sy1*f30+f42*sy2*f32;
659 c[14]=f40*sy1*f40+f41*sz1*f41+f42*sy2*f42+f43*sz2*f43;
660
661 UInt_t index=r1.GetIndex(is);
a819a5f7 662
663 AliTRDtrack *track=new AliTRDtrack(r1[is],index,x,c,x1,ns*alpha+shift);
664
665 Int_t rc=FindProlongation(*track,fTrSec,ns,i2,matched_index,hsame,hdiff);
666
667 // if (match) hsame->Fill((Float_t) track->GetNclusters());
668 // else hdiff->Fill((Float_t) track->GetNclusters());
669 // delete track;
670 // continue;
46d29e70 671
bbf92647 672 if ((rc < 0) ||
673 (track->GetNclusters() < (i1-i2)*fMinClustersInSeed)) delete track;
46d29e70 674 else {
675 fSeeds->AddLast(track); fNseeds++;
a819a5f7 676 printf("\r found seed %d ", fNseeds);
46d29e70 677 }
678 }
679 }
680 }
681
46d29e70 682 fSeeds->Sort();
683}
684
a819a5f7 685//_____________________________________________________________________________
686void AliTRDtracker::ReadClusters(TObjArray *array, const Char_t *filename)
46d29e70 687{
a819a5f7 688 //
689 // Reads AliTRDclusters (option >= 0) or AliTRDrecPoints (option < 0)
690 // from the file. The names of the cluster tree and branches
691 // should match the ones used in AliTRDclusterizer::WriteClusters()
692 //
46d29e70 693
a819a5f7 694 TDirectory *savedir=gDirectory;
695
696 TFile *file = TFile::Open(filename);
697 if (!file->IsOpen()) {printf("Can't open file %s !\n",filename); return;}
698
699 TTree *ClusterTree = (TTree*)file->Get("ClusterTree");
46d29e70 700
a819a5f7 701 TObjArray *ClusterArray = new TObjArray(400);
702
703 ClusterTree->GetBranch("TRDcluster")->SetAddress(&ClusterArray);
704
705 Int_t nEntries = (Int_t) ClusterTree->GetEntries();
706 printf("found %d entries in %s.\n",nEntries,ClusterTree->GetName());
707
708 // Loop through all entries in the tree
709 Int_t nbytes;
710 AliTRDcluster *c = 0;
711
712 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
713
714 // Import the tree
715 nbytes += ClusterTree->GetEvent(iEntry);
716
717 // Get the number of points in the detector
718 Int_t nCluster = ClusterArray->GetEntriesFast();
719 printf("Read %d clusters from entry %d \n", nCluster, iEntry);
720
721 // Loop through all TRD digits
722 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
723 c = (AliTRDcluster*)ClusterArray->UncheckedAt(iCluster);
724 AliTRDcluster *co = new AliTRDcluster(*c);
725 co->SetSigmaY2(c->GetSigmaY2() * fSY2corr);
726 array->AddLast(co);
727 delete ClusterArray->RemoveAt(iCluster);
728 }
729 }
730
731 file->Close();
732 delete ClusterArray;
733 savedir->cd();
734
735}
736
737//___________________________________________________________________
738void AliTRDtracker::FindTracks(AliTRDtrackingSector* fTrSec, TH1F *hs, TH1F *hd)
739{
740 //
741 // Finds tracks in TRD
742 //
743
744 TH1F *hsame = hs;
745 TH1F *hdiff = hd;
46d29e70 746
747 Int_t num_of_time_bins = fTrSec[0].GetNtimeBins();
748 Int_t nseed=fSeeds->GetEntriesFast();
749
750 Int_t nSeedClusters;
751 for (Int_t i=0; i<nseed; i++) {
752 cerr<<"FindTracks: seed "<<i+1<<" out of "<<nseed<<endl;
753
bbf92647 754 AliTRDtrack& t=*((AliTRDtrack*)fSeeds->UncheckedAt(i));
46d29e70 755
756 nSeedClusters = t.GetNclusters();
bbf92647 757 Double_t alpha=t.GetAlpha();
46d29e70 758
759 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
760 if (alpha < 0. ) alpha += 2.*TMath::Pi();
dd56b762 761 Int_t ns=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::kNsect;
46d29e70 762
a819a5f7 763 Int_t label = GetTrackLabel(t);
764
765 if (FindProlongation(t,fTrSec,ns,0,label,hsame,hdiff)) {
46d29e70 766 cerr<<"No of clusters in the track = "<<t.GetNclusters()<<endl;
bbf92647 767 if (t.GetNclusters() >= Int_t(fMinClustersInTrack*num_of_time_bins)) {
46d29e70 768 Int_t label = GetTrackLabel(t);
769 t.SetLabel(label);
a819a5f7 770 t.CookdEdx();
46d29e70 771 UseClusters(t);
bbf92647 772
773 AliTRDtrack *pt = new AliTRDtrack(t);
774 fTracks->AddLast(pt); fNtracks++;
775
46d29e70 776 cerr<<"found track "<<fNtracks<<endl;
777 }
778 }
bbf92647 779 delete fSeeds->RemoveAt(i);
a819a5f7 780 fNseeds--;
46d29e70 781 }
782}
783
784//__________________________________________________________________
bbf92647 785void AliTRDtracker::UseClusters(AliTRDtrack t) {
46d29e70 786 Int_t ncl=t.GetNclusters();
787 for (Int_t i=0; i<ncl; i++) {
788 Int_t index = t.GetClusterIndex(i);
789 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
790 c->Use();
791 }
792}
793
794//__________________________________________________________________
bbf92647 795Int_t AliTRDtracker::GetTrackLabel(AliTRDtrack t) {
46d29e70 796
797 Int_t label=123456789, index, i, j;
798 Int_t ncl=t.GetNclusters();
bbf92647 799 const Int_t range = AliTRDgeometry::kNplan * fGeom->GetTimeMax();
46d29e70 800 Bool_t label_added;
801
d1b06c24 802 // Int_t s[range][2];
803 Int_t **s = new Int_t* [range];
804 for (i=0; i<range; i++) {
805 s[i] = new Int_t[2];
806 }
46d29e70 807 for (i=0; i<range; i++) {
808 s[i][0]=-1;
809 s[i][1]=0;
810 }
811
812 Int_t t0,t1,t2;
813 for (i=0; i<ncl; i++) {
814 index=t.GetClusterIndex(i);
815 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
816 t0=c->GetTrackIndex(0);
817 t1=c->GetTrackIndex(1);
818 t2=c->GetTrackIndex(2);
819 }
820
821 for (i=0; i<ncl; i++) {
822 index=t.GetClusterIndex(i);
823 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
824 for (Int_t k=0; k<3; k++) {
825 label=c->GetTrackIndex(k);
57527628 826 label_added=kFALSE; j=0;
46d29e70 827 if (label >= 0) {
828 while ( (!label_added) && ( j < range ) ) {
829 if (s[j][0]==label || s[j][1]==0) {
830 s[j][0]=label;
831 s[j][1]=s[j][1]+1;
57527628 832 label_added=kTRUE;
46d29e70 833 }
834 j++;
835 }
836 }
837 }
838 }
839
46d29e70 840 Int_t max=0;
841 label = -123456789;
842
843 for (i=0; i<range; i++) {
844 if (s[i][1]>max) {
845 max=s[i][1]; label=s[i][0];
846 }
847 }
d1b06c24 848 delete []s;
bbf92647 849 if(max > ncl*fLabelFraction) return label;
46d29e70 850 else return -1;
851}
852
853//___________________________________________________________________
854
bbf92647 855Int_t AliTRDtracker::WriteTracks(const Char_t *filename) {
46d29e70 856
857 TDirectory *savedir=gDirectory;
858
a819a5f7 859 //TFile *out=TFile::Open(filename,"RECREATE");
860 TFile *out = (TFile*) gROOT->GetListOfFiles()->FindObject(filename);
861 if (!out) {
862 printf("AliTRDtracker::Open -- ");
863 printf("Open the ALIROOT-file %s.\n",filename);
864 out = new TFile(filename,"RECREATE");
865 }
866 else {
867 printf("AliTRDtracker::Open -- ");
868 printf("%s is already open.\n",filename);
869 }
46d29e70 870
871 TTree tracktree("TreeT","Tree with TRD tracks");
872
873 AliTRDtrack *iotrack=0;
874 tracktree.Branch("tracks","AliTRDtrack",&iotrack,32000,0);
875
876 Int_t ntracks=fTracks->GetEntriesFast();
877
878 for (Int_t i=0; i<ntracks; i++) {
879 AliTRDtrack *pt=(AliTRDtrack*)fTracks->UncheckedAt(i);
880 iotrack=pt;
881 tracktree.Fill();
882 cerr<<"WriteTracks: put track "<<i<<" in the tree"<<endl;
883 }
884
885 tracktree.Write();
886 out->Close();
887
888 savedir->cd();
889
890 cerr<<"WriteTracks: done"<<endl;
a819a5f7 891 return 1;
46d29e70 892}
893