Garfield++ 3.0
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
9 m_className = "ComponentConstant";
10}
11
12void ComponentConstant::ElectricField(const double x, const double y,
13 const double z, double& ex, double& ey,
14 double& ez, Medium*& m, int& status) {
15 ex = m_fx;
16 ey = m_fy;
17 ez = m_fz;
18 m = GetMedium(x, y, z);
19 if (!m) {
20 if (m_debug) {
21 std::cout << m_className << "::ElectricField: No medium at ("
22 << x << ", " << y << ", " << z << ").\n";
23 }
24 status = -6;
25 return;
26 }
27
28 if (m->IsDriftable()) {
29 status = 0;
30 } else {
31 status = -5;
32 }
33}
34
35void ComponentConstant::ElectricField(const double x, const double y,
36 const double z, double& ex, double& ey,
37 double& ez, double& v, Medium*& m,
38 int& status) {
39 ex = m_fx;
40 ey = m_fy;
41 ez = m_fz;
42 if (m_hasPotential) {
43 v = m_v0 - (x - m_x0) * m_fx - (y - m_y0) * m_fy - (z - m_z0) * m_fz;
44 } else {
45 v = 0.;
46 if (m_debug) {
47 std::cerr << m_className << "::ElectricField: Potential not defined.\n";
48 }
49 }
50
51 m = GetMedium(x, y, z);
52 if (!m) {
53 if (m_debug) {
54 std::cout << m_className << "::ElectricField: No medium at ("
55 << x << ", " << y << ", " << z << ").\n";
56 }
57 status = -6;
58 return;
59 }
60
61 if (m->IsDriftable()) {
62 status = 0;
63 } else {
64 status = -5;
65 }
66}
67
68bool ComponentConstant::GetVoltageRange(double& vmin, double& vmax) {
69 if (!m_hasPotential) return false;
70
71 if (!m_geometry) {
72 std::cerr << m_className << "::GetVoltageRange: Geometry not set.\n";
73 return false;
74 }
75 double xmin, ymin, zmin;
76 double xmax, ymax, zmax;
77 if (!GetBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax)) {
78 std::cerr << m_className << "::GetVoltageRange:\n"
79 << " Could not determine the bounding box.\n";
80 return false;
81 }
82 // Calculate potentials at each corner
83 const double pxmin = m_v0 - (xmin - m_x0) * m_fx;
84 const double pxmax = m_v0 - (xmax - m_x0) * m_fx;
85 const double pymin = m_v0 - (ymin - m_y0) * m_fy;
86 const double pymax = m_v0 - (ymax - m_y0) * m_fy;
87 const double pzmin = m_v0 - (zmin - m_z0) * m_fz;
88 const double pzmax = m_v0 - (zmax - m_z0) * m_fz;
89 double p[8];
90 p[0] = pxmin + pymin + pzmin;
91 p[1] = pxmin + pymin + pzmax;
92 p[2] = pxmin + pymax + pzmin;
93 p[3] = pxmin + pymax + pzmax;
94 p[4] = pxmax + pymin + pzmin;
95 p[5] = pxmax + pymin + pzmax;
96 p[6] = pxmax + pymax + pzmin;
97 p[7] = pxmax + pymax + pzmax;
98 vmin = vmax = p[7];
99 for (int i = 7; i--;) {
100 if (p[i] > vmax) vmax = p[i];
101 if (p[i] < vmin) vmin = p[i];
102 }
103
104 return true;
105}
106
107void ComponentConstant::WeightingField(const double x, const double y,
108 const double z, double& wx, double& wy,
109 double& wz, const std::string& label) {
110 if (!m_hasWeightingField || label != m_wfield) return;
111
112 Medium* m = GetMedium(x, y, z);
113 if (!m) {
114 wx = wy = wz = 0.;
115 if (m_debug) {
116 std::cout << m_className << "::WeightingField: No medium at ("
117 << x << ", " << y << ", " << z << ")\n";
118 }
119 return;
120 }
121 wx = m_fwx;
122 wy = m_fwy;
123 wz = m_fwz;
124}
125
126double ComponentConstant::WeightingPotential(const double x, const double y,
127 const double z,
128 const std::string& label) {
129 if (!m_hasWeightingPotential || label != m_wfield) return 0.;
130
131 Medium* m = GetMedium(x, y, z);
132 if (!m) return 0.;
133
134 return m_w0 - (x - m_wx0) * m_fwx - (y - m_wy0) * m_fwy - (z - m_wz0) * m_fwz;
135}
136
137void ComponentConstant::SetElectricField(const double ex, const double ey,
138 const double ez) {
139 m_fx = ex;
140 m_fy = ey;
141 m_fz = ez;
142 if (m_fx * m_fx + m_fy * m_fy + m_fz * m_fz > Small) return;
143
144 std::cerr << m_className << "::SetElectricField: Field set to zero.\n";
145 m_ready = true;
146}
147
148void ComponentConstant::SetPotential(const double x, const double y,
149 const double z, const double v) {
150 m_x0 = x;
151 m_y0 = y;
152 m_z0 = z;
153 m_v0 = v;
154 m_hasPotential = true;
155}
156
157void ComponentConstant::SetWeightingField(const double wx, const double wy,
158 const double wz,
159 const std::string label) {
160 m_wfield = label;
161 m_fwx = wx;
162 m_fwy = wy;
163 m_fwz = wz;
164 m_hasWeightingField = true;
165}
166
167void ComponentConstant::SetWeightingPotential(const double x, const double y,
168 const double z, const double v) {
169 if (!m_hasWeightingField) {
170 std::cerr << m_className << "::SetWeightingPotential:\n"
171 << " Set the weighting field first!\n";
172 return;
173 }
174 m_wx0 = x;
175 m_wy0 = y;
176 m_wz0 = z;
177 m_w0 = v;
178 m_hasWeightingPotential = true;
179}
180
181void ComponentConstant::Reset() {
182 m_fx = m_fy = m_fz = 0.;
183 m_hasPotential = false;
184 m_hasWeightingField = false;
185 m_hasWeightingPotential = false;
186 m_wfield = "";
187 m_ready = false;
188}
189
190void ComponentConstant::UpdatePeriodicity() {
191 if (m_debug) {
192 std::cerr << m_className << "::UpdatePeriodicity:\n"
193 << " Periodicities are not supported.\n";
194 }
195}
196}
Abstract base class for components.
GeometryBase * m_geometry
Pointer to the geometry.
bool m_ready
Ready for use?
virtual bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
Get the bounding box coordinates.
std::string m_className
Class name.
bool m_debug
Switch on/off debugging messages.
virtual Medium * GetMedium(const double x, const double y, const double z)
Get the medium at a given location (x, y, z).
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status) override
void SetElectricField(const double ex, const double ey, const double ez)
Set the components of the electric field [V / cm].
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
void SetPotential(const double x, const double y, const double z, const double v=0.)
Specify the potential at a given point.
void SetWeightingPotential(const double x, const double y, const double z, const double v=0.)
Specify the weighting potential at a given point.
void SetWeightingField(const double wx, const double wy, const double wz, const std::string label)
Set the components of the weighting field [1 / cm].
Abstract base class for media.
Definition: Medium.hh:13
bool IsDriftable() const
Is charge carrier transport enabled in this medium?
Definition: Medium.hh:74