]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSsegmentationSSD.cxx
Eff C++ warning removal (Marian)
[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
36 ClassImp(AliITSsegmentationSSD)
37 AliITSsegmentationSSD::AliITSsegmentationSSD(Option_t *opt): AliITSsegmentation(),
38 fNstrips(0),
39 fStereoP(0),
40 fStereoN(0),
41 fPitch(0),
42 fStereoPl5(0),
43 fStereoNl5(0),
44 fStereoPl6(0),
45 fStereoNl6(0),
46 fLayer(0){
47     // default constructor
48     SetDetSize(fgkDxDefault,fgkDzDefault,fgkDyDefault);
49     SetPadSize(fgkPitchDefault,0.);
50     SetNPads(fgkNstripsDefault,0);
51     SetAngles();
52   if(strstr(opt,"TGeo")){
53     if(!gGeoManager){
54       AliError("Geometry is not initialized\n");
55       return;
56     }
57     TGeoVolume *v=NULL;
58     v = gGeoManager->GetVolume("ITSssdSensitivL5");
59     if(!v){
60       AliWarning("TGeo volumeITSssdSensitivL5  not found (hint: use v11Hybrid geometry)\n Using hardwired default values"); 
61     }
62     else {
63       TGeoBBox *s=(TGeoBBox*)v->GetShape();
64       SetDetSize(s->GetDX()*20000.,s->GetDZ()*20000.,s->GetDY()*20000.);
65     }
66   }
67 }
68 //----------------------------------------------------------------------
69 AliITSsegmentationSSD::AliITSsegmentationSSD(AliITSgeom *geom):
70 AliITSsegmentation(geom),
71 fNstrips(0),
72 fStereoP(0),
73 fStereoN(0),
74 fPitch(0),
75 fStereoPl5(0),
76 fStereoNl5(0),
77 fStereoPl6(0),
78 fStereoNl6(0),
79 fLayer(0){
80     // constuctor
81     SetDetSize(fgkDxDefault,fgkDzDefault,fgkDyDefault);
82     SetPadSize(fgkPitchDefault,0.);
83     SetNPads(fgkNstripsDefault,0);
84     SetAngles();
85 }
86 //______________________________________________________________________
87 void AliITSsegmentationSSD::Copy(TObject &obj) const {
88   // protected method. copy this to obj
89   AliITSsegmentation::Copy(obj);
90   ((AliITSsegmentationSSD& ) obj).Clear();
91   ((AliITSsegmentationSSD& ) obj).fNstrips = fNstrips;
92   ((AliITSsegmentationSSD& ) obj).fStereoP = fStereoP;
93   ((AliITSsegmentationSSD& ) obj).fStereoN = fStereoN;
94   ((AliITSsegmentationSSD& ) obj).fStereoPl5 = fStereoPl5;
95   ((AliITSsegmentationSSD& ) obj).fStereoNl5 = fStereoNl5;
96   ((AliITSsegmentationSSD& ) obj).fStereoPl6 = fStereoPl6;
97   ((AliITSsegmentationSSD& ) obj).fStereoNl6 = fStereoNl6;
98   ((AliITSsegmentationSSD& ) obj).fLayer   = fLayer;
99   ((AliITSsegmentationSSD& ) obj).fPitch   = fPitch;
100   ((AliITSsegmentationSSD& ) obj).fLayer   = fLayer;
101  
102 }
103
104 //______________________________________________________________________
105 AliITSsegmentationSSD& AliITSsegmentationSSD::operator=(
106                         const AliITSsegmentationSSD &source){
107 // Operator =
108   if(this != &source){
109     source.Copy(*this);
110   }
111   return *this;
112 }
113 //______________________________________________________________________
114 AliITSsegmentationSSD::AliITSsegmentationSSD(const AliITSsegmentationSSD &source):
115     AliITSsegmentation(source),
116 fNstrips(0),
117 fStereoP(0),
118 fStereoN(0),
119 fPitch(0),
120 fStereoPl5(0),
121 fStereoNl5(0),
122 fStereoPl6(0),
123 fStereoNl6(0),
124 fLayer(0){
125     // copy constructor
126   source.Copy(*this);
127 }
128 //----------------------------------------------------------------------
129 void AliITSsegmentationSSD::Init(){
130     // standard initalizer
131
132     SetPadSize(fgkPitchDefault,0.);
133     SetNPads(fgkNstripsDefault,0);
134     SetAngles();
135 }
136 //----------------------------------------------------------------------
137 void AliITSsegmentationSSD::Angles(Float_t &aP,Float_t &aN) const{
138   // P and N side stereo angles
139     if (fLayer == 5){
140         aP = fStereoPl5;
141         aN = fStereoNl5;
142     } // end if
143     if (fLayer == 6){
144         aP = fStereoPl6;
145         aN = fStereoNl6;
146     } // end if
147 }
148 //----------------------------------------------------------------------
149 void AliITSsegmentationSSD::SetLayer(Int_t l){
150   //set fLayer data member (only 5 or 6 are allowed)
151     if (l==5) fLayer =5;
152     if (l==6) fLayer =6;
153     if((l!=5) && (l!=6))AliError(Form("Layer can be 5 or 6, not %d",l));
154 }
155 //----------------------------------------------------------------------
156 void AliITSsegmentationSSD::GetPadTxz(Float_t &x,Float_t &z) const{
157     // returns P and N sided strip numbers for a given location.
158     // Transformation from microns detector center local coordinates
159     // to detector P and N side strip numbers..
160     /*                       _-  Z
161                     + angle /    ^
162         fNstrips           v     |   N-Side        ...0
163             \-------/------------|-----------\--------\
164             |\\\\\\/////////////.|\\\\\\\\\\\\\\\\\\\\|
165             |0\\\\/////////////..|.\\\\\\\\\\\\\\\\\\\|
166             |00\\/////////////...|..\\\\\\\\\\\\\\\\\\|
167        X <--|000/////////////... |...\\\\\\\\\\\\\\\\\|
168             |00/////////////...  | ...\\\\\\\\\\\\\\\\|
169             |0/////////////...   |  ...\\\\\\\\\\\\\\\|
170             |//////////////...   |  ...\\\\\\\\\\\\\\\|
171             /-----\--------------|--------------------/
172         fNstrips-1             P-Side              ...0
173                      |0\
174                      |00\
175         Dead region: |000/
176                      |00/
177                      |0/
178     // expects x, z in microns
179     */
180     Float_t stereoP, stereoN;
181     Angles(stereoP,stereoN);
182     Float_t tanP = TMath::Tan(stereoP);
183     Float_t tanN = TMath::Tan(-stereoN);
184     Float_t x1 = x;
185     Float_t z1 = z;
186     x1 += fDx/2;
187     z1 += fDz/2;
188     x   = (x1 - z1*tanP)/fPitch;
189     z   = (x1 - tanN*(z1 - fDz))/fPitch;
190 }
191 //----------------------------------------------------------------------
192 void AliITSsegmentationSSD::GetPadIxz(Float_t x,Float_t z,Int_t &iP,Int_t &iN) const {
193   // returns P and N sided strip numbers for a given location.
194     /*                       _-  Z
195                     + angle /    ^
196         fNstrips           v     |   N-Side        ...0
197             \-------/------------|-----------\--------\
198             |\\\\\\/////////////.|\\\\\\\\\\\\\\\\\\\\|
199             |0\\\\/////////////..|.\\\\\\\\\\\\\\\\\\\|
200             |00\\/////////////...|..\\\\\\\\\\\\\\\\\\|
201        X <--|000/////////////... |...\\\\\\\\\\\\\\\\\|
202             |00/////////////...  | ...\\\\\\\\\\\\\\\\|
203             |0/////////////...   |  ...\\\\\\\\\\\\\\\|
204             |//////////////...   |  ...\\\\\\\\\\\\\\\|
205             /-----\--------------|--------------------/
206         fNstrips-1             P-Side              ...0
207                      |0\
208                      |00\
209         Dead region: |000/
210                      |00/
211                      |0/
212
213     // expects x, z in microns
214   */ 
215
216     Float_t stereoP, stereoN;
217     Angles(stereoP,stereoN);
218     Float_t tanP=TMath::Tan(stereoP);
219     Float_t tanN=TMath::Tan(stereoN);
220     Float_t x1=x,z1=z;
221     x1 += fDx/2;
222     z1 += fDz/2;
223     Float_t  ldX = x1 - z1*tanP;          // distance from left-down edge 
224     iP = (Int_t)(ldX/fPitch);
225     iP = (iP<0)? -1: iP;      
226     iP = (iP>fNstrips)? -1: iP;
227
228     ldX = x1 - tanN*(fDz - z1);
229     iN = (Int_t)(ldX/fPitch);
230     iN = (iN<0)? -1: iN;
231     iN = (iN>fNstrips)? -1: iN;
232
233 }
234 //-------------------------------------------------------
235 void AliITSsegmentationSSD::GetPadCxz(Int_t iP,Int_t iN,Float_t &x,Float_t &z) const {
236     // actually this is the GetCrossing(Float_t &,Float_t &)
237     // returns local x, z  in microns !
238
239     Float_t lDx = fDx; // detector size in x direction, microns
240     Float_t lDz = fDz; // detector size in z direction, microns
241     Float_t xP; // x coordinate in the P side from the first P strip
242     Float_t xN; // x coordinate in the N side from the first N strip
243     Float_t stereoP, stereoN;
244     Angles(stereoP,stereoN);
245     Float_t kP=TMath::Tan(stereoP);
246     Float_t kN=TMath::Tan(stereoN);
247
248     xP=iP*fPitch;
249     xN=iN*fPitch; 
250     x = xP + kP*(lDz*kN-xP+xN)/(kP+kN);
251     z = (lDz*kN-xP+xN)/(kP+kN); 
252     x -= lDx/2;
253     z -= lDz/2;
254     //if(TMath::Abs(z) > Dz/2) cout<<"Warning, wrong z local ="<<z<<endl; 
255     // Check that zL is inside the detector for the 
256     // correspondent xP and xN coordinates
257
258     return;   
259 }
260 //______________________________________________________________________
261 Bool_t AliITSsegmentationSSD::LocalToDet(Float_t x,Float_t z,
262                                        Int_t &iP,Int_t &iN) const {
263     // Transformation from Geant cm detector center local coordinates
264     // to detector P and N side strip numbers..
265     /*                       _-  Z
266                     + angle /    ^
267         fNstrips           v     |   N-Side        ...0
268             \-------/------------|-----------\--------\
269             |\\\\\\/////////////.|\\\\\\\\\\\\\\\\\\\\|
270             |0\\\\/////////////..|.\\\\\\\\\\\\\\\\\\\|
271             |00\\/////////////...|..\\\\\\\\\\\\\\\\\\|
272        X <--|000/////////////... |...\\\\\\\\\\\\\\\\\|
273             |00/////////////...  | ...\\\\\\\\\\\\\\\\|
274             |0/////////////...   |  ...\\\\\\\\\\\\\\\|
275             |//////////////...   |  ...\\\\\\\\\\\\\\\|
276             /-----\--------------|--------------------/
277         fNstrips-1             P-Side              ...0
278                      |0\
279                      |00\
280         Dead region: |000/
281                      |00/
282                      |0/
283     */
284     const Double_t kconst = 1.0E-04; // convert microns to cm.
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 void AliITSsegmentationSSD::PrintDefaultParameters() const {
434 // Print default values for parameters. 
435 // Values specified as static const data members are shown
436
437   cout<<"fgkDxDefault = "<<fgkDxDefault<<endl;
438   cout<<"fgkDzDefault = "<<fgkDzDefault<<endl;
439   cout<<"fgkDyDefault = "<<fgkDyDefault<<endl;
440   cout<<"fgkPitchDefault = "<<fgkPitchDefault<<endl;
441   cout<<"fgkNstripsDefault = "<<fgkNstripsDefault<<endl;
442 }