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