1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 ////////////////////////////////////////////////////////////////////////
20 // This is the implementation file for AliITSgeomMatrix class. It
21 // contains the routines to manipulate, setup, and queary the geometry
22 // of a given ITS module. An ITS module may be one of at least three
23 // ITS detector technologies, Silicon Pixel, Drift, or Strip Detectors,
24 // and variations of these in size and/or layout. These routines let
25 // one go between ALICE global coordiantes (cm) to a given modules
26 // specific local coordinates (cm).
27 ////////////////////////////////////////////////////////////////////////
29 #include <Riostream.h>
35 #include <TPolyLine3D.h>
41 #include "AliITSgeomMatrix.h"
43 ClassImp(AliITSgeomMatrix)
44 //----------------------------------------------------------------------
45 AliITSgeomMatrix::AliITSgeomMatrix():
47 fDetectorIndex(0), // Detector type index (like fShapeIndex was)
48 fid(), // layer, ladder, detector numbers.
49 frot(), //! vector of rotations about x,y,z [radians].
50 ftran(), // Translation vector of module x,y,z.
51 fCylR(0.0), //! R Translation in Cylinderical coordinates
52 fCylPhi(0.0),//! Phi Translation vector in Cylindrical coord.
53 fm(), // Rotation matrix based on frot.
54 fPath(){ // Path in geometry to this module
55 // The Default constructor for the AliITSgeomMatrix class. By Default
56 // the angles of rotations are set to zero, meaning that the rotation
57 // matrix is the unit matrix. The translation vector is also set to
58 // zero as are the module id number. The detector type is set to -1
59 // (an undefined value). The full rotation matrix is kept so that
60 // the evaluation of a coordinate transformation can be done
61 // quickly and with a minimum of CPU overhead. The basic coordinate
62 // systems are the ALICE global coordinate system and the detector
63 // local coordinate system. In general this structure is not limited
64 // to just those two coordinate systems.
67 <img src="picts/ITS/AliITSgeomMatrix_L1.gif">
75 // A default constructes AliITSgeomMatrix class.
78 fDetectorIndex = -1; // a value never defined.
81 frot[i] = ftran[i] = 0.0;
82 for(j=0;j<3;j++) fm[i][j] = 0.0;
83 fCylR = fCylPhi = 0.0;
85 fm[0][0] = fm[1][1] = fm[2][2] = 1.0;
88 //----------------------------------------------------------------------
89 AliITSgeomMatrix::AliITSgeomMatrix(const AliITSgeomMatrix &source) :
91 fDetectorIndex(source.fDetectorIndex),
93 fCylPhi(source.fCylPhi),
95 // The standard Copy constructor. This make a full / proper copy of
98 // AliITSgeomMatrix &source The source of this copy
102 // A copy constructes AliITSgeomMatrix class.
105 this->fid[i] = source.fid[i];
106 this->frot[i] = source.frot[i];
107 this->ftran[i] = source.ftran[i];
108 for(j=0;j<3;j++) this->fm[i][j] = source.fm[i][j];
111 //----------------------------------------------------------------------
112 AliITSgeomMatrix& AliITSgeomMatrix::operator=(const AliITSgeomMatrix &source){
113 // The standard = operator. This make a full / proper copy of
115 // The standard Copy constructor. This make a full / proper copy of
118 // AliITSgeomMatrix &source The source of this copy
122 // A copy of the source AliITSgeomMatrix class.
123 if(this == &source)return *this;
126 this->fDetectorIndex = source.fDetectorIndex;
127 this->fCylR = source.fCylR;
128 this->fCylPhi = source.fCylPhi;
130 this->fid[i] = source.fid[i];
131 this->frot[i] = source.frot[i];
132 this->ftran[i] = source.ftran[i];
134 for(j=0;j<3;j++) this->fm[i][j] = source.fm[i][j];
136 this->fPath = source.fPath;
140 //----------------------------------------------------------------------
141 AliITSgeomMatrix::AliITSgeomMatrix(Int_t idt,const Int_t id[3],
142 const Double_t rot[3],const Double_t tran[3]):
144 fDetectorIndex(idt), // Detector type index (like fShapeIndex was)
145 fid(), // layer, ladder, detector numbers.
146 frot(), //! vector of rotations about x,y,z [radians].
147 ftran(), // Translation vector of module x,y,z.
148 fCylR(0.0), //! R Translation in Cylinderical coordinates
149 fCylPhi(0.0),//! Phi Translation vector in Cylindrical coord.
150 fm(), // Rotation matrix based on frot.
151 fPath(){ // Path in geometry to this moduel
152 // This is a constructor for the AliITSgeomMatrix class. The matrix is
153 // defined by 3 standard rotation angles [radians], and the translation
154 // vector tran [cm]. In addition the layer, ladder, and detector number
155 // for this particular module and the type of module must be given.
156 // The full rotation matrix is kept so that the evaluation
157 // of a coordinate transformation can be done quickly and with a minimum
158 // of CPU overhead. The basic coordinate systems are the ALICE global
159 // coordinate system and the detector local coordinate system. In general
160 // this structure is not limited to just those two coordinate systems.
163 <img src="picts/ITS/AliITSgeomMatrix_L1.gif">
167 // Int_t idt The detector index value
168 // Int_t id[3] The layer, ladder, and detector numbers
169 // Double_t rot[3] The 3 Cartician rotaion angles [radians]
170 // Double_t tran[3] The 3 Cartician translation distnaces
174 // A properly inilized AliITSgeomMatrix class.
182 fCylR = TMath::Sqrt(ftran[0]*ftran[0]+ftran[1]*ftran[1]);
183 fCylPhi = TMath::ATan2(ftran[1],ftran[0]);
184 if(fCylPhi<0.0) fCylPhi += TMath::Pi();
185 this->MatrixFromAngle();
187 //----------------------------------------------------------------------
188 AliITSgeomMatrix::AliITSgeomMatrix(Int_t idt, const Int_t id[3],
189 Double_t matrix[3][3],
190 const Double_t tran[3]):
192 fDetectorIndex(idt), // Detector type index (like fShapeIndex was)
193 fid(), // layer, ladder, detector numbers.
194 frot(), //! vector of rotations about x,y,z [radians].
195 ftran(), // Translation vector of module x,y,z.
196 fCylR(0.0), //! R Translation in Cylinderical coordinates
197 fCylPhi(0.0),//! Phi Translation vector in Cylindrical coord.
198 fm(), // Rotation matrix based on frot.
199 fPath(){ // Path in geometry to this module
200 // This is a constructor for the AliITSgeomMatrix class. The
201 // rotation matrix is given as one of the inputs, and the
202 // translation vector tran [cm]. In addition the layer, ladder,
203 // and detector number for this particular module and the type of
204 // module must be given. The full rotation matrix is kept so that
205 // the evaluation of a coordinate transformation can be done quickly
206 // and with a minimum of CPU overhead. The basic coordinate systems
207 // are the ALICE global coordinate system and the detector local
208 // coordinate system. In general this structure is not limited to just
209 // those two coordinate systems.
212 <img src="picts/ITS/AliITSgeomMatrix_L1.gif">
216 // Int_t idt The detector index value
217 // Int_t id[3] The layer, ladder, and detector numbers
218 // Double_t rot[3][3] The 3x3 Cartician rotaion matrix
219 // Double_t tran[3] The 3 Cartician translation distnaces
223 // A properly inilized AliITSgeomMatrix class.
229 for(j=0;j<3;j++) fm[i][j] = matrix[i][j];
231 fCylR = TMath::Sqrt(ftran[0]*ftran[0]+ftran[1]*ftran[1]);
232 fCylPhi = TMath::ATan2(ftran[1],ftran[0]);
233 if(fCylPhi<0.0) fCylPhi += TMath::Pi();
234 this->AngleFromMatrix();
236 //----------------------------------------------------------------------
237 void AliITSgeomMatrix::SixAnglesFromMatrix(Double_t *ang)const{
238 // This function returns the 6 GEANT 3.21 rotation angles [degrees] in
239 // the array ang which must be at least [6] long.
243 // Double_t ang[6] The 6 Geant3.21 rotation angles. [degrees]
246 Double_t si,c=180./TMath::Pi();
248 ang[1] = TMath::ATan2(fm[0][1],fm[0][0]);
249 if(TMath::Cos(ang[1])!=0.0) si = fm[0][0]/TMath::Cos(ang[1]);
250 else si = fm[0][1]/TMath::Sin(ang[1]);
251 ang[0] = TMath::ATan2(si,fm[0][2]);
253 ang[3] = TMath::ATan2(fm[1][1],fm[1][0]);
254 if(TMath::Cos(ang[3])!=0.0) si = fm[1][0]/TMath::Cos(ang[3]);
255 else si = fm[1][1]/TMath::Sin(ang[3]);
256 ang[2] = TMath::ATan2(si,fm[1][2]);
258 ang[5] = TMath::ATan2(fm[2][1],fm[2][0]);
259 if(TMath::Cos(ang[5])!=0.0) si = fm[2][0]/TMath::Cos(ang[5]);
260 else si = fm[2][1]/TMath::Sin(ang[5]);
261 ang[4] = TMath::ATan2(si,fm[2][2]);
263 for(Int_t i=0;i<6;i++) {ang[i] *= c; if(ang[i]<0.0) ang[i] += 360.;}
265 //----------------------------------------------------------------------
266 void AliITSgeomMatrix::MatrixFromSixAngles(const Double_t *ang){
267 // Given the 6 GEANT 3.21 rotation angles [degree], this will compute and
268 // set the rotations matrix and 3 standard rotation angles [radians].
269 // These angles and rotation matrix are overwrite the existing values in
272 // Double_t ang[6] The 6 Geant3.21 rotation angles. [degrees]
278 Double_t si,lr[9],c=TMath::Pi()/180.;
280 si = TMath::Sin(c*ang[0]);
281 if(ang[0]== 90.0) si = +1.0;
282 if(ang[0]==270.0) si = -1.0;
283 if(ang[0]== 0.0||ang[0]==180.) si = 0.0;
284 lr[0] = si * TMath::Cos(c*ang[1]);
285 lr[1] = si * TMath::Sin(c*ang[1]);
286 lr[2] = TMath::Cos(c*ang[0]);
287 if(ang[0]== 90.0||ang[0]==270.) lr[2] = 0.0;
288 if(ang[0]== 0.0) lr[2] = +1.0;
289 if(ang[0]==180.0) lr[2] = -1.0;
291 si = TMath::Sin(c*ang[2]);
292 if(ang[2]== 90.0) si = +1.0;
293 if(ang[2]==270.0) si = -1.0;
294 if(ang[2]== 0.0||ang[2]==180.) si = 0.0;
295 lr[3] = si * TMath::Cos(c*ang[3]);
296 lr[4] = si * TMath::Sin(c*ang[3]);
297 lr[5] = TMath::Cos(c*ang[2]);
298 if(ang[2]== 90.0||ang[2]==270.) lr[5] = 0.0;
299 if(ang[2]== 0.0) lr[5] = +1.0;
300 if(ang[2]==180.0) lr[5] = -1.0;
302 si = TMath::Sin(c*ang[4]);
303 if(ang[4]== 90.0) si = +1.0;
304 if(ang[4]==270.0) si = -1.0;
305 if(ang[4]== 0.0||ang[4]==180.) si = 0.0;
306 lr[6] = si * TMath::Cos(c*ang[5]);
307 lr[7] = si * TMath::Sin(c*ang[5]);
308 lr[8] = TMath::Cos(c*ang[4]);
309 if(ang[4]== 90.0||ang[4]==270.0) lr[8] = 0.0;
310 if(ang[4]== 0.0) lr[8] = +1.0;
311 if(ang[4]==180.0) lr[8] = -1.0;
312 // Normalize these elements and fill matrix fm.
313 for(i=0;i<3;i++){// reuse si.
315 for(j=0;j<3;j++) si += lr[3*i+j]*lr[3*i+j];
316 si = TMath::Sqrt(1./si);
317 for(j=0;j<3;j++) fm[i][j] = si*lr[3*i+j];
319 this->AngleFromMatrix();
321 //----------------------------------------------------------------------
322 AliITSgeomMatrix::AliITSgeomMatrix(const Double_t rotd[6]/*degrees*/,
323 Int_t idt,const Int_t id[3],
324 const Double_t tran[3]):
330 // This is a constructor for the AliITSgeomMatrix class. The matrix
331 // is defined by the 6 GEANT 3.21 rotation angles [degrees], and
332 // the translation vector tran [cm]. In addition the layer, ladder,
333 // and detector number for this particular module and the type of
334 // module must be given. The full rotation matrix is kept so that
335 // the evaluation of a coordinate transformation can be done
336 // quickly and with a minimum of CPU overhead. The basic coordinate
337 // systems are the ALICE global coordinate system and the detector
338 // local coordinate system. In general this structure is not limited
339 // to just those two coordinate systems.
342 <img src="picts/ITS/AliITSgeomMatrix_L1.gif">
346 // Double_t rotd[6] The 6 Geant 3.21 rotation angles [degrees]
347 // Int_t idt The module Id number
348 // Int_t id[3] The layer, ladder and detector number
349 // Double_t tran[3] The translation vector
356 fCylR = TMath::Sqrt(ftran[0]*ftran[0]+ftran[1]*ftran[1]);
357 fCylPhi = TMath::ATan2(ftran[1],ftran[0]);
358 if(fCylPhi<0.0) fCylPhi += TMath::Pi();
359 this->MatrixFromSixAngles(rotd);
362 //----------------------------------------------------------------------
363 void AliITSgeomMatrix::AngleFromMatrix(){
364 // Computes the angles from the rotation matrix up to a phase of
365 // 180 degrees. The matrix used in AliITSgeomMatrix::MatrixFromAngle()
366 // and its inverse AliITSgeomMatrix::AngleFromMatrix() are defined in
367 // the following ways, R = Rz*Ry*Rx (M=R*L+T) where
368 // 1 0 0 Cy 0 +Sy Cz -Sz 0
369 // Rx= 0 Cx -Sx Ry= 0 1 0 Rz=+Sz Cz 0
370 // 0 +Sx Cx -Sy 0 Cy 0 0 1
371 // The choice of the since of S, comes from the choice between
372 // the rotation of the object or the coordinate system (view). I think
373 // that this choice is the first, the rotation of the object.
381 // get angles from matrix up to a phase of 180 degrees.
383 rx = TMath::ATan2(fm[2][1],fm[2][2]);if(rx<0.0) rx += 2.0*TMath::Pi();
384 ry = TMath::ASin(-fm[0][2]); if(ry<0.0) ry += 2.0*TMath::Pi();
385 rz = TMath::ATan2(fm[1][0],fm[0][0]);if(rz<0.0) rz += 2.0*TMath::Pi();
392 //----------------------------------------------------------------------
393 void AliITSgeomMatrix::MatrixFromAngle(){
394 // Computes the Rotation matrix from the angles [radians] kept in this
395 // class. The matrix used in AliITSgeomMatrix::MatrixFromAngle() and
396 // its inverse AliITSgeomMatrix::AngleFromMatrix() are defined in
397 // the following ways, R = Rz*Ry*Rx (M=R*L+T) where
398 // 1 0 0 Cy 0 +Sy Cz -Sz 0
399 // Rx= 0 Cx -Sx Ry= 0 1 0 Rz=+Sz Cz 0
400 // 0 +Sx Cx -Sy 0 Cy 0 0 1
401 // The choice of the since of S, comes from the choice between
402 // the rotation of the object or the coordinate system (view). I think
403 // that this choice is the first, the rotation of the object.
410 Double_t sx,sy,sz,cx,cy,cz;
412 sx = TMath::Sin(frot[0]); cx = TMath::Cos(frot[0]);
413 sy = TMath::Sin(frot[1]); cy = TMath::Cos(frot[1]);
414 sz = TMath::Sin(frot[2]); cz = TMath::Cos(frot[2]);
415 fm[0][0] = +cz*cy; // fr[0]
416 fm[0][1] = +cz*sy*sx - sz*cx; // fr[1]
417 fm[0][2] = +cz*sy*cx + sz*sx; // fr[2]
418 fm[1][0] = +sz*cy; // fr[3]
419 fm[1][1] = +sz*sy*sx + cz*cx; // fr[4]
420 fm[1][2] = +sz*sy*cx - cz*sx; // fr[5]
421 fm[2][0] = -sy; // fr[6]
422 fm[2][1] = +cy*sx; // fr[7]
423 fm[2][2] = +cy*cx; // fr[8]
427 //----------------------------------------------------------------------
428 void AliITSgeomMatrix::GtoLPosition(const Double_t g0[3],Double_t l[3]) const {
429 // Returns the local coordinates given the global coordinates [cm].
431 // Double_t g[3] The position represented in the ALICE
432 // global coordinate system
434 // Double_t l[3] The poistion represented in the local
435 // detector coordiante system
441 for(i=0;i<3;i++) g[i] = g0[i] - ftran[i];
444 for(j=0;j<3;j++) l[i] += fm[i][j]*g[j];
445 // g = R l + translation
449 //----------------------------------------------------------------------
450 void AliITSgeomMatrix::LtoGPosition(const Double_t l[3],Double_t g[3]) const {
451 // Returns the global coordinates given the local coordinates [cm].
453 // Double_t l[3] The poistion represented in the detector
454 // local coordinate system
456 // Double_t g[3] The poistion represented in the ALICE
457 // Global coordinate system
464 for(j=0;j<3;j++) g[i] += fm[j][i]*l[j];
466 // g = R^t l + translation
470 //----------------------------------------------------------------------
471 void AliITSgeomMatrix::GtoLMomentum(const Double_t g[3],Double_t l[3]) const{
472 // Returns the local coordinates of the momentum given the global
473 // coordinates of the momentum. It transforms just like GtoLPosition
474 // except that the translation vector is zero.
476 // Double_t g[3] The momentum represented in the ALICE global
479 // Double_t l[3] the momentum represented in the detector
480 // local coordinate system
487 for(j=0;j<3;j++) l[i] += fm[i][j]*g[j];
492 //----------------------------------------------------------------------
493 void AliITSgeomMatrix::LtoGMomentum(const Double_t l[3],Double_t g[3]) const {
494 // Returns the Global coordinates of the momentum given the local
495 // coordinates of the momentum. It transforms just like LtoGPosition
496 // except that the translation vector is zero.
498 // Double_t l[3] the momentum represented in the detector
499 // local coordinate system
501 // Double_t g[3] The momentum represented in the ALICE global
509 for(j=0;j<3;j++) g[i] += fm[j][i]*l[j];
514 //----------------------------------------------------------------------
515 void AliITSgeomMatrix::GtoLPositionError(const Double_t g[3][3],
516 Double_t l[3][3]) const {
517 // Given an Uncertainty matrix in Global coordinates it is
518 // rotated so that its representation in local coordinates can
519 // be returned. There is no effect due to the translation vector
520 // or its uncertainty.
522 // Double_t g[3][3] The error matrix represented in the ALICE global
525 // Double_t l[3][3] the error matrix represented in the detector
526 // local coordinate system
531 for(i=0;i<3;i++)for(m=0;m<3;m++){
533 for(j=0;j<3;j++)for(k=0;k<3;k++)
534 l[i][m] += fm[j][i]*g[j][k]*fm[k][m];
539 //----------------------------------------------------------------------
540 void AliITSgeomMatrix::LtoGPositionError(const Double_t l[3][3],
541 Double_t g[3][3]) const {
542 // Given an Uncertainty matrix in Local coordinates it is rotated so that
543 // its representation in global coordinates can be returned. There is no
544 // effect due to the translation vector or its uncertainty.
546 // Double_t l[3][3] the error matrix represented in the detector
547 // local coordinate system
549 // Double_t g[3][3] The error matrix represented in the ALICE global
555 for(i=0;i<3;i++)for(m=0;m<3;m++){
557 for(j=0;j<3;j++)for(k=0;k<3;k++)
558 g[i][m] += fm[i][j]*l[j][k]*fm[m][k];
563 //----------------------------------------------------------------------
564 void AliITSgeomMatrix::GtoLPositionTracking(const Double_t g[3],
565 Double_t l[3]) const {
566 // A slightly different coordinate system is used when tracking.
567 // This coordinate system is only relevant when the geometry represents
568 // the cylindrical ALICE ITS geometry. For tracking the Z axis is left
569 // alone but X -> -Y and Y -> X such that X always points out of the
570 // ITS Cylinder for every layer including layer 1 (where the detector
571 // are mounted upside down).
574 <img src="picts/ITS/AliITSgeomMatrix_T1.gif">
578 // Double_t g[3] The position represented in the ALICE
579 // global coordinate system
581 // Double_t l[3] The poistion represented in the local
582 // detector coordiante system
587 this->GtoLPosition(g,l0);
588 if(fid[0]==1){ // for layer 1 the detector are flipped upside down
589 // with respect to the others.
600 //----------------------------------------------------------------------
601 void AliITSgeomMatrix::LtoGPositionTracking(const Double_t l[3],
602 Double_t g[3]) const {
603 // A slightly different coordinate system is used when tracking.
604 // This coordinate system is only relevant when the geometry represents
605 // the cylindrical ALICE ITS geometry. For tracking the Z axis is left
606 // alone but X -> -Y and Y -> X such that X always points out of the
607 // ITS Cylinder for every layer including layer 1 (where the detector
608 // are mounted upside down).
611 <img src="picts/ITS/AliITSgeomMatrix_T1.gif">
615 // Double_t l[3] The poistion represented in the detector
616 // local coordinate system
618 // Double_t g[3] The poistion represented in the ALICE
619 // Global coordinate system
624 if(fid[0]==1){ // for layer 1 the detector are flipped upside down
625 // with respect to the others.
634 this->LtoGPosition(l0,g);
637 //----------------------------------------------------------------------
638 void AliITSgeomMatrix::GtoLMomentumTracking(const Double_t g[3],
639 Double_t l[3]) const {
640 // A slightly different coordinate system is used when tracking.
641 // This coordinate system is only relevant when the geometry represents
642 // the cylindrical ALICE ITS geometry. For tracking the Z axis is left
643 // alone but X -> -Y and Y -> X such that X always points out of the
644 // ITS Cylinder for every layer including layer 1 (where the detector
645 // are mounted upside down).
648 <img src="picts/ITS/AliITSgeomMatrix_T1.gif">
652 // Double_t g[3] The momentum represented in the ALICE global
655 // Double_t l[3] the momentum represented in the detector
656 // local coordinate system
661 this->GtoLMomentum(g,l0);
662 if(fid[0]==1){ // for layer 1 the detector are flipped upside down
663 // with respect to the others.
674 //----------------------------------------------------------------------
675 void AliITSgeomMatrix::LtoGMomentumTracking(const Double_t l[3],
676 Double_t g[3]) const {
677 // A slightly different coordinate system is used when tracking.
678 // This coordinate system is only relevant when the geometry represents
679 // the cylindrical ALICE ITS geometry. For tracking the Z axis is left
680 // alone but X -> -Y and Y -> X such that X always points out of the
681 // ITS Cylinder for every layer including layer 1 (where the detector
682 // are mounted upside down).
685 <img src="picts/ITS/AliITSgeomMatrix_T1.gif">
689 // Double_t l[3] the momentum represented in the detector
690 // local coordinate system
692 // Double_t g[3] The momentum represented in the ALICE global
698 if(fid[0]==1){ // for layer 1 the detector are flipped upside down
699 // with respect to the others.
708 this->LtoGMomentum(l0,g);
711 //----------------------------------------------------------------------
712 void AliITSgeomMatrix::GtoLPositionErrorTracking(const Double_t g[3][3],
713 Double_t l[3][3]) const {
714 // A slightly different coordinate system is used when tracking.
715 // This coordinate system is only relevant when the geometry represents
716 // the cylindrical ALICE ITS geometry. For tracking the Z axis is left
717 // alone but X -> -Y and Y -> X such that X always points out of the
718 // ITS Cylinder for every layer including layer 1 (where the detector
719 // are mounted upside down).
722 <img src="picts/ITS/AliITSgeomMatrix_TE1.gif">
726 // Double_t g[3][3] The error matrix represented in the ALICE global
729 // Double_t l[3][3] the error matrix represented in the detector
730 // local coordinate system
734 Double_t a0[3][3] = {{0.,+1.,0.},{-1.,0.,0.},{0.,0.,+1.}};
735 Double_t a1[3][3] = {{0.,-1.,0.},{+1.,0.,0.},{0.,0.,+1.}};
737 if(fid[0]==1) for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)
738 rt[i][k] = a0[i][j]*fm[j][k];
739 else for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)
740 rt[i][k] = a1[i][j]*fm[j][k];
741 for(i=0;i<3;i++)for(m=0;m<3;m++){
743 for(j=0;j<3;j++)for(k=0;k<3;k++)
744 l[i][m] += rt[j][i]*g[j][k]*rt[k][m];
749 //----------------------------------------------------------------------
750 void AliITSgeomMatrix::LtoGPositionErrorTracking(const Double_t l[3][3],
751 Double_t g[3][3]) const {
752 // A slightly different coordinate system is used when tracking.
753 // This coordinate system is only relevant when the geometry represents
754 // the cylindrical ALICE ITS geometry. For tracking the Z axis is left
755 // alone but X -> -Y and Y -> X such that X always points out of the
756 // ITS Cylinder for every layer including layer 1 (where the detector
757 // are mounted upside down).
760 <img src="picts/ITS/AliITSgeomMatrix_TE1.gif">
764 // Double_t l[3][3] the error matrix represented in the detector
765 // local coordinate system
767 // Double_t g[3][3] The error matrix represented in the ALICE global
773 Double_t a0[3][3] = {{0.,+1.,0.},{-1.,0.,0.},{0.,0.,+1.}};
774 Double_t a1[3][3] = {{0.,-1.,0.},{+1.,0.,0.},{0.,0.,+1.}};
776 if(fid[0]==1) for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)
777 rt[i][k] = a0[i][j]*fm[j][k];
778 else for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)
779 rt[i][k] = a1[i][j]*fm[j][k];
780 for(i=0;i<3;i++)for(m=0;m<3;m++){
782 for(j=0;j<3;j++)for(k=0;k<3;k++)
783 g[i][m] += rt[i][j]*l[j][k]*rt[m][k];
788 //----------------------------------------------------------------------
789 void AliITSgeomMatrix::PrintTitles(ostream *os) const {
790 // Standard output format for this class but it includes variable
791 // names and formatting that makes it easer to read.
793 // ostream *os The output stream to print the title on
800 *os << "fDetectorIndex=" << fDetectorIndex << " fid[3]={";
801 for(i=0;i<3;i++) *os << fid[i] << " ";
802 *os << "} frot[3]={";
803 for(i=0;i<3;i++) *os << frot[i] << " ";
804 *os << "} ftran[3]={";
805 for(i=0;i<3;i++) *os << ftran[i] << " ";
806 *os << "} fm[3][3]={";
807 for(i=0;i<3;i++){for(j=0;j<3;j++){ *os << fm[i][j] << " ";} *os <<"}{";}
811 //----------------------------------------------------------------------
812 void AliITSgeomMatrix::PrintComment(ostream *os) const {
813 // output format used by Print.
815 // ostream *os The output stream to print the comments on
820 *os << "fDetectorIndex fid[0] fid[1] fid[2] ftran[0] ftran[1] ftran[2] ";
821 *os << "fm[0][0] fm[0][1] fm[0][2] fm[1][0] fm[1][1] fm[1][2] ";
822 *os << "fm[2][0] fm[2][1] fm[2][2] ";
825 //----------------------------------------------------------------------
826 void AliITSgeomMatrix::Print(ostream *os)const{
827 // Standard output format for this class.
829 // ostream *os The output stream to print the class data on
842 #if defined __ICC || defined __ECC || defined __xlC__
849 fmt = os->setf(ios::scientific); // set scientific floating point output
850 *os << fDetectorIndex << " ";
851 for(i=0;i<3;i++) *os << fid[i] << " ";
852 // for(i=0;i<3;i++) *os << frot[i] << " "; // Redundant with fm[][].
853 for(i=0;i<3;i++) *os << setprecision(16) << ftran[i] << " ";
854 for(i=0;i<3;i++)for(j=0;j<3;j++) *os << setprecision(16) <<
856 *os << fPath.Length()<< " ";
857 for(i=0;i<fPath.Length();i++) *os << fPath[i];
859 os->flags(fmt); // reset back to old formating.
862 //----------------------------------------------------------------------
863 void AliITSgeomMatrix::Read(istream *is){
864 // Standard input format for this class.
866 // istream *is The input stream to read on
873 *is >> fDetectorIndex;
874 for(i=0;i<3;i++) *is >> fid[i];
875 // for(i=0;i<3;i++) *is >> frot[i]; // Redundant with fm[][].
876 for(i=0;i<3;i++) *is >> ftran[i];
877 for(i=0;i<3;i++)for(j=0;j<3;j++) *is >> fm[i][j];
878 while(is->peek()==' ')is->get(); // skip white spaces
879 if(isprint(is->peek())){ // old format did not have path.
880 *is >> j; // string length
882 for(i=0;i<j;i++) {*is >> fPath[i];}
884 AngleFromMatrix(); // compute angles frot[].
885 fCylR = TMath::Sqrt(ftran[0]*ftran[0]+ftran[1]*ftran[1]);
886 fCylPhi = TMath::ATan2(ftran[1],ftran[0]);
887 if(fCylPhi<0.0) fCylPhi += TMath::Pi();
890 //______________________________________________________________________
891 void AliITSgeomMatrix::Streamer(TBuffer &R__b){
892 // Stream an object of class AliITSgeomMatrix.
894 // TBuffer &R__b The output buffer to stream data on.
900 if (R__b.IsReading()) {
901 AliITSgeomMatrix::Class()->ReadBuffer(R__b, this);
902 fCylR = TMath::Sqrt(ftran[0]*ftran[0]+ftran[1]*ftran[1]);
903 fCylPhi = TMath::ATan2(ftran[1],ftran[0]);
904 this->AngleFromMatrix();
905 if(fCylPhi<0.0) fCylPhi += TMath::Pi();
907 AliITSgeomMatrix::Class()->WriteBuffer(R__b, this);
910 //______________________________________________________________________
911 void AliITSgeomMatrix::SetTranslation(const Double_t tran[3]){
912 // Sets the translation vector and computes fCylR and fCylPhi.
914 // Double_t trans[3] The translation vector to be used
919 for(Int_t i=0;i<3;i++) ftran[i] = tran[i];
920 fCylR = TMath::Sqrt(ftran[0]*ftran[0]+ftran[1]*ftran[1]);
921 fCylPhi = TMath::ATan2(ftran[1],ftran[0]);
922 if(fCylPhi<0.0) fCylPhi += TMath::Pi();
924 //----------------------------------------------------------------------
925 TPolyLine3D* AliITSgeomMatrix::CreateLocalAxis() const {
926 // This class is used as part of the documentation of this class
932 // A pointer to a new TPolyLine3D object showing the 3 line
933 // segments that make up the this local axis in the global
937 Double_t l[5][3]={{1.0,0.0,0.0},{0.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,0.0},
942 LtoGPosition(l[i],g[i]);
943 gf[3*i]=(Float_t)g[i][0];
944 gf[3*i+1]=(Float_t)g[i][1];
945 gf[3*i+2]=(Float_t)g[i][2];
947 return new TPolyLine3D(5,gf);
949 //----------------------------------------------------------------------
950 TPolyLine3D* AliITSgeomMatrix::CreateLocalAxisTracking() const {
951 // This class is used as part of the documentation of this class
957 // A pointer to a new TPolyLine3D object showing the 3 line
958 // segments that make up the this local axis in the global
962 Double_t l[5][3]={{1.0,0.0,0.0},{0.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,0.0},
967 LtoGPositionTracking(l[i],g[i]);
968 gf[3*i]=(Float_t)g[i][0];
969 gf[3*i+1]=(Float_t)g[i][1];
970 gf[3*i+2]=(Float_t)g[i][2];
972 return new TPolyLine3D(5,gf);
974 //----------------------------------------------------------------------
975 TNode* AliITSgeomMatrix::CreateNode(const Char_t *nodeName,
976 const Char_t *nodeTitle,TNode *mother,
977 TShape *shape,Bool_t axis) const {
978 // Creates a node inside of the node mother out of the shape shape
979 // in the position, with respect to mother, indecated by "this". If axis
980 // is ture, it will insert an axis within this node/shape.
982 // Char_t *nodeName This name of this node
983 // Char_t *nodeTitle This node title
984 // TNode *mother The node this node will be inside of/with respect to
985 // TShape *shape The shape of this node
986 // Bool_t axis If ture, a set of x,y,z axis will be included
990 // A pointer to "this" node.
991 Double_t trans[3],matrix[3][3],*matr;
992 TRotMatrix *rot = new TRotMatrix();
995 matr = &(matrix[0][0]);
996 this->GetTranslation(trans);
997 this->GetMatrix(matrix);
998 rot->SetMatrix(matr);
1004 TNode *node1 = new TNode(name.Data(),title.Data(),shape,trans[0],trans[1],trans[2],rot);
1007 const Float_t kScale=0.5,kLw=0.2;
1008 Float_t xchar[13][2]={{0.5*kLw,1.},{0.,0.5*kLw},{0.5-0.5*kLw,0.5},
1009 {0.,0.5*kLw},{0.5*kLw,0.},{0.5,0.5-0.5*kLw},
1010 {1-0.5*kLw,0.},{1.,0.5*kLw},{0.5+0.5*kLw,0.5},
1011 {1.,1.-0.5*kLw},{1.-0.5*kLw,1.},{0.5,0.5+0.5*kLw},
1013 Float_t ychar[10][2]={{.5-0.5*kLw,0.},{.5+0.5*kLw,0.},{.5+0.5*kLw,0.5-0.5*kLw},
1014 {1.,1.-0.5*kLw},{1.-0.5*kLw,1.},{0.5+0.5*kLw,0.5},
1015 {0.5*kLw,1.} ,{0.,1-0.5*kLw} ,{0.5-0.5*kLw,0.5},
1017 Float_t zchar[11][2]={{0.,1.},{0,1.-kLw},{1.-kLw,1.-kLw},{0.,kLw} ,{0.,0.},
1018 {1.,0.},{1.,kLw} ,{kLw,kLw} ,{1.,1.-kLw},{1.,1.},
1020 for(i=0;i<13;i++)for(j=0;j<2;j++){
1021 if(i<13) xchar[i][j] = kScale*xchar[i][j];
1022 if(i<10) ychar[i][j] = kScale*ychar[i][j];
1023 if(i<11) zchar[i][j] = kScale*zchar[i][j];
1025 TXTRU *axisxl = new TXTRU("x","x","text",12,2);
1026 for(i=0;i<12;i++) axisxl->DefineVertex(i,xchar[i][0],xchar[i][1]);
1027 axisxl->DefineSection(0,-0.5*kLw);axisxl->DefineSection(1,0.5*kLw);
1028 TXTRU *axisyl = new TXTRU("y","y","text",9,2);
1029 for(i=0;i<9;i++) axisyl->DefineVertex(i,ychar[i][0],ychar[i][1]);
1030 axisyl->DefineSection(0,-0.5*kLw);axisyl->DefineSection(1,0.5*kLw);
1031 TXTRU *axiszl = new TXTRU("z","z","text",10,2);
1032 for(i=0;i<10;i++) axiszl->DefineVertex(i,zchar[i][0],zchar[i][1]);
1033 axiszl->DefineSection(0,-0.5*kLw);axiszl->DefineSection(1,0.5*kLw);
1034 Float_t lxy[13][2]={{-0.5*kLw,-0.5*kLw},{0.8,-0.5*kLw},{0.8,-0.1},{1.0,0.0},
1035 {0.8,0.1},{0.8,0.5*kLw},{0.5*kLw,0.5*kLw},{0.5*kLw,0.8},
1036 {0.1,0.8},{0.0,1.0},{-0.1,0.8},{-0.5*kLw,0.8},
1037 {-0.5*kLw,-0.5*kLw}};
1038 TXTRU *axisxy = new TXTRU("axisxy","axisxy","text",13,2);
1039 for(i=0;i<13;i++) axisxy->DefineVertex(i,lxy[i][0],lxy[i][1]);
1040 axisxy->DefineSection(0,-0.5*kLw);axisxy->DefineSection(1,0.5*kLw);
1041 Float_t lz[8][2]={{0.5*kLw,-0.5*kLw},{0.8,-0.5*kLw},{0.8,-0.1},{1.0,0.0},
1042 {0.8,0.1},{0.8,0.5*kLw},{0.5*kLw,0.5*kLw},
1043 {0.5*kLw,-0.5*kLw}};
1044 TXTRU *axisz = new TXTRU("axisz","axisz","text",8,2);
1045 for(i=0;i<8;i++) axisz->DefineVertex(i,lz[i][0],lz[i][1]);
1046 axisz->DefineSection(0,-0.5*kLw);axisz->DefineSection(1,0.5*kLw);
1047 //TRotMatrix *xaxis90= new TRotMatrix("xaixis90","",90.0, 0.0, 0.0);
1048 TRotMatrix *yaxis90= new TRotMatrix("yaixis90","", 0.0,90.0, 0.0);
1049 TRotMatrix *zaxis90= new TRotMatrix("zaixis90","", 0.0, 0.0,90.0);
1052 title = name.Append("axisxy");
1053 TNode *nodeaxy = new TNode(title.Data(),title.Data(),axisxy);
1054 title = name.Append("axisz");
1055 TNode *nodeaz = new TNode(title.Data(),title.Data(),axisz,0.,0.,0.,yaxis90);
1056 TNode *textboxX0 = new TNode("textboxX0","textboxX0",axisxl,
1057 lxy[3][0],lxy[3][1],0.0);
1058 TNode *textboxX1 = new TNode("textboxX1","textboxX1",axisxl,
1059 lxy[3][0],lxy[3][1],0.0,yaxis90);
1060 TNode *textboxX2 = new TNode("textboxX2","textboxX2",axisxl,
1061 lxy[3][0],lxy[3][1],0.0,zaxis90);
1062 TNode *textboxY0 = new TNode("textboxY0","textboxY0",axisyl,
1063 lxy[9][0],lxy[9][1],0.0);
1064 TNode *textboxY1 = new TNode("textboxY1","textboxY1",axisyl,
1065 lxy[9][0],lxy[9][1],0.0,yaxis90);
1066 TNode *textboxY2 = new TNode("textboxY2","textboxY2",axisyl,
1067 lxy[9][0],lxy[9][1],0.0,zaxis90);
1068 TNode *textboxZ0 = new TNode("textboxZ0","textboxZ0",axiszl,
1070 TNode *textboxZ1 = new TNode("textboxZ1","textboxZ1",axiszl,
1071 0.0,0.0,lz[3][0],yaxis90);
1072 TNode *textboxZ2 = new TNode("textboxZ2","textboxZ2",axiszl,
1073 0.0,0.0,lz[3][0],zaxis90);
1089 //----------------------------------------------------------------------
1090 void AliITSgeomMatrix::MakeFigures() const {
1091 // make figures to help document this class
1098 const Double_t kDx0=550.,kDy0=550.,kDz0=550.; // cm
1099 const Double_t kDx=1.0,kDy=0.300,kDz=3.0,kRmax=0.1; // cm
1100 Float_t l[5][3]={{1.0,0.0,0.0},{0.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,0.0},
1102 TCanvas *c = new TCanvas(kFALSE);// create a batch mode canvas.
1103 TView *view = new TView(1); // Create Cartesian coordiante view
1104 TBRIK *mother = new TBRIK("Mother","Mother","void",kDx0,kDy0,kDz0);
1105 TBRIK *det = new TBRIK("Detector","","Si",kDx,kDy,kDz);
1106 TPolyLine3D *axis = new TPolyLine3D(5,&(l[0][0]));
1107 TPCON *arrow = new TPCON("arrow","","air",0.0,360.,2);
1108 TRotMatrix *xarrow= new TRotMatrix("xarrow","",90.,0.0,0.0);
1109 TRotMatrix *yarrow= new TRotMatrix("yarrow","",0.0,90.,0.0);
1111 det->SetLineColor(0); // black
1112 det->SetLineStyle(1); // solid line
1113 det->SetLineWidth(2); // pixel units
1114 det->SetFillColor(1); // black
1115 det->SetFillStyle(4010); // window is 90% transparent
1116 arrow->SetLineColor(det->GetLineColor());
1117 arrow->SetLineWidth(det->GetLineWidth());
1118 arrow->SetLineStyle(det->GetLineStyle());
1119 arrow->SetFillColor(1); // black
1120 arrow->SetFillStyle(4100); // window is 100% opaque
1121 arrow->DefineSection(0,0.0,0.0,kRmax);
1122 arrow->DefineSection(1,2.*kRmax,0.0,0.0);
1123 view->SetRange(-kDx0,-kDy0,-kDz0,kDx0,kDy0,kDz0);
1125 TNode *node0 = new TNode("NODE0","NODE0",mother);
1127 TNode *node1 = new TNode("NODE1","NODE1",det);
1129 TNode *nodex = new TNode("NODEx","NODEx",arrow,l[0][0],l[0][1],l[0][2],xarrow);
1130 TNode *nodey = new TNode("NODEy","NODEy",arrow,l[2][0],l[2][1],l[2][2],yarrow);
1131 TNode *nodez = new TNode("NODEz","NODEz",arrow,l[4][0],l[4][1],l[4][2]);
1142 c->SaveAs("AliITSgeomMatrix_L1.gif");
1144 //----------------------------------------------------------------------
1145 ostream &operator<<(ostream &os,AliITSgeomMatrix &p){
1146 // Standard output streaming function.
1148 // ostream &os The output stream to print the class data on
1149 // AliITSgeomMatrix &p This class
1158 //----------------------------------------------------------------------
1159 istream &operator>>(istream &is,AliITSgeomMatrix &r){
1160 // Standard input streaming function.
1162 // ostream &os The input stream to print the class data on
1163 // AliITSgeomMatrix &p This class
1172 //----------------------------------------------------------------------