Fixed up some informational printouts.
[u/mrichter/AliRoot.git] / ITS / AliITSgeomMatrix.cxx
CommitLineData
df5240ea 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
16/*
17$Log$
a8a6107b 18Revision 1.5 2000/10/02 16:32:35 barbera
19Forward declaration added
20
92c19c36 21Revision 1.1.2.6 2000/10/02 15:52:05 barbera
22Forward declaration added
23
24Revision 1.4 2000/09/07 17:30:45 nilsen
25fixed a bug in SixAnglesFromMatrix.
26
3f616de1 27Revision 1.3 2000/09/05 14:25:50 nilsen
28Made fixes for HP compiler. All function parameter default values placed
29in .h file. Fixed the usual problem with HP comilers and the "for(Int_t i..."
30business. Replaced casting (Double_t [3][3]) to (Double_t (*)[3]) for HP.
31Lastly removed all "const" before function parameters which were 2 dim. arrays,
32because on HP root generates some strange code (?). Thanks Peter for the
33changes.
34
d962cab4 35Revision 1.2 2000/08/29 20:16:50 nilsen
36New class for ITS coordiante transformations used by AliITSgeom nearly
37exclusively.
38
df5240ea 39Revision 1.1.2.1 2000/06/04 16:32:31 Nilsen
40A new class to hold the matrix information needed by AliITSgeom.
41
42*/
43#include <iostream.h>
8253cd9a 44#include <iomanip.h>
df5240ea 45#include <TMath.h>
46#include <TBuffer.h>
47
48#include "AliITSgeomMatrix.h"
49
50ClassImp(AliITSgeomMatrix)
51//----------------------------------------------------------------------
52AliITSgeomMatrix::AliITSgeomMatrix(){
53////////////////////////////////////////////////////////////////////////
54// The Default constructor for the AliITSgeomMatrix class. By Default
55// the angles of rotations are set to zero, meaning that the rotation
56// matrix is the unit matrix. The translation vector is also set to zero
57// as are the module id number. The detector type is set to -1 (an undefined
58// value). The full rotation matrix is kept so that the evaluation
59// of a coordinate transformation can be done quickly and with a minimum
60// of CPU overhead. The basic coordinate systems are the ALICE global
61// coordinate system and the detector local coordinate system. In general
62// this structure is not limited to just those two coordinate systems.
63//Begin_Html
64/*
65<img src="picts/ITS/AliISgeomMatrix_L1.gif">
66*/
67//End_Html
68////////////////////////////////////////////////////////////////////////
69 Int_t i,j;
70
71 fDetectorIndex = -1; // a value never defined.
72 for(i=0;i<3;i++){
73 fid[i] = 0;
74 frot[i] = ftran[i] = 0.0;
75 for(j=0;j<3;j++) fm[i][j] = 0.0;
76 }// end for i
77 fm[0][0] = fm[1][1] = fm[2][2] = 1.0;
78}
79//----------------------------------------------------------------------
80AliITSgeomMatrix::AliITSgeomMatrix(const AliITSgeomMatrix &sourse){
81////////////////////////////////////////////////////////////////////////
82// The standard copy constructor. This make a full / proper copy of
83// this class.
84////////////////////////////////////////////////////////////////////////
85 Int_t i,j;
86
87 this->fDetectorIndex = sourse.fDetectorIndex;
88 for(i=0;i<3;i++){
89 this->fid[i] = sourse.fid[i];
90 this->frot[i] = sourse.frot[i];
91 this->ftran[i] = sourse.ftran[i];
92 for(j=0;j<3;j++) this->fm[i][j] = sourse.fm[i][j];
93 }// end for i
94}
95//----------------------------------------------------------------------
96void AliITSgeomMatrix::operator=(const AliITSgeomMatrix &sourse){
97////////////////////////////////////////////////////////////////////////
98// The standard = operator. This make a full / proper copy of
99// this class.
100////////////////////////////////////////////////////////////////////////
101 Int_t i,j;
102
103 this->fDetectorIndex = sourse.fDetectorIndex;
104 for(i=0;i<3;i++){
105 this->fid[i] = sourse.fid[i];
106 this->frot[i] = sourse.frot[i];
107 this->ftran[i] = sourse.ftran[i];
108 for(j=0;j<3;j++) this->fm[i][j] = sourse.fm[i][j];
109 }// end for i
110}
111//----------------------------------------------------------------------
112AliITSgeomMatrix::AliITSgeomMatrix(const Int_t idt,const Int_t id[3],
113 const Double_t rot[3],const Double_t tran[3]){
114////////////////////////////////////////////////////////////////////////
115// This is a constructor for the AliITSgeomMatrix class. The matrix is
116// defined by 3 standard rotation angles [radians], and the translation
117// vector tran [cm]. In addition the layer, ladder, and detector number
118// for this particular module and the type of module must be given.
119// The full rotation matrix is kept so that the evaluation
120// of a coordinate transformation can be done quickly and with a minimum
121// of CPU overhead. The basic coordinate systems are the ALICE global
122// coordinate system and the detector local coordinate system. In general
123// this structure is not limited to just those two coordinate systems.
124//Begin_Html
125/*
126<img src="picts/ITS/AliISgeomMatrix_L1.gif">
127*/
128//End_Html
129////////////////////////////////////////////////////////////////////////
130 Int_t i;
131
132 fDetectorIndex = idt; // a value never defined.
133 for(i=0;i<3;i++){
134 fid[i] = id[i];
135 frot[i] = rot[i];
136 ftran[i] = tran[i];
137 }// end for i
138 this->MatrixFromAngle();
139}
140//----------------------------------------------------------------------
141AliITSgeomMatrix::AliITSgeomMatrix(const Int_t idt, const Int_t id[3],
d962cab4 142 Double_t matrix[3][3],
df5240ea 143 const Double_t tran[3]){
144////////////////////////////////////////////////////////////////////////
145// This is a constructor for the AliITSgeomMatrix class. The rotation matrix
146// is given as one of the inputs, and the translation vector tran [cm]. In
147// addition the layer, ladder, and detector number for this particular
148// module and the type of module must be given. The full rotation matrix
149// is kept so that the evaluation of a coordinate transformation can be
150// done quickly and with a minimum of CPU overhead. The basic coordinate
151// systems are the ALICE global coordinate system and the detector local
152// coordinate system. In general this structure is not limited to just
153// those two coordinate systems.
154//Begin_Html
155/*
156<img src="picts/ITS/AliISgeomMatrix_L1.gif">
157*/
158//End_Html
159////////////////////////////////////////////////////////////////////////
160 Int_t i,j;
161
162 fDetectorIndex = idt; // a value never defined.
163 for(i=0;i<3;i++){
164 fid[i] = id[i];
165 ftran[i] = tran[i];
166 for(j=0;j<3;j++) fm[i][j] = matrix[i][j];
167 }// end for i
168 this->AngleFromMatrix();
169}
170//----------------------------------------------------------------------
171void AliITSgeomMatrix::SixAnglesFromMatrix(Double_t *ang){
172////////////////////////////////////////////////////////////////////////
173// This function returns the 6 GEANT 3.21 rotation angles [degrees] in
174// the array ang which must be at least [6] long.
175////////////////////////////////////////////////////////////////////////
176 Double_t si,c=180./TMath::Pi();
177
178 ang[1] = TMath::ATan2(fm[0][1],fm[0][0]);
179 if(TMath::Cos(ang[1])!=0.0) si = fm[0][0]/TMath::Cos(ang[1]);
180 else si = fm[0][1]/TMath::Sin(ang[1]);
181 ang[0] = TMath::ATan2(si,fm[0][2]);
182
183 ang[3] = TMath::ATan2(fm[1][1],fm[1][0]);
184 if(TMath::Cos(ang[3])!=0.0) si = fm[1][0]/TMath::Cos(ang[3]);
185 else si = fm[1][1]/TMath::Sin(ang[3]);
3f616de1 186 ang[2] = TMath::ATan2(si,fm[1][2]);
df5240ea 187
3f616de1 188 ang[5] = TMath::ATan2(fm[2][1],fm[2][0]);
189 if(TMath::Cos(ang[5])!=0.0) si = fm[2][0]/TMath::Cos(ang[5]);
190 else si = fm[2][1]/TMath::Sin(ang[5]);
191 ang[4] = TMath::ATan2(si,fm[2][2]);
df5240ea 192
193 for(Int_t i=0;i<6;i++) {ang[i] *= c; if(ang[i]<0.0) ang[i] += 360.;}
194}
195//----------------------------------------------------------------------
196void AliITSgeomMatrix::MatrixFromSixAngles(const Double_t *ang){
197////////////////////////////////////////////////////////////////////////
198// Given the 6 GEANT 3.21 rotation angles [degree], this will compute and
199// set the rotations matrix and 3 standard rotation angles [radians].
200// These angles and rotation matrix are overwrite the existing values in
201// this class.
202////////////////////////////////////////////////////////////////////////
203 Int_t i,j;
204 Double_t si,lr[9],c=TMath::Pi()/180.;
205
206 si = TMath::Sin(c*ang[0]);
207 if(ang[0]== 90.0) si = +1.0;
208 if(ang[0]==270.0) si = -1.0;
209 if(ang[0]== 0.0||ang[0]==180.) si = 0.0;
210 lr[0] = si * TMath::Cos(c*ang[1]);
211 lr[1] = si * TMath::Sin(c*ang[1]);
212 lr[2] = TMath::Cos(c*ang[0]);
213 if(ang[0]== 90.0||ang[0]==270.) lr[2] = 0.0;
214 if(ang[0]== 0.0) lr[2] = +1.0;
215 if(ang[0]==180.0) lr[2] = -1.0;
216//
217 si = TMath::Sin(c*ang[2]);
218 if(ang[2]== 90.0) si = +1.0;
219 if(ang[2]==270.0) si = -1.0;
220 if(ang[2]== 0.0||ang[2]==180.) si = 0.0;
221 lr[3] = si * TMath::Cos(c*ang[3]);
222 lr[4] = si * TMath::Sin(c*ang[3]);
223 lr[5] = TMath::Cos(c*ang[2]);
224 if(ang[2]== 90.0||ang[2]==270.) lr[5] = 0.0;
225 if(ang[2]== 0.0) lr[5] = +1.0;
226 if(ang[2]==180.0) lr[5] = -1.0;
227//
228 si = TMath::Sin(c*ang[4]);
229 if(ang[4]== 90.0) si = +1.0;
230 if(ang[4]==270.0) si = -1.0;
231 if(ang[4]== 0.0||ang[4]==180.) si = 0.0;
232 lr[6] = si * TMath::Cos(c*ang[5]);
233 lr[7] = si * TMath::Sin(c*ang[5]);
234 lr[8] = TMath::Cos(c*ang[4]);
235 if(ang[4]== 90.0||ang[4]==270.0) lr[8] = 0.0;
236 if(ang[4]== 0.0) lr[8] = +1.0;
237 if(ang[4]==180.0) lr[8] = -1.0;
238 // Normalize these elements and fill matrix fm.
239 for(i=0;i<3;i++){// reuse si.
240 si = 0.0;
241 for(j=0;j<3;j++) si += lr[3*i+j]*lr[3*i+j];
242 si = TMath::Sqrt(1./si);
243 for(j=0;j<3;j++) fm[i][j] = si*lr[3*i+j];
244 } // end for i
245 this->AngleFromMatrix();
246}
247//----------------------------------------------------------------------
248AliITSgeomMatrix::AliITSgeomMatrix(const Double_t rotd[6]/*degrees*/,
249 const Int_t idt,const Int_t id[3],
250 const Double_t tran[3]){
251////////////////////////////////////////////////////////////////////////
252// This is a constructor for the AliITSgeomMatrix class. The matrix is
253// defined by the 6 GEANT 3.21 rotation angles [degrees], and the translation
254// vector tran [cm]. In addition the layer, ladder, and detector number
255// for this particular module and the type of module must be given.
256// The full rotation matrix is kept so that the evaluation
257// of a coordinate transformation can be done quickly and with a minimum
258// of CPU overhead. The basic coordinate systems are the ALICE global
259// coordinate system and the detector local coordinate system. In general
260// this structure is not limited to just those two coordinate systems.
261//Begin_Html
262/*
263<img src="picts/ITS/AliISgeomMatrix_L1.gif">
264*/
265//End_Html
266////////////////////////////////////////////////////////////////////////
267 Int_t i;
268
269 fDetectorIndex = idt; // a value never defined.
270 for(i=0;i<3;i++){
271 fid[i] = id[i];
272 ftran[i] = tran[i];
273 }// end for i
274 this->MatrixFromSixAngles(rotd);
275}
276//----------------------------------------------------------------------
277void AliITSgeomMatrix::AngleFromMatrix(){
278////////////////////////////////////////////////////////////////////////
279// Computes the angles from the rotation matrix up to a phase of 180 degrees.
280////////////////////////////////////////////////////////////////////////
281 Double_t rx,ry,rz;
282 // get angles from matrix up to a phase of 180 degrees.
283
284 rx = TMath::ATan2(fm[2][1],fm[2][2]);if(rx<0.0) rx += 2.0*TMath::Pi();
285 ry = TMath::ASin(fm[0][2]); if(ry<0.0) ry += 2.0*TMath::Pi();
286 rz = TMath::ATan2(fm[1][1],fm[0][0]);if(rz<0.0) rz += 2.0*TMath::Pi();
287 frot[0] = rx;
288 frot[1] = ry;
289 frot[2] = rz;
290 return;
291}
292//----------------------------------------------------------------------
293void AliITSgeomMatrix::MatrixFromAngle(){
294////////////////////////////////////////////////////////////////////////
295// Computes the Rotation matrix from the angles [radians] kept in this
296// class.
297////////////////////////////////////////////////////////////////////////
298 Double_t sx,sy,sz,cx,cy,cz;
299
300 sx = TMath::Sin(frot[0]); cx = TMath::Cos(frot[0]);
301 sy = TMath::Sin(frot[1]); cy = TMath::Cos(frot[1]);
302 sz = TMath::Sin(frot[2]); cz = TMath::Cos(frot[2]);
303 fm[0][0] = cz*cy; // fr[0]
304 fm[0][1] = -cz*sy*sx - sz*cx; // fr[1]
305 fm[0][2] = -cz*sy*cx + sz*sx; // fr[2]
306 fm[1][0] = sz*cy; // fr[3]
307 fm[1][1] = -sz*sy*sx + cz*cx; // fr[4]
308 fm[1][2] = -sz*sy*cx - cz*sx; // fr[5]
309 fm[2][0] = sy; // fr[6]
310 fm[2][1] = cy*sx; // fr[7]
311 fm[2][2] = cy*cx; // fr[8]
312
313}
314//----------------------------------------------------------------------
315void AliITSgeomMatrix::GtoLPosition(const Double_t g0[3],Double_t l[3]){
316////////////////////////////////////////////////////////////////////////
317// Returns the local coordinates given the global coordinates [cm].
318////////////////////////////////////////////////////////////////////////
319 Int_t i,j;
320 Double_t g[3];
321
322 for(i=0;i<3;i++) g[i] = g0[i] - ftran[i];
323 for(i=0;i<3;i++){
324 l[i] = 0.0;
325 for(j=0;j<3;j++) l[i] += fm[i][j]*g[j];
326 // g = R l + translation
327 } // end for i
328 return;
329}
330//----------------------------------------------------------------------
331void AliITSgeomMatrix::LtoGPosition(const Double_t l[3],Double_t g[3]){
332////////////////////////////////////////////////////////////////////////
333// Returns the global coordinates given the local coordinates [cm].
334////////////////////////////////////////////////////////////////////////
335 Int_t i,j;
336
337 for(i=0;i<3;i++){
338 g[i] = 0.0;
339 for(j=0;j<3;j++) g[i] += fm[j][i]*l[j];
340 g[i] += ftran[i];
341 // g = R^t l + translation
342 } // end for i
343 return;
344}
345//----------------------------------------------------------------------
346void AliITSgeomMatrix::GtoLMomentum(const Double_t g[3],Double_t l[3]){
347////////////////////////////////////////////////////////////////////////
348// Returns the local coordinates of the momentum given the global
349// coordinates of the momentum. It transforms just like GtoLPosition
350// except that the translation vector is zero.
351////////////////////////////////////////////////////////////////////////
352 Int_t i,j;
353
354 for(i=0;i<3;i++){
355 l[i] = 0.0;
356 for(j=0;j<3;j++) l[i] += fm[i][j]*g[j];
357 // g = R l
358 } // end for i
359 return;
360}
361//----------------------------------------------------------------------
362void AliITSgeomMatrix::LtoGMomentum(const Double_t l[3],Double_t g[3]){
363////////////////////////////////////////////////////////////////////////
364// Returns the Global coordinates of the momentum given the local
365// coordinates of the momentum. It transforms just like LtoGPosition
366// except that the translation vector is zero.
367////////////////////////////////////////////////////////////////////////
368 Int_t i,j;
369
370 for(i=0;i<3;i++){
371 g[i] = 0.0;
372 for(j=0;j<3;j++) g[i] += fm[j][i]*l[j];
373 // g = R^t l
374 } // end for i
375 return;
376}
377//----------------------------------------------------------------------
d962cab4 378void AliITSgeomMatrix::GtoLPositionError(Double_t g[3][3],
df5240ea 379 Double_t l[3][3]){
380////////////////////////////////////////////////////////////////////////
381// Given an Uncertainty matrix in Global coordinates it is rotated so that
382// its representation in local coordinates can be returned. There is no
383// effect due to the translation vector or its uncertainty.
384////////////////////////////////////////////////////////////////////////
385 Int_t i,j,k,m;
386
387 for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)for(m=0;m<3;m++)
388 l[i][m] = fm[j][i]*g[j][k]*fm[k][m];
389 // g = R^t l R
390 return;
391}
392//----------------------------------------------------------------------
d962cab4 393void AliITSgeomMatrix::LtoGPositionError(Double_t l[3][3],
df5240ea 394 Double_t g[3][3]){
395////////////////////////////////////////////////////////////////////////
396// Given an Uncertainty matrix in Local coordinates it is rotated so that
397// its representation in global coordinates can be returned. There is no
398// effect due to the translation vector or its uncertainty.
399////////////////////////////////////////////////////////////////////////
400 Int_t i,j,k,m;
401
402 for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)for(m=0;m<3;m++)
403 g[i][m] = fm[i][j]*l[j][k]*fm[m][k];
404 // g = R l R^t
405 return;
406}
407//----------------------------------------------------------------------
408void AliITSgeomMatrix::GtoLPositionTracking(const Double_t g0[3],
409 Double_t l[3]){
410////////////////////////////////////////////////////////////////////////
411// A slightly different coordinate system is used when tracking.
412// This coordinate system is only relevant when the geometry represents
413// the cylindrical ALICE ITS geometry. For tracking the Z axis is left
414// alone but X -> -Y and Y -> X such that X always points out of the
415// ITS Cylinder for every layer including layer 1 (where the detector
416// are mounted upside down).
417//Begin_Html
418/*
419<img src="picts/ITS/AliITSgeomMatrix_T1.gif">
420 */
421//End_Html
422////////////////////////////////////////////////////////////////////////
423 Double_t l0[3];
424
425 this->GtoLPosition(g0,l0);
426 if(fid[0]==1){ // for layer 1 the detector are flipped upside down
427 // with respect to the others.
428 l[0] = +l0[1];
429 l[1] = -l0[0];
430 l[2] = +l0[2];
431 }else{
432 l[0] = -l0[1];
433 l[1] = +l0[0];
434 l[2] = +l0[2];
435 } // end if
436 return;
437}
438//----------------------------------------------------------------------
439void AliITSgeomMatrix::LtoGPositionTracking(const Double_t l[3],
440 Double_t g[3]){
441////////////////////////////////////////////////////////////////////////
442// A slightly different coordinate system is used when tracking.
443// This coordinate system is only relevant when the geometry represents
444// the cylindrical ALICE ITS geometry. For tracking the Z axis is left
445// alone but X -> -Y and Y -> X such that X always points out of the
446// ITS Cylinder for every layer including layer 1 (where the detector
447// are mounted upside down).
448//Begin_Html
449/*
450<img src="picts/ITS/AliITSgeomMatrix_T1.gif">
451 */
452//End_Html
453////////////////////////////////////////////////////////////////////////
454 Double_t l0[3];
455
456 if(fid[0]==1){ // for layer 1 the detector are flipped upside down
457 // with respect to the others.
458 l0[0] = -l[1];
459 l0[1] = +l[0];
460 l0[2] = +l[2];
461 }else{
462 l0[0] = +l[1];
463 l0[1] = -l[0];
464 l0[2] = +l[2];
465 } // end if
466 this->LtoGPosition(l0,g);
467 return;
468}
469//----------------------------------------------------------------------
470void AliITSgeomMatrix::GtoLMomentumTracking(const Double_t g[3],
471 Double_t l[3]){
472////////////////////////////////////////////////////////////////////////
473// A slightly different coordinate system is used when tracking.
474// This coordinate system is only relevant when the geometry represents
475// the cylindrical ALICE ITS geometry. For tracking the Z axis is left
476// alone but X -> -Y and Y -> X such that X always points out of the
477// ITS Cylinder for every layer including layer 1 (where the detector
478// are mounted upside down).
479//Begin_Html
480/*
481<img src="picts/ITS/AliITSgeomMatrix_T1.gif">
482 */
483//End_Html
484////////////////////////////////////////////////////////////////////////
485 Double_t l0[3];
486
487 this->GtoLMomentum(g,l0);
488 if(fid[0]==1){ // for layer 1 the detector are flipped upside down
489 // with respect to the others.
490 l[0] = +l0[1];
491 l[1] = -l0[0];
492 l[2] = +l0[2];
493 }else{
494 l[0] = -l0[1];
495 l[1] = +l0[0];
496 l[2] = +l0[2];
497 } // end if
498 return;
499 return;
500}
501//----------------------------------------------------------------------
502void AliITSgeomMatrix::LtoGMomentumTracking(const Double_t l[3],
503 Double_t g[3]){
504////////////////////////////////////////////////////////////////////////
505// A slightly different coordinate system is used when tracking.
506// This coordinate system is only relevant when the geometry represents
507// the cylindrical ALICE ITS geometry. For tracking the Z axis is left
508// alone but X -> -Y and Y -> X such that X always points out of the
509// ITS Cylinder for every layer including layer 1 (where the detector
510// are mounted upside down).
511//Begin_Html
512/*
513<img src="picts/ITS/AliITSgeomMatrix_T1.gif">
514 */
515//End_Html
516////////////////////////////////////////////////////////////////////////
517 Double_t l0[3];
518
519 if(fid[0]==1){ // for layer 1 the detector are flipped upside down
520 // with respect to the others.
521 l0[0] = -l[1];
522 l0[1] = +l[0];
523 l0[2] = +l[2];
524 }else{
525 l0[0] = +l[1];
526 l0[1] = -l[0];
527 l0[2] = +l[2];
528 } // end if
529 this->LtoGMomentum(l0,g);
530 return;
531}
532//----------------------------------------------------------------------
d962cab4 533void AliITSgeomMatrix::GtoLPositionErrorTracking(Double_t g[3][3],
df5240ea 534 Double_t l[3][3]){
535////////////////////////////////////////////////////////////////////////
536// A slightly different coordinate system is used when tracking.
537// This coordinate system is only relevant when the geometry represents
538// the cylindrical ALICE ITS geometry. For tracking the Z axis is left
539// alone but X -> -Y and Y -> X such that X always points out of the
540// ITS Cylinder for every layer including layer 1 (where the detector
541// are mounted upside down).
542//Begin_Html
543/*
544<img src="picts/ITS/AliITSgeomMatrix_T1.gif">
545 */
546//End_Html
547////////////////////////////////////////////////////////////////////////
548 Int_t i,j,k,m;
549 Double_t Rt[3][3];
550 Double_t A0[3][3] = {{0.,+1.,0.},{-1.,0.,0.},{0.,0.,+1.}};
551 Double_t A1[3][3] = {{0.,-1.,0.},{+1.,0.,0.},{0.,0.,+1.}};
552
553 if(fid[0]==1) for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)
554 Rt[i][k] = A0[i][j]*fm[j][k];
555 else for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)
556 Rt[i][k] = A1[i][j]*fm[j][k];
557 for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)for(m=0;m<3;m++)
558 l[i][m] = Rt[j][i]*g[j][k]*Rt[k][m];
559 // g = R^t l R
560 return;
561}
562//----------------------------------------------------------------------
d962cab4 563void AliITSgeomMatrix::LtoGPositionErrorTracking(Double_t l[3][3],
df5240ea 564 Double_t g[3][3]){
565////////////////////////////////////////////////////////////////////////
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).
572//Begin_Html
573/*
574<img src="picts/ITS/AliITSgeomMatrix_T1.gif">
575 */
576//End_Html
577////////////////////////////////////////////////////////////////////////
578 Int_t i,j,k,m;
579 Double_t Rt[3][3];
580 Double_t A0[3][3] = {{0.,+1.,0.},{-1.,0.,0.},{0.,0.,+1.}};
581 Double_t A1[3][3] = {{0.,-1.,0.},{+1.,0.,0.},{0.,0.,+1.}};
582
583 if(fid[0]==1) for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)
584 Rt[i][k] = A0[i][j]*fm[j][k];
585 else for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)
586 Rt[i][k] = A1[i][j]*fm[j][k];
587 for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)for(m=0;m<3;m++)
588 g[i][m] = Rt[i][j]*l[j][k]*Rt[m][k];
589 // g = R l R^t
590 return;
591}
592//----------------------------------------------------------------------
593void AliITSgeomMatrix::PrintTitles(ostream *os){
594////////////////////////////////////////////////////////////////////////
595// Standard output format for this class but it includes variable
596// names and formatting that makes it easer to read.
597////////////////////////////////////////////////////////////////////////
598 Int_t i,j;
599
600 *os << "fDetectorIndex=" << fDetectorIndex << " fid[3]={";
601 for(i=0;i<3;i++) *os << fid[i] << " ";
602 *os << "} frot[3]={";
603 for(i=0;i<3;i++) *os << frot[i] << " ";
604 *os << "} ftran[3]={";
605 for(i=0;i<3;i++) *os << ftran[i] << " ";
606 *os << "} fm[3][3]={";
607 for(i=0;i<3;i++){for(j=0;j<3;j++){ *os << fm[i][j] << " ";} *os <<"}{";}
608 *os << "}" << endl;
609 return;
610}
611//----------------------------------------------------------------------
8253cd9a 612void AliITSgeomMatrix::PrintComment(ostream *os){
613////////////////////////////////////////////////////////////////////////
614// output format used by Print..
615////////////////////////////////////////////////////////////////////////
616 *os << "fDetectorIndex fid[0] fid[1] fid[2] ftran[0] ftran[1] ftran[2] ";
617 *os << "fm[0][0] fm[0][1] fm[0][2] fm[1][0] fm[1][1] fm[1][2] ";
618 *os << "fm[2][0] fm[2][1] fm[2][2] ";
619 return;
620}
621//----------------------------------------------------------------------
622void AliITSgeomMatrix::Print(ostream *os){
df5240ea 623////////////////////////////////////////////////////////////////////////
624// Standard output format for this class.
625////////////////////////////////////////////////////////////////////////
626 Int_t i,j;
8253cd9a 627 ios::fmtflags fmt;
df5240ea 628
8253cd9a 629 fmt = os->setf(ios::scientific); // set scientific floating point output
df5240ea 630 *os << fDetectorIndex << " ";
631 for(i=0;i<3;i++) *os << fid[i] << " ";
8253cd9a 632// for(i=0;i<3;i++) *os << frot[i] << " "; // Redundant with fm[][].
633 for(i=0;i<3;i++) *os << setprecision(16) << ftran[i] << " ";
634 for(i=0;i<3;i++)for(j=0;j<3;j++) *os << setprecision(16) <<
635 fm[i][j] << " ";
df5240ea 636 *os << endl;
8253cd9a 637 os->flags(fmt); // reset back to old formating.
df5240ea 638 return;
639}
640//----------------------------------------------------------------------
8253cd9a 641void AliITSgeomMatrix::Read(istream *is){
df5240ea 642////////////////////////////////////////////////////////////////////////
643// Standard input format for this class.
644////////////////////////////////////////////////////////////////////////
645 Int_t i,j;
646
647 *is >> fDetectorIndex;
648 for(i=0;i<3;i++) *is >> fid[i];
8253cd9a 649// for(i=0;i<3;i++) *is >> frot[i]; // Redundant with fm[][].
df5240ea 650 for(i=0;i<3;i++) *is >> ftran[i];
651 for(i=0;i<3;i++)for(j=0;j<3;j++) *is >> fm[i][j];
8253cd9a 652 AngleFromMatrix(); // compute angles frot[].
df5240ea 653 return;
654}
655//----------------------------------------------------------------------
656ostream &operator<<(ostream &os,AliITSgeomMatrix &p){
657////////////////////////////////////////////////////////////////////////
658// Standard output streaming function.
659////////////////////////////////////////////////////////////////////////
660
8253cd9a 661 p.Print(&os);
df5240ea 662 return os;
663}
664//----------------------------------------------------------------------
665istream &operator>>(istream &is,AliITSgeomMatrix &r){
666////////////////////////////////////////////////////////////////////////
667// Standard input streaming function.
668////////////////////////////////////////////////////////////////////////
669
8253cd9a 670 r.Read(&is);
df5240ea 671 return is;
672}
8253cd9a 673//----------------------------------------------------------------------