fix coverity
[u/mrichter/AliRoot.git] / TRD / AliTRDpropagationLayer.cxx
CommitLineData
e4f2f73d 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/* $Id$ */
17
18////////////////////////////////////////////////////////////////////////////
19// //
20// The TRD propagation layer //
21// //
22// Authors: //
23// Marian Ivanov <M.Ivanov@gsi.de> //
24// Alex Bercuci <A.Bercuci@gsi.de> //
25// Markus Fasel <M.Fasel@gsi.de> //
26// //
27////////////////////////////////////////////////////////////////////////////
28
29#include "string.h"
30
31#include "TMath.h"
32
33#include "AliTRDpropagationLayer.h"
34//#include "AliTRDtracker.h"
35#include "AliTRDcluster.h"
36#include "AliTRDgeometry.h"
37
38//_____________________________________________________________________________
39AliTRDpropagationLayer::AliTRDpropagationLayer()
40 :TObject()
41 ,fN(0)
42 ,fSec(0)
43 ,fClusters(NULL)
44 ,fIndex(NULL)
45 ,fX(0.)
46 ,fdX(0.)
47 ,fRho(0.)
48 ,fX0(0.)
49 ,fTimeBinIndex(0)
50 ,fPlane(0)
51 ,fYmax(0)
52 ,fYmaxSensitive(0)
53 ,fHole(kFALSE)
54 ,fHoleZc(0)
55 ,fHoleZmax(0)
56 ,fHoleYc(0)
57 ,fHoleYmax(0)
58 ,fHoleRho(0)
59 ,fHoleX0(0)
60{
61 //
62 // Default constructor
63 //
64
2f9bdd85 65 for (Int_t iZones = 0; iZones < (Int_t)kZones; iZones++) {
66 fZc[iZones] = 0.0;
67 fZmax[iZones] = 0.0;
68 fZmaxSensitive[iZones] = 0.0;
69 fIsHole[iZones] = kFALSE;
70 }
41f024fb 71 memset(fZmaxSensitive, 0, kZones*sizeof(Double_t));
e4f2f73d 72}
73
74//_____________________________________________________________________________
75AliTRDpropagationLayer::AliTRDpropagationLayer(Double_t x, Double_t dx, Double_t rho
76 , Double_t radLength, Int_t tbIndex, Int_t plane)
77 :TObject()
78 ,fN(0)
79 ,fSec(0)
80 ,fClusters(NULL)
81 ,fIndex(NULL)
82 ,fX(x)
83 ,fdX(dx)
84 ,fRho(rho)
85 ,fX0(radLength)
86 ,fTimeBinIndex(tbIndex)
87 ,fPlane(plane)
88 ,fYmax(0)
89 ,fYmaxSensitive(0)
90 ,fHole(kFALSE)
91 ,fHoleZc(0)
92 ,fHoleZmax(0)
93 ,fHoleYc(0)
94 ,fHoleYmax(0)
95 ,fHoleRho(0)
96 ,fHoleX0(0)
97{
98 //
99 // AliTRDpropagationLayer constructor
100 //
101
102 for (Int_t i = 0; i < (Int_t)kZones; i++) {
103 fZc[i] = 0;
104 fZmax[i] = 0;
105 }
106
107 if (fTimeBinIndex >= 0) {
108 fClusters = new AliTRDcluster*[kMaxClusterPerTimeBin];
109 fIndex = new UInt_t[kMaxClusterPerTimeBin];
110 }
111
112 for (Int_t i = 0; i < 5; i++) {
113 fIsHole[i] = kFALSE;
114 }
41f024fb 115 memset(fZmaxSensitive, 0, kZones*sizeof(Double_t));
e4f2f73d 116}
117
118//_____________________________________________________________________________
119AliTRDpropagationLayer::AliTRDpropagationLayer(const AliTRDpropagationLayer &p)
120 :TObject((TObject&)p)
121 ,fN(p.fN)
122 ,fSec(p.fSec)
4d6aee34 123 ,fClusters(NULL)
124 ,fIndex(NULL)
e4f2f73d 125 ,fX(p.fX)
126 ,fdX(p.fdX)
127 ,fRho(p.fRho)
128 ,fX0(p.fX0)
129 ,fTimeBinIndex(p.fTimeBinIndex)
130 ,fPlane(p.fPlane)
131 ,fYmax(p.fYmax)
132 ,fYmaxSensitive(p.fYmaxSensitive)
133 ,fHole(p.fHole)
134 ,fHoleZc(p.fHoleZc)
135 ,fHoleZmax(p.fHoleZmax)
136 ,fHoleYc(p.fHoleYc)
137 ,fHoleYmax(p.fHoleYmax)
138 ,fHoleRho(p.fHoleRho)
139 ,fHoleX0(p.fHoleX0)
140{
141 //
142 // AliTRDpropagationLayer copy constructor
143 //
144
145 for (Int_t i = 0; i < (Int_t)kZones; i++) {
146 fZc[i] = p.fZc[i];
147 fZmax[i] = p.fZmax[i];
148 fIsHole[i] = p.fIsHole[i];
149 fZmaxSensitive[i] = p.fZmaxSensitive[i];
150 }
151
152 // Make a deep copy of the Clusters array and the Index array unless they are needed in class AliTRDstackLayer
153 Int_t arrsize = (Int_t)kMaxClusterPerTimeBin;
41f024fb 154 if (fTimeBinIndex >= 0) {
e4f2f73d 155 fClusters = new AliTRDcluster*[arrsize];
156 fIndex = new UInt_t[arrsize];
41f024fb 157 memset(fIndex, 0, sizeof(UInt_t)*arrsize);
158 memset(fClusters, 0, sizeof(AliTRDcluster *)*arrsize);
159 for(Int_t i = 0; i < arrsize; i++){
160 fClusters[i] = p.fClusters[i];
161 fIndex[i] = p.fIndex[i];
162 }
e4f2f73d 163 }
e4f2f73d 164}
165
166//_____________________________________________________________________________
167AliTRDpropagationLayer::~AliTRDpropagationLayer()
168{
169 //
170 // Destructor
171 //
172
173 if (fTimeBinIndex >= 0) {
174 delete[] fClusters;
175 delete[] fIndex;
176 }
177
178}
179
180//_____________________________________________________________________________
181void AliTRDpropagationLayer::Copy(TObject &o) const
182{
183 //
184 // Copy function
185 //
186
187 AliTRDpropagationLayer &p = (AliTRDpropagationLayer &)o;
188 p.fN = fN;
189 p.fSec = fSec;
190 p.fX = fX;
191 p.fdX = fdX;
192 p.fRho = fRho;
193 p.fX0 = fX0;
194 p.fTimeBinIndex = fTimeBinIndex;
195 p.fPlane = fPlane;
196 p.fYmax = fYmax;
197 p.fYmaxSensitive = fYmaxSensitive;
198 p.fHole = fHole;
199 p.fHoleZc = fHoleZc;
200 p.fHoleZmax = fHoleZmax;
201 p.fHoleYc = fHoleYc;
202 p.fHoleYmax = fHoleYmax;
203 p.fHoleRho = fHoleRho;
204 p.fHoleX0 = fHoleX0;
205
206 for (Int_t i = 0; i < (Int_t)kZones; i++) {
207 p.fZc[i] = fZc[i];
208 p.fZmax[i] = fZmax[i];
209 p.fIsHole[i] = fIsHole[i];
210 p.fZmaxSensitive[i] = fZmaxSensitive[i];
211 }
212
213 // Make a deep copy of the Clusters array and the Index array
214 // unless they are needed in class AliTRDstackLayer
215 if (fTimeBinIndex >= 0) {
216 if (!p.fClusters)
217 p.fClusters = new AliTRDcluster*[(Int_t)kMaxClusterPerTimeBin];
218 if (!p.fIndex)
219 p.fIndex = new UInt_t[(Int_t)kMaxClusterPerTimeBin];
220 }
221 for (Int_t i = 0; i < (Int_t)kMaxClusterPerTimeBin; i++){
222 //overwrite
223 p.fClusters[i] = fClusters[i];
224 p.fIndex[i] = fIndex[i];
225 }
226
227}
228
229//_____________________________________________________________________________
4d6aee34 230void AliTRDpropagationLayer::SetZ(Double_t * const center, Double_t * const w, Double_t * const wsensitive )
e4f2f73d 231{
232 //
233 // Set centers and the width of sectors
234 //
235
053767a4 236 for (Int_t istack = 0; istack < AliTRDgeometry::kNstack; istack++) {
237 fZc[istack] = center[istack];
238 fZmax[istack] = w[istack];
239 fZmaxSensitive[istack] = wsensitive[istack];
e4f2f73d 240 }
241
242}
243
244//_____________________________________________________________________________
4d6aee34 245void AliTRDpropagationLayer::SetHoles(Bool_t * const holes)
e4f2f73d 246{
247 //
248 // Set centers and the width of sectors
249 //
250
251 fHole = kFALSE;
252
053767a4 253 for (Int_t istack = 0; istack < AliTRDgeometry::kNstack; istack++) {
254 fIsHole[istack] = holes[istack];
255 if (holes[istack]) {
e4f2f73d 256 fHole = kTRUE;
257 }
258 }
259
260}
261
262//_____________________________________________________________________________
263void AliTRDpropagationLayer::InsertCluster(AliTRDcluster *c, UInt_t index)
264{
265 //
266 // Insert cluster in cluster array.
267 // Clusters are sorted according to Y coordinate.
268 //
269
270 if (fTimeBinIndex < 0) {
271 //AliWarning("Attempt to insert cluster into non-sensitive time bin!\n");
272 return;
273 }
274
275 if (fN == (Int_t) kMaxClusterPerTimeBin) {
276 //AliWarning("Too many clusters !\n");
277 return;
278 }
279
280 if (fN == 0) {
281 fIndex[0] = index;
282 fClusters[fN++] = c;
283 return;
284 }
285
286 Int_t i = Find(c->GetY());
287 memmove(fClusters+i+1,fClusters+i,(fN-i)*sizeof(AliTRDcluster*));
288 memmove(fIndex +i+1,fIndex +i,(fN-i)*sizeof(UInt_t));
289 fIndex[i] = index;
290 fClusters[i] = c;
291 fN++;
292
293}
294
295//_____________________________________________________________________________
296Int_t AliTRDpropagationLayer::Find(Float_t y) const
297{
298 //
299 // Returns index of the cluster nearest in Y
300 //
301
302 if (fN <= 0) {
303 return 0;
304 }
305 if (y <= fClusters[0]->GetY()) {
306 return 0;
307 }
308 if (y > fClusters[fN-1]->GetY()) {
309 return fN;
310 }
311
312 Int_t b = 0;
313 Int_t e = fN - 1;
314 Int_t m = (b + e) / 2;
315
316 for ( ; b < e; m = (b + e) / 2) {
317 if (y > fClusters[m]->GetY()) {
318 b = m + 1;
319 }
320 else {
321 e = m;
322 }
323 }
324
325 return m;
326
327}
328
329//_____________________________________________________________________________
330Int_t AliTRDpropagationLayer::FindNearestCluster(Float_t y, Float_t z
331 , Float_t maxroad
332 , Float_t maxroadz) const
333{
334 //
335 // Returns index of the cluster nearest to the given y,z
336 //
337
338 Int_t index = -1;
339 Int_t maxn = fN;
340 Float_t mindist = maxroad;
341
342 for (Int_t i = Find(y-maxroad); i < maxn; i++) {
343 AliTRDcluster *c = (AliTRDcluster *) (fClusters[i]);
344 Float_t ycl = c->GetY();
345 if (ycl > (y + maxroad)) {
346 break;
347 }
348 if (TMath::Abs(c->GetZ() - z) > maxroadz) {
349 continue;
350 }
351 if (TMath::Abs(ycl - y) < mindist) {
352 mindist = TMath::Abs(ycl - y);
353 index = fIndex[i];
354 }
355 }
356
357 return index;
358
359}
360