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