ROOT logo
//*-- Author : Anar Rustamov

#include "halignmentgrotations.h"
#include "hmdcgetcontainers.h"
#include "hgeomtransform.h"
#include "TString.h"
#include "hgeomvector.h"
#include "TMath.h"


using namespace std;

ClassImp(HAlignmentGRotations)

  HAlignmentGRotations::HAlignmentGRotations()
{
  
  for(Int_t s = 0; s < 6; s++)
  {
    transMdcLabToSec[s]=NULL;
    for(Int_t m = 0; m < 4; m++)
      {
	transMdcLabToMod[s][m] = NULL;
	transMdcSecToMod[s][m] = NULL;
      }
  }
  fGetCont = HMdcGetContainers::getObject();
  fGetCont -> getMdcGeomPar();
  fGetCont -> getSpecGeomPar();
}

HGeomTransform*  HAlignmentGRotations::GetTransMdc(Int_t s, Int_t m)
{
  //return transformation matrix 
  if(!transMdcLabToMod[s][m])
    {
      transMdcLabToMod[s][m] = new HGeomTransform();
      if(!fGetCont->getLabTransMod(*(transMdcLabToMod[s][m]),s,m))
	{
	  return NULL;
	}
    }
  return transMdcLabToMod[s][m];
}

HGeomTransform*  HAlignmentGRotations::GetTransMdc(Int_t s)
{
  //return transformation matrix
  if(!transMdcLabToSec[s])
    {
      transMdcLabToSec[s]=new HGeomTransform();
      if(!fGetCont->getLabTransSec(*(transMdcLabToSec[s]),s))
	{
	  return NULL;
	}
    }
  return transMdcLabToSec[s];
}


HGeomVector HAlignmentGRotations::TransMdc(HGeomVector &p, TString Option, Int_t s, Int_t m)
{
  HGeomVector pDummy(-10000.,-10000,-10000.);
  if(!transMdcLabToMod[s][m])
    {
      transMdcLabToMod[s][m]=new HGeomTransform();
      if(!fGetCont->getLabTransMod(*(transMdcLabToMod[s][m]),s,m))
	{
	   return pDummy;
	}
    }
  
  if(Option=="FromModToLab")
    {
      
      return transMdcLabToMod[s][m]->transFrom(p);
    }
  if(Option=="FromLabToMod")
    {
      return transMdcLabToMod[s][m]->transTo(p);
    }
    
 if(!transMdcSecToMod[s][m])
    {
      transMdcSecToMod[s][m]=new HGeomTransform();
      if(!fGetCont->getSecTransMod(*(transMdcSecToMod[s][m]),s,m))
	{
	  return pDummy;
	}
    }    
    
    
  if(Option=="FromModToSec")
    {
      return transMdcSecToMod[s][m]->transFrom(p);
    }
  if(Option=="FromSecToMod")
    {
      return transMdcSecToMod[s][m]->transTo(p);
    }
    return pDummy;
}


HGeomTransform HAlignmentGRotations::MakeTransMatrix(Double_t phi, Double_t psi, Double_t theta, 
                                                     Double_t x, Double_t y, Double_t z)
{
   phi*=180./acos(-1.);
   psi*=180./acos(-1.);
   theta*=180./acos(-1.);
 
   HGeomRotation rot(phi, psi, theta);
   HGeomVector shift(x,y,z);
   HGeomTransform trans;
   trans.setRotMatrix(rot);
   trans.setTransVector(shift);
   return trans;
}

void HAlignmentGRotations::GetEulerAngles(HGeomTransform &trans, Double_t &phi, Double_t &psi, Double_t &theta)
{
  const HGeomRotation &rot=trans.getRotMatrix();
  psi=acos(rot(8));
  Float_t sinPsi=sin(psi);
  phi=atan2(rot(5)/sinPsi, rot(2)/sinPsi);
  theta=atan2(rot(7)/sinPsi,-1.*rot(6)/sinPsi);
}

void HAlignmentGRotations::GetTransVector(HGeomTransform &trans, Double_t &x, Double_t &y, Double_t &z)
{
  const HGeomVector &shift= trans.getTransVector();
  x=shift.getX();
  y=shift.getY();
  z=shift.getZ();
}

