Some of the coding violations corrected
[u/mrichter/AliRoot.git] / TPC / AliTPCtrackerSector.cxx
CommitLineData
9350f379 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
46ClassImp(AliTPCtrackerRow)
47ClassImp(AliTPCtrackerSector)
48
49
50
51AliTPCtrackerRow::AliTPCtrackerRow():
52 fDeadZone(0.),
53 fClusters1(0),
54 fN1(0),
55 fClusters2(0),
56 fN2(0),
9f98a33d 57 fFastCluster(),
9350f379 58 fN(0),
472f0066 59 fClusters(),
60 fIndex(),
61 fX(0.)
9350f379 62{
63 //
64 // default constructor
65 //
66}
67
68AliTPCtrackerRow::~AliTPCtrackerRow(){
69 //
70 for (Int_t i = 0; i < fN1; i++)
71 fClusters1[i].~AliTPCclusterMI();
72 delete [] fClusters1;
73 for (Int_t i = 0; i < fN2; i++)
74 fClusters2[i].~AliTPCclusterMI();
75 delete [] fClusters2;
76}
77
78
79
80//_________________________________________________________________________
81void
82AliTPCtrackerRow::InsertCluster(const AliTPCclusterMI* c, UInt_t index) {
83 //-----------------------------------------------------------------------
84 // Insert a cluster into this pad row in accordence with its y-coordinate
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 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTPCclusterMI*));
97 memmove(fIndex +i+1 ,fIndex +i,(fN-i)*sizeof(UInt_t));
98 fIndex[i]=index; fClusters[i]=c; fN++;
99}
100
101void AliTPCtrackerRow::ResetClusters() {
102 //
103 // reset clusters
104 // MvL: Need to call destructors for AliTPCclusterMI, to delete fInfo
105 for (Int_t i = 0; i < fN1; i++)
106 fClusters1[i].~AliTPCclusterMI();
107 delete [] fClusters1; fClusters1=0;
108 for (Int_t i = 0; i < fN2; i++)
109 fClusters2[i].~AliTPCclusterMI();
110 delete [] fClusters2; fClusters2=0;
111
112 fN = 0;
113 fN1 = 0;
114 fN2 = 0;
115 //delete[] fClusterArray;
116
117 //fClusterArray=0;
118}
119
120
121//___________________________________________________________________
122Int_t AliTPCtrackerRow::Find(Double_t z) const {
123 //-----------------------------------------------------------------------
124 // Return the index of the nearest cluster
125 //-----------------------------------------------------------------------
126 if (fN==0) return 0;
127 if (z <= fClusters[0]->GetZ()) return 0;
128 if (z > fClusters[fN-1]->GetZ()) return fN;
129 Int_t b=0, e=fN-1, m=(b+e)/2;
130 for (; b<e; m=(b+e)/2) {
131 if (z > fClusters[m]->GetZ()) b=m+1;
132 else e=m;
133 }
134 return m;
135}
136
137
138
139//___________________________________________________________________
140AliTPCclusterMI * AliTPCtrackerRow::FindNearest(Double_t y, Double_t z, Double_t roady, Double_t roadz) const {
141 //-----------------------------------------------------------------------
142 // Return the index of the nearest cluster in z y
143 //-----------------------------------------------------------------------
144 Float_t maxdistance = roady*roady + roadz*roadz;
145
146 AliTPCclusterMI *cl =0;
147 for (Int_t i=Find(z-roadz); i<fN; i++) {
148 AliTPCclusterMI *c=(AliTPCclusterMI*)(fClusters[i]);
149 if (c->GetZ() > z+roadz) break;
150 if ( (c->GetY()-y) > roady ) continue;
151 Float_t distance = (c->GetZ()-z)*(c->GetZ()-z)+(c->GetY()-y)*(c->GetY()-y);
152 if (maxdistance>distance) {
153 maxdistance = distance;
154 cl=c;
155 }
156 }
157 return cl;
158}
159
160AliTPCclusterMI * AliTPCtrackerRow::FindNearest2(Double_t y, Double_t z, Double_t roady, Double_t roadz,UInt_t & index) const
161{
162 //-----------------------------------------------------------------------
163 // Return the index of the nearest cluster in z y
164 //-----------------------------------------------------------------------
165 Float_t maxdistance = roady*roady + roadz*roadz;
166 AliTPCclusterMI *cl =0;
167
168 //PH Check boundaries. 510 is the size of fFastCluster
169 Int_t iz1 = Int_t(z-roadz+254.5);
170 if (iz1<0 || iz1>=510) return cl;
171 iz1 = TMath::Max(GetFastCluster(iz1)-1,0);
172 Int_t iz2 = Int_t(z+roadz+255.5);
173 if (iz2<0 || iz2>=510) return cl;
174 iz2 = TMath::Min(GetFastCluster(iz2)+1,fN);
175 Bool_t skipUsed = !(AliTPCReconstructor::GetRecoParam()->GetClusterSharing());
176 //FindNearest3(y,z,roady,roadz,index);
177 // for (Int_t i=Find(z-roadz); i<fN; i++) {
178 for (Int_t i=iz1; i<iz2; i++) {
179 AliTPCclusterMI *c=(AliTPCclusterMI*)(fClusters[i]);
180 if (c->GetZ() > z+roadz) break;
181 if ( c->GetY()-y > roady ) continue;
182 if ( y-c->GetY() > roady ) continue;
183 if (skipUsed && c->IsUsed(11)) continue;
184 Float_t distance = (c->GetZ()-z)*(c->GetZ()-z)+(c->GetY()-y)*(c->GetY()-y);
185 if (maxdistance>distance) {
186 maxdistance = distance;
187 cl=c;
188 index =i;
189 //roady = TMath::Sqrt(maxdistance);
190 }
191 }
192 return cl;
193}
194
195
196void AliTPCtrackerRow::SetFastCluster(Int_t i, Short_t cl){
197 //
198 // Set cluster info for fast navigation
199 //
472f0066 200 if (i>=510|| i<0){
9350f379 201 }else{
202 fFastCluster[i]=cl;
203 }
204}
205
206
207Int_t AliTPCtrackerSector::GetRowNumber(Double_t x) const
208{
209 //return pad row number for this x
210 Double_t r;
211 if (fN < 64){
212 r=fRow[fN-1].GetX();
213 if (x > r) return fN;
214 r=fRow[0].GetX();
215 if (x < r) return -1;
216 return Int_t((x-r)/fPadPitchLength + 0.5);}
217 else{
218 r=fRow[fN-1].GetX();
219 if (x > r) return fN;
220 r=fRow[0].GetX();
221 if (x < r) return -1;
222 Double_t r1=fRow[64].GetX();
223 if(x<r1){
224 return Int_t((x-r)/f1PadPitchLength + 0.5);}
225 else{
226 return (Int_t((x-r1)/f2PadPitchLength + 0.5)+64);}
227 }
228}
229
230//_________________________________________________________________________
231void AliTPCtrackerSector::Setup(const AliTPCParam *par, Int_t f) {
232 //-----------------------------------------------------------------------
233 // Setup inner sector
234 //-----------------------------------------------------------------------
235 if (f==0) {
236 fAlpha=par->GetInnerAngle();
237 fAlphaShift=par->GetInnerAngleShift();
238 fPadPitchWidth=par->GetInnerPadPitchWidth();
239 fPadPitchLength=par->GetInnerPadPitchLength();
240 fN=par->GetNRowLow();
241 if(fRow)delete [] fRow;fRow = 0;
242 fRow=new AliTPCtrackerRow[fN];
243 for (Int_t i=0; i<fN; i++) {
244 fRow[i].SetX(par->GetPadRowRadiiLow(i));
245 fRow[i].SetDeadZone(1.5); //1.5 cm of dead zone
246 }
247 } else {
248 fAlpha=par->GetOuterAngle();
249 fAlphaShift=par->GetOuterAngleShift();
250 fPadPitchWidth = par->GetOuterPadPitchWidth();
251 fPadPitchLength = par->GetOuter1PadPitchLength();
252 f1PadPitchLength = par->GetOuter1PadPitchLength();
253 f2PadPitchLength = par->GetOuter2PadPitchLength();
254 fN=par->GetNRowUp();
255 if(fRow)delete [] fRow;fRow = 0;
256 fRow=new AliTPCtrackerRow[fN];
257 for (Int_t i=0; i<fN; i++) {
258 fRow[i].SetX(par->GetPadRowRadiiUp(i));
259 fRow[i].SetDeadZone(1.5); // 1.5 cm of dead zone
260 }
261 }
262}
263
aa7f1a5a 264//_________________________________________________________________________
265void AliTPCtrackerSector::InsertCluster(AliTPCclusterMI *cl, Int_t size, const AliTPCParam *par) {
266 //-----------------------------------------------------------------------
267 // Insert cluster to the sector
268 //-----------------------------------------------------------------------
9350f379 269
aa7f1a5a 270 if(!cl) return;
9350f379 271
aa7f1a5a 272 const Int_t fkNIS = par->GetNInnerSector()/2;
273 const Int_t fkNOS = par->GetNOuterSector()/2;
274 Int_t row = cl->GetRow();
275 Int_t sec = cl->GetDetector();
276
277 // add cluster to the corresponding pad row
278 AliTPCtrackerRow *tpcrow = 0x0;
279
280 Int_t left=0;
281 if (sec<fkNIS*2){
282 left = sec/fkNIS;
283 }
284 else{
285 left = (sec-fkNIS*2)/fkNOS;
286 }
287 //
288 if (left ==0){
289 tpcrow = fRow+row;
98ee6d31 290 if(!tpcrow->GetClusters1()) {
291 tpcrow->SetClusters1(new AliTPCclusterMI[size]);
292 tpcrow->SetN1(0);
293 }
aa7f1a5a 294 if(size < kMaxClusterPerRow) {
295 tpcrow->SetCluster1(tpcrow->GetN1(), *cl);
98ee6d31 296 //printf("inner: size %d, tpcrow->GetN1() %d sec %d row %d tpcrow %p cl %p\n", size, tpcrow->GetN1(), sec, row, tpcrow, cl);
aa7f1a5a 297
298 tpcrow->IncrementN1();
299 }
300 }
301 if (left ==1){
302 tpcrow = fRow+row;
98ee6d31 303 if(!tpcrow->GetClusters2()) {
304 tpcrow->SetClusters2(new AliTPCclusterMI[size]);
305 tpcrow->SetN2(0);
306 }
aa7f1a5a 307 if(size < kMaxClusterPerRow) {
308 tpcrow->SetCluster2(tpcrow->GetN2(), *cl);
98ee6d31 309 //printf("outer: size %d, tpcrow->GetN2() %d sec %d row %d tpcrow %p cl %p\n", size, tpcrow->GetN2(), sec, row, tpcrow, cl);
aa7f1a5a 310
311 tpcrow->IncrementN2();
312 }
313 }
314}
9350f379 315
316
317