SecGeom.C

Go to the documentation of this file.
00001 #include "SecGeom.h"
00002 #include "PHGeometron.h"
00003 
00004 #include <iostream>
00005 using namespace std;
00006 
00007 double SecGeom::fgABSURD = -999999.;
00008 
00009 //_____________________________________________________________________________
00010 SecGeom::SecGeom() :
00011   fNx(0), fNy(0),
00012   fTower_xSize(0), fTower_ySize(0)
00013 {
00014 }
00015 
00016 //_____________________________________________________________________________
00017 SecGeom::~SecGeom()
00018 {
00019 }
00020 
00021 //_____________________________________________________________________________
00022 SecGeom::SecGeom(const SecGeom& obj)
00023 {
00024   (const_cast<SecGeom&>(obj)).Copy(*this);
00025 }
00026 
00027 //_____________________________________________________________________________
00028 SecGeom& SecGeom::operator=(const SecGeom& obj)
00029 {
00030   if ( this != &obj ) {
00031     (const_cast<SecGeom&>(obj)).Copy(*this);
00032   }
00033   return *this;
00034 }
00035 
00036 //_____________________________________________________________________________
00037 void SecGeom::Copy(SecGeom& obj)
00038 {
00039   obj.fNx = fNx;
00040   obj.fNy = fNy;
00041   obj.fTower_xSize = fTower_xSize;
00042   obj.fTower_ySize = fTower_ySize;
00043   obj.fRotationMat = fRotationMat;
00044   obj.fTranslationVec = fTranslationVec;
00045   obj.fInvRotationMat = fInvRotationMat;
00046   obj.fInvTranslationVec = fInvTranslationVec;
00047 }
00048 
00049 //_____________________________________________________________________________
00050 int SecGeom::GetTowerPosLocal(size_t ind, float &x, float &y, float &z) const
00051 {
00052   //
00053   // Calculates tower position in Sector frame,
00054   // ind - tower index (ix+iy*nx, ix=0,...; iy=0,... )
00055   //
00056   // Returns 1 in case of success, 0 otherwise.
00057 
00058   size_t ix = ind % fNx;
00059   size_t iy = ind / fNx; 
00060 
00061   if ( iy >= fNy ) {
00062     x = y = z = fgABSURD;
00063     cerr << "<E> SecGeom::GetTowerPosLocal : Wrong tower index : "
00064          << ind << endl;
00065     return 0; // Error
00066   }
00067 
00068   x = fTower_xSize * ix;
00069   y = fTower_ySize * iy;
00070   z = 0;
00071 
00072   return 1; // OK
00073 }
00074 
00075 //_____________________________________________________________________________
00076 int SecGeom::GetTowerPosGlobal(size_t ind, float &x, float &y, float &z) const
00077 {
00078   //
00079   // Calculates tower position in Sector frame,
00080   // is - sector index (0-7)
00081   // ind - tower index (ix+iy*nx, ix=0,...; iy=0,... )
00082   //
00083   // Returns 1 in case of success, 0 otherwise.
00084 
00085   float xl, yl, zl;
00086 
00087   int st = GetTowerPosLocal( ind, xl, yl, zl );
00088 
00089   if( !st ) { 
00090     x = fgABSURD;
00091     y = fgABSURD;
00092     z = fgABSURD;
00093     return 0;
00094   }
00095 
00096   PHGeometron * geometry = PHGeometron::instance();
00097 
00098   PHPoint emcHit(xl, yl, zl);
00099   PHPoint phnxHit  = geometry->transformPoint(fRotationMat, 
00100                                               fTranslationVec, 
00101                                               emcHit);
00102   x =  phnxHit.getX();
00103   y =  phnxHit.getY();
00104   z =  phnxHit.getZ();
00105 
00106   return 1;
00107 }
00108 
00109 //_____________________________________________________________________________
00110 void SecGeom::LocalToGlobal( float xl, float yl, float zl, 
00111                              float &xg, float &yg, float &zg) const
00112 {
00113   //
00114   // Converts local coordinates (xl,yl,zl) to global ones (xg,yg,zg)
00115   //
00116 
00117   PHGeometron * geometry = PHGeometron::instance();
00118   PHPoint emcHit(xl, yl, zl);
00119   PHPoint phnxHit  = geometry->transformPoint(fRotationMat, 
00120                                               fTranslationVec, emcHit);
00121   xg =  phnxHit.getX();
00122   yg =  phnxHit.getY();
00123   zg =  phnxHit.getZ();
00124 }
00125 
00126 //_____________________________________________________________________________
00127 void SecGeom::GlobalToLocal( float xg, float yg, float zg, 
00128                              float &xl, float &yl, float &zl) const
00129 {
00130   //
00131   // Converts global coordinates (xg,yg,zg) to local ones (xl,yl,zl)
00132   //
00133 
00134   PHGeometron * geometry = PHGeometron::instance();
00135   PHPoint phnxHit(xg, yg, zg);
00136   PHPoint emcHit  = geometry->transformPoint(fInvRotationMat, 
00137                                              fInvTranslationVec,
00138                                              phnxHit);
00139   xl =  emcHit.getX();
00140   yl =  emcHit.getY();
00141   zl =  emcHit.getZ();
00142 }
00143 
00144 //_____________________________________________________________________________
00145 void
00146 SecGeom::Print() const
00147 { 
00148   cout << *this << endl; 
00149 }
00150 
00151 //_____________________________________________________________________________
00152 void SecGeom::SetDirectTransformation(PHMatrix mat, PHVector vec)
00153 {
00154   fRotationMat = mat;
00155   fTranslationVec = vec;
00156   PHGeometron* geometron = PHGeometron::instance();
00157   PHFrame local;
00158   PHFrame global = geometron->MatrixAndVector2frames(local,
00159                                                      fRotationMat,
00160                                                      fTranslationVec);
00161   geometron->frames2MatrixAndVector(global,local,
00162                                     fInvRotationMat,
00163                                     fInvTranslationVec);
00164 }
00165 
00166 //_____________________________________________________________________________
00167 ostream& operator<< (ostream& out, const SecGeom& obj)
00168 {
00169   streamsize old_precision = out.precision(20);
00170   out << obj.fNx << " towers in x (xSize=" << obj.fTower_xSize << "cm), " 
00171       << obj.fNy << " towers in y (ySize=" << obj.fTower_ySize << "cm) "
00172       << endl 
00173       << " rot. mat. = " 
00174       << endl 
00175       << obj.fRotationMat
00176       << " trans. vec = " << obj.fTranslationVec
00177       << endl;
00178   out.precision(old_precision);
00179   return out;
00180 }