CMS 3D CMS Logo

Trap.cc
Go to the documentation of this file.
2 
3 #include <cmath>
4 #include <vector>
5 
6 #include "CLHEP/Units/GlobalSystemOfUnits.h"
7 #include "CLHEP/Units/SystemOfUnits.h"
10 
11 using std::sqrt;
12 
13 
14 DDI::Trap::Trap( double pDz,
15  double pTheta,
16  double pPhi,
17  double pDy1, double pDx1,double pDx2,
18  double pAlp1,
19  double pDy2, double pDx3, double pDx4,
20  double pAlp2 )
21  : Solid(ddtrap)
22 {
23  p_.push_back(pDz); // ......... 0
24  p_.push_back(pTheta); // .. 1
25  p_.push_back(pPhi); // ....... 2
26  p_.push_back(pDy1); // ........ 3
27  p_.push_back(pDx1); // ........ 4
28  p_.push_back(pDx2); // ........ 5
29  p_.push_back(pAlp1); // ....... 6
30  p_.push_back(pDy2); // ........ 7
31  p_.push_back(pDx3); // ......... 8
32  p_.push_back(pDx4); // ........ 9
33  p_.push_back(pAlp2);
34 }
35 
36 
37 void DDI::Trap::stream(std::ostream & os) const
38 {
39  os << " dz=" << p_[0]/cm
40  << " theta=" << p_[1]/deg
41  << " phi=" << p_[2]/deg
42  << " dy1=" << p_[3]/cm
43  << " dx1=" << p_[4]/cm
44  << " dx2=" << p_[5]/cm
45  << " alpha1=" << p_[6]/deg
46  << " dy2=" << p_[7]/cm
47  << " dx3=" << p_[8]/cm
48  << " dx4=" << p_[9]/cm
49  << " alpha2=" << p_[10]/deg;
50 }
51 
52 double DDI::Trap::volume() const
53 {
54  double volume=0;
55 
56  /* use notation as described in documentation about geant 3 shapes */
57  /* we do not need all the parameters.*/
58 
59  double Dz=p_[0];
60  double H1=p_[3];
61  double Bl1=p_[4];
62  double Tl1=p_[5];
63  double H2=p_[7];
64  double Bl2=p_[8];
65  double Tl2=p_[9];
66 
67  double z=2*Dz;
68 
69  /* the area of a trapezoid with one side of length 2*Bl1 and other side 2*Tl1, and height 2*H1 is 0.5*(2*Bl1+2*Tl1)*2H1=2*H1(Bl1+Tl1) */
70 
71  /* the volume of a geometry defined by 2 2D parallel trapezoids is (in this case the integral over the area of a trapezoid that is defined as function x between these two trapezoids */
72 
73  /* the following formula describes this parmeterized area in x. x=0: trapezoid defined by H1,Bl1,Tl1, x=z: trapezoid defined by H2,Bl2,Tl2 */
74 
75  /* area(x)=2*(H1+x/z*(H2-H1))*(Bl1+x/z*(Bl2-Bl1)+Tl1+x/z*(Tl2-Tl1)) */
76 
77  /* primitive of area(x):
78  (2*H1*Bl1+2*H1*Tl1)*x+(H1*Bl2-2*H1*Bl1+H1*Tl2-2*H1*Tl1+H2*Bl1+H2*Tl1+H2*Tl2-H2*Tl1)*x*x/z+(2/3)*(H2*Bl2-H2*Bl1-H1*Bl2+H1*Bl1-H1*Tl2+H1*Tl1)*x*x*x/(z*z) */
79 
80 // volume=(2*H1*Bl1+2*H1*Tl1)*z+(H1*Bl2-2*H1*Bl1+H1*Tl2-2*H1*Tl1+H2*Bl1+H2*Tl1+H2*Tl2-H2*Tl1)*z*z+(2/3)*(H2*Bl2-H2*Bl1-H1*Bl2+H1*Bl1-H1*Tl2+H1*Tl1)*z*z*z;
81  volume=(2*H1*Bl1+2*H1*Tl1)*z+(H1*Bl2-2*H1*Bl1+H1*Tl2-2*H1*Tl1+H2*Bl1+H2*Tl1+H2*Tl2-H2*Tl1)*z+(2/3)*(H2*Bl2-H2*Bl1-H1*Bl2+H1*Bl1-H1*Tl2+H1*Tl1)*z;
82 
83 
84  /*
85  Alternative:
86  A ... height of bottom trapez, B ... middle line perpendicular to A
87  a ... height of top trapez, b ... middle line perpendicular to a
88  H ... heigt of the solid
89 
90  V = H/3. * ( A*B + 0.5 * ( A*b + B*a ) + a*b ) <-- this is wrong ..
91  V = H/3 * ( A*B + sqrt( A*B*a*b ) + a*b )
92  */
93 // double A = 2.*p_[3];
94 // double B = p_[4] + p_[5];
95 // double a = 2.*p_[7];
96 // double b = p_[8] + p_[9];
97 
98 
99 // double volu_alt = 2.*p_[0]/3. * ( A*B + sqrt ( A*b*B*a ) + a*b );
100 // DCOUT('V', "alternative-volume=" << volu_alt/m3 << std::endl);
101 
102  //DCOUT_V('C',"DC: solid=" << this->ddname() << " vol=" << volume << " vol_a=" << volu_alt << " d=" << (volume-volu_alt)/volume*100. << "%");
103  return volume;
104 }
double volume() const
Definition: Trap.cc:52
Trap(double pDz, double pTheta, double pPhi, double pDy1, double pDx1, double pDx2, double pAlp1, double pDy2, double pDx3, double pDx4, double pAlp2)
Definition: Trap.cc:14
void stream(std::ostream &) const
Definition: Trap.cc:37
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< double > p_
Definition: Solid.h:32