]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCtrackerSector.cxx
better just warning than error in case of mirrors requesting when putting to local...
[u/mrichter/AliRoot.git] / TPC / AliTPCtrackerSector.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 //-------------------------------------------------------
18 //          Implementation of the TPC tracker helper clasess
19 //  AliTPCtrackerRow
20 //  AliTPCtrackerSector
21 //
22 //   Origin: Marian Ivanov   Marian.Ivanov@cern.ch
23 // 
24 //  AliTPCtrakerMI -  parallel tracker helper clases
25 //
26
27 /* $Id: AliTPCtrackerSector.cxx 25837 2008-05-16 16:39:00Z marian $ */
28
29 #include "Riostream.h"
30 #include <TClonesArray.h>
31 #include "AliLog.h"
32 #include "AliComplexCluster.h"
33 #include "AliTPCcluster.h"
34 #include "AliTPCclusterMI.h"
35 #include "AliTPCClustersRow.h"
36 #include "AliTPCParam.h"
37 #include "AliTPCReconstructor.h"
38 #include "AliTPCreco.h"
39 //
40 #include "AliTPCtrackerSector.h"
41 #include "TStopwatch.h"
42 #include "TTreeStream.h"
43
44 //
45
46 ClassImp(AliTPCtrackerRow)
47 ClassImp(AliTPCtrackerSector)
48
49
50
51 AliTPCtrackerRow::AliTPCtrackerRow():
52   fDeadZone(0.),
53   fClusters1(0),
54   fN1(0),
55   fClusters2(0),
56   fN2(0),
57   fFastCluster(),
58   fN(0),
59   fClusters(),
60   fIndex(),
61   fX(0.)  
62 {
63   //
64   // default constructor
65   //
66 }
67
68 AliTPCtrackerRow::~AliTPCtrackerRow(){
69   //
70   delete fClusters1;
71   delete fClusters2;
72 }
73
74
75
76 //_________________________________________________________________________
77 void 
78 AliTPCtrackerRow::InsertCluster(const AliTPCclusterMI* c, UInt_t index) {
79   //-----------------------------------------------------------------------
80   // Insert a cluster into this pad row in accordence with its y-coordinate
81   //-----------------------------------------------------------------------
82   if (!c) {
83     AliError("Inserting Zerro cluster pointer");
84     return;
85   }
86   if (fN==kMaxClusterPerRow) {
87     //AliInfo("AliTPCtrackerRow::InsertCluster(): Too many clusters"); 
88     return;
89   }
90   if (fN>=fN1+fN2) {
91     //AliInfo("AliTPCtrackerRow::InsertCluster(): Too many clusters !");
92   }
93
94   if (fN==0) {fIndex[0]=index; fClusters[fN++]=c; return;}
95   Int_t i=Find(c->GetZ());
96   if (i>=0 && i<=kMaxClusterPerRow-2) {
97     memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTPCclusterMI*));
98     memmove(fIndex   +i+1 ,fIndex   +i,(fN-i)*sizeof(UInt_t));
99   }
100   fIndex[i]=index; fClusters[i]=c; fN++;
101 }
102
103 void AliTPCtrackerRow::ResetClusters() {
104    //
105    // reset clusters
106    // MvL: Need to call destructors for AliTPCclusterMI, to delete fInfo
107   if (fClusters1) fClusters1->Clear("C");
108   if (fClusters2) fClusters2->Clear("C");
109
110    fN  = 0; 
111    fN1 = 0;
112    fN2 = 0;
113    //delete[] fClusterArray; 
114
115    //fClusterArray=0;
116 }
117
118
119 //___________________________________________________________________
120 Int_t AliTPCtrackerRow::Find(Double_t z) const {
121   //-----------------------------------------------------------------------
122   // Return the index of the nearest cluster 
123   //-----------------------------------------------------------------------
124   if (fN==0) return 0;
125   if (z <= fClusters[0]->GetZ()) return 0;
126   if (z > fClusters[fN-1]->GetZ()) return fN;
127   Int_t b=0, e=fN-1, m=(b+e)/2;
128   for (; b<e; m=(b+e)/2) {
129     if (z > fClusters[m]->GetZ()) b=m+1;
130     else e=m; 
131   }
132   return m;
133 }
134
135
136
137 //___________________________________________________________________
138 AliTPCclusterMI * AliTPCtrackerRow::FindNearest(Double_t y, Double_t z, Double_t roady, Double_t roadz) const {
139   //-----------------------------------------------------------------------
140   // Return the index of the nearest cluster in z y 
141   //-----------------------------------------------------------------------
142   Float_t maxdistance = roady*roady + roadz*roadz;
143
144   AliTPCclusterMI *cl =0;
145   for (Int_t i=Find(z-roadz); i<fN; i++) {
146       AliTPCclusterMI *c=(AliTPCclusterMI*)(fClusters[i]);
147       if (c->GetZ() > z+roadz) break;
148       if ( (c->GetY()-y) >  roady ) continue;
149       Float_t distance = (c->GetZ()-z)*(c->GetZ()-z)+(c->GetY()-y)*(c->GetY()-y);
150       if (maxdistance>distance) {
151         maxdistance = distance;
152         cl=c;       
153       }
154   }
155   return cl;      
156 }
157
158 AliTPCclusterMI * AliTPCtrackerRow::FindNearest2(Double_t y, Double_t z, Double_t roady, Double_t roadz,UInt_t & index) const 
159 {
160   //-----------------------------------------------------------------------
161   // Return the index of the nearest cluster in z y 
162   //-----------------------------------------------------------------------
163   Float_t maxdistance = roady*roady + roadz*roadz;
164   AliTPCclusterMI *cl =0;
165
166   //PH Check boundaries. 510 is the size of fFastCluster
167   Int_t iz1 = Int_t(z-roadz+254.5);
168   if (iz1<0 || iz1>=510) return cl;
169   iz1 = TMath::Max(GetFastCluster(iz1)-1,0);
170   Int_t iz2 = Int_t(z+roadz+255.5);
171   if (iz2<0 || iz2>=510) return cl;
172   iz2 = TMath::Min(GetFastCluster(iz2)+1,fN);
173   Bool_t skipUsed = !(AliTPCReconstructor::GetRecoParam()->GetClusterSharing());
174   //FindNearest3(y,z,roady,roadz,index);
175   //  for (Int_t i=Find(z-roadz); i<fN; i++) {
176   for (Int_t i=iz1; i<iz2; i++) {
177       AliTPCclusterMI *c=(AliTPCclusterMI*)(fClusters[i]);
178       if (c->GetZ() > z+roadz) break;
179       if ( c->GetY()-y >  roady ) continue;
180       if ( y-c->GetY() >  roady ) continue;
181       if (skipUsed && c->IsUsed(11)) continue;
182       Float_t distance = (c->GetZ()-z)*(c->GetZ()-z)+(c->GetY()-y)*(c->GetY()-y);
183       if (maxdistance>distance) {
184         maxdistance = distance;
185         cl=c;       
186         index =i;
187         //roady = TMath::Sqrt(maxdistance);
188       }
189   }
190   return cl;      
191 }
192
193
194 void AliTPCtrackerRow::SetFastCluster(Int_t i, Short_t cl){
195   //
196   // Set cluster info for fast navigation
197   //
198   if (i>=510|| i<0){
199   }else{
200     fFastCluster[i]=cl;
201   }
202 }
203
204
205 Int_t  AliTPCtrackerSector::GetRowNumber(Double_t x) const 
206 {
207   //return pad row number for this x
208   Double_t r;
209   if (fN < 64){
210     r=fRow[fN-1].GetX();
211     if (x > r) return fN;
212     r=fRow[0].GetX();
213     if (x < r) return -1;
214     return Int_t((x-r)/fPadPitchLength + 0.5);}
215   else{    
216     r=fRow[fN-1].GetX();
217     if (x > r) return fN;
218     r=fRow[0].GetX();
219     if (x < r) return -1;
220     Double_t r1=fRow[64].GetX();
221     if(x<r1){       
222       return Int_t((x-r)/f1PadPitchLength + 0.5);}
223     else{
224       return (Int_t((x-r1)/f2PadPitchLength + 0.5)+64);} 
225   }
226 }
227
228
229 void AliTPCtrackerRow::SetCluster1(Int_t i, const AliTPCclusterMI &cl)
230 {
231   // attach cluster
232   if (!fClusters1) fClusters1 = new TClonesArray("AliTPCclusterMI",1000);
233   if (i<=fClusters1->GetLast() && fClusters1->UncheckedAt(i)) fClusters1->RemoveAt(i);
234   new( (*fClusters1)[fClusters1->GetEntriesFast()] ) AliTPCclusterMI(cl);
235   //
236 }
237
238 void AliTPCtrackerRow::SetCluster2(Int_t i, const AliTPCclusterMI &cl)
239 {
240   // attach cluster
241   if (!fClusters2) fClusters2 = new TClonesArray("AliTPCclusterMI",1000);
242   if (i<=fClusters2->GetLast() && fClusters2->UncheckedAt(i)) fClusters2->RemoveAt(i);
243   new( (*fClusters2)[fClusters2->GetEntriesFast()] ) AliTPCclusterMI(cl);
244   //
245 }
246
247
248 //_________________________________________________________________________
249 void AliTPCtrackerSector::Setup(const AliTPCParam *par, Int_t f) {
250   //-----------------------------------------------------------------------
251   // Setup inner sector
252   //-----------------------------------------------------------------------
253   if (f==0) {
254      fAlpha=par->GetInnerAngle();
255      fAlphaShift=par->GetInnerAngleShift();
256      fPadPitchWidth=par->GetInnerPadPitchWidth();
257      fPadPitchLength=par->GetInnerPadPitchLength();
258      fN=par->GetNRowLow();
259      if(fRow)delete [] fRow;fRow = 0;
260      fRow=new AliTPCtrackerRow[fN];
261      for (Int_t i=0; i<fN; i++) {
262        fRow[i].SetX(par->GetPadRowRadiiLow(i));
263        fRow[i].SetDeadZone(1.5);  //1.5 cm of dead zone
264      }
265   } else {
266      fAlpha=par->GetOuterAngle();
267      fAlphaShift=par->GetOuterAngleShift();
268      fPadPitchWidth  = par->GetOuterPadPitchWidth();
269      fPadPitchLength = par->GetOuter1PadPitchLength();
270      f1PadPitchLength = par->GetOuter1PadPitchLength();
271      f2PadPitchLength = par->GetOuter2PadPitchLength();
272      fN=par->GetNRowUp();
273      if(fRow)delete [] fRow;fRow = 0;
274      fRow=new AliTPCtrackerRow[fN];
275      for (Int_t i=0; i<fN; i++) {
276        fRow[i].SetX(par->GetPadRowRadiiUp(i)); 
277        fRow[i].SetDeadZone(1.5);  // 1.5 cm of dead zone
278      }
279   } 
280 }
281
282 //_________________________________________________________________________
283 void AliTPCtrackerSector::InsertCluster(AliTPCclusterMI *cl, Int_t size, const AliTPCParam *par) {
284   //-----------------------------------------------------------------------
285   // Insert cluster to the sector
286   //-----------------------------------------------------------------------
287
288   if(!cl) return; 
289
290   const Int_t fkNIS = par->GetNInnerSector()/2;
291   const Int_t fkNOS = par->GetNOuterSector()/2;
292   Int_t row = cl->GetRow();
293   Int_t sec = cl->GetDetector();
294
295   // add cluster to the corresponding pad row
296   AliTPCtrackerRow *tpcrow = 0x0;
297
298   Int_t left=0;
299   if (sec<fkNIS*2){
300     left = sec/fkNIS;
301   }
302   else{
303     left = (sec-fkNIS*2)/fkNOS;
304   }
305   //
306   if (left ==0){
307     tpcrow = fRow+row;
308     if(!tpcrow->GetClusters1()) {
309        tpcrow->SetN1(0);
310     }
311     if(size < kMaxClusterPerRow) {
312       tpcrow->SetCluster1(tpcrow->GetN1(), *cl);
313       //printf("inner: size %d, tpcrow->GetN1() %d  sec %d row %d tpcrow %p cl %p\n", size, tpcrow->GetN1(), sec, row, tpcrow, cl);
314
315       tpcrow->IncrementN1();
316     }
317   }
318   if (left ==1){
319     tpcrow = fRow+row;
320     if(!tpcrow->GetClusters2()) { 
321       tpcrow->SetN2(0);
322     }
323     if(size < kMaxClusterPerRow)  { 
324       tpcrow->SetCluster2(tpcrow->GetN2(), *cl);
325       //printf("outer: size %d, tpcrow->GetN2() %d  sec %d row %d tpcrow %p cl %p\n", size, tpcrow->GetN2(), sec, row, tpcrow, cl);
326
327       tpcrow->IncrementN2();
328     }
329   }
330 }
331