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