Garfield++ v1r0
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, const double& z) const {
17
18 // Transform the point to local coordinates
19 const double dx = x - m_cX;
20 const double dy = y - m_cY;
21 const double dz = z - m_cZ;
22
23 if (fabs(dx) > m_rMax || fabs(dy) > m_rMax || fabs(dz) > m_rMax) {
24 if (m_debug) {
25 std::cout << "SolidSphere::IsInside:\n";
26 std::cout << " (" << x << ", " << y << ", " << z << ")"
27 << " is outside.\n";
28 }
29 return false;
30 }
31
32 const double r = sqrt(dx * dx + dy * dy + dz * dz);
33 if (r >= m_rMin && r <= m_rMax) {
34 if (m_debug) {
35 std::cout << "SolidSphere::IsInside:\n";
36 std::cout << " (" << x << ", " << y << ", " << z << ")"
37 << " is inside.\n";
38 }
39 return true;
40 }
41
42 if (m_debug) {
43 std::cout << "SolidSphere::IsInside:\n";
44 std::cout << " (" << x << ", " << y << ", " << z << ") "
45 << " is outside.\n";
46 }
47 return false;
48}
49
50bool SolidSphere::GetBoundingBox(double& xmin, double& ymin, double& zmin,
51 double& xmax, double& ymax, double& zmax) const {
52
53 xmin = m_cX - m_rMax;
54 xmax = m_cX + m_rMax;
55 ymin = m_cY - m_rMax;
56 ymax = m_cY + m_rMax;
57 zmin = m_cZ - m_rMax;
58 zmax = m_cZ + m_rMax;
59 return true;
60}
61
62bool SolidSphere::GetCenter(double& x, double& y, double& z) const {
63
64 x = m_cX;
65 y = m_cY;
66 z = m_cZ;
67 return true;
68}
69
70bool SolidSphere::GetDimensions(double& l1, double& l2, double& l3) const {
71
72 l1 = m_rMin;
73 l2 = m_rMax;
74 l3 = 0.;
75 return true;
76}
77
78bool SolidSphere::GetOrientation(double& ctheta, double& stheta, double& cphi,
79 double& sphi) const {
80
81 ctheta = 1.;
82 stheta = 0.;
83 cphi = 1.;
84 sphi = 0.;
85 return true;
86}
87
88void SolidSphere::SetInnerRadius(const double& rmin) {
89
90 if (rmin <= 0.) {
91 std::cerr << "SolidSphere::SetInnerRadius:\n";
92 std::cerr << " Radius must be > 0.\n";
93 return;
94 }
95 if (rmin >= m_rMax) {
96 std::cerr << "SolidSphere::SetInnerRadius:\n";
97 std::cerr << " Inner radius must be smaller than outer radius.\n";
98 return;
99 }
100 m_rMin = rmin;
101}
102
103void SolidSphere::SetOuterRadius(const double& rmax) {
104
105 if (rmax <= 0.) {
106 std::cerr << "SolidSphere::SetOuterRadius:\n";
107 std::cerr << " Radius must be > 0.\n";
108 return;
109 }
110 if (rmax <= m_rMin) {
111 std::cerr << "SolidSphere::SetOuterRadius:\n";
112 std::cerr << " Outer radius must be greater than inner radius.\n";
113 return;
114 }
115 m_rMax = rmax;
116}
117
118}
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:313
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:616
virtual bool GetCenter(double &x, double &y, double &z) const
Definition: SolidSphere.cc:62
virtual bool IsInside(const double &x, const double &y, const double &z) const
Definition: SolidSphere.cc:16
void SetInnerRadius(const double &rmin)
Definition: SolidSphere.cc:88
void SetOuterRadius(const double &rmax)
Definition: SolidSphere.cc:103
virtual bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const
Definition: SolidSphere.cc:50
virtual bool GetOrientation(double &ctheta, double &stheta, double &cphi, double &sphi) const
Definition: SolidSphere.cc:78
SolidSphere(const double &cx, const double &cy, const double &cz, const double &rmin, const double &rmax)
Definition: SolidSphere.cc:10
virtual bool GetDimensions(double &l1, double &l2, double &l3) const
Definition: SolidSphere.cc:70
bool m_debug
Definition: Solid.hh:35