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