Decoupled ITS/UPGRADE cmake stuff from ITS
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSsegmentationPixUpg.cxx
CommitLineData
909b16e7 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: AliITSsegmentationPixUpg.cxx 47180 2011-02-08 09:42:29Z masera $ */
17#include <TGeoManager.h>
18#include <TGeoVolume.h>
19#include <TGeoBBox.h>
20#include "AliITSsegmentationPixUpg.h"
21
22////////////////////////////////////////////////////////////////////////////////////////////////////////////
23// Segmentation class for pixels //
24// Questions to solve: are guardrings needed and do they belong to the sensor or to the module in TGeo //
25// At the moment assume that the local coord syst. is located at bottom left corner //
26// of the ACTIVE matrix. If the guardring to be accounted in the local coords, in //
27// the Z and X conversions one needs to first subtract the fGuardLft and fGuardBot //
28// from the local Z,X coordinates //
29// //
30////////////////////////////////////////////////////////////////////////////////////////////////////////////
31
32ClassImp(AliITSsegmentationPixUpg)
33
34//_____________________________________________________________________________RS
35AliITSsegmentationPixUpg::AliITSsegmentationPixUpg(int nchips,int ncol,int nrow,
36 double pitchX,double pitchZ,
37 double pitchLftC,double pitchRgtC,
38 double thickness,
39 double edgL,double edgR,double edgT,double edgB)
40: AliITSsegmentation()
41 ,fGuardLft(edgL)
42 ,fGuardRgt(edgR)
43 ,fGuardTop(edgT)
44 ,fGuardBot(edgB)
45 ,fPitchX(pitchX)
46 ,fPitchZ(pitchZ)
47 ,fPitchZLftCol(pitchLftC<0 ? pitchZ:pitchLftC)
48 ,fPitchZRgtCol(pitchRgtC<0 ? pitchZ:pitchRgtC)
49 ,fChipDZ(0)
50 ,fNChips(nchips)
51 ,fNColPerChip(nchips>0 ? ncol/nchips:0)
52 ,fNRow(nrow)
53 ,fNCol(ncol)
54{
55 // Default constructor, sizes in microns
56 fChipDZ = (fNColPerChip-2)*fPitchZ + fPitchZLftCol + fPitchZRgtCol;
57 SetDetSize( fNRow*fPitchX /*+fGuardTop+fGuardBot*/,
58 fNChips*fChipDZ /*+fGuardLft+fGuardRgt*/,
59 thickness);
60 //
61}
62
63//_____________________________________________________________________________RS
64void AliITSsegmentationPixUpg::GetPadIxz(Float_t x,Float_t z,Int_t &ix,Int_t &iz) const
65{
66 // Returns pixel coordinates (ix,iz) for given real local coordinates (x,z)
67 // expects x, z in microns
68 ix = int(x/fPitchX) + 1;
69 iz = int(Z2Col(z)) + 1;
70 //
71 if (iz > fNCol) iz= fNCol;
72 if (ix > fNRow) ix= fNRow;
73 //
74}
75
76//_____________________________________________________________________________RS
77void AliITSsegmentationPixUpg::GetPadTxz(Float_t &x,Float_t &z) const
78{
79 // local transformation of real local coordinates (x,z)
80 // expects x, z in microns
81 x /= fPitchX;
82 z = Z2Col(z);
83 //
84}
85
86//_____________________________________________________________________________RS
87void AliITSsegmentationPixUpg::GetPadCxz(Int_t ix,Int_t iz,Float_t &x,Float_t&z) const
88{
89 // Transform from pixel to real local coordinates
90 // returns x, z in microns
91 x = (ix>0) ? Float_t((ix-0.5)*fPitchX) : Float_t((ix+0.5)*fPitchX);
92 z = Col2Z(iz);
93 //
94}
95
96//_____________________________________________________________________________RS
97Float_t AliITSsegmentationPixUpg::Z2Col(Float_t z) const
98{
99 // get column number (from 0) from local Z
100 int chip = z/fChipDZ;
101 float col = chip*fNColPerChip;
102 z -= chip*fChipDZ;
103 if (z<fPitchZLftCol) col += z/fPitchZLftCol;
104 else {
105 z = fPitchZLftCol;
106 col += 1;
107 if (z<(fChipDZ-fPitchZRgtCol)) col += 1+z/fPitchZ;
108 else col += 1+(z - (fNColPerChip-2)*fPitchZ)/fPitchZRgtCol;
109 }
110 return col;
111}
112
113//_____________________________________________________________________________RS
114Float_t AliITSsegmentationPixUpg::Col2Z(Int_t col) const
115{
116 // convert column number (from 0) to Z coordinate
117 int nchip = col/fNColPerChip;
118 col %= fNColPerChip;
119 float z = nchip*fChipDZ;
120 if (!col) z -= fPitchZRgtCol/2;
121 else if (col==1) z += fPitchZLftCol/2;
122 else if (col==fNColPerChip-1) z += fChipDZ - fPitchZRgtCol/2;
123 else z += fPitchZLftCol + (col-0.5)*fChipDZ;
124 return z;
125 //
126}
127
128//______________________________________________________________________RS
129AliITSsegmentationPixUpg& AliITSsegmentationPixUpg::operator=(const AliITSsegmentationPixUpg &src)
130{
131 // = operator
132 if(this==&src) return *this;
133 AliITSsegmentation::operator=(src);
134 fNCol = src.fNCol;
135 fNRow = src.fNRow;
136 fNColPerChip = src.fNColPerChip;
137 fNChips = src.fNChips;
138 fChipDZ = src.fChipDZ;
139 fPitchZRgtCol = src.fPitchZRgtCol;
140 fPitchZLftCol = src.fPitchZLftCol;
141 fPitchZ = src.fPitchZ;
142 fPitchX = src.fPitchX;
143 //
144 fGuardBot = src.fGuardBot;
145 fGuardTop = src.fGuardTop;
146 fGuardRgt = src.fGuardRgt;
147 fGuardLft = src.fGuardLft;
148 //
149 return *this;
150}
151
152//____________________________________________________________________________RS
153AliITSsegmentationPixUpg::AliITSsegmentationPixUpg(const AliITSsegmentationPixUpg &src) :
154 AliITSsegmentation(src)
155 ,fGuardLft(src.fGuardLft)
156 ,fGuardRgt(src.fGuardRgt)
157 ,fGuardTop(src.fGuardTop)
158 ,fGuardBot(src.fGuardBot)
159 ,fPitchX(src.fPitchX)
160 ,fPitchZ(src.fPitchZ)
161 ,fPitchZLftCol(src.fPitchZLftCol)
162 ,fPitchZRgtCol(src.fPitchZRgtCol)
163 ,fChipDZ(src.fChipDZ)
164 ,fNChips(src.fNChips)
165 ,fNColPerChip(src.fNColPerChip)
166 ,fNRow(src.fNRow)
167 ,fNCol(src.fNCol)
168{
169}
170
171//____________________________________________________________________________RS
172Float_t AliITSsegmentationPixUpg::Dpx(Int_t ) const
173{
174 //returs x pixel pitch for a give pixel
175 return fPitchX;
176}
177
178//____________________________________________________________________________RS
179Float_t AliITSsegmentationPixUpg::Dpz(Int_t col) const
180{
181 // returns z pixel pitch for a given pixel (cols starts from 0)
182 col %= fNColPerChip;
183 if (!col) return fPitchZLftCol;
184 if (col==fNColPerChip-1) return fPitchZRgtCol;
185 return fPitchZ;
186 //
187}
188
189//------------------------------
190void AliITSsegmentationPixUpg::Neighbours(Int_t iX, Int_t iZ, Int_t* nlist, Int_t xlist[8], Int_t zlist[8]) const
191{
192 // returns the neighbouring pixels for use in Cluster Finders and the like.
193 //
194 *nlist=8;
195 xlist[0]=xlist[1]=iX;
196 xlist[2]=iX-1;
197 xlist[3]=iX+1;
198 zlist[0]=iZ-1;
199 zlist[1]=iZ+1;
200 zlist[2]=zlist[3]=iZ;
201 // Diagonal elements
202 xlist[4]=iX+1;
203 zlist[4]=iZ+1;
204 //
205 xlist[5]=iX-1;
206 zlist[5]=iZ-1;
207 //
208 xlist[6]=iX-1;
209 zlist[6]=iZ+1;
210 //
211 xlist[7]=iX+1;
212 zlist[7]=iZ-1;
213 //
214}
215
216//______________________________________________________________________
217Bool_t AliITSsegmentationPixUpg::LocalToDet(Float_t x,Float_t z,Int_t &ix,Int_t &iz) const
218{
219 // Transformation from Geant detector centered local coordinates (cm) to
220 // Pixel cell numbers ix and iz.
221 // Input:
222 // Float_t x detector local coordinate x in cm with respect to
223 // the center of the sensitive volume.
224 // Float_t z detector local coordinate z in cm with respect to
225 // the center of the sensitive volulme.
226 // Output:
227 // Int_t ix detector x cell coordinate. Has the range
228 // 0<=ix<fNRow.
229 // Int_t iz detector z cell coordinate. Has the range
230 // 0<=iz<fNCol.
231 // Return:
232 // kTRUE if point x,z is inside sensitive volume, kFALSE otherwise.
233 // A value of -1 for ix or iz indecates that this point is outside of the
234 // detector segmentation as defined.
235 x = x*kCM2MC+0.5*Dx();
236 z = z*kCM2MC+0.5*Dz();
237 ix = iz = -1;
238 if(x<0 || x>Dx()) return kFALSE; // outside x range.
239 if(z<0 || z>Dz()) return kFALSE; // outside z range.
240 ix = int(x/fPitchX);
241 iz = Z2Col(z);
242 return kTRUE; // Found ix and iz, return.
243}
244
245//______________________________________________________________________
246void AliITSsegmentationPixUpg::DetToLocal(Int_t ix,Int_t iz,Float_t &x,Float_t &z) const
247{
248// Transformation from Detector cell coordiantes to Geant detector centerd
249// local coordinates (cm).
250// Input:
251// Int_t ix detector x cell coordinate. Has the range 0<=ix<fNRow.
252// Int_t iz detector z cell coordinate. Has the range 0<=iz<fNCol.
253// Output:
254// Float_t x detector local coordinate x in cm with respect to the
255// center of the sensitive volume.
256// Float_t z detector local coordinate z in cm with respect to the
257// center of the sensitive volulme.
258// If ix and or iz is outside of the segmentation range a value of -0.5*Dx()
259// or -0.5*Dz() is returned.
260 //
261 x = -0.5/kCM2MC*Dx(); // default value.
262 z = -0.5/kCM2MC*Dz(); // default value.
263 // RS: to check: why we don't do strict check for [0:n)
264 if(ix<0 || ix>=fNRow) return; // outside of detector
265 if(iz<0 || iz>=fNCol) return; // outside of detctor
266 x += (ix+0.5)*fPitchX*(1./kCM2MC); // RS: we go to the center of the pad, i.e. + pitch/2, not to the boundary as in SPD
267 z += Col2Z(iz)*(1./kCM2MC);
268 return; // Found x and z, return.
269}
270
271//______________________________________________________________________
272void AliITSsegmentationPixUpg::CellBoundries(Int_t ix,Int_t iz,Double_t &xl,Double_t &xu,Double_t &zl,Double_t &zu) const
273{
274 // Transformation from Detector cell coordiantes to Geant detector centerd
275 // local coordinates (cm).
276 // Input:
277 // Int_t ix detector x cell coordinate. Has the range 0<=ix<fNRow.
278 // Int_t iz detector z cell coordinate. Has the range 0<=iz<fNCol.
279 // Output:
280 // Double_t xl detector local coordinate cell lower bounds x in cm
281 // with respect to the center of the sensitive volume.
282 // Double_t xu detector local coordinate cell upper bounds x in cm
283 // with respect to the center of the sensitive volume.
284 // Double_t zl detector local coordinate lower bounds z in cm with
285 // respect to the center of the sensitive volulme.
286 // Double_t zu detector local coordinate upper bounds z in cm with
287 // respect to the center of the sensitive volulme.
288 // If ix and or iz is outside of the segmentation range a value of -0.5*Dx()
289 // and -0.5*Dx() or -0.5*Dz() and -0.5*Dz() are returned.
290 Float_t x,z;
291 DetToLocal(ix,iz,x,z);
292 //
293 if( ix<0 || ix>=fNRow || iz<0 || iz>=fNCol) {
294 xl = xu = -0.5/kCM2MC*Dx(); // default value.
295 zl = zu = -0.5/kCM2MC*Dz(); // default value.
296 return; // outside of detctor
297 }
298 float zpitchH = Dpz(iz)/2./kCM2MC;
299 float xpitchH = fPitchX/2./kCM2MC;
300 xl -= xpitchH;
301 xu += xpitchH;
302 zl -= zpitchH;
303 zu += zpitchH;
304 return; // Found x and z, return.
305}
306
307//______________________________________________________________________
308Int_t AliITSsegmentationPixUpg::GetChipFromChannel(Int_t, Int_t iz) const
309{
310 // returns chip number (in range 0-4) starting from channel number
311 if(iz>=fNCol || iz<0 ){
312 AliWarning("Bad cell number");
313 return -1;
314 }
315 return iz/fNColPerChip;
316}
317
318//______________________________________________________________________
319Int_t AliITSsegmentationPixUpg::GetChipFromLocal(Float_t, Float_t zloc) const
320{
321 // returns chip number (in range 0-4) starting from local coordinates
322 Int_t ix0,iz;
323 if (!LocalToDet(0,zloc,ix0,iz)) {
324 AliWarning("Bad local coordinate");
325 return -1;
326 }
327 return GetChipFromChannel(ix0,iz);
328}
329
330//______________________________________________________________________
331Int_t AliITSsegmentationPixUpg::GetChipsInLocalWindow(Int_t* array, Float_t zmin, Float_t zmax, Float_t, Float_t) const
332{
333 // returns the number of chips containing a road defined by given local coordinate limits
334 //
335 const Float_t kconv = 1./kCM2MC; // converts microns to cm.
336 //
337 if (zmin>zmax) {
338 AliWarning("Bad coordinate limits: zmin>zmax!");
339 return -1;
340 }
341 //
342 Int_t nChipInW = 0;
343 //
344 Float_t zminDet = -0.5*kconv*Dz();
345 Float_t zmaxDet = 0.5*kconv*Dz();
346 if(zmin<zminDet) zmin=zminDet;
347 if(zmax>zmaxDet) zmax=zmaxDet;
348
349 Int_t n1 = GetChipFromLocal(0,zmin);
350 array[nChipInW] = n1;
351 nChipInW++;
352
353 Int_t n2 = GetChipFromLocal(0,zmax);
354
355 if(n2!=n1){
356 Int_t imin=TMath::Min(n1,n2);
357 Int_t imax=TMath::Max(n1,n2);
358 for(Int_t ichip=imin; ichip<=imax; ichip++){
359 if(ichip==n1) continue;
360 array[nChipInW]=ichip;
361 nChipInW++;
362 }
363 }
364 //
365 return nChipInW;
366}
a84c4b15 367
368//______________________________________________________________________
369void AliITSsegmentationPixUpg::Init()
370{
371 // init settings
372}