Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
SolidTube.cc
Go to the documentation of this file.
1#include <iostream>
2#include <cmath>
3
4#include "SolidTube.hh"
7
8namespace Garfield {
9
10SolidTube::SolidTube(const double& cx, const double& cy, const double& cz,
11 const double& rmin, const double& rmax, const double& lz)
12 : Solid(),
13 m_cX(cx), m_cY(cy), m_cZ(cz),
14 m_rMin(rmin), m_rMax(rmax),
15 m_lZ(lz),
16 m_dX(0.), m_dY(0.), m_dZ(1.),
17 m_cPhi(1.), m_sPhi(0.),
18 m_cTheta(1.), m_sTheta(0.) {}
19
20SolidTube::SolidTube(const double& cx, const double& cy, const double& cz,
21 const double& rmin, const double& rmax, const double& lz,
22 const double& dx, const double& dy, const double& dz)
23 : Solid(),
24 m_cX(cx), m_cY(cy), m_cZ(cz),
25 m_rMin(rmin), m_rMax(rmax),
26 m_lZ(lz),
27 m_dX(0.), m_dY(0.), m_dZ(1.),
28 m_cPhi(1.), m_sPhi(0.),
29 m_cTheta(1.), m_sTheta(0.) {
30
31 const double d = sqrt(dx * dx + dy * dy + dz * dz);
32 if (d < Small) {
33 std::cerr << "SolidTube: Direction vector has zero norm.\n";
34 } else {
35 m_dX = dx / d;
36 m_dY = dy / d;
37 m_dZ = dz / d;
38 double phi, theta;
39 const double dt = sqrt(m_dX * m_dX + m_dY * m_dY);
40 if (dt < Small) {
41 phi = 0.;
42 if (m_dZ > 0.) {
43 theta = 0.;
44 } else {
45 theta = Pi;
46 }
47 } else {
48 phi = atan2(m_dY, m_dX);
49 theta = atan2(dt, m_dZ);
50 }
51 m_cTheta = cos(theta);
52 m_sTheta = sin(theta);
53 m_cPhi = cos(phi);
54 m_sPhi = sin(phi);
55 }
56}
57
58bool SolidTube::IsInside(const double& x, const double& y, const double& z) const {
59
60 // Transform the point to local coordinates
61 const double dx = x - m_cX;
62 const double dy = y - m_cY;
63 const double dz = z - m_cZ;
64 const double u = m_cPhi * m_cTheta * dx + m_sPhi * m_cTheta * dy - m_sTheta * dz;
65 const double v = -m_sPhi * dx + m_cPhi * dy;
66 const double w = m_cPhi * m_sTheta * dx + m_sPhi * m_sTheta * dy + m_cTheta * dz;
67
68 if (fabs(w) > m_lZ) {
69 if (m_debug) {
70 std::cout << "SolidTube::IsInside:\n";
71 std::cout << " (" << x << ", " << y << ", " << z << ")"
72 << " is outside.\n";
73 }
74 return false;
75 }
76
77 const double r = sqrt(u * u + v * v);
78 if (r >= m_rMin && r <= m_rMax) {
79 if (m_debug) {
80 std::cout << "SolidTube::IsInside:\n";
81 std::cout << " (" << x << ", " << y << ", " << z << ")"
82 << " is inside.\n";
83 }
84 return true;
85 }
86
87 if (m_debug) {
88 std::cout << "SolidTube::IsInside:\n";
89 std::cout << " (" << x << ", " << y << ", " << z << ") "
90 << " is outside.\n";
91 }
92 return false;
93}
94
95bool SolidTube::GetBoundingBox(double& xmin, double& ymin, double& zmin,
96 double& xmax, double& ymax, double& zmax) const {
97
98 if (m_cTheta == 1. && m_cPhi == 1.) {
99 xmin = m_cX - m_rMax;
100 xmax = m_cX + m_rMax;
101 ymin = m_cY - m_rMax;
102 ymax = m_cY + m_rMax;
103 zmin = m_cZ - m_lZ;
104 zmax = m_cZ + m_lZ;
105 return true;
106 }
107
108 const double dd = sqrt(m_rMax * m_rMax + m_lZ * m_lZ);
109 xmin = m_cX - dd;
110 xmax = m_cX + dd;
111 ymin = m_cY - dd;
112 ymax = m_cY + dd;
113 zmin = m_cZ - dd;
114 zmax = m_cZ + dd;
115 return true;
116}
117
118bool SolidTube::GetCenter(double& x, double& y, double& z) const {
119
120 x = m_cX;
121 y = m_cY;
122 z = m_cZ;
123 return true;
124}
125
126bool SolidTube::GetDimensions(double& l1, double& l2, double& l3) const {
127
128 l1 = m_rMin;
129 l2 = m_rMax;
130 l3 = m_lZ;
131 return true;
132}
133
134bool SolidTube::GetOrientation(double& ctheta, double& stheta, double& cphi,
135 double& sphi) const {
136
137 ctheta = m_cTheta;
138 stheta = m_sTheta;
139 cphi = m_cPhi;
140 sphi = m_sPhi;
141 return true;
142}
143
144void SolidTube::SetInnerRadius(const double& rmin) {
145
146 if (rmin <= 0.) {
147 std::cerr << "SolidTube::SetInnerRadius:\n";
148 std::cerr << " Radius must be > 0.\n";
149 return;
150 }
151 if (rmin >= m_rMax) {
152 std::cerr << "SolidTube::SetInnerRadius:\n";
153 std::cerr << " Inner radius must be smaller than outer radius.\n";
154 return;
155 }
156 m_rMin = rmin;
157}
158
159void SolidTube::SetOuterRadius(const double& rmax) {
160
161 if (rmax <= 0.) {
162 std::cerr << "SolidTube::SetOuterRadius:\n";
163 std::cerr << " Radius must be > 0.\n";
164 return;
165 }
166 if (rmax <= m_rMin) {
167 std::cerr << "SolidTube::SetOuterRadius:\n";
168 std::cerr << " Outer radius must be greater than inner radius.\n";
169 return;
170 }
171 m_rMax = rmax;
172}
173
174void SolidTube::SetHalfLengthZ(const double& lz) {
175
176 if (lz <= 0.) {
177 std::cerr << "SolidTube::SetHalfLengthZ:\n";
178 std::cerr << " Half-length must be > 0.\n";
179 return;
180 }
181 m_lZ = lz;
182}
183}
DoubleAc cos(const DoubleAc &f)
Definition: DoubleAc.cpp:431
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:313
DoubleAc sin(const DoubleAc &f)
Definition: DoubleAc.cpp:383
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:616
void SetInnerRadius(const double &rmin)
Definition: SolidTube.cc:144
void SetHalfLengthZ(const double &lz)
Definition: SolidTube.cc:174
virtual bool GetOrientation(double &ctheta, double &stheta, double &cphi, double &sphi) const
Definition: SolidTube.cc:134
virtual bool GetDimensions(double &l1, double &l2, double &l3) const
Definition: SolidTube.cc:126
virtual bool IsInside(const double &x, const double &y, const double &z) const
Definition: SolidTube.cc:58
void SetOuterRadius(const double &rmax)
Definition: SolidTube.cc:159
virtual bool GetCenter(double &x, double &y, double &z) const
Definition: SolidTube.cc:118
virtual bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const
Definition: SolidTube.cc:95
SolidTube(const double &cx, const double &cy, const double &cz, const double &rmin, const double &rmax, const double &lz)
Definition: SolidTube.cc:10
bool m_debug
Definition: Solid.hh:35