Coverity
[u/mrichter/AliRoot.git] / TRD / AliTRDpadPlane.cxx
CommitLineData
e0d47c25 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// Describes a pad plane of a TRD ROC //
21// //
22// Contains the information on pad postions, pad dimensions, //
23// tilting angle, etc. //
24// It also provides methods to identify the current pad number from //
25// global coordinates. //
3148e21a 26// The numbering and coordinates should follow the official convention //
27// (see David Emschermanns note on TRD convention //
e0d47c25 28// //
29///////////////////////////////////////////////////////////////////////////////
30
090026bf 31#include <TMath.h>
32
e0d47c25 33#include "AliTRDpadPlane.h"
e0d47c25 34
35ClassImp(AliTRDpadPlane)
36
37//_____________________________________________________________________________
2745a409 38AliTRDpadPlane::AliTRDpadPlane()
39 :TObject()
053767a4 40 ,fLayer(0)
41 ,fStack(0)
2745a409 42 ,fLength(0)
43 ,fWidth(0)
44 ,fLengthRim(0)
45 ,fWidthRim(0)
46 ,fLengthOPad(0)
47 ,fWidthOPad(0)
48 ,fLengthIPad(0)
49 ,fWidthIPad(0)
50 ,fRowSpacing(0)
51 ,fColSpacing(0)
52 ,fNrows(0)
53 ,fNcols(0)
54 ,fTiltingAngle(0)
55 ,fTiltingTan(0)
56 ,fPadRow(0)
57 ,fPadCol(0)
4329977a 58 ,fPadRowSMOffset(0)
58897a75 59 ,fAnodeWireOffset(0)
e0d47c25 60{
61 //
62 // Default constructor
63 //
64
e0d47c25 65}
66
5dfd5caf 67//_____________________________________________________________________________
053767a4 68AliTRDpadPlane::AliTRDpadPlane(Int_t layer, Int_t stack)
5dfd5caf 69 :TObject()
053767a4 70 ,fLayer(layer)
71 ,fStack(stack)
5dfd5caf 72 ,fLength(0)
73 ,fWidth(0)
74 ,fLengthRim(0)
75 ,fWidthRim(0)
76 ,fLengthOPad(0)
77 ,fWidthOPad(0)
78 ,fLengthIPad(0)
79 ,fWidthIPad(0)
80 ,fRowSpacing(0)
81 ,fColSpacing(0)
82 ,fNrows(0)
83 ,fNcols(0)
84 ,fTiltingAngle(0)
85 ,fTiltingTan(0)
86 ,fPadRow(0)
87 ,fPadCol(0)
88 ,fPadRowSMOffset(0)
58897a75 89 ,fAnodeWireOffset(0)
5dfd5caf 90{
91 //
92 // Constructor
93 //
94
95}
96
e0d47c25 97//_____________________________________________________________________________
2745a409 98AliTRDpadPlane::AliTRDpadPlane(const AliTRDpadPlane &p)
99 :TObject(p)
053767a4 100 ,fLayer(p.fLayer)
101 ,fStack(p.fStack)
2745a409 102 ,fLength(p.fLength)
103 ,fWidth(p.fWidth)
104 ,fLengthRim(p.fLengthRim)
105 ,fWidthRim(p.fLengthRim)
106 ,fLengthOPad(p.fLengthOPad)
107 ,fWidthOPad(p.fWidthOPad)
108 ,fLengthIPad(p.fLengthIPad)
109 ,fWidthIPad(p.fWidthIPad)
110 ,fRowSpacing(p.fRowSpacing)
111 ,fColSpacing(p.fColSpacing)
112 ,fNrows(p.fNrows)
113 ,fNcols(p.fNcols)
114 ,fTiltingAngle(p.fTiltingAngle)
115 ,fTiltingTan(p.fTiltingTan)
116 ,fPadRow(0)
117 ,fPadCol(0)
4329977a 118 ,fPadRowSMOffset(p.fPadRowSMOffset)
58897a75 119 ,fAnodeWireOffset(p.fAnodeWireOffset)
e0d47c25 120{
121 //
122 // AliTRDpadPlane copy constructor
123 //
124
2745a409 125 Int_t iBin = 0;
126
024c0422 127 fPadRow = new Double_t[fNrows];
2745a409 128 for (iBin = 0; iBin < fNrows; iBin++) {
024c0422 129 fPadRow[iBin] = ((AliTRDpadPlane &) p).fPadRow[iBin];
2745a409 130 }
131
024c0422 132 fPadCol = new Double_t[fNrows];
2745a409 133 for (iBin = 0; iBin < fNrows; iBin++) {
024c0422 134 fPadCol[iBin] = ((AliTRDpadPlane &) p).fPadCol[iBin];
2745a409 135 }
e0d47c25 136
137}
138
139//_____________________________________________________________________________
140AliTRDpadPlane::~AliTRDpadPlane()
141{
142 //
143 // AliTRDpadPlane destructor
144 //
145
e0d47c25 146 if (fPadRow) {
147 delete [] fPadRow;
148 fPadRow = 0;
149 }
150
151 if (fPadCol) {
152 delete [] fPadCol;
153 fPadCol = 0;
154 }
155
156}
157
3c537e64 158//_____________________________________________________________________________
159AliTRDpadPlane &AliTRDpadPlane::operator=(const AliTRDpadPlane &p)
160{
161 //
162 // Assignment operator
163 //
164
12c9b1c3 165 if (this == &p) {
166 return *this;
f881dc35 167 }
168
12c9b1c3 169 fLayer = p.fLayer;
170 fStack = p.fStack;
171 fLength = p.fLength;
172 fWidth = p.fWidth;
173 fLengthRim = p.fLengthRim;
174 fWidthRim = p.fLengthRim;
175 fLengthOPad = p.fLengthOPad;
176 fWidthOPad = p.fWidthOPad;
177 fLengthIPad = p.fLengthIPad;
178 fWidthIPad = p.fWidthIPad;
179 fRowSpacing = p.fRowSpacing;
180 fColSpacing = p.fColSpacing;
181 fNrows = p.fNrows;
182 fNcols = p.fNcols;
183 fTiltingAngle = p.fTiltingAngle;
184 fTiltingTan = p.fTiltingTan;
185 fPadRow = 0;
186 fPadCol = 0;
187 fPadRowSMOffset = p.fPadRowSMOffset;
188 fAnodeWireOffset = p.fAnodeWireOffset;
189
190 Int_t iBin = 0;
191
089086d3 192 if (fPadRow) {
193 delete [] fPadRow;
194 }
12c9b1c3 195 fPadRow = new Double_t[fNrows];
196 for (iBin = 0; iBin < fNrows; iBin++) {
197 fPadRow[iBin] = ((AliTRDpadPlane &) p).fPadRow[iBin];
198 }
199
089086d3 200 if (fPadCol) {
201 delete [] fPadCol;
202 }
12c9b1c3 203 fPadCol = new Double_t[fNrows];
204 for (iBin = 0; iBin < fNrows; iBin++) {
205 fPadCol[iBin] = ((AliTRDpadPlane &) p).fPadCol[iBin];
206 }
207
3c537e64 208 return *this;
209
210}
211
e0d47c25 212//_____________________________________________________________________________
213void AliTRDpadPlane::Copy(TObject &p) const
214{
215 //
216 // Copy function
217 //
218
219 Int_t iBin = 0;
220
58897a75 221 ((AliTRDpadPlane &) p).fLayer = fLayer;
222 ((AliTRDpadPlane &) p).fStack = fStack;
e0d47c25 223
58897a75 224 ((AliTRDpadPlane &) p).fLength = fLength;
225 ((AliTRDpadPlane &) p).fWidth = fWidth;
226 ((AliTRDpadPlane &) p).fLengthRim = fLengthRim;
227 ((AliTRDpadPlane &) p).fWidthRim = fWidthRim;
228 ((AliTRDpadPlane &) p).fLengthOPad = fLengthOPad;
229 ((AliTRDpadPlane &) p).fWidthOPad = fWidthOPad;
230 ((AliTRDpadPlane &) p).fLengthIPad = fLengthIPad;
231 ((AliTRDpadPlane &) p).fWidthIPad = fWidthIPad;
e0d47c25 232
58897a75 233 ((AliTRDpadPlane &) p).fRowSpacing = fRowSpacing;
234 ((AliTRDpadPlane &) p).fColSpacing = fColSpacing;
e0d47c25 235
58897a75 236 ((AliTRDpadPlane &) p).fNrows = fNrows;
237 ((AliTRDpadPlane &) p).fNcols = fNcols;
e0d47c25 238
58897a75 239 ((AliTRDpadPlane &) p).fTiltingAngle = fTiltingAngle;
240 ((AliTRDpadPlane &) p).fTiltingTan = fTiltingTan;
e0d47c25 241
58897a75 242 ((AliTRDpadPlane &) p).fPadRowSMOffset = fPadRowSMOffset;
243 ((AliTRDpadPlane &) p).fAnodeWireOffset = fAnodeWireOffset;
e0d47c25 244
f881dc35 245 if (((AliTRDpadPlane &) p).fPadRow) {
246 delete [] ((AliTRDpadPlane &) p).fPadRow;
247 }
e0d47c25 248 ((AliTRDpadPlane &) p).fPadRow = new Double_t[fNrows];
249 for (iBin = 0; iBin < fNrows; iBin++) {
250 ((AliTRDpadPlane &) p).fPadRow[iBin] = fPadRow[iBin];
251 }
252
f881dc35 253 if (((AliTRDpadPlane &) p).fPadCol) {
254 delete [] ((AliTRDpadPlane &) p).fPadCol;
255 }
e0d47c25 256 ((AliTRDpadPlane &) p).fPadCol = new Double_t[fNrows];
257 for (iBin = 0; iBin < fNrows; iBin++) {
258 ((AliTRDpadPlane &) p).fPadCol[iBin] = fPadCol[iBin];
259 }
260
261 TObject::Copy(p);
262
263}
264
f18d4f83 265//_____________________________________________________________________________
266void AliTRDpadPlane::SetTiltingAngle(Double_t t)
267{
268 //
269 // Set the tilting angle of the pads
270 //
271
272 fTiltingAngle = t;
273 fTiltingTan = TMath::Tan(TMath::Pi()/180.0 * fTiltingAngle);
274
275}
276
e0d47c25 277//_____________________________________________________________________________
98ce8151 278Int_t AliTRDpadPlane::GetPadRowNumber(Double_t z) const
e0d47c25 279{
280 //
4329977a 281 // Finds the pad row number for a given z-position in local supermodule system
e0d47c25 282 //
283
284 Int_t row = 0;
285 Int_t nabove = 0;
286 Int_t nbelow = 0;
287 Int_t middle = 0;
288
f881dc35 289 if ((z > GetRow0() ) ||
290 (z < GetRowEnd())) {
a5cadd36 291
e0d47c25 292 row = -1;
a5cadd36 293
4329977a 294 }
295 else {
296
297 nabove = fNrows + 1;
298 nbelow = 0;
299 while (nabove - nbelow > 1) {
300 middle = (nabove + nbelow) / 2;
301 if (z == (fPadRow[middle-1] + fPadRowSMOffset)) {
302 row = middle;
303 }
304 if (z > (fPadRow[middle-1] + fPadRowSMOffset)) {
305 nabove = middle;
306 }
307 else {
308 nbelow = middle;
309 }
310 }
311 row = nbelow - 1;
312
313 }
314
315 return row;
316
317}
318
319//_____________________________________________________________________________
320Int_t AliTRDpadPlane::GetPadRowNumberROC(Double_t z) const
321{
322 //
323 // Finds the pad row number for a given z-position in local ROC system
324 //
325
326 Int_t row = 0;
327 Int_t nabove = 0;
328 Int_t nbelow = 0;
329 Int_t middle = 0;
330
331 if ((z > GetRow0ROC() ) ||
332 (z < GetRowEndROC())) {
333
334 row = -1;
335
e0d47c25 336 }
337 else {
a5cadd36 338
f881dc35 339 nabove = fNrows + 1;
e0d47c25 340 nbelow = 0;
341 while (nabove - nbelow > 1) {
342 middle = (nabove + nbelow) / 2;
f881dc35 343 if (z == fPadRow[middle-1]) {
344 row = middle;
345 }
346 if (z > fPadRow[middle-1]) {
347 nabove = middle;
348 }
349 else {
350 nbelow = middle;
351 }
e0d47c25 352 }
353 row = nbelow - 1;
a5cadd36 354
e0d47c25 355 }
356
357 return row;
358
359}
360
361//_____________________________________________________________________________
4329977a 362Int_t AliTRDpadPlane::GetPadColNumber(Double_t rphi) const
e0d47c25 363{
364 //
023b669c 365 // Finds the pad column number for a given rphi-position
e0d47c25 366 //
367
4329977a 368 Int_t col = 0;
369 Int_t nabove = 0;
370 Int_t nbelow = 0;
371 Int_t middle = 0;
2f4fac20 372
023b669c 373 if ((rphi < GetCol0() ) ||
374 (rphi > GetColEnd())) {
e0d47c25 375
e0d47c25 376 col = -1;
a5cadd36 377
e0d47c25 378 }
379 else {
a5cadd36 380
023b669c 381 nabove = fNcols;
e0d47c25 382 nbelow = 0;
383 while (nabove - nbelow > 1) {
384 middle = (nabove + nbelow) / 2;
023b669c 385 if (rphi == fPadCol[middle]) {
f881dc35 386 col = middle;
387 }
023b669c 388 if (rphi > fPadCol[middle]) {
389 nbelow = middle;
f881dc35 390 }
391 else {
023b669c 392 nabove = middle;
f881dc35 393 }
e0d47c25 394 }
023b669c 395 col = nbelow;
e0d47c25 396
e0d47c25 397 }
e0d47c25 398
a5cadd36 399 return col;
e0d47c25 400
401}