HGeomVector HAlignmentGRotations::TransMdc(HGeomVector &p, TString Option, Int_t s)
{
  HGeomVector pDummy(-10000.,-10000,-10000.);
  if(!transMdcLabToSec[s])
    {
      transMdcLabToSec[s]=new HGeomTransform();
      if(!fGetCont->getLabTransSec(*(transMdcLabToSec[s]),s))
	{
	   return pDummy;
	}
    }
  
  if(Option=="FromSecToLab")
    {
      
      return transMdcLabToSec[s]->transFrom(p);
    }
  if(Option=="FromLabToSec")
    {
      return transMdcLabToSec[s]->transTo(p);
    }
 return pDummy;    
}

 halignmentgrotations.cc:1
 halignmentgrotations.cc:2
 halignmentgrotations.cc:3
 halignmentgrotations.cc:4
 halignmentgrotations.cc:5
 halignmentgrotations.cc:6
 halignmentgrotations.cc:7
 halignmentgrotations.cc:8
 halignmentgrotations.cc:9
 halignmentgrotations.cc:10
 halignmentgrotations.cc:11
 halignmentgrotations.cc:12
 halignmentgrotations.cc:13
 halignmentgrotations.cc:14
 halignmentgrotations.cc:15
 halignmentgrotations.cc:16
 halignmentgrotations.cc:17
 halignmentgrotations.cc:18
 halignmentgrotations.cc:19
 halignmentgrotations.cc:20
 halignmentgrotations.cc:21
 halignmentgrotations.cc:22
 halignmentgrotations.cc:23
 halignmentgrotations.cc:24
 halignmentgrotations.cc:25
 halignmentgrotations.cc:26
 halignmentgrotations.cc:27
 halignmentgrotations.cc:28
 halignmentgrotations.cc:29
 halignmentgrotations.cc:30
 halignmentgrotations.cc:31
 halignmentgrotations.cc:32
 halignmentgrotations.cc:33
 halignmentgrotations.cc:34
 halignmentgrotations.cc:35
 halignmentgrotations.cc:36
 halignmentgrotations.cc:37
 halignmentgrotations.cc:38
 halignmentgrotations.cc:39
 halignmentgrotations.cc:40
 halignmentgrotations.cc:41
 halignmentgrotations.cc:42
 halignmentgrotations.cc:43
 halignmentgrotations.cc:44
 halignmentgrotations.cc:45
 halignmentgrotations.cc:46
 halignmentgrotations.cc:47
 halignmentgrotations.cc:48
 halignmentgrotations.cc:49
 halignmentgrotations.cc:50
 halignmentgrotations.cc:51
 halignmentgrotations.cc:52
 halignmentgrotations.cc:53
 halignmentgrotations.cc:54
 halignmentgrotations.cc:55
 halignmentgrotations.cc:56
 halignmentgrotations.cc:57
 halignmentgrotations.cc:58
 halignmentgrotations.cc:59
 halignmentgrotations.cc:60
 halignmentgrotations.cc:61
 halignmentgrotations.cc:62
 halignmentgrotations.cc:63
 halignmentgrotations.cc:64
 halignmentgrotations.cc:65
 halignmentgrotations.cc:66
 halignmentgrotations.cc:67
 halignmentgrotations.cc:68
 halignmentgrotations.cc:69
 halignmentgrotations.cc:70
 halignmentgrotations.cc:71
 halignmentgrotations.cc:72
 halignmentgrotations.cc:73
 halignmentgrotations.cc:74
 halignmentgrotations.cc:75
 halignmentgrotations.cc:76
 halignmentgrotations.cc:77
 halignmentgrotations.cc:78
 halignmentgrotations.cc:79
 halignmentgrotations.cc:80
 halignmentgrotations.cc:81
 halignmentgrotations.cc:82
 halignmentgrotations.cc:83
 halignmentgrotations.cc:84
 halignmentgrotations.cc:85
 halignmentgrotations.cc:86
 halignmentgrotations.cc:87
 halignmentgrotations.cc:88
 halignmentgrotations.cc:89
 halignmentgrotations.cc:90
 halignmentgrotations.cc:91
 halignmentgrotations.cc:92
 halignmentgrotations.cc:93
 halignmentgrotations.cc:94
 halignmentgrotations.cc:95
 halignmentgrotations.cc:96
 halignmentgrotations.cc:97
 halignmentgrotations.cc:98
 halignmentgrotations.cc:99
 halignmentgrotations.cc:100
 halignmentgrotations.cc:101
 halignmentgrotations.cc:102
 halignmentgrotations.cc:103
 halignmentgrotations.cc:104
 halignmentgrotations.cc:105
 halignmentgrotations.cc:106
 halignmentgrotations.cc:107
 halignmentgrotations.cc:108
 halignmentgrotations.cc:109
 halignmentgrotations.cc:110
 halignmentgrotations.cc:111
 halignmentgrotations.cc:112
 halignmentgrotations.cc:113
 halignmentgrotations.cc:114
 halignmentgrotations.cc:115
 halignmentgrotations.cc:116
 halignmentgrotations.cc:117
 halignmentgrotations.cc:118
 halignmentgrotations.cc:119
 halignmentgrotations.cc:120
 halignmentgrotations.cc:121
 halignmentgrotations.cc:122
 halignmentgrotations.cc:123
 halignmentgrotations.cc:124
 halignmentgrotations.cc:125
 halignmentgrotations.cc:126
 halignmentgrotations.cc:127
 halignmentgrotations.cc:128
 halignmentgrotations.cc:129
 halignmentgrotations.cc:130
 halignmentgrotations.cc:131
 halignmentgrotations.cc:132
 halignmentgrotations.cc:133
 halignmentgrotations.cc:134
 halignmentgrotations.cc:135
 halignmentgrotations.cc:136
 halignmentgrotations.cc:137
 halignmentgrotations.cc:138
 halignmentgrotations.cc:139
 halignmentgrotations.cc:140
 halignmentgrotations.cc:141
 halignmentgrotations.cc:142
 halignmentgrotations.cc:143
 halignmentgrotations.cc:144
 halignmentgrotations.cc:145
 halignmentgrotations.cc:146
 halignmentgrotations.cc:147
 halignmentgrotations.cc:148
 halignmentgrotations.cc:149
 halignmentgrotations.cc:150
 halignmentgrotations.cc:151
 halignmentgrotations.cc:152
 halignmentgrotations.cc:153
 halignmentgrotations.cc:154
 halignmentgrotations.cc:155
 halignmentgrotations.cc:156
 halignmentgrotations.cc:157
 halignmentgrotations.cc:158
 halignmentgrotations.cc:159
 halignmentgrotations.cc:160