Changes needed by ICC/IFC compiler (Intel)
[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$
94831058 18Revision 1.13 2002/01/28 21:49:19 nilsen
19Fixed a logical bug in functions GtoLPositionError, LtoGPositionError,
20GtoLPositionErrorTracking, and LtoGPositionErrorTracking.
21
ecb0c8bc 22Revision 1.12 2001/10/12 22:07:20 nilsen
23A patch for C++ io manipulation functions so that they will work both
24with GNU gcc 2.96 and GNU gcc 3.01 compilers. Needs to be tested with
25other platforms.
26
431a7819 27Revision 1.11 2001/09/04 14:54:31 hristov
28Const multidimentional arrays cause problems in the CINT dictionary on HP, const removed
29
8d5bd3f9 30Revision 1.10 2001/08/24 21:06:37 nilsen
31Added more documentation, fixed up some coding violations, and some
32forward declorations.
33
85f1e34a 34Revision 1.9 2001/03/23 15:21:56 nilsen
35Added Cylinderical Coordinates for use with Tracking. Fixed a but in the
36Streamer, It was not setting a value for frot[3] as it should when reading.
37
d8cc8493 38Revision 1.8 2001/02/09 00:00:57 nilsen
39Fixed compatibility problem with HP unix {ios::fmtflags -> Int_t}. Fixed
40bugs in iostream based streamers used to read and write .det files. Fixed
41some detector sizes. Fixed bugs in some default-special constructors.
42
31b8cd63 43Revision 1.7 2001/02/03 00:00:30 nilsen
44New version of AliITSgeom and related files. Now uses automatic streamers,
45set up for new formatted .det file which includes detector information.
46Additional smaller modifications are still to come.
47
a8a6107b 48Revision 1.5 2000/10/02 16:32:35 barbera
49Forward declaration added
50
92c19c36 51Revision 1.1.2.6 2000/10/02 15:52:05 barbera
52Forward declaration added
53
54Revision 1.4 2000/09/07 17:30:45 nilsen
55fixed a bug in SixAnglesFromMatrix.
56
3f616de1 57Revision 1.3 2000/09/05 14:25:50 nilsen
58Made fixes for HP compiler. All function parameter default values placed
59in .h file. Fixed the usual problem with HP comilers and the "for(Int_t i..."
60business. Replaced casting (Double_t [3][3]) to (Double_t (*)[3]) for HP.
61Lastly removed all "const" before function parameters which were 2 dim. arrays,
62because on HP root generates some strange code (?). Thanks Peter for the
63changes.
64
d962cab4 65Revision 1.2 2000/08/29 20:16:50 nilsen
66New class for ITS coordiante transformations used by AliITSgeom nearly
67exclusively.
68
df5240ea 69Revision 1.1.2.1 2000/06/04 16:32:31 Nilsen
70A new class to hold the matrix information needed by AliITSgeom.
71
72*/
85f1e34a 73
74////////////////////////////////////////////////////////////////////////
75// This is the implementation file for AliITSgeomMatrix class. It
76// contains the routines to manipulate, setup, and queary the geometry
77// of a given ITS module. An ITS module may be one of at least three
78// ITS detector technologies, Silicon Pixel, Drift, or Strip Detectors,
79// and variations of these in size and/or layout. These routines let
80// one go between ALICE global coordiantes (cm) to a given modules
81// specific local coordinates (cm).
82////////////////////////////////////////////////////////////////////////
83
df5240ea 84#include <iostream.h>
8253cd9a 85#include <iomanip.h>
df5240ea 86#include <TMath.h>
87#include <TBuffer.h>
d8cc8493 88#include <TClass.h>
df5240ea 89
90#include "AliITSgeomMatrix.h"
91
92ClassImp(AliITSgeomMatrix)
93//----------------------------------------------------------------------
94AliITSgeomMatrix::AliITSgeomMatrix(){
95////////////////////////////////////////////////////////////////////////
96// The Default constructor for the AliITSgeomMatrix class. By Default
97// the angles of rotations are set to zero, meaning that the rotation
98// matrix is the unit matrix. The translation vector is also set to zero
99// as are the module id number. The detector type is set to -1 (an undefined
100// value). The full rotation matrix is kept so that the evaluation
101// of a coordinate transformation can be done quickly and with a minimum
102// of CPU overhead. The basic coordinate systems are the ALICE global
103// coordinate system and the detector local coordinate system. In general
104// this structure is not limited to just those two coordinate systems.
105//Begin_Html
106/*
107<img src="picts/ITS/AliISgeomMatrix_L1.gif">
108*/
109//End_Html
110////////////////////////////////////////////////////////////////////////
111 Int_t i,j;
112
113 fDetectorIndex = -1; // a value never defined.
114 for(i=0;i<3;i++){
115 fid[i] = 0;
116 frot[i] = ftran[i] = 0.0;
117 for(j=0;j<3;j++) fm[i][j] = 0.0;
d8cc8493 118 fCylR = fCylPhi = 0.0;
df5240ea 119 }// end for i
120 fm[0][0] = fm[1][1] = fm[2][2] = 1.0;
121}
122//----------------------------------------------------------------------
123AliITSgeomMatrix::AliITSgeomMatrix(const AliITSgeomMatrix &sourse){
124////////////////////////////////////////////////////////////////////////
125// The standard copy constructor. This make a full / proper copy of
126// this class.
127////////////////////////////////////////////////////////////////////////
128 Int_t i,j;
129
130 this->fDetectorIndex = sourse.fDetectorIndex;
131 for(i=0;i<3;i++){
132 this->fid[i] = sourse.fid[i];
133 this->frot[i] = sourse.frot[i];
134 this->ftran[i] = sourse.ftran[i];
d8cc8493 135 this->fCylR = sourse.fCylR;
136 this->fCylPhi = sourse.fCylPhi;
df5240ea 137 for(j=0;j<3;j++) this->fm[i][j] = sourse.fm[i][j];
138 }// end for i
139}
140//----------------------------------------------------------------------
141void AliITSgeomMatrix::operator=(const AliITSgeomMatrix &sourse){
142////////////////////////////////////////////////////////////////////////
143// The standard = operator. This make a full / proper copy of
144// this class.
145////////////////////////////////////////////////////////////////////////
146 Int_t i,j;
147
148 this->fDetectorIndex = sourse.fDetectorIndex;
149 for(i=0;i<3;i++){
150 this->fid[i] = sourse.fid[i];
151 this->frot[i] = sourse.frot[i];
152 this->ftran[i] = sourse.ftran[i];
d8cc8493 153 this->fCylR = sourse.fCylR;
154 this->fCylPhi = sourse.fCylPhi;
df5240ea 155 for(j=0;j<3;j++) this->fm[i][j] = sourse.fm[i][j];
156 }// end for i
157}
158//----------------------------------------------------------------------
159AliITSgeomMatrix::AliITSgeomMatrix(const Int_t idt,const Int_t id[3],
160 const Double_t rot[3],const Double_t tran[3]){
161////////////////////////////////////////////////////////////////////////
162// This is a constructor for the AliITSgeomMatrix class. The matrix is
163// defined by 3 standard rotation angles [radians], and the translation
164// vector tran [cm]. In addition the layer, ladder, and detector number
165// for this particular module and the type of module must be given.
166// The full rotation matrix is kept so that the evaluation
167// of a coordinate transformation can be done quickly and with a minimum
168// of CPU overhead. The basic coordinate systems are the ALICE global
169// coordinate system and the detector local coordinate system. In general
170// this structure is not limited to just those two coordinate systems.
171//Begin_Html
172/*
173<img src="picts/ITS/AliISgeomMatrix_L1.gif">
174*/
175//End_Html
176////////////////////////////////////////////////////////////////////////
d8cc8493 177 Int_t i;
df5240ea 178
d8cc8493 179 fDetectorIndex = idt; // a value never defined.
180 for(i=0;i<3;i++){
181 fid[i] = id[i];
182 frot[i] = rot[i];
183 ftran[i] = tran[i];
184 }// end for i
185 fCylR = TMath::Sqrt(ftran[0]*ftran[0]+ftran[1]*ftran[1]);
186 fCylPhi = TMath::ATan2(ftran[1],ftran[0]);
187 if(fCylPhi<0.0) fCylPhi += TMath::Pi();
188 this->MatrixFromAngle();
df5240ea 189}
190//----------------------------------------------------------------------
191AliITSgeomMatrix::AliITSgeomMatrix(const Int_t idt, const Int_t id[3],
d962cab4 192 Double_t matrix[3][3],
df5240ea 193 const Double_t tran[3]){
194////////////////////////////////////////////////////////////////////////
195// This is a constructor for the AliITSgeomMatrix class. The rotation matrix
196// is given as one of the inputs, and the translation vector tran [cm]. In
197// addition the layer, ladder, and detector number for this particular
198// module and the type of module must be given. The full rotation matrix
199// is kept so that the evaluation of a coordinate transformation can be
200// done quickly and with a minimum of CPU overhead. The basic coordinate
201// systems are the ALICE global coordinate system and the detector local
202// coordinate system. In general this structure is not limited to just
203// those two coordinate systems.
204//Begin_Html
205/*
206<img src="picts/ITS/AliISgeomMatrix_L1.gif">
207*/
208//End_Html
209////////////////////////////////////////////////////////////////////////
d8cc8493 210 Int_t i,j;
df5240ea 211
d8cc8493 212 fDetectorIndex = idt; // a value never defined.
213 for(i=0;i<3;i++){
214 fid[i] = id[i];
215 ftran[i] = tran[i];
216 for(j=0;j<3;j++) fm[i][j] = matrix[i][j];
217 }// end for i
218 fCylR = TMath::Sqrt(ftran[0]*ftran[0]+ftran[1]*ftran[1]);
219 fCylPhi = TMath::ATan2(ftran[1],ftran[0]);
220 if(fCylPhi<0.0) fCylPhi += TMath::Pi();
221 this->AngleFromMatrix();
df5240ea 222}
223//----------------------------------------------------------------------
224void AliITSgeomMatrix::SixAnglesFromMatrix(Double_t *ang){
225////////////////////////////////////////////////////////////////////////
226// This function returns the 6 GEANT 3.21 rotation angles [degrees] in
227// the array ang which must be at least [6] long.
228////////////////////////////////////////////////////////////////////////
229 Double_t si,c=180./TMath::Pi();
230
231 ang[1] = TMath::ATan2(fm[0][1],fm[0][0]);
232 if(TMath::Cos(ang[1])!=0.0) si = fm[0][0]/TMath::Cos(ang[1]);
233 else si = fm[0][1]/TMath::Sin(ang[1]);
234 ang[0] = TMath::ATan2(si,fm[0][2]);
235
236 ang[3] = TMath::ATan2(fm[1][1],fm[1][0]);
237 if(TMath::Cos(ang[3])!=0.0) si = fm[1][0]/TMath::Cos(ang[3]);
238 else si = fm[1][1]/TMath::Sin(ang[3]);
3f616de1 239 ang[2] = TMath::ATan2(si,fm[1][2]);
df5240ea 240
3f616de1 241 ang[5] = TMath::ATan2(fm[2][1],fm[2][0]);
242 if(TMath::Cos(ang[5])!=0.0) si = fm[2][0]/TMath::Cos(ang[5]);
243 else si = fm[2][1]/TMath::Sin(ang[5]);
244 ang[4] = TMath::ATan2(si,fm[2][2]);
df5240ea 245
246 for(Int_t i=0;i<6;i++) {ang[i] *= c; if(ang[i]<0.0) ang[i] += 360.;}
247}
248//----------------------------------------------------------------------
249void AliITSgeomMatrix::MatrixFromSixAngles(const Double_t *ang){
250////////////////////////////////////////////////////////////////////////
251// Given the 6 GEANT 3.21 rotation angles [degree], this will compute and
252// set the rotations matrix and 3 standard rotation angles [radians].
253// These angles and rotation matrix are overwrite the existing values in
254// this class.
255////////////////////////////////////////////////////////////////////////
256 Int_t i,j;
257 Double_t si,lr[9],c=TMath::Pi()/180.;
258
259 si = TMath::Sin(c*ang[0]);
260 if(ang[0]== 90.0) si = +1.0;
261 if(ang[0]==270.0) si = -1.0;
262 if(ang[0]== 0.0||ang[0]==180.) si = 0.0;
263 lr[0] = si * TMath::Cos(c*ang[1]);
264 lr[1] = si * TMath::Sin(c*ang[1]);
265 lr[2] = TMath::Cos(c*ang[0]);
266 if(ang[0]== 90.0||ang[0]==270.) lr[2] = 0.0;
267 if(ang[0]== 0.0) lr[2] = +1.0;
268 if(ang[0]==180.0) lr[2] = -1.0;
269//
270 si = TMath::Sin(c*ang[2]);
271 if(ang[2]== 90.0) si = +1.0;
272 if(ang[2]==270.0) si = -1.0;
273 if(ang[2]== 0.0||ang[2]==180.) si = 0.0;
274 lr[3] = si * TMath::Cos(c*ang[3]);
275 lr[4] = si * TMath::Sin(c*ang[3]);
276 lr[5] = TMath::Cos(c*ang[2]);
277 if(ang[2]== 90.0||ang[2]==270.) lr[5] = 0.0;
278 if(ang[2]== 0.0) lr[5] = +1.0;
279 if(ang[2]==180.0) lr[5] = -1.0;
280//
281 si = TMath::Sin(c*ang[4]);
282 if(ang[4]== 90.0) si = +1.0;
283 if(ang[4]==270.0) si = -1.0;
284 if(ang[4]== 0.0||ang[4]==180.) si = 0.0;
285 lr[6] = si * TMath::Cos(c*ang[5]);
286 lr[7] = si * TMath::Sin(c*ang[5]);
287 lr[8] = TMath::Cos(c*ang[4]);
288 if(ang[4]== 90.0||ang[4]==270.0) lr[8] = 0.0;
289 if(ang[4]== 0.0) lr[8] = +1.0;
290 if(ang[4]==180.0) lr[8] = -1.0;
291 // Normalize these elements and fill matrix fm.
292 for(i=0;i<3;i++){// reuse si.
293 si = 0.0;
294 for(j=0;j<3;j++) si += lr[3*i+j]*lr[3*i+j];
295 si = TMath::Sqrt(1./si);
296 for(j=0;j<3;j++) fm[i][j] = si*lr[3*i+j];
297 } // end for i
298 this->AngleFromMatrix();
299}
300//----------------------------------------------------------------------
301AliITSgeomMatrix::AliITSgeomMatrix(const Double_t rotd[6]/*degrees*/,
302 const Int_t idt,const Int_t id[3],
303 const Double_t tran[3]){
304////////////////////////////////////////////////////////////////////////
305// This is a constructor for the AliITSgeomMatrix class. The matrix is
306// defined by the 6 GEANT 3.21 rotation angles [degrees], and the translation
307// vector tran [cm]. In addition the layer, ladder, and detector number
308// for this particular module and the type of module must be given.
309// The full rotation matrix is kept so that the evaluation
310// of a coordinate transformation can be done quickly and with a minimum
311// of CPU overhead. The basic coordinate systems are the ALICE global
312// coordinate system and the detector local coordinate system. In general
313// this structure is not limited to just those two coordinate systems.
314//Begin_Html
315/*
316<img src="picts/ITS/AliISgeomMatrix_L1.gif">
317*/
318//End_Html
319////////////////////////////////////////////////////////////////////////
320 Int_t i;
321
322 fDetectorIndex = idt; // a value never defined.
323 for(i=0;i<3;i++){
324 fid[i] = id[i];
325 ftran[i] = tran[i];
326 }// end for i
d8cc8493 327 fCylR = TMath::Sqrt(ftran[0]*ftran[0]+ftran[1]*ftran[1]);
328 fCylPhi = TMath::ATan2(ftran[1],ftran[0]);
329 if(fCylPhi<0.0) fCylPhi += TMath::Pi();
df5240ea 330 this->MatrixFromSixAngles(rotd);
331}
332//----------------------------------------------------------------------
333void AliITSgeomMatrix::AngleFromMatrix(){
334////////////////////////////////////////////////////////////////////////
335// Computes the angles from the rotation matrix up to a phase of 180 degrees.
336////////////////////////////////////////////////////////////////////////
337 Double_t rx,ry,rz;
338 // get angles from matrix up to a phase of 180 degrees.
339
340 rx = TMath::ATan2(fm[2][1],fm[2][2]);if(rx<0.0) rx += 2.0*TMath::Pi();
341 ry = TMath::ASin(fm[0][2]); if(ry<0.0) ry += 2.0*TMath::Pi();
342 rz = TMath::ATan2(fm[1][1],fm[0][0]);if(rz<0.0) rz += 2.0*TMath::Pi();
343 frot[0] = rx;
344 frot[1] = ry;
345 frot[2] = rz;
346 return;
347}
348//----------------------------------------------------------------------
349void AliITSgeomMatrix::MatrixFromAngle(){
350////////////////////////////////////////////////////////////////////////
351// Computes the Rotation matrix from the angles [radians] kept in this
352// class.
353////////////////////////////////////////////////////////////////////////
354 Double_t sx,sy,sz,cx,cy,cz;
355
356 sx = TMath::Sin(frot[0]); cx = TMath::Cos(frot[0]);
357 sy = TMath::Sin(frot[1]); cy = TMath::Cos(frot[1]);
358 sz = TMath::Sin(frot[2]); cz = TMath::Cos(frot[2]);
359 fm[0][0] = cz*cy; // fr[0]
360 fm[0][1] = -cz*sy*sx - sz*cx; // fr[1]
361 fm[0][2] = -cz*sy*cx + sz*sx; // fr[2]
362 fm[1][0] = sz*cy; // fr[3]
363 fm[1][1] = -sz*sy*sx + cz*cx; // fr[4]
364 fm[1][2] = -sz*sy*cx - cz*sx; // fr[5]
365 fm[2][0] = sy; // fr[6]
366 fm[2][1] = cy*sx; // fr[7]
367 fm[2][2] = cy*cx; // fr[8]
368
369}
370//----------------------------------------------------------------------
371void AliITSgeomMatrix::GtoLPosition(const Double_t g0[3],Double_t l[3]){
372////////////////////////////////////////////////////////////////////////
373// Returns the local coordinates given the global coordinates [cm].
374////////////////////////////////////////////////////////////////////////
375 Int_t i,j;
376 Double_t g[3];
377
378 for(i=0;i<3;i++) g[i] = g0[i] - ftran[i];
379 for(i=0;i<3;i++){
380 l[i] = 0.0;
381 for(j=0;j<3;j++) l[i] += fm[i][j]*g[j];
382 // g = R l + translation
383 } // end for i
384 return;
385}
386//----------------------------------------------------------------------
387void AliITSgeomMatrix::LtoGPosition(const Double_t l[3],Double_t g[3]){
388////////////////////////////////////////////////////////////////////////
389// Returns the global coordinates given the local coordinates [cm].
390////////////////////////////////////////////////////////////////////////
391 Int_t i,j;
392
393 for(i=0;i<3;i++){
394 g[i] = 0.0;
395 for(j=0;j<3;j++) g[i] += fm[j][i]*l[j];
396 g[i] += ftran[i];
397 // g = R^t l + translation
398 } // end for i
399 return;
400}
401//----------------------------------------------------------------------
402void AliITSgeomMatrix::GtoLMomentum(const Double_t g[3],Double_t l[3]){
403////////////////////////////////////////////////////////////////////////
404// Returns the local coordinates of the momentum given the global
405// coordinates of the momentum. It transforms just like GtoLPosition
406// except that the translation vector is zero.
407////////////////////////////////////////////////////////////////////////
408 Int_t i,j;
409
410 for(i=0;i<3;i++){
411 l[i] = 0.0;
412 for(j=0;j<3;j++) l[i] += fm[i][j]*g[j];
413 // g = R l
414 } // end for i
415 return;
416}
417//----------------------------------------------------------------------
418void AliITSgeomMatrix::LtoGMomentum(const Double_t l[3],Double_t g[3]){
419////////////////////////////////////////////////////////////////////////
420// Returns the Global coordinates of the momentum given the local
421// coordinates of the momentum. It transforms just like LtoGPosition
422// except that the translation vector is zero.
423////////////////////////////////////////////////////////////////////////
424 Int_t i,j;
425
426 for(i=0;i<3;i++){
427 g[i] = 0.0;
428 for(j=0;j<3;j++) g[i] += fm[j][i]*l[j];
429 // g = R^t l
430 } // end for i
431 return;
432}
433//----------------------------------------------------------------------
8d5bd3f9 434void AliITSgeomMatrix::GtoLPositionError( Double_t g[3][3],
df5240ea 435 Double_t l[3][3]){
436////////////////////////////////////////////////////////////////////////
437// Given an Uncertainty matrix in Global coordinates it is rotated so that
438// its representation in local coordinates can be returned. There is no
439// effect due to the translation vector or its uncertainty.
440////////////////////////////////////////////////////////////////////////
441 Int_t i,j,k,m;
442
ecb0c8bc 443 for(i=0;i<3;i++)for(m=0;m<3;m++){
444 l[i][m] = 0.0;
445 for(j=0;j<3;j++)for(k=0;k<3;k++)
446 l[i][m] += fm[j][i]*g[j][k]*fm[k][m];
447 } // end for i,m
448 // g = R^t l R
df5240ea 449 return;
450}
451//----------------------------------------------------------------------
8d5bd3f9 452void AliITSgeomMatrix::LtoGPositionError( Double_t l[3][3],
df5240ea 453 Double_t g[3][3]){
454////////////////////////////////////////////////////////////////////////
455// Given an Uncertainty matrix in Local coordinates it is rotated so that
456// its representation in global coordinates can be returned. There is no
457// effect due to the translation vector or its uncertainty.
458////////////////////////////////////////////////////////////////////////
459 Int_t i,j,k,m;
460
ecb0c8bc 461 for(i=0;i<3;i++)for(m=0;m<3;m++){
462 g[i][m] = 0.0;
463 for(j=0;j<3;j++)for(k=0;k<3;k++)
464 g[i][m] += fm[i][j]*l[j][k]*fm[m][k];
465 } // end for i,m
466 // g = R l R^t
df5240ea 467 return;
468}
469//----------------------------------------------------------------------
470void AliITSgeomMatrix::GtoLPositionTracking(const Double_t g0[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->GtoLPosition(g0,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}
500//----------------------------------------------------------------------
501void AliITSgeomMatrix::LtoGPositionTracking(const Double_t l[3],
502 Double_t g[3]){
503////////////////////////////////////////////////////////////////////////
504// A slightly different coordinate system is used when tracking.
505// This coordinate system is only relevant when the geometry represents
506// the cylindrical ALICE ITS geometry. For tracking the Z axis is left
507// alone but X -> -Y and Y -> X such that X always points out of the
508// ITS Cylinder for every layer including layer 1 (where the detector
509// are mounted upside down).
510//Begin_Html
511/*
512<img src="picts/ITS/AliITSgeomMatrix_T1.gif">
513 */
514//End_Html
515////////////////////////////////////////////////////////////////////////
516 Double_t l0[3];
517
518 if(fid[0]==1){ // for layer 1 the detector are flipped upside down
519 // with respect to the others.
520 l0[0] = -l[1];
521 l0[1] = +l[0];
522 l0[2] = +l[2];
523 }else{
524 l0[0] = +l[1];
525 l0[1] = -l[0];
526 l0[2] = +l[2];
527 } // end if
528 this->LtoGPosition(l0,g);
529 return;
530}
531//----------------------------------------------------------------------
532void AliITSgeomMatrix::GtoLMomentumTracking(const Double_t g[3],
533 Double_t l[3]){
534////////////////////////////////////////////////////////////////////////
535// A slightly different coordinate system is used when tracking.
536// This coordinate system is only relevant when the geometry represents
537// the cylindrical ALICE ITS geometry. For tracking the Z axis is left
538// alone but X -> -Y and Y -> X such that X always points out of the
539// ITS Cylinder for every layer including layer 1 (where the detector
540// are mounted upside down).
541//Begin_Html
542/*
543<img src="picts/ITS/AliITSgeomMatrix_T1.gif">
544 */
545//End_Html
546////////////////////////////////////////////////////////////////////////
547 Double_t l0[3];
548
549 this->GtoLMomentum(g,l0);
550 if(fid[0]==1){ // for layer 1 the detector are flipped upside down
551 // with respect to the others.
552 l[0] = +l0[1];
553 l[1] = -l0[0];
554 l[2] = +l0[2];
555 }else{
556 l[0] = -l0[1];
557 l[1] = +l0[0];
558 l[2] = +l0[2];
559 } // end if
560 return;
561 return;
562}
563//----------------------------------------------------------------------
564void AliITSgeomMatrix::LtoGMomentumTracking(const Double_t l[3],
565 Double_t g[3]){
566////////////////////////////////////////////////////////////////////////
567// A slightly different coordinate system is used when tracking.
568// This coordinate system is only relevant when the geometry represents
569// the cylindrical ALICE ITS geometry. For tracking the Z axis is left
570// alone but X -> -Y and Y -> X such that X always points out of the
571// ITS Cylinder for every layer including layer 1 (where the detector
572// are mounted upside down).
573//Begin_Html
574/*
575<img src="picts/ITS/AliITSgeomMatrix_T1.gif">
576 */
577//End_Html
578////////////////////////////////////////////////////////////////////////
579 Double_t l0[3];
580
581 if(fid[0]==1){ // for layer 1 the detector are flipped upside down
582 // with respect to the others.
583 l0[0] = -l[1];
584 l0[1] = +l[0];
585 l0[2] = +l[2];
586 }else{
587 l0[0] = +l[1];
588 l0[1] = -l[0];
589 l0[2] = +l[2];
590 } // end if
591 this->LtoGMomentum(l0,g);
592 return;
593}
594//----------------------------------------------------------------------
8d5bd3f9 595void AliITSgeomMatrix::GtoLPositionErrorTracking( Double_t g[3][3],
df5240ea 596 Double_t l[3][3]){
597////////////////////////////////////////////////////////////////////////
598// A slightly different coordinate system is used when tracking.
599// This coordinate system is only relevant when the geometry represents
600// the cylindrical ALICE ITS geometry. For tracking the Z axis is left
601// alone but X -> -Y and Y -> X such that X always points out of the
602// ITS Cylinder for every layer including layer 1 (where the detector
603// are mounted upside down).
604//Begin_Html
605/*
606<img src="picts/ITS/AliITSgeomMatrix_T1.gif">
607 */
608//End_Html
609////////////////////////////////////////////////////////////////////////
610 Int_t i,j,k,m;
85f1e34a 611 Double_t rt[3][3];
612 Double_t a0[3][3] = {{0.,+1.,0.},{-1.,0.,0.},{0.,0.,+1.}};
613 Double_t a1[3][3] = {{0.,-1.,0.},{+1.,0.,0.},{0.,0.,+1.}};
df5240ea 614
615 if(fid[0]==1) for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)
85f1e34a 616 rt[i][k] = a0[i][j]*fm[j][k];
df5240ea 617 else for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)
85f1e34a 618 rt[i][k] = a1[i][j]*fm[j][k];
ecb0c8bc 619 for(i=0;i<3;i++)for(m=0;m<3;m++){
620 l[i][m] = 0.0;
621 for(j=0;j<3;j++)for(k=0;k<3;k++)
622 l[i][m] += rt[j][i]*g[j][k]*rt[k][m];
623 } // end for i,m
624 // g = R^t l R
df5240ea 625 return;
626}
627//----------------------------------------------------------------------
8d5bd3f9 628void AliITSgeomMatrix::LtoGPositionErrorTracking( Double_t l[3][3],
df5240ea 629 Double_t g[3][3]){
630////////////////////////////////////////////////////////////////////////
631// A slightly different coordinate system is used when tracking.
632// This coordinate system is only relevant when the geometry represents
633// the cylindrical ALICE ITS geometry. For tracking the Z axis is left
634// alone but X -> -Y and Y -> X such that X always points out of the
635// ITS Cylinder for every layer including layer 1 (where the detector
636// are mounted upside down).
637//Begin_Html
638/*
639<img src="picts/ITS/AliITSgeomMatrix_T1.gif">
640 */
641//End_Html
642////////////////////////////////////////////////////////////////////////
643 Int_t i,j,k,m;
85f1e34a 644 Double_t rt[3][3];
645 Double_t a0[3][3] = {{0.,+1.,0.},{-1.,0.,0.},{0.,0.,+1.}};
646 Double_t a1[3][3] = {{0.,-1.,0.},{+1.,0.,0.},{0.,0.,+1.}};
df5240ea 647
648 if(fid[0]==1) for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)
85f1e34a 649 rt[i][k] = a0[i][j]*fm[j][k];
df5240ea 650 else for(i=0;i<3;i++)for(j=0;j<3;j++)for(k=0;k<3;k++)
85f1e34a 651 rt[i][k] = a1[i][j]*fm[j][k];
ecb0c8bc 652 for(i=0;i<3;i++)for(m=0;m<3;m++){
653 g[i][m] = 0.0;
654 for(j=0;j<3;j++)for(k=0;k<3;k++)
655 g[i][m] += rt[i][j]*l[j][k]*rt[m][k];
656 } // end for i,m
657 // g = R l R^t
df5240ea 658 return;
659}
660//----------------------------------------------------------------------
661void AliITSgeomMatrix::PrintTitles(ostream *os){
662////////////////////////////////////////////////////////////////////////
663// Standard output format for this class but it includes variable
664// names and formatting that makes it easer to read.
665////////////////////////////////////////////////////////////////////////
666 Int_t i,j;
667
668 *os << "fDetectorIndex=" << fDetectorIndex << " fid[3]={";
669 for(i=0;i<3;i++) *os << fid[i] << " ";
670 *os << "} frot[3]={";
671 for(i=0;i<3;i++) *os << frot[i] << " ";
672 *os << "} ftran[3]={";
673 for(i=0;i<3;i++) *os << ftran[i] << " ";
674 *os << "} fm[3][3]={";
675 for(i=0;i<3;i++){for(j=0;j<3;j++){ *os << fm[i][j] << " ";} *os <<"}{";}
676 *os << "}" << endl;
677 return;
678}
679//----------------------------------------------------------------------
8253cd9a 680void AliITSgeomMatrix::PrintComment(ostream *os){
681////////////////////////////////////////////////////////////////////////
682// output format used by Print..
683////////////////////////////////////////////////////////////////////////
684 *os << "fDetectorIndex fid[0] fid[1] fid[2] ftran[0] ftran[1] ftran[2] ";
685 *os << "fm[0][0] fm[0][1] fm[0][2] fm[1][0] fm[1][1] fm[1][2] ";
686 *os << "fm[2][0] fm[2][1] fm[2][2] ";
687 return;
688}
689//----------------------------------------------------------------------
690void AliITSgeomMatrix::Print(ostream *os){
df5240ea 691////////////////////////////////////////////////////////////////////////
692// Standard output format for this class.
693////////////////////////////////////////////////////////////////////////
694 Int_t i,j;
431a7819 695#if defined __GNUC__
696#if __GNUC__ > 2
697 ios::fmtflags fmt;
698#else
699 Int_t fmt;
700#endif
701#else
94831058 702#if defined __ICC
703 ios::fmtflags fmt;
704#else
31b8cd63 705 Int_t fmt;
431a7819 706#endif
94831058 707#endif
df5240ea 708
8253cd9a 709 fmt = os->setf(ios::scientific); // set scientific floating point output
df5240ea 710 *os << fDetectorIndex << " ";
711 for(i=0;i<3;i++) *os << fid[i] << " ";
8253cd9a 712// for(i=0;i<3;i++) *os << frot[i] << " "; // Redundant with fm[][].
713 for(i=0;i<3;i++) *os << setprecision(16) << ftran[i] << " ";
714 for(i=0;i<3;i++)for(j=0;j<3;j++) *os << setprecision(16) <<
715 fm[i][j] << " ";
df5240ea 716 *os << endl;
8253cd9a 717 os->flags(fmt); // reset back to old formating.
df5240ea 718 return;
719}
720//----------------------------------------------------------------------
8253cd9a 721void AliITSgeomMatrix::Read(istream *is){
df5240ea 722////////////////////////////////////////////////////////////////////////
723// Standard input format for this class.
724////////////////////////////////////////////////////////////////////////
725 Int_t i,j;
726
727 *is >> fDetectorIndex;
728 for(i=0;i<3;i++) *is >> fid[i];
8253cd9a 729// for(i=0;i<3;i++) *is >> frot[i]; // Redundant with fm[][].
df5240ea 730 for(i=0;i<3;i++) *is >> ftran[i];
731 for(i=0;i<3;i++)for(j=0;j<3;j++) *is >> fm[i][j];
8253cd9a 732 AngleFromMatrix(); // compute angles frot[].
d8cc8493 733 fCylR = TMath::Sqrt(ftran[0]*ftran[0]+ftran[1]*ftran[1]);
734 fCylPhi = TMath::ATan2(ftran[1],ftran[0]);
735 if(fCylPhi<0.0) fCylPhi += TMath::Pi();
df5240ea 736 return;
737}
d8cc8493 738//______________________________________________________________________
739void AliITSgeomMatrix::Streamer(TBuffer &R__b){
740 // Stream an object of class AliITSgeomMatrix.
741
742 if (R__b.IsReading()) {
743 AliITSgeomMatrix::Class()->ReadBuffer(R__b, this);
744 fCylR = TMath::Sqrt(ftran[0]*ftran[0]+ftran[1]*ftran[1]);
745 fCylPhi = TMath::ATan2(ftran[1],ftran[0]);
746 this->AngleFromMatrix();
747 if(fCylPhi<0.0) fCylPhi += TMath::Pi();
748 } else {
749 AliITSgeomMatrix::Class()->WriteBuffer(R__b, this);
750 }
751}
df5240ea 752//----------------------------------------------------------------------
753ostream &operator<<(ostream &os,AliITSgeomMatrix &p){
754////////////////////////////////////////////////////////////////////////
755// Standard output streaming function.
756////////////////////////////////////////////////////////////////////////
757
8253cd9a 758 p.Print(&os);
df5240ea 759 return os;
760}
761//----------------------------------------------------------------------
762istream &operator>>(istream &is,AliITSgeomMatrix &r){
763////////////////////////////////////////////////////////////////////////
764// Standard input streaming function.
765////////////////////////////////////////////////////////////////////////
766
8253cd9a 767 r.Read(&is);
df5240ea 768 return is;
769}
8253cd9a 770//----------------------------------------------------------------------