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