]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSsegmentationSDD.cxx
Memory leak corrected (Ch. Klein-Boesing)
[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 <Riostream.h>
16 #include <TMath.h>
17
18 #include "AliITSsegmentationSDD.h"
19 // #include "AliITS.h"
20 #include "AliITSgeom.h"
21 #include "AliITSgeomSDD.h"
22 #include "AliITSCalibration.h"
23 #include "AliITSCalibrationSDD.h"
24 #include "AliITSresponseSDD.h"
25 //////////////////////////////////////////////////////
26 // Segmentation class for                           //
27 // drift detectors                                  //
28 //                                                  //
29 //////////////////////////////////////////////////////
30
31 const Float_t AliITSsegmentationSDD::fgkDxDefault = 35085.;
32 const Float_t AliITSsegmentationSDD::fgkDzDefault = 75264.;
33 const Float_t AliITSsegmentationSDD::fgkDyDefault = 300.;
34 const Float_t AliITSsegmentationSDD::fgkPitchDefault = 294.;
35 const Float_t AliITSsegmentationSDD::fgkClockDefault = 40.;
36 const Int_t AliITSsegmentationSDD::fgkHalfNanodesDefault = 256; 
37 const Int_t AliITSsegmentationSDD::fgkNsamplesDefault = 256;
38
39 ClassImp(AliITSsegmentationSDD)
40 //----------------------------------------------------------------------
41 AliITSsegmentationSDD::AliITSsegmentationSDD(AliITSgeom* geom,
42                                              AliITSCalibration *resp):
43 fNsamples(0),
44 fNanodes(0),
45 fPitch(0),
46 fTimeStep(0),
47 fDriftSpeed(0){
48   // constructor
49    fGeom=geom;
50    AliITSCalibrationSDD* sp = (AliITSCalibrationSDD*)resp;
51    fDriftSpeed=sp->GetDriftSpeed();
52    fCorr=0;
53    SetDetSize(fgkDxDefault,fgkDzDefault,fgkDyDefault);
54    SetPadSize(fgkPitchDefault,fgkClockDefault);
55    SetNPads(fgkHalfNanodesDefault,fgkNsamplesDefault);
56
57 }
58 //______________________________________________________________________
59 AliITSsegmentationSDD::AliITSsegmentationSDD() : AliITSsegmentation(),
60 fNsamples(0),
61 fNanodes(0),
62 fPitch(0),
63 fTimeStep(0),
64 fDriftSpeed(0){
65   // Default constructor
66    fDriftSpeed=0;  
67    SetDetSize(fgkDxDefault,fgkDzDefault,fgkDyDefault);
68    SetPadSize(fgkPitchDefault,fgkClockDefault);
69    SetNPads(fgkHalfNanodesDefault,fgkNsamplesDefault);
70
71 }
72
73 //______________________________________________________________________
74 void AliITSsegmentationSDD::Copy(TObject &obj) const {
75   // protected method. copy this to obj
76   AliITSsegmentation::Copy(obj);
77   ((AliITSsegmentationSDD& ) obj).fNsamples = fNsamples;
78   ((AliITSsegmentationSDD& ) obj).fNanodes = fNanodes;
79   ((AliITSsegmentationSDD& ) obj).fPitch = fPitch;
80   ((AliITSsegmentationSDD& ) obj).fTimeStep = fTimeStep;
81   ((AliITSsegmentationSDD& ) obj).fDriftSpeed = fDriftSpeed;
82 }
83
84 //______________________________________________________________________
85 AliITSsegmentationSDD& AliITSsegmentationSDD::operator=(const AliITSsegmentationSDD &source){
86    // = operator
87    if(this==&source) return *this;
88    source.Copy(*this);
89    return *this;
90 }
91
92 //____________________________________________________________________________
93 AliITSsegmentationSDD::AliITSsegmentationSDD(const AliITSsegmentationSDD &source) :
94     AliITSsegmentation(source),
95 fNsamples(0),
96 fNanodes(0),
97 fPitch(0),
98 fTimeStep(0),
99 fDriftSpeed(0){
100   // copy constructor
101   source.Copy(*this);
102 }
103
104 //----------------------------------------------------------------------
105 void AliITSsegmentationSDD::Init(){
106   // Standard initilisation routine
107
108    if(!fGeom) {
109      Fatal("Init","the pointer to the ITS geometry class (AliITSgeom) is null\n");
110      return;
111    }
112    AliITSgeomSDD *gsdd = (AliITSgeomSDD *) (fGeom->GetShape(3,1,1));
113
114    const Float_t kconv=10000.;
115    fDz = 2.*kconv*gsdd->GetDz();
116    fDx = kconv*gsdd->GetDx();
117    fDy = 2.*kconv*gsdd->GetDy();
118 }
119
120 //----------------------------------------------------------------------
121 void AliITSsegmentationSDD::
122 Neighbours(Int_t iX, Int_t iZ, Int_t* Nlist, Int_t Xlist[8], Int_t Zlist[8]) const {
123   // returns neighbours for use in Cluster Finder routines and the like
124
125     if(iX >= fNanodes) printf("iX > fNanodes %d %d\n",iX,fNanodes);
126     if(iZ >= fNsamples) printf("iZ > fNsamples %d %d\n",iZ,fNsamples);
127     *Nlist=4;
128     Xlist[0]=Xlist[1]=iX;
129     if(iX && (iX != fNanodes/2)) Xlist[2]=iX-1;
130     else Xlist[2]=iX;
131     if ((iX !=fNanodes/2 -1) && (iX != fNanodes)) Xlist[3]=iX+1;
132     else Xlist[3]=iX;
133     if(iZ) Zlist[0]=iZ-1;
134     else Zlist[0]=iZ;
135     if (iZ < fNsamples) Zlist[1]=iZ+1;
136     else Zlist[1]=iZ;
137     Zlist[2]=Zlist[3]=iZ;
138 }
139 //----------------------------------------------------------------------
140 void AliITSsegmentationSDD::GetPadIxz(Float_t x,Float_t z,
141                                       Int_t &timebin,Int_t &anode) const {
142 // Returns cell coordinates (time sample,anode) incremented by 1 !!!!! 
143 // for given real local coordinates (x,z)
144
145     // expects x, z in cm
146
147     const Float_t kconv=10000;  // cm->um
148
149     x *= kconv; // Convert to microns
150     z *= kconv; // Convert to microns
151     Int_t na = fNanodes/2;
152     Float_t driftpath=fDx-TMath::Abs(x);
153     timebin=(Int_t)(driftpath/fDriftSpeed/fTimeStep);
154     anode=(Int_t)(z/fPitch + na/2);
155     if (x > 0) anode += na;
156
157     timebin+=1;
158     anode+=1;
159
160 }
161 //----------------------------------------------------------------------
162 void AliITSsegmentationSDD::GetPadCxz(Int_t timebin,Int_t anode,
163                                       Float_t &x ,Float_t &z) const{
164     // Transform from cell to real local coordinates
165     // returns x, z in cm
166
167   // the +0.5 means that an # and time bin # should start from 0 !!! 
168     const Float_t kconv=10000;  // um->cm
169   // the +0.5 means that an # and time bin # should start from 0 !!! 
170
171     Int_t na = fNanodes/2;
172     Float_t driftpath=(timebin+0.5)*fTimeStep*fDriftSpeed;
173     if (anode >= na) x=(fDx-driftpath)/kconv;
174     else x = -(fDx-driftpath)/kconv;
175     if (anode >= na) anode-=na;
176     z=((anode+0.5)*fPitch-fDz/2)/kconv;
177
178 }
179 //----------------------------------------------------------------------
180 void AliITSsegmentationSDD::GetPadTxz(Float_t &x,Float_t &z) const{
181     // Get anode and time bucket as floats - numbering from 0
182
183     // expects x, z in cm
184
185     const Float_t kconv=10000;  // cm->um
186
187     Float_t x0=x;
188     Int_t na = fNanodes/2;
189     Float_t driftpath=fDx-TMath::Abs(kconv*x);
190     x=driftpath/fDriftSpeed/fTimeStep;
191     z=kconv*z/fPitch + (float)na/2;
192     if (x0 < 0) x = -x;
193
194 }
195 //----------------------------------------------------------------------
196 void AliITSsegmentationSDD::GetLocal(Int_t module,Float_t *g ,Float_t *l) const {
197   // returns local coordinates from global
198     if(!fGeom) {
199       Fatal("GetLocal","the pointer to the ITS geometry class (AliITSgeom) is null\n");
200         return;
201     }
202     fGeom->GtoL(module,g,l);
203 }
204 //----------------------------------------------------------------------
205 void AliITSsegmentationSDD::GetGlobal(Int_t module,Float_t *l ,Float_t *g) const {
206   // return global coordinates from local
207     if(!fGeom) {
208       Fatal("GetGlobal","the pointer to the ITS geometry class (AliITSgeom) is null\n");
209     }
210
211     fGeom->LtoG(module,l,g);
212
213 }
214 //----------------------------------------------------------------------
215 void AliITSsegmentationSDD::Print(Option_t *opt) const {
216   // Print SDD segmentation Parameters
217
218    cout << "**************************************************" << endl;
219    cout << "  Silicon Drift Detector Segmentation Parameters  " << opt << endl;
220    cout << "**************************************************" << endl;
221    cout << "Number of Time Samples: " << fNsamples << endl;
222    cout << "Number of Anodes: " << fNanodes << endl;
223    cout << "Time Step (ns): " << fTimeStep << endl;
224    cout << "Anode Pitch (um): " << fPitch << endl;
225    cout << "Full Detector Width     (x): " << fDx;
226    cout<<" (Default is "<<fgkDxDefault<<") "<<endl;
227    cout << "Half Detector Length    (z): " << fDz;
228    cout<<" (Default is "<<fgkDzDefault<<") "<<endl;
229    cout << "Full Detector Thickness (y): " << fDy;
230    cout<<" (Default is "<<fgkDyDefault<<") "<<endl;
231    cout << "**************************************************" << endl;
232
233 }
234
235 //----------------------------------------------------------------------
236 void AliITSsegmentationSDD::PrintDefaultParameters() const {
237   // print SDD parameters defined as static const data members
238
239   cout << "**************************************************" << endl;
240   cout << "  Silicon Drift Detector Segmentation Parameters  " << endl;
241   cout << " Default values defined as static const data members"<< endl;
242   cout << " Actual values can be set with the relevant setters"<< endl; 
243   cout << "**************************************************" << endl;
244   cout<<"fgkDxDefault = "<<fgkDxDefault<<endl;
245   cout<<"fgkDzDefault = "<<fgkDzDefault<<endl;
246   cout<<"fgkDyDefault = "<<fgkDyDefault<<endl;
247   cout<<"fgkPitchDefault = "<<fgkPitchDefault<<endl;
248   cout<<"fgkClockDefault = "<<fgkClockDefault<<endl;
249   cout<<"fgkHalfNanodesDefault = "<<fgkHalfNanodesDefault<<endl;
250   cout<<"fgkNsamplesDefault = "<<fgkNsamplesDefault<<endl;
251   cout << "**************************************************" << endl;
252
253 }
254
255 //______________________________________________________________________
256 Bool_t AliITSsegmentationSDD::LocalToDet(Float_t x,Float_t z,
257                                          Int_t &ix,Int_t &iz) const {
258 // Transformation from Geant detector centered local coordinates (cm) to
259 // time bucket numbers ix and anode number iz.
260 // Input:
261 // Float_t   x      detector local coordinate x in cm with respect to the
262 //                  center of the sensitive volume.
263 // Float_t   z      detector local coordinate z in cm with respect to the
264 //                  center of the sensitive volulme.
265 // Output:
266 // Int_t    ix      detector x time coordinate. Has the range 0<=ix<fNsamples.
267 // Int_t    iz      detector z anode coordinate. Has the range 0<=iz<fNandoes.
268 //   A value of -1 for ix or iz indecates that this point is outside of the
269 // detector segmentation as defined.
270 //     This segmentation geometry can be discribed as the following:
271 // {assumes 2*Dx()=7.0cm Dz()=7.5264cm, Dpx()=25ns,
272 //  res->DeriftSpeed()=7.3mic/ns, Dpz()=512. For other values a only the 
273 //  specific numbers will change not their layout.}
274 //
275 //        0                     191                    0
276 //      0 |----------------------|---------------------| 256
277 //        | a     time-bins      |     time-bins     a |
278 //        | n                    |                   n |
279 //        | o                    |___________________o_|__> X
280 //        | d                    |                   d |
281 //        | e                    |                   e |
282 //        | s                    |                   s |
283 //    255 |----------------------|---------------------| 511
284 //                               |
285 //                               V
286 //                               Z
287     Float_t dx,dz,tb;
288     const Float_t kconv = 1.0E-04; // converts microns to cm.
289
290     ix = -1; // default values
291     iz = -1; // default values
292     dx = -kconv*Dx(); // lower left edge in cm.
293     dz = -0.5*kconv*Dz(); // lower left edge in cm.
294     if(x<dx || x>-dx) {
295       Warning("LocalToDet","input argument %f out of range (%f, %f)",x,dx,-dx);
296       return kFALSE; // outside of defined volume.
297     }
298     if(z<dz || z>-dz) {
299       Warning("LocalToDet","input argument %f out of range (%f, %f)",z,dz,-dz);
300       return kFALSE; // outside of defined volume.
301     }
302     tb = fDriftSpeed*fTimeStep*kconv; // compute size of time bin.
303     if(x>0) dx = -(dx + x)/tb; // distance from + side in time bin units
304     else dx = (x - dx)/tb;     // distance from - side in time bin units
305     dz = (z - dz)/(kconv*fPitch); // distance in z in anode pitch units
306     ix = (Int_t) dx;   // time bin
307     iz = (Int_t) dz;   // anode
308     if(x>0) iz += Npz()/2; // if x>0 then + side anodes values.
309     return kTRUE; // Found ix and iz, return.
310 }
311 //______________________________________________________________________
312 void AliITSsegmentationSDD::DetToLocal(Int_t ix,Int_t iz,Float_t &x,Float_t &z) const
313 {
314 // Transformation from Detector time bucket and anode coordiantes to Geant 
315 // detector centerd local coordinates (cm).
316 // Input:
317 // Int_t    ix      detector x time coordinate. Has the range 0<=ix<fNsamples.
318 // Int_t    iz      detector z anode coordinate. Has the range 0<=iz<fNandoes.
319 // Output:
320 // Float_t   x      detector local coordinate x in cm with respect to the
321 //                  center of the sensitive volume.
322 // Float_t   z      detector local coordinate z in cm with respect to the
323 //                  center of the sensitive volulme.
324 // If ix and or iz is outside of the segmentation range a value of -Dx()
325 // or -0.5*Dz() is returned.
326 //     This segmentation geometry can be discribed as the following:
327 // {assumes 2*Dx()=7.0cm Dz()=7.5264cm, Dpx()=25ns,
328 //  res->DeriftSpeed()=7.3mic/ns, Dpz()=512. For other values a only the 
329 //  specific numbers will change not their layout.}
330 //
331 //        0                     191                    0
332 //      0 |----------------------|---------------------| 256
333 //        | a     time-bins      |     time-bins     a |
334 //        | n                    |                   n |
335 //        | o                    |___________________o_|__> X
336 //        | d                    |                   d |
337 //        | e                    |                   e |
338 //        | s                    |                   s |
339 //    255 |----------------------|---------------------| 511
340 //                               |
341 //                               V
342 //                               Z
343     Int_t i,j;
344     Float_t tb;
345     const Float_t kconv = 1.0E-04; // converts microns to cm.
346
347     if(iz>=Npz()/2) x = kconv*Dx(); // default value for +x side.
348     else x = -kconv*Dx(); // default value for -x side.
349     z = -0.5*kconv*Dz(); // default value.
350     if(ix<0 || ix>=Npx()) {
351       Warning("DetToLocal","input argument %d out of range (0, %d)",ix,Npx());
352       return; // outside of detector
353     }
354     if(iz<0 || iz>=Npz()) {
355       Warning("DetToLocal","input argument %d out of range (0, %d)",iz,Npz());
356      return; // outside of detctor
357     }
358     tb = fDriftSpeed*fTimeStep*kconv; // compute size of time bin.
359     if(iz>=Npz()/2) tb *= -1.0; // for +x side decrement frmo Dx().
360     for(i=0;i<ix;i++) x += tb; // sum up to cell ix-1
361     x += 0.5*tb; // add 1/2 of cell ix for center location.
362     if(iz>=Npz()/2) iz -=Npz()/2;// If +x side don't count anodes from -x side.
363     for(j=0;j<iz;j++) z += kconv*fPitch; // sum up cell iz-1
364     z += 0.5*kconv*fPitch; // add 1/2 of cell iz for center location.
365     return; // Found x and z, return.
366 }