]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSsegmentationSDD.cxx
3cf1f933fa13ccf08a1712386e22070154d58c4e
[u/mrichter/AliRoot.git] / ITS / AliITSsegmentationSDD.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 #include <iomanip.h>
16 #include <fstream.h>
17 #include <TF1.h>
18 #include <TMath.h>
19
20 #include "AliITSsegmentationSDD.h"
21 #include "AliITS.h"
22 #include "AliITSgeom.h"
23 #include "AliITSgeomSDD.h"
24 #include "AliRun.h"
25 #include "AliITSresponse.h"
26
27 ClassImp(AliITSsegmentationSDD)
28 //----------------------------------------------------------------------
29 AliITSsegmentationSDD::AliITSsegmentationSDD(AliITSgeom* geom,
30                                              AliITSresponse *resp){
31   // constructor
32    fGeom=geom;
33    fDriftSpeed=resp->DriftSpeed();
34    fCorr=0;
35    SetDetSize();
36    SetPadSize();
37    SetNPads();
38
39 }
40 //______________________________________________________________________
41 AliITSsegmentationSDD::AliITSsegmentationSDD(){
42   // standard constructor
43    fGeom=0;
44    fDriftSpeed=0;  
45    fCorr=0;
46    SetDetSize();
47    SetPadSize();
48    SetNPads();
49
50 }
51 //----------------------------------------------------------------------
52 void AliITSsegmentationSDD::Init(){
53   // Standard initilisation routine
54
55    if(!fGeom) {
56      return;
57      //fGeom = ((AliITS*)gAlice->GetModule("ITS"))->GetITSgeom();
58    }
59    AliITSgeomSDD *gsdd = (AliITSgeomSDD *) (fGeom->GetShape(3,1,1));
60
61    const Float_t kconv=10000.;
62    fDz = 2.*kconv*gsdd->GetDz();
63    fDx = kconv*gsdd->GetDx();
64    fDy = 2.*kconv*gsdd->GetDy();
65 }
66
67 //----------------------------------------------------------------------
68 void AliITSsegmentationSDD::
69 Neighbours(Int_t iX, Int_t iZ, Int_t* Nlist, Int_t Xlist[8], Int_t Zlist[8]){
70   // returns neighbours for use in Cluster Finder routines and the like
71
72     if(iX >= fNanodes) printf("iX > fNanodes %d %d\n",iX,fNanodes);
73     if(iZ >= fNsamples) printf("iZ > fNsamples %d %d\n",iZ,fNsamples);
74     *Nlist=4;
75     Xlist[0]=Xlist[1]=iX;
76     if(iX && (iX != fNanodes/2)) Xlist[2]=iX-1;
77     else Xlist[2]=iX;
78     if ((iX !=fNanodes/2 -1) && (iX != fNanodes)) Xlist[3]=iX+1;
79     else Xlist[3]=iX;
80     if(iZ) Zlist[0]=iZ-1;
81     else Zlist[0]=iZ;
82     if (iZ < fNsamples) Zlist[1]=iZ+1;
83     else Zlist[1]=iZ;
84     Zlist[2]=Zlist[3]=iZ;
85 }
86 //----------------------------------------------------------------------
87 void AliITSsegmentationSDD::GetPadIxz(Float_t x,Float_t z,
88                                       Int_t &timebin,Int_t &anode){
89 // Returns cell coordinates (time sample,anode) incremented by 1 !!!!! 
90 // for given real local coordinates (x,z)
91
92     // expects x, z in cm
93
94     const Float_t kconv=10000;  // cm->um
95
96     Int_t na = fNanodes/2;
97     Float_t driftpath=fDx-TMath::Abs(kconv*x);
98     timebin=(Int_t)(driftpath/fDriftSpeed/fTimeStep);
99     anode=(Int_t)(kconv*(z/fPitch + na/2));
100     if (x > 0) anode += na;
101
102     timebin+=1;
103     anode+=1;
104
105 }
106 //----------------------------------------------------------------------
107 void AliITSsegmentationSDD::GetPadCxz(Int_t timebin,Int_t anode,
108                                       Float_t &x ,Float_t &z){
109     // Transform from cell to real local coordinates
110     // returns x, z in cm
111
112   // the +0.5 means that an # and time bin # should start from 0 !!! 
113     const Float_t kconv=10000;  // um->cm
114   // the +0.5 means that an # and time bin # should start from 0 !!! 
115
116     Int_t na = fNanodes/2;
117     Float_t driftpath=(timebin+0.5)*fTimeStep*fDriftSpeed;
118     if (anode >= na) x=(fDx-driftpath)/kconv;
119     else x = -(fDx-driftpath)/kconv;
120     if (anode >= na) anode-=na;
121     z=((anode+0.5)*fPitch-fDz/2)/kconv;
122
123 }
124 //----------------------------------------------------------------------
125 void AliITSsegmentationSDD::GetPadTxz(Float_t &x,Float_t &z){
126     // Get anode and time bucket as floats - numbering from 0
127
128     // expects x, z in cm
129
130     const Float_t kconv=10000;  // cm->um
131
132     Float_t x0=x;
133     Int_t na = fNanodes/2;
134     Float_t driftpath=fDx-TMath::Abs(kconv*x);
135     x=driftpath/fDriftSpeed/fTimeStep;
136     z=kconv*z/fPitch + (float)na/2;
137     if (x0 < 0) x = -x;
138
139 }
140 //----------------------------------------------------------------------
141 void AliITSsegmentationSDD::GetLocal(Int_t module,Float_t *g ,Float_t *l){
142   // returns local coordinates from global
143     if(!fGeom) {
144         return;
145         //fGeom = ((AliITS*)gAlice->GetModule("ITS"))->GetITSgeom();
146     }
147     fGeom->GtoL(module,g,l);
148 }
149 //----------------------------------------------------------------------
150 void AliITSsegmentationSDD::GetGlobal(Int_t module,Float_t *l ,Float_t *g){
151   // return global coordinates from local
152     if(!fGeom) {
153         return;
154         //fGeom = ((AliITS*)gAlice->GetModule("ITS"))->GetITSgeom();
155     }
156
157     fGeom->LtoG(module,l,g);
158
159 }
160 //----------------------------------------------------------------------
161 void AliITSsegmentationSDD::Print(){
162   // Print SDD segmentation Parameters
163
164    cout << "**************************************************" << endl;
165    cout << "  Silicon Drift Detector Segmentation Parameters  " << endl;
166    cout << "**************************************************" << endl;
167    cout << "Number of Time Samples: " << fNsamples << endl;
168    cout << "Number of Anodes: " << fNanodes << endl;
169    cout << "Time Step (ns): " << fTimeStep << endl;
170    cout << "Anode Pitch (um): " << fPitch << endl;
171    cout << "Full Detector Width     (x): " << fDx << endl;
172    cout << "Half Detector Length    (z): " << fDz << endl;
173    cout << "Full Detector Thickness (y): " << fDy << endl;
174    cout << "**************************************************" << endl;
175
176 }
177 //______________________________________________________________________
178
179 //______________________________________________________________________
180 void AliITSsegmentationSDD::LocalToDet(Float_t x,Float_t z,Int_t &ix,Int_t &iz){
181 // Transformation from Geant detector centered local coordinates (cm) to
182 // time bucket numbers ix and anode number iz.
183 // Input:
184 // Float_t   x      detector local coordinate x in cm with respect to the
185 //                  center of the sensitive volume.
186 // Float_t   z      detector local coordinate z in cm with respect to the
187 //                  center of the sensitive volulme.
188 // Output:
189 // Int_t    ix      detector x time coordinate. Has the range 0<=ix<fNsamples.
190 // Int_t    iz      detector z anode coordinate. Has the range 0<=iz<fNandoes.
191 //   A value of -1 for ix or iz indecates that this point is outside of the
192 // detector segmentation as defined.
193 //     This segmentation geometry can be discribed as the following:
194 // {assumes 2*Dx()=7.0cm Dz()=7.5264cm, Dpx()=25ns,
195 //  res->DeriftSpeed()=7.3mic/ns, Dpz()=512. For other values a only the 
196 //  specific numbers will change not their layout.}
197 //
198 //        0                     191                    0
199 //      0 |----------------------|---------------------| 256
200 //        | a     time-bins      |     time-bins     a |
201 //        | n                    |                   n |
202 //        | o                    |___________________o_|__> X
203 //        | d                    |                   d |
204 //        | e                    |                   e |
205 //        | s                    |                   s |
206 //    255 |----------------------|---------------------| 511
207 //                               |
208 //                               V
209 //                               Z
210     Float_t dx,dz,tb;
211     const Float_t kconv = 1.0E-04; // converts microns to cm.
212
213     ix = -1; // default values
214     iz = -1; // default values
215     dx = -kconv*Dx(); // lower left edge in cm.
216     dz = -0.5*kconv*Dz(); // lower left edge in cm.
217     if(x<dx || x>-dx) return; // outside of defined volume.
218     if(z<dz || z>-dz) return; // outside of defined volume.
219     tb = fDriftSpeed*fTimeStep*kconv; // compute size of time bin.
220     if(x>0) dx = -(dx + x)/tb; // distance from + side in time bin units
221     else dx = (x - dx)/tb;     // distance from - side in time bin units
222     dz = (z - dz)/(kconv*fPitch); // distance in z in anode pitch units
223     ix = (Int_t) dx;   // time bin
224     iz = (Int_t) dz;   // anode
225     if(x>0) iz += Npz()/2; // if x>0 then + side anodes values.
226     return; // Found ix and iz, return.
227 }
228 //______________________________________________________________________
229 void AliITSsegmentationSDD::DetToLocal(Int_t ix,Int_t iz,Float_t &x,Float_t &z)
230 {
231 // Transformation from Detector time bucket and anode coordiantes to Geant 
232 // detector centerd local coordinates (cm).
233 // Input:
234 // Int_t    ix      detector x time coordinate. Has the range 0<=ix<fNsamples.
235 // Int_t    iz      detector z anode coordinate. Has the range 0<=iz<fNandoes.
236 // Output:
237 // Float_t   x      detector local coordinate x in cm with respect to the
238 //                  center of the sensitive volume.
239 // Float_t   z      detector local coordinate z in cm with respect to the
240 //                  center of the sensitive volulme.
241 // If ix and or iz is outside of the segmentation range a value of -Dx()
242 // or -0.5*Dz() is returned.
243 //     This segmentation geometry can be discribed as the following:
244 // {assumes 2*Dx()=7.0cm Dz()=7.5264cm, Dpx()=25ns,
245 //  res->DeriftSpeed()=7.3mic/ns, Dpz()=512. For other values a only the 
246 //  specific numbers will change not their layout.}
247 //
248 //        0                     191                    0
249 //      0 |----------------------|---------------------| 256
250 //        | a     time-bins      |     time-bins     a |
251 //        | n                    |                   n |
252 //        | o                    |___________________o_|__> X
253 //        | d                    |                   d |
254 //        | e                    |                   e |
255 //        | s                    |                   s |
256 //    255 |----------------------|---------------------| 511
257 //                               |
258 //                               V
259 //                               Z
260     Int_t i,j;
261     Float_t tb;
262     const Float_t kconv = 1.0E-04; // converts microns to cm.
263
264     if(iz>=Npz()/2) x = kconv*Dx(); // default value for +x side.
265     else x = -kconv*Dx(); // default value for -x side.
266     z = -0.5*kconv*Dz(); // default value.
267     if(ix<0 || ix>=Npx()) return; // outside of detector
268     if(iz<0 || iz>=Npz()) return; // outside of detctor
269     tb = fDriftSpeed*fTimeStep*kconv; // compute size of time bin.
270     if(iz>=Npz()/2) tb *= -1.0; // for +x side decrement frmo Dx().
271     for(i=0;i<ix;i++) x += tb; // sum up to cell ix-1
272     x += 0.5*tb; // add 1/2 of cell ix for center location.
273     if(iz>=Npz()/2) iz -=Npz()/2;// If +x side don't count anodes from -x side.
274     for(j=0;j<iz;j++) z += kconv*fPitch; // sum up cell iz-1
275     z += 0.5*kconv*fPitch; // add 1/2 of cell iz for center location.
276     return; // Found x and z, return.
277 }