EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairGeoTrap.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairGeoTrap.cxx
1 //*-- AUTHOR : Ilse Koenig
2 //*-- Modified : 11/11/2003 by Ilse Koenig
3 //*-- Modified : 16/05/99 by Ilse Koenig
4 
6 //
7 // FairGeoTrap
8 //
9 // class for the GEANT shape TRAP
10 //
11 // The technical coordinate system of a TRAP, which sits in
12 // CAVE and is not rotated, is the laboratory system.
13 // The y-axis points from the smaller side to the larger one.
14 // That's the same definitition as for a TRAP and different from
15 // the Geant or ROOT definition for a TRAP.
16 // Therefore a transformation is needed:
17 // x-technical = - (x-Geant)
18 // y-technical = - (y-Geant)
19 // z-technical = z-Geant
20 // This is stored in the data element intrinsicRot which is
21 // created in the function calcVoluPosition(...)
22 //
24 
25 #include "FairGeoTrap.h"
26 
27 #include "FairGeoVolume.h"
28 #include "FairGeoVector.h"
29 
30 #include "TArrayD.h"
31 
32 #include <iostream>
33 
34 using std::cout;
35 
37 
40  intrinsicRot(FairGeoRotation())
41 {
42  // constructor
43  fName="TRAP";
44  nPoints=8;
45  nParam=11;
46  param=new TArrayD(nParam);
47  intrinsicRot.setElement(-1.,0);
48  intrinsicRot.setElement(-1.,4);
49 }
50 
51 
53 {
54  // destructor
55  if (param) {
56  delete param;
57  param=0;
58  }
59  if (center) {
60  delete center;
61  center=0;
62  }
63  if (position) {
64  delete position;
65  position=0;
66  }
67 }
68 
69 
71 {
72  // calculates the parameters needed to create the shape
73  const Double_t fac=20.;
74  const Double_t raddeg=180./TMath::Pi();
75  Double_t alpha, beta;
76  FairGeoVector cb, ct, dc;
77  for(Int_t i=0; i<4; i++) { cb+=*(volu->getPoint(i)); } // bottom plane
78  for(Int_t j=4; j<8; j++) { ct+=*(volu->getPoint(j)); } // top plane
79  dc=(ct-cb);
80 // cout << dc <<" "<< ct <<" "<< cb <<" "<< endl;
81  dc*=0.25; // vector from bottom to top plane
82  dc.setX(-dc(0)); // GEANT coordinate system
83  dc.setY(-dc(1));
84  param->AddAt(TMath::Abs(dc(2))/fac,0);
85  alpha=TMath::ATan(TMath::Sqrt(dc(0)*dc(0)+dc(1)*dc(1))/dc(2))*raddeg;
86  if (TMath::Abs(alpha)<0.0001) {
87  alpha=0.0;
88  beta=0.0;
89  } else {
90  if (TMath::Abs(dc(0))<0.0001) {
91  if (dc(1)>0) { beta=90.0; }
92  else { beta=270.0; }
93  } else {
94  beta=atan(dc(1)/dc(0))*raddeg;
95  if (dc(0)<0) { beta=180.0 + beta; }
96  if (beta<0) { beta=360.0 + beta; }
97  }
98  }
99  param->AddAt(alpha,1);
100  param->AddAt(beta,2);
101  param->AddAt(((*(volu->getPoint(1)))(1)-(*(volu->getPoint(0)))(1))/fac,3);
102  param->AddAt(((*(volu->getPoint(1)))(0)-(*(volu->getPoint(2)))(0))/fac,4);
103  param->AddAt(((*(volu->getPoint(0)))(0)-(*(volu->getPoint(3)))(0))/fac,5);
104 
105  Double_t a=TMath::ATan(((*(volu->getPoint(1)))(0)
106  - (*(volu->getPoint(0)))(0)
107  + (*(volu->getPoint(2)))(0)
108  - (*(volu->getPoint(3)))(0))/40./param->At(3)
109  )*raddeg;
110  if (TMath::Abs(a)<=0.0001) { param->AddAt(0.,6); }
111  else { param->AddAt(a,6); }
112  param->AddAt(((*(volu->getPoint(5)))(1)-(*(volu->getPoint(4)))(1))/fac,7);
113  param->AddAt(((*(volu->getPoint(5)))(0)-(*(volu->getPoint(6)))(0))/fac,8);
114  param->AddAt(((*(volu->getPoint(4)))(0)-(*(volu->getPoint(7)))(0))/fac,9);
115  a=TMath::ATan(((*(volu->getPoint(5)))(0)
116  - (*(volu->getPoint(4)))(0)
117  + (*(volu->getPoint(6)))(0)
118  - (*(volu->getPoint(7)))(0))/40./param->At(7))*raddeg;
119  if (TMath::Abs(a)<=0.0001) { param->AddAt(0.,10); }
120  else { param->AddAt(a,10); }
121 // check if coplanar
122  Double_t dx=(param->At(4) - param->At(5)) / param->At(3) * param->At(7) -
123  (param->At(8) - param->At(9));
124  if (TMath::Abs(dx)>=0.001) {
125  cout << "top and bottom plane are not coplanar for shape TRAP\n";
126  cout << "lenght in x-direction of top plane is changed\n";
127  cout << "old values: " << param->At(8) << " " << param->At(9) << "\n";
128  param->AddAt(param->At(8) + dx/2.,8);
129  param->AddAt(param->At(9) - dx/2.,9);
130  cout << "new values: " << param->At(8) << " " << param->At(9) << "\n";
131  }
132  return param;
133 }
134 
135 
137  const FairGeoTransform& dTC,const FairGeoTransform& mTR)
138 {
139  // calls the function posInMother(...) to calculate the position of the
140  // volume in its mother
141  Double_t t[3]= {0.,0.,0.};
142  for(Int_t i=0; i<8; i++) { t[0]+=(*(volu->getPoint(i)))(0); }
143  t[0]/=8.;
144  t[1]=((*(volu->getPoint(1)))(1) + (*(volu->getPoint(0)))(1) +
145  (*(volu->getPoint(5)))(1) + (*(volu->getPoint(4)))(1))/4.;
146  t[2]=((*(volu->getPoint(4)))(2) + (*(volu->getPoint(0)))(2))/2.;
149  posInMother(dTC,mTR);
150 }
151 
152