Garfield++ v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
SolidSphere.cc
Go to the documentation of this file.
1#include <iostream>
2#include <cmath>
3
4#include "SolidSphere.hh"
7
8namespace Garfield {
9
10SolidSphere::SolidSphere(const double cx, const double cy, const double cz,
11 const double rmin, const double rmax)
12 : Solid(),
13 m_cX(cx), m_cY(cy), m_cZ(cz),
14 m_rMin(rmin), m_rMax(rmax) {}
15
16bool SolidSphere::IsInside(const double x, const double y,
17 const double z) const {
18
19 // Transform the point to local coordinates
20 const double dx = x - m_cX;
21 const double dy = y - m_cY;
22 const double dz = z - m_cZ;
23
24 if (fabs(dx) > m_rMax || fabs(dy) > m_rMax || fabs(dz) > m_rMax) {
25 if (m_debug) {
26 std::cout << "SolidSphere::IsInside:\n";
27 std::cout << " (" << x << ", " << y << ", " << z << ")"
28 << " is outside.\n";
29 }
30 return false;
31 }
32
33 const double r = sqrt(dx * dx + dy * dy + dz * dz);
34 if (r >= m_rMin && r <= m_rMax) {
35 if (m_debug) {
36 std::cout << "SolidSphere::IsInside:\n";
37 std::cout << " (" << x << ", " << y << ", " << z << ")"
38 << " is inside.\n";
39 }
40 return true;
41 }
42
43 if (m_debug) {
44 std::cout << "SolidSphere::IsInside:\n";
45 std::cout << " (" << x << ", " << y << ", " << z << ") "
46 << " is outside.\n";
47 }
48 return false;
49}
50
51bool SolidSphere::GetBoundingBox(double& xmin, double& ymin, double& zmin,
52 double& xmax, double& ymax, double& zmax) const {
53
54 xmin = m_cX - m_rMax;
55 xmax = m_cX + m_rMax;
56 ymin = m_cY - m_rMax;
57 ymax = m_cY + m_rMax;
58 zmin = m_cZ - m_rMax;
59 zmax = m_cZ + m_rMax;
60 return true;
61}
62
63bool SolidSphere::GetCenter(double& x, double& y, double& z) const {
64
65 x = m_cX;
66 y = m_cY;
67 z = m_cZ;
68 return true;
69}
70
71bool SolidSphere::GetDimensions(double& l1, double& l2, double& l3) const {
72
73 l1 = m_rMin;
74 l2 = m_rMax;
75 l3 = 0.;
76 return true;
77}
78
79bool SolidSphere::GetOrientation(double& ctheta, double& stheta, double& cphi,
80 double& sphi) const {
81
82 ctheta = 1.;
83 stheta = 0.;
84 cphi = 1.;
85 sphi = 0.;
86 return true;
87}
88
89void SolidSphere::SetInnerRadius(const double rmin) {
90
91 if (rmin <= 0.) {
92 std::cerr << "SolidSphere::SetInnerRadius:\n";
93 std::cerr << " Radius must be > 0.\n";
94 return;
95 }
96 if (rmin >= m_rMax) {
97 std::cerr << "SolidSphere::SetInnerRadius:\n";
98 std::cerr << " Inner radius must be smaller than outer radius.\n";
99 return;
100 }
101 m_rMin = rmin;
102}
103
104void SolidSphere::SetOuterRadius(const double rmax) {
105
106 if (rmax <= 0.) {
107 std::cerr << "SolidSphere::SetOuterRadius:\n";
108 std::cerr << " Radius must be > 0.\n";
109 return;
110 }
111 if (rmax <= m_rMin) {
112 std::cerr << "SolidSphere::SetOuterRadius:\n";
113 std::cerr << " Outer radius must be greater than inner radius.\n";
114 return;
115 }
116 m_rMax = rmax;
117}
118
119}
virtual bool GetCenter(double &x, double &y, double &z) const
Definition: SolidSphere.cc:63
SolidSphere(const double cx, const double cy, const double cz, const double rmin, const double rmax)
Constructor.
Definition: SolidSphere.cc:10
void SetOuterRadius(const double rmax)
Definition: SolidSphere.cc:104
virtual bool IsInside(const double x, const double y, const double z) const
Check whether a given point is inside the solid.
Definition: SolidSphere.cc:16
virtual bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const
Return the bounding box of the solid.
Definition: SolidSphere.cc:51
virtual bool GetOrientation(double &ctheta, double &stheta, double &cphi, double &sphi) const
Definition: SolidSphere.cc:79
virtual bool GetDimensions(double &l1, double &l2, double &l3) const
Definition: SolidSphere.cc:71
void SetInnerRadius(const double rmin)
Definition: SolidSphere.cc:89
Abstract base class for solids.
Definition: Solid.hh:8
bool m_debug
Definition: Solid.hh:39