]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDtracker.cxx
Additional functions, corrections to match the base class (T.Kuhr)
[u/mrichter/AliRoot.git] / TRD / AliTRDtracker.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15                                                       
16 /*
17 $Log$
18 Revision 1.23  2003/02/10 14:06:10  cblume
19 Add tracking without tilted pads as option
20
21 Revision 1.22  2003/01/30 15:19:58  cblume
22 New set of  parameters
23
24 Revision 1.21  2003/01/27 16:34:49  cblume
25 Update of tracking by Sergei and Chuncheng
26
27 Revision 1.20  2002/11/07 15:52:09  cblume
28 Update of tracking code for tilted pads
29
30 Revision 1.19  2002/10/22 15:53:08  alibrary
31 Introducing Riostream.h
32
33 Revision 1.18  2002/10/14 14:57:44  hristov
34 Merging the VirtualMC branch to the main development branch (HEAD)
35
36 Revision 1.14.6.2  2002/07/24 10:09:31  alibrary
37 Updating VirtualMC
38
39 Revision 1.17  2002/06/13 12:09:58  hristov
40 Minor corrections
41
42 Revision 1.16  2002/06/12 09:54:36  cblume
43 Update of tracking code provided by Sergei
44
45 Revision 1.14  2001/11/14 10:50:46  cblume
46 Changes in digits IO. Add merging of summable digits
47
48 Revision 1.13  2001/05/30 12:17:47  hristov
49 Loop variables declared once
50
51 Revision 1.12  2001/05/28 17:07:58  hristov
52 Last minute changes; ExB correction in AliTRDclusterizerV1; taking into account of material in G10 TEC frames and material between TEC planes (C.Blume,S.Sedykh)
53
54 Revision 1.8  2000/12/20 13:00:44  cblume
55 Modifications for the HP-compiler
56
57 Revision 1.7  2000/12/08 16:07:02  cblume
58 Update of the tracking by Sergei
59
60 Revision 1.6  2000/11/30 17:38:08  cblume
61 Changes to get in line with new STEER and EVGEN
62
63 Revision 1.5  2000/11/14 14:40:27  cblume
64 Correction for the Sun compiler (kTRUE and kFALSE)
65
66 Revision 1.4  2000/11/10 14:57:52  cblume
67 Changes in the geometry constants for the DEC compiler
68
69 Revision 1.3  2000/10/15 23:40:01  cblume
70 Remove AliTRDconst
71
72 Revision 1.2  2000/10/06 16:49:46  cblume
73 Made Getters const
74
75 Revision 1.1.2.2  2000/10/04 16:34:58  cblume
76 Replace include files by forward declarations
77
78 Revision 1.1.2.1  2000/09/22 14:47:52  cblume
79 Add the tracking code
80
81 */   
82
83 #include <Riostream.h>
84
85 #include <TFile.h>
86 #include <TBranch.h>
87 #include <TTree.h>  
88 #include <TObjArray.h> 
89
90 #include "AliTRDgeometry.h"
91 #include "AliTRDparameter.h"
92 #include "AliTRDgeometryDetail.h"
93 #include "AliTRDcluster.h" 
94 #include "AliTRDtrack.h"
95 #include "../TPC/AliTPCtrack.h"
96
97 #include "AliTRDtracker.h"
98
99 ClassImp(AliTRDtracker) 
100
101   const  Float_t     AliTRDtracker::fSeedDepth          = 0.5; 
102   const  Float_t     AliTRDtracker::fSeedStep           = 0.10;   
103   const  Float_t     AliTRDtracker::fSeedGap            = 0.25;  
104
105   const  Float_t     AliTRDtracker::fMaxSeedDeltaZ12    = 40.;  
106   const  Float_t     AliTRDtracker::fMaxSeedDeltaZ      = 25.;  
107   const  Float_t     AliTRDtracker::fMaxSeedC           = 0.0052; 
108   const  Float_t     AliTRDtracker::fMaxSeedTan         = 1.2;  
109   const  Float_t     AliTRDtracker::fMaxSeedVertexZ     = 150.; 
110
111   const  Double_t    AliTRDtracker::fSeedErrorSY        = 0.2;
112   const  Double_t    AliTRDtracker::fSeedErrorSY3       = 2.5;
113   const  Double_t    AliTRDtracker::fSeedErrorSZ        = 0.1;
114
115   const  Float_t     AliTRDtracker::fMinClustersInSeed  = 0.7;  
116
117   const  Float_t     AliTRDtracker::fMinClustersInTrack = 0.5;  
118   const  Float_t     AliTRDtracker::fMinFractionOfFoundClusters = 0.8;  
119
120   const  Float_t     AliTRDtracker::fSkipDepth          = 0.3;
121   const  Float_t     AliTRDtracker::fLabelFraction      = 0.8;  
122   const  Float_t     AliTRDtracker::fWideRoad           = 20.;
123
124   const  Double_t    AliTRDtracker::fMaxChi2            = 12.; 
125
126
127 //____________________________________________________________________
128 AliTRDtracker::AliTRDtracker(const TFile *geomfile)
129 {
130   // 
131   //  Main constructor
132   //  
133
134   Float_t fTzero = 0;
135    
136   fAddTRDseeds = kFALSE;
137   fGeom = NULL;
138   fNoTilt = kFALSE;
139   
140   TDirectory *savedir=gDirectory; 
141   TFile *in=(TFile*)geomfile;  
142   if (!in->IsOpen()) {
143     printf("AliTRDtracker::AliTRDtracker(): geometry file is not open!\n");
144     printf("    DETAIL TRD geometry and DEFAULT TRD parameter will be used\n");
145   }
146   else {
147     in->cd();  
148     in->ls();
149     fGeom = (AliTRDgeometry*) in->Get("TRDgeometry");
150     fPar  = (AliTRDparameter*) in->Get("TRDparameter");
151     fGeom->Dump();
152   }
153
154   if(fGeom) {
155     //    fTzero = geo->GetT0();
156     printf("Found geometry version %d on file \n", fGeom->IsVersion());
157   }
158   else { 
159     printf("AliTRDtracker::AliTRDtracker(): cann't find TRD geometry!\n");
160     printf("    DETAIL TRD geometry and DEFAULT TRD parameter will be used\n");
161     fGeom = new AliTRDgeometryDetail(); 
162     fPar = new AliTRDparameter();
163   }
164
165   savedir->cd();  
166
167
168   //  fGeom->SetT0(fTzero);
169
170   fEvent     = 0;
171
172   fNclusters = 0;
173   fClusters  = new TObjArray(2000); 
174   fNseeds    = 0;
175   fSeeds     = new TObjArray(2000);
176   fNtracks   = 0;
177   fTracks    = new TObjArray(1000);
178
179   for(Int_t geom_s = 0; geom_s < kTRACKING_SECTORS; geom_s++) {
180     Int_t tr_s = CookSectorIndex(geom_s);
181     fTrSec[tr_s] = new AliTRDtrackingSector(fGeom, geom_s, fPar);
182   }
183
184   Float_t tilt_angle = TMath::Abs(fPar->GetTiltingAngle()); 
185   if(tilt_angle < 0.1) {
186     fNoTilt = kTRUE;
187   }
188
189   fSY2corr = 0.2;
190   fSZ2corr = 120.;      
191
192   if(fNoTilt && (tilt_angle > 0.1)) fSY2corr = fSY2corr + tilt_angle * 0.05; 
193
194
195   // calculate max gap on track
196
197   Double_t dxAmp = (Double_t) fGeom->CamHght();   // Amplification region
198   Double_t dxDrift = (Double_t) fGeom->CdrHght(); // Drift region
199
200   Double_t dx = (Double_t) fPar->GetTimeBinSize();   
201   Int_t tbAmp = fPar->GetTimeBefore();
202   Int_t maxAmp = (Int_t) ((dxAmp+0.000001)/dx);
203   if(kTRUE) maxAmp = 0;  // intentional until we change the parameter class 
204   Int_t tbDrift = fPar->GetTimeMax();
205   Int_t maxDrift = (Int_t) ((dxDrift+0.000001)/dx);
206
207   tbDrift = TMath::Min(tbDrift,maxDrift);
208   tbAmp = TMath::Min(tbAmp,maxAmp);
209
210   fTimeBinsPerPlane = tbAmp + tbDrift;
211   fMaxGap = (Int_t) (fTimeBinsPerPlane * fGeom->Nplan() * fSkipDepth);
212
213   fVocal = kFALSE;
214
215 }   
216
217 //___________________________________________________________________
218 AliTRDtracker::~AliTRDtracker()
219 {
220   delete fClusters;
221   delete fTracks;
222   delete fSeeds;
223   delete fGeom;  
224   delete fPar;  
225
226   for(Int_t geom_s = 0; geom_s < kTRACKING_SECTORS; geom_s++) {
227     delete fTrSec[geom_s];
228   }
229 }   
230
231 //_____________________________________________________________________
232 inline Double_t f1trd(Double_t x1,Double_t y1,
233                       Double_t x2,Double_t y2,
234                       Double_t x3,Double_t y3)
235 {
236   //
237   // Initial approximation of the track curvature
238   //
239   Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
240   Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
241                   (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
242   Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
243                   (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
244
245   Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
246
247   return -xr*yr/sqrt(xr*xr+yr*yr);
248 }          
249
250 //_____________________________________________________________________
251 inline Double_t f2trd(Double_t x1,Double_t y1,
252                       Double_t x2,Double_t y2,
253                       Double_t x3,Double_t y3)
254 {
255   //
256   // Initial approximation of the track curvature times X coordinate
257   // of the center of curvature
258   //
259
260   Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
261   Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
262                   (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
263   Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
264                   (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
265
266   Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
267
268   return -a/(d*y1-b)*xr/sqrt(xr*xr+yr*yr);
269 }          
270
271 //_____________________________________________________________________
272 inline Double_t f3trd(Double_t x1,Double_t y1,
273                       Double_t x2,Double_t y2,
274                       Double_t z1,Double_t z2)
275 {
276   //
277   // Initial approximation of the tangent of the track dip angle
278   //
279
280   return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
281 }            
282
283 //___________________________________________________________________
284 Int_t AliTRDtracker::Clusters2Tracks(const TFile *inp, TFile *out)
285 {
286   //
287   // Finds tracks within the TRD. File <inp> is expected to contain seeds 
288   // at the outer part of the TRD. If <inp> is NULL, the seeds
289   // are found within the TRD if fAddTRDseeds is TRUE. 
290   // The tracks are propagated to the innermost time bin 
291   // of the TRD and stored in file <out>. 
292   //
293
294   LoadEvent();
295  
296   TDirectory *savedir=gDirectory;
297
298   char   tname[100];
299
300   if (!out->IsOpen()) {
301     cerr<<"AliTRDtracker::Clusters2Tracks(): output file is not open !\n";
302     return 1;
303   }    
304
305   sprintf(tname,"seedTRDtoTPC_%d",fEvent); 
306   TTree tpc_tree(tname,"Tree with seeds from TRD at outer TPC pad row");
307   AliTPCtrack *iotrack=0;
308   tpc_tree.Branch("tracks","AliTPCtrack",&iotrack,32000,0); 
309
310   sprintf(tname,"TreeT%d_TRD",fEvent);
311   TTree trd_tree(tname,"TRD tracks at inner TRD time bin");
312   AliTRDtrack *iotrack_trd=0;
313   trd_tree.Branch("tracks","AliTRDtrack",&iotrack_trd,32000,0);  
314
315   Int_t timeBins = fTrSec[0]->GetNumberOfTimeBins();
316   Float_t foundMin = fMinClustersInTrack * timeBins; 
317
318   if (inp) {
319      TFile *in=(TFile*)inp;
320      if (!in->IsOpen()) {
321         cerr<<"AliTRDtracker::Clusters2Tracks(): file with seeds is not open !\n";
322         cerr<<" ... going for seeds finding inside the TRD\n";
323      }
324      else {
325        in->cd();
326        sprintf(tname,"TRDb_%d",fEvent);  
327        TTree *seedTree=(TTree*)in->Get(tname);  
328        if (!seedTree) {
329          cerr<<"AliTRDtracker::Clusters2Tracks(): ";
330          cerr<<"can't get a tree with track seeds !\n";
331          return 3;
332        }  
333        AliTRDtrack *seed=new AliTRDtrack;
334        seedTree->SetBranchAddress("tracks",&seed);
335
336        Int_t n=(Int_t)seedTree->GetEntries();
337        for (Int_t i=0; i<n; i++) {
338          seedTree->GetEvent(i);
339          seed->ResetCovariance(); 
340          AliTRDtrack *tr = new AliTRDtrack(*seed,seed->GetAlpha());
341          fSeeds->AddLast(tr);
342          fNseeds++;
343        }          
344        delete seed;
345        delete seedTree;
346      }
347   }
348
349   out->cd();
350
351
352   // find tracks from loaded seeds
353
354   Int_t nseed=fSeeds->GetEntriesFast();
355   Int_t i, found = 0;
356   Int_t innerTB = fTrSec[0]->GetInnerTimeBin();
357
358   for (i=0; i<nseed; i++) {   
359     AliTRDtrack *pt=(AliTRDtrack*)fSeeds->UncheckedAt(i), &t=*pt; 
360     FollowProlongation(t, innerTB); 
361     if (t.GetNumberOfClusters() >= foundMin) {
362       UseClusters(&t);
363       CookLabel(pt, 1-fLabelFraction);
364       //      t.CookdEdx();
365     }
366     iotrack_trd = pt;
367     trd_tree.Fill();
368     cout<<found++<<'\r';     
369
370     if(PropagateToTPC(t)) {
371       AliTPCtrack *tpc = new AliTPCtrack(*pt,pt->GetAlpha());
372       iotrack = tpc;
373       tpc_tree.Fill();
374       delete tpc;
375     }  
376     delete fSeeds->RemoveAt(i);
377     fNseeds--;
378   }     
379
380   cout<<"Number of loaded seeds: "<<nseed<<endl;  
381   cout<<"Number of found tracks from loaded seeds: "<<found<<endl;
382
383   // after tracks from loaded seeds are found and the corresponding 
384   // clusters are used, look for additional seeds from TRD
385
386   if(fAddTRDseeds) { 
387     // Find tracks for the seeds in the TRD
388     Int_t timeBins = fTrSec[0]->GetNumberOfTimeBins();
389   
390     Int_t nSteps = (Int_t) (fSeedDepth / fSeedStep);
391     Int_t gap = (Int_t) (timeBins * fSeedGap);
392     Int_t step = (Int_t) (timeBins * fSeedStep);
393   
394     // make a first turn with tight cut on initial curvature
395     for(Int_t turn = 1; turn <= 2; turn++) {
396       if(turn == 2) {
397         nSteps = (Int_t) (fSeedDepth / (3*fSeedStep));
398         step = (Int_t) (timeBins * (3*fSeedStep));
399       }
400       for(Int_t i=0; i<nSteps; i++) {
401         Int_t outer=timeBins-1-i*step; 
402         Int_t inner=outer-gap;
403
404         nseed=fSeeds->GetEntriesFast();
405       
406         MakeSeeds(inner, outer, turn);
407       
408         nseed=fSeeds->GetEntriesFast();
409         printf("\n turn %d, step %d: number of seeds for TRD inward %d\n", 
410                turn, i, nseed); 
411               
412         for (Int_t i=0; i<nseed; i++) {   
413           AliTRDtrack *pt=(AliTRDtrack*)fSeeds->UncheckedAt(i), &t=*pt; 
414           FollowProlongation(t,innerTB); 
415           if (t.GetNumberOfClusters() >= foundMin) {
416             UseClusters(&t);
417             CookLabel(pt, 1-fLabelFraction);
418             t.CookdEdx();
419             cout<<found++<<'\r';     
420             iotrack_trd = pt;
421             trd_tree.Fill();
422             if(PropagateToTPC(t)) {
423               AliTPCtrack *tpc = new AliTPCtrack(*pt,pt->GetAlpha());
424               iotrack = tpc;
425               tpc_tree.Fill();
426               delete tpc;
427             }        
428           }
429           delete fSeeds->RemoveAt(i);
430           fNseeds--;
431         }
432       }
433     }
434   }
435   tpc_tree.Write(); 
436   trd_tree.Write(); 
437   
438   cout<<"Total number of found tracks: "<<found<<endl;
439     
440   UnloadEvent();
441     
442   savedir->cd();  
443   
444   return 0;    
445 }     
446      
447   
448
449 //_____________________________________________________________________________
450 Int_t AliTRDtracker::PropagateBack(const TFile *inp, TFile *out) {
451   //
452   // Reads seeds from file <inp>. The seeds are AliTPCtrack's found and
453   // backpropagated by the TPC tracker. Each seed is first propagated 
454   // to the TRD, and then its prolongation is searched in the TRD.
455   // If sufficiently long continuation of the track is found in the TRD
456   // the track is updated, otherwise it's stored as originaly defined 
457   // by the TPC tracker.   
458   //  
459
460   LoadEvent();
461
462   TDirectory *savedir=gDirectory;
463
464   TFile *in=(TFile*)inp;
465
466   if (!in->IsOpen()) {
467      cerr<<"AliTRDtracker::PropagateBack(): ";
468      cerr<<"file with back propagated TPC tracks is not open !\n";
469      return 1;
470   }                   
471
472   if (!out->IsOpen()) {
473      cerr<<"AliTRDtracker::PropagateBack(): ";
474      cerr<<"file for back propagated TRD tracks is not open !\n";
475      return 2;
476   }      
477
478   in->cd();
479   char   tname[100];
480   sprintf(tname,"seedsTPCtoTRD_%d",fEvent);       
481   TTree *seedTree=(TTree*)in->Get(tname);
482   if (!seedTree) {
483      cerr<<"AliTRDtracker::PropagateBack(): ";
484      cerr<<"can't get a tree with seeds from TPC !\n";
485      cerr<<"check if your version of TPC tracker creates tree "<<tname<<"\n";
486      return 3;
487   }
488
489   AliTPCtrack *seed=new AliTPCtrack;
490   seedTree->SetBranchAddress("tracks",&seed);
491
492   Int_t n=(Int_t)seedTree->GetEntries();
493   for (Int_t i=0; i<n; i++) {
494      seedTree->GetEvent(i);
495      Int_t lbl = seed->GetLabel();
496      AliTRDtrack *tr = new AliTRDtrack(*seed,seed->GetAlpha());
497      tr->SetSeedLabel(lbl);
498      fSeeds->AddLast(tr);
499      fNseeds++;
500   }
501
502   delete seed;
503   delete seedTree;
504
505   out->cd();
506
507   AliTPCtrack *otrack=0;
508
509   sprintf(tname,"seedsTRDtoTOF1_%d",fEvent);  
510   TTree tofTree1(tname,"Tracks back propagated through TPC and TRD");
511   tofTree1.Branch("tracks","AliTPCtrack",&otrack,32000,0);  
512
513   sprintf(tname,"seedsTRDtoTOF2_%d",fEvent);  
514   TTree tofTree2(tname,"Tracks back propagated through TPC and TRD");
515   tofTree2.Branch("tracks","AliTPCtrack",&otrack,32000,0);  
516
517   sprintf(tname,"seedsTRDtoPHOS_%d",fEvent);  
518   TTree phosTree(tname,"Tracks back propagated through TPC and TRD");
519   phosTree.Branch("tracks","AliTPCtrack",&otrack,32000,0);  
520
521   sprintf(tname,"seedsTRDtoRICH_%d",fEvent);  
522   TTree richTree(tname,"Tracks back propagated through TPC and TRD");
523   richTree.Branch("tracks","AliTPCtrack",&otrack,32000,0);  
524
525   sprintf(tname,"TRDb_%d",fEvent);  
526   TTree trdTree(tname,"Back propagated TRD tracks at outer TRD time bin");
527   AliTRDtrack *otrack_trd=0;
528   trdTree.Branch("tracks","AliTRDtrack",&otrack_trd,32000,0);   
529      
530   Int_t found=0;  
531
532   Int_t nseed=fSeeds->GetEntriesFast();
533
534   //  Float_t foundMin = fMinClustersInTrack * fTimeBinsPerPlane * fGeom->Nplan(); 
535   Float_t foundMin = 0;
536
537   Int_t outermost_tb  = fTrSec[0]->GetOuterTimeBin();
538
539   for (Int_t i=0; i<nseed; i++) {  
540
541     AliTRDtrack *ps=(AliTRDtrack*)fSeeds->UncheckedAt(i), &s=*ps;
542     Int_t expectedClr = FollowBackProlongation(s);
543     Int_t foundClr = s.GetNumberOfClusters();
544     Int_t last_tb = fTrSec[0]->GetLayerNumber(s.GetX());
545
546     //    printf("seed %d: found %d out of %d expected clusters, Min is %f\n",
547     //     i, foundClr, expectedClr, foundMin);
548
549     if (foundClr >= foundMin) {
550       if(foundClr >= 2) {
551         s.CookdEdx(); 
552         CookLabel(ps, 1-fLabelFraction);
553         UseClusters(ps);
554       }
555       
556       // Propagate to outer reference plane [SR, GSI, 18.02.2003]
557       ps->PropagateTo(364.8);
558       otrack_trd=ps;
559       trdTree.Fill();
560       cout<<found++<<'\r';
561     }
562
563     if(((expectedClr < 10) && (last_tb == outermost_tb)) ||
564        ((expectedClr >= 10) && 
565         (((Float_t) foundClr) / ((Float_t) expectedClr) >= 
566          fMinFractionOfFoundClusters) && (last_tb == outermost_tb))) {
567
568       Double_t x_tof = 375.5;
569     
570       if(PropagateToOuterPlane(s,x_tof)) {
571         AliTPCtrack *pt = new AliTPCtrack(*ps,ps->GetAlpha());
572         otrack = pt;
573         tofTree1.Fill();
574         delete pt;
575
576         x_tof = 381.5;
577     
578         if(PropagateToOuterPlane(s,x_tof)) {
579           AliTPCtrack *pt = new AliTPCtrack(*ps,ps->GetAlpha());
580           otrack = pt;
581           tofTree2.Fill();
582           delete pt;
583
584           Double_t x_phos = 460.;
585           
586           if(PropagateToOuterPlane(s,x_phos)) {
587             AliTPCtrack *pt = new AliTPCtrack(*ps,ps->GetAlpha());
588             otrack = pt;
589             phosTree.Fill();
590             delete pt;
591             
592             Double_t x_rich = 490+1.267;
593             
594             if(PropagateToOuterPlane(s,x_rich)) {
595               AliTPCtrack *pt = new AliTPCtrack(*ps,ps->GetAlpha());
596               otrack = pt;
597               richTree.Fill();
598               delete pt;
599             }   
600           }
601         }
602       }      
603     }
604   }
605   
606   tofTree1.Write(); 
607   tofTree2.Write(); 
608   phosTree.Write(); 
609   richTree.Write(); 
610   trdTree.Write(); 
611
612   savedir->cd();  
613   cerr<<"Number of seeds: "<<nseed<<endl;  
614   cerr<<"Number of back propagated TRD tracks: "<<found<<endl;
615
616   UnloadEvent();
617
618   return 0;
619
620 }
621
622
623 //---------------------------------------------------------------------------
624 Int_t AliTRDtracker::FollowProlongation(AliTRDtrack& t, Int_t rf)
625 {
626   // Starting from current position on track=t this function tries
627   // to extrapolate the track up to timeBin=0 and to confirm prolongation
628   // if a close cluster is found. Returns the number of clusters
629   // expected to be found in sensitive layers
630
631   Float_t  wIndex, wTB, wChi2;
632   Float_t  wYrt, wYclosest, wYcorrect, wYwindow;
633   Float_t  wZrt, wZclosest, wZcorrect, wZwindow;
634   Float_t  wPx, wPy, wPz, wC;
635   Double_t Px, Py, Pz;
636   Float_t  wSigmaC2, wSigmaTgl2, wSigmaY2, wSigmaZ2;
637
638   Int_t trackIndex = t.GetLabel();  
639
640   Int_t ns=Int_t(2*TMath::Pi()/AliTRDgeometry::GetAlpha()+0.5);     
641
642   Int_t try_again=fMaxGap;
643
644   Double_t alpha=t.GetAlpha();
645
646   if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
647   if (alpha < 0.            ) alpha += 2.*TMath::Pi();
648
649   Int_t s=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::kNsect;  
650
651   Double_t rad_length, rho, x, dx, y, ymax, z;
652
653   Int_t expectedNumberOfClusters = 0;
654   Bool_t lookForCluster;
655
656   alpha=AliTRDgeometry::GetAlpha();  // note: change in meaning
657
658  
659   for (Int_t nr=fTrSec[0]->GetLayerNumber(t.GetX()); nr>rf; nr--) { 
660
661     y = t.GetY(); z = t.GetZ();
662
663     // first propagate to the inner surface of the current time bin 
664     fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,rad_length,lookForCluster);
665     x = fTrSec[s]->GetLayer(nr)->GetX()-dx/2; y = t.GetY(); z = t.GetZ();
666     if(!t.PropagateTo(x,rad_length,rho)) break;
667     y = t.GetY();
668     ymax = x*TMath::Tan(0.5*alpha);
669     if (y > ymax) {
670       s = (s+1) % ns;
671       if (!t.Rotate(alpha)) break;
672       if(!t.PropagateTo(x,rad_length,rho)) break;
673     } else if (y <-ymax) {
674       s = (s-1+ns) % ns;                           
675       if (!t.Rotate(-alpha)) break;   
676       if(!t.PropagateTo(x,rad_length,rho)) break;
677     } 
678
679     y = t.GetY(); z = t.GetZ();
680
681     // now propagate to the middle plane of the next time bin 
682     fTrSec[s]->GetLayer(nr-1)->GetPropagationParameters(y,z,dx,rho,rad_length,lookForCluster);
683     x = fTrSec[s]->GetLayer(nr-1)->GetX(); y = t.GetY(); z = t.GetZ();
684     if(!t.PropagateTo(x,rad_length,rho)) break;
685     y = t.GetY();
686     ymax = x*TMath::Tan(0.5*alpha);
687     if (y > ymax) {
688       s = (s+1) % ns;
689       if (!t.Rotate(alpha)) break;
690       if(!t.PropagateTo(x,rad_length,rho)) break;
691     } else if (y <-ymax) {
692       s = (s-1+ns) % ns;                           
693       if (!t.Rotate(-alpha)) break;   
694       if(!t.PropagateTo(x,rad_length,rho)) break;
695     } 
696
697
698     if(lookForCluster) {
699
700       expectedNumberOfClusters++;       
701       wIndex = (Float_t) t.GetLabel();
702       wTB = nr;
703
704       AliTRDpropagationLayer& time_bin=*(fTrSec[s]->GetLayer(nr-1));
705
706       Double_t sy2=ExpectedSigmaY2(x,t.GetTgl(),t.GetPt());
707       Double_t sz2=ExpectedSigmaZ2(x,t.GetTgl());
708
709       Double_t road;
710       if((t.GetSigmaY2() + sy2) > 0) road=10.*sqrt(t.GetSigmaY2() + sy2);
711       else return expectedNumberOfClusters;
712       
713       wYrt = (Float_t) y;
714       wZrt = (Float_t) z;
715       wYwindow = (Float_t) road;
716       t.GetPxPyPz(Px,Py,Pz);
717       wPx = (Float_t) Px;
718       wPy = (Float_t) Py;
719       wPz = (Float_t) Pz;
720       wC  = (Float_t) t.GetC();
721       wSigmaC2 = (Float_t) t.GetSigmaC2();
722       wSigmaTgl2    = (Float_t) t.GetSigmaTgl2();
723       wSigmaY2 = (Float_t) t.GetSigmaY2();
724       wSigmaZ2 = (Float_t) t.GetSigmaZ2();
725       wChi2 = -1;            
726       
727       if (road>fWideRoad) {
728         if (t.GetNumberOfClusters()>4)
729           cerr<<t.GetNumberOfClusters()
730               <<"FindProlongation warning: Too broad road !\n";
731         return 0;
732       }             
733
734       AliTRDcluster *cl=0;
735       UInt_t index=0;
736
737       Double_t max_chi2=fMaxChi2;
738
739       wYclosest = 12345678;
740       wYcorrect = 12345678;
741       wZclosest = 12345678;
742       wZcorrect = 12345678;
743       wZwindow  = TMath::Sqrt(2.25 * 12 * sz2);   
744
745       // Find the closest correct cluster for debugging purposes
746       if (time_bin) {
747         Float_t minDY = 1000000;
748         for (Int_t i=0; i<time_bin; i++) {
749           AliTRDcluster* c=(AliTRDcluster*)(time_bin[i]);
750           if((c->GetLabel(0) != trackIndex) &&
751              (c->GetLabel(1) != trackIndex) &&
752              (c->GetLabel(2) != trackIndex)) continue;
753           if(TMath::Abs(c->GetY() - y) > minDY) continue;
754           minDY = TMath::Abs(c->GetY() - y);
755           wYcorrect = c->GetY();
756           wZcorrect = c->GetZ();
757
758           Double_t h01 = GetTiltFactor(c);
759           wChi2 = t.GetPredictedChi2(c, h01);
760         }
761       }                    
762
763       // Now go for the real cluster search
764
765       if (time_bin) {
766
767         for (Int_t i=time_bin.Find(y-road); i<time_bin; i++) {
768           AliTRDcluster* c=(AliTRDcluster*)(time_bin[i]);
769           if (c->GetY() > y+road) break;
770           if (c->IsUsed() > 0) continue;
771           if((c->GetZ()-z)*(c->GetZ()-z) > 3 * sz2) continue;
772
773           Double_t h01 = GetTiltFactor(c);
774           Double_t chi2=t.GetPredictedChi2(c,h01);
775           
776           if (chi2 > max_chi2) continue;
777           max_chi2=chi2;
778           cl=c;
779           index=time_bin.GetIndex(i);
780         }               
781
782         if(!cl) {
783
784           for (Int_t i=time_bin.Find(y-road); i<time_bin; i++) {
785             AliTRDcluster* c=(AliTRDcluster*)(time_bin[i]);
786             
787             if (c->GetY() > y+road) break;
788             if (c->IsUsed() > 0) continue;
789             if((c->GetZ()-z)*(c->GetZ()-z) > 12 * sz2) continue;
790             
791             Double_t h01 = GetTiltFactor(c);
792             Double_t chi2=t.GetPredictedChi2(c, h01);
793             
794             if (chi2 > max_chi2) continue;
795             max_chi2=chi2;
796             cl=c;
797             index=time_bin.GetIndex(i);
798           }
799         }        
800         
801
802         if (cl) {
803           wYclosest = cl->GetY();
804           wZclosest = cl->GetZ();
805           Double_t h01 = GetTiltFactor(cl);
806
807           t.SetSampledEdx(cl->GetQ()/dx,t.GetNumberOfClusters()); 
808           if(!t.Update(cl,max_chi2,index,h01)) {
809             if(!try_again--) return 0;
810           }  
811           else try_again=fMaxGap;
812         }
813         else {
814           if (try_again==0) break; 
815           try_again--;
816         }
817
818         /*
819         if((((Int_t) wTB)%15 == 0) || (((Int_t) wTB)%15 == 14)) {
820           
821           printf(" %f", wIndex);       //1
822           printf(" %f", wTB);          //2
823           printf(" %f", wYrt);         //3
824           printf(" %f", wYclosest);    //4
825           printf(" %f", wYcorrect);    //5
826           printf(" %f", wYwindow);     //6
827           printf(" %f", wZrt);         //7
828           printf(" %f", wZclosest);    //8
829           printf(" %f", wZcorrect);    //9
830           printf(" %f", wZwindow);     //10
831           printf(" %f", wPx);          //11
832           printf(" %f", wPy);          //12
833           printf(" %f", wPz);          //13
834           printf(" %f", wSigmaC2*1000000);  //14
835           printf(" %f", wSigmaTgl2*1000);   //15
836           printf(" %f", wSigmaY2);     //16
837           //      printf(" %f", wSigmaZ2);     //17
838           printf(" %f", wChi2);     //17
839           printf(" %f", wC);           //18
840           printf("\n");
841         } 
842         */                        
843       }
844     }  
845   }
846   return expectedNumberOfClusters;
847   
848   
849 }                
850
851 //___________________________________________________________________
852
853 Int_t AliTRDtracker::FollowBackProlongation(AliTRDtrack& t)
854 {
855   // Starting from current radial position of track <t> this function
856   // extrapolates the track up to outer timebin and in the sensitive
857   // layers confirms prolongation if a close cluster is found. 
858   // Returns the number of clusters expected to be found in sensitive layers
859
860   Float_t  wIndex, wTB, wChi2;
861   Float_t  wYrt, wYclosest, wYcorrect, wYwindow;
862   Float_t  wZrt, wZclosest, wZcorrect, wZwindow;
863   Float_t  wPx, wPy, wPz, wC;
864   Double_t Px, Py, Pz;
865   Float_t  wSigmaC2, wSigmaTgl2, wSigmaY2, wSigmaZ2;
866
867   Int_t trackIndex = t.GetLabel();  
868
869   Int_t ns=Int_t(2*TMath::Pi()/AliTRDgeometry::GetAlpha()+0.5);     
870
871   Int_t try_again=fMaxGap;
872
873   Double_t alpha=t.GetAlpha();
874
875   if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
876   if (alpha < 0.            ) alpha += 2.*TMath::Pi();
877
878   Int_t s=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::kNsect;  
879
880   Int_t outerTB = fTrSec[0]->GetOuterTimeBin();
881
882   Double_t rad_length, rho, x, dx, y, ymax, z;
883
884   Bool_t lookForCluster;
885
886   Int_t expectedNumberOfClusters = 0;
887   x = t.GetX();
888
889   alpha=AliTRDgeometry::GetAlpha();  // note: change in meaning
890
891
892   for (Int_t nr=fTrSec[0]->GetLayerNumber(t.GetX()); nr<outerTB; nr++) { 
893
894     y = t.GetY(); z = t.GetZ();
895
896     // first propagate to the outer surface of the current time bin 
897
898     fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,rad_length,lookForCluster);
899     x = fTrSec[s]->GetLayer(nr)->GetX()+dx/2; y = t.GetY(); z = t.GetZ();
900
901     if(!t.PropagateTo(x,rad_length,rho)) break;
902
903     y = t.GetY();
904     ymax = x*TMath::Tan(0.5*alpha);
905
906     if (y > ymax) {
907       s = (s+1) % ns;
908       if (!t.Rotate(alpha)) break;
909       if(!t.PropagateTo(x,rad_length,rho)) break;
910     } else if (y <-ymax) {
911       s = (s-1+ns) % ns;                           
912       if (!t.Rotate(-alpha)) break;   
913       if(!t.PropagateTo(x,rad_length,rho)) break;
914     } 
915     y = t.GetY(); z = t.GetZ();
916
917     // now propagate to the middle plane of the next time bin 
918     fTrSec[s]->GetLayer(nr+1)->GetPropagationParameters(y,z,dx,rho,rad_length,lookForCluster);
919
920     x = fTrSec[s]->GetLayer(nr+1)->GetX(); y = t.GetY(); z = t.GetZ();
921
922     if(!t.PropagateTo(x,rad_length,rho)) break;
923
924     y = t.GetY();
925
926     ymax = x*TMath::Tan(0.5*alpha);
927
928     if(fVocal) printf("nr+1=%d, x %f, z %f, y %f, ymax %f\n",nr+1,x,z,y,ymax);
929
930     if (y > ymax) {
931       s = (s+1) % ns;
932       if (!t.Rotate(alpha)) break;
933       if(!t.PropagateTo(x,rad_length,rho)) break;
934     } else if (y <-ymax) {
935       s = (s-1+ns) % ns;              
936       if (!t.Rotate(-alpha)) break;   
937       if(!t.PropagateTo(x,rad_length,rho)) break;
938     } 
939
940     //    printf("label %d, pl %d, lookForCluster %d \n",
941     //     trackIndex, nr+1, lookForCluster);
942
943     if(lookForCluster) {
944       expectedNumberOfClusters++;       
945
946       wIndex = (Float_t) t.GetLabel();
947       wTB = fTrSec[s]->GetLayer(nr+1)->GetTimeBinIndex();
948
949       AliTRDpropagationLayer& time_bin=*(fTrSec[s]->GetLayer(nr+1));
950       Double_t sy2=ExpectedSigmaY2(t.GetX(),t.GetTgl(),t.GetPt());
951       Double_t sz2=ExpectedSigmaZ2(t.GetX(),t.GetTgl());
952       if((t.GetSigmaY2() + sy2) < 0) break;
953       Double_t road = 10.*sqrt(t.GetSigmaY2() + sy2); 
954       Double_t y=t.GetY(), z=t.GetZ();
955
956       wYrt = (Float_t) y;
957       wZrt = (Float_t) z;
958       wYwindow = (Float_t) road;
959       t.GetPxPyPz(Px,Py,Pz);
960       wPx = (Float_t) Px;
961       wPy = (Float_t) Py;
962       wPz = (Float_t) Pz;
963       wC  = (Float_t) t.GetC();
964       wSigmaC2 = (Float_t) t.GetSigmaC2();
965       wSigmaTgl2    = (Float_t) t.GetSigmaTgl2();
966       wSigmaY2 = (Float_t) t.GetSigmaY2();
967       wSigmaZ2 = (Float_t) t.GetSigmaZ2();
968       wChi2 = -1;            
969       
970       if (road>fWideRoad) {
971         if (t.GetNumberOfClusters()>4)
972           cerr<<t.GetNumberOfClusters()
973               <<"FindProlongation warning: Too broad road !\n";
974         return 0;
975       }      
976
977       AliTRDcluster *cl=0;
978       UInt_t index=0;
979
980       Double_t max_chi2=fMaxChi2;
981
982       wYclosest = 12345678;
983       wYcorrect = 12345678;
984       wZclosest = 12345678;
985       wZcorrect = 12345678;
986       wZwindow  = TMath::Sqrt(2.25 * 12 * sz2);   
987
988       // Find the closest correct cluster for debugging purposes
989       if (time_bin) {
990         Float_t minDY = 1000000;
991         for (Int_t i=0; i<time_bin; i++) {
992           AliTRDcluster* c=(AliTRDcluster*)(time_bin[i]);
993           if((c->GetLabel(0) != trackIndex) &&
994              (c->GetLabel(1) != trackIndex) &&
995              (c->GetLabel(2) != trackIndex)) continue;
996           if(TMath::Abs(c->GetY() - y) > minDY) continue;
997           minDY = TMath::Abs(c->GetY() - y);
998           wYcorrect = c->GetY();
999           wZcorrect = c->GetZ();
1000
1001           Double_t h01 = GetTiltFactor(c);
1002           wChi2 = t.GetPredictedChi2(c, h01);
1003         }
1004       }                    
1005
1006       // Now go for the real cluster search
1007
1008       if (time_bin) {
1009
1010         for (Int_t i=time_bin.Find(y-road); i<time_bin; i++) {
1011           AliTRDcluster* c=(AliTRDcluster*)(time_bin[i]);
1012           if (c->GetY() > y+road) break;
1013           //          if (c->IsUsed() > 0) continue;
1014           if((c->GetZ()-z)*(c->GetZ()-z) > 3 * sz2) continue;
1015
1016           Double_t h01 = GetTiltFactor(c);
1017           Double_t chi2=t.GetPredictedChi2(c,h01);
1018           
1019           if (chi2 > max_chi2) continue;
1020           max_chi2=chi2;
1021           cl=c;
1022           index=time_bin.GetIndex(i);
1023         }               
1024         
1025         if(!cl) {
1026
1027           for (Int_t i=time_bin.Find(y-road); i<time_bin; i++) {
1028             AliTRDcluster* c=(AliTRDcluster*)(time_bin[i]);
1029             
1030             if (c->GetY() > y+road) break;
1031             //            if (c->IsUsed() > 0) continue;
1032             if((c->GetZ()-z)*(c->GetZ()-z) > 2.25 * 12 * sz2) continue;
1033             
1034             Double_t h01 = GetTiltFactor(c);
1035             Double_t chi2=t.GetPredictedChi2(c,h01);
1036             
1037             if (chi2 > max_chi2) continue;
1038             max_chi2=chi2;
1039             cl=c;
1040             index=time_bin.GetIndex(i);
1041           }
1042         }        
1043         
1044         if (cl) {
1045           wYclosest = cl->GetY();
1046           wZclosest = cl->GetZ();
1047
1048           t.SetSampledEdx(cl->GetQ()/dx,t.GetNumberOfClusters()); 
1049           Double_t h01 = GetTiltFactor(cl);
1050           if(!t.Update(cl,max_chi2,index,h01)) {
1051             if(!try_again--) return 0;
1052           }  
1053           else try_again=fMaxGap;
1054         }
1055         else {
1056           if (try_again==0) break; 
1057           try_again--;
1058         }
1059
1060         /*
1061         if((((Int_t) wTB)%15 == 0) || (((Int_t) wTB)%15 == 14)) {
1062           
1063           printf(" %f", wIndex);       //1
1064           printf(" %f", wTB);          //2
1065           printf(" %f", wYrt);         //3
1066           printf(" %f", wYclosest);    //4
1067           printf(" %f", wYcorrect);    //5
1068           printf(" %f", wYwindow);     //6
1069           printf(" %f", wZrt);         //7
1070           printf(" %f", wZclosest);    //8
1071           printf(" %f", wZcorrect);    //9
1072           printf(" %f", wZwindow);     //10
1073           printf(" %f", wPx);          //11
1074           printf(" %f", wPy);          //12
1075           printf(" %f", wPz);          //13
1076           printf(" %f", wSigmaC2*1000000);  //14
1077           printf(" %f", wSigmaTgl2*1000);   //15
1078           printf(" %f", wSigmaY2);     //16
1079           //      printf(" %f", wSigmaZ2);     //17
1080           printf(" %f", wChi2);     //17
1081           printf(" %f", wC);           //18
1082           printf("\n");
1083         } 
1084         */                        
1085       }
1086     }  
1087   }
1088   return expectedNumberOfClusters;
1089 }         
1090
1091 //___________________________________________________________________
1092
1093 Int_t AliTRDtracker::PropagateToOuterPlane(AliTRDtrack& t, Double_t xToGo)
1094 {
1095   // Starting from current radial position of track <t> this function
1096   // extrapolates the track up to radial position <xToGo>. 
1097   // Returns 1 if track reaches the plane, and 0 otherwise 
1098
1099   Int_t ns=Int_t(2*TMath::Pi()/AliTRDgeometry::GetAlpha()+0.5);     
1100
1101   Double_t alpha=t.GetAlpha();
1102
1103   if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
1104   if (alpha < 0.            ) alpha += 2.*TMath::Pi();
1105
1106   Int_t s=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::kNsect;  
1107
1108   Bool_t lookForCluster;
1109   Double_t rad_length, rho, x, dx, y, ymax, z;
1110
1111   x = t.GetX();
1112
1113   alpha=AliTRDgeometry::GetAlpha();  // note: change in meaning
1114
1115   Int_t plToGo = fTrSec[0]->GetLayerNumber(xToGo);
1116
1117   for (Int_t nr=fTrSec[0]->GetLayerNumber(x); nr<plToGo; nr++) { 
1118
1119     y = t.GetY(); z = t.GetZ();
1120
1121     // first propagate to the outer surface of the current time bin 
1122     fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,rad_length,lookForCluster);
1123     x = fTrSec[s]->GetLayer(nr)->GetX()+dx/2; y = t.GetY(); z = t.GetZ();
1124     if(!t.PropagateTo(x,rad_length,rho)) return 0;
1125     y = t.GetY();
1126     ymax = x*TMath::Tan(0.5*alpha);
1127     if (y > ymax) {
1128       s = (s+1) % ns;
1129       if (!t.Rotate(alpha)) return 0;
1130     } else if (y <-ymax) {
1131       s = (s-1+ns) % ns;                           
1132       if (!t.Rotate(-alpha)) return 0;   
1133     } 
1134     if(!t.PropagateTo(x,rad_length,rho)) return 0;
1135
1136     y = t.GetY(); z = t.GetZ();
1137
1138     // now propagate to the middle plane of the next time bin 
1139     fTrSec[s]->GetLayer(nr+1)->GetPropagationParameters(y,z,dx,rho,rad_length,lookForCluster);
1140     x = fTrSec[s]->GetLayer(nr+1)->GetX(); y = t.GetY(); z = t.GetZ();
1141     if(!t.PropagateTo(x,rad_length,rho)) return 0;
1142     y = t.GetY();
1143     ymax = x*TMath::Tan(0.5*alpha);
1144     if (y > ymax) {
1145       s = (s+1) % ns;
1146       if (!t.Rotate(alpha)) return 0;
1147     } else if (y <-ymax) {
1148       s = (s-1+ns) % ns;                           
1149       if (!t.Rotate(-alpha)) return 0;   
1150     } 
1151     if(!t.PropagateTo(x,rad_length,rho)) return 0;
1152   }
1153   return 1;
1154 }         
1155
1156 //___________________________________________________________________
1157
1158 Int_t AliTRDtracker::PropagateToTPC(AliTRDtrack& t)
1159 {
1160   // Starting from current radial position of track <t> this function
1161   // extrapolates the track up to radial position of the outermost
1162   // padrow of the TPC. 
1163   // Returns 1 if track reaches the TPC, and 0 otherwise 
1164
1165   Int_t ns=Int_t(2*TMath::Pi()/AliTRDgeometry::GetAlpha()+0.5);     
1166
1167   Double_t alpha=t.GetAlpha();
1168
1169   if (alpha > 2.*TMath::Pi()) alpha -= 2.*TMath::Pi();
1170   if (alpha < 0.            ) alpha += 2.*TMath::Pi();
1171
1172   Int_t s=Int_t(alpha/AliTRDgeometry::GetAlpha())%AliTRDgeometry::kNsect;  
1173
1174   Bool_t lookForCluster;
1175   Double_t rad_length, rho, x, dx, y, ymax, z;
1176
1177   x = t.GetX();
1178
1179   alpha=AliTRDgeometry::GetAlpha();  // note: change in meaning
1180
1181   Int_t plTPC = fTrSec[0]->GetLayerNumber(246.055);
1182
1183   for (Int_t nr=fTrSec[0]->GetLayerNumber(x); nr>plTPC; nr--) { 
1184
1185     y = t.GetY(); z = t.GetZ();
1186
1187     // first propagate to the outer surface of the current time bin 
1188     fTrSec[s]->GetLayer(nr)->GetPropagationParameters(y,z,dx,rho,rad_length,lookForCluster);
1189     x = fTrSec[s]->GetLayer(nr)->GetX()-dx/2; y = t.GetY(); z = t.GetZ();
1190     if(!t.PropagateTo(x,rad_length,rho)) return 0;
1191     y = t.GetY();
1192     ymax = x*TMath::Tan(0.5*alpha);
1193     if (y > ymax) {
1194       s = (s+1) % ns;
1195       if (!t.Rotate(alpha)) return 0;
1196     } else if (y <-ymax) {
1197       s = (s-1+ns) % ns;                           
1198       if (!t.Rotate(-alpha)) return 0;   
1199     } 
1200     if(!t.PropagateTo(x,rad_length,rho)) return 0;
1201
1202     y = t.GetY(); z = t.GetZ();
1203
1204     // now propagate to the middle plane of the next time bin 
1205     fTrSec[s]->GetLayer(nr-1)->GetPropagationParameters(y,z,dx,rho,rad_length,lookForCluster);
1206     x = fTrSec[s]->GetLayer(nr-1)->GetX(); y = t.GetY(); z = t.GetZ();
1207     if(!t.PropagateTo(x,rad_length,rho)) return 0;
1208     y = t.GetY();
1209     ymax = x*TMath::Tan(0.5*alpha);
1210     if (y > ymax) {
1211       s = (s+1) % ns;
1212       if (!t.Rotate(alpha)) return 0;
1213     } else if (y <-ymax) {
1214       s = (s-1+ns) % ns;                           
1215       if (!t.Rotate(-alpha)) return 0;   
1216     } 
1217     if(!t.PropagateTo(x,rad_length,rho)) return 0;
1218   }
1219   return 1;
1220 }         
1221
1222
1223 //_____________________________________________________________________________
1224 void AliTRDtracker::LoadEvent()
1225 {
1226   // Fills clusters into TRD tracking_sectors 
1227   // Note that the numbering scheme for the TRD tracking_sectors 
1228   // differs from that of TRD sectors
1229
1230   ReadClusters(fClusters);
1231   Int_t ncl=fClusters->GetEntriesFast();
1232   cout<<"\n LoadSectors: sorting "<<ncl<<" clusters"<<endl;
1233               
1234   UInt_t index;
1235   while (ncl--) {
1236     printf("\r %d left  ",ncl); 
1237     AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(ncl);
1238     Int_t detector=c->GetDetector(), local_time_bin=c->GetLocalTimeBin();
1239     Int_t sector=fGeom->GetSector(detector);
1240     Int_t plane=fGeom->GetPlane(detector);
1241
1242     Int_t tracking_sector = CookSectorIndex(sector);
1243
1244     Int_t gtb = fTrSec[tracking_sector]->CookTimeBinIndex(plane,local_time_bin);
1245     if(gtb < 0) continue; 
1246     Int_t layer = fTrSec[tracking_sector]->GetLayerNumber(gtb);
1247
1248     index=ncl;
1249     fTrSec[tracking_sector]->GetLayer(layer)->InsertCluster(c,index);
1250   }    
1251   printf("\r\n");
1252
1253 }
1254
1255 //_____________________________________________________________________________
1256 void AliTRDtracker::UnloadEvent() 
1257
1258   //
1259   // Clears the arrays of clusters and tracks. Resets sectors and timebins 
1260   //
1261
1262   Int_t i, nentr;
1263
1264   nentr = fClusters->GetEntriesFast();
1265   for (i = 0; i < nentr; i++) delete fClusters->RemoveAt(i);
1266
1267   nentr = fSeeds->GetEntriesFast();
1268   for (i = 0; i < nentr; i++) delete fSeeds->RemoveAt(i);
1269
1270   nentr = fTracks->GetEntriesFast();
1271   for (i = 0; i < nentr; i++) delete fTracks->RemoveAt(i);
1272
1273   Int_t nsec = AliTRDgeometry::kNsect;
1274
1275   for (i = 0; i < nsec; i++) {    
1276     for(Int_t pl = 0; pl < fTrSec[i]->GetNumberOfLayers(); pl++) {
1277       fTrSec[i]->GetLayer(pl)->Clear();
1278     }
1279   }
1280
1281 }
1282
1283 //__________________________________________________________________________
1284 void AliTRDtracker::MakeSeeds(Int_t inner, Int_t outer, Int_t turn)
1285 {
1286   // Creates track seeds using clusters in timeBins=i1,i2
1287
1288   if(turn > 2) {
1289     cerr<<"MakeSeeds: turn "<<turn<<" exceeds the limit of 2"<<endl;
1290     return;
1291   }
1292
1293   Double_t x[5], c[15];
1294   Int_t max_sec=AliTRDgeometry::kNsect;
1295   
1296   Double_t alpha=AliTRDgeometry::GetAlpha();
1297   Double_t shift=AliTRDgeometry::GetAlpha()/2.;
1298   Double_t cs=cos(alpha), sn=sin(alpha);
1299   Double_t cs2=cos(2.*alpha), sn2=sin(2.*alpha);
1300     
1301       
1302   Int_t i2 = fTrSec[0]->GetLayerNumber(inner);
1303   Int_t i1 = fTrSec[0]->GetLayerNumber(outer);
1304       
1305   Double_t x1 =fTrSec[0]->GetX(i1);
1306   Double_t xx2=fTrSec[0]->GetX(i2);
1307       
1308   for (Int_t ns=0; ns<max_sec; ns++) {
1309     
1310     Int_t nl2 = *(fTrSec[(ns-2+max_sec)%max_sec]->GetLayer(i2));
1311     Int_t nl=(*fTrSec[(ns-1+max_sec)%max_sec]->GetLayer(i2));
1312     Int_t nm=(*fTrSec[ns]->GetLayer(i2));
1313     Int_t nu=(*fTrSec[(ns+1)%max_sec]->GetLayer(i2));
1314     Int_t nu2=(*fTrSec[(ns+2)%max_sec]->GetLayer(i2));
1315     
1316     AliTRDpropagationLayer& r1=*(fTrSec[ns]->GetLayer(i1));
1317     
1318     for (Int_t is=0; is < r1; is++) {
1319       Double_t y1=r1[is]->GetY(), z1=r1[is]->GetZ();
1320       
1321       for (Int_t js=0; js < nl2+nl+nm+nu+nu2; js++) {
1322         
1323         const AliTRDcluster *cl;
1324         Double_t x2,   y2,   z2;
1325         Double_t x3=0., y3=0.;   
1326         
1327         if (js<nl2) {
1328           if(turn != 2) continue;
1329           AliTRDpropagationLayer& r2=*(fTrSec[(ns-2+max_sec)%max_sec]->GetLayer(i2));
1330           cl=r2[js];
1331           y2=cl->GetY(); z2=cl->GetZ();
1332           
1333           x2= xx2*cs2+y2*sn2;
1334           y2=-xx2*sn2+y2*cs2;
1335         }
1336         else if (js<nl2+nl) {
1337           if(turn != 1) continue;
1338           AliTRDpropagationLayer& r2=*(fTrSec[(ns-1+max_sec)%max_sec]->GetLayer(i2));
1339           cl=r2[js-nl2];
1340           y2=cl->GetY(); z2=cl->GetZ();
1341           
1342           x2= xx2*cs+y2*sn;
1343           y2=-xx2*sn+y2*cs;
1344         }                                
1345         else if (js<nl2+nl+nm) {
1346           if(turn != 1) continue;
1347           AliTRDpropagationLayer& r2=*(fTrSec[ns]->GetLayer(i2));
1348           cl=r2[js-nl2-nl];
1349           x2=xx2; y2=cl->GetY(); z2=cl->GetZ();
1350         }
1351         else if (js<nl2+nl+nm+nu) {
1352           if(turn != 1) continue;
1353           AliTRDpropagationLayer& r2=*(fTrSec[(ns+1)%max_sec]->GetLayer(i2));
1354           cl=r2[js-nl2-nl-nm];
1355           y2=cl->GetY(); z2=cl->GetZ();
1356           
1357           x2=xx2*cs-y2*sn;
1358           y2=xx2*sn+y2*cs;
1359         }              
1360         else {
1361           if(turn != 2) continue;
1362           AliTRDpropagationLayer& r2=*(fTrSec[(ns+2)%max_sec]->GetLayer(i2));
1363           cl=r2[js-nl2-nl-nm-nu];
1364           y2=cl->GetY(); z2=cl->GetZ();
1365           
1366           x2=xx2*cs2-y2*sn2;
1367           y2=xx2*sn2+y2*cs2;
1368         }
1369         
1370         if(TMath::Abs(z1-z2) > fMaxSeedDeltaZ12) continue;
1371         
1372         Double_t zz=z1 - z1/x1*(x1-x2);
1373         
1374         if (TMath::Abs(zz-z2)>fMaxSeedDeltaZ) continue;
1375         
1376         Double_t d=(x2-x1)*(0.-y2)-(0.-x2)*(y2-y1);
1377         if (d==0.) {cerr<<"TRD MakeSeeds: Straight seed !\n"; continue;}
1378         
1379         x[0]=y1;
1380         x[1]=z1;
1381         x[4]=f1trd(x1,y1,x2,y2,x3,y3);
1382         
1383         if (TMath::Abs(x[4]) > fMaxSeedC) continue;      
1384         
1385         x[2]=f2trd(x1,y1,x2,y2,x3,y3);
1386         
1387         if (TMath::Abs(x[4]*x1-x[2]) >= 0.99999) continue;
1388         
1389         x[3]=f3trd(x1,y1,x2,y2,z1,z2);
1390         
1391         if (TMath::Abs(x[3]) > fMaxSeedTan) continue;
1392         
1393         Double_t a=asin(x[2]);
1394         Double_t zv=z1 - x[3]/x[4]*(a+asin(x[4]*x1-x[2]));
1395         
1396         if (TMath::Abs(zv)>fMaxSeedVertexZ) continue;
1397         
1398         Double_t sy1=r1[is]->GetSigmaY2(), sz1=r1[is]->GetSigmaZ2();
1399         Double_t sy2=cl->GetSigmaY2(),     sz2=cl->GetSigmaZ2();
1400         Double_t sy3=fSeedErrorSY3, sy=fSeedErrorSY, sz=fSeedErrorSZ;  
1401
1402         // Tilt changes
1403         Double_t h01 = GetTiltFactor(r1[is]);
1404         Double_t xu_factor = 100.;
1405         if(fNoTilt) { 
1406           h01 = 0;
1407           xu_factor = 1;
1408         }
1409
1410         sy1=sy1+sz1*h01*h01;
1411         Double_t syz=sz1*(-h01);
1412         // end of tilt changes
1413         
1414         Double_t f40=(f1trd(x1,y1+sy,x2,y2,x3,y3)-x[4])/sy;
1415         Double_t f42=(f1trd(x1,y1,x2,y2+sy,x3,y3)-x[4])/sy;
1416         Double_t f43=(f1trd(x1,y1,x2,y2,x3,y3+sy)-x[4])/sy;
1417         Double_t f20=(f2trd(x1,y1+sy,x2,y2,x3,y3)-x[2])/sy;
1418         Double_t f22=(f2trd(x1,y1,x2,y2+sy,x3,y3)-x[2])/sy;
1419         Double_t f23=(f2trd(x1,y1,x2,y2,x3,y3+sy)-x[2])/sy;
1420         Double_t f30=(f3trd(x1,y1+sy,x2,y2,z1,z2)-x[3])/sy;
1421         Double_t f31=(f3trd(x1,y1,x2,y2,z1+sz,z2)-x[3])/sz;
1422         Double_t f32=(f3trd(x1,y1,x2,y2+sy,z1,z2)-x[3])/sy;
1423         Double_t f34=(f3trd(x1,y1,x2,y2,z1,z2+sz)-x[3])/sz;    
1424
1425         
1426         c[0]=sy1;
1427         //        c[1]=0.;       c[2]=sz1;
1428         c[1]=syz;       c[2]=sz1*xu_factor;
1429         c[3]=f20*sy1;  c[4]=0.;       c[5]=f20*sy1*f20+f22*sy2*f22+f23*sy3*f23;
1430         c[6]=f30*sy1;  c[7]=f31*sz1;  c[8]=f30*sy1*f20+f32*sy2*f22;
1431                        c[9]=f30*sy1*f30+f31*sz1*f31+f32*sy2*f32+f34*sz2*f34;
1432         c[10]=f40*sy1; c[11]=0.; c[12]=f40*sy1*f20+f42*sy2*f22+f43*sy3*f23;
1433         c[13]=f30*sy1*f40+f32*sy2*f42;
1434         c[14]=f40*sy1*f40+f42*sy2*f42+f43*sy3*f43;      
1435         
1436         UInt_t index=r1.GetIndex(is);
1437         
1438         AliTRDtrack *track=new AliTRDtrack(r1[is],index,x,c,x1,ns*alpha+shift);
1439
1440         Int_t rc=FollowProlongation(*track, i2);     
1441         
1442         if ((rc < 1) ||
1443             (track->GetNumberOfClusters() < 
1444              (outer-inner)*fMinClustersInSeed)) delete track;
1445         else {
1446           fSeeds->AddLast(track); fNseeds++;
1447           cerr<<"\r found seed "<<fNseeds;
1448         }
1449       }
1450     }
1451   }
1452 }            
1453
1454 //_____________________________________________________________________________
1455 void AliTRDtracker::ReadClusters(TObjArray *array, const TFile *inp) 
1456 {
1457   //
1458   // Reads AliTRDclusters (option >= 0) or AliTRDrecPoints (option < 0) 
1459   // from the file. The names of the cluster tree and branches 
1460   // should match the ones used in AliTRDclusterizer::WriteClusters()
1461   //
1462
1463   TDirectory *savedir=gDirectory; 
1464
1465   if (inp) {
1466      TFile *in=(TFile*)inp;
1467      if (!in->IsOpen()) {
1468         cerr<<"AliTRDtracker::ReadClusters(): input file is not open !\n";
1469         return;
1470      }
1471      else{
1472        in->cd();
1473      }
1474   }
1475
1476   Char_t treeName[12];
1477   sprintf(treeName,"TreeR%d_TRD",fEvent);
1478   TTree *ClusterTree = (TTree*) gDirectory->Get(treeName);
1479   
1480   TObjArray *ClusterArray = new TObjArray(400); 
1481   
1482   ClusterTree->GetBranch("TRDcluster")->SetAddress(&ClusterArray); 
1483   
1484   Int_t nEntries = (Int_t) ClusterTree->GetEntries();
1485   printf("found %d entries in %s.\n",nEntries,ClusterTree->GetName());
1486   
1487   // Loop through all entries in the tree
1488   Int_t nbytes;
1489   AliTRDcluster *c = 0;
1490   printf("\n");
1491
1492   for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {    
1493     
1494     // Import the tree
1495     nbytes += ClusterTree->GetEvent(iEntry);  
1496     
1497     // Get the number of points in the detector
1498     Int_t nCluster = ClusterArray->GetEntriesFast();  
1499     printf("\r Read %d clusters from entry %d", nCluster, iEntry);
1500     
1501     // Loop through all TRD digits
1502     for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) { 
1503       c = (AliTRDcluster*)ClusterArray->UncheckedAt(iCluster);
1504       AliTRDcluster *co = new AliTRDcluster(*c);
1505       co->SetSigmaY2(c->GetSigmaY2() * fSY2corr);
1506       Int_t ltb = co->GetLocalTimeBin();
1507       if(ltb == 19) co->SetSigmaZ2(c->GetSigmaZ2());
1508       else if(fNoTilt) co->SetSigmaZ2(c->GetSigmaZ2() * fSZ2corr);
1509       array->AddLast(co);
1510       delete ClusterArray->RemoveAt(iCluster); 
1511     }
1512   }
1513
1514   delete ClusterArray;
1515   savedir->cd();   
1516
1517 }
1518
1519 //______________________________________________________________________
1520 void AliTRDtracker::ReadClusters(TObjArray *array, const Char_t *filename)
1521 {
1522   //
1523   // Reads AliTRDclusters from file <filename>. The names of the cluster
1524   // tree and branches should match the ones used in
1525   // AliTRDclusterizer::WriteClusters()
1526   // if <array> == 0, clusters are added into AliTRDtracker fCluster array
1527   //
1528
1529   TDirectory *savedir=gDirectory;
1530
1531   TFile *file = TFile::Open(filename);
1532   if (!file->IsOpen()) {
1533     cerr<<"Can't open file with TRD clusters"<<endl;
1534     return;
1535   }
1536
1537   Char_t treeName[12];
1538   sprintf(treeName,"TreeR%d_TRD",fEvent);
1539   TTree *ClusterTree = (TTree*) gDirectory->Get(treeName);
1540
1541   if (!ClusterTree) {
1542      cerr<<"AliTRDtracker::ReadClusters(): ";
1543      cerr<<"can't get a tree with clusters !\n";
1544      return;
1545   }
1546
1547   TObjArray *ClusterArray = new TObjArray(400);
1548
1549   ClusterTree->GetBranch("TRDcluster")->SetAddress(&ClusterArray);
1550
1551   Int_t nEntries = (Int_t) ClusterTree->GetEntries();
1552   cout<<"found "<<nEntries<<" in ClusterTree"<<endl;   
1553
1554   // Loop through all entries in the tree
1555   Int_t nbytes;
1556   AliTRDcluster *c = 0;
1557
1558   printf("\n");
1559
1560   for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
1561
1562     // Import the tree
1563     nbytes += ClusterTree->GetEvent(iEntry);
1564
1565     // Get the number of points in the detector
1566     Int_t nCluster = ClusterArray->GetEntriesFast();
1567     printf("\n Read %d clusters from entry %d", nCluster, iEntry);
1568
1569     // Loop through all TRD digits
1570     for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
1571       c = (AliTRDcluster*)ClusterArray->UncheckedAt(iCluster);
1572       AliTRDcluster *co = new AliTRDcluster(*c);
1573       co->SetSigmaY2(c->GetSigmaY2() * fSY2corr);
1574       Int_t ltb = co->GetLocalTimeBin();
1575       if(ltb == 19) co->SetSigmaZ2(c->GetSigmaZ2());
1576       else if(fNoTilt) co->SetSigmaZ2(c->GetSigmaZ2() * fSZ2corr);
1577       array->AddLast(co);
1578       delete ClusterArray->RemoveAt(iCluster);
1579     }
1580   }
1581
1582   file->Close();
1583   delete ClusterArray;
1584   savedir->cd();
1585
1586 }                      
1587
1588
1589 //__________________________________________________________________
1590 void AliTRDtracker::CookLabel(AliKalmanTrack* pt, Float_t wrong) const {
1591
1592   Int_t label=123456789, index, i, j;
1593   Int_t ncl=pt->GetNumberOfClusters();
1594   const Int_t range = fTrSec[0]->GetOuterTimeBin()+1;
1595
1596   Bool_t label_added;
1597
1598   //  Int_t s[range][2];
1599   Int_t **s = new Int_t* [range];
1600   for (i=0; i<range; i++) {
1601     s[i] = new Int_t[2];
1602   }
1603   for (i=0; i<range; i++) {
1604     s[i][0]=-1;
1605     s[i][1]=0;
1606   }
1607
1608   Int_t t0,t1,t2;
1609   for (i=0; i<ncl; i++) {
1610     index=pt->GetClusterIndex(i);
1611     AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
1612     t0=c->GetLabel(0);
1613     t1=c->GetLabel(1);
1614     t2=c->GetLabel(2);
1615   }
1616
1617   for (i=0; i<ncl; i++) {
1618     index=pt->GetClusterIndex(i);
1619     AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
1620     for (Int_t k=0; k<3; k++) { 
1621       label=c->GetLabel(k);
1622       label_added=kFALSE; j=0;
1623       if (label >= 0) {
1624         while ( (!label_added) && ( j < range ) ) {
1625           if (s[j][0]==label || s[j][1]==0) {
1626             s[j][0]=label; 
1627             s[j][1]=s[j][1]+1; 
1628             label_added=kTRUE;
1629           }
1630           j++;
1631         }
1632       }
1633     }
1634   }
1635
1636   Int_t max=0;
1637   label = -123456789;
1638
1639   for (i=0; i<range; i++) {
1640     if (s[i][1]>max) {
1641       max=s[i][1]; label=s[i][0];
1642     }
1643   }
1644
1645   for (i=0; i<range; i++) {
1646     delete []s[i];
1647   }        
1648
1649   delete []s;
1650
1651   if ((1.- Float_t(max)/ncl) > wrong) label=-label;   
1652
1653   pt->SetLabel(label); 
1654
1655 }
1656
1657
1658 //__________________________________________________________________
1659 void AliTRDtracker::UseClusters(const AliKalmanTrack* t, Int_t from) const {
1660   Int_t ncl=t->GetNumberOfClusters();
1661   for (Int_t i=from; i<ncl; i++) {
1662     Int_t index = t->GetClusterIndex(i);
1663     AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(index);
1664     c->Use();
1665   }
1666 }
1667
1668
1669 //_____________________________________________________________________
1670 Double_t AliTRDtracker::ExpectedSigmaY2(Double_t r, Double_t tgl, Double_t pt)
1671 {
1672   // Parametrised "expected" error of the cluster reconstruction in Y 
1673
1674   Double_t s = 0.08 * 0.08;    
1675   return s;
1676 }
1677
1678 //_____________________________________________________________________
1679 Double_t AliTRDtracker::ExpectedSigmaZ2(Double_t r, Double_t tgl)
1680 {
1681   // Parametrised "expected" error of the cluster reconstruction in Z 
1682
1683   Double_t s = 9 * 9 /12.;  
1684   return s;
1685 }                  
1686
1687
1688 //_____________________________________________________________________
1689 Double_t AliTRDtracker::GetX(Int_t sector, Int_t plane, Int_t local_tb) const 
1690 {
1691   //
1692   // Returns radial position which corresponds to time bin <local_tb>
1693   // in tracking sector <sector> and plane <plane>
1694   //
1695
1696   Int_t index = fTrSec[sector]->CookTimeBinIndex(plane, local_tb); 
1697   Int_t pl = fTrSec[sector]->GetLayerNumber(index);
1698   return fTrSec[sector]->GetLayer(pl)->GetX();
1699
1700 }
1701
1702
1703 //_______________________________________________________
1704 AliTRDtracker::AliTRDpropagationLayer::AliTRDpropagationLayer(Double_t x, 
1705                Double_t dx, Double_t rho, Double_t rad_length, Int_t tb_index)
1706
1707   //
1708   // AliTRDpropagationLayer constructor
1709   //
1710
1711   fN = 0; fX = x; fdX = dx; fRho = rho; fX0 = rad_length;
1712   fClusters = NULL; fIndex = NULL; fTimeBinIndex = tb_index;
1713
1714
1715   for(Int_t i=0; i < (Int_t) kZONES; i++) {
1716     fZc[i]=0; fZmax[i] = 0;
1717   }
1718
1719   fYmax = 0;
1720
1721   if(fTimeBinIndex >= 0) { 
1722     fClusters = new AliTRDcluster*[kMAX_CLUSTER_PER_TIME_BIN];
1723     fIndex = new UInt_t[kMAX_CLUSTER_PER_TIME_BIN];
1724   }
1725
1726   fHole = kFALSE;
1727   fHoleZc = 0;
1728   fHoleZmax = 0;
1729   fHoleYc = 0;
1730   fHoleYmax = 0;
1731   fHoleRho = 0;
1732   fHoleX0 = 0;
1733
1734 }
1735
1736 //_______________________________________________________
1737 void AliTRDtracker::AliTRDpropagationLayer::SetHole(
1738           Double_t Zmax, Double_t Ymax, Double_t rho, 
1739           Double_t rad_length, Double_t Yc, Double_t Zc) 
1740 {
1741   //
1742   // Sets hole in the layer 
1743   //
1744
1745   fHole = kTRUE;
1746   fHoleZc = Zc;
1747   fHoleZmax = Zmax;
1748   fHoleYc = Yc;
1749   fHoleYmax = Ymax;
1750   fHoleRho = rho;
1751   fHoleX0 = rad_length;
1752 }
1753   
1754
1755 //_______________________________________________________
1756 AliTRDtracker::AliTRDtrackingSector::AliTRDtrackingSector(AliTRDgeometry* geo, Int_t gs, AliTRDparameter* par)
1757 {
1758   //
1759   // AliTRDtrackingSector Constructor
1760   //
1761
1762   fGeom = geo;
1763   fPar = par;
1764   fGeomSector = gs;
1765   fTzeroShift = 0.13;
1766   fN = 0;
1767
1768   for(UInt_t i=0; i < kMAX_TIME_BIN_INDEX; i++) fTimeBinIndex[i] = -1;
1769
1770
1771   AliTRDpropagationLayer* ppl;
1772
1773   Double_t x, xin, xout, dx, rho, rad_length;
1774   Int_t    steps;
1775
1776   // set time bins in the gas of the TPC
1777
1778   xin = 246.055; xout = 254.055; steps = 20; dx = (xout-xin)/steps;
1779   rho = 0.9e-3;  rad_length = 28.94;
1780
1781   for(Int_t i=0; i<steps; i++) {
1782     x = xin + i*dx + dx/2;
1783     ppl = new AliTRDpropagationLayer(x,dx,rho,rad_length,-1);
1784     InsertLayer(ppl);
1785   }
1786
1787   // set time bins in the outer field cage vessel
1788
1789   dx = 50e-4; xin = xout; xout = xin + dx; rho = 1.71; rad_length = 44.77; // Tedlar
1790   ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,rad_length,-1);
1791   InsertLayer(ppl);
1792
1793   dx = 0.02; xin = xout; xout = xin + dx; rho = 1.45; rad_length = 44.86; // prepreg
1794   ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,rad_length,-1);
1795   InsertLayer(ppl);
1796
1797   dx = 2.; xin = xout; xout = xin + dx; rho = 1.45*0.02; rad_length = 41.28; // Nomex
1798   steps = 5; dx = (xout - xin)/steps;
1799   for(Int_t i=0; i<steps; i++) {
1800     x = xin + i*dx + dx/2;
1801     ppl = new AliTRDpropagationLayer(x,dx,rho,rad_length,-1);
1802     InsertLayer(ppl);
1803   }
1804
1805   dx = 0.02; xin = xout; xout = xin + dx; rho = 1.45; rad_length = 44.86; // prepreg
1806   ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,rad_length,-1);
1807   InsertLayer(ppl);
1808
1809   dx = 50e-4; xin = xout; xout = xin + dx; rho = 1.71; rad_length = 44.77; // Tedlar
1810   ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,rad_length,-1);
1811   InsertLayer(ppl);
1812
1813
1814   // set time bins in CO2
1815
1816   xin = xout; xout = 275.0; 
1817   steps = 50; dx = (xout - xin)/steps;
1818   rho = 1.977e-3;  rad_length = 36.2;
1819   
1820   for(Int_t i=0; i<steps; i++) {
1821     x = xin + i*dx + dx/2;
1822     ppl = new AliTRDpropagationLayer(x,dx,rho,rad_length,-1);
1823     InsertLayer(ppl);
1824   }
1825
1826   // set time bins in the outer containment vessel
1827
1828   dx = 50e-4; xin = xout; xout = xin + dx; rho = 2.7; rad_length = 24.01; // Al
1829   ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,rad_length,-1);
1830   InsertLayer(ppl);
1831
1832   dx = 50e-4; xin = xout; xout = xin + dx; rho = 1.71; rad_length = 44.77; // Tedlar
1833   ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,rad_length,-1);
1834   InsertLayer(ppl);
1835
1836   dx = 0.06; xin = xout; xout = xin + dx; rho = 1.45; rad_length = 44.86; // prepreg
1837   ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,rad_length,-1);
1838   InsertLayer(ppl);
1839
1840   dx = 3.; xin = xout; xout = xin + dx; rho = 1.45*0.02; rad_length = 41.28; // Nomex
1841   steps = 10; dx = (xout - xin)/steps;
1842   for(Int_t i=0; i<steps; i++) {
1843     x = xin + i*dx + dx/2;
1844     ppl = new AliTRDpropagationLayer(x,dx,rho,rad_length,-1);
1845     InsertLayer(ppl);
1846   }
1847
1848   dx = 0.06; xin = xout; xout = xin + dx; rho = 1.45; rad_length = 44.86; // prepreg
1849   ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,rad_length,-1);
1850   InsertLayer(ppl);
1851
1852   dx = 50e-4; xin = xout; xout = xin + dx; rho = 1.71; rad_length = 44.77; // Tedlar
1853   ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,rad_length,-1);
1854   InsertLayer(ppl);
1855   
1856   dx = 50e-4; xin = xout; xout = xin + dx; rho = 2.7; rad_length = 24.01; // Al
1857   ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,rad_length,-1);
1858   InsertLayer(ppl);
1859
1860   Double_t xtrd = (Double_t) fGeom->Rmin();  
1861
1862   // add layers between TPC and TRD (Air temporarily)
1863   xin = xout; xout = xtrd;
1864   steps = 50; dx = (xout - xin)/steps;
1865   rho = 1.2e-3;  rad_length = 36.66;
1866   
1867   for(Int_t i=0; i<steps; i++) {
1868     x = xin + i*dx + dx/2;
1869     ppl = new AliTRDpropagationLayer(x,dx,rho,rad_length,-1);
1870     InsertLayer(ppl);
1871   }
1872
1873
1874   Double_t alpha=AliTRDgeometry::GetAlpha();
1875
1876   // add layers for each of the planes
1877
1878   Double_t dxRo = (Double_t) fGeom->CroHght();    // Rohacell 
1879   Double_t dxSpace = (Double_t) fGeom->Cspace();  // Spacing between planes
1880   Double_t dxAmp = (Double_t) fGeom->CamHght();   // Amplification region
1881   Double_t dxDrift = (Double_t) fGeom->CdrHght(); // Drift region  
1882   Double_t dxRad = (Double_t) fGeom->CraHght();   // Radiator
1883   Double_t dxTEC = dxRad + dxDrift + dxAmp + dxRo; 
1884   Double_t dxPlane = dxTEC + dxSpace; 
1885
1886   Int_t tb, tb_index;
1887   const Int_t  nChambers = AliTRDgeometry::Ncham();
1888   Double_t  Ymax = 0, holeYmax = 0;
1889   Double_t *  Zc  = new Double_t[nChambers];
1890   Double_t * Zmax = new Double_t[nChambers];
1891   Double_t  holeZmax = 1000.;   // the whole sector is missing
1892
1893   for(Int_t plane = 0; plane < AliTRDgeometry::Nplan(); plane++) {
1894
1895     // Radiator 
1896     xin = xtrd + plane * dxPlane; xout = xin + dxRad;
1897     steps = 12; dx = (xout - xin)/steps; rho = 0.074; rad_length = 40.6; 
1898     for(Int_t i=0; i<steps; i++) {
1899       x = xin + i*dx + dx/2;
1900       ppl = new AliTRDpropagationLayer(x,dx,rho,rad_length,-1);
1901       if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
1902         holeYmax = x*TMath::Tan(0.5*alpha);
1903         ppl->SetHole(holeYmax, holeZmax);
1904       }
1905       if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
1906         holeYmax = x*TMath::Tan(0.5*alpha);
1907         ppl->SetHole(holeYmax, holeZmax);
1908       }
1909       InsertLayer(ppl);
1910     }
1911
1912     Ymax = fGeom->GetChamberWidth(plane)/2;
1913     for(Int_t ch = 0; ch < nChambers; ch++) {
1914       Zmax[ch] = fGeom->GetChamberLength(plane,ch)/2;
1915       Float_t pad = fPar->GetRowPadSize(plane,ch,0);
1916       Float_t row0 = fPar->GetRow0(plane,ch,0);
1917       Int_t nPads = fPar->GetRowMax(plane,ch,0);
1918       Zc[ch] = (pad * nPads)/2 + row0 - pad/2;
1919     }
1920
1921     dx = fPar->GetTimeBinSize(); 
1922     rho = 0.00295 * 0.85; rad_length = 11.0;  
1923
1924     Double_t x0 = (Double_t) fPar->GetTime0(plane);
1925     Double_t xbottom = x0 - dxDrift;
1926     Double_t xtop = x0 + dxAmp;
1927
1928     // Amplification region
1929
1930     steps = (Int_t) (dxAmp/dx);
1931
1932     for(tb = 0; tb < steps; tb++) {
1933       x = x0 + tb * dx + dx/2;
1934       tb_index = CookTimeBinIndex(plane, -tb-1);
1935       ppl = new AliTRDpropagationLayer(x,dx,rho,rad_length,tb_index);
1936       ppl->SetYmax(Ymax);
1937       for(Int_t ch = 0; ch < nChambers; ch++) {
1938         ppl->SetZmax(ch, Zc[ch], Zmax[ch]);
1939       }
1940       if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
1941         holeYmax = x*TMath::Tan(0.5*alpha);
1942         ppl->SetHole(holeYmax, holeZmax);
1943       }
1944       if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
1945         holeYmax = x*TMath::Tan(0.5*alpha);
1946         ppl->SetHole(holeYmax, holeZmax);
1947       }
1948       InsertLayer(ppl);
1949     }
1950     tb_index = CookTimeBinIndex(plane, -steps);
1951     x = (x + dx/2 + xtop)/2;
1952     dx = 2*(xtop-x);
1953     ppl = new AliTRDpropagationLayer(x,dx,rho,rad_length,tb_index);
1954     ppl->SetYmax(Ymax);
1955     for(Int_t ch = 0; ch < nChambers; ch++) {
1956       ppl->SetZmax(ch, Zc[ch], Zmax[ch]);
1957     }
1958     if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
1959       holeYmax = x*TMath::Tan(0.5*alpha);
1960       ppl->SetHole(holeYmax, holeZmax);
1961     }
1962     if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
1963       holeYmax = x*TMath::Tan(0.5*alpha);
1964       ppl->SetHole(holeYmax, holeZmax);
1965     }
1966     InsertLayer(ppl);
1967
1968     // Drift region
1969     dx = fPar->GetTimeBinSize();
1970     steps = (Int_t) (dxDrift/dx);
1971
1972     for(tb = 0; tb < steps; tb++) {
1973       x = x0 - tb * dx - dx/2;
1974       tb_index = CookTimeBinIndex(plane, tb);
1975
1976       ppl = new AliTRDpropagationLayer(x,dx,rho,rad_length,tb_index);
1977       ppl->SetYmax(Ymax);
1978       for(Int_t ch = 0; ch < nChambers; ch++) {
1979         ppl->SetZmax(ch, Zc[ch], Zmax[ch]);
1980       }
1981       if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
1982         holeYmax = x*TMath::Tan(0.5*alpha);
1983         ppl->SetHole(holeYmax, holeZmax);
1984       }
1985       if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
1986         holeYmax = x*TMath::Tan(0.5*alpha);
1987         ppl->SetHole(holeYmax, holeZmax);
1988       }
1989       InsertLayer(ppl);
1990     }
1991     tb_index = CookTimeBinIndex(plane, steps);
1992     x = (x - dx/2 + xbottom)/2;
1993     dx = 2*(x-xbottom);
1994     ppl = new AliTRDpropagationLayer(x,dx,rho,rad_length,tb_index);
1995     ppl->SetYmax(Ymax);
1996     for(Int_t ch = 0; ch < nChambers; ch++) {
1997       ppl->SetZmax(ch, Zc[ch], Zmax[ch]);
1998     }
1999     if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
2000       holeYmax = x*TMath::Tan(0.5*alpha);
2001       ppl->SetHole(holeYmax, holeZmax);
2002     }
2003     if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
2004       holeYmax = x*TMath::Tan(0.5*alpha);
2005       ppl->SetHole(holeYmax, holeZmax);
2006     }
2007     InsertLayer(ppl);
2008
2009     // Pad Plane
2010     xin = xtop; dx = 0.025; xout = xin + dx; rho = 1.7; rad_length = 33.0;
2011     ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,rad_length,-1);
2012     if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
2013       holeYmax = (xin+dx/2)*TMath::Tan(0.5*alpha);
2014       ppl->SetHole(holeYmax, holeZmax);
2015     }
2016     if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
2017       holeYmax = (xin+dx/2)*TMath::Tan(0.5*alpha);
2018       ppl->SetHole(holeYmax, holeZmax);
2019     }
2020     InsertLayer(ppl);
2021
2022     // Rohacell
2023     xin = xout; xout = xtrd + (plane + 1) * dxPlane - dxSpace;
2024     steps = 5; dx = (xout - xin)/steps; rho = 0.074; rad_length = 40.6; 
2025     for(Int_t i=0; i<steps; i++) {
2026       x = xin + i*dx + dx/2;
2027       ppl = new AliTRDpropagationLayer(x,dx,rho,rad_length,-1);
2028       if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
2029         holeYmax = x*TMath::Tan(0.5*alpha);
2030         ppl->SetHole(holeYmax, holeZmax);
2031       }
2032       if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
2033         holeYmax = x*TMath::Tan(0.5*alpha);
2034         ppl->SetHole(holeYmax, holeZmax);
2035       }
2036       InsertLayer(ppl);
2037     }
2038
2039     // Space between the chambers, air
2040     xin = xout; xout = xtrd + (plane + 1) * dxPlane;
2041     steps = 5; dx = (xout - xin)/steps; rho = 1.29e-3; rad_length = 36.66; 
2042     for(Int_t i=0; i<steps; i++) {
2043       x = xin + i*dx + dx/2;
2044       ppl = new AliTRDpropagationLayer(x,dx,rho,rad_length,-1);
2045       if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
2046         holeYmax = x*TMath::Tan(0.5*alpha);
2047         ppl->SetHole(holeYmax, holeZmax);
2048       }
2049       if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
2050         holeYmax = x*TMath::Tan(0.5*alpha);
2051         ppl->SetHole(holeYmax, holeZmax);
2052       }
2053       InsertLayer(ppl);
2054     }
2055   }    
2056
2057   // Space between the TRD and RICH
2058   Double_t xRICH = 500.;
2059   xin = xout; xout = xRICH;
2060   steps = 200; dx = (xout - xin)/steps; rho = 1.29e-3; rad_length = 36.66; 
2061   for(Int_t i=0; i<steps; i++) {
2062     x = xin + i*dx + dx/2;
2063     ppl = new AliTRDpropagationLayer(x,dx,rho,rad_length,-1);
2064     InsertLayer(ppl);
2065   }
2066
2067   MapTimeBinLayers();
2068   delete [] Zc;
2069   delete [] Zmax;
2070
2071 }
2072
2073 //______________________________________________________
2074
2075 Int_t  AliTRDtracker::AliTRDtrackingSector::CookTimeBinIndex(Int_t plane, Int_t local_tb) const
2076 {
2077   //
2078   // depending on the digitization parameters calculates "global"
2079   // time bin index for timebin <local_tb> in plane <plane>
2080   //
2081
2082   Double_t dxAmp = (Double_t) fGeom->CamHght();   // Amplification region
2083   Double_t dxDrift = (Double_t) fGeom->CdrHght(); // Drift region  
2084   Double_t dx = (Double_t) fPar->GetTimeBinSize();  
2085
2086   Int_t tbAmp = fPar->GetTimeBefore();
2087   Int_t maxAmp = (Int_t) ((dxAmp+0.000001)/dx);
2088   if(kTRUE) maxAmp = 0;   // intentional until we change parameter class 
2089   Int_t tbDrift = fPar->GetTimeMax();
2090   Int_t maxDrift = (Int_t) ((dxDrift+0.000001)/dx);
2091
2092   Int_t tb_per_plane = TMath::Min(tbAmp,maxAmp) + TMath::Min(tbDrift,maxDrift);
2093
2094   Int_t gtb = (plane+1) * tb_per_plane - local_tb - 1 - TMath::Min(tbAmp,maxAmp);
2095
2096   if((local_tb < 0) && 
2097      (TMath::Abs(local_tb) > TMath::Min(tbAmp,maxAmp))) return -1;
2098   if(local_tb >= TMath::Min(tbDrift,maxDrift)) return -1;
2099
2100   return gtb;
2101
2102
2103 }
2104
2105 //______________________________________________________
2106
2107 void AliTRDtracker::AliTRDtrackingSector::MapTimeBinLayers() 
2108 {
2109   //
2110   // For all sensitive time bins sets corresponding layer index
2111   // in the array fTimeBins 
2112   //
2113
2114   Int_t index;
2115
2116   for(Int_t i = 0; i < fN; i++) {
2117     index = fLayers[i]->GetTimeBinIndex();
2118     
2119     //    printf("gtb %d -> pl %d -> x %f \n", index, i, fLayers[i]->GetX());
2120
2121     if(index < 0) continue;
2122     if(index >= (Int_t) kMAX_TIME_BIN_INDEX) {
2123       printf("*** AliTRDtracker::MapTimeBinLayers: \n");
2124       printf("    index %d exceeds allowed maximum of %d!\n",
2125              index, kMAX_TIME_BIN_INDEX-1);
2126       continue;
2127     }
2128     fTimeBinIndex[index] = i;
2129   }
2130
2131   Double_t x1, dx1, x2, dx2, gap;
2132
2133   for(Int_t i = 0; i < fN-1; i++) {
2134     x1 = fLayers[i]->GetX();
2135     dx1 = fLayers[i]->GetdX();
2136     x2 = fLayers[i+1]->GetX();
2137     dx2 = fLayers[i+1]->GetdX();
2138     gap = (x2 - dx2/2) - (x1 + dx1/2);
2139     if(gap < -0.01) {
2140       printf("*** warning: layers %d and %d are overlayed:\n",i,i+1);
2141       printf("             %f + %f + %f > %f\n", x1, dx1/2, dx2/2, x2);
2142     }
2143     if(gap > 0.01) { 
2144       printf("*** warning: layers %d and %d have a large gap:\n",i,i+1);
2145       printf("             (%f - %f) - (%f + %f) = %f\n", 
2146              x2, dx2/2, x1, dx1, gap);
2147     }
2148   }
2149 }
2150   
2151
2152 //______________________________________________________
2153
2154
2155 Int_t AliTRDtracker::AliTRDtrackingSector::GetLayerNumber(Double_t x) const
2156 {
2157   // 
2158   // Returns the number of time bin which in radial position is closest to <x>
2159   //
2160
2161   if(x >= fLayers[fN-1]->GetX()) return fN-1; 
2162   if(x <= fLayers[0]->GetX()) return 0; 
2163
2164   Int_t b=0, e=fN-1, m=(b+e)/2;
2165   for (; b<e; m=(b+e)/2) {
2166     if (x > fLayers[m]->GetX()) b=m+1;
2167     else e=m;
2168   }
2169   if(TMath::Abs(x - fLayers[m]->GetX()) > 
2170      TMath::Abs(x - fLayers[m+1]->GetX())) return m+1;
2171   else return m;
2172
2173 }
2174
2175 //______________________________________________________
2176
2177 Int_t AliTRDtracker::AliTRDtrackingSector::GetInnerTimeBin() const 
2178 {
2179   // 
2180   // Returns number of the innermost SENSITIVE propagation layer
2181   //
2182
2183   return GetLayerNumber(0);
2184 }
2185
2186 //______________________________________________________
2187
2188 Int_t AliTRDtracker::AliTRDtrackingSector::GetOuterTimeBin() const 
2189 {
2190   // 
2191   // Returns number of the outermost SENSITIVE time bin
2192   //
2193
2194   return GetLayerNumber(GetNumberOfTimeBins() - 1);
2195 }
2196
2197 //______________________________________________________
2198
2199 Int_t AliTRDtracker::AliTRDtrackingSector::GetNumberOfTimeBins() const 
2200 {
2201   // 
2202   // Returns number of SENSITIVE time bins
2203   //
2204
2205   Int_t tb, layer;
2206   for(tb = kMAX_TIME_BIN_INDEX-1; tb >=0; tb--) {
2207     layer = GetLayerNumber(tb);
2208     if(layer>=0) break;
2209   }
2210   return tb+1;
2211 }
2212
2213 //______________________________________________________
2214
2215 void AliTRDtracker::AliTRDtrackingSector::InsertLayer(AliTRDpropagationLayer* pl)
2216
2217   //
2218   // Insert layer <pl> in fLayers array.
2219   // Layers are sorted according to X coordinate.
2220
2221   if ( fN == ((Int_t) kMAX_LAYERS_PER_SECTOR)) {
2222     printf("AliTRDtrackingSector::InsertLayer(): Too many layers !\n");
2223     return;
2224   }
2225   if (fN==0) {fLayers[fN++] = pl; return;}
2226   Int_t i=Find(pl->GetX());
2227
2228   memmove(fLayers+i+1 ,fLayers+i,(fN-i)*sizeof(AliTRDpropagationLayer*));
2229   fLayers[i]=pl; fN++;
2230
2231 }              
2232
2233 //______________________________________________________
2234
2235 Int_t AliTRDtracker::AliTRDtrackingSector::Find(Double_t x) const 
2236 {
2237   //
2238   // Returns index of the propagation layer nearest to X 
2239   //
2240
2241   if (x <= fLayers[0]->GetX()) return 0;
2242   if (x > fLayers[fN-1]->GetX()) return fN;
2243   Int_t b=0, e=fN-1, m=(b+e)/2;
2244   for (; b<e; m=(b+e)/2) {
2245     if (x > fLayers[m]->GetX()) b=m+1;
2246     else e=m;
2247   }
2248   return m;
2249 }             
2250
2251 //______________________________________________________
2252
2253 void AliTRDtracker::AliTRDpropagationLayer::GetPropagationParameters(
2254         Double_t y, Double_t z, Double_t &dx, Double_t &rho, Double_t &rad_length, 
2255         Bool_t &lookForCluster) const
2256 {
2257   //
2258   // Returns radial step <dx>, density <rho>, rad. length <rad_length>,
2259   // and sensitivity <lookForCluster> in point <y,z>  
2260   //
2261
2262   dx  = fdX;
2263   rho = fRho;
2264   rad_length  = fX0;
2265   lookForCluster = kFALSE;
2266
2267   // check dead regions
2268   if(fTimeBinIndex >= 0) {
2269     for(Int_t ch = 0; ch < (Int_t) kZONES; ch++) {
2270       if(TMath::Abs(z - fZc[ch]) < fZmax[ch]) 
2271         lookForCluster = kTRUE;
2272       //  else { rho = 1.7; rad_length = 33.0; } // G10 
2273     }
2274     if(TMath::Abs(y) > fYmax) lookForCluster = kFALSE;
2275     if(!lookForCluster) { 
2276       //      rho = 1.7; rad_length = 33.0; // G10 
2277     }
2278   }
2279
2280   // check hole
2281   if(fHole && (TMath::Abs(y - fHoleYc) < fHoleYmax) && 
2282               (TMath::Abs(z - fHoleZc) < fHoleZmax)) {
2283     lookForCluster = kFALSE;
2284     rho = fHoleRho;
2285     rad_length  = fHoleX0;
2286   }         
2287
2288   return;
2289 }
2290
2291 //______________________________________________________
2292
2293 void AliTRDtracker::AliTRDpropagationLayer::InsertCluster(AliTRDcluster* c, 
2294                                                           UInt_t index) {
2295
2296 // Insert cluster in cluster array.
2297 // Clusters are sorted according to Y coordinate.  
2298
2299   if(fTimeBinIndex < 0) { 
2300     printf("*** attempt to insert cluster into non-sensitive time bin!\n");
2301     return;
2302   }
2303
2304   if (fN== (Int_t) kMAX_CLUSTER_PER_TIME_BIN) {
2305     printf("AliTRDpropagationLayer::InsertCluster(): Too many clusters !\n"); 
2306     return;
2307   }
2308   if (fN==0) {fIndex[0]=index; fClusters[fN++]=c; return;}
2309   Int_t i=Find(c->GetY());
2310   memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTRDcluster*));
2311   memmove(fIndex   +i+1 ,fIndex   +i,(fN-i)*sizeof(UInt_t)); 
2312   fIndex[i]=index; fClusters[i]=c; fN++;
2313 }  
2314
2315 //______________________________________________________
2316
2317 Int_t AliTRDtracker::AliTRDpropagationLayer::Find(Double_t y) const {
2318
2319 // Returns index of the cluster nearest in Y    
2320
2321   if (y <= fClusters[0]->GetY()) return 0;
2322   if (y > fClusters[fN-1]->GetY()) return fN;
2323   Int_t b=0, e=fN-1, m=(b+e)/2;
2324   for (; b<e; m=(b+e)/2) {
2325     if (y > fClusters[m]->GetY()) b=m+1;
2326     else e=m;
2327   }
2328   return m;
2329 }    
2330
2331 //---------------------------------------------------------
2332
2333 Double_t AliTRDtracker::GetTiltFactor(const AliTRDcluster* c) {
2334 //
2335 //  Returns correction factor for tilted pads geometry 
2336 //
2337
2338   Double_t h01 = sin(TMath::Pi() / 180.0 * fPar->GetTiltingAngle());
2339   Int_t det = c->GetDetector();    
2340   Int_t plane = fGeom->GetPlane(det);
2341
2342   if((plane == 1) || (plane == 3) || (plane == 5)) h01=-h01;
2343
2344   if(fNoTilt) h01 = 0;
2345   
2346   return h01;
2347 }
2348
2349
2350
2351
2352
2353