Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentConstant.cc
Go to the documentation of this file.
1#include <iostream>
2
5
6namespace Garfield {
7
10 fx(0.),
11 fy(0.),
12 fz(0.),
13 hasPotential(false),
14 x0(0.),
15 y0(0.),
16 z0(0.),
17 v0(0.),
18 hasWeightingField(false),
19 wfield(""),
20 fwx(0.),
21 fwy(0.),
22 fwz(0.),
23 hasWeightingPotential(false),
24 wx0(0.),
25 wy0(0.),
26 wz0(0.),
27 w0(0.) {
28
29 m_className = "ComponentConstant";
30}
31
32void ComponentConstant::ElectricField(const double x, const double y,
33 const double z, double& ex, double& ey,
34 double& ez, Medium*& m, int& status) {
35
36 ex = fx;
37 ey = fy;
38 ez = fz;
39 m = GetMedium(x, y, z);
40 if (m == NULL) {
41 if (debug) {
42 std::cerr << m_className << "::ElectricField:\n";
43 std::cerr << " (" << x << ", " << y << ", " << z << ")"
44 << " is not inside a medium.\n";
45 }
46 status = -6;
47 return;
48 }
49
50 if (m->IsDriftable()) {
51 status = 0;
52 } else {
53 status = -5;
54 }
55}
56
57void ComponentConstant::ElectricField(const double x, const double y,
58 const double z, double& ex, double& ey,
59 double& ez, double& v, Medium*& m,
60 int& status) {
61
62 ex = fx;
63 ey = fy;
64 ez = fz;
65 if (hasPotential) {
66 v = v0 - (x - x0) * fx - (y - y0) * fy - (z - z0) * fz;
67 } else {
68 v = 0.;
69 if (debug) {
70 std::cerr << m_className << "::ElectricField:\n";
71 std::cerr << " Potential is not defined.\n";
72 }
73 }
74
75 m = GetMedium(x, y, z);
76 if (m == NULL) {
77 if (debug) {
78 std::cerr << m_className << "::ElectricField:\n";
79 std::cerr << " (" << x << ", " << y << ", " << z << ")"
80 << " is not inside a medium.\n";
81 }
82 status = -6;
83 return;
84 }
85
86 if (m->IsDriftable()) {
87 status = 0;
88 } else {
89 status = -5;
90 }
91}
92
93bool ComponentConstant::GetVoltageRange(double& vmin, double& vmax) {
94
95 if (!hasPotential) return false;
96
97 if (theGeometry == 0) {
98 std::cerr << m_className << "::GetVoltageRange:\n";
99 std::cerr << " Geometry pointer is null.\n";
100 return false;
101 }
102 double xmin, ymin, zmin;
103 double xmax, ymax, zmax;
104 if (!GetBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax)) {
105 std::cerr << m_className << "::GetVoltageRange:\n";
106 std::cerr << " Could not determine bounding box.\n";
107 return false;
108 }
109 // Calculate potentials at each corner
110 const double pxmin = v0 - (xmin - x0) * fx;
111 const double pxmax = v0 - (xmax - x0) * fx;
112 const double pymin = -(ymin - y0) * fy;
113 const double pymax = -(ymax - y0) * fy;
114 const double pzmin = -(zmin - z0) * fz;
115 const double pzmax = -(zmax - z0) * fz;
116 double p[8];
117 p[0] = pxmin + pymin + pzmin;
118 p[1] = pxmin + pymin + pzmax;
119 p[2] = pxmin + pymax + pzmin;
120 p[3] = pxmin + pymax + pzmax;
121 p[4] = pxmax + pymin + pzmin;
122 p[5] = pxmax + pymin + pzmax;
123 p[6] = pxmax + pymax + pzmin;
124 p[7] = pxmax + pymax + pzmax;
125 vmin = vmax = p[7];
126 for (int i = 7; i--;) {
127 if (p[i] > vmax) vmax = p[i];
128 if (p[i] < vmin) vmin = p[i];
129 }
130
131 return true;
132}
133
134void ComponentConstant::WeightingField(const double x, const double y,
135 const double z, double& wx, double& wy,
136 double& wz, const std::string label) {
137
138 if (!hasWeightingField || label != wfield) return;
139
140 Medium* m = GetMedium(x, y, z);
141 if (m == NULL) {
142 wx = wy = wz = 0.;
143 if (debug) {
144 std::cout << m_className << "::WeightingField:\n";
145 std::cout << " No medium at (" << x << ", " << y << ", " << z << ")\n";
146 }
147 return;
148 }
149 wx = fwx;
150 wy = fwy;
151 wz = fwz;
152}
153
154double ComponentConstant::WeightingPotential(const double x, const double y,
155 const double z,
156 const std::string label) {
157
158 if (!hasWeightingPotential || label != wfield) return 0.;
159
160 Medium* m = GetMedium(x, y, z);
161 if (m == NULL) return 0.;
162
163 return w0 - (x - wx0) * fwx - (y - wy0) * fwy - (z - wz0) * fwz;
164}
165
166void ComponentConstant::SetElectricField(const double ex, const double ey,
167 const double ez) {
168
169 fx = ex;
170 fy = ey;
171 fz = ez;
172 if (fx * fx + fy * fy + fz * fz > Small) return;
173
174 std::cerr << m_className << "::SetField:\n";
175 std::cerr << " Electric field is set to zero.\n";
176 ready = true;
177}
178
179void ComponentConstant::SetPotential(const double x, const double y,
180 const double z, const double v) {
181
182 x0 = x;
183 y0 = y;
184 z0 = z;
185 v0 = v;
186 hasPotential = true;
187}
188
189void ComponentConstant::SetWeightingField(const double wx, const double wy,
190 const double wz,
191 const std::string label) {
192
193 wfield = label;
194 fwx = wx;
195 fwy = wy;
196 fwz = wz;
197 hasWeightingField = true;
198}
199
200void ComponentConstant::SetWeightingPotential(const double x, const double y,
201 const double z, const double v) {
202
203 if (!hasWeightingField) {
204 std::cerr << m_className << "::SetWeightingPotential:\n";
205 std::cerr << " Set the weighting field first!\n";
206 return;
207 }
208 wx0 = x;
209 wy0 = y;
210 wz0 = z;
211 w0 = v;
212 hasWeightingPotential = true;
213}
214
215void ComponentConstant::Reset() {
216
217 fx = fy = fz = 0.;
218 hasPotential = false;
219 ready = false;
220}
221
222void ComponentConstant::UpdatePeriodicity() {
223
224 if (debug) {
225 std::cerr << m_className << "::UpdatePeriodicity:\n";
226 std::cerr << " Periodicities are not supported.\n";
227 }
228}
229}
GeometryBase * theGeometry
virtual bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
virtual Medium * GetMedium(const double &x, const double &y, const double &z)
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)
void SetElectricField(const double ex, const double ey, const double ez)
double WeightingPotential(const double x, const double y, const double z, const std::string label)
bool GetVoltageRange(double &vmin, double &vmax)
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string label)
void SetPotential(const double x, const double y, const double z, const double v=0.)
void SetWeightingPotential(const double x, const double y, const double z, const double v=0.)
void SetWeightingField(const double wx, const double wy, const double wz, const std::string label)
bool IsDriftable() const
Definition: Medium.hh:57