ROOT logo
//*-- AUTHOR : Ilse Koenig
//*-- Modified : 16/06/99

//_HADES_CLASS_DESCRIPTION 
///////////////////////////////////////////////////////////////////////////////
//
// HGeomTransform
//
// Class to hold the orientation (rotation matrix) and the position
// (translation vector) of a coordinate system (system 2) relative to a
// reference coordinate system (system 1)
// It provides member functions to transform a vector or a point and an other
// coordinate system from its own coordinate system into the reference
// coordinate system and vice versa.
// Instances of this class can e.g. hold the lab or detector transformation of
// a geometry volume (see class HGeomVolume)
//
// Inline functions:
//
// HGeomTransform()
//    The default constructor creates an identity transformation  
// HGeomTransform(HGeomTransform& t)
//    copy constructor
// void setTransform(const HGeomTransform& t)
//    copies the given transformation
// void setRotMatrix(const HGeomRotation& r)
//    copies the given rotation matrix
// void setRotMatrix(const Double_t* a)
//    creates a rotation matrix taking an Double_t array with 9 components 
// void setTransVector(const HGeomVector& t)
//    copies the given translation vector
// void setTransVector(const Double_t* a)
//    creates a translation vector taking an Double_t array with 6 components
// const HGeomRotation& getRotMatrix() const
//    returns the rotation matrix
// const HGeomVector& getTransVector() const
//    returns the  translation vector
//
///////////////////////////////////////////////////////////////////////////////
using namespace std;
#include "hgeomtransform.h"
#include <iostream> 
#include <iomanip>
#include <math.h>

ClassImp(HGeomTransform)

HGeomTransform& HGeomTransform::operator=(const HGeomTransform& t)  {
  rot=t.getRotMatrix();
  trans=t.getTransVector();

  return *this;
}


HGeomVector HGeomTransform::transFrom(const HGeomVector& p) const {
  // Transforms a vector (point) given in its own coordinate
  // system (2) into the reference coordinate system (1)
  // e.g. v2 is a vector (point) in the detector coordinate system;
  // it can be transformed to a vector v2 the lab system with
  //    HGeomVector v2=mo.transFrom(v1)
  // where mo is the coordinate system of the mother
  return rot*p+trans;
}

HGeomVector HGeomTransform::transTo(const HGeomVector& p) const {
  // Transforms a vector (point) given in the reference system (1)
  // into the local coordinate system (2)
  // e.g. v1 is a vector (point) in the lab system; it can be transformed to
  // a vector v2 the detector coordinate system with
  //    HGeomVector v2=mo.transTo(v1)
  // where mo is the coordinate system of the mother
  return rot.inverse()*(p-trans);
}

void HGeomTransform::transTo(const HGeomTransform& s) {
  // Transforms the coordinate system into the coordinate system
  // described by s. Both transformations must have the same reference
  // system e.g. the lab system
  // This function is e.g. used to transform a daughter coordinate system
  // with a transformation relative to the lab into the detector coordinate
  // system.
  const HGeomRotation& rm=s.getRotMatrix();
  HGeomRotation rt(rm.inverse());
  if (rm.diff2(rot)<0.000001) rot.setUnitMatrix();
  else rot.transform(rt);
  trans-=s.getTransVector();
  trans=rt*trans;
  //  trans.round(3); // rounds to 3 digits (precision 1 micrometer)
}

void HGeomTransform::transFrom(const HGeomTransform& s) {
  // Transforms the coordinate system described by s into the local
  // coordinate system
  // This function is e.g. used to transform a daughter coordinate system
  // with a transformation relative to its mother into the lab system.
  // e.g. daughterDetTransform.transFrom(motherLabTransform)
  const HGeomRotation& r=s.getRotMatrix();
  rot.transform(r);
  trans=r*trans;
  trans+=s.getTransVector();
}

void HGeomTransform::clear() {
  trans.clear();
  rot.setUnitMatrix();
}

void HGeomTransform::print() const {
  rot.print();
  trans.print();
}

