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