]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSsegmentationSSD.cxx
Anode numbering adapted to hardware channel numbering + Code cleanup of segmentation...
[u/mrichter/AliRoot.git] / ITS / AliITSsegmentationSSD.cxx
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 #include <Riostream.h>
19 #include <TMath.h>
20 #include "AliITSsegmentationSSD.h"
21
22 //////////////////////////////////////////////////////
23 // Segmentation class for                           //
24 // silicon strips                                   //
25 //                                                  //
26 //////////////////////////////////////////////////////
27 const Float_t AliITSsegmentationSSD::fgkDxDefault = 72960.;
28 const Float_t AliITSsegmentationSSD::fgkDzDefault = 40000.;
29 const Float_t AliITSsegmentationSSD::fgkDyDefault = 300.;
30 const Float_t AliITSsegmentationSSD::fgkPitchDefault = 95.;
31 const Int_t AliITSsegmentationSSD::fgkNstripsDefault = 768;
32
33 ClassImp(AliITSsegmentationSSD)
34 AliITSsegmentationSSD::AliITSsegmentationSSD(): AliITSsegmentation(),
35 fNstrips(0),
36 fStereoP(0),
37 fStereoN(0),
38 fPitch(0),
39 fStereoPl5(0),
40 fStereoNl5(0),
41 fStereoPl6(0),
42 fStereoNl6(0),
43 fLayer(0){
44     // default constructor
45 }
46 //----------------------------------------------------------------------
47 AliITSsegmentationSSD::AliITSsegmentationSSD(AliITSgeom *geom):
48 AliITSsegmentation(geom),
49 fNstrips(0),
50 fStereoP(0),
51 fStereoN(0),
52 fPitch(0),
53 fStereoPl5(0),
54 fStereoNl5(0),
55 fStereoPl6(0),
56 fStereoNl6(0),
57 fLayer(0){
58     // constuctor
59     fCorr = 0;
60     SetDetSize(fgkDxDefault,fgkDzDefault,fgkDyDefault);
61     SetPadSize(fgkPitchDefault,0.);
62     SetNPads(fgkNstripsDefault,0);
63     SetAngles();
64     fLayer = 0;
65 }
66 //______________________________________________________________________
67 void AliITSsegmentationSSD::Copy(TObject &obj) const {
68   // protected method. copy this to obj
69   AliITSsegmentation::Copy(obj);
70   ((AliITSsegmentationSSD& ) obj).Clear();
71   ((AliITSsegmentationSSD& ) obj).fNstrips = fNstrips;
72   ((AliITSsegmentationSSD& ) obj).fStereoP = fStereoP;
73   ((AliITSsegmentationSSD& ) obj).fStereoN = fStereoN;
74   ((AliITSsegmentationSSD& ) obj).fStereoPl5 = fStereoPl5;
75   ((AliITSsegmentationSSD& ) obj).fStereoNl5 = fStereoNl5;
76   ((AliITSsegmentationSSD& ) obj).fStereoPl6 = fStereoPl6;
77   ((AliITSsegmentationSSD& ) obj).fStereoNl6 = fStereoNl6;
78   ((AliITSsegmentationSSD& ) obj).fLayer   = fLayer;
79   ((AliITSsegmentationSSD& ) obj).fPitch   = fPitch;
80   ((AliITSsegmentationSSD& ) obj).fLayer   = fLayer;
81  
82 }
83
84 //______________________________________________________________________
85 AliITSsegmentationSSD& AliITSsegmentationSSD::operator=(
86                         const AliITSsegmentationSSD &source){
87 // Operator =
88   if(this != &source){
89     source.Copy(*this);
90   }
91   return *this;
92 }
93 //______________________________________________________________________
94 AliITSsegmentationSSD::AliITSsegmentationSSD(const AliITSsegmentationSSD &source):
95     AliITSsegmentation(source),
96 fNstrips(0),
97 fStereoP(0),
98 fStereoN(0),
99 fPitch(0),
100 fStereoPl5(0),
101 fStereoNl5(0),
102 fStereoPl6(0),
103 fStereoNl6(0),
104 fLayer(0){
105     // copy constructor
106   source.Copy(*this);
107 }
108 //----------------------------------------------------------------------
109 void AliITSsegmentationSSD::Init(){
110     // standard initalizer
111
112     SetPadSize(fgkPitchDefault,0.);
113     SetNPads(fgkNstripsDefault,0);
114     SetAngles();
115 }
116 //----------------------------------------------------------------------
117 void AliITSsegmentationSSD::Angles(Float_t &aP,Float_t &aN) const{
118   // P and N side stereo angles
119     if (fLayer == 5){
120         aP = fStereoPl5;
121         aN = fStereoNl5;
122     } // end if
123     if (fLayer == 6){
124         aP = fStereoPl6;
125         aN = fStereoNl6;
126     } // end if
127 }
128 //----------------------------------------------------------------------
129 void AliITSsegmentationSSD::SetLayer(Int_t l){
130   //set fLayer data member (only 5 or 6 are allowed)
131     if (l==5) fLayer =5;
132     if (l==6) fLayer =6;
133     if((l!=5) && (l!=6))AliError(Form("Layer can be 5 or 6, not %d",l));
134 }
135 //----------------------------------------------------------------------
136 void AliITSsegmentationSSD::GetPadTxz(Float_t &x,Float_t &z) const{
137     // returns P and N sided strip numbers for a given location.
138     // Transformation from microns detector center local coordinates
139     // to detector P and N side strip numbers..
140     /*                       _-  Z
141                     + angle /    ^
142         fNstrips           v     |   N-Side        ...0
143             \-------/------------|-----------\--------\
144             |\\\\\\/////////////.|\\\\\\\\\\\\\\\\\\\\|
145             |0\\\\/////////////..|.\\\\\\\\\\\\\\\\\\\|
146             |00\\/////////////...|..\\\\\\\\\\\\\\\\\\|
147        X <--|000/////////////... |...\\\\\\\\\\\\\\\\\|
148             |00/////////////...  | ...\\\\\\\\\\\\\\\\|
149             |0/////////////...   |  ...\\\\\\\\\\\\\\\|
150             |//////////////...   |  ...\\\\\\\\\\\\\\\|
151             /-----\--------------|--------------------/
152         fNstrips-1             P-Side              ...0
153                      |0\
154                      |00\
155         Dead region: |000/
156                      |00/
157                      |0/
158     // expects x, z in microns
159     */
160     Float_t stereoP, stereoN;
161     Angles(stereoP,stereoN);
162     Float_t tanP = TMath::Tan(stereoP);
163     Float_t tanN = TMath::Tan(-stereoN);
164     Float_t x1 = x;
165     Float_t z1 = z;
166     x1 += fDx/2;
167     z1 += fDz/2;
168     x   = (x1 - z1*tanP)/fPitch;
169     z   = (x1 - tanN*(z1 - fDz))/fPitch;
170 }
171 //----------------------------------------------------------------------
172 void AliITSsegmentationSSD::GetPadIxz(Float_t x,Float_t z,Int_t &iP,Int_t &iN) const {
173   // returns P and N sided strip numbers for a given location.
174     /*                       _-  Z
175                     + angle /    ^
176         fNstrips           v     |   N-Side        ...0
177             \-------/------------|-----------\--------\
178             |\\\\\\/////////////.|\\\\\\\\\\\\\\\\\\\\|
179             |0\\\\/////////////..|.\\\\\\\\\\\\\\\\\\\|
180             |00\\/////////////...|..\\\\\\\\\\\\\\\\\\|
181        X <--|000/////////////... |...\\\\\\\\\\\\\\\\\|
182             |00/////////////...  | ...\\\\\\\\\\\\\\\\|
183             |0/////////////...   |  ...\\\\\\\\\\\\\\\|
184             |//////////////...   |  ...\\\\\\\\\\\\\\\|
185             /-----\--------------|--------------------/
186         fNstrips-1             P-Side              ...0
187                      |0\
188                      |00\
189         Dead region: |000/
190                      |00/
191                      |0/
192
193     // expects x, z in microns
194   */ 
195
196     Float_t stereoP, stereoN;
197     Angles(stereoP,stereoN);
198     Float_t tanP=TMath::Tan(stereoP);
199     Float_t tanN=TMath::Tan(stereoN);
200     Float_t x1=x,z1=z;
201     x1 += fDx/2;
202     z1 += fDz/2;
203     Float_t  ldX = x1 - z1*tanP;          // distance from left-down edge 
204     iP = (Int_t)(ldX/fPitch);
205     iP = (iP<0)? -1: iP;      
206     iP = (iP>fNstrips)? -1: iP;
207
208     ldX = x1 - tanN*(fDz - z1);
209     iN = (Int_t)(ldX/fPitch);
210     iN = (iN<0)? -1: iN;
211     iN = (iN>fNstrips)? -1: iN;
212
213 }
214 //-------------------------------------------------------
215 void AliITSsegmentationSSD::GetPadCxz(Int_t iP,Int_t iN,Float_t &x,Float_t &z) const {
216     // actually this is the GetCrossing(Float_t &,Float_t &)
217     // returns local x, z  in microns !
218
219     Float_t lDx = fDx; // detector size in x direction, microns
220     Float_t lDz = fDz; // detector size in z direction, microns
221     Float_t xP; // x coordinate in the P side from the first P strip
222     Float_t xN; // x coordinate in the N side from the first N strip
223     Float_t stereoP, stereoN;
224     Angles(stereoP,stereoN);
225     Float_t kP=TMath::Tan(stereoP);
226     Float_t kN=TMath::Tan(stereoN);
227
228     xP=iP*fPitch;
229     xN=iN*fPitch; 
230     x = xP + kP*(lDz*kN-xP+xN)/(kP+kN);
231     z = (lDz*kN-xP+xN)/(kP+kN); 
232     x -= lDx/2;
233     z -= lDz/2;
234     //if(TMath::Abs(z) > Dz/2) cout<<"Warning, wrong z local ="<<z<<endl; 
235     // Check that zL is inside the detector for the 
236     // correspondent xP and xN coordinates
237
238     return;   
239 }
240 //______________________________________________________________________
241 Bool_t AliITSsegmentationSSD::LocalToDet(Float_t x,Float_t z,
242                                        Int_t &iP,Int_t &iN) const {
243     // Transformation from Geant cm detector center local coordinates
244     // to detector P and N side strip numbers..
245     /*                       _-  Z
246                     + angle /    ^
247         fNstrips           v     |   N-Side        ...0
248             \-------/------------|-----------\--------\
249             |\\\\\\/////////////.|\\\\\\\\\\\\\\\\\\\\|
250             |0\\\\/////////////..|.\\\\\\\\\\\\\\\\\\\|
251             |00\\/////////////...|..\\\\\\\\\\\\\\\\\\|
252        X <--|000/////////////... |...\\\\\\\\\\\\\\\\\|
253             |00/////////////...  | ...\\\\\\\\\\\\\\\\|
254             |0/////////////...   |  ...\\\\\\\\\\\\\\\|
255             |//////////////...   |  ...\\\\\\\\\\\\\\\|
256             /-----\--------------|--------------------/
257         fNstrips-1             P-Side              ...0
258                      |0\
259                      |00\
260         Dead region: |000/
261                      |00/
262                      |0/
263     */
264     const Double_t kconst = 1.0E-04; // convert microns to cm.
265
266     x /= kconst;  // convert to microns
267     z /= kconst;  // convert to microns
268     this->GetPadTxz(x,z);
269
270     // first for P side
271     iP = (Int_t) x;
272     if(iP<0 || iP>=fNstrips) iP=-1; // strip number must be in range.
273     // Now for N side)
274     iN = (Int_t) z;
275     if(iN<0 || iN>=fNstrips) iN=-1; // strip number must be in range.
276     return kTRUE;
277 }
278 //----------------------------------------------------------------------
279 void AliITSsegmentationSSD::DetToLocal(Int_t ix,Int_t iPN,
280                                        Float_t &x,Float_t &z) const{
281     // Transformation from detector segmentation/cell coordiantes starting
282     // from 0. iPN=0 for P side and 1 for N side strip. Returned is z=0.0
283     // and the corresponding x value..
284     /*                       _-  Z
285                     + angle /    ^
286         fNstrips           v     |   N-Side        ...0
287             \-------/------------|-----------\--------\
288             |\\\\\\/////////////.|\\\\\\\\\\\\\\\\\\\\|
289             |0\\\\/////////////..|.\\\\\\\\\\\\\\\\\\\|
290             |00\\/////////////...|..\\\\\\\\\\\\\\\\\\|
291        X <--|000/////////////... |...\\\\\\\\\\\\\\\\\|
292             |00/////////////...  | ...\\\\\\\\\\\\\\\\|
293             |0/////////////...   |  ...\\\\\\\\\\\\\\\|
294             |//////////////...   |  ...\\\\\\\\\\\\\\\|
295             /-----\--------------|--------------------/
296         fNstrips-1             P-Side              ...0
297                      |0\
298                      |00\
299         Dead region: |000/
300                      |00/
301                      |0/
302     */
303     // for strips p-side
304     // x = a + b + z*tan(fStereoP); a = Dpx(iP)*(iP+0.5)-dx; b = dz*th;
305     // for strips n-side
306     // x = a + b + z*tan(fStereoP); a = Dpx(iN)*(iN+0.5)-dx; b = -dz*th;
307     const Double_t kconst = 1.0E-04; // convert microns to cm.
308     Float_t flag=kconst*Dx(); // error value
309     Double_t th=0.0,dx,dz,i,a,b=0.0,xb[4],zb[4];
310     Float_t stereoP, stereoN;
311     Angles(stereoP,stereoN);
312
313     z = 0.0;  // Strip center in z.
314     if(iPN<0 || iPN>1){// if error return full detector size in x.
315         x = z = flag; 
316         return;
317     } // end if
318     if(ix<0 || ix>=fNstrips) { // if error return full detector size in x.
319         x = z = flag;
320         return;
321     } // end if
322     i  = (Double_t) ix;      // convert to double
323     dx = 0.5*kconst*Dx();    // half distance in x in cm
324     dz = 0.5*kconst*Dz();    // half distance in z in cm
325     a  = kconst*Dpx(ix)*(i+0.5)-dx; // Min x value.
326     if(iPN==0){ //P-side angle defined backwards.
327         th = TMath::Tan(stereoP); 
328         b  = dz*th;
329     }else if(iPN==1){ // N-side
330          th = TMath::Tan(-stereoN);
331          b  = -dz*th;
332     } // end if
333     // compute average/center position of the strip.
334     xb[0] = +dx; if(th!=0.0) zb[0] = (+dx-a-b)/th; else zb[0] = 0.0;
335     xb[1] = -dx; if(th!=0.0) zb[1] = (-dx-a-b)/th; else zb[1] = 0.0;
336     xb[2] = a+b+dz*th; zb[2] = +dz;
337     xb[3] = a+b-dz*th; zb[3] = -dz;
338     x = 0.0; z = 0.0;
339     for(Int_t j=0;j<4;j++){
340         if(xb[j]>=-dx && xb[j]<=dx && zb[j]>=-dz && zb[j]<=dz){
341             x += xb[j];
342             z += zb[j];
343         } // end if
344     } // end for
345     x *= 0.5;
346     z *= 0.5;
347     return;
348 }
349 //----------------------------------------------------------------------
350 Bool_t AliITSsegmentationSSD::GetCrossing(Int_t iP,Int_t iN,
351                                           Float_t &x,Float_t &z,
352                                           Float_t c[2][2]){
353     // Given one P side strip and one N side strip, Returns kTRUE if they
354     // cross each other and the location of the two crossing strips and
355     // their correxlation matrix c[2][2].
356     /*                       _-  Z
357                     + angle /    ^
358         fNstrips           v     |   N-Side        ...0
359             \-------/------------|-----------\--------\
360             |\\\\\\/////////////.|\\\\\\\\\\\\\\\\\\\\|
361             |0\\\\/////////////..|.\\\\\\\\\\\\\\\\\\\|
362             |00\\/////////////...|..\\\\\\\\\\\\\\\\\\|
363        X <--|000/////////////... |...\\\\\\\\\\\\\\\\\|
364             |00/////////////...  | ...\\\\\\\\\\\\\\\\|
365             |0/////////////...   |  ...\\\\\\\\\\\\\\\|
366             |//////////////...   |  ...\\\\\\\\\\\\\\\|
367             /-----\--------------|--------------------/
368         fNstrips-1             P-Side              ...0
369                      |0\
370                      |00\
371         Dead region: |000/
372                      |00/
373                      |0/
374        c[2][2] is defined as follows
375        /c[0][0]  c[0][1]\ /delta iP\ = /delta x\
376        \c[1][0]  c[1][1]/ \delta iN/ = \delta z/
377     */
378     const Double_t kconst = 1.0E-04; // convert microns to cm.
379     Double_t thp,thn,th,dx,dz,p,ip,in;
380     Float_t stereoP, stereoN;
381     Angles(stereoP,stereoN);
382     
383     thp = TMath::Tan(stereoP);
384     thn = TMath::Tan(-stereoN);
385     th  = thp-thn;
386     if(th==0.0) { // parall strips then never cross.
387         x = 0.0;
388         z = 0.0;
389         c[0][0] = c[1][0] = c[0][1] = c[1][1] = 0.0;
390         return kFALSE;
391     } // end if
392     // The strips must cross some place in space.
393     ip = (Double_t) iP;       // convert to double now for speed
394     in = (Double_t) iN;       // convert to double now for speed
395     dx = 0.5*kconst*Dx();     // half distance in x in cm
396     dz = 0.5*kconst*Dz();     // half distance in z in cm
397     p  = kconst*Dpx(iP);      // Get strip spacing/pitch now
398     x  = 0.5*p+dx + (p*(in*thp-ip*thn)-2.0*dz*thp*thn)/th;
399     z  =(p*(in-ip)-dz*(thp+thn))/th;
400     // compute correlations.
401     c[0][0] = -thn*p/th; // dx/diP
402     c[1][1] = p/th;      // dz/diN
403     c[0][1] = p*thp/th;  // dx/diN
404     c[1][0] = -p/th;     // dz/diP
405     if(x<-dx || x>dx || z<-dz || z>dz) return kFALSE; // crossing is outside
406                                                       // of the detector so
407                                                       // these strips don't
408                                                       // cross.
409     return kTRUE;
410 }
411
412 //----------------------------------------------------------------------
413 void AliITSsegmentationSSD::PrintDefaultParameters() const {
414 // Print default values for parameters. 
415 // Values specified as static const data members are shown
416
417   cout<<"fgkDxDefault = "<<fgkDxDefault<<endl;
418   cout<<"fgkDzDefault = "<<fgkDzDefault<<endl;
419   cout<<"fgkDyDefault = "<<fgkDyDefault<<endl;
420   cout<<"fgkPitchDefault = "<<fgkPitchDefault<<endl;
421   cout<<"fgkNstripsDefault = "<<fgkNstripsDefault<<endl;
422 }