void HGeomTransform::invert(void) {
  rot.invert();
  trans = rot*trans;
  trans *= -1.;
}
 hgeomtransform.cc:1
 hgeomtransform.cc:2
 hgeomtransform.cc:3
 hgeomtransform.cc:4
 hgeomtransform.cc:5
 hgeomtransform.cc:6
 hgeomtransform.cc:7
 hgeomtransform.cc:8
 hgeomtransform.cc:9
 hgeomtransform.cc:10
 hgeomtransform.cc:11
 hgeomtransform.cc:12
 hgeomtransform.cc:13
 hgeomtransform.cc:14
 hgeomtransform.cc:15
 hgeomtransform.cc:16
 hgeomtransform.cc:17
 hgeomtransform.cc:18
 hgeomtransform.cc:19
 hgeomtransform.cc:20
 hgeomtransform.cc:21
 hgeomtransform.cc:22
 hgeomtransform.cc:23
 hgeomtransform.cc:24
 hgeomtransform.cc:25
 hgeomtransform.cc:26
 hgeomtransform.cc:27
 hgeomtransform.cc:28
 hgeomtransform.cc:29
 hgeomtransform.cc:30
 hgeomtransform.cc:31
 hgeomtransform.cc:32
 hgeomtransform.cc:33
 hgeomtransform.cc:34
 hgeomtransform.cc:35
 hgeomtransform.cc:36
 hgeomtransform.cc:37
 hgeomtransform.cc:38
 hgeomtransform.cc:39
 hgeomtransform.cc:40
 hgeomtransform.cc:41
 hgeomtransform.cc:42
 hgeomtransform.cc:43
 hgeomtransform.cc:44
 hgeomtransform.cc:45
 hgeomtransform.cc:46
 hgeomtransform.cc:47
 hgeomtransform.cc:48
 hgeomtransform.cc:49
 hgeomtransform.cc:50
 hgeomtransform.cc:51
 hgeomtransform.cc:52
 hgeomtransform.cc:53
 hgeomtransform.cc:54
 hgeomtransform.cc:55
 hgeomtransform.cc:56
 hgeomtransform.cc:57
 hgeomtransform.cc:58
 hgeomtransform.cc:59
 hgeomtransform.cc:60
 hgeomtransform.cc:61
 hgeomtransform.cc:62
 hgeomtransform.cc:63
 hgeomtransform.cc:64
 hgeomtransform.cc:65
 hgeomtransform.cc:66
 hgeomtransform.cc:67
 hgeomtransform.cc:68
 hgeomtransform.cc:69
 hgeomtransform.cc:70
 hgeomtransform.cc:71
 hgeomtransform.cc:72
 hgeomtransform.cc:73
 hgeomtransform.cc:74
 hgeomtransform.cc:75
 hgeomtransform.cc:76
 hgeomtransform.cc:77
 hgeomtransform.cc:78
 hgeomtransform.cc:79
 hgeomtransform.cc:80
 hgeomtransform.cc:81
 hgeomtransform.cc:82
 hgeomtransform.cc:83
 hgeomtransform.cc:84
 hgeomtransform.cc:85
 hgeomtransform.cc:86
 hgeomtransform.cc:87
 hgeomtransform.cc:88
 hgeomtransform.cc:89
 hgeomtransform.cc:90
 hgeomtransform.cc:91
 hgeomtransform.cc:92
 hgeomtransform.cc:93
 hgeomtransform.cc:94
 hgeomtransform.cc:95
 hgeomtransform.cc:96
 hgeomtransform.cc:97
 hgeomtransform.cc:98
 hgeomtransform.cc:99
 hgeomtransform.cc:100
 hgeomtransform.cc:101
 hgeomtransform.cc:102
 hgeomtransform.cc:103
 hgeomtransform.cc:104
 hgeomtransform.cc:105
 hgeomtransform.cc:106
 hgeomtransform.cc:107
 hgeomtransform.cc:108
 hgeomtransform.cc:109
 hgeomtransform.cc:110
 hgeomtransform.cc:111
 hgeomtransform.cc:112
 hgeomtransform.cc:113
 hgeomtransform.cc:114
 hgeomtransform.cc:115
 hgeomtransform.cc:116
 hgeomtransform.cc:117
 hgeomtransform.cc:118