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