Line data Source code
1 : #ifndef ALIITSGEOM_H
2 : #define ALIITSGEOM_H
3 : /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 : * See cxx source for full Copyright notice */
5 :
6 : /* $Id$ */
7 :
8 : /////////////////////////////////////////////////////////////////////////
9 : // ITS geometry manipulation routines.
10 : // Created April 15 1999.
11 : // version: 0.0.0
12 : // By: Bjorn S. Nilsen
13 : //
14 : // A package of geometry routines to do transformations between
15 : // local, detector active area, and ALICE global coordinate system in such
16 : // a way as to allow for detector alignment studies and the like. All of
17 : // the information needed to do the coordinate transformation are kept in
18 : // a specialized structure for ease of implementation.
19 : /////////////////////////////////////////////////////////////////////////
20 : #include <TObject.h>
21 : #include <TObjArray.h>
22 : #include <TVector.h>
23 : #include <TString.h>
24 : #include <TArrayI.h>
25 : #include <TMath.h>
26 : //
27 : #include "AliITSgeomMatrix.h"
28 :
29 : typedef enum {kND=-1,kSPD=0, kSDD=1, kSSD=2, kSSDp=3,kSDDp=4, kUPG=5} AliITSDetector;
30 :
31 : //_______________________________________________________________________
32 :
33 : class AliITSgeom : public TObject {
34 :
35 : public:
36 : AliITSgeom(); // Default constructor
37 : AliITSgeom(Int_t itype,Int_t nlayers,const Int_t *nlads,const Int_t *ndets,
38 : Int_t nmods); // Constructor
39 : AliITSgeom(const AliITSgeom &source); // Copy constructor
40 : AliITSgeom& operator=(const AliITSgeom &source);// = operator
41 : virtual ~AliITSgeom(); // Default destructor
42 : // Zero and reinitilizes this class.
43 : void Init(Int_t itype,Int_t nlayers,const Int_t *nlads,
44 : const Int_t *ndets,Int_t mods);
45 : // this function allocates a AliITSgeomMatrix for a particular module.
46 : void CreateMatrix(Int_t mod,Int_t lay,Int_t lad,Int_t det,
47 : AliITSDetector idet,const Double_t tran[3],
48 : const Double_t rot[10]);
49 : // Getters
50 0 : Int_t GetTransformationType() const {return fTrans;}
51 : //
52 : // returns kTRUE if the transformation defined by this class is
53 : // for Global GEANT coordinate system to the local GEANT coordinate system
54 : // of the detector. These are the transformation used by GEANT.
55 0 : Bool_t IsGeantToGeant() const {return (fTrans == 0);}
56 : // returns kTRUE if the transformation defined by this class is
57 : // for Global GEANT coordinate system to the local "Tracking" coordinate
58 : // system of the detector. These are the transformation used by the
59 : // Tracking code.
60 0 : Bool_t IsGeantToTracking() const {return ((fTrans&0xfffe)!= 0);}
61 : // returns kTRUE if the transformation defined by this class is
62 : // for Global GEANT coordinate system to the local GEANT coordinate system
63 : // of the detector but may have been displaced by some typically small
64 : // amount. These are modified transformation similar to that used by GEANT.
65 0 : Bool_t IsGeantToDisplaced() const {return ((fTrans&0xfffd)!= 0);}
66 : //
67 : // This function returns a pointer to the particular AliITSgeomMatrix
68 : // class for a specific module index.
69 92316 : AliITSgeomMatrix *GetGeomMatrix(Int_t index){if(index<fGm.GetSize()&&index>=0)
70 46158 : return (AliITSgeomMatrix*)(fGm.At(index));else
71 46158 : Error("GetGeomMatrix","index=%d<0||>=GetSize()=%d",index,fGm.GetSize());return 0;}
72 74842 : AliITSgeomMatrix *GetGeomMatrix(Int_t index)const{if(index<fGm.GetSize()&&index>=0)
73 37421 : return (AliITSgeomMatrix*)(fGm.At(index));else
74 37421 : Error("GetGeomMatrix","index=%d<0||>=GetSize()=%d",index,fGm.GetSize());return 0;}
75 : // This function find and return the number of detector types only.
76 0 : Int_t GetNDetTypes()const{Int_t max;return GetNDetTypes(max);};
77 : // This function find and return the number of detector types and the
78 : // maximum det type value.
79 : Int_t GetNDetTypes(Int_t &max)const;
80 : // This function finds and return the number of detector types and the
81 : // and the number of each type in the TArrayI and their types.
82 : Int_t GetNDetTypes(TArrayI &maxs,AliITSDetector *types)const;
83 : // This function returns the number of detectors/ladder for a give
84 : // layer. In particular it returns fNdet[layer-1].
85 0 : Int_t GetNdetectors(Int_t lay) const {return fNdet[lay-1];}
86 : // This function returns the number of ladders for a give layer. In
87 : // particular it returns fNlad[layer-1].
88 0 : Int_t GetNladders(Int_t lay) const {return fNlad[lay-1];};
89 : // This function returns the number of layers defined in the ITS
90 : // geometry. In particular it returns fNlayers.
91 32 : Int_t GetNlayers() const {return fNlayers;}
92 : Int_t GetModuleIndex(Int_t lay,Int_t lad,Int_t det)const;
93 : // This function returns the module index number given the layer,
94 : // ladder and detector numbers put into the array id[3].
95 : Int_t GetModuleIndex(const Int_t *id)const{
96 0 : return GetModuleIndex(id[0],id[1],id[2]);}
97 : void GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det)const;
98 : // Returns the detector type
99 : //Int_t GetModuleType(Int_t index)const{
100 : // return GetGeomMatrix(index)->GetDetectorIndex();}
101 : AliITSDetector GetModuleType(Int_t index)const{
102 52752 : return (AliITSDetector)(GetGeomMatrix(index)->GetDetectorIndex());}
103 : // Returns the detector type as a string
104 : const char * GetModuleTypeName(Int_t index)const{
105 0 : return GetDetectorTypeName(GetModuleType(index));}
106 : // Returns the detector type as a string
107 0 : const char * GetDetectorTypeName(Int_t index)const{switch(index) {
108 0 : case kSPD : return "kSPD" ; case kSDD : return "kSDD" ;
109 0 : case kSSD : return "kSSD" ; case kSSDp: return "kSSDp";
110 0 : case kSDDp: return "kSDDp"; default : return "Undefined";};}
111 : //
112 : Int_t GetStartDet(Int_t dtype )const;
113 : Int_t GetLastDet(Int_t dtype)const;
114 : // Returns the starting module index number for SPD detector,
115 : // assuming the modules are placed in the "standard" cylindrical
116 : // ITS structure.
117 0 : Int_t GetStartSPD()const{return GetStartDet(kSPD);}
118 : // Returns the ending module index number for SPD detector,
119 : // assuming the modules are placed in the "standard" cylindrical
120 : // ITS structure.
121 0 : Int_t GetLastSPD()const{return GetLastDet(kSPD);}
122 : // Returns the starting module index number for SDD detector,
123 : // assuming the modules are placed in the "standard" cylindrical
124 : // ITS structure.
125 0 : Int_t GetStartSDD()const{return GetStartDet(kSDD);}
126 : // Returns the ending module index number for SDD detector,
127 : // assuming the modules are placed in the "standard" cylindrical
128 : // ITS structure.
129 0 : Int_t GetLastSDD()const{return GetLastDet(kSDD);}
130 : // Returns the starting module index number for SSD detector,
131 : // assuming the modules are placed in the "standard" cylindrical
132 : // ITS structure.
133 0 : Int_t GetStartSSD()const{return GetStartDet(kSSD);}
134 : // Returns the ending module index number for SSD detector,
135 : // assuming the modules are placed in the "standard" cylindrical
136 : // ITS structure.
137 0 : Int_t GetLastSSD()const{return GetLastDet(kSSD);}
138 : // Returns the last module index number.
139 52816 : Int_t GetIndexMax() const {return fNmodules;}
140 : //
141 : // This function returns the rotation angles for a give module
142 : // in the Double point array ang[3]. The angles are in radians
143 : void GetAngles(Int_t index,Double_t *ang)const{
144 0 : GetGeomMatrix(index)->GetAngles(ang);}
145 : // This function returns the rotation angles for a give module
146 : // in the three floating point variables provided. rx = frx,
147 : // fy = fry, rz = frz. The angles are in radians
148 : void GetAngles(Int_t index,Float_t &rx,Float_t &ry,Float_t &rz)const{
149 0 : Double_t a[3];GetAngles(index,a);rx = a[0];ry = a[1];rz = a[2];}
150 : // This function returns the rotation angles for a give detector on
151 : // a give ladder in a give layer in the three floating point variables
152 : // provided. rx = frx, fy = fry, rz = frz. The angles are in radians
153 : void GetAngles(Int_t lay,Int_t lad,Int_t det,
154 : Float_t &rx,Float_t &ry,Float_t &rz)const{
155 0 : GetAngles(GetModuleIndex(lay,lad,det),rx,ry,rz);}
156 : //
157 : // This function returns the 6 GEANT rotation angles for a give
158 : // module in the double point array ang[3]. The angles are in degrees
159 : void GetGeantAngles(Int_t index,Double_t *ang)const{
160 0 : GetGeomMatrix(index)->SixAnglesFromMatrix(ang);}
161 : //
162 : // This function returns the Cartesian translation for a give
163 : // module in the Double array t[3]. The units are
164 : // those of the Monte Carlo, generally cm.
165 : void GetTrans(Int_t index,Double_t *t)const{
166 0 : GetGeomMatrix(index)->GetTranslation(t);}
167 : // This function returns the Cartesian translation for a give
168 : // module index in the three floating point variables provided.
169 : // x = fx0, y = fy0, z = fz0. The units are those of the Mont
170 : // Carlo, generally cm.
171 : void GetTrans(Int_t index,Float_t &x,Float_t &y,Float_t &z)const{
172 0 : Double_t t[3];GetTrans(index,t);x = t[0];y = t[1];z = t[2];}
173 : // This function returns the Cartesian translation for a give
174 : // detector on a give ladder in a give layer in the three floating
175 : // point variables provided. x = fx0, y = fy0, z = fz0. The units are
176 : // those of the Monte Carlo, generally cm.
177 : void GetTrans(Int_t lay,Int_t lad,Int_t det,
178 : Float_t &x,Float_t &y,Float_t &z)const{
179 0 : GetTrans(GetModuleIndex(lay,lad,det),x,y,z);}
180 : //
181 : // This function returns the Cartesian translation for a give
182 : // module in the Double array t[3]. The units are
183 : // those of the Monte Carlo, generally cm.
184 : void GetTransCyln(Int_t index,Double_t *t)const{
185 0 : GetGeomMatrix(index)->GetTranslationCylinderical(t);}
186 : // This function returns the Cartesian translation for a give
187 : // module index in the three floating point variables provided.
188 : // x = fx0, y = fy0, z = fz0. The units are those of the Mont
189 : // Carlo, generally cm.
190 : void GetTransCyln(Int_t index,Float_t &x,Float_t &y,Float_t &z)const{
191 0 : Double_t t[3];GetTransCyln(index,t);x = t[0];y = t[1];z = t[2];}
192 : // This function returns the Cartesian translation for a give
193 : // detector on a give ladder in a give layer in the three floating
194 : // point variables provided. x = fx0, y = fy0, z = fz0. The units are
195 : // those of the Monte Carlo, generally cm.
196 : void GetTransCyln(Int_t lay,Int_t lad,Int_t det,
197 : Float_t &x,Float_t &y,Float_t &z)const{
198 0 : GetTransCyln(GetModuleIndex(lay,lad,det),x,y,z);}
199 : //
200 : // This function returns the Cartesian translation [cm] and the
201 : // 6 GEANT rotation angles [degrees]for a given layer ladder and
202 : // detector number, in the TVector x (at least 9 elements large).
203 : // This function is required to be in-lined for speed.
204 : void GetCenterThetaPhi(Int_t lay,Int_t lad,Int_t det,TVector &x)const{
205 0 : Double_t t[3],a[6];Int_t i=GetModuleIndex(lay,lad,det);GetTrans(i,t);
206 0 : GetGeantAngles(i,a);x(0)=t[0];x(1)=t[1];x(2)=t[2];x(3)=a[0];x(4)=a[1];
207 0 : x(5)=a[2];x(6)=a[3];x(7)=a[4];x(8)=a[5];}
208 : //
209 : // This function returns the rotation matrix in Double
210 : // precision for a given module.
211 : void GetRotMatrix(Int_t index,Double_t mat[3][3])const{
212 0 : GetGeomMatrix(index)->GetMatrix(mat);}
213 : // This function returns the rotation matrix in a Double
214 : // precision pointer for a given module. mat[i][j] => mat[3*i+j].
215 : void GetRotMatrix(Int_t index,Double_t *mat)const{
216 0 : Double_t rot[3][3];GetRotMatrix(index,rot);
217 0 : for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) mat[3*i+j] = rot[i][j];}
218 : // This function returns the rotation matrix in a floating
219 : // precision pointer for a given layer ladder and detector module.
220 : // mat[i][j] => mat[3*i+j].
221 : void GetRotMatrix(Int_t lay,Int_t lad,Int_t det,Float_t *mat)const{
222 0 : GetRotMatrix(GetModuleIndex(lay,lad,det),mat);}
223 : // This function returns the rotation matrix in a Double
224 : // precision pointer for a given layer ladder and detector module.
225 : // mat[i][j] => mat[3*i+j].
226 : void GetRotMatrix(Int_t lay,Int_t lad,Int_t det,Double_t *mat)const{
227 0 : GetRotMatrix(GetModuleIndex(lay,lad,det),mat);}
228 : // This function returns the rotation matrix in a floating
229 : // precision pointer for a given module. mat[i][j] => mat[3*i+j].
230 : void GetRotMatrix(Int_t index,Float_t *mat)const{
231 0 : Double_t rot[3][3];
232 0 : GetGeomMatrix(index)->GetMatrix(rot);
233 0 : for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) mat[3*i+j] = rot[i][j];}
234 : // This function sets the rotation matrix in a Double
235 : // precision pointer for a given module. mat[i][j] => mat[3*i+j].
236 30772 : void SetRotMatrix(Int_t index,const Double_t *mat){Double_t rot[3][3];
237 492352 : for(Int_t i=0;i<3;i++)for(Int_t j=0;j<3;j++) rot[i][j]=mat[3*i+j];
238 15386 : GetGeomMatrix(index)->SetMatrix(rot);}
239 : // Return the normal for a specific module
240 : void GetGlobalNormal(Int_t index,Double_t n[3]){
241 0 : GetGeomMatrix(index)->GetGlobalNormal(n[0],n[1],n[2]);}
242 : //
243 : //
244 : // Setters
245 : // Sets the rotation angles and matrix for a give module index
246 : // via the double precision array a[3] [radians].
247 : void SetByAngles(Int_t index,const Double_t a[]){
248 0 : GetGeomMatrix(index)->SetAngles(a);}
249 : // Sets the rotation angles and matrix for a give module index
250 : // via the 3 floating precision variables rx, ry, and rz [radians].
251 : void SetByAngles(Int_t index,Float_t rx, Float_t ry, Float_t rz) {
252 0 : Double_t a[3];a[0] = rx;a[1] = ry;a[2] = rz;
253 0 : GetGeomMatrix(index)->SetAngles(a);}
254 : // Sets the rotation angles and matrix for a give layer, ladder,
255 : // and detector numbers via the 3 floating precision variables rx,
256 : // ry, and rz [radians].
257 : void SetByAngles(Int_t lay,Int_t lad,Int_t det,
258 : Float_t rx, Float_t ry, Float_t rz) {
259 0 : SetByAngles(GetModuleIndex(lay,lad,det),rx,ry,rz);}
260 : //
261 : // Sets the rotation angles and matrix for a give module index
262 : // via the Double precision array a[6] [degree]. The angles are those
263 : // defined by GEANT 3.12.
264 : void SetByGeantAngles(Int_t index,const Double_t *ang){
265 0 : GetGeomMatrix(index)->MatrixFromSixAngles(ang);}
266 : // Sets the rotation angles and matrix for a give layer, ladder
267 : // and detector, in the array id[3] via the Double precision array
268 : // a[6] [degree]. The angles are those defined by GEANT 3.12.
269 : void SetByGeantAngles(const Int_t *id,const Double_t *ang){
270 0 : SetByGeantAngles(GetModuleIndex(id),ang);}
271 : // Sets the rotation angles and matrix for a give layer, ladder
272 : // and detector, via the Double precision array a[6] [degree]. The
273 : // angles are those defined by GEANT 3.12.
274 : void SetByGeantAngles(Int_t lay,Int_t lad,Int_t det,
275 : const Double_t *ang){
276 0 : SetByGeantAngles(GetModuleIndex(lay,lad,det),ang);}
277 : //
278 : // This function sets a new translation vector, given by the
279 : // array x[3], for the Cartesian coordinate transformation
280 : // for a give module index.
281 : void SetTrans(Int_t index,Double_t x[]){
282 30772 : GetGeomMatrix(index)->SetTranslation(x);}
283 : // This function sets a new translation vector, given by the three
284 : // variables x, y, and z, for the Cartesian coordinate transformation
285 : // for the detector defined by layer, ladder and detector.
286 : void SetTrans(Int_t lay,Int_t lad,Int_t det,
287 0 : Float_t x,Float_t y,Float_t z){Double_t t[3];
288 0 : t[0] = x;t[1] = y;t[2] = z;
289 0 : SetTrans(GetModuleIndex(lay,lad,det),t);}
290 : //
291 : // transformations
292 : // Transforms from the ALICE Global coordinate system
293 : // to the detector local coordinate system for the detector
294 : // defined by the layer, ladder, and detector numbers. The
295 : // global and local coordinate are given in two floating point
296 : // arrays g[3], and l[3].
297 : void GtoL(Int_t lay,Int_t lad,Int_t det,
298 : const Float_t *g,Float_t *l)const{
299 0 : GtoL(GetModuleIndex(lay,lad,det),g,l);}
300 : // Transforms from the ALICE Global coordinate system
301 : // to the detector local coordinate system for the detector
302 : // defined by the id[0], id[1], and id[2] numbers. The
303 : // global and local coordinate are given in two floating point
304 : // arrays g[3], and l[3].
305 : void GtoL(const Int_t *id,const Float_t *g,Float_t *l)const{
306 0 : GtoL(GetModuleIndex(id),g,l);}
307 : // Transforms from the ALICE Global coordinate system
308 : // to the detector local coordinate system for the detector
309 : // module index number. The global and local coordinate are
310 : // given in two floating point arrays g[3], and l[3].
311 : void GtoL(Int_t index,const Float_t *g,Float_t *l)const{
312 35973 : Double_t dg[3],dl[3];Int_t i;for(i=0;i<3;i++) dg[i] = g[i];
313 3997 : GetGeomMatrix(index)->GtoLPosition(dg,dl);
314 35973 : for(i=0;i<3;i++) l[i] =dl[i];}
315 : // Transforms from the ALICE Global coordinate system
316 : // to the detector local coordinate system for the detector
317 : // defined by the layer, ladder, and detector numbers. The
318 : // global and local coordinate are given in two Double point
319 : // arrays g[3], and l[3].
320 : void GtoL(Int_t lay,Int_t lad,Int_t det,
321 : const Double_t *g,Double_t *l)const{
322 0 : GtoL(GetModuleIndex(lay,lad,det),g,l);}
323 : // Transforms from the ALICE Global coordinate system
324 : // to the detector local coordinate system for the detector
325 : // defined by the id[0], id[1], and id[2] numbers. The
326 : // global and local coordinate are given in two Double point
327 : // arrays g[3], and l[3].
328 : void GtoL(const Int_t *id,const Double_t *g,Double_t *l)const{
329 0 : GtoL(GetModuleIndex(id),g,l);}
330 : // Transforms from the ALICE Global coordinate system
331 : // to the detector local coordinate system for the detector
332 : // module index number. The global and local coordinate are
333 : // given in two Double point arrays g[3], and l[3].
334 : void GtoL(Int_t index,const Double_t g[3],Double_t l[3])const{
335 0 : GetGeomMatrix(index)->GtoLPosition(g,l);}
336 :
337 : // Find Specific Modules
338 : // Locate the nearest module to the point g, in ALICE global Cartesian
339 : // coordinates [cm] in a give layer. If layer = 0 then it search in
340 : // all layers.
341 : Int_t GetNearest(const Double_t g[3],Int_t lay=0)const;
342 : // Locates the nearest 27 modules, in nearest order, to the point g, in
343 : // ALICE global Cartesian coordinates [cm] in a give layer. If layer = 0
344 : // then it searches in all layers. (there are 27 elements in a 3x3x3
345 : // cube.
346 : void GetNearest27(const Double_t g[3],Int_t n[27],Int_t lay=0)const;
347 : // Returns the distance [cm] between the point g[3] and the center of
348 : // the detector/module specified by the the module index number.
349 : Double_t Distance(Int_t index,const Double_t g[3])const{
350 0 : return TMath::Sqrt(GetGeomMatrix(index)->Distance2(g));}
351 : // This routine prints, to a file, the contents of this class.
352 : void PrintData(FILE *fp,Int_t lay,Int_t lad,Int_t det)const;
353 : // This function prints out this class in a single stream. This steam
354 : // can be read by ReadGeom.
355 : // (Coverity warnings) void PrintGeom(ostream *out)const;
356 :
357 : //Conversion from det. local coordinates to local ("V2") coordinates
358 : //used for tracking
359 :
360 : void DetLToTrackingV2(Int_t md,Float_t xin,Float_t zin,
361 : Float_t &yout, Float_t &zout) const ;
362 :
363 : void TrackingV2ToDetL(Int_t md,Float_t yin,Float_t zin,
364 : Float_t &xout,Float_t &zout) const ;
365 :
366 : private:
367 : TString fVersion; // Transformation version.
368 : Int_t fTrans; // Flag to keep track of which transformation
369 : Int_t fNmodules;// The total number of modules
370 : Int_t fNlayers; // The number of layers.
371 : TArrayI fNlad; // Array of the number of ladders/layer(layer)
372 : TArrayI fNdet; // Array of the number of detector/ladder(layer)
373 : TObjArray fGm; // Structure of translation. and rotation.
374 :
375 118 : ClassDef(AliITSgeom,4) // ITS geometry class
376 : };
377 : // Input and output function for standard C++ input/output.
378 :
379 : #endif
|