CMS 3D CMS Logo

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