]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSsegmentationSSD.cxx
macro to be updated for newIO
[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 <TMath.h>
19 #include <TF1.h>
20 #include <Riostream.h>
21 #include "AliITSsegmentationSSD.h"
22 #include "AliITSgeom.h"
23 #include "AliRun.h"
24 #include "AliModule.h"
25
26 ClassImp(AliITSsegmentationSSD)
27 AliITSsegmentationSSD::AliITSsegmentationSSD(){
28     // default constructor
29     fGeom  = 0;
30     fCorr  = 0;
31     fLayer = 0;
32 }
33 //----------------------------------------------------------------------
34 AliITSsegmentationSSD::AliITSsegmentationSSD(AliITSgeom *geom){
35     // constuctor
36     fGeom = geom;
37     fCorr = 0;
38     SetDetSize();
39     SetPadSize();
40     SetNPads();
41     SetAngles();
42     fLayer = 0;
43 }
44 //______________________________________________________________________
45 AliITSsegmentationSSD& AliITSsegmentationSSD::operator=(
46                                              AliITSsegmentationSSD &source){
47 // Operator =
48     if(this==&source) return *this;
49     this->fNstrips = source.fNstrips;
50     this->fStereoP = source.fStereoP;
51     this->fStereoN = source.fStereoN;
52     this->fStereoPl5 = source.fStereoPl5;
53     this->fStereoNl5 = source.fStereoNl5;
54     this->fStereoPl6 = source.fStereoPl6;
55     this->fStereoNl6 = source.fStereoNl6;
56     this->fLayer   = source.fLayer;
57     this->fPitch   = source.fPitch;
58     this->fDz      = source.fDz;
59     this->fDx      = source.fDx;
60     this->fDy      = source.fDy;
61     this->fLayer   = source.fLayer;
62     this->fGeom    = source.fGeom; // copy only the pointer
63     this->fCorr    = new TF1(*(source.fCorr)); // make a proper copy
64     return *this;     
65 }
66 //______________________________________________________________________
67 AliITSsegmentationSSD::AliITSsegmentationSSD(AliITSsegmentationSSD &source){
68     // copy constructor
69     *this = source;
70 }
71 //----------------------------------------------------------------------
72 void AliITSsegmentationSSD::Init(){
73     // standard initalizer
74
75     SetPadSize();
76     SetNPads();
77     SetAngles();
78 }
79 //----------------------------------------------------------------------
80 void AliITSsegmentationSSD::Angles(Float_t &aP,Float_t &aN){
81
82     if (fLayer == 5){
83         aP = fStereoPl5;
84         aN = fStereoNl5;
85     } // end if
86     if (fLayer == 6){
87         aP = fStereoPl6;
88         aN = fStereoNl6;
89     } // end if
90 }
91 //----------------------------------------------------------------------
92 void AliITSsegmentationSSD::SetLayer(Int_t l){
93
94     if (l==5) fLayer =5;
95     if (l==6) fLayer =6;
96 }
97 //----------------------------------------------------------------------
98 void AliITSsegmentationSSD::GetPadTxz(Float_t &x,Float_t &z){
99     // returns P and N sided strip numbers for a given location.
100     // Transformation from microns detector center local coordinates
101     // to detector P and N side strip numbers..
102     /*                       _-  Z
103                     + angle /    ^
104         fNstrips           v     |   N-Side        ...0
105             \-------/------------|-----------\--------\
106             |\\\\\\/////////////.|\\\\\\\\\\\\\\\\\\\\|
107             |0\\\\/////////////..|.\\\\\\\\\\\\\\\\\\\|
108             |00\\/////////////...|..\\\\\\\\\\\\\\\\\\|
109        X <--|000/////////////... |...\\\\\\\\\\\\\\\\\|
110             |00/////////////...  | ...\\\\\\\\\\\\\\\\|
111             |0/////////////...   |  ...\\\\\\\\\\\\\\\|
112             |//////////////...   |  ...\\\\\\\\\\\\\\\|
113             /-----\--------------|--------------------/
114         fNstrips-1             P-Side              ...0
115                      |0\
116                      |00\
117         Dead region: |000/
118                      |00/
119                      |0/
120     // expects x, z in microns
121     */
122     Float_t StereoP, StereoN;
123     Angles(StereoP,StereoN);
124     Float_t tanP = TMath::Tan(StereoP);
125     Float_t tanN = TMath::Tan(-StereoN);
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     Float_t StereoP, StereoN;
273     Angles(StereoP,StereoN);
274
275     z = 0.0;  // Strip center in z.
276     if(iPN<0 || iPN>1){// if error return full detector size in x.
277         x = z = flag; 
278         return;
279     } // end if
280     if(ix<0 || ix>=fNstrips) { // if error return full detector size in x.
281         x = z = flag;
282         return;
283     } // end if
284     i  = (Double_t) ix;      // convert to double
285     dx = 0.5*kconst*Dx();    // half distance in x in cm
286     dz = 0.5*kconst*Dz();    // half distance in z in cm
287     a  = kconst*Dpx(ix)*(i+0.5)-dx; // Min x value.
288     if(iPN==0){ //P-side angle defined backwards.
289         th = TMath::Tan(StereoP); 
290         b  = dz*th;
291     }else if(iPN==1){ // N-side
292          th = TMath::Tan(-StereoN);
293          b  = -dz*th;
294     } // end if
295     // compute average/center position of the strip.
296     xb[0] = +dx; if(th!=0.0) zb[0] = (+dx-a-b)/th; else zb[0] = 0.0;
297     xb[1] = -dx; if(th!=0.0) zb[1] = (-dx-a-b)/th; else zb[1] = 0.0;
298     xb[2] = a+b+dz*th; zb[2] = +dz;
299     xb[3] = a+b-dz*th; zb[3] = -dz;
300     x = 0.0; z = 0.0;
301     for(Int_t j=0;j<4;j++){
302         if(xb[j]>=-dx && xb[j]<=dx && zb[j]>=-dz && zb[j]<=dz){
303             x += xb[j];
304             z += zb[j];
305         } // end if
306     } // end for
307     x *= 0.5;
308     z *= 0.5;
309     return;
310 }
311 //----------------------------------------------------------------------
312 Bool_t AliITSsegmentationSSD::GetCrossing(Int_t iP,Int_t iN,
313                                           Float_t &x,Float_t &z,
314                                           Float_t c[2][2]){
315     // Given one P side strip and one N side strip, Returns kTRUE if they
316     // cross each other and the location of the two crossing strips and
317     // their correxlation matrix c[2][2].
318     /*                       _-  Z
319                     + angle /    ^
320         fNstrips           v     |   N-Side        ...0
321             \-------/------------|-----------\--------\
322             |\\\\\\/////////////.|\\\\\\\\\\\\\\\\\\\\|
323             |0\\\\/////////////..|.\\\\\\\\\\\\\\\\\\\|
324             |00\\/////////////...|..\\\\\\\\\\\\\\\\\\|
325        X <--|000/////////////... |...\\\\\\\\\\\\\\\\\|
326             |00/////////////...  | ...\\\\\\\\\\\\\\\\|
327             |0/////////////...   |  ...\\\\\\\\\\\\\\\|
328             |//////////////...   |  ...\\\\\\\\\\\\\\\|
329             /-----\--------------|--------------------/
330         fNstrips-1             P-Side              ...0
331                      |0\
332                      |00\
333         Dead region: |000/
334                      |00/
335                      |0/
336        c[2][2] is defined as follows
337        /c[0][0]  c[0][1]\ /delta iP\ = /delta x\
338        \c[1][0]  c[1][1]/ \delta iN/ = \delta z/
339     */
340     const Double_t kconst = 1.0E-04; // convert microns to cm.
341     Double_t thp,thn,th,dx,dz,p,ip,in;
342     Float_t StereoP, StereoN;
343     Angles(StereoP,StereoN);
344     
345     thp = TMath::Tan(StereoP);
346     thn = TMath::Tan(-StereoN);
347     th  = thp-thn;
348     if(th==0.0) { // parall strips then never cross.
349         x = 0.0;
350         z = 0.0;
351         c[0][0] = c[1][0] = c[0][1] = c[1][1] = 0.0;
352         return kFALSE;
353     } // end if
354     // The strips must cross some place in space.
355     ip = (Double_t) iP;       // convert to double now for speed
356     in = (Double_t) iN;       // convert to double now for speed
357     dx = 0.5*kconst*Dx();     // half distance in x in cm
358     dz = 0.5*kconst*Dz();     // half distance in z in cm
359     p  = kconst*Dpx(iP);      // Get strip spacing/pitch now
360     x  = 0.5*p+dx + (p*(in*thp-ip*thn)-2.0*dz*thp*thn)/th;
361     z  =(p*(in-ip)-dz*(thp+thn))/th;
362     // compute correlations.
363     c[0][0] = -thn*p/th; // dx/diP
364     c[1][1] = p/th;      // dz/diN
365     c[0][1] = p*thp/th;  // dx/diN
366     c[1][0] = -p/th;     // dz/diP
367     if(x<-dx || x>dx || z<-dz || z>dz) return kFALSE; // crossing is outside
368                                                       // of the detector so
369                                                       // these strips don't
370                                                       // cross.
371     return kTRUE;
372 }