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