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