ROOT logo
//*-- AUTHOR : Ilse Koenig
//*-- Modified : 11/11/2003 by Ilse Koenig
//*-- Modified : 16/05/99 by Ilse Koenig

//_HADES_CLASS_DESCRIPTION 
/////////////////////////////////////////////////////////////
//
// HGeomTrap
//
// class for the GEANT shape TRAP
// 
// The technical coordinate system of a TRAP, which sits in
// CAVE and is not rotated, is the laboratory system.
// The y-axis points from the smaller side to the larger one.
// That's the same definitition as for a TRAP and different from
// the Geant or ROOT definition for a TRAP.
// Therefore a transformation is needed:
//              x-technical = - (x-Geant)
//              y-technical = - (y-Geant)
//              z-technical = z-Geant
// This is stored in the data element intrinsicRot which is
// created in the function calcVoluPosition(...)
// 
/////////////////////////////////////////////////////////////

#include "hgeomtrap.h"
#include "hgeomvolume.h"
#include "hgeomvector.h"

ClassImp(HGeomTrap)

HGeomTrap::HGeomTrap() {
  // constructor
  fName="TRAP";
  nPoints=8;
  nParam=11;
  param=new TArrayD(nParam);
  intrinsicRot.setElement(-1.,0);
  intrinsicRot.setElement(-1.,4);
}


HGeomTrap::~HGeomTrap() {
  // destructor
  if (param) {
    delete param;
    param=0;
  }
  if (center) {
    delete center;
    center=0;
  }
  if (position) {
    delete position;
    position=0;
  }
}


TArrayD* HGeomTrap::calcVoluParam(HGeomVolume* volu) {
  // calculates the parameters needed to create the shape 
  const Double_t fac=20.;
  const Double_t raddeg=180./TMath::Pi();
  Double_t alpha, beta;
  HGeomVector cb, ct, dc;
  for(Int_t i=0;i<4;i++) cb+=*(volu->getPoint(i));  // bottom plane
  for(Int_t i=4;i<8;i++) ct+=*(volu->getPoint(i));  // top plane
  dc=(ct-cb);
  dc*=0.25;    // vector from bottom to top plane
  dc.setX(-dc(0));  // GEANT coordinate system
  dc.setY(-dc(1));
  param->AddAt(TMath::Abs(dc(2))/fac,0);
  alpha=TMath::ATan(TMath::Sqrt(dc(0)*dc(0)+dc(1)*dc(1))/dc(2))*raddeg;
  if (TMath::Abs(alpha)<0.0001) {
    alpha=0.0;
    beta=0.0;
  } else {
    if (TMath::Abs(dc(0))<0.0001) {
      if (dc(1)>0) beta=90.0;
      else beta=270.0;
    } else {
      beta=atan(dc(1)/dc(0))*raddeg;
      if (dc(0)<0) beta=180.0 + beta;
      if (beta<0) beta=360.0 + beta;
    }
  }
  param->AddAt(alpha,1);
  param->AddAt(beta,2);
  param->AddAt(((*(volu->getPoint(1)))(1)-(*(volu->getPoint(0)))(1))/fac,3);
  param->AddAt(((*(volu->getPoint(1)))(0)-(*(volu->getPoint(2)))(0))/fac,4);
  param->AddAt(((*(volu->getPoint(0)))(0)-(*(volu->getPoint(3)))(0))/fac,5);

  Double_t a=TMath::ATan(((*(volu->getPoint(1)))(0)
                          - (*(volu->getPoint(0)))(0)
                          + (*(volu->getPoint(2)))(0)
                          - (*(volu->getPoint(3)))(0))/40./param->At(3)
              )*raddeg;
  if (TMath::Abs(a)<=0.0001) param->AddAt(0.,6);
  else param->AddAt(a,6);
  param->AddAt(((*(volu->getPoint(5)))(1)-(*(volu->getPoint(4)))(1))/fac,7);
  param->AddAt(((*(volu->getPoint(5)))(0)-(*(volu->getPoint(6)))(0))/fac,8);
  param->AddAt(((*(volu->getPoint(4)))(0)-(*(volu->getPoint(7)))(0))/fac,9);
  a=TMath::ATan(((*(volu->getPoint(5)))(0)
               - (*(volu->getPoint(4)))(0)
               + (*(volu->getPoint(6)))(0)
               - (*(volu->getPoint(7)))(0))/40./param->At(7))*raddeg;
  if (TMath::Abs(a)<=0.0001) param->AddAt(0.,10);
  else param->AddAt(a,10);
// check if coplanar
  Double_t dx=(param->At(4) - param->At(5)) / param->At(3) * param->At(7) -
              (param->At(8) - param->At(9));
  if (TMath::Abs(dx)>=0.001) {
    cout << "top and bottom plane are not coplanar for shape TRAP\n";
    cout << "lenght in x-direction of top plane is changed\n";
    cout << "old values: " << param->At(8) << "  " << param->At(9) << "\n";
    param->AddAt(param->At(8) + dx/2.,8);
    param->AddAt(param->At(9) - dx/2.,9);
    cout << "new values: " << param->At(8) << "  " << param->At(9) << "\n";
  }
  return param;
} 


void HGeomTrap::calcVoluPosition(HGeomVolume* volu,
           const HGeomTransform& dTC,const HGeomTransform& mTR) {
  // calls the function posInMother(...) to calculate the position of the
  // volume in its mother 
  Double_t t[3]={0.,0.,0.};
  for(Int_t i=0;i<8;i++) t[0]+=(*(volu->getPoint(i)))(0);
  t[0]/=8.;
  t[1]=((*(volu->getPoint(1)))(1) + (*(volu->getPoint(0)))(1) +
           (*(volu->getPoint(5)))(1) + (*(volu->getPoint(4)))(1))/4.;
  t[2]=((*(volu->getPoint(4)))(2) + (*(volu->getPoint(0)))(2))/2.;
  center->setTransVector(t);
  center->setRotMatrix(intrinsicRot);
  posInMother(dTC,mTR);
}


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