Do not delete the geometry, it doesn't belong to the object
[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"
a5cadd36 32#include "AliTRDpadPlane.h"
7ad19338 33#include "AliTRDgeometryDetail.h"
46d29e70 34#include "AliTRDcluster.h"
35#include "AliTRDtrack.h"
b7a0917f 36#include "AliESD.h"
46d29e70 37
7ad19338 38#include "TTreeStream.h"
39#include "TGraph.h"
46d29e70 40#include "AliTRDtracker.h"
69b55c55 41#include "TLinearFitter.h"
42#include "AliRieman.h"
8979685e 43
7ad19338 44//
46d29e70 45
46ClassImp(AliTRDtracker)
69b55c55 47ClassImp(AliTRDseed)
46d29e70 48
029cd327 49 const Float_t AliTRDtracker::fgkSeedDepth = 0.5;
50 const Float_t AliTRDtracker::fgkSeedStep = 0.10;
51 const Float_t AliTRDtracker::fgkSeedGap = 0.25;
5443e65e 52
8979685e 53 const Float_t AliTRDtracker::fgkMaxSeedDeltaZ12 = 40.;
029cd327 54 const Float_t AliTRDtracker::fgkMaxSeedDeltaZ = 25.;
55 const Float_t AliTRDtracker::fgkMaxSeedC = 0.0052;
56 const Float_t AliTRDtracker::fgkMaxSeedTan = 1.2;
69b55c55 57 const Float_t AliTRDtracker::fgkMaxSeedVertexZ = 150.;
a819a5f7 58
029cd327 59 const Double_t AliTRDtracker::fgkSeedErrorSY = 0.2;
60 const Double_t AliTRDtracker::fgkSeedErrorSY3 = 2.5;
61 const Double_t AliTRDtracker::fgkSeedErrorSZ = 0.1;
bbf92647 62
029cd327 63 const Float_t AliTRDtracker::fgkMinClustersInSeed = 0.7;
bbf92647 64
029cd327 65 const Float_t AliTRDtracker::fgkMinClustersInTrack = 0.5;
66 const Float_t AliTRDtracker::fgkMinFractionOfFoundClusters = 0.8;
bbf92647 67
029cd327 68 const Float_t AliTRDtracker::fgkSkipDepth = 0.3;
69 const Float_t AliTRDtracker::fgkLabelFraction = 0.8;
70 const Float_t AliTRDtracker::fgkWideRoad = 20.;
5443e65e 71
029cd327 72 const Double_t AliTRDtracker::fgkMaxChi2 = 12.;
a819a5f7 73
7ad19338 74// const Double_t AliTRDtracker::fgkOffset = -0.012;
75// const Double_t AliTRDtracker::fgkOffsetX = 0.35;
76// const Double_t AliTRDtracker::fgkCoef = 0.00;
77// const Double_t AliTRDtracker::fgkMean = 8.;
78// const Double_t AliTRDtracker::fgkDriftCorrection = 1.07;
79// const Double_t AliTRDtracker::fgkExB = 0.072;
80
69b55c55 81 const Double_t AliTRDtracker::fgkOffset = -0.019;
82 const Double_t AliTRDtracker::fgkOffsetX = 0.26; // "time offset"
83// const Double_t AliTRDtracker::fgkCoef = 0.0096; // angular shift
84 const Double_t AliTRDtracker::fgkCoef = 0.0106; // angular shift
7ad19338 85 const Double_t AliTRDtracker::fgkMean = 0.;
69b55c55 86 const Double_t AliTRDtracker::fgkDriftCorrection = 1.055; // drift coefficient correction
7ad19338 87 const Double_t AliTRDtracker::fgkExB = 0.072; // ExB angle - for error parameterization
88
89
90// poscorrection = fgkCoef*(GetLocalTimeBin() - fgkMean)+fgkOffset;
91
029cd327 92const Int_t AliTRDtracker::fgkFirstPlane = 5;
93const Int_t AliTRDtracker::fgkLastPlane = 17;
9c9d2487 94
89f05372 95//____________________________________________________________________
96AliTRDtracker::AliTRDtracker():AliTracker(),
97 fGeom(0),
98 fPar(0),
99 fNclusters(0),
100 fClusters(0),
101 fNseeds(0),
102 fSeeds(0),
103 fNtracks(0),
104 fTracks(0),
105 fSY2corr(0),
106 fSZ2corr(0),
107 fTimeBinsPerPlane(0),
108 fMaxGap(0),
109 fVocal(kFALSE),
110 fAddTRDseeds(kFALSE),
111 fNoTilt(kFALSE)
112{
b7a0917f 113 // Default constructor
114
89f05372 115 for(Int_t i=0;i<kTrackingSectors;i++) fTrSec[i]=0;
116 for(Int_t j=0;j<5;j++)
117 for(Int_t k=0;k<18;k++) fHoles[j][k]=kFALSE;
7ad19338 118 fDebugStreamer = 0;
89f05372 119}
46d29e70 120//____________________________________________________________________
c630aafd 121AliTRDtracker::AliTRDtracker(const TFile *geomfile):AliTracker()
46d29e70 122{
5443e65e 123 //
124 // Main constructor
125 //
46d29e70 126
c630aafd 127 //Float_t fTzero = 0;
b8dc2353 128
5443e65e 129 fAddTRDseeds = kFALSE;
5443e65e 130 fGeom = NULL;
b8dc2353 131 fNoTilt = kFALSE;
5443e65e 132
133 TDirectory *savedir=gDirectory;
134 TFile *in=(TFile*)geomfile;
135 if (!in->IsOpen()) {
136 printf("AliTRDtracker::AliTRDtracker(): geometry file is not open!\n");
137 printf(" DETAIL TRD geometry and DEFAULT TRD parameter will be used\n");
138 }
139 else {
140 in->cd();
c630aafd 141// in->ls();
5443e65e 142 fGeom = (AliTRDgeometry*) in->Get("TRDgeometry");
143 fPar = (AliTRDparameter*) in->Get("TRDparameter");
c630aafd 144// fGeom->Dump();
5443e65e 145 }
46d29e70 146
5443e65e 147 if(fGeom) {
148 // fTzero = geo->GetT0();
7c1698cb 149 // printf("Found geometry version %d on file \n", fGeom->IsVersion());
5443e65e 150 }
151 else {
c630aafd 152 printf("AliTRDtracker::AliTRDtracker(): can't find TRD geometry!\n");
3c625a9b 153 //printf("The DETAIL TRD geometry will be used\n");
154 //fGeom = new AliTRDgeometryDetail();
7ad19338 155 fGeom = new AliTRDgeometryDetail();
3c625a9b 156 fGeom->SetPHOShole();
157 fGeom->SetRICHhole();
c630aafd 158 }
159
160 if (!fPar) {
161 printf("AliTRDtracker::AliTRDtracker(): can't find TRD parameter!\n");
162 printf("The DEFAULT TRD parameter will be used\n");
7ad19338 163 fPar = new AliTRDparameter("Pica","Vyjebana");
5443e65e 164 }
7ad19338 165 fPar = new AliTRDparameter("Pica","Vyjebana");
598156ef 166 fPar->Init();
5443e65e 167
168 savedir->cd();
46d29e70 169
7ad19338 170
5443e65e 171 // fGeom->SetT0(fTzero);
0a29d0f1 172
46d29e70 173 fNclusters = 0;
174 fClusters = new TObjArray(2000);
175 fNseeds = 0;
5443e65e 176 fSeeds = new TObjArray(2000);
46d29e70 177 fNtracks = 0;
5443e65e 178 fTracks = new TObjArray(1000);
a819a5f7 179
029cd327 180 for(Int_t geomS = 0; geomS < kTrackingSectors; geomS++) {
181 Int_t trS = CookSectorIndex(geomS);
182 fTrSec[trS] = new AliTRDtrackingSector(fGeom, geomS, fPar);
3c625a9b 183 for (Int_t icham=0;icham<AliTRDgeometry::kNcham; icham++){
184 fHoles[icham][trS]=fGeom->IsHole(0,icham,geomS);
185 }
5443e65e 186 }
a5cadd36 187 AliTRDpadPlane *padPlane = fPar->GetPadPlane(0,0);
7ad19338 188 Float_t tiltAngle = TMath::Abs(padPlane->GetTiltingAngle());
189 // Float_t tiltAngle = TMath::Abs(fPar->GetTiltingAngle());
029cd327 190 if(tiltAngle < 0.1) {
b8dc2353 191 fNoTilt = kTRUE;
192 }
193
194 fSY2corr = 0.2;
195 fSZ2corr = 120.;
196
029cd327 197 if(fNoTilt && (tiltAngle > 0.1)) fSY2corr = fSY2corr + tiltAngle * 0.05;
b8dc2353 198
bbf92647 199
5443e65e 200 // calculate max gap on track
a819a5f7 201
5443e65e 202 Double_t dxAmp = (Double_t) fGeom->CamHght(); // Amplification region
203 Double_t dxDrift = (Double_t) fGeom->CdrHght(); // Drift region
a819a5f7 204
7ad19338 205 Double_t dx = fgkDriftCorrection*(Double_t) fPar->GetDriftVelocity()
ccb4315c 206 / fPar->GetSamplingFrequency();
7ad19338 207
5443e65e 208 Int_t tbAmp = fPar->GetTimeBefore();
209 Int_t maxAmp = (Int_t) ((dxAmp+0.000001)/dx);
b3a5a838 210 if(kTRUE) maxAmp = 0; // intentional until we change the parameter class
5443e65e 211 Int_t tbDrift = fPar->GetTimeMax();
8979685e 212 Int_t maxDrift = (Int_t) ((dxDrift+0.000001)/dx)+4; // MI change - take also last time bins
a819a5f7 213
8979685e 214 tbDrift = TMath::Min(tbDrift,maxDrift);
215 tbAmp = TMath::Min(tbAmp,maxAmp);
46d29e70 216
5443e65e 217 fTimeBinsPerPlane = tbAmp + tbDrift;
029cd327 218 fMaxGap = (Int_t) (fTimeBinsPerPlane * fGeom->Nplan() * fgkSkipDepth);
46d29e70 219
5443e65e 220 fVocal = kFALSE;
7ad19338 221
222 fDebugStreamer = new TTreeSRedirector("TRDdebug.root");
0a29d0f1 223
9c9d2487 224 savedir->cd();
5443e65e 225}
46d29e70 226
5443e65e 227//___________________________________________________________________
228AliTRDtracker::~AliTRDtracker()
46d29e70 229{
029cd327 230 //
231 // Destructor of AliTRDtracker
232 //
233
89f05372 234 if (fClusters) {
235 fClusters->Delete();
236 delete fClusters;
237 }
238 if (fTracks) {
239 fTracks->Delete();
240 delete fTracks;
241 }
242 if (fSeeds) {
243 fSeeds->Delete();
244 delete fSeeds;
245 }
5443e65e 246 delete fGeom;
247 delete fPar;
0a29d0f1 248
029cd327 249 for(Int_t geomS = 0; geomS < kTrackingSectors; geomS++) {
250 delete fTrSec[geomS];
5443e65e 251 }
7ad19338 252 if (fDebugStreamer) {
253 //fDebugStreamer->Close();
254 delete fDebugStreamer;
255 }
5443e65e 256}
46d29e70 257
9c9d2487 258//_____________________________________________________________________
259
9c9d2487 260Bool_t AliTRDtracker::AdjustSector(AliTRDtrack *track) {
261 //
262 // Rotates the track when necessary
263 //
264
265 Double_t alpha = AliTRDgeometry::GetAlpha();
266 Double_t y = track->GetY();
267 Double_t ymax = track->GetX()*TMath::Tan(0.5*alpha);
268
c630aafd 269 //Int_t ns = AliTRDgeometry::kNsect;
9c9d2487 270 //Int_t s=Int_t(track->GetAlpha()/alpha)%ns;
271
272 if (y > ymax) {
273 //s = (s+1) % ns;
274 if (!track->Rotate(alpha)) return kFALSE;
275 } else if (y <-ymax) {
276 //s = (s-1+ns) % ns;
277 if (!track->Rotate(-alpha)) return kFALSE;
278 }
279
280 return kTRUE;
281}
282
46d29e70 283//_____________________________________________________________________
5443e65e 284inline Double_t f1trd(Double_t x1,Double_t y1,
a9814c09 285 Double_t x2,Double_t y2,
286 Double_t x3,Double_t y3)
46d29e70 287{
0a29d0f1 288 //
46d29e70 289 // Initial approximation of the track curvature
0a29d0f1 290 //
46d29e70 291 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
292 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
293 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
294 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
295 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
296
297 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
298
299 return -xr*yr/sqrt(xr*xr+yr*yr);
300}
301
302//_____________________________________________________________________
5443e65e 303inline Double_t f2trd(Double_t x1,Double_t y1,
a9814c09 304 Double_t x2,Double_t y2,
305 Double_t x3,Double_t y3)
46d29e70 306{
0a29d0f1 307 //
5443e65e 308 // Initial approximation of the track curvature times X coordinate
309 // of the center of curvature
0a29d0f1 310 //
46d29e70 311
312 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
313 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
314 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
315 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
316 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
317
318 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
319
320 return -a/(d*y1-b)*xr/sqrt(xr*xr+yr*yr);
321}
322
323//_____________________________________________________________________
5443e65e 324inline Double_t f3trd(Double_t x1,Double_t y1,
a9814c09 325 Double_t x2,Double_t y2,
326 Double_t z1,Double_t z2)
46d29e70 327{
0a29d0f1 328 //
46d29e70 329 // Initial approximation of the tangent of the track dip angle
0a29d0f1 330 //
46d29e70 331
332 return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
333}
334
46e2d86c 335
7ad19338 336AliTRDcluster * AliTRDtracker::GetCluster(AliTRDtrack * track, Int_t plane, Int_t timebin, UInt_t &index){
46e2d86c 337 //
338 //try to find cluster in the backup list
339 //
340 AliTRDcluster * cl =0;
341 UInt_t *indexes = track->GetBackupIndexes();
342 for (UInt_t i=0;i<kMaxTimeBinIndex;i++){
343 if (indexes[i]==0) break;
344 AliTRDcluster * cli = (AliTRDcluster*)fClusters->UncheckedAt(indexes[i]);
345 if (!cli) break;
346 if (cli->GetLocalTimeBin()!=timebin) continue;
347 Int_t iplane = fGeom->GetPlane(cli->GetDetector());
348 if (iplane==plane) {
349 cl = cli;
7ad19338 350 index = indexes[i];
46e2d86c 351 break;
352 }
353 }
354 return cl;
355}
356
3c625a9b 357
358Int_t AliTRDtracker::GetLastPlane(AliTRDtrack * track){
359 //
360 //return last updated plane
361 Int_t lastplane=0;
362 UInt_t *indexes = track->GetBackupIndexes();
363 for (UInt_t i=0;i<kMaxTimeBinIndex;i++){
364 AliTRDcluster * cli = (AliTRDcluster*)fClusters->UncheckedAt(indexes[i]);
365 if (!cli) break;
366 Int_t iplane = fGeom->GetPlane(cli->GetDetector());
367 if (iplane>lastplane) {
368 lastplane = iplane;
369 }
370 }
371 return lastplane;
372}
c630aafd 373//___________________________________________________________________
374Int_t AliTRDtracker::Clusters2Tracks(AliESD* event)
375{
376 //
377 // Finds tracks within the TRD. The ESD event is expected to contain seeds
378 // at the outer part of the TRD. The seeds
379 // are found within the TRD if fAddTRDseeds is TRUE.
380 // The tracks are propagated to the innermost time bin
381 // of the TRD and the ESD event is updated
382 //
383
384 Int_t timeBins = fTrSec[0]->GetNumberOfTimeBins();
029cd327 385 Float_t foundMin = fgkMinClustersInTrack * timeBins;
c630aafd 386 Int_t nseed = 0;
387 Int_t found = 0;
388 Int_t innerTB = fTrSec[0]->GetInnerTimeBin();
389
390 Int_t n = event->GetNumberOfTracks();
391 for (Int_t i=0; i<n; i++) {
392 AliESDtrack* seed=event->GetTrack(i);
393 ULong_t status=seed->GetStatus();
394 if ( (status & AliESDtrack::kTRDout ) == 0 ) continue;
395 if ( (status & AliESDtrack::kTRDin) != 0 ) continue;
396 nseed++;
7ad19338 397
c630aafd 398 AliTRDtrack* seed2 = new AliTRDtrack(*seed);
46e2d86c 399 //seed2->ResetCovariance();
c630aafd 400 AliTRDtrack *pt = new AliTRDtrack(*seed2,seed2->GetAlpha());
401 AliTRDtrack &t=*pt;
402 FollowProlongation(t, innerTB);
403 if (t.GetNumberOfClusters() >= foundMin) {
404 UseClusters(&t);
029cd327 405 CookLabel(pt, 1-fgkLabelFraction);
c630aafd 406 // t.CookdEdx();
407 }
408 found++;
409// cout<<found<<'\r';
410
411 if(PropagateToTPC(t)) {
412 seed->UpdateTrackParams(pt, AliESDtrack::kTRDin);
413 }
414 delete seed2;
415 delete pt;
416 }
417
418 cout<<"Number of loaded seeds: "<<nseed<<endl;
419 cout<<"Number of found tracks from loaded seeds: "<<found<<endl;
420
421 // after tracks from loaded seeds are found and the corresponding
422 // clusters are used, look for additional seeds from TRD
423
424 if(fAddTRDseeds) {
425 // Find tracks for the seeds in the TRD
426 Int_t timeBins = fTrSec[0]->GetNumberOfTimeBins();
427
029cd327 428 Int_t nSteps = (Int_t) (fgkSeedDepth / fgkSeedStep);
429 Int_t gap = (Int_t) (timeBins * fgkSeedGap);
430 Int_t step = (Int_t) (timeBins * fgkSeedStep);
c630aafd 431
432 // make a first turn with tight cut on initial curvature
433 for(Int_t turn = 1; turn <= 2; turn++) {
434 if(turn == 2) {
029cd327 435 nSteps = (Int_t) (fgkSeedDepth / (3*fgkSeedStep));
436 step = (Int_t) (timeBins * (3*fgkSeedStep));
c630aafd 437 }
438 for(Int_t i=0; i<nSteps; i++) {
439 Int_t outer=timeBins-1-i*step;
440 Int_t inner=outer-gap;
441
442 nseed=fSeeds->GetEntriesFast();
443
444 MakeSeeds(inner, outer, turn);
445
446 nseed=fSeeds->GetEntriesFast();
7bed16a7 447 // printf("\n turn %d, step %d: number of seeds for TRD inward %d\n",
448 // turn, i, nseed);
c630aafd 449
450 for (Int_t i=0; i<nseed; i++) {
451 AliTRDtrack *pt=(AliTRDtrack*)fSeeds->UncheckedAt(i), &t=*pt;
452 FollowProlongation(t,innerTB);
453 if (t.GetNumberOfClusters() >= foundMin) {
454 UseClusters(&t);
029cd327 455 CookLabel(pt, 1-fgkLabelFraction);
c630aafd 456 t.CookdEdx();
457 found++;
458// cout<<found<<'\r';
459 if(PropagateToTPC(t)) {
460 AliESDtrack track;
461 track.UpdateTrackParams(pt,AliESDtrack::kTRDin);
462 event->AddTrack(&track);
c5a8e3df 463 // track.SetTRDtrack(new AliTRDtrack(*pt));
c630aafd 464 }
465 }
466 delete fSeeds->RemoveAt(i);
467 fNseeds--;
468 }
469 }
470 }
471 }
472
473 cout<<"Total number of found tracks: "<<found<<endl;
474
475 return 0;
476}
5443e65e 477
c630aafd 478
5443e65e 479
c630aafd 480//_____________________________________________________________________________
481Int_t AliTRDtracker::PropagateBack(AliESD* event) {
482 //
483 // Gets seeds from ESD event. The seeds are AliTPCtrack's found and
484 // backpropagated by the TPC tracker. Each seed is first propagated
485 // to the TRD, and then its prolongation is searched in the TRD.
486 // If sufficiently long continuation of the track is found in the TRD
487 // the track is updated, otherwise it's stored as originaly defined
488 // by the TPC tracker.
489 //
490
491 Int_t found=0;
c5a8e3df 492 Float_t foundMin = 20;
c630aafd 493 Int_t n = event->GetNumberOfTracks();
4f1c04d3 494 //
495 //Sort tracks
496 Float_t *quality =new Float_t[n];
497 Int_t *index =new Int_t[n];
c630aafd 498 for (Int_t i=0; i<n; i++) {
499 AliESDtrack* seed=event->GetTrack(i);
4f1c04d3 500 Double_t covariance[15];
501 seed->GetExternalCovariance(covariance);
502 quality[i] = covariance[0]+covariance[2];
503 }
504 TMath::Sort(n,quality,index,kFALSE);
505 //
506 for (Int_t i=0; i<n; i++) {
507 // AliESDtrack* seed=event->GetTrack(i);
508 AliESDtrack* seed=event->GetTrack(index[i]);
509
c630aafd 510 ULong_t status=seed->GetStatus();
511 if ( (status & AliESDtrack::kTPCout ) == 0 ) continue;
512 if ( (status & AliESDtrack::kTRDout) != 0 ) continue;
513
514 Int_t lbl = seed->GetLabel();
515 AliTRDtrack *track = new AliTRDtrack(*seed);
516 track->SetSeedLabel(lbl);
f4e9508c 517 seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup); //make backup
c630aafd 518 fNseeds++;
4f1c04d3 519 Float_t p4 = track->GetC();
7bed16a7 520 //
8979685e 521 Int_t expectedClr = FollowBackProlongationG(*track);
f4e9508c 522 /*
523 // only debug purpose
3c625a9b 524 if (track->GetNumberOfClusters()<expectedClr/3){
525 AliTRDtrack *track1 = new AliTRDtrack(*seed);
526 track1->SetSeedLabel(lbl);
527 FollowBackProlongation(*track1);
528 AliTRDtrack *track2= new AliTRDtrack(*seed);
529 track->SetSeedLabel(lbl);
530 FollowBackProlongation(*track2);
531 delete track1;
532 delete track2;
533 }
f4e9508c 534 */
4f1c04d3 535 if (TMath::Abs(track->GetC()-p4)/TMath::Abs(p4)<0.2 || TMath::Abs(track->GetPt())>0.8 ) {
536 //
537 //make backup for back propagation
538 //
539 Int_t foundClr = track->GetNumberOfClusters();
540 if (foundClr >= foundMin) {
541 track->CookdEdx();
8979685e 542 CookdEdxTimBin(*track);
4f1c04d3 543 CookLabel(track, 1-fgkLabelFraction);
69b55c55 544 if (track->GetBackupTrack()) UseClusters(track->GetBackupTrack());
4f1c04d3 545 if(track->GetChi2()/track->GetNumberOfClusters()<4) { // sign only gold tracks
546 if (seed->GetKinkIndex(0)==0&&TMath::Abs(track->GetPt())<1.5 ) UseClusters(track);
547 }
548 Bool_t isGold = kFALSE;
549
550 if (track->GetChi2()/track->GetNumberOfClusters()<5) { //full gold track
7ad19338 551 // seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
552 if (track->GetBackupTrack()) seed->UpdateTrackParams(track->GetBackupTrack(), AliESDtrack::kTRDbackup);
4f1c04d3 553 isGold = kTRUE;
554 }
555 if (!isGold && track->GetNCross()==0&&track->GetChi2()/track->GetNumberOfClusters()<7){ //almost gold track
7ad19338 556 // seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
557 if (track->GetBackupTrack()) seed->UpdateTrackParams(track->GetBackupTrack(), AliESDtrack::kTRDbackup);
f4e9508c 558 isGold = kTRUE;
559 }
4f1c04d3 560 if (!isGold && track->GetBackupTrack()){
561 if (track->GetBackupTrack()->GetNumberOfClusters()>foundMin&&
562 (track->GetBackupTrack()->GetChi2()/(track->GetBackupTrack()->GetNumberOfClusters()+1))<7){
563 seed->UpdateTrackParams(track->GetBackupTrack(), AliESDtrack::kTRDbackup);
564 isGold = kTRUE;
565 }
566 }
7ad19338 567 if (track->StatusForTOF()>0 &&track->fNCross==0 && Float_t(track->fN)/Float_t(track->fNExpected)>0.4){
568 seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
569 }
16d9fbba 570 }
c630aafd 571 }
8979685e 572 // Debug part of tracking
573 TTreeSRedirector& cstream = *fDebugStreamer;
574 Int_t eventNr = event->GetEventNumber();
575 if (track->GetBackupTrack()){
576 cstream<<"Tracks"<<
577 "EventNr="<<eventNr<<
578 "ESD.="<<seed<<
579 "trd.="<<track<<
580 "trdback.="<<track->GetBackupTrack()<<
581 "\n";
582 }else{
583 cstream<<"Tracks"<<
584 "EventNr="<<eventNr<<
585 "ESD.="<<seed<<
586 "trd.="<<track<<
587 "trdback.="<<track<<
588 "\n";
589 }
590 //
591 //Propagation to the TOF (I.Belikov)
3c625a9b 592 if (track->GetStop()==kFALSE){
4f1c04d3 593
b94f0a96 594 Double_t xtof=371.;
3c625a9b 595 Double_t c2=track->GetC()*xtof - track->GetEta();
4f1c04d3 596 if (TMath::Abs(c2)>=0.99) {
c5a8e3df 597 delete track;
598 continue;
599 }
4f1c04d3 600 Double_t xTOF0 = 365. ;
16d9fbba 601 PropagateToOuterPlane(*track,xTOF0);
4f1c04d3 602 //
603 //energy losses taken to the account - check one more time
604 c2=track->GetC()*xtof - track->GetEta();
605 if (TMath::Abs(c2)>=0.99) {
606 delete track;
607 continue;
608 }
609
7bed16a7 610 //
3c625a9b 611 Double_t ymax=xtof*TMath::Tan(0.5*AliTRDgeometry::GetAlpha());
612 Double_t y=track->GetYat(xtof);
613 if (y > ymax) {
7ac6fa52 614 if (!track->Rotate(AliTRDgeometry::GetAlpha())) {
615 delete track;
7bed16a7 616 continue;
7ac6fa52 617 }
3c625a9b 618 } else if (y <-ymax) {
7ac6fa52 619 if (!track->Rotate(-AliTRDgeometry::GetAlpha())) {
620 delete track;
7bed16a7 621 continue;
7ac6fa52 622 }
3c625a9b 623 }
624
625 if (track->PropagateTo(xtof)) {
eab5961e 626 seed->UpdateTrackParams(track, AliESDtrack::kTRDout);
627 for (Int_t i=0;i<kNPlane;i++) {
628 seed->SetTRDsignals(track->GetPIDsignals(i),i);
629 seed->SetTRDTimBin(track->GetPIDTimBin(i),i);
630 }
7ad19338 631 // seed->SetTRDtrack(new AliTRDtrack(*track));
3c625a9b 632 if (track->GetNumberOfClusters()>foundMin) found++;
633 }
634 }else{
635 if (track->GetNumberOfClusters()>15&&track->GetNumberOfClusters()>0.5*expectedClr){
636 seed->UpdateTrackParams(track, AliESDtrack::kTRDout);
16d9fbba 637 //seed->SetStatus(AliESDtrack::kTRDStop);
eab5961e 638 for (Int_t i=0;i<kNPlane;i++) {
639 seed->SetTRDsignals(track->GetPIDsignals(i),i);
640 seed->SetTRDTimBin(track->GetPIDTimBin(i),i);
641 }
7ad19338 642 //seed->SetTRDtrack(new AliTRDtrack(*track));
3c625a9b 643 found++;
644 }
1e9bb598 645 }
7ad19338 646 seed->SetTRDQuality(track->StatusForTOF());
8979685e 647 seed->SetTRDBudget(track->fBudget[0]);
648
d9b8978b 649 delete track;
7ad19338 650 //
1e9bb598 651 //End of propagation to the TOF
3c625a9b 652 //if (foundClr>foundMin)
653 // seed->UpdateTrackParams(track, AliESDtrack::kTRDout);
654
c630aafd 655
656 }
657
658 cerr<<"Number of seeds: "<<fNseeds<<endl;
659 cerr<<"Number of back propagated TRD tracks: "<<found<<endl;
69b55c55 660
661 // MakeSeedsMI(3,5,event); //new seeding
7ad19338 662
663
1e9bb598 664 fSeeds->Clear(); fNseeds=0;
4f1c04d3 665 delete [] index;
666 delete [] quality;
667
1e9bb598 668 return 0;
669
670}
671
672//_____________________________________________________________________________
673Int_t AliTRDtracker::RefitInward(AliESD* event)
674{
675 //
676 // Refits tracks within the TRD. The ESD event is expected to contain seeds
677 // at the outer part of the TRD.
678 // The tracks are propagated to the innermost time bin
679 // of the TRD and the ESD event is updated
680 // Origin: Thomas KUHR (Thomas.Kuhr@cern.ch)
681 //
682
683 Int_t timeBins = fTrSec[0]->GetNumberOfTimeBins();
684 Float_t foundMin = fgkMinClustersInTrack * timeBins;
685 Int_t nseed = 0;
686 Int_t found = 0;
687 Int_t innerTB = fTrSec[0]->GetInnerTimeBin();
4f1c04d3 688 AliTRDtrack seed2;
1e9bb598 689
690 Int_t n = event->GetNumberOfTracks();
691 for (Int_t i=0; i<n; i++) {
692 AliESDtrack* seed=event->GetTrack(i);
4f1c04d3 693 new(&seed2) AliTRDtrack(*seed);
694 if (seed2.GetX()<270){
695 seed->UpdateTrackParams(&seed2, AliESDtrack::kTRDbackup); // backup TPC track - only update
f4e9508c 696 continue;
697 }
698
1e9bb598 699 ULong_t status=seed->GetStatus();
0dd7d129 700 if ( (status & AliESDtrack::kTRDout ) == 0 ) {
0dd7d129 701 continue;
702 }
703 if ( (status & AliESDtrack::kTRDin) != 0 ) {
0dd7d129 704 continue;
705 }
f4e9508c 706 nseed++;
7ad19338 707// if (1/seed2.Get1Pt()>1.5&& seed2.GetX()>260.) {
708// Double_t oldx = seed2.GetX();
709// seed2.PropagateTo(500.);
710// seed2.ResetCovariance(1.);
711// seed2.PropagateTo(oldx);
712// }
713// else{
714// seed2.ResetCovariance(5.);
715// }
4f1c04d3 716
717 AliTRDtrack *pt = new AliTRDtrack(seed2,seed2.GetAlpha());
718 UInt_t * indexes2 = seed2.GetIndexes();
7ad19338 719 for (Int_t i=0;i<kNPlane;i++) {
720 pt->SetPIDsignals(seed2.GetPIDsignals(i),i);
721 pt->SetPIDTimBin(seed2.GetPIDTimBin(i),i);
722 }
eab5961e 723
46e2d86c 724 UInt_t * indexes3 = pt->GetBackupIndexes();
725 for (Int_t i=0;i<200;i++) {
726 if (indexes2[i]==0) break;
727 indexes3[i] = indexes2[i];
728 }
729 //AliTRDtrack *pt = seed2;
1e9bb598 730 AliTRDtrack &t=*pt;
8979685e 731 FollowProlongationG(t, innerTB);
1e9bb598 732 if (t.GetNumberOfClusters() >= foundMin) {
46e2d86c 733 // UseClusters(&t);
734 //CookLabel(pt, 1-fgkLabelFraction);
7ad19338 735 t.CookdEdx();
736 CookdEdxTimBin(t);
1e9bb598 737 }
738 found++;
739// cout<<found<<'\r';
740
741 if(PropagateToTPC(t)) {
0fa7dfa7 742 seed->UpdateTrackParams(pt, AliESDtrack::kTRDrefit);
7ad19338 743 for (Int_t i=0;i<kNPlane;i++) {
744 seed->SetTRDsignals(pt->GetPIDsignals(i),i);
745 seed->SetTRDTimBin(pt->GetPIDTimBin(i),i);
746 }
7bed16a7 747 }else{
748 //if not prolongation to TPC - propagate without update
749 AliTRDtrack* seed2 = new AliTRDtrack(*seed);
750 seed2->ResetCovariance(5.);
751 AliTRDtrack *pt2 = new AliTRDtrack(*seed2,seed2->GetAlpha());
752 delete seed2;
eab5961e 753 if (PropagateToTPC(*pt2)) {
754 pt2->CookdEdx(0.,1.);
755 CookdEdxTimBin(*pt2);
7bed16a7 756 seed->UpdateTrackParams(pt2, AliESDtrack::kTRDrefit);
7ad19338 757 for (Int_t i=0;i<kNPlane;i++) {
758 seed->SetTRDsignals(pt2->GetPIDsignals(i),i);
759 seed->SetTRDTimBin(pt2->GetPIDTimBin(i),i);
760 }
eab5961e 761 }
7bed16a7 762 delete pt2;
1e9bb598 763 }
1e9bb598 764 delete pt;
eab5961e 765 }
1e9bb598 766
767 cout<<"Number of loaded seeds: "<<nseed<<endl;
768 cout<<"Number of found tracks from loaded seeds: "<<found<<endl;
769
c630aafd 770 return 0;
771
772}
773
bbf92647 774
5443e65e 775//---------------------------------------------------------------------------
776Int_t AliTRDtracker::FollowProlongation(AliTRDtrack& t, Int_t rf)
777{
778 // Starting from current position on track=t this function tries
779 // to extrapolate the track up to timeBin=0 and to confirm prolongation
780 // if a close cluster is found. Returns the number of clusters
781 // expected to be found in sensitive layers
bbf92647 782
5443e65e 783 Float_t wIndex, wTB, wChi2;
784 Float_t wYrt, wYclosest, wYcorrect, wYwindow;
785 Float_t wZrt, wZclosest, wZcorrect, wZwindow;
786 Float_t wPx, wPy, wPz, wC;
029cd327 787 Double_t px, py, pz;
5443e65e 788 Float_t wSigmaC2, wSigmaTgl2, wSigmaY2, wSigmaZ2;
3c625a9b 789 Int_t lastplane = GetLastPlane(&t);
8979685e 790 Double_t dxsample = fgkDriftCorrection*(Double_t) fPar->GetDriftVelocity()
791 / fPar->GetSamplingFrequency();
5443e65e 792 Int_t trackIndex = t.GetLabel();
46d29e70 793
5443e65e 794 Int_t ns=Int_t(2*TMath::Pi()/AliTRDgeometry::GetAlpha()+0.5);
46d29e70 795
029cd327 796 Int_t tryAgain=fMaxGap;
46d29e70 797
5443e65e 798 Double_t alpha=t.GetAlpha();
c630aafd 799 alpha = TVector2::Phi_0_2pi(alpha);
46d29e70 800
5443e65e 801 Int_t s=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::kNsect;
029cd327 802 Double_t radLength, rho, x, dx, y, ymax, z;
46d29e70 803
5443e65e 804 Int_t expectedNumberOfClusters = 0;
805 Bool_t lookForCluster;
46d29e70 806
5443e65e 807 alpha=AliTRDgeometry::GetAlpha(); // note: change in meaning
46d29e70 808
5443e65e 809
810 for (Int_t nr=fTrSec[0]->GetLayerNumber(t.GetX()); nr>rf; nr--) {
811
812 y = t.GetY(); z = t.GetZ();
813
814 // first propagate to the inner surface of the current time bin
029cd327 815 fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
5443e65e 816 x = fTrSec[s]->GetLayer(nr)->GetX()-dx/2; y = t.GetY(); z = t.GetZ();
029cd327 817 if(!t.PropagateTo(x,radLength,rho)) break;
5443e65e 818 y = t.GetY();
819 ymax = x*TMath::Tan(0.5*alpha);
820 if (y > ymax) {
821 s = (s+1) % ns;
822 if (!t.Rotate(alpha)) break;
029cd327 823 if(!t.PropagateTo(x,radLength,rho)) break;
5443e65e 824 } else if (y <-ymax) {
825 s = (s-1+ns) % ns;
826 if (!t.Rotate(-alpha)) break;
029cd327 827 if(!t.PropagateTo(x,radLength,rho)) break;
5443e65e 828 }
46d29e70 829
5443e65e 830 y = t.GetY(); z = t.GetZ();
831
832 // now propagate to the middle plane of the next time bin
029cd327 833 fTrSec[s]->GetLayer(nr-1)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
5443e65e 834 x = fTrSec[s]->GetLayer(nr-1)->GetX(); y = t.GetY(); z = t.GetZ();
029cd327 835 if(!t.PropagateTo(x,radLength,rho)) break;
5443e65e 836 y = t.GetY();
837 ymax = x*TMath::Tan(0.5*alpha);
838 if (y > ymax) {
839 s = (s+1) % ns;
840 if (!t.Rotate(alpha)) break;
029cd327 841 if(!t.PropagateTo(x,radLength,rho)) break;
5443e65e 842 } else if (y <-ymax) {
843 s = (s-1+ns) % ns;
844 if (!t.Rotate(-alpha)) break;
029cd327 845 if(!t.PropagateTo(x,radLength,rho)) break;
5443e65e 846 }
46d29e70 847
46d29e70 848
5443e65e 849 if(lookForCluster) {
a819a5f7 850
5443e65e 851 expectedNumberOfClusters++;
5443e65e 852 wIndex = (Float_t) t.GetLabel();
853 wTB = nr;
46d29e70 854
029cd327 855 AliTRDpropagationLayer& timeBin=*(fTrSec[s]->GetLayer(nr-1));
46d29e70 856
5443e65e 857 Double_t sy2=ExpectedSigmaY2(x,t.GetTgl(),t.GetPt());
5443e65e 858 Double_t sz2=ExpectedSigmaZ2(x,t.GetTgl());
46d29e70 859
5443e65e 860 Double_t road;
861 if((t.GetSigmaY2() + sy2) > 0) road=10.*sqrt(t.GetSigmaY2() + sy2);
862 else return expectedNumberOfClusters;
863
864 wYrt = (Float_t) y;
865 wZrt = (Float_t) z;
866 wYwindow = (Float_t) road;
029cd327 867 t.GetPxPyPz(px,py,pz);
868 wPx = (Float_t) px;
869 wPy = (Float_t) py;
870 wPz = (Float_t) pz;
5443e65e 871 wC = (Float_t) t.GetC();
872 wSigmaC2 = (Float_t) t.GetSigmaC2();
873 wSigmaTgl2 = (Float_t) t.GetSigmaTgl2();
874 wSigmaY2 = (Float_t) t.GetSigmaY2();
875 wSigmaZ2 = (Float_t) t.GetSigmaZ2();
876 wChi2 = -1;
877
5443e65e 878
879 AliTRDcluster *cl=0;
880 UInt_t index=0;
881
029cd327 882 Double_t maxChi2=fgkMaxChi2;
5443e65e 883
884 wYclosest = 12345678;
885 wYcorrect = 12345678;
886 wZclosest = 12345678;
887 wZcorrect = 12345678;
888 wZwindow = TMath::Sqrt(2.25 * 12 * sz2);
889
890 // Find the closest correct cluster for debugging purposes
4f1c04d3 891 if (timeBin&&fVocal) {
a9814c09 892 Float_t minDY = 1000000;
029cd327 893 for (Int_t i=0; i<timeBin; i++) {
894 AliTRDcluster* c=(AliTRDcluster*)(timeBin[i]);
a9814c09 895 if((c->GetLabel(0) != trackIndex) &&
896 (c->GetLabel(1) != trackIndex) &&
897 (c->GetLabel(2) != trackIndex)) continue;
898 if(TMath::Abs(c->GetY() - y) > minDY) continue;
899 minDY = TMath::Abs(c->GetY() - y);
900 wYcorrect = c->GetY();
901 wZcorrect = c->GetZ();
902
903 Double_t h01 = GetTiltFactor(c);
904 wChi2 = t.GetPredictedChi2(c, h01);
905 }
5443e65e 906 }
46d29e70 907
5443e65e 908 // Now go for the real cluster search
a819a5f7 909
029cd327 910 if (timeBin) {
46e2d86c 911 //
912 //find cluster in history
913 cl =0;
914
915 AliTRDcluster * cl0 = timeBin[0];
916 if (!cl0) {
917 continue;
918 }
919 Int_t plane = fGeom->GetPlane(cl0->GetDetector());
3c625a9b 920 if (plane>lastplane) continue;
46e2d86c 921 Int_t timebin = cl0->GetLocalTimeBin();
7ad19338 922 AliTRDcluster * cl2= GetCluster(&t,plane, timebin,index);
3c625a9b 923 if (cl2) {
924 cl =cl2;
925 Double_t h01 = GetTiltFactor(cl);
926 maxChi2=t.GetPredictedChi2(cl,h01);
927 }
46e2d86c 928 if ((!cl) && road>fgkWideRoad) {
929 //if (t.GetNumberOfClusters()>4)
930 // cerr<<t.GetNumberOfClusters()
931 // <<"FindProlongation warning: Too broad road !\n";
932 continue;
933 }
934
a9814c09 935 if (cl) {
4f1c04d3 936
a9814c09 937 wYclosest = cl->GetY();
938 wZclosest = cl->GetZ();
939 Double_t h01 = GetTiltFactor(cl);
940
8979685e 941 //if (cl->GetNPads()<5)
942 t.SetSampledEdx(TMath::Abs(cl->GetQ()/dxsample));
3c625a9b 943 Int_t det = cl->GetDetector();
944 Int_t plane = fGeom->GetPlane(det);
46e2d86c 945
3c625a9b 946 if(!t.UpdateMI(cl,maxChi2,index,h01,plane)) {
947 //if(!t.Update(cl,maxChi2,index,h01)) {
948 //if(!tryAgain--) return 0;
a9814c09 949 }
029cd327 950 else tryAgain=fMaxGap;
a9814c09 951 }
952 else {
3c625a9b 953 //if (tryAgain==0) break;
029cd327 954 tryAgain--;
a9814c09 955 }
5443e65e 956 }
957 }
958 }
959 return expectedNumberOfClusters;
960
961
962}
a819a5f7 963
8979685e 964
965
966
967//---------------------------------------------------------------------------
968Int_t AliTRDtracker::FollowProlongationG(AliTRDtrack& t, Int_t rf)
969{
970 // Starting from current position on track=t this function tries
971 // to extrapolate the track up to timeBin=0 and to confirm prolongation
972 // if a close cluster is found. Returns the number of clusters
973 // expected to be found in sensitive layers
974 // GeoManager used to estimate mean density
975 Int_t sector;
976 Int_t lastplane = GetLastPlane(&t);
977 Int_t tryAgain=fMaxGap;
978 Double_t alpha=t.GetAlpha();
979 alpha = TVector2::Phi_0_2pi(alpha);
980 Double_t radLength, rho, x, dx;
981 //, y, ymax, z;
982 Int_t expectedNumberOfClusters = 0;
983 Double_t dxsample = fgkDriftCorrection*(Double_t) fPar->GetDriftVelocity()
984 / fPar->GetSamplingFrequency();
985 //
986 //
987 alpha=AliTRDgeometry::GetAlpha(); // note: change in meaning
988 Double_t tanmax = TMath::Tan(0.5*alpha);
989
990 for (Int_t nr=fTrSec[0]->GetLayerNumber(t.GetX()); nr>rf; nr--) {
991 //
992 // propagate track in non active layers
993 //
994 if (!(fTrSec[0]->GetLayer(nr)->IsSensitive())){
995 Double_t xyz0[3],xyz1[3],param[7],x,y,z;
996 t.GetGlobalXYZ(xyz0[0],xyz0[1],xyz0[2]); //starting global position
997 while (nr >rf && (!(fTrSec[0]->GetLayer(nr)->IsSensitive()))){
998 x = fTrSec[0]->GetLayer(nr)->GetX();
999 nr--;
1000 if (!t.GetProlongation(x,y,z)) break;
1001 if (TMath::Abs(y)>x*tanmax){
1002 nr--;
1003 break;
1004 }
1005 }
1006 nr++;
1007 x = fTrSec[0]->GetLayer(nr)->GetX();
1008 if (!t.GetProlongation(x,y,z)) break;
1009 //
1010 // minimal mean and maximal budget scan
1011 Float_t minbudget =10000;
1012 Float_t meanbudget =0;
1013 Float_t maxbudget =-1;
1014// Float_t normbudget =0;
1015// for (Int_t idy=-1;idy<=1;idy++)
1016// for (Int_t idz=-1;idz<=1;idz++){
1017 for (Int_t idy=0;idy<1;idy++)
1018 for (Int_t idz=0;idz<1;idz++){
1019 Double_t y2 = y+idy*TMath::Min(TMath::Sqrt(t.GetSigmaY2()),1.);
1020 Double_t z2 = z+idz*TMath::Min(TMath::Sqrt(t.GetSigmaY2()),1.);
1021 xyz1[0] = x*TMath::Cos(t.GetAlpha())-y2*TMath::Sin(t.GetAlpha());
1022 xyz1[1] = +x*TMath::Sin(t.GetAlpha())+y2*TMath::Cos(t.GetAlpha());
1023 xyz1[2] = z2;
1024 AliKalmanTrack::MeanMaterialBudget(xyz0,xyz1,param);
1025 Float_t budget = param[0]*param[4];
1026 meanbudget+=budget;
1027 if (budget<minbudget) minbudget=budget;
1028 if (budget>maxbudget) maxbudget=budget;
1029 }
1030 t.fBudget[0]+=minbudget;
1031 t.fBudget[1]+=meanbudget/9.;
1032 t.fBudget[2]+=minbudget;
1033 //
1034 //
1035 xyz1[0] = x*TMath::Cos(t.GetAlpha())-y*TMath::Sin(t.GetAlpha());
1036 xyz1[1] = +x*TMath::Sin(t.GetAlpha())+y*TMath::Cos(t.GetAlpha());
1037 xyz1[2] = z;
1038 AliKalmanTrack::MeanMaterialBudget(xyz0,xyz1,param);
1039
1040 t.PropagateTo(x,param[1],param[0]);
1041 t.GetGlobalXYZ(xyz0[0],xyz0[1],xyz0[2]); //end global position
1042 AdjustSector(&t);
1043 continue;
1044 }
1045 //
1046 //
1047 // stop tracking for highly inclined tracks
1048 if (!AdjustSector(&t)) break;
1049 if (TMath::Abs(t.GetSnp())>0.95) break;
1050 //
1051 // propagate and update track in active layers
1052 //
1053 Int_t nr0 = nr; //first active layer
1054 if (nr >rf && (fTrSec[0]->GetLayer(nr)->IsSensitive())){
1055 Double_t xyz0[3],xyz1[3],param[7],x,y,z;
1056 t.GetGlobalXYZ(xyz0[0],xyz0[1],xyz0[2]); //starting global position
1057 while (nr >rf && ((fTrSec[0]->GetLayer(nr)->IsSensitive()))){
1058 x = fTrSec[0]->GetLayer(nr)->GetX();
1059 nr--;
1060 if (!t.GetProlongation(x,y,z)) break;
1061 if (TMath::Abs(y)>x*tanmax){
1062 nr--;
1063 break;
1064 }
1065 }
1066 // nr++;
1067 x = fTrSec[0]->GetLayer(nr)->GetX();
1068 if (!t.GetProlongation(x,y,z)) break;
1069 xyz1[0] = x*TMath::Cos(t.GetAlpha())-y*TMath::Sin(t.GetAlpha());
1070 xyz1[1] = +x*TMath::Sin(t.GetAlpha())+y*TMath::Cos(t.GetAlpha());
1071 xyz1[2] = z;
1072 // end global position
1073 AliKalmanTrack::MeanMaterialBudget(xyz0,xyz1,param);
1074 rho = param[0];
1075 radLength = param[1]; // get mean propagation parameters
1076 }
1077 //
1078 // propagate and update
1079 if (nr0-nr<5){
1080 // short tracklet - do not update - edge effect
1081 x = fTrSec[0]->GetLayer(nr)->GetX();
1082 t.PropagateTo(x,radLength,rho);
1083 AdjustSector(&t);
1084 continue;
1085 }
1086 sector = t.GetSector();
1087 //
1088 //
1089 for (Int_t ilayer=nr0;ilayer>=nr;ilayer--) {
1090 expectedNumberOfClusters++;
1091 t.fNExpected++;
1092 if (t.fX>345) t.fNExpectedLast++;
1093 AliTRDpropagationLayer& timeBin=*(fTrSec[sector]->GetLayer(ilayer));
1094 AliTRDcluster *cl=0;
1095 UInt_t index=0;
1096 Double_t maxChi2=fgkMaxChi2;
1097 dx = (fTrSec[sector]->GetLayer(ilayer+1))->GetX()-timeBin.GetX();
1098 x = timeBin.GetX();
1099 t.PropagateTo(x,radLength,rho);
1100 // Now go for the real cluster search
1101 if (timeBin) {
1102 AliTRDcluster * cl0 = timeBin[0];
1103 if (!cl0) continue; // no clusters in given time bin
1104 Int_t plane = fGeom->GetPlane(cl0->GetDetector());
1105 if (plane>lastplane) continue;
1106 Int_t timebin = cl0->GetLocalTimeBin();
1107 AliTRDcluster * cl2= GetCluster(&t,plane, timebin,index);
1108 //
1109 if (cl2) {
1110 cl =cl2;
1111 Double_t h01 = GetTiltFactor(cl);
1112 maxChi2=t.GetPredictedChi2(cl,h01);
1113 }
1114
1115 if (cl) {
1116 // if (cl->GetNPads()<5)
1117 t.SetSampledEdx(TMath::Abs(cl->GetQ()/dxsample));
1118 Double_t h01 = GetTiltFactor(cl);
1119 Int_t det = cl->GetDetector();
1120 Int_t plane = fGeom->GetPlane(det);
1121 if (t.fX>345){
1122 t.fNLast++;
1123 t.fChi2Last+=maxChi2;
1124 }
1125 if(!t.UpdateMI(cl,maxChi2,index,h01,plane)) {
1126 if(!t.Update(cl,maxChi2,index,h01)) {
1127 //if(!tryAgain--) return 0;
1128 }
1129 }
1130 else tryAgain=fMaxGap;
1131 //
1132 }
1133 }
1134 }
1135 }
1136 return expectedNumberOfClusters;
1137
1138
1139}
1140
5443e65e 1141//___________________________________________________________________
46d29e70 1142
5443e65e 1143Int_t AliTRDtracker::FollowBackProlongation(AliTRDtrack& t)
1144{
1145 // Starting from current radial position of track <t> this function
1146 // extrapolates the track up to outer timebin and in the sensitive
1147 // layers confirms prolongation if a close cluster is found.
1148 // Returns the number of clusters expected to be found in sensitive layers
46d29e70 1149
029cd327 1150 Int_t tryAgain=fMaxGap;
46d29e70 1151
5443e65e 1152 Double_t alpha=t.GetAlpha();
9c9d2487 1153 TVector2::Phi_0_2pi(alpha);
46d29e70 1154
9c9d2487 1155 Int_t s;
4f1c04d3 1156
1157 Int_t clusters[1000];
1158 for (Int_t i=0;i<1000;i++) clusters[i]=-1;
46d29e70 1159
5443e65e 1160 Int_t outerTB = fTrSec[0]->GetOuterTimeBin();
7ad19338 1161 //Double_t radLength, rho, x, dx, y, ymax = 0, z;
1162 Double_t radLength, rho, x, dx, y, z;
5443e65e 1163 Bool_t lookForCluster;
8979685e 1164 Double_t dxsample = fgkDriftCorrection*(Double_t) fPar->GetDriftVelocity()
1165 / fPar->GetSamplingFrequency();
a819a5f7 1166
5443e65e 1167 Int_t expectedNumberOfClusters = 0;
1168 x = t.GetX();
46d29e70 1169
5443e65e 1170 alpha=AliTRDgeometry::GetAlpha(); // note: change in meaning
8979685e 1171
7ad19338 1172 // Int_t zone =0;
3c625a9b 1173 Int_t nr;
7ad19338 1174 Float_t ratio0=0;
1175 AliTRDtracklet tracklet;
1176 //
3c625a9b 1177 for (nr=fTrSec[0]->GetLayerNumber(t.GetX()); nr<outerTB+1; nr++) {
9c9d2487 1178 y = t.GetY();
1179 z = t.GetZ();
5443e65e 1180 // first propagate to the outer surface of the current time bin
46d29e70 1181
9c9d2487 1182 s = t.GetSector();
029cd327 1183 fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
9c9d2487 1184 x = fTrSec[s]->GetLayer(nr)->GetX()+dx/2;
1185 y = t.GetY();
1186 z = t.GetZ();
46d29e70 1187
029cd327 1188 if(!t.PropagateTo(x,radLength,rho)) break;
3c625a9b 1189 //
1190 // MI -fix untill correct material desription will be implemented
1191 //
7ad19338 1192 //Int_t nrotate = t.GetNRotate();
1193 if (!AdjustSector(&t)) break;
3c625a9b 1194 //
1195 //
5443e65e 1196 y = t.GetY();
9c9d2487 1197 z = t.GetZ();
9c9d2487 1198 s = t.GetSector();
a819a5f7 1199
9c9d2487 1200 // now propagate to the middle plane of the next time bin
029cd327 1201 fTrSec[s]->GetLayer(nr+1)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
7ad19338 1202// if (nrotate!=t.GetNRotate()){
1203// rho = 1000*2.7; radLength = 24.01; //TEMPORARY - aluminium in between z - will be detected using GeoModeler in future versions
1204// }
9c9d2487 1205 x = fTrSec[s]->GetLayer(nr+1)->GetX();
4f1c04d3 1206 if(!t.PropagateTo(x,radLength,rho)) break;
9c9d2487 1207 if (!AdjustSector(&t)) break;
1208 s = t.GetSector();
7ad19338 1209 // if(!t.PropagateTo(x,radLength,rho)) break;
4f1c04d3 1210
1211 if (TMath::Abs(t.GetSnp())>0.95) break;
46d29e70 1212
9c9d2487 1213 y = t.GetY();
1214 z = t.GetZ();
1215
5443e65e 1216 if(lookForCluster) {
7ad19338 1217 if (clusters[nr]==-1) {
1218 Float_t ncl = FindClusters(s,nr,nr+30,&t,clusters,tracklet);
1219 ratio0 = ncl/Float_t(fTimeBinsPerPlane);
1220 Float_t ratio1 = Float_t(t.fN+1)/Float_t(t.fNExpected+1.);
1221 if (tracklet.GetChi2()<18.&&ratio0>0.8 && ratio1>0.6 && ratio0+ratio1>1.5 && t.GetNCross()==0 && TMath::Abs(t.GetSnp())<0.85&&t.fN>20){
1222 t.MakeBackupTrack(); // make backup of the track until is gold
1223 }
1224// if (ncl>4){
1225// t.PropagateTo(tracklet.GetX());
1226// t.UpdateMI(tracklet);
1227// nr = fTrSec[0]->GetLayerNumber(t.GetX())+1;
1228// continue;
1229// }
1230 }
5443e65e 1231
4f1c04d3 1232 expectedNumberOfClusters++;
1233 t.fNExpected++;
1234 if (t.fX>345) t.fNExpectedLast++;
5443e65e 1235
029cd327 1236 AliTRDpropagationLayer& timeBin=*(fTrSec[s]->GetLayer(nr+1));
5443e65e 1237 Double_t sy2=ExpectedSigmaY2(t.GetX(),t.GetTgl(),t.GetPt());
7ad19338 1238 if((t.GetSigmaY2() + sy2) < 0) {
1239 printf("problem\n");
1240 break;
1241 }
5443e65e 1242 Double_t road = 10.*sqrt(t.GetSigmaY2() + sy2);
5443e65e 1243
029cd327 1244 if (road>fgkWideRoad) {
a9814c09 1245 return 0;
5443e65e 1246 }
1247
1248 AliTRDcluster *cl=0;
1249 UInt_t index=0;
029cd327 1250 Double_t maxChi2=fgkMaxChi2;
9c9d2487 1251
5443e65e 1252 // Now go for the real cluster search
46d29e70 1253
029cd327 1254 if (timeBin) {
7ad19338 1255
1256 if (clusters[nr+1]>0) {
4f1c04d3 1257 index = clusters[nr+1];
1258 cl = (AliTRDcluster*)GetCluster(index);
1259 Double_t h01 = GetTiltFactor(cl);
1260 maxChi2=t.GetPredictedChi2(cl,h01);
4f1c04d3 1261 }
7ad19338 1262
a9814c09 1263 if (cl) {
8979685e 1264 // if (cl->GetNPads()<5)
1265 t.SetSampledEdx(TMath::Abs(cl->GetQ()/dxsample));
a9814c09 1266 Double_t h01 = GetTiltFactor(cl);
3c625a9b 1267 Int_t det = cl->GetDetector();
1268 Int_t plane = fGeom->GetPlane(det);
4f1c04d3 1269 if (t.fX>345){
1270 t.fNLast++;
1271 t.fChi2Last+=maxChi2;
1272 }
3c625a9b 1273 if(!t.UpdateMI(cl,maxChi2,index,h01,plane)) {
4f1c04d3 1274 if(!t.Update(cl,maxChi2,index,h01)) {
7ad19338 1275 //if(!tryAgain--) return 0;
4f1c04d3 1276 }
a9814c09 1277 }
029cd327 1278 else tryAgain=fMaxGap;
7ad19338 1279 //
1280
1281 if (cl->GetLocalTimeBin()==1&&t.fN>20 && float(t.fChi2)/float(t.fN)<5){
1282 Float_t ratio1 = Float_t(t.fN)/Float_t(t.fNExpected);
1283 if (tracklet.GetChi2()<18&&ratio0>0.8&&ratio1>0.6 &&ratio0+ratio1>1.5 && t.GetNCross()==0 && TMath::Abs(t.GetSnp())<0.85){
1284 t.MakeBackupTrack(); // make backup of the track until is gold
1285 }
1286 }
1287
1288 }
a9814c09 1289 else {
7ad19338 1290 // if (tryAgain==0) break;
1291 //tryAgain--;
8979685e 1292 }
5443e65e 1293 }
1294 }
1295 }
3c625a9b 1296 if (nr<outerTB)
1297 t.SetStop(kTRUE);
1298 else
1299 t.SetStop(kFALSE);
8979685e 1300 return expectedNumberOfClusters;
1301}
1302
1303
69b55c55 1304
8979685e 1305//___________________________________________________________________
1306Int_t AliTRDtracker::FollowBackProlongationG(AliTRDtrack& t)
1307{
7ad19338 1308
8979685e 1309 // Starting from current radial position of track <t> this function
1310 // extrapolates the track up to outer timebin and in the sensitive
1311 // layers confirms prolongation if a close cluster is found.
1312 // Returns the number of clusters expected to be found in sensitive layers
1313 // Use GEO manager for material Description
1314 Int_t tryAgain=fMaxGap;
1315
1316 Double_t alpha=t.GetAlpha();
1317 TVector2::Phi_0_2pi(alpha);
1318 Int_t sector;
1319 Int_t clusters[1000];
1320 for (Int_t i=0;i<1000;i++) clusters[i]=-1;
1321 Double_t dxsample = fgkDriftCorrection*(Double_t) fPar->GetDriftVelocity()
1322 / fPar->GetSamplingFrequency();
1323 Int_t outerTB = fTrSec[0]->GetOuterTimeBin();
1324 Double_t radLength, rho, x, dx; //y, z;
1325
1326 Int_t expectedNumberOfClusters = 0;
1327 x = t.GetX();
1328
1329 alpha=AliTRDgeometry::GetAlpha(); // note: change in meaning
1330 Double_t tanmax = TMath::Tan(0.5*alpha);
1331 Int_t nr;
1332 Float_t ratio0=0;
1333 AliTRDtracklet tracklet;
1334 //
1335 //
1336 //
1337 for (nr=fTrSec[0]->GetLayerNumber(t.GetX()); nr<outerTB+1; nr++) {
1338 //
1339 // propagate track in non active layers
1340 //
1341 if (!(fTrSec[0]->GetLayer(nr)->IsSensitive())){
1342 Double_t xyz0[3],xyz1[3],param[7],x,y,z;
1343 t.GetGlobalXYZ(xyz0[0],xyz0[1],xyz0[2]); //starting global position
1344 while (nr <outerTB && (!(fTrSec[0]->GetLayer(nr)->IsSensitive()))){
1345 x = fTrSec[0]->GetLayer(nr)->GetX();
1346 nr++;
1347 if (!t.GetProlongation(x,y,z)) break;
1348 if (TMath::Abs(y)>x*tanmax){
1349 nr++;
1350 break;
1351 }
1352 }
1353 nr--;
1354 x = fTrSec[0]->GetLayer(nr)->GetX();
1355 if (!t.GetProlongation(x,y,z)) break;
1356 // minimal mean and maximal budget scan
1357 Float_t minbudget =10000;
1358 Float_t meanbudget =0;
1359 Float_t maxbudget =-1;
1360// Float_t normbudget =0;
1361// for (Int_t idy=-1;idy<=1;idy++)
1362// for (Int_t idz=-1;idz<=1;idz++){
1363 for (Int_t idy=0;idy<1;idy++)
1364 for (Int_t idz=0;idz<1;idz++){
1365 Double_t y2 = y+idy*TMath::Min(TMath::Sqrt(t.GetSigmaY2()),1.);
3a946bfb 1366 Double_t z2 = z+idz*TMath::Min(TMath::Sqrt(t.GetSigmaZ2()),1.);
8979685e 1367
1368 xyz1[0] = x*TMath::Cos(t.GetAlpha())-y2*TMath::Sin(t.GetAlpha());
1369 xyz1[1] = +x*TMath::Sin(t.GetAlpha())+y2*TMath::Cos(t.GetAlpha());
1370 xyz1[2] = z2;
1371 AliKalmanTrack::MeanMaterialBudget(xyz0,xyz1,param);
1372 Float_t budget = param[0]*param[4];
1373 meanbudget+=budget;
1374 if (budget<minbudget) minbudget=budget;
1375 if (budget>maxbudget) maxbudget=budget;
1376 }
1377 t.fBudget[0]+=minbudget;
1378 t.fBudget[1]+=meanbudget/9.;
1379 t.fBudget[2]+=minbudget;
1380
1381 xyz1[0] = x*TMath::Cos(t.GetAlpha())-y*TMath::Sin(t.GetAlpha());
1382 xyz1[1] = +x*TMath::Sin(t.GetAlpha())+y*TMath::Cos(t.GetAlpha());
1383 xyz1[2] = z;
1384 AliKalmanTrack::MeanMaterialBudget(xyz0,xyz1,param);
1385 t.PropagateTo(x,param[1],param[0]);
1386 t.GetGlobalXYZ(xyz0[0],xyz0[1],xyz0[2]); //end global position
1387 AdjustSector(&t);
1388 continue;
1389 }
1390 //
1391 //
1392 // stop tracking for highly inclined tracks
1393 if (!AdjustSector(&t)) break;
1394 if (TMath::Abs(t.GetSnp())>0.95) break;
1395 //
1396 // propagate and update track in active layers
1397 //
1398 Int_t nr0 = nr; //first active layer
1399 if (nr <outerTB && (fTrSec[0]->GetLayer(nr)->IsSensitive())){
1400 Double_t xyz0[3],xyz1[3],param[7],x,y,z;
1401 t.GetGlobalXYZ(xyz0[0],xyz0[1],xyz0[2]); //starting global position
1402 while (nr <outerTB && ((fTrSec[0]->GetLayer(nr)->IsSensitive()))){
1403 x = fTrSec[0]->GetLayer(nr)->GetX();
1404 nr++;
1405 if (!t.GetProlongation(x,y,z)) break;
1406 if (TMath::Abs(y)>(x*tanmax)){
1407 nr++;
1408 break;
1409 }
1410 }
1411 x = fTrSec[0]->GetLayer(nr)->GetX();
1412 if (!t.GetProlongation(x,y,z)) break;
1413 // minimal mean and maximal budget scan
1414 Float_t minbudget =10000;
1415 Float_t meanbudget =0;
1416 Float_t maxbudget =-1;
1417 // Float_t normbudget =0;
1418 // for (Int_t idy=-1;idy<=1;idy++)
1419 // for (Int_t idz=-1;idz<=1;idz++){
1420 for (Int_t idy=0;idy<1;idy++)
1421 for (Int_t idz=0;idz<1;idz++){
1422 Double_t y2 = y+idy*TMath::Min(TMath::Sqrt(t.GetSigmaY2()),1.);
3a946bfb 1423 Double_t z2 = z+idz*TMath::Min(TMath::Sqrt(t.GetSigmaZ2()),1.);
8979685e 1424
1425 xyz1[0] = x*TMath::Cos(t.GetAlpha())-y2*TMath::Sin(t.GetAlpha());
1426 xyz1[1] = +x*TMath::Sin(t.GetAlpha())+y2*TMath::Cos(t.GetAlpha());
1427 xyz1[2] = z2;
1428 AliKalmanTrack::MeanMaterialBudget(xyz0,xyz1,param);
1429 Float_t budget = param[0]*param[4];
1430 meanbudget+=budget;
1431 if (budget<minbudget) minbudget=budget;
1432 if (budget>maxbudget) maxbudget=budget;
1433 }
1434 t.fBudget[0]+=minbudget;
1435 t.fBudget[1]+=meanbudget/9.;
1436 t.fBudget[2]+=minbudget;
1437 //
1438 xyz1[0] = x*TMath::Cos(t.GetAlpha())-y*TMath::Sin(t.GetAlpha());
1439 xyz1[1] = +x*TMath::Sin(t.GetAlpha())+y*TMath::Cos(t.GetAlpha());
1440 xyz1[2] = z;
1441 // end global position
1442 AliKalmanTrack::MeanMaterialBudget(xyz0,xyz1,param);
1443 rho = param[0];
1444 radLength = param[1]; // get mean propagation parameters
1445 }
1446 //
1447 //
1448 if (nr-nr0<5){
1449 // short tracklet - do not update - edge effect
1450 x = fTrSec[0]->GetLayer(nr+1)->GetX();
1451 t.PropagateTo(x,radLength,rho);
1452 AdjustSector(&t);
1453 continue;
1454 }
1455 //
1456 //
1457 sector = t.GetSector();
1458 Float_t ncl = FindClusters(sector,nr0,nr,&t,clusters,tracklet);
1459 if (tracklet.GetN()-2*tracklet.GetNCross()<10) continue;
1460 ratio0 = ncl/Float_t(fTimeBinsPerPlane);
1461 Float_t ratio1 = Float_t(t.fN+1)/Float_t(t.fNExpected+1.);
1462 if (tracklet.GetChi2()<18.&&ratio0>0.8 && ratio1>0.6 && ratio0+ratio1>1.5 && t.GetNCross()==0 && TMath::Abs(t.GetSnp())<0.85&&t.fN>20){
1463 t.MakeBackupTrack(); // make backup of the track until is gold
1464 }
1465 //
1466 //
1467 for (Int_t ilayer=nr0;ilayer<=nr;ilayer++) {
1468 expectedNumberOfClusters++;
1469 t.fNExpected++;
1470 if (t.fX>345) t.fNExpectedLast++;
1471 AliTRDpropagationLayer& timeBin=*(fTrSec[sector]->GetLayer(ilayer));
1472 AliTRDcluster *cl=0;
1473 UInt_t index=0;
1474 Double_t maxChi2=fgkMaxChi2;
1475 dx = (fTrSec[sector]->GetLayer(ilayer-1))->GetX()-timeBin.GetX();
1476 x = timeBin.GetX();
1477 t.PropagateTo(x,radLength,rho);
1478 // Now go for the real cluster search
1479 if (timeBin) {
1480 if (clusters[ilayer]>0) {
1481 index = clusters[ilayer];
1482 cl = (AliTRDcluster*)GetCluster(index);
1483 Double_t h01 = GetTiltFactor(cl);
1484 maxChi2=t.GetPredictedChi2(cl,h01);
1485 }
1486
1487 if (cl) {
1488 // if (cl->GetNPads()<5)
1489 t.SetSampledEdx(TMath::Abs(cl->GetQ()/dxsample));
1490 Double_t h01 = GetTiltFactor(cl);
1491 Int_t det = cl->GetDetector();
1492 Int_t plane = fGeom->GetPlane(det);
1493 if (t.fX>345){
1494 t.fNLast++;
1495 t.fChi2Last+=maxChi2;
1496 }
1497 if(!t.UpdateMI(cl,maxChi2,index,h01,plane)) {
1498 if(!t.Update(cl,maxChi2,index,h01)) {
1499 //if(!tryAgain--) return 0;
1500 }
1501 }
1502 else tryAgain=fMaxGap;
1503 //
1504
1505 if (cl->GetLocalTimeBin()==1&&t.fN>20 && float(t.fChi2)/float(t.fN)<5){
1506 Float_t ratio1 = Float_t(t.fN)/Float_t(t.fNExpected);
1507 if (tracklet.GetChi2()<18&&ratio0>0.8&&ratio1>0.6 &&ratio0+ratio1>1.5 && t.GetNCross()==0 && TMath::Abs(t.GetSnp())<0.85){
1508 t.MakeBackupTrack(); // make backup of the track until is gold
1509 }
1510 }
1511 // reset material budget if 2 consecutive gold
1512 if (plane>0)
1513 if (t.fTracklets[plane].GetN()+t.fTracklets[plane-1].GetN()>20){
1514 t.fBudget[2] = 0;
1515 }
1516 }
1517 }
1518 }
1519 }
1520 //
1521 if (nr<outerTB)
1522 t.SetStop(kTRUE);
1523 else
1524 t.SetStop(kFALSE);
1525 return expectedNumberOfClusters;
5443e65e 1526}
1527
1e9bb598 1528//---------------------------------------------------------------------------
1529Int_t AliTRDtracker::Refit(AliTRDtrack& t, Int_t rf)
1530{
1531 // Starting from current position on track=t this function tries
1532 // to extrapolate the track up to timeBin=0 and to reuse already
1533 // assigned clusters. Returns the number of clusters
1534 // expected to be found in sensitive layers
1535 // get indices of assigned clusters for each layer
1536 // Origin: Thomas KUHR (Thomas.Kuhr@cern.ch)
8979685e 1537 Double_t dxsample = fgkDriftCorrection*(Double_t) fPar->GetDriftVelocity()
1538 / fPar->GetSamplingFrequency();
1e9bb598 1539 Int_t iCluster[90];
1540 for (Int_t i = 0; i < 90; i++) iCluster[i] = 0;
1541 for (Int_t i = 0; i < t.GetNumberOfClusters(); i++) {
1542 Int_t index = t.GetClusterIndex(i);
1543 AliTRDcluster *cl=(AliTRDcluster*) GetCluster(index);
1544 if (!cl) continue;
1545 Int_t detector=cl->GetDetector();
1546 Int_t localTimeBin=cl->GetLocalTimeBin();
1547 Int_t sector=fGeom->GetSector(detector);
1548 Int_t plane=fGeom->GetPlane(detector);
1549
1550 Int_t trackingSector = CookSectorIndex(sector);
1551
1552 Int_t gtb = fTrSec[trackingSector]->CookTimeBinIndex(plane,localTimeBin);
1553 if(gtb < 0) continue;
1554 Int_t layer = fTrSec[trackingSector]->GetLayerNumber(gtb);
1555 iCluster[layer] = index;
1556 }
1557 t.ResetClusters();
1558
1559 Int_t ns=Int_t(2*TMath::Pi()/AliTRDgeometry::GetAlpha()+0.5);
1560
1561 Double_t alpha=t.GetAlpha();
1562 alpha = TVector2::Phi_0_2pi(alpha);
1563
1564 Int_t s=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::kNsect;
1565 Double_t radLength, rho, x, dx, y, ymax, z;
1566
1567 Int_t expectedNumberOfClusters = 0;
1568 Bool_t lookForCluster;
1569
1570 alpha=AliTRDgeometry::GetAlpha(); // note: change in meaning
1571
1572
1573 for (Int_t nr=fTrSec[0]->GetLayerNumber(t.GetX()); nr>rf; nr--) {
1574
1575 y = t.GetY(); z = t.GetZ();
1576
1577 // first propagate to the inner surface of the current time bin
1578 fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
1579 x = fTrSec[s]->GetLayer(nr)->GetX()-dx/2; y = t.GetY(); z = t.GetZ();
1580 if(!t.PropagateTo(x,radLength,rho)) break;
1581 y = t.GetY();
1582 ymax = x*TMath::Tan(0.5*alpha);
1583 if (y > ymax) {
1584 s = (s+1) % ns;
1585 if (!t.Rotate(alpha)) break;
1586 if(!t.PropagateTo(x,radLength,rho)) break;
1587 } else if (y <-ymax) {
1588 s = (s-1+ns) % ns;
1589 if (!t.Rotate(-alpha)) break;
1590 if(!t.PropagateTo(x,radLength,rho)) break;
1591 }
1592
1593 y = t.GetY(); z = t.GetZ();
1594
1595 // now propagate to the middle plane of the next time bin
1596 fTrSec[s]->GetLayer(nr-1)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
1597 x = fTrSec[s]->GetLayer(nr-1)->GetX(); y = t.GetY(); z = t.GetZ();
1598 if(!t.PropagateTo(x,radLength,rho)) break;
1599 y = t.GetY();
1600 ymax = x*TMath::Tan(0.5*alpha);
1601 if (y > ymax) {
1602 s = (s+1) % ns;
1603 if (!t.Rotate(alpha)) break;
1604 if(!t.PropagateTo(x,radLength,rho)) break;
1605 } else if (y <-ymax) {
1606 s = (s-1+ns) % ns;
1607 if (!t.Rotate(-alpha)) break;
1608 if(!t.PropagateTo(x,radLength,rho)) break;
1609 }
1610
1611 if(lookForCluster) expectedNumberOfClusters++;
1612
1613 // use assigned cluster
1614 if (!iCluster[nr-1]) continue;
1615 AliTRDcluster *cl=(AliTRDcluster*)GetCluster(iCluster[nr-1]);
1616 Double_t h01 = GetTiltFactor(cl);
1617 Double_t chi2=t.GetPredictedChi2(cl, h01);
8979685e 1618 //if (cl->GetNPads()<5)
1619 t.SetSampledEdx(TMath::Abs(cl->GetQ()/dxsample));
4f1c04d3 1620
1621 //t.SetSampledEdx(cl->GetQ()/dx,t.GetNumberOfClusters());
1e9bb598 1622 t.Update(cl,chi2,iCluster[nr-1],h01);
1623 }
1624
1625 return expectedNumberOfClusters;
1626}
1627
5443e65e 1628//___________________________________________________________________
1629
1630Int_t AliTRDtracker::PropagateToOuterPlane(AliTRDtrack& t, Double_t xToGo)
1631{
1632 // Starting from current radial position of track <t> this function
1633 // extrapolates the track up to radial position <xToGo>.
1634 // Returns 1 if track reaches the plane, and 0 otherwise
1635
1636 Int_t ns=Int_t(2*TMath::Pi()/AliTRDgeometry::GetAlpha()+0.5);
1637
1638 Double_t alpha=t.GetAlpha();
1639
1640 if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
1641 if (alpha < 0. ) alpha += 2.*TMath::Pi();
1642
1643 Int_t s=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::kNsect;
1644
1645 Bool_t lookForCluster;
029cd327 1646 Double_t radLength, rho, x, dx, y, ymax, z;
5443e65e 1647
1648 x = t.GetX();
1649
1650 alpha=AliTRDgeometry::GetAlpha(); // note: change in meaning
1651
1652 Int_t plToGo = fTrSec[0]->GetLayerNumber(xToGo);
1653
1654 for (Int_t nr=fTrSec[0]->GetLayerNumber(x); nr<plToGo; nr++) {
1655
1656 y = t.GetY(); z = t.GetZ();
1657
1658 // first propagate to the outer surface of the current time bin
029cd327 1659 fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
5443e65e 1660 x = fTrSec[s]->GetLayer(nr)->GetX()+dx/2; y = t.GetY(); z = t.GetZ();
029cd327 1661 if(!t.PropagateTo(x,radLength,rho)) return 0;
5443e65e 1662 y = t.GetY();
1663 ymax = x*TMath::Tan(0.5*alpha);
1664 if (y > ymax) {
1665 s = (s+1) % ns;
1666 if (!t.Rotate(alpha)) return 0;
1667 } else if (y <-ymax) {
1668 s = (s-1+ns) % ns;
1669 if (!t.Rotate(-alpha)) return 0;
1670 }
029cd327 1671 if(!t.PropagateTo(x,radLength,rho)) return 0;
5443e65e 1672
1673 y = t.GetY(); z = t.GetZ();
1674
1675 // now propagate to the middle plane of the next time bin
029cd327 1676 fTrSec[s]->GetLayer(nr+1)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
5443e65e 1677 x = fTrSec[s]->GetLayer(nr+1)->GetX(); y = t.GetY(); z = t.GetZ();
029cd327 1678 if(!t.PropagateTo(x,radLength,rho)) return 0;
5443e65e 1679 y = t.GetY();
1680 ymax = x*TMath::Tan(0.5*alpha);
1681 if (y > ymax) {
1682 s = (s+1) % ns;
1683 if (!t.Rotate(alpha)) return 0;
1684 } else if (y <-ymax) {
1685 s = (s-1+ns) % ns;
1686 if (!t.Rotate(-alpha)) return 0;
1687 }
029cd327 1688 if(!t.PropagateTo(x,radLength,rho)) return 0;
5443e65e 1689 }
1690 return 1;
1691}
1692
1693//___________________________________________________________________
1694
1695Int_t AliTRDtracker::PropagateToTPC(AliTRDtrack& t)
1696{
1697 // Starting from current radial position of track <t> this function
1698 // extrapolates the track up to radial position of the outermost
1699 // padrow of the TPC.
1700 // Returns 1 if track reaches the TPC, and 0 otherwise
1701
c630aafd 1702 //Int_t ns=Int_t(2*TMath::Pi()/AliTRDgeometry::GetAlpha()+0.5);
5443e65e 1703
1704 Double_t alpha=t.GetAlpha();
c630aafd 1705 alpha = TVector2::Phi_0_2pi(alpha);
5443e65e 1706
1707 Int_t s=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::kNsect;
1708
1709 Bool_t lookForCluster;
029cd327 1710 Double_t radLength, rho, x, dx, y, /*ymax,*/ z;
5443e65e 1711
1712 x = t.GetX();
1713
1714 alpha=AliTRDgeometry::GetAlpha(); // note: change in meaning
5443e65e 1715 Int_t plTPC = fTrSec[0]->GetLayerNumber(246.055);
1716
1717 for (Int_t nr=fTrSec[0]->GetLayerNumber(x); nr>plTPC; nr--) {
1718
9c9d2487 1719 y = t.GetY();
1720 z = t.GetZ();
5443e65e 1721
1722 // first propagate to the outer surface of the current time bin
029cd327 1723 fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
9c9d2487 1724 x = fTrSec[s]->GetLayer(nr)->GetX()-dx/2;
1725
029cd327 1726 if(!t.PropagateTo(x,radLength,rho)) return 0;
9c9d2487 1727 AdjustSector(&t);
029cd327 1728 if(!t.PropagateTo(x,radLength,rho)) return 0;
5443e65e 1729
9c9d2487 1730 y = t.GetY();
1731 z = t.GetZ();
5443e65e 1732
1733 // now propagate to the middle plane of the next time bin
029cd327 1734 fTrSec[s]->GetLayer(nr-1)->GetPropagationParameters(y,z,dx,rho,radLength,lookForCluster);
9c9d2487 1735 x = fTrSec[s]->GetLayer(nr-1)->GetX();
1736
029cd327 1737 if(!t.PropagateTo(x,radLength,rho)) return 0;
9c9d2487 1738 AdjustSector(&t);
029cd327 1739 if(!t.PropagateTo(x,radLength,rho)) return 0;
c5a8e3df 1740 }
5443e65e 1741 return 1;
1742}
1743
c630aafd 1744//_____________________________________________________________________________
1745Int_t AliTRDtracker::LoadClusters(TTree *cTree)
1746{
1747 // Fills clusters into TRD tracking_sectors
1748 // Note that the numbering scheme for the TRD tracking_sectors
1749 // differs from that of TRD sectors
4f1c04d3 1750 cout<<"\n Read Sectors clusters"<<endl;
c630aafd 1751 if (ReadClusters(fClusters,cTree)) {
1752 Error("LoadClusters","Problem with reading the clusters !");
1753 return 1;
1754 }
1755 Int_t ncl=fClusters->GetEntriesFast();
b7a0917f 1756 fNclusters=ncl;
c630aafd 1757 cout<<"\n LoadSectors: sorting "<<ncl<<" clusters"<<endl;
1758
1759 UInt_t index;
3c625a9b 1760 for (Int_t ichamber=0;ichamber<5;ichamber++)
1761 for (Int_t isector=0;isector<18;isector++){
1762 fHoles[ichamber][isector]=kTRUE;
1763 }
1764
1765
c630aafd 1766 while (ncl--) {
1767// printf("\r %d left ",ncl);
1768 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(ncl);
029cd327 1769 Int_t detector=c->GetDetector();
1770 Int_t localTimeBin=c->GetLocalTimeBin();
c630aafd 1771 Int_t sector=fGeom->GetSector(detector);
1772 Int_t plane=fGeom->GetPlane(detector);
3c625a9b 1773
029cd327 1774 Int_t trackingSector = CookSectorIndex(sector);
3c625a9b 1775 if (c->GetLabel(0)>0){
1776 Int_t chamber = fGeom->GetChamber(detector);
1777 fHoles[chamber][trackingSector]=kFALSE;
1778 }
c630aafd 1779
029cd327 1780 Int_t gtb = fTrSec[trackingSector]->CookTimeBinIndex(plane,localTimeBin);
c630aafd 1781 if(gtb < 0) continue;
029cd327 1782 Int_t layer = fTrSec[trackingSector]->GetLayerNumber(gtb);
c630aafd 1783
1784 index=ncl;
69b55c55 1785 //
1786 // apply pos correction
1787 Float_t poscor = fgkCoef*(c->GetLocalTimeBin() - fgkMean)+fgkOffset;
1788 c->SetY(c->GetY()-poscor);
029cd327 1789 fTrSec[trackingSector]->GetLayer(layer)->InsertCluster(c,index);
c630aafd 1790 }
7bed16a7 1791 // printf("\r\n");
3c625a9b 1792 //
1793 //
1794 /*
1795 for (Int_t isector=0;isector<18;isector++){
1796 for (Int_t ichamber=0;ichamber<5;ichamber++)
1797 if (fHoles[ichamber][isector]!=fGeom->IsHole(0,ichamber,17-isector))
1798 printf("Problem \t%d\t%d\t%d\t%d\n",isector,ichamber,fHoles[ichamber][isector],
1799 fGeom->IsHole(0,ichamber,17-isector));
1800 }
1801 */
c630aafd 1802 return 0;
1803}
1804
5443e65e 1805//_____________________________________________________________________________
b7a0917f 1806void AliTRDtracker::UnloadClusters()
5443e65e 1807{
1808 //
1809 // Clears the arrays of clusters and tracks. Resets sectors and timebins
1810 //
1811
1812 Int_t i, nentr;
1813
1814 nentr = fClusters->GetEntriesFast();
1815 for (i = 0; i < nentr; i++) delete fClusters->RemoveAt(i);
b7a0917f 1816 fNclusters = 0;
5443e65e 1817
1818 nentr = fSeeds->GetEntriesFast();
1819 for (i = 0; i < nentr; i++) delete fSeeds->RemoveAt(i);
1820
1821 nentr = fTracks->GetEntriesFast();
1822 for (i = 0; i < nentr; i++) delete fTracks->RemoveAt(i);
1823
1824 Int_t nsec = AliTRDgeometry::kNsect;
1825
1826 for (i = 0; i < nsec; i++) {
1827 for(Int_t pl = 0; pl < fTrSec[i]->GetNumberOfLayers(); pl++) {
1828 fTrSec[i]->GetLayer(pl)->Clear();
1829 }
1830 }
1831
1832}
1833
1834//__________________________________________________________________________
1835void AliTRDtracker::MakeSeeds(Int_t inner, Int_t outer, Int_t turn)
1836{
1837 // Creates track seeds using clusters in timeBins=i1,i2
1838
1839 if(turn > 2) {
1840 cerr<<"MakeSeeds: turn "<<turn<<" exceeds the limit of 2"<<endl;
1841 return;
1842 }
1843
1844 Double_t x[5], c[15];
69b55c55 1845 Int_t maxSec=AliTRDgeometry::kNsect;
5443e65e 1846 Double_t alpha=AliTRDgeometry::GetAlpha();
1847 Double_t shift=AliTRDgeometry::GetAlpha()/2.;
1848 Double_t cs=cos(alpha), sn=sin(alpha);
69b55c55 1849 Double_t cs2=cos(2.*alpha), sn2=sin(2.*alpha);
5443e65e 1850 Int_t i2 = fTrSec[0]->GetLayerNumber(inner);
69b55c55 1851 Int_t i1 = fTrSec[0]->GetLayerNumber(outer);
5443e65e 1852 Double_t x1 =fTrSec[0]->GetX(i1);
1853 Double_t xx2=fTrSec[0]->GetX(i2);
1854
029cd327 1855 for (Int_t ns=0; ns<maxSec; ns++) {
5443e65e 1856
029cd327 1857 Int_t nl2 = *(fTrSec[(ns-2+maxSec)%maxSec]->GetLayer(i2));
1858 Int_t nl=(*fTrSec[(ns-1+maxSec)%maxSec]->GetLayer(i2));
5443e65e 1859 Int_t nm=(*fTrSec[ns]->GetLayer(i2));
029cd327 1860 Int_t nu=(*fTrSec[(ns+1)%maxSec]->GetLayer(i2));
1861 Int_t nu2=(*fTrSec[(ns+2)%maxSec]->GetLayer(i2));
5443e65e 1862
1863 AliTRDpropagationLayer& r1=*(fTrSec[ns]->GetLayer(i1));
1864
1865 for (Int_t is=0; is < r1; is++) {
1866 Double_t y1=r1[is]->GetY(), z1=r1[is]->GetZ();
1867
1868 for (Int_t js=0; js < nl2+nl+nm+nu+nu2; js++) {
a9814c09 1869
1870 const AliTRDcluster *cl;
1871 Double_t x2, y2, z2;
1872 Double_t x3=0., y3=0.;
1873
1874 if (js<nl2) {
1875 if(turn != 2) continue;
029cd327 1876 AliTRDpropagationLayer& r2=*(fTrSec[(ns-2+maxSec)%maxSec]->GetLayer(i2));
a9814c09 1877 cl=r2[js];
1878 y2=cl->GetY(); z2=cl->GetZ();
1879
1880 x2= xx2*cs2+y2*sn2;
1881 y2=-xx2*sn2+y2*cs2;
1882 }
1883 else if (js<nl2+nl) {
1884 if(turn != 1) continue;
029cd327 1885 AliTRDpropagationLayer& r2=*(fTrSec[(ns-1+maxSec)%maxSec]->GetLayer(i2));
a9814c09 1886 cl=r2[js-nl2];
1887 y2=cl->GetY(); z2=cl->GetZ();
1888
1889 x2= xx2*cs+y2*sn;
1890 y2=-xx2*sn+y2*cs;
1891 }
1892 else if (js<nl2+nl+nm) {
1893 if(turn != 1) continue;
1894 AliTRDpropagationLayer& r2=*(fTrSec[ns]->GetLayer(i2));
1895 cl=r2[js-nl2-nl];
1896 x2=xx2; y2=cl->GetY(); z2=cl->GetZ();
1897 }
1898 else if (js<nl2+nl+nm+nu) {
1899 if(turn != 1) continue;
029cd327 1900 AliTRDpropagationLayer& r2=*(fTrSec[(ns+1)%maxSec]->GetLayer(i2));
a9814c09 1901 cl=r2[js-nl2-nl-nm];
1902 y2=cl->GetY(); z2=cl->GetZ();
1903
1904 x2=xx2*cs-y2*sn;
1905 y2=xx2*sn+y2*cs;
1906 }
1907 else {
1908 if(turn != 2) continue;
029cd327 1909 AliTRDpropagationLayer& r2=*(fTrSec[(ns+2)%maxSec]->GetLayer(i2));
a9814c09 1910 cl=r2[js-nl2-nl-nm-nu];
1911 y2=cl->GetY(); z2=cl->GetZ();
1912
1913 x2=xx2*cs2-y2*sn2;
1914 y2=xx2*sn2+y2*cs2;
1915 }
1916
029cd327 1917 if(TMath::Abs(z1-z2) > fgkMaxSeedDeltaZ12) continue;
a9814c09 1918
1919 Double_t zz=z1 - z1/x1*(x1-x2);
1920
029cd327 1921 if (TMath::Abs(zz-z2)>fgkMaxSeedDeltaZ) continue;
a9814c09 1922
1923 Double_t d=(x2-x1)*(0.-y2)-(0.-x2)*(y2-y1);
1924 if (d==0.) {cerr<<"TRD MakeSeeds: Straight seed !\n"; continue;}
1925
1926 x[0]=y1;
1927 x[1]=z1;
1928 x[4]=f1trd(x1,y1,x2,y2,x3,y3);
1929
029cd327 1930 if (TMath::Abs(x[4]) > fgkMaxSeedC) continue;
a9814c09 1931
1932 x[2]=f2trd(x1,y1,x2,y2,x3,y3);
1933
1934 if (TMath::Abs(x[4]*x1-x[2]) >= 0.99999) continue;
1935
1936 x[3]=f3trd(x1,y1,x2,y2,z1,z2);
1937
029cd327 1938 if (TMath::Abs(x[3]) > fgkMaxSeedTan) continue;
a9814c09 1939
1940 Double_t a=asin(x[2]);
1941 Double_t zv=z1 - x[3]/x[4]*(a+asin(x[4]*x1-x[2]));
1942
029cd327 1943 if (TMath::Abs(zv)>fgkMaxSeedVertexZ) continue;
a9814c09 1944
1945 Double_t sy1=r1[is]->GetSigmaY2(), sz1=r1[is]->GetSigmaZ2();
1946 Double_t sy2=cl->GetSigmaY2(), sz2=cl->GetSigmaZ2();
029cd327 1947 Double_t sy3=fgkSeedErrorSY3, sy=fgkSeedErrorSY, sz=fgkSeedErrorSZ;
a9814c09 1948
1949 // Tilt changes
1950 Double_t h01 = GetTiltFactor(r1[is]);
029cd327 1951 Double_t xuFactor = 100.;
b8dc2353 1952 if(fNoTilt) {
1953 h01 = 0;
029cd327 1954 xuFactor = 1;
b8dc2353 1955 }
1956
fd621f36 1957 sy1=sy1+sz1*h01*h01;
b3a5a838 1958 Double_t syz=sz1*(-h01);
a9814c09 1959 // end of tilt changes
1960
b3a5a838 1961 Double_t f40=(f1trd(x1,y1+sy,x2,y2,x3,y3)-x[4])/sy;
1962 Double_t f42=(f1trd(x1,y1,x2,y2+sy,x3,y3)-x[4])/sy;
1963 Double_t f43=(f1trd(x1,y1,x2,y2,x3,y3+sy)-x[4])/sy;
1964 Double_t f20=(f2trd(x1,y1+sy,x2,y2,x3,y3)-x[2])/sy;
1965 Double_t f22=(f2trd(x1,y1,x2,y2+sy,x3,y3)-x[2])/sy;
1966 Double_t f23=(f2trd(x1,y1,x2,y2,x3,y3+sy)-x[2])/sy;
1967 Double_t f30=(f3trd(x1,y1+sy,x2,y2,z1,z2)-x[3])/sy;
1968 Double_t f31=(f3trd(x1,y1,x2,y2,z1+sz,z2)-x[3])/sz;
1969 Double_t f32=(f3trd(x1,y1,x2,y2+sy,z1,z2)-x[3])/sy;
1970 Double_t f34=(f3trd(x1,y1,x2,y2,z1,z2+sz)-x[3])/sz;
1971
a9814c09 1972
b3a5a838 1973 c[0]=sy1;
a9814c09 1974 // c[1]=0.; c[2]=sz1;
029cd327 1975 c[1]=syz; c[2]=sz1*xuFactor;
b3a5a838 1976 c[3]=f20*sy1; c[4]=0.; c[5]=f20*sy1*f20+f22*sy2*f22+f23*sy3*f23;
1977 c[6]=f30*sy1; c[7]=f31*sz1; c[8]=f30*sy1*f20+f32*sy2*f22;
1978 c[9]=f30*sy1*f30+f31*sz1*f31+f32*sy2*f32+f34*sz2*f34;
1979 c[10]=f40*sy1; c[11]=0.; c[12]=f40*sy1*f20+f42*sy2*f22+f43*sy3*f23;
1980 c[13]=f30*sy1*f40+f32*sy2*f42;
1981 c[14]=f40*sy1*f40+f42*sy2*f42+f43*sy3*f43;
a9814c09 1982
1983 UInt_t index=r1.GetIndex(is);
1984
1985 AliTRDtrack *track=new AliTRDtrack(r1[is],index,x,c,x1,ns*alpha+shift);
1986
1987 Int_t rc=FollowProlongation(*track, i2);
1988
1989 if ((rc < 1) ||
1990 (track->GetNumberOfClusters() <
029cd327 1991 (outer-inner)*fgkMinClustersInSeed)) delete track;
a9814c09 1992 else {
1993 fSeeds->AddLast(track); fNseeds++;
e24ea474 1994// cerr<<"\r found seed "<<fNseeds;
a9814c09 1995 }
5443e65e 1996 }
1997 }
1998 }
1999}
7ad19338 2000//__________________________________________________________________________
69b55c55 2001void AliTRDtracker::MakeSeedsMI(Int_t /*inner*/, Int_t /*outer*/, AliESD * esd)
7ad19338 2002{
2003 //
2004 // Creates seeds using clusters between position inner plane and outer plane
2005 //
69b55c55 2006 const Double_t maxtheta = 1;
2007 const Double_t maxphi = 2.0;
2008 //
2009 const Double_t kRoad0y = 6; // road for middle cluster
2010 const Double_t kRoad0z = 8.5; // road for middle cluster
2011 //
2012 const Double_t kRoad1y = 2; // road in y for seeded cluster
2013 const Double_t kRoad1z = 20; // road in z for seeded cluster
2014 //
2015 const Double_t kRoad2y = 3; // road in y for extrapolated cluster
2016 const Double_t kRoad2z = 20; // road in z for extrapolated cluster
2017 const Int_t maxseed = 3000;
2018 Int_t maxSec=AliTRDgeometry::kNsect;
7ad19338 2019
69b55c55 2020 //
2021 // linear fitters in planes
2022 TLinearFitter fitterTC(2,"hyp2"); // fitting with tilting pads - kz fixed - kz= Z/x, + vertex const
2023 TLinearFitter fitterT2(4,"hyp4"); // fitting with tilting pads - kz not fixed
2024 fitterTC.StoreData(kTRUE);
2025 fitterT2.StoreData(kTRUE);
2026 AliRieman rieman(1000); // rieman fitter
2027 AliRieman rieman2(1000); // rieman fitter
7ad19338 2028 //
2029 // find the maximal and minimal layer for the planes
7ad19338 2030 //
2031 Int_t layers[6][2];
69b55c55 2032 AliTRDpropagationLayer* reflayers[6];
7ad19338 2033 for (Int_t i=0;i<6;i++){layers[i][0]=10000; layers[i][1]=0;}
7ad19338 2034 for (Int_t ns=0;ns<maxSec;ns++){
2035 for (Int_t ilayer=0;ilayer<fTrSec[ns]->GetNumberOfLayers();ilayer++){
2036 AliTRDpropagationLayer& layer=*(fTrSec[ns]->GetLayer(ilayer));
2037 if (layer==0) continue;
2038 Int_t det = layer[0]->GetDetector();
2039 Int_t plane = fGeom->GetPlane(det);
2040 if (ilayer<layers[plane][0]) layers[plane][0] = ilayer;
2041 if (ilayer>layers[plane][1]) layers[plane][1] = ilayer;
2042 }
2043 }
2044 //
69b55c55 2045 AliTRDpadPlane *padPlane = fPar->GetPadPlane(0,0);
2046 Double_t h01 = TMath::Tan(-TMath::Pi() / 180.0 * padPlane->GetTiltingAngle());
2047 Double_t hL[6]; // tilting angle
2048 Double_t xcl[6]; // x - position of reference cluster
2049 Double_t ycl[6]; // y - position of reference cluster
2050 Double_t zcl[6]; // z - position of reference cluster
2051 AliTRDcluster *cl[6]={0,0,0,0,0,0}; // seeding clusters
2052 Float_t padlength[6]={10,10,10,10,10,10}; //current pad-length
2053 Double_t chi2R =0, chi2Z=0;
2054 Double_t chi2RF =0, chi2ZF=0;
2055 //
2056 Int_t nclusters; // total number of clusters
2057 for (Int_t i=0;i<6;i++) {hL[i]=h01; if (i%2==1) hL[i]*=-1.;}
2058 //
2059 //
2060 // registered seed
2061 AliTRDseed *pseed = new AliTRDseed[maxseed*6];
2062 AliTRDseed *seed[maxseed];
2063 for (Int_t iseed=0;iseed<maxseed;iseed++) seed[iseed]= &pseed[iseed*6];
2064 AliTRDseed *cseed = seed[0];
2065 //
2066 Double_t seedquality[maxseed];
2067 Double_t seedquality2[maxseed];
2068 Double_t seedparams[maxseed][7];
2069 Int_t seedlayer[maxseed];
2070 Int_t registered =0;
2071 Int_t sort[maxseed];
2072 //
2073 // seeding part
2074 //
2075 for (Int_t ns = 0; ns<maxSec; ns++){ //loop over sectors
2076 //for (Int_t ns = 0; ns<5; ns++){ //loop over sectors
2077 registered = 0; // reset registerd seed counter
2078 cseed = seed[registered];
2079 Float_t iter=0;
2080 for (Int_t sLayer=2; sLayer>=0;sLayer--){
2081 //for (Int_t dseed=5;dseed<15; dseed+=3){ //loop over central seeding time bins
2082 iter+=1.;
2083 Int_t dseed = 5+Int_t(iter)*3;
2084 // Initialize seeding layers
2085 for (Int_t ilayer=0;ilayer<6;ilayer++){
2086 reflayers[ilayer] = fTrSec[ns]->GetLayer(layers[ilayer][1]-dseed);
2087 xcl[ilayer] = reflayers[ilayer]->GetX();
2088 }
7ad19338 2089 //
69b55c55 2090 Double_t xref = (xcl[sLayer+1] + xcl[sLayer+2])*0.5;
2091 AliTRDpropagationLayer& layer0=*reflayers[sLayer+0];
2092 AliTRDpropagationLayer& layer1=*reflayers[sLayer+1];
2093 AliTRDpropagationLayer& layer2=*reflayers[sLayer+2];
2094 AliTRDpropagationLayer& layer3=*reflayers[sLayer+3];
2095 //
2096 Int_t maxn3 = layer3;
2097 for (Int_t icl3=0;icl3<maxn3;icl3++){
2098 AliTRDcluster *cl3 = layer3[icl3];
2099 if (!cl3) continue;
2100 padlength[sLayer+3] = TMath::Sqrt(cl3->GetSigmaZ2()*12.);
2101 ycl[sLayer+3] = cl3->GetY();
2102 zcl[sLayer+3] = cl3->GetZ();
2103 Float_t yymin0 = ycl[sLayer+3] - 1- maxphi *(xcl[sLayer+3]-xcl[sLayer+0]);
2104 Float_t yymax0 = ycl[sLayer+3] + 1+ maxphi *(xcl[sLayer+3]-xcl[sLayer+0]);
2105 Int_t maxn0 = layer0; //
2106 for (Int_t icl0=layer0.Find(yymin0);icl0<maxn0;icl0++){
2107 AliTRDcluster *cl0 = layer0[icl0];
2108 if (!cl0) continue;
2109 if (cl3->IsUsed()&&cl0->IsUsed()) continue;
2110 ycl[sLayer+0] = cl0->GetY();
2111 zcl[sLayer+0] = cl0->GetZ();
2112 if ( ycl[sLayer+0]>yymax0) break;
2113 Double_t tanphi = (ycl[sLayer+3]-ycl[sLayer+0])/(xcl[sLayer+3]-xcl[sLayer+0]);
2114 if (TMath::Abs(tanphi)>maxphi) continue;
2115 Double_t tantheta = (zcl[sLayer+3]-zcl[sLayer+0])/(xcl[sLayer+3]-xcl[sLayer+0]);
2116 if (TMath::Abs(tantheta)>maxtheta) continue;
2117 padlength[sLayer+0] = TMath::Sqrt(cl0->GetSigmaZ2()*12.);
2118 //
2119 // expected position in 1 layer
2120 Double_t y1exp = ycl[sLayer+0]+(tanphi) *(xcl[sLayer+1]-xcl[sLayer+0]);
2121 Double_t z1exp = zcl[sLayer+0]+(tantheta)*(xcl[sLayer+1]-xcl[sLayer+0]);
2122 Float_t yymin1 = y1exp - kRoad0y-tanphi;
2123 Float_t yymax1 = y1exp + kRoad0y+tanphi;
2124 Int_t maxn1 = layer1; //
2125 //
2126 for (Int_t icl1=layer1.Find(yymin1);icl1<maxn1;icl1++){
2127 AliTRDcluster *cl1 = layer1[icl1];
2128 if (!cl1) continue;
2129 Int_t nusedCl = 0;
2130 if (cl3->IsUsed()) nusedCl++;
2131 if (cl0->IsUsed()) nusedCl++;
2132 if (cl1->IsUsed()) nusedCl++;
2133 if (nusedCl>1) continue;
2134 ycl[sLayer+1] = cl1->GetY();
2135 zcl[sLayer+1] = cl1->GetZ();
2136 if ( ycl[sLayer+1]>yymax1) break;
2137 if (TMath::Abs(ycl[sLayer+1]-y1exp)>kRoad0y+tanphi) continue;
2138 if (TMath::Abs(zcl[sLayer+1]-z1exp)>kRoad0z) continue;
2139 padlength[sLayer+1] = TMath::Sqrt(cl1->GetSigmaZ2()*12.);
2140 //
2141 Double_t y2exp = ycl[sLayer+0]+(tanphi) *(xcl[sLayer+2]-xcl[sLayer+0])+(ycl[sLayer+1]-y1exp);
2142 Double_t z2exp = zcl[sLayer+0]+(tantheta)*(xcl[sLayer+2]-xcl[sLayer+0]);
2143 Int_t index2 = layer2.FindNearestCluster(y2exp,z2exp,kRoad1y, kRoad1z);
2144 if (index2<=0) continue;
2145 AliTRDcluster *cl2 = (AliTRDcluster*)GetCluster(index2);
2146 padlength[sLayer+2] = TMath::Sqrt(cl2->GetSigmaZ2()*12.);
2147 ycl[sLayer+2] = cl2->GetY();
2148 zcl[sLayer+2] = cl2->GetZ();
2149 if (TMath::Abs(cl2->GetZ()-z2exp)>kRoad0z) continue;
2150 //
2151 rieman.Reset();
2152 rieman.AddPoint(xcl[sLayer+0],ycl[sLayer+0],zcl[sLayer+0],1,10);
2153 rieman.AddPoint(xcl[sLayer+1],ycl[sLayer+1],zcl[sLayer+1],1,10);
2154 rieman.AddPoint(xcl[sLayer+3],ycl[sLayer+3],zcl[sLayer+3],1,10);
2155 rieman.AddPoint(xcl[sLayer+2],ycl[sLayer+2],zcl[sLayer+2],1,10);
2156 rieman.Update();
2157 //
2158 // reset fitter
2159 for (Int_t iLayer=0;iLayer<6;iLayer++){
2160 cseed[iLayer].Reset();
2161 }
2162 chi2Z =0.; chi2R=0.;
2163 for (Int_t iLayer=0;iLayer<4;iLayer++){
2164 cseed[sLayer+iLayer].fZref[0] = rieman.GetZat(xcl[sLayer+iLayer]);
2165 chi2Z += (cseed[sLayer+iLayer].fZref[0]- zcl[sLayer+iLayer])*
2166 (cseed[sLayer+iLayer].fZref[0]- zcl[sLayer+iLayer]);
2167 cseed[sLayer+iLayer].fZref[1] = rieman.GetDZat(xcl[sLayer+iLayer]);
2168 cseed[sLayer+iLayer].fYref[0] = rieman.GetYat(xcl[sLayer+iLayer]);
2169 chi2R += (cseed[sLayer+iLayer].fYref[0]- ycl[sLayer+iLayer])*
2170 (cseed[sLayer+iLayer].fYref[0]- ycl[sLayer+iLayer]);
2171 cseed[sLayer+iLayer].fYref[1] = rieman.GetDYat(xcl[sLayer+iLayer]);
2172 }
2173 if (TMath::Sqrt(chi2R)>1./iter) continue;
2174 if (TMath::Sqrt(chi2Z)>7./iter) continue;
2175 //
2176 //
2177 //
2178 Float_t minmax[2]={-100,100};
2179 for (Int_t iLayer=0;iLayer<4;iLayer++){
2180 Float_t max = zcl[sLayer+iLayer]+padlength[sLayer+iLayer]*0.5+1 -cseed[sLayer+iLayer].fZref[0];
2181 if (max<minmax[1]) minmax[1]=max;
2182 Float_t min = zcl[sLayer+iLayer]-padlength[sLayer+iLayer]*0.5-1 -cseed[sLayer+iLayer].fZref[0];
2183 if (min>minmax[0]) minmax[0]=min;
2184 }
2185 Bool_t isFake = kFALSE;
2186 if (cl0->GetLabel(0)!=cl3->GetLabel(0)) isFake = kTRUE;
2187 if (cl1->GetLabel(0)!=cl3->GetLabel(0)) isFake = kTRUE;
2188 if (cl2->GetLabel(0)!=cl3->GetLabel(0)) isFake = kTRUE;
2189 if ((!isFake) || (icl3%10)==0 ){ //debugging print
2190 TTreeSRedirector& cstream = *fDebugStreamer;
2191 cstream<<"Seeds0"<<
2192 "isFake="<<isFake<<
2193 "Cl0.="<<cl0<<
2194 "Cl1.="<<cl1<<
2195 "Cl2.="<<cl2<<
2196 "Cl3.="<<cl3<<
2197 "Xref="<<xref<<
2198 "X0="<<xcl[sLayer+0]<<
2199 "X1="<<xcl[sLayer+1]<<
2200 "X2="<<xcl[sLayer+2]<<
2201 "X3="<<xcl[sLayer+3]<<
2202 "Y2exp="<<y2exp<<
2203 "Z2exp="<<z2exp<<
2204 "Chi2R="<<chi2R<<
2205 "Chi2Z="<<chi2Z<<
2206 "Seed0.="<<&cseed[sLayer+0]<<
2207 "Seed1.="<<&cseed[sLayer+1]<<
2208 "Seed2.="<<&cseed[sLayer+2]<<
2209 "Seed3.="<<&cseed[sLayer+3]<<
2210 "Zmin="<<minmax[0]<<
2211 "Zmax="<<minmax[1]<<
2212 "\n";
2213 }
2214
2215 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2216 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2217 //<<<<<<<<<<<<<<<<<< FIT SEEDING PART <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2218 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2219 cl[sLayer+0] = cl0;
2220 cl[sLayer+1] = cl1;
2221 cl[sLayer+2] = cl2;
2222 cl[sLayer+3] = cl3;
2223 Bool_t isOK=kTRUE;
2224 for (Int_t jLayer=0;jLayer<4;jLayer++){
2225 cseed[sLayer+jLayer].fTilt = hL[sLayer+jLayer];
2226 cseed[sLayer+jLayer].fPadLength = padlength[sLayer+jLayer];
2227 cseed[sLayer+jLayer].fX0 = xcl[sLayer+jLayer];
2228 for (Int_t iter=0; iter<2; iter++){
2229 //
2230 // in iteration 0 we try only one pad-row
2231 // if quality not sufficient we try 2 pad-rows - about 5% of tracks cross 2 pad-rows
2232 //
2233 AliTRDseed tseed = cseed[sLayer+jLayer];
2234 Float_t roadz = padlength[sLayer+jLayer]*0.5;
2235 if (iter>0) roadz = padlength[sLayer+jLayer];
2236 //
2237 Float_t quality =10000;
2238 for (Int_t iTime=2;iTime<20;iTime++){
2239 AliTRDpropagationLayer& layer = *(fTrSec[ns]->GetLayer(layers[sLayer+jLayer][1]-iTime));
2240 Double_t dxlayer= layer.GetX()-xcl[sLayer+jLayer];
2241 Double_t zexp = cl[sLayer+jLayer]->GetZ() ;
2242 if (iter>0){
2243 // try 2 pad-rows in second iteration
2244 zexp = tseed.fZref[0]+ tseed.fZref[1]*dxlayer;
2245 if (zexp>cl[sLayer+jLayer]->GetZ()) zexp = cl[sLayer+jLayer]->GetZ()+padlength[sLayer+jLayer]*0.5;
2246 if (zexp<cl[sLayer+jLayer]->GetZ()) zexp = cl[sLayer+jLayer]->GetZ()-padlength[sLayer+jLayer]*0.5;
2247 }
2248 //
2249 Double_t yexp = tseed.fYref[0]+
2250 tseed.fYref[1]*dxlayer;
2251 Int_t index = layer.FindNearestCluster(yexp,zexp,kRoad1y, roadz);
2252 if (index<=0) continue;
2253 AliTRDcluster *cl = (AliTRDcluster*)GetCluster(index);
2254 //
2255 tseed.fIndexes[iTime] = index;
2256 tseed.fClusters[iTime] = cl; // register cluster
2257 tseed.fX[iTime] = dxlayer; // register cluster
2258 tseed.fY[iTime] = cl->GetY(); // register cluster
2259 tseed.fZ[iTime] = cl->GetZ(); // register cluster
2260 }
2261 tseed.Update();
2262 //count the number of clusters and distortions into quality
2263 Float_t dangle = tseed.fYfit[1]-tseed.fYref[1];
2264 Float_t tquality = (18-tseed.fN2)/2. + TMath::Abs(dangle)/0.1+
2265 TMath::Abs(tseed.fYfit[0]-tseed.fYref[0])/0.2+
2266 2.*TMath::Abs(tseed.fMeanz-tseed.fZref[0])/padlength[jLayer];
2267 if (iter==0 && tseed.isOK()) {
2268 cseed[sLayer+jLayer] = tseed;
2269 quality = tquality;
2270 if (tquality<5) break;
2271 }
2272 if (tseed.isOK() && tquality<quality)
2273 cseed[sLayer+jLayer] = tseed;
2274 }
2275 if (!cseed[sLayer+jLayer].isOK()){
2276 isOK = kFALSE;
2277 break;
2278 }
2279 cseed[sLayer+jLayer].CookLabels();
2280 cseed[sLayer+jLayer].UpdateUsed();
2281 nusedCl+= cseed[sLayer+jLayer].fNUsed;
2282 if (nusedCl>25){
2283 isOK = kFALSE;
2284 break;
2285 }
2286 }
2287 //
2288 if (!isOK) continue;
2289 nclusters=0;
2290 for (Int_t iLayer=0;iLayer<4;iLayer++){
2291 if (cseed[sLayer+iLayer].isOK()){
2292 nclusters+=cseed[sLayer+iLayer].fN2;
2293 }
2294 }
2295 //
2296 // iteration 0
2297 rieman.Reset();
2298 for (Int_t iLayer=0;iLayer<4;iLayer++){
2299 rieman.AddPoint(xcl[sLayer+iLayer],cseed[sLayer+iLayer].fYfitR[0],
2300 cseed[sLayer+iLayer].fZProb,1,10);
2301 }
2302 rieman.Update();
2303 //
2304 //
2305 chi2R =0; chi2Z=0;
2306 for (Int_t iLayer=0;iLayer<4;iLayer++){
2307 cseed[sLayer+iLayer].fYref[0] = rieman.GetYat(xcl[sLayer+iLayer]);
2308 chi2R += (cseed[sLayer+iLayer].fYref[0]-cseed[sLayer+iLayer].fYfitR[0])*
2309 (cseed[sLayer+iLayer].fYref[0]-cseed[sLayer+iLayer].fYfitR[0]);
2310 cseed[sLayer+iLayer].fYref[1] = rieman.GetDYat(xcl[sLayer+iLayer]);
2311 cseed[sLayer+iLayer].fZref[0] = rieman.GetZat(xcl[sLayer+iLayer]);
2312 chi2Z += (cseed[sLayer+iLayer].fZref[0]- cseed[sLayer+iLayer].fMeanz)*
2313 (cseed[sLayer+iLayer].fZref[0]- cseed[sLayer+iLayer].fMeanz);
2314 cseed[sLayer+iLayer].fZref[1] = rieman.GetDZat(xcl[sLayer+iLayer]);
2315 }
2316 Double_t curv = rieman.GetC();
2317 //
2318 // likelihoods
2319 //
2320 Double_t sumda =
2321 TMath::Abs(cseed[sLayer+0].fYfitR[1]- cseed[sLayer+0].fYref[1])+
2322 TMath::Abs(cseed[sLayer+1].fYfitR[1]- cseed[sLayer+1].fYref[1])+
2323 TMath::Abs(cseed[sLayer+2].fYfitR[1]- cseed[sLayer+2].fYref[1])+
2324 TMath::Abs(cseed[sLayer+3].fYfitR[1]- cseed[sLayer+3].fYref[1]);
2325 Double_t likea = TMath::Exp(-sumda*10.6);
2326 Double_t likechi2 = 0.0000000001;
2327 if (chi2R<0.5) likechi2+=TMath::Exp(-TMath::Sqrt(chi2R)*7.73);
2328 Double_t likechi2z = TMath::Exp(-chi2Z*0.088)/TMath::Exp(-chi2Z*0.019);
2329 Double_t likeN = TMath::Exp(-(72-nclusters)*0.19);
2330 Double_t like = likea*likechi2*likechi2z*likeN;
2331 //
2332 Double_t likePrimY = TMath::Exp(-TMath::Abs(cseed[sLayer+0].fYref[1]-130*curv)*1.9);
2333 Double_t likePrimZ = TMath::Exp(-TMath::Abs(cseed[sLayer+0].fZref[1]-
2334 cseed[sLayer+0].fZref[0]/xcl[sLayer+0])*5.9);
2335 Double_t likePrim = TMath::Max(likePrimY*likePrimZ,0.0005);
2336
2337 seedquality[registered] = like;
2338 seedlayer[registered] = sLayer;
2339 if (TMath::Log(0.000000000000001+like)<-15) continue;
2340 AliTRDseed seedb[6];
2341 for (Int_t iLayer=0;iLayer<6;iLayer++){
2342 seedb[iLayer] = cseed[iLayer];
2343 }
2344 //
2345 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2346 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2347 //<<<<<<<<<<<<<<< FULL TRACK FIT PART <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2348 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2349 //
2350 Int_t nlayers = 0;
2351 Int_t nusedf = 0;
2352 Int_t findable = 0;
2353 //
2354 // add new layers - avoid long extrapolation
2355 //
2356 Int_t tLayer[2]={0,0};
2357 if (sLayer==2) {tLayer[0]=1; tLayer[1]=0;}
2358 if (sLayer==1) {tLayer[0]=5; tLayer[1]=0;}
2359 if (sLayer==0) {tLayer[0]=4; tLayer[1]=5;}
2360 //
2361 for (Int_t iLayer=0;iLayer<2;iLayer++){
2362 Int_t jLayer = tLayer[iLayer]; // set tracking layer
2363 cseed[jLayer].Reset();
2364 cseed[jLayer].fTilt = hL[jLayer];
2365 cseed[jLayer].fPadLength = padlength[jLayer];
2366 cseed[jLayer].fX0 = xcl[jLayer];
2367 // get pad length and rough cluster
2368 Int_t indexdummy = reflayers[jLayer]->FindNearestCluster(cseed[jLayer].fYref[0],
2369 cseed[jLayer].fZref[0],kRoad2y,kRoad2z);
2370 if (indexdummy<=0) continue;
2371 AliTRDcluster *cldummy = (AliTRDcluster*)GetCluster(indexdummy);
2372 padlength[jLayer] = TMath::Sqrt(cldummy->GetSigmaZ2()*12.);
2373 }
2374 AliTRDseed::FitRiemanTilt(cseed, kTRUE);
2375 //
2376 for (Int_t iLayer=0;iLayer<2;iLayer++){
2377 Int_t jLayer = tLayer[iLayer]; // set tracking layer
2378 if ( (jLayer==0) && !(cseed[1].isOK())) continue; // break not allowed
2379 if ( (jLayer==5) && !(cseed[4].isOK())) continue; // break not allowed
2380 Float_t zexp = cseed[jLayer].fZref[0];
2381 Double_t zroad = padlength[jLayer]*0.5+1.;
2382 //
2383 //
2384 for (Int_t iter=0;iter<2;iter++){
2385 AliTRDseed tseed = cseed[jLayer];
2386 Float_t quality = 10000;
2387 for (Int_t iTime=2;iTime<20;iTime++){
2388 AliTRDpropagationLayer& layer = *(fTrSec[ns]->GetLayer(layers[jLayer][1]-iTime));
2389 Double_t dxlayer = layer.GetX()-xcl[jLayer];
2390 Double_t yexp = tseed.fYref[0]+tseed.fYref[1]*dxlayer;
2391 Float_t yroad = kRoad1y;
2392 Int_t index = layer.FindNearestCluster(yexp,zexp, yroad, zroad);
2393 if (index<=0) continue;
2394 AliTRDcluster *cl = (AliTRDcluster*)GetCluster(index);
2395 //
2396 tseed.fIndexes[iTime] = index;
2397 tseed.fClusters[iTime] = cl; // register cluster
2398 tseed.fX[iTime] = dxlayer; // register cluster
2399 tseed.fY[iTime] = cl->GetY(); // register cluster
2400 tseed.fZ[iTime] = cl->GetZ(); // register cluster
2401 }
2402 tseed.Update();
2403 if (tseed.isOK()){
2404 Float_t dangle = tseed.fYfit[1]-tseed.fYref[1];
2405 Float_t tquality = (18-tseed.fN2)/2. + TMath::Abs(dangle)/0.1+
2406 TMath::Abs(tseed.fYfit[0]-tseed.fYref[0])/0.2+
2407 2.*TMath::Abs(tseed.fMeanz-tseed.fZref[0])/padlength[jLayer];
2408 //
2409 if (tquality<quality){
2410 cseed[jLayer]=tseed;
2411 quality = tquality;
2412 }
2413 }
2414 zroad*=2.;
2415 }
2416 if ( cseed[jLayer].isOK()){
2417 cseed[jLayer].CookLabels();
2418 cseed[jLayer].UpdateUsed();
2419 nusedf+= cseed[jLayer].fNUsed;
2420 AliTRDseed::FitRiemanTilt(cseed, kTRUE);
2421 }
2422 }
2423 //
2424 //
2425 // make copy
2426 AliTRDseed bseed[6];
2427 for (Int_t jLayer=0;jLayer<6;jLayer++){
2428 bseed[jLayer] = cseed[jLayer];
2429 }
2430 Float_t lastquality = 10000;
2431 Float_t lastchi2 = 10000;
2432 Float_t chi2 = 1000;
2433
2434 //
2435 for (Int_t iter =0; iter<4;iter++){
2436 //
2437 // sort tracklets according "quality", try to "improve" 4 worst
2438 //
2439 Float_t sumquality = 0;
2440 Float_t squality[6];
2441 Int_t sortindexes[6];
2442 for (Int_t jLayer=0;jLayer<6;jLayer++){
2443 if (bseed[jLayer].isOK()){
2444 AliTRDseed &tseed = bseed[jLayer];
2445 Double_t zcor = tseed.fTilt*(tseed.fZProb-tseed.fZref[0]);
2446 Float_t dangle = tseed.fYfit[1]-tseed.fYref[1];
2447 Float_t tquality = (18-tseed.fN2)/2. + TMath::Abs(dangle)/0.1+
2448 TMath::Abs(tseed.fYfit[0]-(tseed.fYref[0]-zcor))/0.2+
2449 2.*TMath::Abs(tseed.fMeanz-tseed.fZref[0])/padlength[jLayer];
2450 squality[jLayer] = tquality;
2451 }
2452 else squality[jLayer]=-1;
2453 sumquality +=squality[jLayer];
2454 }
2455
2456 if (sumquality>=lastquality || chi2>lastchi2) break;
2457 lastquality = sumquality;
2458 lastchi2 = chi2;
2459 if (iter>0){
2460 for (Int_t jLayer=0;jLayer<6;jLayer++){
2461 cseed[jLayer] = bseed[jLayer];
2462 }
2463 }
2464 TMath::Sort(6,squality,sortindexes,kFALSE);
2465 //
2466 //
2467 for (Int_t jLayer=5;jLayer>1;jLayer--){
2468 Int_t bLayer = sortindexes[jLayer];
2469 AliTRDseed tseed = bseed[bLayer];
2470 for (Int_t iTime=2;iTime<20;iTime++){
2471 AliTRDpropagationLayer& layer = *(fTrSec[ns]->GetLayer(layers[bLayer][1]-iTime));
2472 Double_t dxlayer= layer.GetX()-xcl[bLayer];
2473 //
2474 Double_t zexp = tseed.fZref[0];
2475 Double_t zcor = tseed.fTilt*(tseed.fZProb-tseed.fZref[0]);
2476 //
2477 Float_t roadz = padlength[bLayer]+1;
2478 if (TMath::Abs(tseed.fZProb-zexp)> padlength[bLayer]*0.5) {roadz = padlength[bLayer]*0.5;}
2479 if (tseed.fZfit[1]*tseed.fZref[1]<0) {roadz = padlength[bLayer]*0.5;}
2480 if (TMath::Abs(tseed.fZProb-zexp)<0.1*padlength[bLayer]) {
2481 zexp = tseed.fZProb;
2482 roadz = padlength[bLayer]*0.5;
2483 }
2484 //
2485 Double_t yexp = tseed.fYref[0]+
2486 tseed.fYref[1]*dxlayer-zcor;
2487 Int_t index = layer.FindNearestCluster(yexp,zexp,kRoad1y, roadz);
2488 if (index<=0) continue;
2489 AliTRDcluster *cl = (AliTRDcluster*)GetCluster(index);
2490 //
2491 tseed.fIndexes[iTime] = index;
2492 tseed.fClusters[iTime] = cl; // register cluster
2493 tseed.fX[iTime] = dxlayer; // register cluster
2494 tseed.fY[iTime] = cl->GetY(); // register cluster
2495 tseed.fZ[iTime] = cl->GetZ(); // register cluster
2496 }
2497 tseed.Update();
2498 if (tseed.isOK()) {
2499 Float_t dangle = tseed.fYfit[1]-tseed.fYref[1];
2500 Double_t zcor = tseed.fTilt*(tseed.fZProb-tseed.fZref[0]);
2501 //
2502 Float_t tquality = (18-tseed.fN2)/2. + TMath::Abs(dangle)/0.1+
2503 TMath::Abs(tseed.fYfit[0]-(tseed.fYref[0]-zcor))/0.2+
2504 2.*TMath::Abs(tseed.fMeanz-tseed.fZref[0])/padlength[jLayer];
2505 //
2506 if (tquality<squality[bLayer])
2507 bseed[bLayer] = tseed;
2508 }
2509 }
2510 chi2 = AliTRDseed::FitRiemanTilt(bseed, kTRUE);
2511 }
2512 //
2513 //
2514 //
2515 nclusters = 0;
2516 nlayers = 0;
2517 findable = 0;
2518 for (Int_t iLayer=0;iLayer<6;iLayer++) {
2519 if (TMath::Abs(cseed[iLayer].fYref[0]/cseed[iLayer].fX0)<0.15)
2520 findable++;
2521 if (cseed[iLayer].isOK()){
2522 nclusters+=cseed[iLayer].fN2;
2523 nlayers++;
2524 }
2525 }
2526 if (nlayers<3) continue;
2527 rieman.Reset();
2528 for (Int_t iLayer=0;iLayer<6;iLayer++){
2529 if (cseed[iLayer].isOK()) rieman.AddPoint(xcl[iLayer],cseed[iLayer].fYfitR[0],
2530 cseed[iLayer].fZProb,1,10);
2531 }
2532 rieman.Update();
2533 //
2534 chi2RF =0;
2535 chi2ZF =0;
2536 for (Int_t iLayer=0;iLayer<6;iLayer++){
2537 if (cseed[iLayer].isOK()){
2538 cseed[iLayer].fYref[0] = rieman.GetYat(xcl[iLayer]);
2539 chi2RF += (cseed[iLayer].fYref[0]-cseed[iLayer].fYfitR[0])*
2540 (cseed[iLayer].fYref[0]-cseed[iLayer].fYfitR[0]);
2541 cseed[iLayer].fYref[1] = rieman.GetDYat(xcl[iLayer]);
2542 cseed[iLayer].fZref[0] = rieman.GetZat(xcl[iLayer]);
2543 chi2ZF += (cseed[iLayer].fZref[0]- cseed[iLayer].fMeanz)*
2544 (cseed[iLayer].fZref[0]- cseed[iLayer].fMeanz);
2545 cseed[iLayer].fZref[1] = rieman.GetDZat(xcl[iLayer]);
2546 }
2547 }
2548 chi2RF/=TMath::Max((nlayers-3.),1.);
2549 chi2ZF/=TMath::Max((nlayers-3.),1.);
2550 curv = rieman.GetC();
2551
2552 //
2553
2554 Double_t xref2 = (xcl[2]+xcl[3])*0.5; // middle of the chamber
2555 Double_t dzmf = rieman.GetDZat(xref2);
2556 Double_t zmf = rieman.GetZat(xref2);
2557 //
2558 // fit hyperplane
2559 //
2560 Int_t npointsT =0;
2561 fitterTC.ClearPoints();
2562 fitterT2.ClearPoints();
2563 rieman2.Reset();
2564 for (Int_t iLayer=0; iLayer<6;iLayer++){
2565 if (!cseed[iLayer].isOK()) continue;
2566 for (Int_t itime=0;itime<25;itime++){
2567 if (!cseed[iLayer].fUsable[itime]) continue;
2568 Double_t x = cseed[iLayer].fX[itime]+cseed[iLayer].fX0-xref2; // x relative to the midle chamber
2569 Double_t y = cseed[iLayer].fY[itime];
2570 Double_t z = cseed[iLayer].fZ[itime];
2571 // ExB correction to the correction
2572 // tilted rieman
2573 //
2574 Double_t uvt[6];
2575 Double_t x2 = cseed[iLayer].fX[itime]+cseed[iLayer].fX0; // global x
2576 //
2577 Double_t t = 1./(x2*x2+y*y);
2578 uvt[1] = t; // t
2579 uvt[0] = 2.*x2*uvt[1]; // u
2580 //
2581 uvt[2] = 2.0*hL[iLayer]*uvt[1];
2582 uvt[3] = 2.0*hL[iLayer]*x*uvt[1];
2583 uvt[4] = 2.0*(y+hL[iLayer]*z)*uvt[1];
2584 //
2585 Double_t error = 2*0.2*uvt[1];
2586 fitterT2.AddPoint(uvt,uvt[4],error);
2587 //
2588 // constrained rieman
2589 //
2590 z =cseed[iLayer].fZ[itime];
2591 uvt[0] = 2.*x2*t; // u
2592 uvt[1] = 2*hL[iLayer]*x2*uvt[1];
2593 uvt[2] = 2*(y+hL[iLayer]*(z-GetZ()))*t;
2594 fitterTC.AddPoint(uvt,uvt[2],error);
2595 //
2596 rieman2.AddPoint(x2,y,z,1,10);
2597 npointsT++;
2598 }
2599 }
2600 rieman2.Update();
2601 fitterTC.Eval();
2602 fitterT2.Eval();
2603 Double_t rpolz0 = fitterT2.GetParameter(3);
2604 Double_t rpolz1 = fitterT2.GetParameter(4);
2605 //
2606 // linear fitter - not possible to make boundaries
2607 // non accept non possible z and dzdx combination
2608 //
2609 Bool_t acceptablez =kTRUE;
2610 for (Int_t iLayer=0; iLayer<6;iLayer++){
2611 if (cseed[iLayer].isOK()){
2612 Double_t zT2 = rpolz0+rpolz1*(xcl[iLayer] - xref2);
2613 if (TMath::Abs(cseed[iLayer].fZProb-zT2)>padlength[iLayer]*0.5+1)
2614 acceptablez = kFALSE;
2615 }
2616 }
2617 if (!acceptablez){
2618 fitterT2.FixParameter(3,zmf);
2619 fitterT2.FixParameter(4,dzmf);
2620 fitterT2.Eval();
2621 fitterT2.ReleaseParameter(3);
2622 fitterT2.ReleaseParameter(4);
2623 rpolz0 = fitterT2.GetParameter(3);
2624 rpolz1 = fitterT2.GetParameter(4);
2625 }
2626 //
2627 Double_t chi2TR = fitterT2.GetChisquare()/Float_t(npointsT);
2628 Double_t chi2TC = fitterTC.GetChisquare()/Float_t(npointsT);
2629 //
2630 Double_t polz1c = fitterTC.GetParameter(2);
2631 Double_t polz0c = polz1c*xref2;
2632 //
2633 Double_t aC = fitterTC.GetParameter(0);
2634 Double_t bC = fitterTC.GetParameter(1);
2635 Double_t CC = aC/TMath::Sqrt(bC*bC+1.); // curvature
2636 //
2637 Double_t aR = fitterT2.GetParameter(0);
2638 Double_t bR = fitterT2.GetParameter(1);
2639 Double_t dR = fitterT2.GetParameter(2);
2640 Double_t CR = 1+bR*bR-dR*aR;
2641 Double_t dca = 0.;
2642 if (CR>0){
2643 dca = -dR/(TMath::Sqrt(1+bR*bR-dR*aR)+TMath::Sqrt(1+bR*bR));
2644 CR = aR/TMath::Sqrt(CR);
2645 }
2646 //
2647 Double_t chi2ZT2=0, chi2ZTC=0;
2648 for (Int_t iLayer=0; iLayer<6;iLayer++){
2649 if (cseed[iLayer].isOK()){
2650 Double_t zT2 = rpolz0+rpolz1*(xcl[iLayer] - xref2);
2651 Double_t zTC = polz0c+polz1c*(xcl[iLayer] - xref2);
2652 chi2ZT2 += TMath::Abs(cseed[iLayer].fMeanz-zT2);
2653 chi2ZTC += TMath::Abs(cseed[iLayer].fMeanz-zTC);
2654 }
2655 }
2656 chi2ZT2/=TMath::Max((nlayers-3.),1.);
2657 chi2ZTC/=TMath::Max((nlayers-3.),1.);
2658 //
2659 //
2660 //
2661 AliTRDseed::FitRiemanTilt(cseed, kTRUE);
2662 Float_t sumdaf = 0;
2663 for (Int_t iLayer=0;iLayer<6;iLayer++){
2664 if (cseed[iLayer].isOK())
2665 sumdaf += TMath::Abs((cseed[iLayer].fYfit[1]-cseed[iLayer].fYref[1])/cseed[iLayer].fSigmaY2);
2666 }
2667 sumdaf /= Float_t (nlayers-2.);
2668 //
2669 // likelihoods for full track
2670 //
2671 Double_t likezf = TMath::Exp(-chi2ZF*0.14);
2672 Double_t likechi2C = TMath::Exp(-chi2TC*0.677);
2673 Double_t likechi2TR = TMath::Exp(-chi2TR*0.78);
2674 Double_t likeaf = TMath::Exp(-sumdaf*3.23);
2675 seedquality2[registered] = likezf*likechi2TR*likeaf;
2676// Bool_t isGold = kFALSE;
2677//
2678// if (nlayers == 6 && TMath::Log(0.000000001+seedquality2[index])<-5.) isGold =kTRUE; // gold
2679// if (nlayers == findable && TMath::Log(0.000000001+seedquality2[index])<-4.) isGold =kTRUE; // gold
2680// if (isGold &&nusedf<10){
2681// for (Int_t jLayer=0;jLayer<6;jLayer++){
2682// if ( seed[index][jLayer].isOK()&&TMath::Abs(seed[index][jLayer].fYfit[1]-seed[index][jLayer].fYfit[1])<0.1)
2683// seed[index][jLayer].UseClusters(); //sign gold
2684// }
2685// }
2686 //
2687 //
2688 //
2689 Int_t index0=0;
2690 if (!cseed[0].isOK()){
2691 index0 = 1;
2692 if (!cseed[1].isOK()) index0 = 2;
2693 }
2694 seedparams[registered][0] = cseed[index0].fX0;
2695 seedparams[registered][1] = cseed[index0].fYref[0];
2696 seedparams[registered][2] = cseed[index0].fZref[0];
2697 seedparams[registered][5] = CR;
2698 seedparams[registered][3] = cseed[index0].fX0*CR - TMath::Sin(TMath::ATan(cseed[0].fYref[1]));
2699 seedparams[registered][4] = cseed[index0].fZref[1]/
2700 TMath::Sqrt(1+cseed[index0].fYref[1]*cseed[index0].fYref[1]);
2701 seedparams[registered][6] = ns;
2702 //
2703 //
2704 Int_t labels[12], outlab[24];
2705 Int_t nlab=0;
2706 for (Int_t iLayer=0;iLayer<6;iLayer++){
2707 if (!cseed[iLayer].isOK()) continue;
2708 if (cseed[iLayer].fLabels[0]>=0) {
2709 labels[nlab] = cseed[iLayer].fLabels[0];
2710 nlab++;
2711 }
2712 if (cseed[iLayer].fLabels[1]>=0) {
2713 labels[nlab] = cseed[iLayer].fLabels[1];
2714 nlab++;
2715 }
2716 }
2717 Freq(nlab,labels,outlab,kFALSE);
2718 Int_t label = outlab[0];
2719 Int_t frequency = outlab[1];
2720 for (Int_t iLayer=0;iLayer<6;iLayer++){
2721 cseed[iLayer].fFreq = frequency;
2722 cseed[iLayer].fC = CR;
2723 cseed[iLayer].fCC = CC;
2724 cseed[iLayer].fChi2 = chi2TR;
2725 cseed[iLayer].fChi2Z = chi2ZF;
2726 }
2727 //
2728 if (1||(!isFake)){ //debugging print
2729 Float_t zvertex = GetZ();
2730 TTreeSRedirector& cstream = *fDebugStreamer;
2731 cstream<<"Seeds1"<<
2732 "isFake="<<isFake<<
2733 "Vertex="<<zvertex<<
2734 "Rieman2.="<<&rieman2<<
2735 "Rieman.="<<&rieman<<
2736 "Xref="<<xref<<
2737 "X0="<<xcl[0]<<
2738 "X1="<<xcl[1]<<
2739 "X2="<<xcl[2]<<
2740 "X3="<<xcl[3]<<
2741 "X4="<<xcl[4]<<
2742 "X5="<<xcl[5]<<
2743 "Chi2R="<<chi2R<<
2744 "Chi2Z="<<chi2Z<<
2745 "Chi2RF="<<chi2RF<< //chi2 of trackletes on full track
2746 "Chi2ZF="<<chi2ZF<< //chi2 z on tracklets on full track
2747 "Chi2ZT2="<<chi2ZT2<< //chi2 z on tracklets on full track - rieman tilt
2748 "Chi2ZTC="<<chi2ZTC<< //chi2 z on tracklets on full track - rieman tilt const
2749 //
2750 "Chi2TR="<<chi2TR<< //chi2 without vertex constrain
2751 "Chi2TC="<<chi2TC<< //chi2 with vertex constrain
2752 "C="<<curv<< // non constrained - no tilt correction
2753 "DR="<<dR<< // DR parameter - tilt correction
2754 "DCA="<<dca<< // DCA - tilt correction
2755 "CR="<<CR<< // non constrained curvature - tilt correction
2756 "CC="<<CC<< // constrained curvature
2757 "Polz0="<<polz0c<<
2758 "Polz1="<<polz1c<<
2759 "RPolz0="<<rpolz0<<
2760 "RPolz1="<<rpolz1<<
2761 "Ncl="<<nclusters<<
2762 "Nlayers="<<nlayers<<
2763 "NUsedS="<<nusedCl<<
2764 "NUsed="<<nusedf<<
2765 "Findable="<<findable<<
2766 "Like="<<like<<
2767 "LikePrim="<<likePrim<<
2768 "Likechi2C="<<likechi2C<<
2769 "Likechi2TR="<<likechi2TR<<
2770 "Likezf="<<likezf<<
2771 "LikeF="<<seedquality2[registered]<<
2772 "S0.="<<&cseed[0]<<
2773 "S1.="<<&cseed[1]<<
2774 "S2.="<<&cseed[2]<<
2775 "S3.="<<&cseed[3]<<
2776 "S4.="<<&cseed[4]<<
2777 "S5.="<<&cseed[5]<<
2778 "SB0.="<<&seedb[0]<<
2779 "SB1.="<<&seedb[1]<<
2780 "SB2.="<<&seedb[2]<<
2781 "SB3.="<<&seedb[3]<<
2782 "SB4.="<<&seedb[4]<<
2783 "SB5.="<<&seedb[5]<<
2784 "Label="<<label<<
2785 "Freq="<<frequency<<
2786 "sLayer="<<sLayer<<
2787 "\n";
2788 }
2789 if (registered<maxseed-1) {
2790 registered++;
2791 cseed = seed[registered];
2792 }
2793 }// end of loop over layer 1
2794 } // end of loop over layer 0
2795 } // end of loop over layer 3
2796 } // end of loop over seeding time bins
2797 //
2798 // choos best
2799 //
2800 TMath::Sort(registered,seedquality2,sort,kTRUE);
2801 Bool_t signedseed[maxseed];
2802 for (Int_t i=0;i<registered;i++){
2803 signedseed[i]= kFALSE;
2804 }
2805 for (Int_t iter=0; iter<5; iter++){
2806 for (Int_t iseed=0;iseed<registered;iseed++){
2807 Int_t index = sort[iseed];
2808 if (signedseed[index]) continue;
2809 Int_t labelsall[1000];
2810 Int_t nlabelsall=0;
2811 Int_t naccepted=0;;
2812 Int_t sLayer = seedlayer[index];
2813 Int_t ncl = 0;
2814 Int_t nused = 0;
2815 Int_t nlayers =0;
2816 Int_t findable = 0;
2817 for (Int_t jLayer=0;jLayer<6;jLayer++){
2818 if (TMath::Abs(seed[index][jLayer].fYref[0]/xcl[jLayer])<0.15)
2819 findable++;
2820 if (seed[index][jLayer].isOK()){
2821 seed[index][jLayer].UpdateUsed();
2822 ncl +=seed[index][jLayer].fN2;
2823 nused +=seed[index][jLayer].fNUsed;
2824 nlayers++;
2825 //cooking label
2826 for (Int_t itime=0;itime<25;itime++){
2827 if (seed[index][jLayer].fUsable[itime]){
2828 naccepted++;
2829 for (Int_t ilab=0;ilab<3;ilab++){
2830 Int_t tindex = seed[index][jLayer].fClusters[itime]->GetLabel(ilab);
2831 if (tindex>=0){
2832 labelsall[nlabelsall] = tindex;
2833 nlabelsall++;
2834 }
2835 }
2836 }
2837 }
2838 }
2839 }
7ad19338 2840 //
69b55c55 2841 if (nused>30) continue;
7ad19338 2842 //
69b55c55 2843 if (iter==0){
2844 if (nlayers<6) continue;
2845 if (TMath::Log(0.000000001+seedquality2[index])<-5.) continue; // gold
2846 }
2847 //
2848 if (iter==1){
2849 if (nlayers<findable) continue;
2850 if (TMath::Log(0.000000001+seedquality2[index])<-4.) continue; //
7ad19338 2851 }
7ad19338 2852 //
7ad19338 2853 //
69b55c55 2854 if (iter==2){
2855 if (nlayers==findable || nlayers==6) continue;
2856 if (TMath::Log(0.000000001+seedquality2[index])<-6.) continue;
2857 }
7ad19338 2858 //
69b55c55 2859 if (iter==3){
2860 if (TMath::Log(0.000000001+seedquality2[index])<-5.) continue;
2861 }
7ad19338 2862 //
69b55c55 2863 if (iter==4){
2864 if (TMath::Log(0.000000001+seedquality2[index])-nused/(nlayers-3.)<-15.) continue;
2865 }
7ad19338 2866 //
69b55c55 2867 signedseed[index] = kTRUE;
2868 //
2869 Int_t labels[1000], outlab[1000];
2870 Int_t nlab=0;
2871 for (Int_t iLayer=0;iLayer<6;iLayer++){
2872 if (seed[index][iLayer].isOK()){
2873 if (seed[index][iLayer].fLabels[0]>=0) {
2874 labels[nlab] = seed[index][iLayer].fLabels[0];
2875 nlab++;
2876 }
2877 if (seed[index][iLayer].fLabels[1]>=0) {
2878 labels[nlab] = seed[index][iLayer].fLabels[1];
2879 nlab++;
2880 }
2881 }
7ad19338 2882 }
69b55c55 2883 Freq(nlab,labels,outlab,kFALSE);
2884 Int_t label = outlab[0];
2885 Int_t frequency = outlab[1];
2886 Freq(nlabelsall,labelsall,outlab,kFALSE);
2887 Int_t label1 = outlab[0];
2888 Int_t label2 = outlab[2];
2889 Float_t fakeratio = (naccepted-outlab[1])/Float_t(naccepted);
2890 Float_t ratio = Float_t(nused)/Float_t(ncl);
2891 if (ratio<0.25){
2892 for (Int_t jLayer=0;jLayer<6;jLayer++){
2893 if ( seed[index][jLayer].isOK()&&TMath::Abs(seed[index][jLayer].fYfit[1]-seed[index][jLayer].fYfit[1])<0.2 )
2894 seed[index][jLayer].UseClusters(); //sign gold
2895 }
7ad19338 2896 }
2897 //
69b55c55 2898 Int_t eventNr = esd->GetEventNumber();
2899 TTreeSRedirector& cstream = *fDebugStreamer;
2900 //
2901 // register seed
2902 //
2903 AliTRDtrack * track = RegisterSeed(seed[index],seedparams[index]);
2904 AliTRDtrack dummy;
2905 if (!track) track=&dummy;
2906 else{
2907 AliESDtrack esdtrack;
2908 esdtrack.UpdateTrackParams(track, AliESDtrack::kTRDout);
2909 esdtrack.SetLabel(label);
2910 esd->AddTrack(&esdtrack);
7ad19338 2911 TTreeSRedirector& cstream = *fDebugStreamer;
69b55c55 2912 cstream<<"Tracks"<<
2913 "EventNr="<<eventNr<<
2914 "ESD.="<<&esdtrack<<
2915 "trd.="<<track<<
2916 "trdback.="<<track<<
7ad19338 2917 "\n";
2918 }
69b55c55 2919
2920 cstream<<"Seeds2"<<
2921 "Iter="<<iter<<
2922 "Track.="<<track<<
2923 "Like="<<seedquality[index]<<
2924 "LikeF="<<seedquality2[index]<<
2925 "S0.="<<&seed[index][0]<<
2926 "S1.="<<&seed[index][1]<<
2927 "S2.="<<&seed[index][2]<<
2928 "S3.="<<&seed[index][3]<<
2929 "S4.="<<&seed[index][4]<<
2930 "S5.="<<&seed[index][5]<<
2931 "Label="<<label<<
2932 "Label1="<<label1<<
2933 "Label2="<<label2<<
2934 "FakeRatio="<<fakeratio<<
2935 "Freq="<<frequency<<
2936 "Ncl="<<ncl<<
2937 "Nlayers="<<nlayers<<
2938 "Findable="<<findable<<
2939 "NUsed="<<nused<<
2940 "sLayer="<<sLayer<<
2941 "EventNr="<<eventNr<<
2942 "\n";
7ad19338 2943 }
2944 }
69b55c55 2945 } // end of loop over sectors
2946 delete [] pseed;
2947}
2948
5443e65e 2949//_____________________________________________________________________________
b7a0917f 2950Int_t AliTRDtracker::ReadClusters(TObjArray *array, TTree *ClusterTree) const
5443e65e 2951{
2952 //
a819a5f7 2953 // Reads AliTRDclusters (option >= 0) or AliTRDrecPoints (option < 0)
2954 // from the file. The names of the cluster tree and branches
2955 // should match the ones used in AliTRDclusterizer::WriteClusters()
2956 //
4f1c04d3 2957 Int_t nsize = Int_t(ClusterTree->GetTotBytes()/(sizeof(AliTRDcluster)));
2958 TObjArray *clusterArray = new TObjArray(nsize+1000);
5443e65e 2959
c630aafd 2960 TBranch *branch=ClusterTree->GetBranch("TRDcluster");
2961 if (!branch) {
2962 Error("ReadClusters","Can't get the branch !");
2963 return 1;
2964 }
029cd327 2965 branch->SetAddress(&clusterArray);
5443e65e 2966
2967 Int_t nEntries = (Int_t) ClusterTree->GetEntries();
19dd5b2f 2968 // printf("found %d entries in %s.\n",nEntries,ClusterTree->GetName());
a819a5f7 2969
a819a5f7 2970 // Loop through all entries in the tree
eb187bed 2971 Int_t nbytes = 0;
a819a5f7 2972 AliTRDcluster *c = 0;
7bed16a7 2973 // printf("\n");
a819a5f7 2974 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
2975
2976 // Import the tree
5443e65e 2977 nbytes += ClusterTree->GetEvent(iEntry);
2978
a819a5f7 2979 // Get the number of points in the detector
029cd327 2980 Int_t nCluster = clusterArray->GetEntriesFast();
e24ea474 2981// printf("\r Read %d clusters from entry %d", nCluster, iEntry);
5443e65e 2982
a819a5f7 2983 // Loop through all TRD digits
2984 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
029cd327 2985 c = (AliTRDcluster*)clusterArray->UncheckedAt(iCluster);
7ad19338 2986// if (c->GetNPads()>3&&(iCluster%3>0)) {
2987// delete clusterArray->RemoveAt(iCluster);
2988// continue;
2989// }
4f1c04d3 2990 // AliTRDcluster *co = new AliTRDcluster(*c); //remove unnecesary coping - + clusters are together in memory
2991 AliTRDcluster *co = c;
a819a5f7 2992 co->SetSigmaY2(c->GetSigmaY2() * fSY2corr);
5443e65e 2993 Int_t ltb = co->GetLocalTimeBin();
b8dc2353 2994 if(ltb == 19) co->SetSigmaZ2(c->GetSigmaZ2());
2995 else if(fNoTilt) co->SetSigmaZ2(c->GetSigmaZ2() * fSZ2corr);
a819a5f7 2996 array->AddLast(co);
4f1c04d3 2997 // delete clusterArray->RemoveAt(iCluster);
2998 clusterArray->RemoveAt(iCluster);
a819a5f7 2999 }
3000 }
7c1698cb 3001// cout<<"Allocated"<<nsize<<"\tLoaded"<<array->GetEntriesFast()<<"\n";
a819a5f7 3002
029cd327 3003 delete clusterArray;
5443e65e 3004
c630aafd 3005 return 0;
a819a5f7 3006}
3007
46d29e70 3008//__________________________________________________________________
029cd327 3009void AliTRDtracker::CookLabel(AliKalmanTrack* pt, Float_t wrong) const
3010{
3011 //
3012 // This cooks a label. Mmmmh, smells good...
3013 //
46d29e70 3014
3015 Int_t label=123456789, index, i, j;
5443e65e 3016 Int_t ncl=pt->GetNumberOfClusters();
029cd327 3017 const Int_t kRange = fTrSec[0]->GetOuterTimeBin()+1;
5443e65e 3018
029cd327 3019 Bool_t labelAdded;
46d29e70 3020
029cd327 3021 // Int_t s[kRange][2];
3022 Int_t **s = new Int_t* [kRange];
3023 for (i=0; i<kRange; i++) {
d1b06c24 3024 s[i] = new Int_t[2];
3025 }
029cd327 3026 for (i=0; i<kRange; i++) {
46d29e70 3027 s[i][0]=-1;
3028 s[i][1]=0;
3029 }
3030
3031 Int_t t0,t1,t2;
3032 for (i=0; i<ncl; i++) {
5443e65e 3033 index=pt->GetClusterIndex(i);
46d29e70 3034 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
5443e65e 3035 t0=c->GetLabel(0);
3036 t1=c->GetLabel(1);
3037 t2=c->GetLabel(2);
46d29e70 3038 }
3039
3040 for (i=0; i<ncl; i++) {
5443e65e 3041 index=pt->GetClusterIndex(i);
46d29e70 3042 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
3043 for (Int_t k=0; k<3; k++) {
5443e65e 3044 label=c->GetLabel(k);
029cd327 3045 labelAdded=kFALSE; j=0;
46d29e70 3046 if (label >= 0) {
029cd327 3047 while ( (!labelAdded) && ( j < kRange ) ) {
a9814c09 3048 if (s[j][0]==label || s[j][1]==0) {
3049 s[j][0]=label;
3050 s[j][1]=s[j][1]+1;
029cd327 3051 labelAdded=kTRUE;
a9814c09 3052 }
3053 j++;
3054 }
46d29e70 3055 }
3056 }
3057 }
3058
46d29e70 3059 Int_t max=0;
3060 label = -123456789;
3061
029cd327 3062 for (i=0; i<kRange; i++) {
46d29e70 3063 if (s[i][1]>max) {
3064 max=s[i][1]; label=s[i][0];
3065 }
3066 }
5443e65e 3067
029cd327 3068 for (i=0; i<kRange; i++) {
5443e65e 3069 delete []s[i];
3070 }
3071
d1b06c24 3072 delete []s;
5443e65e 3073
3074 if ((1.- Float_t(max)/ncl) > wrong) label=-label;
3075
3076 pt->SetLabel(label);
3077
46d29e70 3078}
3079
c630aafd 3080
5443e65e 3081//__________________________________________________________________
029cd327 3082void AliTRDtracker::UseClusters(const AliKalmanTrack* t, Int_t from) const
3083{
3084 //
3085 // Use clusters, but don't abuse them!
3086 //
69b55c55 3087 const Float_t kmaxchi2 =18;
3088 const Float_t kmincl =10;
3089 AliTRDtrack * track = (AliTRDtrack*)t;
3090 //
5443e65e 3091 Int_t ncl=t->GetNumberOfClusters();
3092 for (Int_t i=from; i<ncl; i++) {
3093 Int_t index = t->GetClusterIndex(i);
3094 AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
69b55c55 3095 //
3096 Int_t iplane = fGeom->GetPlane(c->GetDetector());
3097 if (track->fTracklets[iplane].GetChi2()>kmaxchi2) continue;
3098 if (track->fTracklets[iplane].GetN()<kmincl) continue;
3099 if (!(c->IsUsed())) c->Use();
5443e65e 3100 }
3101}
3102
3103
3104//_____________________________________________________________________
029cd327 3105Double_t AliTRDtracker::ExpectedSigmaY2(Double_t , Double_t , Double_t ) const
5443e65e 3106{
3107 // Parametrised "expected" error of the cluster reconstruction in Y
3108
3109 Double_t s = 0.08 * 0.08;
3110 return s;
3111}
3112
3113//_____________________________________________________________________
029cd327 3114Double_t AliTRDtracker::ExpectedSigmaZ2(Double_t , Double_t ) const
0a29d0f1 3115{
5443e65e 3116 // Parametrised "expected" error of the cluster reconstruction in Z
3117
a9814c09 3118 Double_t s = 9 * 9 /12.;
5443e65e 3119 return s;
3120}
3121
5443e65e 3122//_____________________________________________________________________
029cd327 3123Double_t AliTRDtracker::GetX(Int_t sector, Int_t plane, Int_t localTB) const
5443e65e 3124{
3125 //
029cd327 3126 // Returns radial position which corresponds to time bin <localTB>
5443e65e 3127 // in tracking sector <sector> and plane <plane>
3128 //
3129
029cd327 3130 Int_t index = fTrSec[sector]->CookTimeBinIndex(plane, localTB);
5443e65e 3131 Int_t pl = fTrSec[sector]->GetLayerNumber(index);
3132 return fTrSec[sector]->GetLayer(pl)->GetX();
3133
3134}
3135
c630aafd 3136
5443e65e 3137//_______________________________________________________
3138AliTRDtracker::AliTRDpropagationLayer::AliTRDpropagationLayer(Double_t x,
029cd327 3139 Double_t dx, Double_t rho, Double_t radLength, Int_t tbIndex)
5443e65e 3140{
0a29d0f1 3141 //
5443e65e 3142 // AliTRDpropagationLayer constructor
0a29d0f1 3143 //
46d29e70 3144
029cd327 3145 fN = 0; fX = x; fdX = dx; fRho = rho; fX0 = radLength;
3146 fClusters = NULL; fIndex = NULL; fTimeBinIndex = tbIndex;
5443e65e 3147
46d29e70 3148
029cd327 3149 for(Int_t i=0; i < (Int_t) kZones; i++) {
5443e65e 3150 fZc[i]=0; fZmax[i] = 0;
a819a5f7 3151 }
5443e65e 3152
3153 fYmax = 0;
3154
3155 if(fTimeBinIndex >= 0) {
029cd327 3156 fClusters = new AliTRDcluster*[kMaxClusterPerTimeBin];
3157 fIndex = new UInt_t[kMaxClusterPerTimeBin];
a819a5f7 3158 }
46d29e70 3159
3c625a9b 3160 for (Int_t i=0;i<5;i++) fIsHole[i] = kFALSE;
5443e65e 3161 fHole = kFALSE;
3162 fHoleZc = 0;
3163 fHoleZmax = 0;
3164 fHoleYc = 0;
3165 fHoleYmax = 0;
3166 fHoleRho = 0;
3167 fHoleX0 = 0;
3168
3169}
3170
3171//_______________________________________________________
3172void AliTRDtracker::AliTRDpropagationLayer::SetHole(
a9814c09 3173 Double_t Zmax, Double_t Ymax, Double_t rho,
029cd327 3174 Double_t radLength, Double_t Yc, Double_t Zc)
5443e65e 3175{
3176 //
3177 // Sets hole in the layer
3178 //
5443e65e 3179 fHole = kTRUE;
3180 fHoleZc = Zc;
3181 fHoleZmax = Zmax;
3182 fHoleYc = Yc;
3183 fHoleYmax = Ymax;
3184 fHoleRho = rho;
029cd327 3185 fHoleX0 = radLength;
5443e65e 3186}
3187
46d29e70 3188
5443e65e 3189//_______________________________________________________
3190AliTRDtracker::AliTRDtrackingSector::AliTRDtrackingSector(AliTRDgeometry* geo, Int_t gs, AliTRDparameter* par)
3191{
3192 //
3193 // AliTRDtrackingSector Constructor
3194 //
a5cadd36 3195 AliTRDpadPlane *padPlane = 0;
3196
5443e65e 3197 fGeom = geo;
3198 fPar = par;
3199 fGeomSector = gs;
3200 fTzeroShift = 0.13;
3201 fN = 0;
3c625a9b 3202 //
3203 // get holes description from geometry
3204 Bool_t holes[AliTRDgeometry::kNcham];
3205 //printf("sector\t%d\t",gs);
3206 for (Int_t icham=0; icham<AliTRDgeometry::kNcham;icham++){
3207 holes[icham] = fGeom->IsHole(0,icham,gs);
3208 //printf("%d",holes[icham]);
3209 }
3210 //printf("\n");
3211
029cd327 3212 for(UInt_t i=0; i < kMaxTimeBinIndex; i++) fTimeBinIndex[i] = -1;
5443e65e 3213
3214
3215 AliTRDpropagationLayer* ppl;
3216
029cd327 3217 Double_t x, xin, xout, dx, rho, radLength;
5443e65e 3218 Int_t steps;
46d29e70 3219
5443e65e 3220 // set time bins in the gas of the TPC
46d29e70 3221
5443e65e 3222 xin = 246.055; xout = 254.055; steps = 20; dx = (xout-xin)/steps;
029cd327 3223 rho = 0.9e-3; radLength = 28.94;
5443e65e 3224
3225 for(Int_t i=0; i<steps; i++) {
3226 x = xin + i*dx + dx/2;
029cd327 3227 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 3228 InsertLayer(ppl);
46d29e70 3229 }
3230
5443e65e 3231 // set time bins in the outer field cage vessel
46d29e70 3232
029cd327 3233 dx = 50e-4; xin = xout; xout = xin + dx; rho = 1.71; radLength = 44.77; // Tedlar
3234 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 3235 InsertLayer(ppl);
46d29e70 3236
029cd327 3237 dx = 0.02; xin = xout; xout = xin + dx; rho = 1.45; radLength = 44.86; // prepreg
3238 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 3239 InsertLayer(ppl);
3240
029cd327 3241 dx = 2.; xin = xout; xout = xin + dx; rho = 1.45*0.02; radLength = 41.28; // Nomex
5443e65e 3242 steps = 5; dx = (xout - xin)/steps;
3243 for(Int_t i=0; i<steps; i++) {
3244 x = xin + i*dx + dx/2;
029cd327 3245 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 3246 InsertLayer(ppl);
3247 }
3248
029cd327 3249 dx = 0.02; xin = xout; xout = xin + dx; rho = 1.45; radLength = 44.86; // prepreg
3250 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 3251 InsertLayer(ppl);
3252
029cd327 3253 dx = 50e-4; xin = xout; xout = xin + dx; rho = 1.71; radLength = 44.77; // Tedlar
3254 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 3255 InsertLayer(ppl);
0a29d0f1 3256
5443e65e 3257
3258 // set time bins in CO2
3259
3260 xin = xout; xout = 275.0;
3261 steps = 50; dx = (xout - xin)/steps;
029cd327 3262 rho = 1.977e-3; radLength = 36.2;
5443e65e 3263
3264 for(Int_t i=0; i<steps; i++) {
3265 x = xin + i*dx + dx/2;
029cd327 3266 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 3267 InsertLayer(ppl);
3268 }
3269
3270 // set time bins in the outer containment vessel
3271
029cd327 3272 dx = 50e-4; xin = xout; xout = xin + dx; rho = 2.7; radLength = 24.01; // Al
3273 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 3274 InsertLayer(ppl);
3275
029cd327 3276 dx = 50e-4; xin = xout; xout = xin + dx; rho = 1.71; radLength = 44.77; // Tedlar
3277 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 3278 InsertLayer(ppl);
3279
029cd327 3280 dx = 0.06; xin = xout; xout = xin + dx; rho = 1.45; radLength = 44.86; // prepreg
3281 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 3282 InsertLayer(ppl);
3283
029cd327 3284 dx = 3.; xin = xout; xout = xin + dx; rho = 1.45*0.02; radLength = 41.28; // Nomex
5443e65e 3285 steps = 10; dx = (xout - xin)/steps;
3286 for(Int_t i=0; i<steps; i++) {
3287 x = xin + i*dx + dx/2;
029cd327 3288 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 3289 InsertLayer(ppl);
3290 }
3291
029cd327 3292 dx = 0.06; xin = xout; xout = xin + dx; rho = 1.45; radLength = 44.86; // prepreg
3293 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 3294 InsertLayer(ppl);
3295
029cd327 3296 dx = 50e-4; xin = xout; xout = xin + dx; rho = 1.71; radLength = 44.77; // Tedlar
3297 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 3298 InsertLayer(ppl);
3299
029cd327 3300 dx = 50e-4; xin = xout; xout = xin + dx; rho = 2.7; radLength = 24.01; // Al
3301 ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
5443e65e 3302 InsertLayer(ppl);
3303
3304 Double_t xtrd = (Double_t) fGeom->Rmin();
3305
3306 // add layers between TPC and TRD (Air temporarily)
3307 xin = xout; xout = xtrd;
3308 steps = 50; dx = (xout - xin)/steps;
029cd327 3309 rho = 1.2e-3; radLength = 36.66;
5443e65e 3310
3311 for(Int_t i=0; i<steps; i++) {
3312 x = xin + i*dx + dx/2;
029cd327 3313 ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
5443e65e 3314 InsertLayer(ppl);
3315 }
3316
3317
3c625a9b 3318 // Double_t alpha=AliTRDgeometry::GetAlpha();
5443e65e 3319
3320 // add layers for each of the planes
3321
3322 Double_t dxRo = (Double_t) fGeom->CroHght(); // Rohacell
3323 Double_t dxSpace = (Double_t) fGeom->Cspace(); // Spacing between planes
3324 Double_t dxAmp = (Double_t) fGeom->CamHght(); // Amplification region
3325 Double_t dxDrift = (Double_t) fGeom->CdrHght(); // Drift region
3326 Double_t dxRad = (Double_t) fGeom->CraHght(); // Radiator
3327 Double_t dxTEC = dxRad + dxDrift + dxAmp + dxRo;
3328 Double_t dxPlane = dxTEC + dxSpace;
3329
029cd327 3330 Int_t tb, tbIndex;
3331 const Int_t kNchambers = AliTRDgeometry::Ncham();
3c625a9b 3332 Double_t ymax = 0;
3333 //, holeYmax = 0;
3334 Double_t ymaxsensitive=0;
029cd327 3335 Double_t *zc = new Double_t[kNchambers];
3336 Double_t *zmax = new Double_t[kNchambers];
3c625a9b 3337 Double_t *zmaxsensitive = new Double_t[kNchambers];
3338 // Double_t holeZmax = 1000.; // the whole sector is missing
5443e65e 3339
5443e65e 3340 for(Int_t plane = 0; plane < AliTRDgeometry::Nplan(); plane++) {
3c625a9b 3341 //
5443e65e 3342 // Radiator
3343 xin = xtrd + plane * dxPlane; xout = xin + dxRad;
029cd327 3344 steps = 12; dx = (xout - xin)/steps; rho = 0.074; radLength = 40.6;
5443e65e 3345 for(Int_t i=0; i<steps; i++) {
3346 x = xin + i*dx + dx/2;
3c625a9b