]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDtracker.cxx
Taking into account the edge effects (M.Ivanov)
[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
0fa7dfa7 16/* $Id$ */
bbf92647 17
029cd327 18///////////////////////////////////////////////////////////////////////////////
19// //
20// The standard TRD tracker //
21// //
22///////////////////////////////////////////////////////////////////////////////
23
a2cb5b3d 24#include <Riostream.h>
46d29e70 25#include <TFile.h>
46d29e70 26#include <TBranch.h>
5443e65e 27#include <TTree.h>
c630aafd 28#include <TObjArray.h>
46d29e70 29
46d29e70 30#include "AliTRDgeometry.h"
5443e65e 31#include "AliTRDparameter.h"
32#include "AliTRDgeometryDetail.h"
46d29e70 33#include "AliTRDcluster.h"
34#include "AliTRDtrack.h"
c630aafd 35#include "AliTRDPartID.h"
5443e65e 36#include "../TPC/AliTPCtrack.h"
46d29e70 37
38#include "AliTRDtracker.h"
39
40ClassImp(AliTRDtracker)
41
029cd327 42 const Float_t AliTRDtracker::fgkSeedDepth = 0.5;
43 const Float_t AliTRDtracker::fgkSeedStep = 0.10;
44 const Float_t AliTRDtracker::fgkSeedGap = 0.25;
5443e65e 45
029cd327 46 const Float_t AliTRDtracker::fgkMaxSeedDeltaZ12 = 40.;
47 const Float_t AliTRDtracker::fgkMaxSeedDeltaZ = 25.;
48 const Float_t AliTRDtracker::fgkMaxSeedC = 0.0052;
49 const Float_t AliTRDtracker::fgkMaxSeedTan = 1.2;
50 const Float_t AliTRDtracker::fgkMaxSeedVertexZ = 150.;
a819a5f7 51
029cd327 52 const Double_t AliTRDtracker::fgkSeedErrorSY = 0.2;
53 const Double_t AliTRDtracker::fgkSeedErrorSY3 = 2.5;
54 const Double_t AliTRDtracker::fgkSeedErrorSZ = 0.1;
bbf92647 55
029cd327 56 const Float_t AliTRDtracker::fgkMinClustersInSeed = 0.7;
bbf92647 57
029cd327 58 const Float_t AliTRDtracker::fgkMinClustersInTrack = 0.5;
59 const Float_t AliTRDtracker::fgkMinFractionOfFoundClusters = 0.8;
bbf92647 60
029cd327 61 const Float_t AliTRDtracker::fgkSkipDepth = 0.3;
62 const Float_t AliTRDtracker::fgkLabelFraction = 0.8;
63 const Float_t AliTRDtracker::fgkWideRoad = 20.;
5443e65e 64
029cd327 65 const Double_t AliTRDtracker::fgkMaxChi2 = 12.;
a819a5f7 66
029cd327 67const Int_t AliTRDtracker::fgkFirstPlane = 5;
68const Int_t AliTRDtracker::fgkLastPlane = 17;
9c9d2487 69
bbf92647 70
46d29e70 71//____________________________________________________________________
c630aafd 72AliTRDtracker::AliTRDtracker(const TFile *geomfile):AliTracker()
46d29e70 73{
5443e65e 74 //
75 // Main constructor
76 //
46d29e70 77
c630aafd 78 //Float_t fTzero = 0;
b8dc2353 79
5443e65e 80 fAddTRDseeds = kFALSE;
5443e65e 81 fGeom = NULL;
b8dc2353 82 fNoTilt = kFALSE;
5443e65e 83
84 TDirectory *savedir=gDirectory;
85 TFile *in=(TFile*)geomfile;
86 if (!in->IsOpen()) {
87 printf("AliTRDtracker::AliTRDtracker(): geometry file is not open!\n");
88 printf(" DETAIL TRD geometry and DEFAULT TRD parameter will be used\n");
89 }
90 else {
91 in->cd();
c630aafd 92// in->ls();
5443e65e 93 fGeom = (AliTRDgeometry*) in->Get("TRDgeometry");
94 fPar = (AliTRDparameter*) in->Get("TRDparameter");
c630aafd 95// fGeom->Dump();
5443e65e 96 }
46d29e70 97
5443e65e 98 if(fGeom) {
99 // fTzero = geo->GetT0();
b8dc2353 100 printf("Found geometry version %d on file \n", fGeom->IsVersion());
5443e65e 101 }
102 else {
c630aafd 103 printf("AliTRDtracker::AliTRDtracker(): can't find TRD geometry!\n");
104 printf("The DETAIL TRD geometry will be used\n");
105 fGeom = new AliTRDgeometryDetail();
106 }
107
108 if (!fPar) {
109 printf("AliTRDtracker::AliTRDtracker(): can't find TRD parameter!\n");
110 printf("The DEFAULT TRD parameter will be used\n");
5443e65e 111 fPar = new AliTRDparameter();
112 }
c630aafd 113 fPar->ReInit();
5443e65e 114
115 savedir->cd();
46d29e70 116
5443e65e 117
118 // fGeom->SetT0(fTzero);
0a29d0f1 119
46d29e70 120 fNclusters = 0;
121 fClusters = new TObjArray(2000);
122 fNseeds = 0;
5443e65e 123 fSeeds = new TObjArray(2000);
46d29e70 124 fNtracks = 0;
5443e65e 125 fTracks = new TObjArray(1000);
a819a5f7 126
029cd327 127 for(Int_t geomS = 0; geomS < kTrackingSectors; geomS++) {
128 Int_t trS = CookSectorIndex(geomS);
129 fTrSec[trS] = new AliTRDtrackingSector(fGeom, geomS, fPar);
5443e65e 130 }
a819a5f7 131
029cd327 132 Float_t tiltAngle = TMath::Abs(fPar->GetTiltingAngle());
133 if(tiltAngle < 0.1) {
b8dc2353 134 fNoTilt = kTRUE;
135 }
136
137 fSY2corr = 0.2;
138 fSZ2corr = 120.;
139
029cd327 140 if(fNoTilt && (tiltAngle > 0.1)) fSY2corr = fSY2corr + tiltAngle * 0.05;
b8dc2353 141
bbf92647 142
5443e65e 143 // calculate max gap on track
a819a5f7 144
5443e65e 145 Double_t dxAmp = (Double_t) fGeom->CamHght(); // Amplification region
146 Double_t dxDrift = (Double_t) fGeom->CdrHght(); // Drift region
a819a5f7 147
5443e65e 148 Double_t dx = (Double_t) fPar->GetTimeBinSize();
149 Int_t tbAmp = fPar->GetTimeBefore();
150 Int_t maxAmp = (Int_t) ((dxAmp+0.000001)/dx);
b3a5a838 151 if(kTRUE) maxAmp = 0; // intentional until we change the parameter class
5443e65e 152 Int_t tbDrift = fPar->GetTimeMax();
153 Int_t maxDrift = (Int_t) ((dxDrift+0.000001)/dx);
a819a5f7 154
5443e65e 155 tbDrift = TMath::Min(tbDrift,maxDrift);
156 tbAmp = TMath::Min(tbAmp,maxAmp);
46d29e70 157
5443e65e 158 fTimeBinsPerPlane = tbAmp + tbDrift;
029cd327 159 fMaxGap = (Int_t) (fTimeBinsPerPlane * fGeom->Nplan() * fgkSkipDepth);
46d29e70 160
5443e65e 161 fVocal = kFALSE;
0a29d0f1 162
9c9d2487 163
164 // Barrel Tracks [SR, 03.04.2003]
165
166 fBarrelFile = 0;
167 fBarrelTree = 0;
168 fBarrelArray = 0;
169 fBarrelTrack = 0;
170
171 savedir->cd();
5443e65e 172}
46d29e70 173
5443e65e 174//___________________________________________________________________
175AliTRDtracker::~AliTRDtracker()
46d29e70 176{
029cd327 177 //
178 // Destructor of AliTRDtracker
179 //
180
5443e65e 181 delete fClusters;
182 delete fTracks;
183 delete fSeeds;
184 delete fGeom;
185 delete fPar;
0a29d0f1 186
029cd327 187 for(Int_t geomS = 0; geomS < kTrackingSectors; geomS++) {
188 delete fTrSec[geomS];
5443e65e 189 }
190}
46d29e70 191
9c9d2487 192//_____________________________________________________________________
193
194void AliTRDtracker::SetBarrelTree(const char *mode) {
195 //
196 //
197 //
198
199 if (!IsStoringBarrel()) return;
200
201 TDirectory *sav = gDirectory;
202 if (!fBarrelFile) fBarrelFile = new TFile("AliBarrelTracks.root", "UPDATE");
203
204 char buff[40];
205 sprintf(buff, "BarrelTRD_%d_%s", GetEventNumber(), mode);
206
207 fBarrelFile->cd();
208 fBarrelTree = new TTree(buff, "Barrel TPC tracks");
209
029cd327 210 Int_t nRefs = fgkLastPlane - fgkFirstPlane + 1;
9c9d2487 211
212 if (!fBarrelArray) fBarrelArray = new TClonesArray("AliBarrelTrack", nRefs);
213 for(Int_t i=0; i<nRefs; i++) new((*fBarrelArray)[i]) AliBarrelTrack();
214
215 fBarrelTree->Branch("tracks", &fBarrelArray);
216 sav->cd();
217}
218
219//_____________________________________________________________________
220
221void AliTRDtracker::StoreBarrelTrack(AliTRDtrack *ps, Int_t refPlane, Int_t isIn) {
222 //
223 //
224 //
225
226 if (!IsStoringBarrel()) return;
227
228 static Int_t nClusters;
229 static Int_t nWrong;
230 static Double_t chi2;
231 static Int_t index;
232 static Bool_t wasLast = kTRUE;
233
234 Int_t newClusters, newWrong;
235 Double_t newChi2;
236
237 if (wasLast) {
238
239 fBarrelArray->Clear();
240 nClusters = nWrong = 0;
241 chi2 = 0.0;
242 index = 0;
243 wasLast = kFALSE;
244 }
245
246 fBarrelTrack = (AliBarrelTrack*)(*fBarrelArray)[index++];
247 ps->GetBarrelTrack(fBarrelTrack);
248
249 newClusters = ps->GetNumberOfClusters() - nClusters;
250 newWrong = ps->GetNWrong() - nWrong;
251 newChi2 = ps->GetChi2() - chi2;
252
253 nClusters = ps->GetNumberOfClusters();
254 nWrong = ps->GetNWrong();
255 chi2 = ps->GetChi2();
256
029cd327 257 if (refPlane != fgkLastPlane) {
9c9d2487 258 fBarrelTrack->SetNClusters(newClusters, newChi2);
259 fBarrelTrack->SetNWrongClusters(newWrong);
260 } else {
261 wasLast = kTRUE;
262 }
263
264 fBarrelTrack->SetRefPlane(refPlane, isIn);
265}
266
267//_____________________________________________________________________
268
269Bool_t AliTRDtracker::AdjustSector(AliTRDtrack *track) {
270 //
271 // Rotates the track when necessary
272 //
273
274 Double_t alpha = AliTRDgeometry::GetAlpha();
275 Double_t y = track->GetY();
276 Double_t ymax = track->GetX()*TMath::Tan(0.5*alpha);
277
c630aafd 278 //Int_t ns = AliTRDgeometry::kNsect;
9c9d2487 279 //Int_t s=Int_t(track->GetAlpha()/alpha)%ns;
280
281 if (y > ymax) {
282 //s = (s+1) % ns;
283 if (!track->Rotate(alpha)) return kFALSE;
284 } else if (y <-ymax) {
285 //s = (s-1+ns) % ns;
286 if (!track->Rotate(-alpha)) return kFALSE;
287 }
288
289 return kTRUE;
290}
291
46d29e70 292//_____________________________________________________________________
5443e65e 293inline Double_t f1trd(Double_t x1,Double_t y1,
a9814c09 294 Double_t x2,Double_t y2,
295 Double_t x3,Double_t y3)
46d29e70 296{
0a29d0f1 297 //
46d29e70 298 // Initial approximation of the track curvature
0a29d0f1 299 //
46d29e70 300 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
301 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
302 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
303 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
304 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
305
306 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
307
308 return -xr*yr/sqrt(xr*xr+yr*yr);
309}
310
311//_____________________________________________________________________
5443e65e 312inline Double_t f2trd(Double_t x1,Double_t y1,
a9814c09 313 Double_t x2,Double_t y2,
314 Double_t x3,Double_t y3)
46d29e70 315{
0a29d0f1 316 //
5443e65e 317 // Initial approximation of the track curvature times X coordinate
318 // of the center of curvature
0a29d0f1 319 //
46d29e70 320
321 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
322 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
323 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
324 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
325 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
326
327 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
328
329 return -a/(d*y1-b)*xr/sqrt(xr*xr+yr*yr);
330}
331
332//_____________________________________________________________________
5443e65e 333inline Double_t f3trd(Double_t x1,Double_t y1,
a9814c09 334 Double_t x2,Double_t y2,
335 Double_t z1,Double_t z2)
46d29e70 336{
0a29d0f1 337 //
46d29e70 338 // Initial approximation of the tangent of the track dip angle
0a29d0f1 339 //
46d29e70 340
341 return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
342}
343
46e2d86c 344
345AliTRDcluster * AliTRDtracker::GetCluster(AliTRDtrack * track, Int_t plane, Int_t timebin){
346 //
347 //try to find cluster in the backup list
348 //
349 AliTRDcluster * cl =0;
350 UInt_t *indexes = track->GetBackupIndexes();
351 for (UInt_t i=0;i<kMaxTimeBinIndex;i++){
352 if (indexes[i]==0) break;
353 AliTRDcluster * cli = (AliTRDcluster*)fClusters->UncheckedAt(indexes[i]);
354 if (!cli) break;
355 if (cli->GetLocalTimeBin()!=timebin) continue;
356 Int_t iplane = fGeom->GetPlane(cli->GetDetector());
357 if (iplane==plane) {
358 cl = cli;
359 break;
360 }
361 }
362 return cl;
363}
364
46d29e70 365//___________________________________________________________________
5443e65e 366Int_t AliTRDtracker::Clusters2Tracks(const TFile *inp, TFile *out)
46d29e70 367{
0a29d0f1 368 //
5443e65e 369 // Finds tracks within the TRD. File <inp> is expected to contain seeds
370 // at the outer part of the TRD. If <inp> is NULL, the seeds
371 // are found within the TRD if fAddTRDseeds is TRUE.
372 // The tracks are propagated to the innermost time bin
373 // of the TRD and stored in file <out>.
0a29d0f1 374 //
a819a5f7 375
5443e65e 376 LoadEvent();
377
378 TDirectory *savedir=gDirectory;
a819a5f7 379
5443e65e 380 char tname[100];
a819a5f7 381
5443e65e 382 if (!out->IsOpen()) {
383 cerr<<"AliTRDtracker::Clusters2Tracks(): output file is not open !\n";
384 return 1;
385 }
46d29e70 386
e24ea474 387 sprintf(tname,"seedTRDtoTPC_%d",GetEventNumber());
029cd327 388 TTree tpcTree(tname,"Tree with seeds from TRD at outer TPC pad row");
5443e65e 389 AliTPCtrack *iotrack=0;
029cd327 390 tpcTree.Branch("tracks","AliTPCtrack",&iotrack,32000,0);
5443e65e 391
e24ea474 392 sprintf(tname,"TreeT%d_TRD",GetEventNumber());
029cd327 393 TTree trdTree(tname,"TRD tracks at inner TRD time bin");
394 AliTRDtrack *iotrackTRD=0;
395 trdTree.Branch("tracks","AliTRDtrack",&iotrackTRD,32000,0);
5443e65e 396
397 Int_t timeBins = fTrSec[0]->GetNumberOfTimeBins();
029cd327 398 Float_t foundMin = fgkMinClustersInTrack * timeBins;
5443e65e 399
400 if (inp) {
401 TFile *in=(TFile*)inp;
402 if (!in->IsOpen()) {
c630aafd 403 cerr<<
404 "AliTRDtracker::Clusters2Tracks(): file with seeds is not open !\n";
5443e65e 405 cerr<<" ... going for seeds finding inside the TRD\n";
406 }
407 else {
408 in->cd();
e24ea474 409 sprintf(tname,"TRDb_%d",GetEventNumber());
5443e65e 410 TTree *seedTree=(TTree*)in->Get(tname);
411 if (!seedTree) {
a9814c09 412 cerr<<"AliTRDtracker::Clusters2Tracks(): ";
413 cerr<<"can't get a tree with track seeds !\n";
414 return 3;
5443e65e 415 }
416 AliTRDtrack *seed=new AliTRDtrack;
417 seedTree->SetBranchAddress("tracks",&seed);
418
419 Int_t n=(Int_t)seedTree->GetEntries();
420 for (Int_t i=0; i<n; i++) {
a9814c09 421 seedTree->GetEvent(i);
422 seed->ResetCovariance();
423 AliTRDtrack *tr = new AliTRDtrack(*seed,seed->GetAlpha());
424 fSeeds->AddLast(tr);
425 fNseeds++;
5443e65e 426 }
427 delete seed;
fd621f36 428 delete seedTree;
5443e65e 429 }
430 }
46d29e70 431
5443e65e 432 out->cd();
46d29e70 433
fd621f36 434
5443e65e 435 // find tracks from loaded seeds
a819a5f7 436
5443e65e 437 Int_t nseed=fSeeds->GetEntriesFast();
438 Int_t i, found = 0;
439 Int_t innerTB = fTrSec[0]->GetInnerTimeBin();
440
441 for (i=0; i<nseed; i++) {
442 AliTRDtrack *pt=(AliTRDtrack*)fSeeds->UncheckedAt(i), &t=*pt;
443 FollowProlongation(t, innerTB);
444 if (t.GetNumberOfClusters() >= foundMin) {
445 UseClusters(&t);
029cd327 446 CookLabel(pt, 1-fgkLabelFraction);
5443e65e 447 // t.CookdEdx();
448 }
029cd327 449 iotrackTRD = pt;
450 trdTree.Fill();
e24ea474 451 found++;
452// cout<<found<<'\r';
5443e65e 453
454 if(PropagateToTPC(t)) {
455 AliTPCtrack *tpc = new AliTPCtrack(*pt,pt->GetAlpha());
456 iotrack = tpc;
029cd327 457 tpcTree.Fill();
5443e65e 458 delete tpc;
459 }
460 delete fSeeds->RemoveAt(i);
461 fNseeds--;
462 }
a819a5f7 463
5443e65e 464 cout<<"Number of loaded seeds: "<<nseed<<endl;
465 cout<<"Number of found tracks from loaded seeds: "<<found<<endl;
a819a5f7 466
5443e65e 467 // after tracks from loaded seeds are found and the corresponding
468 // clusters are used, look for additional seeds from TRD
46d29e70 469
5443e65e 470 if(fAddTRDseeds) {
471 // Find tracks for the seeds in the TRD
472 Int_t timeBins = fTrSec[0]->GetNumberOfTimeBins();
473
029cd327 474 Int_t nSteps = (Int_t) (fgkSeedDepth / fgkSeedStep);
475 Int_t gap = (Int_t) (timeBins * fgkSeedGap);
476 Int_t step = (Int_t) (timeBins * fgkSeedStep);
5443e65e 477
478 // make a first turn with tight cut on initial curvature
479 for(Int_t turn = 1; turn <= 2; turn++) {
480 if(turn == 2) {
029cd327 481 nSteps = (Int_t) (fgkSeedDepth / (3*fgkSeedStep));
482 step = (Int_t) (timeBins * (3*fgkSeedStep));
5443e65e 483 }
484 for(Int_t i=0; i<nSteps; i++) {
a9814c09 485 Int_t outer=timeBins-1-i*step;
486 Int_t inner=outer-gap;
46d29e70 487
a9814c09 488 nseed=fSeeds->GetEntriesFast();
5443e65e 489
a9814c09 490 MakeSeeds(inner, outer, turn);
5443e65e 491
a9814c09 492 nseed=fSeeds->GetEntriesFast();
493 printf("\n turn %d, step %d: number of seeds for TRD inward %d\n",
494 turn, i, nseed);
495
496 for (Int_t i=0; i<nseed; i++) {
497 AliTRDtrack *pt=(AliTRDtrack*)fSeeds->UncheckedAt(i), &t=*pt;
498 FollowProlongation(t,innerTB);
499 if (t.GetNumberOfClusters() >= foundMin) {
500 UseClusters(&t);
029cd327 501 CookLabel(pt, 1-fgkLabelFraction);
a9814c09 502 t.CookdEdx();
c630aafd 503 found++;
e24ea474 504// cout<<found<<'\r';
029cd327 505 iotrackTRD = pt;
506 trdTree.Fill();
a9814c09 507 if(PropagateToTPC(t)) {
508 AliTPCtrack *tpc = new AliTPCtrack(*pt,pt->GetAlpha());
509 iotrack = tpc;
029cd327 510 tpcTree.Fill();
a9814c09 511 delete tpc;
512 }
513 }
514 delete fSeeds->RemoveAt(i);
515 fNseeds--;
516 }
46d29e70 517 }
5443e65e 518 }
519 }
029cd327 520 tpcTree.Write();
521 trdTree.Write();
5443e65e 522
523 cout<<"Total number of found tracks: "<<found<<endl;
524
525 UnloadEvent();
526
527 savedir->cd();
528
529 return 0;
530}
c630aafd 531
532//___________________________________________________________________
533Int_t AliTRDtracker::Clusters2Tracks(AliESD* event)
534{
535 //
536 // Finds tracks within the TRD. The ESD event is expected to contain seeds
537 // at the outer part of the TRD. The seeds
538 // are found within the TRD if fAddTRDseeds is TRUE.
539 // The tracks are propagated to the innermost time bin
540 // of the TRD and the ESD event is updated
541 //
542
543 Int_t timeBins = fTrSec[0]->GetNumberOfTimeBins();
029cd327 544 Float_t foundMin = fgkMinClustersInTrack * timeBins;
c630aafd 545 Int_t nseed = 0;
546 Int_t found = 0;
547 Int_t innerTB = fTrSec[0]->GetInnerTimeBin();
548
549 Int_t n = event->GetNumberOfTracks();
550 for (Int_t i=0; i<n; i++) {
551 AliESDtrack* seed=event->GetTrack(i);
552 ULong_t status=seed->GetStatus();
553 if ( (status & AliESDtrack::kTRDout ) == 0 ) continue;
554 if ( (status & AliESDtrack::kTRDin) != 0 ) continue;
555 nseed++;
556
557 AliTRDtrack* seed2 = new AliTRDtrack(*seed);
46e2d86c 558 //seed2->ResetCovariance();
c630aafd 559 AliTRDtrack *pt = new AliTRDtrack(*seed2,seed2->GetAlpha());
560 AliTRDtrack &t=*pt;
561 FollowProlongation(t, innerTB);
562 if (t.GetNumberOfClusters() >= foundMin) {
563 UseClusters(&t);
029cd327 564 CookLabel(pt, 1-fgkLabelFraction);
c630aafd 565 // t.CookdEdx();
566 }
567 found++;
568// cout<<found<<'\r';
569
570 if(PropagateToTPC(t)) {
571 seed->UpdateTrackParams(pt, AliESDtrack::kTRDin);
572 }
573 delete seed2;
574 delete pt;
575 }
576
577 cout<<"Number of loaded seeds: "<<nseed<<endl;
578 cout<<"Number of found tracks from loaded seeds: "<<found<<endl;
579
580 // after tracks from loaded seeds are found and the corresponding
581 // clusters are used, look for additional seeds from TRD
582
583 if(fAddTRDseeds) {
584 // Find tracks for the seeds in the TRD
585 Int_t timeBins = fTrSec[0]->GetNumberOfTimeBins();
586
029cd327 587 Int_t nSteps = (Int_t) (fgkSeedDepth / fgkSeedStep);
588 Int_t gap = (Int_t) (timeBins * fgkSeedGap);
589 Int_t step = (Int_t) (timeBins * fgkSeedStep);
c630aafd 590
591 // make a first turn with tight cut on initial curvature
592 for(Int_t turn = 1; turn <= 2; turn++) {
593 if(turn == 2) {
029cd327 594 nSteps = (Int_t) (fgkSeedDepth / (3*fgkSeedStep));
595 step = (Int_t) (timeBins * (3*fgkSeedStep));
c630aafd 596 }
597 for(Int_t i=0; i<nSteps; i++) {
598 Int_t outer=timeBins-1-i*step;
599 Int_t inner=outer-gap;
600
601 nseed=fSeeds->GetEntriesFast();
602
603 MakeSeeds(inner, outer, turn);
604
605 nseed=fSeeds->GetEntriesFast();
606 printf("\n turn %d, step %d: number of seeds for TRD inward %d\n",
607 turn, i, nseed);
608
609 for (Int_t i=0; i<nseed; i++) {
610 AliTRDtrack *pt=(AliTRDtrack*)fSeeds->UncheckedAt(i), &t=*pt;
611 FollowProlongation(t,innerTB);
612 if (t.GetNumberOfClusters() >= foundMin) {
613 UseClusters(&t);
029cd327 614 CookLabel(pt, 1-fgkLabelFraction);
c630aafd 615 t.CookdEdx();
616 found++;
617// cout<<found<<'\r';
618 if(PropagateToTPC(t)) {
619 AliESDtrack track;
620 track.UpdateTrackParams(pt,AliESDtrack::kTRDin);
621 event->AddTrack(&track);
622 }
623 }
624 delete fSeeds->RemoveAt(i);
625 fNseeds--;
626 }
627 }
628 }
629 }
630
631 cout<<"Total number of found tracks: "<<found<<endl;
632
633 return 0;
634}
5443e65e 635
c630aafd 636
5443e65e 637
638//_____________________________________________________________________________
639Int_t AliTRDtracker::PropagateBack(const TFile *inp, TFile *out) {
640 //
641 // Reads seeds from file <inp>. The seeds are AliTPCtrack's found and
642 // backpropagated by the TPC tracker. Each seed is first propagated
643 // to the TRD, and then its prolongation is searched in the TRD.
644 // If sufficiently long continuation of the track is found in the TRD
645 // the track is updated, otherwise it's stored as originaly defined
646 // by the TPC tracker.
647 //
648
5443e65e 649 LoadEvent();
650
651 TDirectory *savedir=gDirectory;
652
653 TFile *in=(TFile*)inp;
654
655 if (!in->IsOpen()) {
656 cerr<<"AliTRDtracker::PropagateBack(): ";
657 cerr<<"file with back propagated TPC tracks is not open !\n";
658 return 1;
659 }
660
661 if (!out->IsOpen()) {
662 cerr<<"AliTRDtracker::PropagateBack(): ";
663 cerr<<"file for back propagated TRD tracks is not open !\n";
664 return 2;
665 }
666
667 in->cd();
668 char tname[100];
e24ea474 669 sprintf(tname,"seedsTPCtoTRD_%d",GetEventNumber());
5443e65e 670 TTree *seedTree=(TTree*)in->Get(tname);
671 if (!seedTree) {
672 cerr<<"AliTRDtracker::PropagateBack(): ";
673 cerr<<"can't get a tree with seeds from TPC !\n";
674 cerr<<"check if your version of TPC tracker creates tree "<<tname<<"\n";
675 return 3;
676 }
46d29e70 677
5443e65e 678 AliTPCtrack *seed=new AliTPCtrack;
679 seedTree->SetBranchAddress("tracks",&seed);
680
681 Int_t n=(Int_t)seedTree->GetEntries();
682 for (Int_t i=0; i<n; i++) {
683 seedTree->GetEvent(i);
684 Int_t lbl = seed->GetLabel();
685 AliTRDtrack *tr = new AliTRDtrack(*seed,seed->GetAlpha());
686 tr->SetSeedLabel(lbl);
687 fSeeds->AddLast(tr);
688 fNseeds++;
689 }
a819a5f7 690
5443e65e 691 delete seed;
692 delete seedTree;
a819a5f7 693
5443e65e 694 out->cd();
a819a5f7 695
5443e65e 696 AliTPCtrack *otrack=0;
a819a5f7 697
e24ea474 698 sprintf(tname,"seedsTRDtoTOF1_%d",GetEventNumber());
5443e65e 699 TTree tofTree1(tname,"Tracks back propagated through TPC and TRD");
700 tofTree1.Branch("tracks","AliTPCtrack",&otrack,32000,0);
a819a5f7 701
e24ea474 702 sprintf(tname,"seedsTRDtoTOF2_%d",GetEventNumber());
5443e65e 703 TTree tofTree2(tname,"Tracks back propagated through TPC and TRD");
704 tofTree2.Branch("tracks","AliTPCtrack",&otrack,32000,0);
46d29e70 705
e24ea474 706 sprintf(tname,"seedsTRDtoPHOS_%d",GetEventNumber());
5443e65e 707 TTree phosTree(tname,"Tracks back propagated through TPC and TRD");
708 phosTree.Branch("tracks","AliTPCtrack",&otrack,32000,0);
a819a5f7 709
e24ea474 710 sprintf(tname,"seedsTRDtoRICH_%d",GetEventNumber());
5443e65e 711 TTree richTree(tname,"Tracks back propagated through TPC and TRD");
712 richTree.Branch("tracks","AliTPCtrack",&otrack,32000,0);
a819a5f7 713
e24ea474 714 sprintf(tname,"TRDb_%d",GetEventNumber());
5443e65e 715 TTree trdTree(tname,"Back propagated TRD tracks at outer TRD time bin");
029cd327 716 AliTRDtrack *otrackTRD=0;
717 trdTree.Branch("tracks","AliTRDtrack",&otrackTRD,32000,0);
5443e65e 718
9c9d2487 719 if (IsStoringBarrel()) SetBarrelTree("back");
720 out->cd();
46d29e70 721
9c9d2487 722 Int_t found=0;
5443e65e 723 Int_t nseed=fSeeds->GetEntriesFast();
46d29e70 724
029cd327 725 // Float_t foundMin = fgkMinClustersInTrack * fTimeBinsPerPlane * fGeom->Nplan();
9c9d2487 726 Float_t foundMin = 40;
a819a5f7 727
029cd327 728 Int_t outermostTB = fTrSec[0]->GetOuterTimeBin();
a819a5f7 729
5443e65e 730 for (Int_t i=0; i<nseed; i++) {
a819a5f7 731
5443e65e 732 AliTRDtrack *ps=(AliTRDtrack*)fSeeds->UncheckedAt(i), &s=*ps;
733 Int_t expectedClr = FollowBackProlongation(s);
9c9d2487 734
735 if (IsStoringBarrel()) {
029cd327 736 StoreBarrelTrack(ps, fgkLastPlane, kTrackBack);
9c9d2487 737 fBarrelTree->Fill();
738 }
739
5443e65e 740 Int_t foundClr = s.GetNumberOfClusters();
029cd327 741 Int_t lastTB = fTrSec[0]->GetLayerNumber(s.GetX());
a819a5f7 742
fd621f36 743 // printf("seed %d: found %d out of %d expected clusters, Min is %f\n",
a9814c09 744 // i, foundClr, expectedClr, foundMin);
a819a5f7 745
5443e65e 746 if (foundClr >= foundMin) {
a9814c09 747 if(foundClr >= 2) {
748 s.CookdEdx();
029cd327 749 CookLabel(ps, 1-fgkLabelFraction);
a9814c09 750 UseClusters(ps);
751 }
0d5b5c27 752
753 // Propagate to outer reference plane [SR, GSI, 18.02.2003]
754 ps->PropagateTo(364.8);
029cd327 755 otrackTRD=ps;
5443e65e 756 trdTree.Fill();
e24ea474 757 found++;
758// cout<<found<<'\r';
46d29e70 759 }
a819a5f7 760
029cd327 761 if(((expectedClr < 10) && (lastTB == outermostTB)) ||
5443e65e 762 ((expectedClr >= 10) &&
a9814c09 763 (((Float_t) foundClr) / ((Float_t) expectedClr) >=
029cd327 764 fgkMinFractionOfFoundClusters) && (lastTB == outermostTB))) {
5443e65e 765
029cd327 766 Double_t xTOF = 375.5;
5443e65e 767
029cd327 768 if(PropagateToOuterPlane(s,xTOF)) {
a9814c09 769 AliTPCtrack *pt = new AliTPCtrack(*ps,ps->GetAlpha());
770 otrack = pt;
771 tofTree1.Fill();
772 delete pt;
5443e65e 773
029cd327 774 xTOF = 381.5;
5443e65e 775
029cd327 776 if(PropagateToOuterPlane(s,xTOF)) {
a9814c09 777 AliTPCtrack *pt = new AliTPCtrack(*ps,ps->GetAlpha());
778 otrack = pt;
779 tofTree2.Fill();
780 delete pt;
781
029cd327 782 Double_t xPHOS = 460.;
a9814c09 783
029cd327 784 if(PropagateToOuterPlane(s,xPHOS)) {
a9814c09 785 AliTPCtrack *pt = new AliTPCtrack(*ps,ps->GetAlpha());
786 otrack = pt;
787 phosTree.Fill();
788 delete pt;
789
029cd327 790 Double_t xRICH = 490+1.267;
a9814c09 791
029cd327 792 if(PropagateToOuterPlane(s,xRICH)) {
a9814c09 793 AliTPCtrack *pt = new AliTPCtrack(*ps,ps->GetAlpha());
794 otrack = pt;
795 richTree.Fill();
796 delete pt;
797 }
798 }
799 }
5443e65e 800 }
46d29e70 801 }
802 }
5443e65e 803
9c9d2487 804
805 out->cd();
5443e65e 806 tofTree1.Write();
807 tofTree2.Write();
808 phosTree.Write();
809 richTree.Write();
810 trdTree.Write();
46d29e70 811
9c9d2487 812 if (IsStoringBarrel()) { // [SR, 03.04.2003]
813 fBarrelFile->cd();
814 fBarrelTree->Write();
815 fBarrelFile->Flush();
816 }
817
5443e65e 818 savedir->cd();
819 cerr<<"Number of seeds: "<<nseed<<endl;
820 cerr<<"Number of back propagated TRD tracks: "<<found<<endl;
46d29e70 821
5443e65e 822 UnloadEvent();
46d29e70 823
5443e65e 824 return 0;
46d29e70 825
5443e65e 826}
46d29e70 827
c630aafd 828//_____________________________________________________________________________
829Int_t AliTRDtracker::PropagateBack(AliESD* event) {
830 //
831 // Gets seeds from ESD event. The seeds are AliTPCtrack's found and
832 // backpropagated by the TPC tracker. Each seed is first propagated
833 // to the TRD, and then its prolongation is searched in the TRD.
834 // If sufficiently long continuation of the track is found in the TRD
835 // the track is updated, otherwise it's stored as originaly defined
836 // by the TPC tracker.
837 //
838
839 Int_t found=0;
840 Float_t foundMin = 40;
841
842 Int_t n = event->GetNumberOfTracks();
843 for (Int_t i=0; i<n; i++) {
844 AliESDtrack* seed=event->GetTrack(i);
845 ULong_t status=seed->GetStatus();
846 if ( (status & AliESDtrack::kTPCout ) == 0 ) continue;
847 if ( (status & AliESDtrack::kTRDout) != 0 ) continue;
848
849 Int_t lbl = seed->GetLabel();
850 AliTRDtrack *track = new AliTRDtrack(*seed);
851 track->SetSeedLabel(lbl);
852 fNseeds++;
853
854 /*Int_t expectedClr = */FollowBackProlongation(*track);
855
856 Int_t foundClr = track->GetNumberOfClusters();
857 if (foundClr >= foundMin) {
858 if(foundClr >= 2) {
859 track->CookdEdx();
029cd327 860// CookLabel(track, 1-fgkLabelFraction);
c630aafd 861 UseClusters(track);
862 }
863
864 // Propagate to outer reference plane [SR, GSI, 18.02.2003]
865// track->PropagateTo(364.8); why?
866
867 //seed->UpdateTrackParams(track, AliESDtrack::kTRDout);
868 //found++;
869 }
870
1e9bb598 871 //Propagation to the TOF (I.Belikov)
872 Double_t xtof=378.;
873 Double_t c2=track->GetC()*xtof - track->GetEta();
874 if (TMath::Abs(c2)>=0.9999999) continue;
875
876 Double_t ymax=xtof*TMath::Tan(0.5*AliTRDgeometry::GetAlpha());
877 Double_t y=track->GetYat(xtof);
878 if (y > ymax) {
879 if (!track->Rotate(AliTRDgeometry::GetAlpha())) return 1;
880 } else if (y <-ymax) {
881 if (!track->Rotate(-AliTRDgeometry::GetAlpha())) return 1;
882 }
883
884 if (track->PropagateTo(xtof)) {
c630aafd 885 seed->UpdateTrackParams(track, AliESDtrack::kTRDout);
886 found++;
887 }
1e9bb598 888 //End of propagation to the TOF
c630aafd 889
890 }
891
892 cerr<<"Number of seeds: "<<fNseeds<<endl;
893 cerr<<"Number of back propagated TRD tracks: "<<found<<endl;
894
1e9bb598 895 fSeeds->Clear(); fNseeds=0;
896
897 return 0;
898
899}
900
901//_____________________________________________________________________________
902Int_t AliTRDtracker::RefitInward(AliESD* event)
903{
904 //
905 // Refits tracks within the TRD. The ESD event is expected to contain seeds
906 // at the outer part of the TRD.
907 // The tracks are propagated to the innermost time bin
908 // of the TRD and the ESD event is updated
909 // Origin: Thomas KUHR (Thomas.Kuhr@cern.ch)
910 //
911
912 Int_t timeBins = fTrSec[0]->GetNumberOfTimeBins();
913 Float_t foundMin = fgkMinClustersInTrack * timeBins;
914 Int_t nseed = 0;
915 Int_t found = 0;
916 Int_t innerTB = fTrSec[0]->GetInnerTimeBin();
917
918 Int_t n = event->GetNumberOfTracks();
919 for (Int_t i=0; i<n; i++) {
920 AliESDtrack* seed=event->GetTrack(i);
921 ULong_t status=seed->GetStatus();
922 if ( (status & AliESDtrack::kTRDout ) == 0 ) continue;
46e2d86c 923 if ( (status & AliESDtrack::kTRDin) != 0 ) continue;
1e9bb598 924 nseed++;
925
926 AliTRDtrack* seed2 = new AliTRDtrack(*seed);
46e2d86c 927 seed2->ResetCovariance(2.);
1e9bb598 928 AliTRDtrack *pt = new AliTRDtrack(*seed2,seed2->GetAlpha());
46e2d86c 929 UInt_t * indexes2 = seed2->GetIndexes();
930 UInt_t * indexes3 = pt->GetBackupIndexes();
931 for (Int_t i=0;i<200;i++) {
932 if (indexes2[i]==0) break;
933 indexes3[i] = indexes2[i];
934 }
935 //AliTRDtrack *pt = seed2;
1e9bb598 936 AliTRDtrack &t=*pt;
937 FollowProlongation(t, innerTB);
46e2d86c 938
939 if (t.GetNumberOfClusters()<seed->GetTRDclusters(indexes3)*0.5){
940 // debug - why we dont go back?
941 AliTRDtrack *pt2 = new AliTRDtrack(*seed2,seed2->GetAlpha());
942 UInt_t * indexes2 = seed2->GetIndexes();
943 UInt_t * indexes3 = pt2->GetBackupIndexes();
944 for (Int_t i=0;i<200;i++) {
945 if (indexes2[i]==0) break;
946 indexes3[i] = indexes2[i];
947 }
948 FollowProlongation(*pt2, innerTB);
949 }
950
1e9bb598 951 if (t.GetNumberOfClusters() >= foundMin) {
46e2d86c 952 // UseClusters(&t);
953 //CookLabel(pt, 1-fgkLabelFraction);
1e9bb598 954 // t.CookdEdx();
955 }
956 found++;
957// cout<<found<<'\r';
958
959 if(PropagateToTPC(t)) {
0fa7dfa7 960 seed->UpdateTrackParams(pt, AliESDtrack::kTRDrefit);
1e9bb598 961 }
962 delete seed2;
963 delete pt;
964 }
965
966 cout<<"Number of loaded seeds: "<<nseed<<endl;
967 cout<<"Number of found tracks from loaded seeds: "<<found<<endl;
968
c630aafd 969 return 0;
970
971}
972
bbf92647 973
5443e65e 974//---------------------------------------------------------------------------
975Int_t AliTRDtracker::FollowProlongation(AliTRDtrack& t, Int_t rf)
976{
977 // Starting from current position on track=t this function tries
978 // to extrapolate the track up to timeBin=0 and to confirm prolongation
979 // if a close cluster is found. Returns the number of clusters
980 // expected to be found in sensitive layers
bbf92647 981
5443e65e 982 Float_t wIndex, wTB, wChi2;
983 Float_t wYrt, wYclosest, wYcorrect, wYwindow;
984 Float_t wZrt, wZclosest, wZcorrect, wZwindow;
985 Float_t wPx, wPy, wPz, wC;
029cd327 986 Double_t px, py, pz;
5443e65e 987 Float_t wSigmaC2, wSigmaTgl2, wSigmaY2, wSigmaZ2;
46d29e70 988
5443e65e 989 Int_t trackIndex = t.GetLabel();
46d29e70 990
5443e65e 991 Int_t ns=Int_t(2*TMath::Pi()/AliTRDgeometry::GetAlpha()+0.5);
46d29e70 992
029cd327 993 Int_t tryAgain=fMaxGap;
46d29e70 994
5443e65e 995 Double_t alpha=t.GetAlpha();
c630aafd 996 alpha = TVector2::Phi_0_2pi(alpha);
46d29e70 997
5443e65e 998 Int_t s=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::kNsect;
029cd327 999 Double_t radLength, rho, x, dx, y, ymax, z;
46d29e70 1000
5443e65e 1001 Int_t expectedNumberOfClusters = 0;
1002 Bool_t lookForCluster;
46d29e70 1003
5443e65e 1004 alpha=AliTRDgeometry::GetAlpha(); // note: change in meaning
46d29e70 1005
5443e65e 1006
1007 for (Int_t nr=fTrSec[0]->GetLayerNumber(t.GetX()); nr>rf; nr--) {
1008
1009 y = t.GetY(); z = t.GetZ();
1010
1011 // first propagate to the inner surface of the current time bin
029cd327 1012 fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
5443e65e 1013 x = fTrSec[s]->GetLayer(nr)->GetX()-dx/2; y = t.GetY(); z = t.GetZ();
029cd327 1014 if(!t.PropagateTo(x,radLength,rho)) break;
5443e65e 1015 y = t.GetY();
1016 ymax = x*TMath::Tan(0.5*alpha);
1017 if (y > ymax) {
1018 s = (s+1) % ns;
1019 if (!t.Rotate(alpha)) break;
029cd327 1020 if(!t.PropagateTo(x,radLength,rho)) break;
5443e65e 1021 } else if (y <-ymax) {
1022 s = (s-1+ns) % ns;
1023 if (!t.Rotate(-alpha)) break;
029cd327 1024 if(!t.PropagateTo(x,radLength,rho)) break;
5443e65e 1025 }
46d29e70 1026
5443e65e 1027 y = t.GetY(); z = t.GetZ();
1028
1029 // now propagate to the middle plane of the next time bin
029cd327 1030 fTrSec[s]->GetLayer(nr-1)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
5443e65e 1031 x = fTrSec[s]->GetLayer(nr-1)->GetX(); y = t.GetY(); z = t.GetZ();
029cd327 1032 if(!t.PropagateTo(x,radLength,rho)) break;
5443e65e 1033 y = t.GetY();
1034 ymax = x*TMath::Tan(0.5*alpha);
1035 if (y > ymax) {
1036 s = (s+1) % ns;
1037 if (!t.Rotate(alpha)) break;
029cd327 1038 if(!t.PropagateTo(x,radLength,rho)) break;
5443e65e 1039 } else if (y <-ymax) {
1040 s = (s-1+ns) % ns;
1041 if (!t.Rotate(-alpha)) break;
029cd327 1042 if(!t.PropagateTo(x,radLength,rho)) break;
5443e65e 1043 }
46d29e70 1044
46d29e70 1045
5443e65e 1046 if(lookForCluster) {
a819a5f7 1047
5443e65e 1048 expectedNumberOfClusters++;
5443e65e 1049 wIndex = (Float_t) t.GetLabel();
1050 wTB = nr;
46d29e70 1051
029cd327 1052 AliTRDpropagationLayer& timeBin=*(fTrSec[s]->GetLayer(nr-1));
46d29e70 1053
5443e65e 1054 Double_t sy2=ExpectedSigmaY2(x,t.GetTgl(),t.GetPt());
5443e65e 1055 Double_t sz2=ExpectedSigmaZ2(x,t.GetTgl());
46d29e70 1056
5443e65e 1057 Double_t road;
1058 if((t.GetSigmaY2() + sy2) > 0) road=10.*sqrt(t.GetSigmaY2() + sy2);
1059 else return expectedNumberOfClusters;
1060
1061 wYrt = (Float_t) y;
1062 wZrt = (Float_t) z;
1063 wYwindow = (Float_t) road;
029cd327 1064 t.GetPxPyPz(px,py,pz);
1065 wPx = (Float_t) px;
1066 wPy = (Float_t) py;
1067 wPz = (Float_t) pz;
5443e65e 1068 wC = (Float_t) t.GetC();
1069 wSigmaC2 = (Float_t) t.GetSigmaC2();
1070 wSigmaTgl2 = (Float_t) t.GetSigmaTgl2();
1071 wSigmaY2 = (Float_t) t.GetSigmaY2();
1072 wSigmaZ2 = (Float_t) t.GetSigmaZ2();
1073 wChi2 = -1;
1074
5443e65e 1075
1076 AliTRDcluster *cl=0;
1077 UInt_t index=0;
1078
029cd327 1079 Double_t maxChi2=fgkMaxChi2;
5443e65e 1080
1081 wYclosest = 12345678;
1082 wYcorrect = 12345678;
1083 wZclosest = 12345678;
1084 wZcorrect = 12345678;
1085 wZwindow = TMath::Sqrt(2.25 * 12 * sz2);
1086
1087 // Find the closest correct cluster for debugging purposes
029cd327 1088 if (timeBin) {
a9814c09 1089 Float_t minDY = 1000000;
029cd327 1090 for (Int_t i=0; i<timeBin; i++) {
1091 AliTRDcluster* c=(AliTRDcluster*)(timeBin[i]);
a9814c09 1092 if((c->GetLabel(0) != trackIndex) &&
1093 (c->GetLabel(1) != trackIndex) &&
1094 (c->GetLabel(2) != trackIndex)) continue;
1095 if(TMath::Abs(c->GetY() - y) > minDY) continue;
1096 minDY = TMath::Abs(c->GetY() - y);
1097 wYcorrect = c->GetY();
1098 wZcorrect = c->GetZ();
1099
1100 Double_t h01 = GetTiltFactor(c);
1101 wChi2 = t.GetPredictedChi2(c, h01);
1102 }
5443e65e 1103 }
46d29e70 1104
5443e65e 1105 // Now go for the real cluster search
a819a5f7 1106
029cd327 1107 if (timeBin) {
46e2d86c 1108 //
1109 //find cluster in history
1110 cl =0;
1111
1112 AliTRDcluster * cl0 = timeBin[0];
1113 if (!cl0) {
1114 continue;
1115 }
1116 Int_t plane = fGeom->GetPlane(cl0->GetDetector());
1117 Int_t timebin = cl0->GetLocalTimeBin();
1118 AliTRDcluster * cl2= GetCluster(&t,plane, timebin);
1119 if (cl2) cl =cl2;
1120
1121 if ((!cl) && road>fgkWideRoad) {
1122 //if (t.GetNumberOfClusters()>4)
1123 // cerr<<t.GetNumberOfClusters()
1124 // <<"FindProlongation warning: Too broad road !\n";
1125 continue;
1126 }
1127
1128
1129 if(!cl){
1130
1131 for (Int_t i=timeBin.Find(y-road); i<timeBin; i++) {
1132 AliTRDcluster* c=(AliTRDcluster*)(timeBin[i]);
1133 if (c->GetY() > y+road) break;
1134 if (c->IsUsed() > 0) continue;
1135 if((c->GetZ()-z)*(c->GetZ()-z) > 3 * sz2) continue;
1136
1137 Double_t h01 = GetTiltFactor(c);
1138 Double_t chi2=t.GetPredictedChi2(c,h01);
1139
1140 if (chi2 > maxChi2) continue;
1141 maxChi2=chi2;
1142 cl=c;
1143 index=timeBin.GetIndex(i);
1144 }
1145 }
a9814c09 1146
1147 if(!cl) {
1148
029cd327 1149 for (Int_t i=timeBin.Find(y-road); i<timeBin; i++) {
1150 AliTRDcluster* c=(AliTRDcluster*)(timeBin[i]);
a9814c09 1151
1152 if (c->GetY() > y+road) break;
1153 if (c->IsUsed() > 0) continue;
1154 if((c->GetZ()-z)*(c->GetZ()-z) > 12 * sz2) continue;
1155
1156 Double_t h01 = GetTiltFactor(c);
1157 Double_t chi2=t.GetPredictedChi2(c, h01);
1158
029cd327 1159 if (chi2 > maxChi2) continue;
1160 maxChi2=chi2;
a9814c09 1161 cl=c;
029cd327 1162 index=timeBin.GetIndex(i);
a9814c09 1163 }
1164 }
a9814c09 1165 if (cl) {
1166 wYclosest = cl->GetY();
1167 wZclosest = cl->GetZ();
1168 Double_t h01 = GetTiltFactor(cl);
1169
1170 t.SetSampledEdx(cl->GetQ()/dx,t.GetNumberOfClusters());
46e2d86c 1171 //printf("Track position\t%f\t%f\t%f\n",t.GetX(),t.GetY(),t.GetZ());
1172 //printf("Cluster position\t%d\t%f\t%f\n",cl->GetLocalTimeBin(),cl->GetY(),cl->GetZ());
1173
1174
1175 if(!t.UpdateMI(cl,maxChi2,index,h01)) {
029cd327 1176 if(!tryAgain--) return 0;
a9814c09 1177 }
029cd327 1178 else tryAgain=fMaxGap;
a9814c09 1179 }
1180 else {
029cd327 1181 if (tryAgain==0) break;
1182 tryAgain--;
a9814c09 1183 }
1184
1185 /*
1186 if((((Int_t) wTB)%15 == 0) || (((Int_t) wTB)%15 == 14)) {
1187
1188 printf(" %f", wIndex); //1
1189 printf(" %f", wTB); //2
1190 printf(" %f", wYrt); //3
1191 printf(" %f", wYclosest); //4
1192 printf(" %f", wYcorrect); //5
1193 printf(" %f", wYwindow); //6
1194 printf(" %f", wZrt); //7
1195 printf(" %f", wZclosest); //8
1196 printf(" %f", wZcorrect); //9
1197 printf(" %f", wZwindow); //10
1198 printf(" %f", wPx); //11
1199 printf(" %f", wPy); //12
1200 printf(" %f", wPz); //13
1201 printf(" %f", wSigmaC2*1000000); //14
1202 printf(" %f", wSigmaTgl2*1000); //15
1203 printf(" %f", wSigmaY2); //16
1204 // printf(" %f", wSigmaZ2); //17
1205 printf(" %f", wChi2); //17
1206 printf(" %f", wC); //18
1207 printf("\n");
1208 }
1209 */
5443e65e 1210 }
1211 }
1212 }
1213 return expectedNumberOfClusters;
1214
1215
1216}
a819a5f7 1217
5443e65e 1218//___________________________________________________________________
46d29e70 1219
5443e65e 1220Int_t AliTRDtracker::FollowBackProlongation(AliTRDtrack& t)
1221{
1222 // Starting from current radial position of track <t> this function
1223 // extrapolates the track up to outer timebin and in the sensitive
1224 // layers confirms prolongation if a close cluster is found.
1225 // Returns the number of clusters expected to be found in sensitive layers
46d29e70 1226
5443e65e 1227 Float_t wIndex, wTB, wChi2;
1228 Float_t wYrt, wYclosest, wYcorrect, wYwindow;
1229 Float_t wZrt, wZclosest, wZcorrect, wZwindow;
1230 Float_t wPx, wPy, wPz, wC;
029cd327 1231 Double_t px, py, pz;
5443e65e 1232 Float_t wSigmaC2, wSigmaTgl2, wSigmaY2, wSigmaZ2;
46d29e70 1233
5443e65e 1234 Int_t trackIndex = t.GetLabel();
029cd327 1235 Int_t tryAgain=fMaxGap;
46d29e70 1236
5443e65e 1237 Double_t alpha=t.GetAlpha();
9c9d2487 1238 TVector2::Phi_0_2pi(alpha);
46d29e70 1239
9c9d2487 1240 Int_t s;
46d29e70 1241
5443e65e 1242 Int_t outerTB = fTrSec[0]->GetOuterTimeBin();
029cd327 1243 Double_t radLength, rho, x, dx, y, ymax = 0, z;
5443e65e 1244 Bool_t lookForCluster;
a819a5f7 1245
5443e65e 1246 Int_t expectedNumberOfClusters = 0;
1247 x = t.GetX();
46d29e70 1248
5443e65e 1249 alpha=AliTRDgeometry::GetAlpha(); // note: change in meaning
46d29e70 1250
029cd327 1251 Int_t nRefPlane = fgkFirstPlane;
9c9d2487 1252 Bool_t isNewLayer = kFALSE;
46d29e70 1253
9c9d2487 1254 Double_t chi2;
1255 Double_t minDY;
46d29e70 1256
9c9d2487 1257 for (Int_t nr=fTrSec[0]->GetLayerNumber(t.GetX()); nr<outerTB+1; nr++) {
1258
1259 y = t.GetY();
1260 z = t.GetZ();
46d29e70 1261
5443e65e 1262 // first propagate to the outer surface of the current time bin
46d29e70 1263
9c9d2487 1264 s = t.GetSector();
029cd327 1265 fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
9c9d2487 1266 x = fTrSec[s]->GetLayer(nr)->GetX()+dx/2;
1267 y = t.GetY();
1268 z = t.GetZ();
46d29e70 1269
029cd327 1270 if(!t.PropagateTo(x,radLength,rho)) break;
9c9d2487 1271 if (!AdjustSector(&t)) break;
1272 s = t.GetSector();
029cd327 1273 if (!t.PropagateTo(x,radLength,rho)) break;
46d29e70 1274
5443e65e 1275 y = t.GetY();
9c9d2487 1276 z = t.GetZ();
a819a5f7 1277
9c9d2487 1278 // Barrel Tracks [SR, 04.04.2003]
46d29e70 1279
9c9d2487 1280 s = t.GetSector();
1281 if (fTrSec[s]->GetLayer(nr)->IsSensitive() !=
1282 fTrSec[s]->GetLayer(nr+1)->IsSensitive() ) {
46d29e70 1283
c630aafd 1284// if (IsStoringBarrel()) StoreBarrelTrack(&t, nRefPlane++, kTrackBack);
9c9d2487 1285 }
46d29e70 1286
9c9d2487 1287 if (fTrSec[s]->GetLayer(nr-1)->IsSensitive() &&
1288 ! fTrSec[s]->GetLayer(nr)->IsSensitive()) {
1289 isNewLayer = kTRUE;
1290 } else {isNewLayer = kFALSE;}
46d29e70 1291
5443e65e 1292 y = t.GetY();
9c9d2487 1293 z = t.GetZ();
a819a5f7 1294
9c9d2487 1295 // now propagate to the middle plane of the next time bin
029cd327 1296 fTrSec[s]->GetLayer(nr+1)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
5443e65e 1297
9c9d2487 1298 x = fTrSec[s]->GetLayer(nr+1)->GetX();
029cd327 1299 if(!t.PropagateTo(x,radLength,rho)) break;
9c9d2487 1300 if (!AdjustSector(&t)) break;
1301 s = t.GetSector();
029cd327 1302 if(!t.PropagateTo(x,radLength,rho)) break;
46d29e70 1303
9c9d2487 1304 y = t.GetY();
1305 z = t.GetZ();
1306
1307 if(fVocal) printf("nr+1=%d, x %f, z %f, y %f, ymax %f\n",nr+1,x,z,y,ymax);
5443e65e 1308 // printf("label %d, pl %d, lookForCluster %d \n",
a9814c09 1309 // trackIndex, nr+1, lookForCluster);
5443e65e 1310
1311 if(lookForCluster) {
1312 expectedNumberOfClusters++;
1313
1314 wIndex = (Float_t) t.GetLabel();
1315 wTB = fTrSec[s]->GetLayer(nr+1)->GetTimeBinIndex();
1316
029cd327 1317 AliTRDpropagationLayer& timeBin=*(fTrSec[s]->GetLayer(nr+1));
5443e65e 1318 Double_t sy2=ExpectedSigmaY2(t.GetX(),t.GetTgl(),t.GetPt());
1319 Double_t sz2=ExpectedSigmaZ2(t.GetX(),t.GetTgl());
1320 if((t.GetSigmaY2() + sy2) < 0) break;
1321 Double_t road = 10.*sqrt(t.GetSigmaY2() + sy2);
1322 Double_t y=t.GetY(), z=t.GetZ();
1323
1324 wYrt = (Float_t) y;
1325 wZrt = (Float_t) z;
1326 wYwindow = (Float_t) road;
029cd327 1327 t.GetPxPyPz(px,py,pz);
1328 wPx = (Float_t) px;
1329 wPy = (Float_t) py;
1330 wPz = (Float_t) pz;
5443e65e 1331 wC = (Float_t) t.GetC();
1332 wSigmaC2 = (Float_t) t.GetSigmaC2();
1333 wSigmaTgl2 = (Float_t) t.GetSigmaTgl2();
1334 wSigmaY2 = (Float_t) t.GetSigmaY2();
1335 wSigmaZ2 = (Float_t) t.GetSigmaZ2();
1336 wChi2 = -1;
1337
029cd327 1338 if (road>fgkWideRoad) {
a9814c09 1339 if (t.GetNumberOfClusters()>4)
1340 cerr<<t.GetNumberOfClusters()
1341 <<"FindProlongation warning: Too broad road !\n";
1342 return 0;
5443e65e 1343 }
1344
1345 AliTRDcluster *cl=0;
1346 UInt_t index=0;
1347
029cd327 1348 Double_t maxChi2=fgkMaxChi2;
5443e65e 1349
9c9d2487 1350 if (isNewLayer) {
1351 road = 3 * road;
1352 //sz2 = 3 * sz2;
029cd327 1353 maxChi2 = 10 * fgkMaxChi2;
9c9d2487 1354 }
1355
029cd327 1356 if (nRefPlane == fgkFirstPlane) maxChi2 = 20 * fgkMaxChi2;
1357 if (nRefPlane == fgkFirstPlane+2) maxChi2 = 15 * fgkMaxChi2;
1358 if (t.GetNRotate() > 0) maxChi2 = 3 * maxChi2;
9c9d2487 1359
1360
5443e65e 1361 wYclosest = 12345678;
1362 wYcorrect = 12345678;
1363 wZclosest = 12345678;
1364 wZcorrect = 12345678;
1365 wZwindow = TMath::Sqrt(2.25 * 12 * sz2);
1366
1367 // Find the closest correct cluster for debugging purposes
029cd327 1368 if (timeBin) {
9c9d2487 1369 minDY = 1000000;
029cd327 1370 for (Int_t i=0; i<timeBin; i++) {
1371 AliTRDcluster* c=(AliTRDcluster*)(timeBin[i]);
a9814c09 1372 if((c->GetLabel(0) != trackIndex) &&
1373 (c->GetLabel(1) != trackIndex) &&
1374 (c->GetLabel(2) != trackIndex)) continue;
1375 if(TMath::Abs(c->GetY() - y) > minDY) continue;
9c9d2487 1376 //minDY = TMath::Abs(c->GetY() - y);
1377 minDY = c->GetY() - y;
a9814c09 1378 wYcorrect = c->GetY();
1379 wZcorrect = c->GetZ();
1380
1381 Double_t h01 = GetTiltFactor(c);
1382 wChi2 = t.GetPredictedChi2(c, h01);
1383 }
5443e65e 1384 }
46d29e70 1385
5443e65e 1386 // Now go for the real cluster search
46d29e70 1387
029cd327 1388 if (timeBin) {
5443e65e 1389
029cd327 1390 for (Int_t i=timeBin.Find(y-road); i<timeBin; i++) {
1391 AliTRDcluster* c=(AliTRDcluster*)(timeBin[i]);
a9814c09 1392 if (c->GetY() > y+road) break;
9c9d2487 1393 if (c->IsUsed() > 0) continue;
a9814c09 1394 if((c->GetZ()-z)*(c->GetZ()-z) > 3 * sz2) continue;
1395
1396 Double_t h01 = GetTiltFactor(c);
9c9d2487 1397 chi2=t.GetPredictedChi2(c,h01);
a9814c09 1398
029cd327 1399 if (chi2 > maxChi2) continue;
1400 maxChi2=chi2;
a9814c09 1401 cl=c;
029cd327 1402 index=timeBin.GetIndex(i);
9c9d2487 1403
1404 //check is correct
1405 if((c->GetLabel(0) != trackIndex) &&
1406 (c->GetLabel(1) != trackIndex) &&
1407 (c->GetLabel(2) != trackIndex)) t.AddNWrong();
a9814c09 1408 }
5443e65e 1409
a9814c09 1410 if(!cl) {
1411
029cd327 1412 for (Int_t i=timeBin.Find(y-road); i<timeBin; i++) {
1413 AliTRDcluster* c=(AliTRDcluster*)(timeBin[i]);
a9814c09 1414
1415 if (c->GetY() > y+road) break;
9c9d2487 1416 if (c->IsUsed() > 0) continue;
a9814c09 1417 if((c->GetZ()-z)*(c->GetZ()-z) > 2.25 * 12 * sz2) continue;
1418
1419 Double_t h01 = GetTiltFactor(c);
9c9d2487 1420 chi2=t.GetPredictedChi2(c,h01);
a9814c09 1421
029cd327 1422 if (chi2 > maxChi2) continue;
1423 maxChi2=chi2;
a9814c09 1424 cl=c;
029cd327 1425 index=timeBin.GetIndex(i);
a9814c09 1426 }
1427 }
1428
1429 if (cl) {
1430 wYclosest = cl->GetY();
1431 wZclosest = cl->GetZ();
1432
1433 t.SetSampledEdx(cl->GetQ()/dx,t.GetNumberOfClusters());
1434 Double_t h01 = GetTiltFactor(cl);
46e2d86c 1435 if(!t.UpdateMI(cl,maxChi2,index,h01)) {
029cd327 1436 if(!tryAgain--) return 0;
a9814c09 1437 }
029cd327 1438 else tryAgain=fMaxGap;
a9814c09 1439 }
1440 else {
029cd327 1441 if (tryAgain==0) break;
1442 tryAgain--;
9c9d2487 1443
1444 //if (minDY < 1000000 && isNewLayer)
1445 //cout << "\t" << nRefPlane << "\t" << "\t" << t.GetNRotate() << "\t" <<
029cd327 1446 // road << "\t" << minDY << "\t" << chi2 << "\t" << wChi2 << "\t" << maxChi2 << endl;
9c9d2487 1447
a9814c09 1448 }
1449
9c9d2487 1450 isNewLayer = kFALSE;
1451
a9814c09 1452 /*
1453 if((((Int_t) wTB)%15 == 0) || (((Int_t) wTB)%15 == 14)) {
1454
1455 printf(" %f", wIndex); //1
1456 printf(" %f", wTB); //2
1457 printf(" %f", wYrt); //3
1458 printf(" %f", wYclosest); //4
1459 printf(" %f", wYcorrect); //5
1460 printf(" %f", wYwindow); //6
1461 printf(" %f", wZrt); //7
1462 printf(" %f", wZclosest); //8
1463 printf(" %f", wZcorrect); //9
1464 printf(" %f", wZwindow); //10
1465 printf(" %f", wPx); //11
1466 printf(" %f", wPy); //12
1467 printf(" %f", wPz); //13
1468 printf(" %f", wSigmaC2*1000000); //14
1469 printf(" %f", wSigmaTgl2*1000); //15
1470 printf(" %f", wSigmaY2); //16
1471 // printf(" %f", wSigmaZ2); //17
1472 printf(" %f", wChi2); //17
1473 printf(" %f", wC); //18
1474 printf("\n");
1475 }
1476 */
5443e65e 1477 }
1478 }
1479 }
1480 return expectedNumberOfClusters;
9c9d2487 1481
1482
5443e65e 1483}
1484
1e9bb598 1485//---------------------------------------------------------------------------
1486Int_t AliTRDtracker::Refit(AliTRDtrack& t, Int_t rf)
1487{
1488 // Starting from current position on track=t this function tries
1489 // to extrapolate the track up to timeBin=0 and to reuse already
1490 // assigned clusters. Returns the number of clusters
1491 // expected to be found in sensitive layers
1492 // get indices of assigned clusters for each layer
1493 // Origin: Thomas KUHR (Thomas.Kuhr@cern.ch)
1494
1495 Int_t iCluster[90];
1496 for (Int_t i = 0; i < 90; i++) iCluster[i] = 0;
1497 for (Int_t i = 0; i < t.GetNumberOfClusters(); i++) {
1498 Int_t index = t.GetClusterIndex(i);
1499 AliTRDcluster *cl=(AliTRDcluster*) GetCluster(index);
1500 if (!cl) continue;
1501 Int_t detector=cl->GetDetector();
1502 Int_t localTimeBin=cl->GetLocalTimeBin();
1503 Int_t sector=fGeom->GetSector(detector);
1504 Int_t plane=fGeom->GetPlane(detector);
1505
1506 Int_t trackingSector = CookSectorIndex(sector);
1507
1508 Int_t gtb = fTrSec[trackingSector]->CookTimeBinIndex(plane,localTimeBin);
1509 if(gtb < 0) continue;
1510 Int_t layer = fTrSec[trackingSector]->GetLayerNumber(gtb);
1511 iCluster[layer] = index;
1512 }
1513 t.ResetClusters();
1514
1515 Int_t ns=Int_t(2*TMath::Pi()/AliTRDgeometry::GetAlpha()+0.5);
1516
1517 Double_t alpha=t.GetAlpha();
1518 alpha = TVector2::Phi_0_2pi(alpha);
1519
1520 Int_t s=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::kNsect;
1521 Double_t radLength, rho, x, dx, y, ymax, z;
1522
1523 Int_t expectedNumberOfClusters = 0;
1524 Bool_t lookForCluster;
1525
1526 alpha=AliTRDgeometry::GetAlpha(); // note: change in meaning
1527
1528
1529 for (Int_t nr=fTrSec[0]->GetLayerNumber(t.GetX()); nr>rf; nr--) {
1530
1531 y = t.GetY(); z = t.GetZ();
1532
1533 // first propagate to the inner surface of the current time bin
1534 fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
1535 x = fTrSec[s]->GetLayer(nr)->GetX()-dx/2; y = t.GetY(); z = t.GetZ();
1536 if(!t.PropagateTo(x,radLength,rho)) break;
1537 y = t.GetY();
1538 ymax = x*TMath::Tan(0.5*alpha);
1539 if (y > ymax) {
1540 s = (s+1) % ns;
1541 if (!t.Rotate(alpha)) break;
1542 if(!t.PropagateTo(x,radLength,rho)) break;
1543 } else if (y <-ymax) {
1544 s = (s-1+ns) % ns;
1545 if (!t.Rotate(-alpha)) break;
1546 if(!t.PropagateTo(x,radLength,rho)) break;
1547 }
1548
1549 y = t.GetY(); z = t.GetZ();
1550
1551 // now propagate to the middle plane of the next time bin
1552 fTrSec[s]->GetLayer(nr-1)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
1553 x = fTrSec[s]->GetLayer(nr-1)->GetX(); y = t.GetY(); z = t.GetZ();
1554 if(!t.PropagateTo(x,radLength,rho)) break;
1555 y = t.GetY();
1556 ymax = x*TMath::Tan(0.5*alpha);
1557 if (y > ymax) {
1558 s = (s+1) % ns;
1559 if (!t.Rotate(alpha)) break;
1560 if(!t.PropagateTo(x,radLength,rho)) break;
1561 } else if (y <-ymax) {
1562 s = (s-1+ns) % ns;
1563 if (!t.Rotate(-alpha)) break;
1564 if(!t.PropagateTo(x,radLength,rho)) break;
1565 }
1566
1567 if(lookForCluster) expectedNumberOfClusters++;
1568
1569 // use assigned cluster
1570 if (!iCluster[nr-1]) continue;
1571 AliTRDcluster *cl=(AliTRDcluster*)GetCluster(iCluster[nr-1]);
1572 Double_t h01 = GetTiltFactor(cl);
1573 Double_t chi2=t.GetPredictedChi2(cl, h01);
1574 t.SetSampledEdx(cl->GetQ()/dx,t.GetNumberOfClusters());
1575 t.Update(cl,chi2,iCluster[nr-1],h01);
1576 }
1577
1578 return expectedNumberOfClusters;
1579}
1580
5443e65e 1581//___________________________________________________________________
1582
1583Int_t AliTRDtracker::PropagateToOuterPlane(AliTRDtrack& t, Double_t xToGo)
1584{
1585 // Starting from current radial position of track <t> this function
1586 // extrapolates the track up to radial position <xToGo>.
1587 // Returns 1 if track reaches the plane, and 0 otherwise
1588
1589 Int_t ns=Int_t(2*TMath::Pi()/AliTRDgeometry::GetAlpha()+0.5);
1590
1591 Double_t alpha=t.GetAlpha();
1592
1593 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
1594 if (alpha < 0. ) alpha += 2.*TMath::Pi();
1595
1596 Int_t s=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::kNsect;
1597
1598 Bool_t lookForCluster;
029cd327 1599 Double_t radLength, rho, x, dx, y, ymax, z;
5443e65e 1600
1601 x = t.GetX();
1602
1603 alpha=AliTRDgeometry::GetAlpha(); // note: change in meaning
1604
1605 Int_t plToGo = fTrSec[0]->GetLayerNumber(xToGo);
1606
1607 for (Int_t nr=fTrSec[0]->GetLayerNumber(x); nr<plToGo; nr++) {
1608
1609 y = t.GetY(); z = t.GetZ();
1610
1611 // first propagate to the outer surface of the current time bin
029cd327 1612 fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
5443e65e 1613 x = fTrSec[s]->GetLayer(nr)->GetX()+dx/2; y = t.GetY(); z = t.GetZ();
029cd327 1614 if(!t.PropagateTo(x,radLength,rho)) return 0;
5443e65e 1615 y = t.GetY();
1616 ymax = x*TMath::Tan(0.5*alpha);
1617 if (y > ymax) {
1618 s = (s+1) % ns;
1619 if (!t.Rotate(alpha)) return 0;
1620 } else if (y <-ymax) {
1621 s = (s-1+ns) % ns;
1622 if (!t.Rotate(-alpha)) return 0;
1623 }
029cd327 1624 if(!t.PropagateTo(x,radLength,rho)) return 0;
5443e65e 1625
1626 y = t.GetY(); z = t.GetZ();
1627
1628 // now propagate to the middle plane of the next time bin
029cd327 1629 fTrSec[s]->GetLayer(nr+1)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
5443e65e 1630 x = fTrSec[s]->GetLayer(nr+1)->GetX(); y = t.GetY(); z = t.GetZ();
029cd327 1631 if(!t.PropagateTo(x,radLength,rho)) return 0;
5443e65e 1632 y = t.GetY();
1633 ymax = x*TMath::Tan(0.5*alpha);
1634 if (y > ymax) {
1635 s = (s+1) % ns;
1636 if (!t.Rotate(alpha)) return 0;
1637 } else if (y <-ymax) {
1638 s = (s-1+ns) % ns;
1639 if (!t.Rotate(-alpha)) return 0;
1640 }
029cd327 1641 if(!t.PropagateTo(x,radLength,rho)) return 0;
5443e65e 1642 }
1643 return 1;
1644}
1645
1646//___________________________________________________________________
1647
1648Int_t AliTRDtracker::PropagateToTPC(AliTRDtrack& t)
1649{
1650 // Starting from current radial position of track <t> this function
1651 // extrapolates the track up to radial position of the outermost
1652 // padrow of the TPC.
1653 // Returns 1 if track reaches the TPC, and 0 otherwise
1654
c630aafd 1655 //Int_t ns=Int_t(2*TMath::Pi()/AliTRDgeometry::GetAlpha()+0.5);
5443e65e 1656
1657 Double_t alpha=t.GetAlpha();
c630aafd 1658 alpha = TVector2::Phi_0_2pi(alpha);
5443e65e 1659
1660 Int_t s=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::kNsect;
1661
1662 Bool_t lookForCluster;
029cd327 1663 Double_t radLength, rho, x, dx, y, /*ymax,*/ z;
5443e65e 1664
1665 x = t.GetX();
1666
1667 alpha=AliTRDgeometry::GetAlpha(); // note: change in meaning
5443e65e 1668 Int_t plTPC = fTrSec[0]->GetLayerNumber(246.055);
1669
1670 for (Int_t nr=fTrSec[0]->GetLayerNumber(x); nr>plTPC; nr--) {
1671
9c9d2487 1672 y = t.GetY();
1673 z = t.GetZ();
5443e65e 1674
1675 // first propagate to the outer surface of the current time bin
029cd327 1676 fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
9c9d2487 1677 x = fTrSec[s]->GetLayer(nr)->GetX()-dx/2;
1678
029cd327 1679 if(!t.PropagateTo(x,radLength,rho)) return 0;
9c9d2487 1680 AdjustSector(&t);
029cd327 1681 if(!t.PropagateTo(x,radLength,rho)) return 0;
5443e65e 1682
9c9d2487 1683 y = t.GetY();
1684 z = t.GetZ();
5443e65e 1685
1686 // now propagate to the middle plane of the next time bin
029cd327 1687 fTrSec[s]->GetLayer(nr-1)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
9c9d2487 1688 x = fTrSec[s]->GetLayer(nr-1)->GetX();
1689
029cd327 1690 if(!t.PropagateTo(x,radLength,rho)) return 0;
9c9d2487 1691 AdjustSector(&t);
029cd327 1692 if(!t.PropagateTo(x,radLength,rho)) return 0;
5443e65e 1693 }
1694 return 1;
1695}
1696
5443e65e 1697void AliTRDtracker::LoadEvent()
1698{
1699 // Fills clusters into TRD tracking_sectors
1700 // Note that the numbering scheme for the TRD tracking_sectors
1701 // differs from that of TRD sectors
1702
1703 ReadClusters(fClusters);
1704 Int_t ncl=fClusters->GetEntriesFast();
1705 cout<<"\n LoadSectors: sorting "<<ncl<<" clusters"<<endl;
1706
1707 UInt_t index;
1708 while (ncl--) {
e24ea474 1709// printf("\r %d left ",ncl);
5443e65e 1710 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(ncl);
029cd327 1711 Int_t detector=c->GetDetector();
1712 Int_t localTimeBin=c->GetLocalTimeBin();
5443e65e 1713 Int_t sector=fGeom->GetSector(detector);
1714 Int_t plane=fGeom->GetPlane(detector);
1715
029cd327 1716 Int_t trackingSector = CookSectorIndex(sector);
5443e65e 1717
029cd327 1718 Int_t gtb = fTrSec[trackingSector]->CookTimeBinIndex(plane,localTimeBin);
b3a5a838 1719 if(gtb < 0) continue;
029cd327 1720 Int_t layer = fTrSec[trackingSector]->GetLayerNumber(gtb);
5443e65e 1721
1722 index=ncl;
029cd327 1723 fTrSec[trackingSector]->GetLayer(layer)->InsertCluster(c,index);
5443e65e 1724 }
1725 printf("\r\n");
1726
1727}
1728
c630aafd 1729//_____________________________________________________________________________
1730Int_t AliTRDtracker::LoadClusters(TTree *cTree)
1731{
1732 // Fills clusters into TRD tracking_sectors
1733 // Note that the numbering scheme for the TRD tracking_sectors
1734 // differs from that of TRD sectors
1735
1736 if (ReadClusters(fClusters,cTree)) {
1737 Error("LoadClusters","Problem with reading the clusters !");
1738 return 1;
1739 }
1740 Int_t ncl=fClusters->GetEntriesFast();
1741 cout<<"\n LoadSectors: sorting "<<ncl<<" clusters"<<endl;
1742
1743 UInt_t index;
1744 while (ncl--) {
1745// printf("\r %d left ",ncl);
1746 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(ncl);
029cd327 1747 Int_t detector=c->GetDetector();
1748 Int_t localTimeBin=c->GetLocalTimeBin();
c630aafd 1749 Int_t sector=fGeom->GetSector(detector);
1750 Int_t plane=fGeom->GetPlane(detector);
1751
029cd327 1752 Int_t trackingSector = CookSectorIndex(sector);
c630aafd 1753
029cd327 1754 Int_t gtb = fTrSec[trackingSector]->CookTimeBinIndex(plane,localTimeBin);
c630aafd 1755 if(gtb < 0) continue;
029cd327 1756 Int_t layer = fTrSec[trackingSector]->GetLayerNumber(gtb);
c630aafd 1757
1758 index=ncl;
029cd327 1759 fTrSec[trackingSector]->GetLayer(layer)->InsertCluster(c,index);
c630aafd 1760 }
1761 printf("\r\n");
1762
1763 return 0;
1764}
1765
5443e65e 1766//_____________________________________________________________________________
1767void AliTRDtracker::UnloadEvent()
1768{
1769 //
1770 // Clears the arrays of clusters and tracks. Resets sectors and timebins
1771 //
1772
1773 Int_t i, nentr;
1774
1775 nentr = fClusters->GetEntriesFast();
1776 for (i = 0; i < nentr; i++) delete fClusters->RemoveAt(i);
1777
1778 nentr = fSeeds->GetEntriesFast();
1779 for (i = 0; i < nentr; i++) delete fSeeds->RemoveAt(i);
1780
1781 nentr = fTracks->GetEntriesFast();
1782 for (i = 0; i < nentr; i++) delete fTracks->RemoveAt(i);
1783
1784 Int_t nsec = AliTRDgeometry::kNsect;
1785
1786 for (i = 0; i < nsec; i++) {
1787 for(Int_t pl = 0; pl < fTrSec[i]->GetNumberOfLayers(); pl++) {
1788 fTrSec[i]->GetLayer(pl)->Clear();
1789 }
1790 }
1791
1792}
1793
1794//__________________________________________________________________________
1795void AliTRDtracker::MakeSeeds(Int_t inner, Int_t outer, Int_t turn)
1796{
1797 // Creates track seeds using clusters in timeBins=i1,i2
1798
1799 if(turn > 2) {
1800 cerr<<"MakeSeeds: turn "<<turn<<" exceeds the limit of 2"<<endl;
1801 return;
1802 }
1803
1804 Double_t x[5], c[15];
029cd327 1805 Int_t maxSec=AliTRDgeometry::kNsect;
5443e65e 1806
1807 Double_t alpha=AliTRDgeometry::GetAlpha();
1808 Double_t shift=AliTRDgeometry::GetAlpha()/2.;
1809 Double_t cs=cos(alpha), sn=sin(alpha);
1810 Double_t cs2=cos(2.*alpha), sn2=sin(2.*alpha);
1811
1812
1813 Int_t i2 = fTrSec[0]->GetLayerNumber(inner);
1814 Int_t i1 = fTrSec[0]->GetLayerNumber(outer);
1815
1816 Double_t x1 =fTrSec[0]->GetX(i1);
1817 Double_t xx2=fTrSec[0]->GetX(i2);
1818
029cd327 1819 for (Int_t ns=0; ns<maxSec; ns++) {
5443e65e 1820
029cd327 1821 Int_t nl2 = *(fTrSec[(ns-2+maxSec)%maxSec]->GetLayer(i2));
1822 Int_t nl=(*fTrSec[(ns-1+maxSec)%maxSec]->GetLayer(i2));
5443e65e 1823 Int_t nm=(*fTrSec[ns]->GetLayer(i2));
029cd327 1824 Int_t nu=(*fTrSec[(ns+1)%maxSec]->GetLayer(i2));
1825 Int_t nu2=(*fTrSec[(ns+2)%maxSec]->GetLayer(i2));
5443e65e 1826
1827 AliTRDpropagationLayer& r1=*(fTrSec[ns]->GetLayer(i1));
1828
1829 for (Int_t is=0; is < r1; is++) {
1830 Double_t y1=r1[is]->GetY(), z1=r1[is]->GetZ();
1831
1832 for (Int_t js=0; js < nl2+nl+nm+nu+nu2; js++) {
a9814c09 1833
1834 const AliTRDcluster *cl;
1835 Double_t x2, y2, z2;
1836 Double_t x3=0., y3=0.;
1837
1838 if (js<nl2) {
1839 if(turn != 2) continue;
029cd327 1840 AliTRDpropagationLayer& r2=*(fTrSec[(ns-2+maxSec)%maxSec]->GetLayer(i2));
a9814c09 1841 cl=r2[js];
1842 y2=cl->GetY(); z2=cl->GetZ();
1843
1844 x2= xx2*cs2+y2*sn2;
1845 y2=-xx2*sn2+y2*cs2;
1846 }
1847 else if (js<nl2+nl) {
1848 if(turn != 1) continue;
029cd327 1849 AliTRDpropagationLayer& r2=*(fTrSec[(ns-1+maxSec)%maxSec]->GetLayer(i2));
a9814c09 1850 cl=r2[js-nl2];
1851 y2=cl->GetY(); z2=cl->GetZ();
1852
1853 x2= xx2*cs+y2*sn;
1854 y2=-xx2*sn+y2*cs;
1855 }
1856 else if (js<nl2+nl+nm) {
1857 if(turn != 1) continue;
1858 AliTRDpropagationLayer& r2=*(fTrSec[ns]->GetLayer(i2));
1859 cl=r2[js-nl2-nl];
1860 x2=xx2; y2=cl->GetY(); z2=cl->GetZ();
1861 }
1862 else if (js<nl2+nl+nm+nu) {
1863 if(turn != 1) continue;
029cd327 1864 AliTRDpropagationLayer& r2=*(fTrSec[(ns+1)%maxSec]->GetLayer(i2));
a9814c09 1865 cl=r2[js-nl2-nl-nm];
1866 y2=cl->GetY(); z2=cl->GetZ();
1867
1868 x2=xx2*cs-y2*sn;
1869 y2=xx2*sn+y2*cs;
1870 }
1871 else {
1872 if(turn != 2) continue;
029cd327 1873 AliTRDpropagationLayer& r2=*(fTrSec[(ns+2)%maxSec]->GetLayer(i2));
a9814c09 1874 cl=r2[js-nl2-nl-nm-nu];
1875 y2=cl->GetY(); z2=cl->GetZ();
1876
1877 x2=xx2*cs2-y2*sn2;
1878 y2=xx2*sn2+y2*cs2;
1879 }
1880
029cd327 1881 if(TMath::Abs(z1-z2) > fgkMaxSeedDeltaZ12) continue;
a9814c09 1882
1883 Double_t zz=z1 - z1/x1*(x1-x2);
1884
029cd327 1885 if (TMath::Abs(zz-z2)>fgkMaxSeedDeltaZ) continue;
a9814c09 1886
1887 Double_t d=(x2-x1)*(0.-y2)-(0.-x2)*(y2-y1);
1888 if (d==0.) {cerr<<"TRD MakeSeeds: Straight seed !\n"; continue;}
1889
1890 x[0]=y1;
1891 x[1]=z1;
1892 x[4]=f1trd(x1,y1,x2,y2,x3,y3);
1893
029cd327 1894 if (TMath::Abs(x[4]) > fgkMaxSeedC) continue;
a9814c09 1895
1896 x[2]=f2trd(x1,y1,x2,y2,x3,y3);
1897
1898 if (TMath::Abs(x[4]*x1-x[2]) >= 0.99999) continue;
1899
1900 x[3]=f3trd(x1,y1,x2,y2,z1,z2);
1901
029cd327 1902 if (TMath::Abs(x[3]) > fgkMaxSeedTan) continue;
a9814c09 1903
1904 Double_t a=asin(x[2]);
1905 Double_t zv=z1 - x[3]/x[4]*(a+asin(x[4]*x1-x[2]));
1906
029cd327 1907 if (TMath::Abs(zv)>fgkMaxSeedVertexZ) continue;
a9814c09 1908
1909 Double_t sy1=r1[is]->GetSigmaY2(), sz1=r1[is]->GetSigmaZ2();
1910 Double_t sy2=cl->GetSigmaY2(), sz2=cl->GetSigmaZ2();
029cd327 1911 Double_t sy3=fgkSeedErrorSY3, sy=fgkSeedErrorSY, sz=fgkSeedErrorSZ;
a9814c09 1912
1913 // Tilt changes
1914 Double_t h01 = GetTiltFactor(r1[is]);
029cd327 1915 Double_t xuFactor = 100.;
b8dc2353 1916 if(fNoTilt) {
1917 h01 = 0;
029cd327 1918 xuFactor = 1;
b8dc2353 1919 }
1920
fd621f36 1921 sy1=sy1+sz1*h01*h01;
b3a5a838 1922 Double_t syz=sz1*(-h01);
a9814c09 1923 // end of tilt changes
1924
b3a5a838 1925 Double_t f40=(f1trd(x1,y1+sy,x2,y2,x3,y3)-x[4])/sy;
1926 Double_t f42=(f1trd(x1,y1,x2,y2+sy,x3,y3)-x[4])/sy;
1927 Double_t f43=(f1trd(x1,y1,x2,y2,x3,y3+sy)-x[4])/sy;
1928 Double_t f20=(f2trd(x1,y1+sy,x2,y2,x3,y3)-x[2])/sy;
1929 Double_t f22=(f2trd(x1,y1,x2,y2+sy,x3,y3)-x[2])/sy;
1930 Double_t f23=(f2trd(x1,y1,x2,y2,x3,y3+sy)-x[2])/sy;
1931 Double_t f30=(f3trd(x1,y1+sy,x2,y2,z1,z2)-x[3])/sy;
1932 Double_t f31=(f3trd(x1,y1,x2,y2,z1+sz,z2)-x[3])/sz;
1933 Double_t f32=(f3trd(x1,y1,x2,y2+sy,z1,z2)-x[3])/sy;
1934 Double_t f34=(f3trd(x1,y1,x2,y2,z1,z2+sz)-x[3])/sz;
1935
a9814c09 1936
b3a5a838 1937 c[0]=sy1;
a9814c09 1938 // c[1]=0.; c[2]=sz1;
029cd327 1939 c[1]=syz; c[2]=sz1*xuFactor;
b3a5a838 1940 c[3]=f20*sy1; c[4]=0.; c[5]=f20*sy1*f20+f22*sy2*f22+f23*sy3*f23;
1941 c[6]=f30*sy1; c[7]=f31*sz1; c[8]=f30*sy1*f20+f32*sy2*f22;
1942 c[9]=f30*sy1*f30+f31*sz1*f31+f32*sy2*f32+f34*sz2*f34;
1943 c[10]=f40*sy1; c[11]=0.; c[12]=f40*sy1*f20+f42*sy2*f22+f43*sy3*f23;
1944 c[13]=f30*sy1*f40+f32*sy2*f42;
1945 c[14]=f40*sy1*f40+f42*sy2*f42+f43*sy3*f43;
a9814c09 1946
1947 UInt_t index=r1.GetIndex(is);
1948
1949 AliTRDtrack *track=new AliTRDtrack(r1[is],index,x,c,x1,ns*alpha+shift);
1950
1951 Int_t rc=FollowProlongation(*track, i2);
1952
1953 if ((rc < 1) ||
1954 (track->GetNumberOfClusters() <
029cd327 1955 (outer-inner)*fgkMinClustersInSeed)) delete track;
a9814c09 1956 else {
1957 fSeeds->AddLast(track); fNseeds++;
e24ea474 1958// cerr<<"\r found seed "<<fNseeds;
a9814c09 1959 }
5443e65e 1960 }
1961 }
1962 }
1963}
1964
1965//_____________________________________________________________________________
c630aafd 1966Int_t AliTRDtracker::ReadClusters(TObjArray *array, TTree *ClusterTree)
5443e65e 1967{
1968 //
a819a5f7 1969 // Reads AliTRDclusters (option >= 0) or AliTRDrecPoints (option < 0)
1970 // from the file. The names of the cluster tree and branches
1971 // should match the ones used in AliTRDclusterizer::WriteClusters()
1972 //
029cd327 1973 TObjArray *clusterArray = new TObjArray(400);
5443e65e 1974
c630aafd 1975 TBranch *branch=ClusterTree->GetBranch("TRDcluster");
1976 if (!branch) {
1977 Error("ReadClusters","Can't get the branch !");
1978 return 1;
1979 }
029cd327 1980 branch->SetAddress(&clusterArray);
5443e65e 1981
1982 Int_t nEntries = (Int_t) ClusterTree->GetEntries();
1983 printf("found %d entries in %s.\n",nEntries,ClusterTree->GetName());
a819a5f7 1984
a819a5f7 1985 // Loop through all entries in the tree
1986 Int_t nbytes;
1987 AliTRDcluster *c = 0;
5443e65e 1988 printf("\n");
a819a5f7 1989
1990 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
1991
1992 // Import the tree
5443e65e 1993 nbytes += ClusterTree->GetEvent(iEntry);
1994
a819a5f7 1995 // Get the number of points in the detector
029cd327 1996 Int_t nCluster = clusterArray->GetEntriesFast();
e24ea474 1997// printf("\r Read %d clusters from entry %d", nCluster, iEntry);
5443e65e 1998
a819a5f7 1999 // Loop through all TRD digits
2000 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
029cd327 2001 c = (AliTRDcluster*)clusterArray->UncheckedAt(iCluster);
a819a5f7 2002 AliTRDcluster *co = new AliTRDcluster(*c);
2003 co->SetSigmaY2(c->GetSigmaY2() * fSY2corr);
5443e65e 2004 Int_t ltb = co->GetLocalTimeBin();
b8dc2353 2005 if(ltb == 19) co->SetSigmaZ2(c->GetSigmaZ2());
2006 else if(fNoTilt) co->SetSigmaZ2(c->GetSigmaZ2() * fSZ2corr);
a819a5f7 2007 array->AddLast(co);
029cd327 2008 delete clusterArray->RemoveAt(iCluster);
a819a5f7 2009 }
2010 }
2011
029cd327 2012 delete clusterArray;
5443e65e 2013
c630aafd 2014 return 0;
a819a5f7 2015}
2016
5443e65e 2017//______________________________________________________________________
2018void AliTRDtracker::ReadClusters(TObjArray *array, const Char_t *filename)
a819a5f7 2019{
2020 //
5443e65e 2021 // Reads AliTRDclusters from file <filename>. The names of the cluster
2022 // tree and branches should match the ones used in
2023 // AliTRDclusterizer::WriteClusters()
2024 // if <array> == 0, clusters are added into AliTRDtracker fCluster array
a819a5f7 2025 //
2026
5443e65e 2027 TDirectory *savedir=gDirectory;
46d29e70 2028
5443e65e 2029 TFile *file = TFile::Open(filename);
2030 if (!file->IsOpen()) {
2031 cerr<<"Can't open file with TRD clusters"<<endl;
2032 return;
2033 }
46d29e70 2034
5443e65e 2035 Char_t treeName[12];
e24ea474 2036 sprintf(treeName,"TreeR%d_TRD",GetEventNumber());
029cd327 2037 TTree *clusterTree = (TTree*) gDirectory->Get(treeName);
46d29e70 2038
029cd327 2039 if (!clusterTree) {
5443e65e 2040 cerr<<"AliTRDtracker::ReadClusters(): ";
2041 cerr<<"can't get a tree with clusters !\n";
2042 return;
2043 }
46d29e70 2044
029cd327 2045 TObjArray *clusterArray = new TObjArray(400);
46d29e70 2046
029cd327 2047 clusterTree->GetBranch("TRDcluster")->SetAddress(&clusterArray);
46d29e70 2048
029cd327 2049 Int_t nEntries = (Int_t) clusterTree->GetEntries();
2050 cout<<"found "<<nEntries<<" in clusterTree"<<endl;
a819a5f7 2051
5443e65e 2052 // Loop through all entries in the tree
2053 Int_t nbytes;
2054 AliTRDcluster *c = 0;
bbf92647 2055
5443e65e 2056 printf("\n");
bbf92647 2057
5443e65e 2058 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
46d29e70 2059
5443e65e 2060 // Import the tree
029cd327 2061 nbytes += clusterTree->GetEvent(iEntry);
0a29d0f1 2062
5443e65e 2063 // Get the number of points in the detector
029cd327 2064 Int_t nCluster = clusterArray->GetEntriesFast();
b3a5a838 2065 printf("\n Read %d clusters from entry %d", nCluster, iEntry);
5443e65e 2066
2067 // Loop through all TRD digits
2068 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
029cd327 2069 c = (AliTRDcluster*)clusterArray->UncheckedAt(iCluster);
5443e65e 2070 AliTRDcluster *co = new AliTRDcluster(*c);
2071 co->SetSigmaY2(c->GetSigmaY2() * fSY2corr);
2072 Int_t ltb = co->GetLocalTimeBin();
b8dc2353 2073 if(ltb == 19) co->SetSigmaZ2(c->GetSigmaZ2());
2074 else if(fNoTilt) co->SetSigmaZ2(c->GetSigmaZ2() * fSZ2corr);
5443e65e 2075 array->AddLast(co);
029cd327 2076 delete clusterArray->RemoveAt(iCluster);
5443e65e 2077 }
46d29e70 2078 }
0a29d0f1 2079
5443e65e 2080 file->Close();
029cd327 2081 delete clusterArray;
5443e65e 2082 savedir->cd();
2083
2084}
2085
c630aafd 2086void AliTRDtracker::ReadClusters(TObjArray *array, const TFile *inp)
2087{
2088 //
2089 // Reads AliTRDclusters (option >= 0) or AliTRDrecPoints (option < 0)
2090 // from the file. The names of the cluster tree and branches
2091 // should match the ones used in AliTRDclusterizer::WriteClusters()
2092 //
2093
2094 TDirectory *savedir=gDirectory;
2095
2096 if (inp) {
2097 TFile *in=(TFile*)inp;
2098 if (!in->IsOpen()) {
2099 cerr<<"AliTRDtracker::ReadClusters(): input file is not open !\n";
2100 return;
2101 }
2102 else{
2103 in->cd();
2104 }
2105 }
2106
2107 Char_t treeName[12];
2108 sprintf(treeName,"TreeR%d_TRD",GetEventNumber());
029cd327 2109 TTree *clusterTree = (TTree*) gDirectory->Get(treeName);
c630aafd 2110
029cd327 2111 TObjArray *clusterArray = new TObjArray(400);
c630aafd 2112
029cd327 2113 clusterTree->GetBranch("TRDcluster")->SetAddress(&clusterArray);
c630aafd 2114
029cd327 2115 Int_t nEntries = (Int_t) clusterTree->GetEntries();
2116 printf("found %d entries in %s.\n",nEntries,clusterTree->GetName());
c630aafd 2117
2118 // Loop through all entries in the tree
2119 Int_t nbytes;
2120 AliTRDcluster *c = 0;
2121 printf("\n");
2122
2123 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
2124
2125 // Import the tree
029cd327 2126 nbytes += clusterTree->GetEvent(iEntry);
c630aafd 2127
2128 // Get the number of points in the detector
029cd327 2129 Int_t nCluster = clusterArray->GetEntriesFast();
c630aafd 2130// printf("\r Read %d clusters from entry %d", nCluster, iEntry);
2131
2132 // Loop through all TRD digits
2133 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
029cd327 2134 c = (AliTRDcluster*)clusterArray->UncheckedAt(iCluster);
c630aafd 2135 AliTRDcluster *co = new AliTRDcluster(*c);
2136 co->SetSigmaY2(c->GetSigmaY2() * fSY2corr);
2137 Int_t ltb = co->GetLocalTimeBin();
2138 if(ltb == 19) co->SetSigmaZ2(c->GetSigmaZ2());
2139 else if(fNoTilt) co->SetSigmaZ2(c->GetSigmaZ2() * fSZ2corr);
2140 array->AddLast(co);
029cd327 2141 delete clusterArray->RemoveAt(iCluster);
c630aafd 2142 }
2143 }
2144
029cd327 2145 delete clusterArray;
c630aafd 2146 savedir->cd();
2147
2148}
46d29e70 2149
2150//__________________________________________________________________
029cd327 2151void AliTRDtracker::CookLabel(AliKalmanTrack* pt, Float_t wrong) const
2152{
2153 //
2154 // This cooks a label. Mmmmh, smells good...
2155 //
46d29e70 2156
2157 Int_t label=123456789, index, i, j;
5443e65e 2158 Int_t ncl=pt->GetNumberOfClusters();
029cd327 2159 const Int_t kRange = fTrSec[0]->GetOuterTimeBin()+1;
5443e65e 2160
029cd327 2161 Bool_t labelAdded;
46d29e70 2162
029cd327 2163 // Int_t s[kRange][2];
2164 Int_t **s = new Int_t* [kRange];
2165 for (i=0; i<kRange; i++) {
d1b06c24 2166 s[i] = new Int_t[2];
2167 }
029cd327 2168 for (i=0; i<kRange; i++) {
46d29e70 2169 s[i][0]=-1;
2170 s[i][1]=0;
2171 }
2172
2173 Int_t t0,t1,t2;
2174 for (i=0; i<ncl; i++) {
5443e65e 2175 index=pt->GetClusterIndex(i);
46d29e70 2176 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
5443e65e 2177 t0=c->GetLabel(0);
2178 t1=c->GetLabel(1);
2179 t2=c->GetLabel(2);
46d29e70 2180 }
2181
2182 for (i=0; i<ncl; i++) {
5443e65e 2183 index=pt->GetClusterIndex(i);
46d29e70 2184 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
2185 for (Int_t k=0; k<3; k++) {
5443e65e 2186 label=c->GetLabel(k);
029cd327 2187 labelAdded=kFALSE; j=0;
46d29e70 2188 if (label >= 0) {
029cd327 2189 while ( (!labelAdded) && ( j < kRange ) ) {
a9814c09 2190 if (s[j][0]==label || s[j][1]==0) {
2191 s[j][0]=label;
2192 s[j][1]=s[j][1]+1;
029cd327 2193 labelAdded=kTRUE;
a9814c09 2194 }
2195 j++;
2196 }
46d29e70 2197 }
2198 }
2199 }
2200
46d29e70 2201 Int_t max=0;
2202 label = -123456789;
2203
029cd327 2204 for (i=0; i<kRange; i++) {
46d29e70 2205 if (s[i][1]>max) {
2206 max=s[i][1]; label=s[i][0];
2207 }
2208 }
5443e65e 2209
029cd327 2210 for (i=0; i<kRange; i++) {
5443e65e 2211 delete []s[i];
2212 }
2213
d1b06c24 2214 delete []s;
5443e65e 2215
2216 if ((1.- Float_t(max)/ncl) > wrong) label=-label;
2217
2218 pt->SetLabel(label);
2219
46d29e70 2220}
2221
c630aafd 2222
5443e65e 2223//__________________________________________________________________
029cd327 2224void AliTRDtracker::UseClusters(const AliKalmanTrack* t, Int_t from) const
2225{
2226 //
2227 // Use clusters, but don't abuse them!
2228 //
2229
5443e65e 2230 Int_t ncl=t->GetNumberOfClusters();
2231 for (Int_t i=from; i<ncl; i++) {
2232 Int_t index = t->GetClusterIndex(i);
2233 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
2234 c->Use();
2235 }
2236}
2237
2238
2239//_____________________________________________________________________
029cd327 2240Double_t AliTRDtracker::ExpectedSigmaY2(Double_t , Double_t , Double_t ) const
5443e65e 2241{
2242 // Parametrised "expected" error of the cluster reconstruction in Y
2243
2244 Double_t s = 0.08 * 0.08;
2245 return s;
2246}
2247
2248//_____________________________________________________________________
029cd327 2249Double_t AliTRDtracker::ExpectedSigmaZ2(Double_t , Double_t ) const
0a29d0f1 2250{
5443e65e 2251 // Parametrised "expected" error of the cluster reconstruction in Z
2252
a9814c09 2253 Double_t s = 9 * 9 /12.;
5443e65e 2254 return s;
2255}
2256
5443e65e 2257//_____________________________________________________________________
029cd327 2258Double_t AliTRDtracker::GetX(Int_t sector, Int_t plane, Int_t localTB) const
5443e65e 2259{
2260 //
029cd327 2261 // Returns radial position which corresponds to time bin <localTB>
5443e65e 2262 // in tracking sector <sector> and plane <plane>
2263 //
2264
029cd327 2265 Int_t index = fTrSec[sector]->CookTimeBinIndex(plane, localTB);
5443e65e 2266 Int_t pl = fTrSec[sector]->GetLayerNumber(index);
2267 return fTrSec[sector]->GetLayer(pl)->GetX();
2268
2269}
2270
c630aafd 2271
5443e65e 2272//_______________________________________________________
2273AliTRDtracker::AliTRDpropagationLayer::AliTRDpropagationLayer(Double_t x,
029cd327 2274 Double_t dx, Double_t rho, Double_t radLength, Int_t tbIndex)
5443e65e 2275{
0a29d0f1 2276 //
5443e65e 2277 // AliTRDpropagationLayer constructor
0a29d0f1 2278 //
46d29e70 2279
029cd327 2280 fN = 0; fX = x; fdX = dx; fRho = rho; fX0 = radLength;
2281 fClusters = NULL; fIndex = NULL; fTimeBinIndex = tbIndex;
5443e65e 2282
46d29e70 2283
029cd327 2284 for(Int_t i=0; i < (Int_t) kZones; i++) {
5443e65e 2285 fZc[i]=0; fZmax[i] = 0;
a819a5f7 2286 }
5443e65e 2287
2288 fYmax = 0;
2289
2290 if(fTimeBinIndex >= 0) {
029cd327 2291 fClusters = new AliTRDcluster*[kMaxClusterPerTimeBin];
2292 fIndex = new UInt_t[kMaxClusterPerTimeBin];
a819a5f7 2293 }
46d29e70 2294
5443e65e 2295 fHole = kFALSE;
2296 fHoleZc = 0;
2297 fHoleZmax = 0;
2298 fHoleYc = 0;
2299 fHoleYmax = 0;
2300 fHoleRho = 0;
2301 fHoleX0 = 0;
2302
2303}
2304
2305//_______________________________________________________
2306void AliTRDtracker::AliTRDpropagationLayer::SetHole(
a9814c09 2307 Double_t Zmax, Double_t Ymax, Double_t rho,
029cd327 2308 Double_t radLength, Double_t Yc, Double_t Zc)
5443e65e 2309{
2310 //
2311 // Sets hole in the layer
2312 //
2313
2314 fHole = kTRUE;
2315 fHoleZc = Zc;
2316 fHoleZmax = Zmax;
2317 fHoleYc = Yc;
2318 fHoleYmax = Ymax;
2319 fHoleRho = rho;
029cd327 2320 fHoleX0 = radLength;
5443e65e 2321}
2322
46d29e70 2323
5443e65e 2324//_______________________________________________________
2325AliTRDtracker::AliTRDtrackingSector::AliTRDtrackingSector(AliTRDgeometry* geo, Int_t gs, AliTRDparameter* par)
2326{
2327 //
2328 // AliTRDtrackingSector Constructor
2329 //
2330
2331 fGeom = geo;
2332 fPar = par;
2333 fGeomSector = gs;
2334 fTzeroShift = 0.13;
2335 fN = 0;
2336
029cd327 2337 for(UInt_t i=0; i < kMaxTimeBinIndex; i++) fTimeBinIndex[i] = -1;
5443e65e 2338
2339
2340 AliTRDpropagationLayer* ppl;
2341
029cd327 2342 Double_t x, xin, xout, dx, rho, radLength;
5443e65e 2343 Int_t steps;
46d29e70 2344
5443e65e 2345 // set time bins in the gas of the TPC
46d29e70 2346
5443e65e 2347 xin = 246.055; xout = 254.055; steps = 20; dx = (xout-xin)/steps;
029cd327 2348 rho = 0.9e-3; radLength = 28.94;
5443e65e 2349
2350 for(Int_t i=0; i<steps; i++) {
2351 x = xin + i*dx + dx/2;
029cd327 2352 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 2353 InsertLayer(ppl);
46d29e70 2354 }
2355
5443e65e 2356 // set time bins in the outer field cage vessel
46d29e70 2357
029cd327 2358 dx = 50e-4; xin = xout; xout = xin + dx; rho = 1.71; radLength = 44.77; // Tedlar
2359 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 2360 InsertLayer(ppl);
46d29e70 2361
029cd327 2362 dx = 0.02; xin = xout; xout = xin + dx; rho = 1.45; radLength = 44.86; // prepreg
2363 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 2364 InsertLayer(ppl);
2365
029cd327 2366 dx = 2.; xin = xout; xout = xin + dx; rho = 1.45*0.02; radLength = 41.28; // Nomex
5443e65e 2367 steps = 5; dx = (xout - xin)/steps;
2368 for(Int_t i=0; i<steps; i++) {
2369 x = xin + i*dx + dx/2;
029cd327 2370 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 2371 InsertLayer(ppl);
2372 }
2373
029cd327 2374 dx = 0.02; xin = xout; xout = xin + dx; rho = 1.45; radLength = 44.86; // prepreg
2375 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 2376 InsertLayer(ppl);
2377
029cd327 2378 dx = 50e-4; xin = xout; xout = xin + dx; rho = 1.71; radLength = 44.77; // Tedlar
2379 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 2380 InsertLayer(ppl);
0a29d0f1 2381
5443e65e 2382
2383 // set time bins in CO2
2384
2385 xin = xout; xout = 275.0;
2386 steps = 50; dx = (xout - xin)/steps;
029cd327 2387 rho = 1.977e-3; radLength = 36.2;
5443e65e 2388
2389 for(Int_t i=0; i<steps; i++) {
2390 x = xin + i*dx + dx/2;
029cd327 2391 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 2392 InsertLayer(ppl);
2393 }
2394
2395 // set time bins in the outer containment vessel
2396
029cd327 2397 dx = 50e-4; xin = xout; xout = xin + dx; rho = 2.7; radLength = 24.01; // Al
2398 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 2399 InsertLayer(ppl);
2400
029cd327 2401 dx = 50e-4; xin = xout; xout = xin + dx; rho = 1.71; radLength = 44.77; // Tedlar
2402 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 2403 InsertLayer(ppl);
2404
029cd327 2405 dx = 0.06; xin = xout; xout = xin + dx; rho = 1.45; radLength = 44.86; // prepreg
2406 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 2407 InsertLayer(ppl);
2408
029cd327 2409 dx = 3.; xin = xout; xout = xin + dx; rho = 1.45*0.02; radLength = 41.28; // Nomex
5443e65e 2410 steps = 10; dx = (xout - xin)/steps;
2411 for(Int_t i=0; i<steps; i++) {
2412 x = xin + i*dx + dx/2;
029cd327 2413 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 2414 InsertLayer(ppl);
2415 }
2416
029cd327 2417 dx = 0.06; xin = xout; xout = xin + dx; rho = 1.45; radLength = 44.86; // prepreg
2418 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 2419 InsertLayer(ppl);
2420
029cd327 2421 dx = 50e-4; xin = xout; xout = xin + dx; rho = 1.71; radLength = 44.77; // Tedlar
2422 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 2423 InsertLayer(ppl);
2424
029cd327 2425 dx = 50e-4; xin = xout; xout = xin + dx; rho = 2.7; radLength = 24.01; // Al
2426 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 2427 InsertLayer(ppl);
2428
2429 Double_t xtrd = (Double_t) fGeom->Rmin();
2430
2431 // add layers between TPC and TRD (Air temporarily)
2432 xin = xout; xout = xtrd;
2433 steps = 50; dx = (xout - xin)/steps;
029cd327 2434 rho = 1.2e-3; radLength = 36.66;
5443e65e 2435
2436 for(Int_t i=0; i<steps; i++) {
2437 x = xin + i*dx + dx/2;
029cd327 2438 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 2439 InsertLayer(ppl);
2440 }
2441
2442
2443 Double_t alpha=AliTRDgeometry::GetAlpha();
2444
2445 // add layers for each of the planes
2446
2447 Double_t dxRo = (Double_t) fGeom->CroHght(); // Rohacell
2448 Double_t dxSpace = (Double_t) fGeom->Cspace(); // Spacing between planes
2449 Double_t dxAmp = (Double_t) fGeom->CamHght(); // Amplification region
2450 Double_t dxDrift = (Double_t) fGeom->CdrHght(); // Drift region
2451 Double_t dxRad = (Double_t) fGeom->CraHght(); // Radiator
2452 Double_t dxTEC = dxRad + dxDrift + dxAmp + dxRo;
2453 Double_t dxPlane = dxTEC + dxSpace;
2454
029cd327 2455 Int_t tb, tbIndex;
2456 const Int_t kNchambers = AliTRDgeometry::Ncham();
2457 Double_t ymax = 0, holeYmax = 0;
2458 Double_t *zc = new Double_t[kNchambers];
2459 Double_t *zmax = new Double_t[kNchambers];
5443e65e 2460 Double_t holeZmax = 1000.; // the whole sector is missing
2461
5443e65e 2462 for(Int_t plane = 0; plane < AliTRDgeometry::Nplan(); plane++) {
2463
2464 // Radiator
2465 xin = xtrd + plane * dxPlane; xout = xin + dxRad;
029cd327 2466 steps = 12; dx = (xout - xin)/steps; rho = 0.074; radLength = 40.6;
5443e65e 2467 for(Int_t i=0; i<steps; i++) {
2468 x = xin + i*dx + dx/2;
029cd327 2469 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 2470 if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
a9814c09 2471 holeYmax = x*TMath::Tan(0.5*alpha);
2472 ppl->SetHole(holeYmax, holeZmax);
5443e65e 2473 }
2474 if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
a9814c09 2475 holeYmax = x*TMath::Tan(0.5*alpha);
2476 ppl->SetHole(holeYmax, holeZmax);
5443e65e 2477 }
2478 InsertLayer(ppl);
2479 }
2480
029cd327 2481 ymax = fGeom->GetChamberWidth(plane)/2;
2482 for(Int_t ch = 0; ch < kNchambers; ch++) {
2483 zmax[ch] = fGeom->GetChamberLength(plane,ch)/2;
5443e65e 2484 Float_t pad = fPar->GetRowPadSize(plane,ch,0);
2485 Float_t row0 = fPar->GetRow0(plane,ch,0);
2486 Int_t nPads = fPar->GetRowMax(plane,ch,0);
029cd327 2487 zc[ch] = (pad * nPads)/2 + row0 - pad/2;
5443e65e 2488 }
2489
2490 dx = fPar->GetTimeBinSize();
029cd327 2491 rho = 0.00295 * 0.85; radLength = 11.0;
5443e65e 2492
2493 Double_t x0 = (Double_t) fPar->GetTime0(plane);
2494 Double_t xbottom = x0 - dxDrift;
2495 Double_t xtop = x0 + dxAmp;
2496
2497 // Amplification region
2498
2499 steps = (Int_t) (dxAmp/dx);
2500
2501 for(tb = 0; tb < steps; tb++) {
2502 x = x0 + tb * dx + dx/2;
029cd327 2503 tbIndex = CookTimeBinIndex(plane, -tb-1);
2504 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,tbIndex);
2505 ppl->SetYmax(ymax);
2506 for(Int_t ch = 0; ch < kNchambers; ch++) {
2507 ppl->SetZmax(ch, zc[ch], zmax[ch]);
5443e65e 2508 }
2509 if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
a9814c09 2510 holeYmax = x*TMath::Tan(0.5*alpha);
2511 ppl->SetHole(holeYmax, holeZmax);
5443e65e 2512 }
2513 if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
a9814c09 2514 holeYmax = x*TMath::Tan(0.5*alpha);
2515 ppl->SetHole(holeYmax, holeZmax);
5443e65e 2516 }
2517 InsertLayer(ppl);
2518 }
029cd327 2519 tbIndex = CookTimeBinIndex(plane, -steps);
5443e65e 2520 x = (x + dx/2 + xtop)/2;
2521 dx = 2*(xtop-x);
029cd327 2522 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,tbIndex);
2523 ppl->SetYmax(ymax);
2524 for(Int_t ch = 0; ch < kNchambers; ch++) {
2525 ppl->SetZmax(ch, zc[ch], zmax[ch]);
5443e65e 2526 }
2527 if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
2528 holeYmax = x*TMath::Tan(0.5*alpha);
2529 ppl->SetHole(holeYmax, holeZmax);
2530 }
2531 if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
2532 holeYmax = x*TMath::Tan(0.5*alpha);
2533 ppl->SetHole(holeYmax, holeZmax);
2534 }
2535 InsertLayer(ppl);
2536
2537 // Drift region
2538 dx = fPar->GetTimeBinSize();
2539 steps = (Int_t) (dxDrift/dx);
2540
2541 for(tb = 0; tb < steps; tb++) {
2542 x = x0 - tb * dx - dx/2;
029cd327 2543 tbIndex = CookTimeBinIndex(plane, tb);
5443e65e 2544
029cd327 2545 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,tbIndex);
2546 ppl->SetYmax(ymax);
2547 for(Int_t ch = 0; ch < kNchambers; ch++) {
2548 ppl->SetZmax(ch, zc[ch], zmax[ch]);
5443e65e 2549 }
2550 if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
a9814c09 2551 holeYmax = x*TMath::Tan(0.5*alpha);
2552 ppl->SetHole(holeYmax, holeZmax);
5443e65e 2553 }
2554 if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
a9814c09 2555 holeYmax = x*TMath::Tan(0.5*alpha);
2556 ppl->SetHole(holeYmax, holeZmax);
5443e65e 2557 }
2558 InsertLayer(ppl);
2559 }
029cd327 2560 tbIndex = CookTimeBinIndex(plane, steps);
5443e65e 2561 x = (x - dx/2 + xbottom)/2;
2562 dx = 2*(x-xbottom);
029cd327 2563 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,tbIndex);
2564 ppl->SetYmax(ymax);
2565 for(Int_t ch = 0; ch < kNchambers; ch++) {
2566 ppl->SetZmax(ch, zc[ch], zmax[ch]);
5443e65e 2567 }
2568 if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
2569 holeYmax = x*TMath::Tan(0.5*alpha);
2570 ppl->SetHole(holeYmax, holeZmax);
2571 }
2572 if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
2573 holeYmax = x*TMath::Tan(0.5*alpha);
2574 ppl->SetHole(holeYmax, holeZmax);
2575 }
2576 InsertLayer(ppl);
2577
2578 // Pad Plane
029cd327 2579 xin = xtop; dx = 0.025; xout = xin + dx; rho = 1.7; radLength = 33.0;
2580 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 2581 if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
2582 holeYmax = (xin+dx/2)*TMath::Tan(0.5*alpha);
2583 ppl->SetHole(holeYmax, holeZmax);
2584 }
2585 if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
2586 holeYmax = (xin+dx/2)*TMath::Tan(0.5*alpha);
2587 ppl->SetHole(holeYmax, holeZmax);
2588 }
2589 InsertLayer(ppl);
2590
2591 // Rohacell
2592 xin = xout; xout = xtrd + (plane + 1) * dxPlane - dxSpace;
029cd327 2593 steps = 5; dx = (xout - xin)/steps; rho = 0.074; radLength = 40.6;
5443e65e 2594 for(Int_t i=0; i<steps; i++) {
2595 x = xin + i*dx + dx/2;
029cd327 2596 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 2597 if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
a9814c09 2598 holeYmax = x*TMath::Tan(0.5*alpha);
2599 ppl->SetHole(holeYmax, holeZmax);
5443e65e 2600 }
2601 if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
a9814c09 2602 holeYmax = x*TMath::Tan(0.5*alpha);
2603 ppl->SetHole(holeYmax, holeZmax);
5443e65e 2604 }
2605 InsertLayer(ppl);
2606 }
2607
2608 // Space between the chambers, air
2609 xin = xout; xout = xtrd + (plane + 1) * dxPlane;
029cd327 2610 steps = 5; dx = (xout - xin)/steps; rho = 1.29e-3; radLength = 36.66;
5443e65e 2611 for(Int_t i=0; i<steps; i++) {
2612 x = xin + i*dx + dx/2;
029cd327 2613 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 2614 if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
a9814c09 2615 holeYmax = x*TMath::Tan(0.5*alpha);
2616 ppl->SetHole(holeYmax, holeZmax);
5443e65e 2617 }
2618 if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
a9814c09 2619 holeYmax = x*TMath::Tan(0.5*alpha);
2620 ppl->SetHole(holeYmax, holeZmax);
5443e65e 2621 }
2622 InsertLayer(ppl);
2623 }
2624 }
2625
2626 // Space between the TRD and RICH
2627 Double_t xRICH = 500.;
2628 xin = xout; xout = xRICH;
029cd327 2629 steps = 200; dx = (xout - xin)/steps; rho = 1.29e-3; radLength = 36.66;
5443e65e 2630 for(Int_t i=0; i<steps; i++) {
2631 x = xin + i*dx + dx/2;
029cd327 2632 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 2633 InsertLayer(ppl);
2634 }
2635
2636 MapTimeBinLayers();
029cd327 2637 delete [] zc;
2638 delete [] zmax;
5443e65e 2639
2640}
2641
2642//______________________________________________________
2643
029cd327 2644Int_t AliTRDtracker::AliTRDtrackingSector::CookTimeBinIndex(Int_t plane, Int_t localTB) const
5443e65e 2645{
2646 //
2647 // depending on the digitization parameters calculates "global"
029cd327 2648 // time bin index for timebin <localTB> in plane <plane>
5443e65e 2649 //
2650
2651 Double_t dxAmp = (Double_t) fGeom->CamHght(); // Amplification region
2652 Double_t dxDrift = (Double_t) fGeom->CdrHght(); // Drift region
2653 Double_t dx = (Double_t) fPar->GetTimeBinSize();
2654
2655 Int_t tbAmp = fPar->GetTimeBefore();
2656 Int_t maxAmp = (Int_t) ((dxAmp+0.000001)/dx);
b3a5a838 2657 if(kTRUE) maxAmp = 0; // intentional until we change parameter class
5443e65e 2658 Int_t tbDrift = fPar->GetTimeMax();
2659 Int_t maxDrift = (Int_t) ((dxDrift+0.000001)/dx);
2660
029cd327 2661 Int_t tbPerPlane = TMath::Min(tbAmp,maxAmp) + TMath::Min(tbDrift,maxDrift);
5443e65e 2662
029cd327 2663 Int_t gtb = (plane+1) * tbPerPlane - localTB - 1 - TMath::Min(tbAmp,maxAmp);
5443e65e 2664
029cd327 2665 if((localTB < 0) &&
2666 (TMath::Abs(localTB) > TMath::Min(tbAmp,maxAmp))) return -1;
2667 if(localTB >= TMath::Min(tbDrift,maxDrift)) return -1;
5443e65e 2668
2669 return gtb;
2670
2671
2672}
2673
2674//______________________________________________________
2675
2676void AliTRDtracker::AliTRDtrackingSector::MapTimeBinLayers()
2677{
2678 //
2679 // For all sensitive time bins sets corresponding layer index
2680 // in the array fTimeBins
2681 //
2682
2683 Int_t index;
2684
2685 for(Int_t i = 0; i < fN; i++) {
2686 index = fLayers[i]->GetTimeBinIndex();
2687
2688 // printf("gtb %d -> pl %d -> x %f \n", index, i, fLayers[i]->GetX());
2689
2690 if(index < 0) continue;
029cd327 2691 if(index >= (Int_t) kMaxTimeBinIndex) {
5443e65e 2692 printf("*** AliTRDtracker::MapTimeBinLayers: \n");
2693 printf(" index %d exceeds allowed maximum of %d!\n",
029cd327 2694 index, kMaxTimeBinIndex-1);
5443e65e 2695 continue;
2696 }
2697 fTimeBinIndex[index] = i;
2698 }
2699
2700 Double_t x1, dx1, x2, dx2, gap;
2701
2702 for(Int_t i = 0; i < fN-1; i++) {
2703 x1 = fLayers[i]->GetX();
2704 dx1 = fLayers[i]->GetdX();
2705 x2 = fLayers[i+1]->GetX();
2706 dx2 = fLayers[i+1]->GetdX();
2707 gap = (x2 - dx2/2) - (x1 + dx1/2);
2708 if(gap < -0.01) {
2709 printf("*** warning: layers %d and %d are overlayed:\n",i,i+1);
2710 printf(" %f + %f + %f > %f\n", x1, dx1/2, dx2/2, x2);
2711 }
2712 if(gap > 0.01) {
2713 printf("*** warning: layers %d and %d have a large gap:\n",i,i+1);
2714 printf(" (%f - %f) - (%f + %f) = %f\n",
a9814c09 2715 x2, dx2/2, x1, dx1, gap);
5443e65e 2716 }
2717 }
2718}
2719
2720
2721//______________________________________________________
2722
2723
2724Int_t AliTRDtracker::AliTRDtrackingSector::GetLayerNumber(Double_t x) const
2725{
2726 //
2727 // Returns the number of time bin which in radial position is closest to <x>
2728 //
2729
2730 if(x >= fLayers[fN-1]->GetX()) return fN-1;
2731 if(x <= fLayers[0]->GetX()) return 0;
2732
2733 Int_t b=0, e=fN-1, m=(b+e)/2;
2734 for (; b<e; m=(b+e)/2) {
2735 if (x > fLayers[m]->GetX()) b=m+1;
2736 else e=m;
2737 }
2738 if(TMath::Abs(x - fLayers[m]->GetX()) >
2739 TMath::Abs(x - fLayers[m+1]->GetX())) return m+1;
2740 else return m;
2741
2742}
2743
2744//______________________________________________________
2745
2746Int_t AliTRDtracker::AliTRDtrackingSector::GetInnerTimeBin() const
2747{
2748 //
2749 // Returns number of the innermost SENSITIVE propagation layer
2750 //
2751
2752 return GetLayerNumber(0);
2753}
2754
2755//______________________________________________________
2756
2757Int_t AliTRDtracker::AliTRDtrackingSector::GetOuterTimeBin() const
2758{
2759 //
2760 // Returns number of the outermost SENSITIVE time bin
2761 //
2762
2763 return GetLayerNumber(GetNumberOfTimeBins() - 1);
46d29e70 2764}
2765
5443e65e 2766//______________________________________________________
2767
2768Int_t AliTRDtracker::AliTRDtrackingSector::GetNumberOfTimeBins() const
2769{
2770 //
2771 // Returns number of SENSITIVE time bins
2772 //
2773
2774 Int_t tb, layer;
029cd327 2775 for(tb = kMaxTimeBinIndex-1; tb >=0; tb--) {
5443e65e 2776 layer = GetLayerNumber(tb);
2777 if(layer>=0) break;
2778 }
2779 return tb+1;
2780}
2781
2782//______________________________________________________
2783
2784void AliTRDtracker::AliTRDtrackingSector::InsertLayer(AliTRDpropagationLayer* pl)
2785{
2786 //
2787 // Insert layer <pl> in fLayers array.
2788 // Layers are sorted according to X coordinate.
2789
029cd327 2790 if ( fN == ((Int_t) kMaxLayersPerSector)) {
5443e65e 2791 printf("AliTRDtrackingSector::InsertLayer(): Too many layers !\n");
2792 return;
2793 }
2794 if (fN==0) {fLayers[fN++] = pl; return;}
2795 Int_t i=Find(pl->GetX());
2796
2797 memmove(fLayers+i+1 ,fLayers+i,(fN-i)*sizeof(AliTRDpropagationLayer*));
2798 fLayers[i]=pl; fN++;
2799
2800}
2801
2802//______________________________________________________
2803
2804Int_t AliTRDtracker::AliTRDtrackingSector::Find(Double_t x) const
2805{
2806 //
2807 // Returns index of the propagation layer nearest to X
2808 //
2809
2810 if (x <= fLayers[0]->GetX()) return 0;
2811 if (x > fLayers[fN-1]->GetX()) return fN;
2812 Int_t b=0, e=fN-1, m=(b+e)/2;
2813 for (; b<e; m=(b+e)/2) {
2814 if (x > fLayers[m]->GetX()) b=m+1;
2815 else e=m;
2816 }
2817 return m;
2818}
2819
2820//______________________________________________________
2821
2822void AliTRDtracker::AliTRDpropagationLayer::GetPropagationParameters(
029cd327 2823 Double_t y, Double_t z, Double_t &dx, Double_t &rho, Double_t &radLength,
a9814c09 2824 Bool_t &lookForCluster) const
5443e65e 2825{
2826 //
029cd327 2827 // Returns radial step <dx>, density <rho>, rad. length <radLength>,
5443e65e 2828 // and sensitivity <lookForCluster> in point <y,z>
2829 //
2830
2831 dx = fdX;
2832 rho = fRho;
029cd327 2833 radLength = fX0;
5443e65e 2834 lookForCluster = kFALSE;
2835
2836 // check dead regions
2837 if(fTimeBinIndex >= 0) {
029cd327 2838 for(Int_t ch = 0; ch < (Int_t) kZones; ch++) {
5443e65e 2839 if(TMath::Abs(z - fZc[ch]) < fZmax[ch])
a9814c09 2840 lookForCluster = kTRUE;
029cd327 2841 // else { rho = 1.7; radLength = 33.0; } // G10
5443e65e 2842 }
2843 if(TMath::Abs(y) > fYmax) lookForCluster = kFALSE;
2844 if(!lookForCluster) {
029cd327 2845 // rho = 1.7; radLength = 33.0; // G10
5443e65e 2846 }
2847 }
2848
2849 // check hole
2850 if(fHole && (TMath::Abs(y - fHoleYc) < fHoleYmax) &&
2851 (TMath::Abs(z - fHoleZc) < fHoleZmax)) {
2852 lookForCluster = kFALSE;
2853 rho = fHoleRho;
029cd327 2854 radLength = fHoleX0;
5443e65e 2855 }
2856
2857 return;
2858}
2859
2860//______________________________________________________
2861
2862void AliTRDtracker::AliTRDpropagationLayer::InsertCluster(AliTRDcluster* c,
a9814c09 2863 UInt_t index) {
5443e65e 2864
2865// Insert cluster in cluster array.
2866// Clusters are sorted according to Y coordinate.
2867
2868 if(fTimeBinIndex < 0) {
2869 printf("*** attempt to insert cluster into non-sensitive time bin!\n");
2870 return;
2871 }
2872
029cd327 2873 if (fN== (Int_t) kMaxClusterPerTimeBin) {
5443e65e 2874 printf("AliTRDpropagationLayer::InsertCluster(): Too many clusters !\n");
2875 return;
2876 }
2877 if (fN==0) {fIndex[0]=index; fClusters[fN++]=c; return;}
2878 Int_t i=Find(c->GetY());
2879 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTRDcluster*));
2880 memmove(fIndex +i+1 ,fIndex +i,(fN-i)*sizeof(UInt_t));
2881 fIndex[i]=index; fClusters[i]=c; fN++;
2882}
2883
2884//______________________________________________________
2885
2886Int_t AliTRDtracker::AliTRDpropagationLayer::Find(Double_t y) const {
2887
2888// Returns index of the cluster nearest in Y
2889
2890 if (y <= fClusters[0]->GetY()) return 0;
2891 if (y > fClusters[fN-1]->GetY()) return fN;
2892 Int_t b=0, e=fN-1, m=(b+e)/2;
2893 for (; b<e; m=(b+e)/2) {
2894 if (y > fClusters[m]->GetY()) b=m+1;
2895 else e=m;
2896 }
2897 return m;
2898}
2899
fd621f36 2900//---------------------------------------------------------
5443e65e 2901
fd621f36 2902Double_t AliTRDtracker::GetTiltFactor(const AliTRDcluster* c) {
2903//
2904// Returns correction factor for tilted pads geometry
2905//
5443e65e 2906
fd621f36 2907 Double_t h01 = sin(TMath::Pi() / 180.0 * fPar->GetTiltingAngle());
2908 Int_t det = c->GetDetector();
2909 Int_t plane = fGeom->GetPlane(det);
b3a5a838 2910
2911 if((plane == 1) || (plane == 3) || (plane == 5)) h01=-h01;
b8dc2353 2912
2913 if(fNoTilt) h01 = 0;
fd621f36 2914
2915 return h01;
2916}
5443e65e 2917
c630aafd 2918
2919
2920
2921
2922