Fixes for Coverity warnings (M. van Leeuwen)
[u/mrichter/AliRoot.git] / ITS / AliITSsegmentationSSD.cxx
CommitLineData
b0f5e3fc 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 **************************************************************************/
4ae5bbc4 15
88cb7938 16/* $Id$ */
b0f5e3fc 17
4ae5bbc4 18#include <Riostream.h>
55d2c544 19#include <TMath.h>
c9649d1e 20#include <TGeoManager.h>
21#include <TGeoVolume.h>
22#include <TGeoBBox.h>
b0f5e3fc 23#include "AliITSsegmentationSSD.h"
55d2c544 24
25//////////////////////////////////////////////////////
26// Segmentation class for //
27// silicon strips //
28// //
29//////////////////////////////////////////////////////
c60e9baf 30const Float_t AliITSsegmentationSSD::fgkDxDefault = 73000.;
55d2c544 31const Float_t AliITSsegmentationSSD::fgkDzDefault = 40000.;
32const Float_t AliITSsegmentationSSD::fgkDyDefault = 300.;
33const Float_t AliITSsegmentationSSD::fgkPitchDefault = 95.;
34const Int_t AliITSsegmentationSSD::fgkNstripsDefault = 768;
6d38396a 35const Int_t AliITSsegmentationSSD::fgkNchipsPerSide = 6;
36const Int_t AliITSsegmentationSSD::fgkNstripsPerChip = 128;
fd61217e 37
b0f5e3fc 38ClassImp(AliITSsegmentationSSD)
fa4f0f62 39
c9649d1e 40AliITSsegmentationSSD::AliITSsegmentationSSD(Option_t *opt): AliITSsegmentation(),
e56160b8 41fNstrips(0),
42fStereoP(0),
43fStereoN(0),
44fPitch(0),
e56160b8 45fLayer(0){
179578b2 46 // default constructor
fa4f0f62 47 SetDetSize(fgkDxDefault,fgkDzDefault,fgkDyDefault);
48 SetPadSize(fgkPitchDefault,0.);
49 SetNPads(fgkNstripsDefault,0);
50 SetAngles();
c9649d1e 51 if(strstr(opt,"TGeo")){
52 if(!gGeoManager){
53 AliError("Geometry is not initialized\n");
54 return;
55 }
56 TGeoVolume *v=NULL;
57 v = gGeoManager->GetVolume("ITSssdSensitivL5");
58 if(!v){
59 AliWarning("TGeo volumeITSssdSensitivL5 not found (hint: use v11Hybrid geometry)\n Using hardwired default values");
60 }
61 else {
62 TGeoBBox *s=(TGeoBBox*)v->GetShape();
63 SetDetSize(s->GetDX()*20000.,s->GetDZ()*20000.,s->GetDY()*20000.);
64 }
65 }
b0f5e3fc 66}
fa4f0f62 67
55d2c544 68//______________________________________________________________________
69void AliITSsegmentationSSD::Copy(TObject &obj) const {
70 // protected method. copy this to obj
71 AliITSsegmentation::Copy(obj);
72 ((AliITSsegmentationSSD& ) obj).Clear();
73 ((AliITSsegmentationSSD& ) obj).fNstrips = fNstrips;
74 ((AliITSsegmentationSSD& ) obj).fStereoP = fStereoP;
75 ((AliITSsegmentationSSD& ) obj).fStereoN = fStereoN;
55d2c544 76 ((AliITSsegmentationSSD& ) obj).fLayer = fLayer;
77 ((AliITSsegmentationSSD& ) obj).fPitch = fPitch;
78 ((AliITSsegmentationSSD& ) obj).fLayer = fLayer;
79
80}
81
179578b2 82//______________________________________________________________________
83AliITSsegmentationSSD& AliITSsegmentationSSD::operator=(
55d2c544 84 const AliITSsegmentationSSD &source){
0315d466 85// Operator =
55d2c544 86 if(this != &source){
87 source.Copy(*this);
88 }
89 return *this;
b0f5e3fc 90}
179578b2 91//______________________________________________________________________
55d2c544 92AliITSsegmentationSSD::AliITSsegmentationSSD(const AliITSsegmentationSSD &source):
e56160b8 93 AliITSsegmentation(source),
94fNstrips(0),
95fStereoP(0),
96fStereoN(0),
97fPitch(0),
e56160b8 98fLayer(0){
179578b2 99 // copy constructor
55d2c544 100 source.Copy(*this);
b0f5e3fc 101}
179578b2 102//----------------------------------------------------------------------
b0f5e3fc 103void AliITSsegmentationSSD::Init(){
179578b2 104 // standard initalizer
b0f5e3fc 105
55d2c544 106 SetPadSize(fgkPitchDefault,0.);
107 SetNPads(fgkNstripsDefault,0);
b0f5e3fc 108 SetAngles();
179578b2 109}
110//----------------------------------------------------------------------
55d2c544 111void AliITSsegmentationSSD::Angles(Float_t &aP,Float_t &aN) const{
112 // P and N side stereo angles
82adfb7d 113 aP = fStereoP;
114 aN = fStereoN;
0315d466 115}
179578b2 116//----------------------------------------------------------------------
117void AliITSsegmentationSSD::SetLayer(Int_t l){
55d2c544 118 //set fLayer data member (only 5 or 6 are allowed)
179578b2 119 if (l==5) fLayer =5;
82adfb7d 120 else if (l==6) fLayer =6;
121 else AliError(Form("Layer can be 5 or 6, not %d",l));
179578b2 122}
123//----------------------------------------------------------------------
55d2c544 124void AliITSsegmentationSSD::GetPadTxz(Float_t &x,Float_t &z) const{
179578b2 125 // returns P and N sided strip numbers for a given location.
126 // Transformation from microns detector center local coordinates
127 // to detector P and N side strip numbers..
128 /* _- Z
129 + angle / ^
130 fNstrips v | N-Side ...0
131 \-------/------------|-----------\--------\
132 |\\\\\\/////////////.|\\\\\\\\\\\\\\\\\\\\|
133 |0\\\\/////////////..|.\\\\\\\\\\\\\\\\\\\|
134 |00\\/////////////...|..\\\\\\\\\\\\\\\\\\|
135 X <--|000/////////////... |...\\\\\\\\\\\\\\\\\|
136 |00/////////////... | ...\\\\\\\\\\\\\\\\|
137 |0/////////////... | ...\\\\\\\\\\\\\\\|
138 |//////////////... | ...\\\\\\\\\\\\\\\|
139 /-----\--------------|--------------------/
140 fNstrips-1 P-Side ...0
141 |0\
142 |00\
143 Dead region: |000/
144 |00/
145 |0/
8be4e1b1 146 // expects x, z in cm
179578b2 147 */
82adfb7d 148
149 /*
55d2c544 150 Float_t stereoP, stereoN;
151 Angles(stereoP,stereoN);
152 Float_t tanP = TMath::Tan(stereoP);
153 Float_t tanN = TMath::Tan(-stereoN);
179578b2 154 Float_t x1 = x;
155 Float_t z1 = z;
156 x1 += fDx/2;
157 z1 += fDz/2;
158 x = (x1 - z1*tanP)/fPitch;
159 z = (x1 - tanN*(z1 - fDz))/fPitch;
82adfb7d 160 */
161
162 Float_t P=0;
163 Float_t N=0;
164 if(fLayer==5) {
8be4e1b1 165 P = 105.26*x - 0.7895*z + 382.000; //- 0.79*z + 381.89;
166 N = P + 3.684*z - 4;
82adfb7d 167 }
168 else if(fLayer==6) {
8be4e1b1 169 P = -105.26*x - 0.7895*z + 385.000; //- 0.79*z + 384.66;
170 N = P + 3.684*z + 4;
82adfb7d 171 }
172 else AliError("Layer can be 5 or 6");
173
174 x=P;
175 z=N;
176
179578b2 177}
178//----------------------------------------------------------------------
55d2c544 179void AliITSsegmentationSSD::GetPadIxz(Float_t x,Float_t z,Int_t &iP,Int_t &iN) const {
0315d466 180 // returns P and N sided strip numbers for a given location.
8be4e1b1 181 // expects x, z in cm
0315d466 182
8be4e1b1 183 GetPadTxz(x,z);
184 iP = Int_t(x+0.5);
185 iN = Int_t(z+0.5);
b0f5e3fc 186}
0315d466 187//-------------------------------------------------------
8be4e1b1 188void AliITSsegmentationSSD::GetPadCxz(Float_t iP,Float_t iN,Float_t &x,Float_t &z) const {
179578b2 189 // actually this is the GetCrossing(Float_t &,Float_t &)
8be4e1b1 190 // returns local x, z in cm
191 const Float_t kStartXzero=3.64325;
192 const Float_t kDeltaXzero5or6=0.02239;
193 const Float_t kDeltaZ5to6=7.6/7.0;
b0f5e3fc 194
8be4e1b1 195 z = 1.9*(iN-iP)/7.0;
196 x = kStartXzero-(285*iN + 1045*iP)/140000.0;
b0f5e3fc 197
8be4e1b1 198 if (fLayer==5){
199 z += kDeltaZ5to6;
200 x = -x + kDeltaXzero5or6;
201 }
202 else if (fLayer==6) {
203 z -= kDeltaZ5to6;
204 x += kDeltaXzero5or6;
205 }
206 else {
207 AliWarning("Layer shoudl be 5 or 6");
208 x = -99999;
209 z = -99999;
210 }
b0f5e3fc 211}
179578b2 212//______________________________________________________________________
aacedc3e 213Bool_t AliITSsegmentationSSD::LocalToDet(Float_t x,Float_t z,
55d2c544 214 Int_t &iP,Int_t &iN) const {
179578b2 215 // Transformation from Geant cm detector center local coordinates
216 // to detector P and N side strip numbers..
217 /* _- Z
218 + angle / ^
219 fNstrips v | N-Side ...0
220 \-------/------------|-----------\--------\
221 |\\\\\\/////////////.|\\\\\\\\\\\\\\\\\\\\|
222 |0\\\\/////////////..|.\\\\\\\\\\\\\\\\\\\|
223 |00\\/////////////...|..\\\\\\\\\\\\\\\\\\|
224 X <--|000/////////////... |...\\\\\\\\\\\\\\\\\|
225 |00/////////////... | ...\\\\\\\\\\\\\\\\|
226 |0/////////////... | ...\\\\\\\\\\\\\\\|
227 |//////////////... | ...\\\\\\\\\\\\\\\|
228 /-----\--------------|--------------------/
229 fNstrips-1 P-Side ...0
230 |0\
231 |00\
232 Dead region: |000/
233 |00/
234 |0/
235 */
6d38396a 236 Float_t dx,dz;
237 const Double_t kconst = 1.0E-04; // convert microns to cm.
238 dx = 0.5*kconst*Dx();
239 dz = 0.5*kconst*Dz();
23197852 240 if( (x<-dx) || (x>dx) ) {
241 iP=-1;
242 AliWarning(Form("Input argument %f out of range (%f, %f)",x,dx,-dx));
243 return kFALSE; // outside of defined volume.
244 } // outside x range.
245 if( (z<-dz) || (z>dz) ) {
246 iN=-1;
247 AliWarning(Form("Input argument %f out of range (%f, %f)",z,dz,-dz));
248 return kFALSE; // outside of defined volume.
249 }
6d38396a 250
82adfb7d 251 //x /= kconst; // convert to microns
252 //z /= kconst; // convert to microns
6d38396a 253 this->GetPadTxz(x,z);
254
255 // first for P side
256 iP = (Int_t) x;
257 if(iP<0 || iP>=fNstrips) iP=-1; // strip number must be in range.
258 // Now for N side)
259 iN = (Int_t) z;
260 if(iN<0 || iN>=fNstrips) iN=-1; // strip number must be in range.
261 return kTRUE;
179578b2 262}
263//----------------------------------------------------------------------
264void AliITSsegmentationSSD::DetToLocal(Int_t ix,Int_t iPN,
55d2c544 265 Float_t &x,Float_t &z) const{
179578b2 266 // Transformation from detector segmentation/cell coordiantes starting
267 // from 0. iPN=0 for P side and 1 for N side strip. Returned is z=0.0
268 // and the corresponding x value..
269 /* _- Z
270 + angle / ^
271 fNstrips v | N-Side ...0
272 \-------/------------|-----------\--------\
273 |\\\\\\/////////////.|\\\\\\\\\\\\\\\\\\\\|
274 |0\\\\/////////////..|.\\\\\\\\\\\\\\\\\\\|
275 |00\\/////////////...|..\\\\\\\\\\\\\\\\\\|
276 X <--|000/////////////... |...\\\\\\\\\\\\\\\\\|
277 |00/////////////... | ...\\\\\\\\\\\\\\\\|
278 |0/////////////... | ...\\\\\\\\\\\\\\\|
279 |//////////////... | ...\\\\\\\\\\\\\\\|
280 /-----\--------------|--------------------/
281 fNstrips-1 P-Side ...0
282 |0\
283 |00\
284 Dead region: |000/
285 |00/
286 |0/
287 */
288 // for strips p-side
289 // x = a + b + z*tan(fStereoP); a = Dpx(iP)*(iP+0.5)-dx; b = dz*th;
290 // for strips n-side
291 // x = a + b + z*tan(fStereoP); a = Dpx(iN)*(iN+0.5)-dx; b = -dz*th;
8be4e1b1 292 AliWarning("This function has not been verified. Should probably use GetPadCxz");
179578b2 293 const Double_t kconst = 1.0E-04; // convert microns to cm.
294 Float_t flag=kconst*Dx(); // error value
295 Double_t th=0.0,dx,dz,i,a,b=0.0,xb[4],zb[4];
55d2c544 296 Float_t stereoP, stereoN;
297 Angles(stereoP,stereoN);
5752a110 298
179578b2 299 z = 0.0; // Strip center in z.
300 if(iPN<0 || iPN>1){// if error return full detector size in x.
301 x = z = flag;
302 return;
303 } // end if
304 if(ix<0 || ix>=fNstrips) { // if error return full detector size in x.
305 x = z = flag;
306 return;
307 } // end if
308 i = (Double_t) ix; // convert to double
309 dx = 0.5*kconst*Dx(); // half distance in x in cm
310 dz = 0.5*kconst*Dz(); // half distance in z in cm
311 a = kconst*Dpx(ix)*(i+0.5)-dx; // Min x value.
312 if(iPN==0){ //P-side angle defined backwards.
55d2c544 313 th = TMath::Tan(stereoP);
179578b2 314 b = dz*th;
315 }else if(iPN==1){ // N-side
55d2c544 316 th = TMath::Tan(-stereoN);
179578b2 317 b = -dz*th;
318 } // end if
319 // compute average/center position of the strip.
320 xb[0] = +dx; if(th!=0.0) zb[0] = (+dx-a-b)/th; else zb[0] = 0.0;
321 xb[1] = -dx; if(th!=0.0) zb[1] = (-dx-a-b)/th; else zb[1] = 0.0;
322 xb[2] = a+b+dz*th; zb[2] = +dz;
323 xb[3] = a+b-dz*th; zb[3] = -dz;
324 x = 0.0; z = 0.0;
325 for(Int_t j=0;j<4;j++){
326 if(xb[j]>=-dx && xb[j]<=dx && zb[j]>=-dz && zb[j]<=dz){
327 x += xb[j];
328 z += zb[j];
329 } // end if
330 } // end for
331 x *= 0.5;
332 z *= 0.5;
333 return;
334}
335//----------------------------------------------------------------------
6d38396a 336Int_t AliITSsegmentationSSD::GetChipFromChannel(Int_t ix, Int_t iz) const {
337 // returns chip number (in range 0-11) starting from channel number
338
339 if( (iz>=fgkNstripsDefault) || (iz<0) || (ix<0) || (ix>1) ) {
340 AliError("Bad cell number");
341 return -1;
342 }
343
344 if(ix==1) iz = 1535-iz;
345 Int_t theChip =iz/fgkNstripsPerChip;
346 return theChip;
347
348}
349//----------------------------------------------------------------------
350Int_t AliITSsegmentationSSD::GetChipFromLocal(Float_t xloc, Float_t zloc) const
351{
352 // returns chip numbers starting from local coordinates
353 // The two Nside chip number and Pside chip number are
354 // coded as chip=Nchip*10+Pchip
355
356 Int_t iP=0;
357 Int_t iN=0;
358 if (!LocalToDet(xloc,zloc,iP,iN) ||
359 (iP<0) || (iP>=fNstrips) || (iN<0) || (iN>=fNstrips) ) {
23197852 360 //AliWarning("Bad local coordinate");
6d38396a 361 return -1;
362 }
363
364 Int_t iChip = GetChipFromChannel(0,iP);
365 iChip += 10*GetChipFromChannel(1,iN); // add Nside
366
367 return iChip;
368
369}
370//
371
23197852 372Int_t AliITSsegmentationSSD::GetChipsInLocalWindow(Int_t* array, Float_t zmin, Float_t zmax,
373 Float_t xmin, Float_t xmax) const {
18f63405 374 // returns chip number in a given xz window
23197852 375
376 Int_t nChipInW = 0;
377
378 Float_t zminDet=-fDz*1.0E-04/2.;
379 Float_t zmaxDet=fDz*1.0E-04/2.;
380 if(zmin<zminDet) zmin=zminDet;
381 if(zmax>zmaxDet) zmax=zmaxDet;
382
383 Float_t xminDet=-fDx*1.0E-04/2;
384 Float_t xmaxDet=fDx*1.0E-04/2;
385 if(xmin<xminDet) xmin=xminDet;
386 if(xmax>xmaxDet) xmax=xmaxDet;
387
388 Int_t n1N=-1;
389 Int_t n1P=-1;
390 Int_t n1=GetChipFromLocal(xmin,zmin);
391 if(n1!=-1) { // Note! Recpoint can be on the sensor but in the dead area not covered by strips!
392 n1N = (Int_t) (n1/10); // N-side chip coded as 10*chip_index
393 n1P = n1 - 10 * n1N; // P-side chip coded 0-5
394 array[nChipInW]=n1P;
395 nChipInW++;
396 array[nChipInW]=n1N;
397 nChipInW++;
398 }
399
400 Int_t n2N=-1;
401 Int_t n2P=-1;
402 Int_t n2=GetChipFromLocal(xmin,zmax);
403 if(n2!=-1) { // Note! Recpoint can be on the sensor but in the dead area not covered by strips!
404 n2N = (Int_t) (n2/10); // N-side chip coded as 10*chip_index
405 n2P = n2 - 10 * n2N; // P-side chip coded 0-5
406 if(n2P!=n1P) { array[nChipInW]=n2P; nChipInW++;}
407 if(n2N!=n1N) { array[nChipInW]=n2N; nChipInW++;}
408 }
409
410 Int_t n3N=-1;
411 Int_t n3P=-1;
412 Int_t n3=GetChipFromLocal(xmax,zmin);
413 if(n3!=-1) {
414 n3N=(Int_t) (n3/10); // N-side chip coded as 10*chip_index
415 n3P=n3 - 10 * n3N; // P-side chip coded 0-5
416 if((n3P!=n1P)&&(n3P!=n2P)) { array[nChipInW]=n3P; nChipInW++;}
417 if((n3N!=n1N)&&(n3N!=n2N)) { array[nChipInW]=n3N; nChipInW++;}
418 }
419
420 Int_t n4N=-1;
421 Int_t n4P=-1;
422 Int_t n4=GetChipFromLocal(xmax,zmax);
423 if(n4!=-1) {
424 n4N=(Int_t) (n4/10); // N-side chip coded as 10*chip_index
425 n4P=n4 - 10 * n4N; // P-side chip coded 0-5
426 if((n4P!=n1P)&&(n4P!=n2P)&&(n4P!=n3P)) { array[nChipInW]=n4P; nChipInW++;}
427 if((n4N!=n1N)&&(n4N!=n2N)&&(n4N!=n3N)) { array[nChipInW]=n4N; nChipInW++;}
428 }
429
430 return nChipInW;
431
432}
433
6d38396a 434//----------------------------------------------------------------------
55d2c544 435void AliITSsegmentationSSD::PrintDefaultParameters() const {
436// Print default values for parameters.
437// Values specified as static const data members are shown
438
439 cout<<"fgkDxDefault = "<<fgkDxDefault<<endl;
440 cout<<"fgkDzDefault = "<<fgkDzDefault<<endl;
441 cout<<"fgkDyDefault = "<<fgkDyDefault<<endl;
442 cout<<"fgkPitchDefault = "<<fgkPitchDefault<<endl;
443 cout<<"fgkNstripsDefault = "<<fgkNstripsDefault<<endl;
444}