TMatrixElement.cxx
Go to the documentation of this file.
1 #include "TMatrixElement.hxx"
2 
3 #include <TGeoManager.h>
4 #include <TGeoShape.h>
5 #include <TGeoEltu.h>
6 #include <TGeoMatrix.h>
7 #include <TVectorD.h>
8 
10 
12  const TVector3& position,
13  const TMatrixD& matrix,
14  bool longAxis)
15  : TEveGeoShape(name) {
16  Initialize(position,matrix,longAxis);
17 }
18 
20  const TVector3& position,
21  const TMatrixF& matrix,
22  bool longAxis)
23  : TEveGeoShape(name) {
24  TMatrixD mat(matrix);
25  Initialize(position,mat,longAxis);
26 }
27 
29  const TMatrixD& matrix,
30  bool longAxis) {
31  // Find the rotation of the object to be displayed. If longAxis is true,
32  // the the matrix is represented as a tube with the long axis along the
33  // local Z direction, and the major and minor in the XY plane. Otherwise,
34  // the matrix is represented as a tube with the short axis along the local
35  // Z direction.
36  TMatrixD tubeRot(3,3);
37  for (int i=0; i<3; ++i) {
38  for (int j=0; j<3; ++j) {
39  tubeRot(i,j) = matrix(i,j);
40  }
41  }
42 
43  double tubeAxis;
44  double tubeMajor;
45  double tubeMinor;
46  TVectorD values(3);
47  TMatrixD tubeEigen(tubeRot.EigenVectors(values));
48  if (longAxis) {
49  tubeAxis = std::sqrt(values(0));
50  tubeRot(0,2) = tubeEigen(0,0);
51  tubeRot(1,2) = tubeEigen(1,0);
52  tubeRot(2,2) = tubeEigen(2,0);
53  tubeMajor = std::sqrt(values(1));
54  tubeRot(0,0) = tubeEigen(0,1);
55  tubeRot(1,0) = tubeEigen(1,1);
56  tubeRot(2,0) = tubeEigen(2,1);
57  tubeMinor = std::sqrt(values(2));
58  tubeRot(0,1) = tubeEigen(0,2);
59  tubeRot(1,1) = tubeEigen(1,2);
60  tubeRot(2,1) = tubeEigen(2,2);
61  }
62  else {
63  tubeAxis = std::sqrt(values(2));
64  tubeRot(0,2) = tubeEigen(0,2);
65  tubeRot(1,2) = tubeEigen(1,2);
66  tubeRot(2,2) = tubeEigen(2,2);
67  tubeMajor = std::sqrt(values(0));
68  tubeRot(0,0) = tubeEigen(0,0);
69  tubeRot(1,0) = tubeEigen(1,0);
70  tubeRot(2,0) = tubeEigen(2,0);
71  tubeMinor = std::sqrt(values(1));
72  tubeRot(0,1) = tubeEigen(0,1);
73  tubeRot(1,1) = tubeEigen(1,1);
74  tubeRot(2,1) = tubeEigen(2,1);
75  }
76 
77  // Create the rotation matrix.
78  TGeoRotation rot;
79  rot.SetMatrix(tubeRot.GetMatrixArray());
80 
81  // Set the translation
82  TGeoTranslation trans(position.X(), position.Y(), position.Z());
83 
84  // Finally set the transform for the object.
85  TGeoCombiTrans rotTrans(trans,rot);
86  SetTransMatrix(rotTrans);
87 
88  // Make sure the tube size doesn't get too small.
89  tubeAxis = std::max(1.5, tubeAxis);
90  tubeMajor = std::max(1.5, tubeMajor);
91  tubeMinor = std::max(1.5, tubeMinor);
92 
93  // Create the shape to display. This has to play some fancy footsie to
94  // get the gGeoManager memory management right. It first saves the
95  // current manager, then gets an internal geometry manager used by
96  // TEveGeoShape, and then resets the old manager once the shape is
97  // created. You gotta love global variables...
98  TGeoManager* saveGeom = gGeoManager;
99  gGeoManager = GetGeoMangeur();
100  TGeoShape* geoShape = new TGeoEltu(tubeMajor,tubeMinor,tubeAxis);
101  SetShape(geoShape);
102  gGeoManager = saveGeom;
103 }
static QCString name
Definition: declinfo.cpp:673
void Initialize(const TVector3 &position, const TMatrixD &matrix, bool longAxis)
TMatrixElement(const char *name, const TVector3 &position, const TMatrixD &matrix, bool longAxis)
Q_UINT16 values[128]
static int max(int a, int b)