Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Component.hh
Go to the documentation of this file.
1#ifndef G_COMPONENT_H
2#define G_COMPONENT_H
3
4#include <array>
5#include <string>
6
7#include "Geometry.hh"
8
9namespace Garfield {
10
11/// Abstract base class for components.
12
13class Component {
14 public:
15 /// Default constructor.
16 Component() = delete;
17 /// Constructor
18 Component(const std::string& name);
19 /// Destructor
20 virtual ~Component() {}
21
22 /// Define the geometry.
23 virtual void SetGeometry(Geometry* geo);
24 /// Reset.
25 virtual void Clear();
26
27 /// Get the medium at a given location (x, y, z).
28 virtual Medium* GetMedium(const double x, const double y, const double z);
29
30 /** Calculate the drift field at given point.
31 *
32 * \param x,y,z coordinates [cm].
33 * \param ex,ey,ez components of the electric field [V/cm].
34 * \param m pointer to the medium at this location.
35 * \param status status flag
36 *
37 * Status flags:
38 *
39 * 0: Inside an active medium
40 * > 0: Inside a wire of type X
41 * -4 ... -1: On the side of a plane where no wires are
42 * -5: Inside the mesh but not in an active medium
43 * -6: Outside the mesh
44 * -10: Unknown potential type (should not occur)
45 * other: Other cases (should not occur)
46 */
47 virtual void ElectricField(const double x, const double y, const double z,
48 double& ex, double& ey, double& ez, Medium*& m,
49 int& status) = 0;
50 /// Calculate the drift field [V/cm] and potential [V] at (x, y, z).
51 virtual void ElectricField(const double x, const double y, const double z,
52 double& ex, double& ey, double& ez, double& v,
53 Medium*& m, int& status) = 0;
54 /// Calculate the voltage range [V].
55 virtual bool GetVoltageRange(double& vmin, double& vmax) = 0;
56
57 /** Calculate the weighting field at a given point and for a given electrode.
58 * \param x,y,z coordinates [cm].
59 * \param wx,wy,wz components of the weighting field [1/cm].
60 * \param label name of the electrode
61 */
62 virtual void WeightingField(const double x, const double y, const double z,
63 double& wx, double& wy, double& wz,
64 const std::string& label);
65 /** Calculate the weighting potential at a given point.
66 * \param x,y,z coordinates [cm].
67 * \param label name of the electrode.
68 * \return weighting potential [dimensionless].
69 */
70 virtual double WeightingPotential(const double x, const double y,
71 const double z, const std::string& label);
72 /** Calculate the delayed weighting field at a given point and time
73 * and for a given electrode.
74 * \param x,y,z coordinates [cm].
75 * \param t time [ns].
76 * \param wx,wy,wz components of the weighting field [1/cm].
77 * \param label name of the electrode
78 */
79 virtual void DelayedWeightingField(const double x, const double y,
80 const double z, const double t, double& wx,
81 double& wy, double& wz,
82 const std::string& label);
83
84 /** Calculate the delayed weighting potential at a given point and time
85 * and for a given electrode.
86 * \param x,y,z coordinates [cm].
87 * \param t time [ns].
88 * \param label name of the electrode
89 */
90 virtual double DelayedWeightingPotential(const double x, const double y,
91 const double z, const double t,
92 const std::string& label);
93
94 /** Calculate the magnetic field at a given point.
95 *
96 * \param x,y,z coordinates [cm].
97 * \param bx,by,bz components of the magnetic field [Tesla].
98 * \param status status flag.
99 */
100 virtual void MagneticField(const double x, const double y, const double z,
101 double& bx, double& by, double& bz, int& status);
102 /// Set a constant magnetic field.
103 void SetMagneticField(const double bx, const double by, const double bz);
104
105 /// Ready for use?
106 virtual bool IsReady() { return m_ready; }
107
108 /// Get the bounding box coordinates.
109 virtual bool GetBoundingBox(double& xmin, double& ymin, double& zmin,
110 double& xmax, double& ymax, double& zmax);
111
112 /// Get the coordinates of the elementary cell.
113 virtual bool GetElementaryCell(double& xmin, double& ymin, double& zmin,
114 double& xmax, double& ymax, double& zmax);
115
116 /** Integrate the normal component of the electric field over a circle.
117 * \param xc,yc centre of the circle [cm]
118 * \param r radius [cm]
119 * \param nI number of intervals for the integration
120 *
121 * \return charge enclosed in the circle [fC / cm]
122 */
123 double IntegrateFluxCircle(const double xc, const double yc, const double r,
124 const unsigned int nI = 50);
125 /** Integrate the normal component of the electric field over a sphere.
126 * \param xc,yc,zc centre of the sphere [cm]
127 * \param r radius of the sphere [cm]
128 * \param nI number of integration intervals in phi and theta
129 *
130 * \return charge enclosed in the sphere [fC]
131 */
132 double IntegrateFluxSphere(const double xc, const double yc, const double zc,
133 const double r, const unsigned int nI = 20);
134
135 /** Integrate the normal component of the electric field over a parallelogram.
136 * \param x0,y0,z0 coordinates of one of the corners [cm]
137 * \param dx1,dy1,dz1 vector to one of the adjacent corners [cm]
138 * \param dx2,dy2,dz2 vector to the other adjacent corner [cm]
139 * \param nU,nV number of integration points in the two directions
140 *
141 * \return flux [V cm]
142 */
144 const double x0, const double y0, const double z0, const double dx1,
145 const double dy1, const double dz1, const double dx2, const double dy2,
146 const double dz2, const unsigned int nU = 20, const unsigned int nV = 20);
147
148 /// Integrate the normal component of the weighting field
149 /// over a parallelogram.
150 double IntegrateWeightingFluxParallelogram(const std::string& label,
151 const double x0, const double y0, const double z0, const double dx1,
152 const double dy1, const double dz1, const double dx2, const double dy2,
153 const double dz2, const unsigned int nU = 20, const unsigned int nV = 20);
154
155 /** Integrate the electric field flux through a line from
156 * (x0,y0,z0) to (x1,y1,z1) along a direction (xp,yp,zp).
157 * \param x0,y0,z0 coordinates of the starting point
158 * \param x1,y1,z1 coordinates of the end point
159 * \param xp,yp,zp normal vector
160 * \param nI number of intervals for the integration
161 * \param isign include both negative and positive contributions (0)
162 or only contributions with a given polarity (+1,-1)
163 */
164 double IntegrateFluxLine(const double x0, const double y0, const double z0,
165 const double x1, const double y1, const double z1,
166 const double xp, const double yp, const double zp,
167 const unsigned int nI, const int isign = 0);
168
169 /** Determine whether the line between two points crosses a wire.
170 * \param x0,y0,z0 first point [cm].
171 * \param x1,y1,z1 second point [cm]
172 * \param xc,yc,zc point [cm] where the line crosses the wire or the
173 coordinates of the wire centre.
174 * \param centre flag whether to return the coordinates of the line-wire
175 * crossing point or of the wire centre.
176 * \param rc radius [cm] of the wire.
177 */
178 virtual bool IsWireCrossed(const double x0, const double y0, const double z0,
179 const double x1, const double y1, const double z1,
180 double& xc, double& yc, double& zc,
181 const bool centre, double& rc);
182 /** Determine whether a particle is inside the trap radius of a wire.
183 * \param q0 charge of the particle [in elementary charges].
184 * \param x0,y0,z0 position [cm] of the particle.
185 * \param xw,yw coordinates of the wire (if applicable).
186 * \param rw radius of the wire (if applicable).
187 */
188 virtual bool IsInTrapRadius(const double q0, const double x0, const double y0,
189 const double z0, double& xw, double& yw,
190 double& rw);
191
192 /// Enable simple periodicity in the \f$x\f$ direction.
193 void EnablePeriodicityX(const bool on = true) {
194 m_periodic[0] = on;
196 }
197 /// Enable simple periodicity in the \f$y\f$ direction.
198 void EnablePeriodicityY(const bool on = true) {
199 m_periodic[1] = on;
201 }
202 /// Enable simple periodicity in the \f$z\f$ direction.
203 void EnablePeriodicityZ(const bool on = true) {
204 m_periodic[2] = on;
206 }
207 /// Return periodicity flags.
208 void IsPeriodic(bool& perx, bool& pery, bool& perz) {
209 perx = m_periodic[0];
210 pery = m_periodic[1];
211 perz = m_periodic[2];
212 }
213
214 /// Enable mirror periodicity in the \f$x\f$ direction.
215 void EnableMirrorPeriodicityX(const bool on = true) {
216 m_mirrorPeriodic[0] = on;
218 }
219 /// Enable mirror periodicity in the \f$y\f$ direction.
220 void EnableMirrorPeriodicityY(const bool on = true) {
221 m_mirrorPeriodic[1] = on;
223 }
224 /// Enable mirror periodicity in the \f$y\f$ direction.
225 void EnableMirrorPeriodicityZ(const bool on = true) {
226 m_mirrorPeriodic[2] = on;
228 }
229 /// Return mirror periodicity flags.
230 void IsMirrorPeriodic(bool& perx, bool& pery, bool& perz) {
231 perx = m_mirrorPeriodic[0];
232 pery = m_mirrorPeriodic[1];
233 perz = m_mirrorPeriodic[2];
234 }
235
236 /// Enable axial periodicity in the \f$x\f$ direction.
237 void EnableAxialPeriodicityX(const bool on = true) {
238 m_axiallyPeriodic[0] = on;
240 }
241 /// Enable axial periodicity in the \f$y\f$ direction.
242 void EnableAxialPeriodicityY(const bool on = true) {
243 m_axiallyPeriodic[1] = on;
245 }
246 /// Enable axial periodicity in the \f$z\f$ direction.
247 void EnableAxialPeriodicityZ(const bool on = true) {
248 m_axiallyPeriodic[2] = on;
250 }
251 /// Return axial periodicity flags.
252 void IsAxiallyPeriodic(bool& perx, bool& pery, bool& perz) {
253 perx = m_axiallyPeriodic[0];
254 pery = m_axiallyPeriodic[1];
255 perz = m_axiallyPeriodic[2];
256 }
257
258 /// Enable rotation symmetry around the \f$x\f$ axis.
259 void EnableRotationSymmetryX(const bool on = true) {
260 m_rotationSymmetric[0] = on;
262 }
263 /// Enable rotation symmetry around the \f$y\f$ axis.
264 void EnableRotationSymmetryY(const bool on = true) {
265 m_rotationSymmetric[1] = on;
267 }
268 /// Enable rotation symmetry around the \f$z\f$ axis.
269 void EnableRotationSymmetryZ(const bool on = true) {
270 m_rotationSymmetric[2] = on;
272 }
273 /// Return rotation symmetry flags.
274 void IsRotationSymmetric(bool& rotx, bool& roty, bool& rotz) {
275 rotx = m_rotationSymmetric[0];
276 roty = m_rotationSymmetric[1];
277 rotz = m_rotationSymmetric[2];
278 }
279
280 /// Switch on debugging messages.
281 void EnableDebugging() { m_debug = true; }
282 /// Switch off debugging messages.
283 void DisableDebugging() { m_debug = false; }
284
285 /// Does the component have attachment maps?
286 virtual bool HasAttachmentMap() const { return false; }
287 /// Does the component have velocity maps?
288 virtual bool HasVelocityMap() const { return false; }
289
290 /// Get the electron attachment coefficient.
291 virtual bool ElectronAttachment(const double /*x*/, const double /*y*/,
292 const double /*z*/, double& eta) {
293 eta = 0;
294 return false;
295 }
296 /// Get the hole attachment coefficient.
297 virtual bool HoleAttachment(const double /*x*/, const double /*y*/,
298 const double /*z*/, double& eta) {
299 eta = 0;
300 return false;
301 }
302 /// Get the electron drift velocity.
303 virtual bool ElectronVelocity(const double /*x*/, const double /*y*/,
304 const double /*z*/, double& vx, double& vy,
305 double& vz) {
306 vx = vy = vz = 0;
307 return false;
308 }
309 /// Get the hole drift velocity.
310 virtual bool HoleVelocity(const double /*x*/, const double /*y*/,
311 const double /*z*/, double& vx, double& vy,
312 double& vz) {
313 vx = vy = vz = 0;
314 return false;
315 }
316 virtual bool GetElectronLifetime(const double /*x*/, const double /*y*/,
317 const double /*z*/, double& etau) {
318 etau = -1;
319 return false;
320 }
321 virtual bool GetHoleLifetime(const double /*x*/, const double /*y*/,
322 const double /*z*/, double& htau) {
323 htau = -1;
324 return false;
325 }
326
327 protected:
328 /// Class name.
329 std::string m_className = "Component";
330
331 /// Pointer to the geometry.
333
334 /// Constant magnetic field.
335 std::array<double, 3> m_b0 = {{0., 0., 0.}};
336
337 /// Ready for use?
338 bool m_ready = false;
339
340 /// Switch on/off debugging messages
341 bool m_debug = false;
342
343 /// Simple periodicity in x, y, z.
344 std::array<bool, 3> m_periodic = {{false, false, false}};
345 /// Mirror periodicity in x, y, z.
346 std::array<bool, 3> m_mirrorPeriodic = {{false, false, false}};
347 /// Axial periodicity in x, y, z.
348 std::array<bool, 3> m_axiallyPeriodic = {{false, false, false}};
349 /// Rotation symmetry around x-axis, y-axis, z-axis.
350 std::array<bool, 3> m_rotationSymmetric = {{false, false, false}};
351
352 /// Reset the component.
353 virtual void Reset() = 0;
354 /// Verify periodicities.
355 virtual void UpdatePeriodicity() = 0;
356 private:
357
359 const double x0, const double y0, const double z0, const double dx1,
360 const double dy1, const double dz1, const double dx2, const double dy2,
361 const double dz2, const unsigned int nU, const unsigned int nV,
362 const bool wfield, const std::string& label);
363
364};
365} // namespace Garfield
366
367#endif
Abstract base class for components.
Definition: Component.hh:13
virtual void UpdatePeriodicity()=0
Verify periodicities.
void IsAxiallyPeriodic(bool &perx, bool &pery, bool &perz)
Return axial periodicity flags.
Definition: Component.hh:252
virtual double WeightingPotential(const double x, const double y, const double z, const std::string &label)
Definition: Component.cc:59
virtual bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
Get the bounding box coordinates.
Definition: Component.cc:99
virtual bool GetHoleLifetime(const double, const double, const double, double &htau)
Definition: Component.hh:321
std::array< bool, 3 > m_rotationSymmetric
Rotation symmetry around x-axis, y-axis, z-axis.
Definition: Component.hh:350
void EnableMirrorPeriodicityX(const bool on=true)
Enable mirror periodicity in the direction.
Definition: Component.hh:215
std::array< bool, 3 > m_mirrorPeriodic
Mirror periodicity in x, y, z.
Definition: Component.hh:346
virtual void Reset()=0
Reset the component.
void DisableDebugging()
Switch off debugging messages.
Definition: Component.hh:283
void EnablePeriodicityX(const bool on=true)
Enable simple periodicity in the direction.
Definition: Component.hh:193
void IsRotationSymmetric(bool &rotx, bool &roty, bool &rotz)
Return rotation symmetry flags.
Definition: Component.hh:274
void EnableDebugging()
Switch on debugging messages.
Definition: Component.hh:281
virtual void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)=0
virtual Medium * GetMedium(const double x, const double y, const double z)
Get the medium at a given location (x, y, z).
Definition: Component.cc:22
virtual void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label)
Definition: Component.cc:40
virtual void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&m, int &status)=0
Calculate the drift field [V/cm] and potential [V] at (x, y, z).
virtual bool ElectronVelocity(const double, const double, const double, double &vx, double &vy, double &vz)
Get the electron drift velocity.
Definition: Component.hh:303
void EnablePeriodicityY(const bool on=true)
Enable simple periodicity in the direction.
Definition: Component.hh:198
virtual bool GetElectronLifetime(const double, const double, const double, double &etau)
Definition: Component.hh:316
bool m_debug
Switch on/off debugging messages.
Definition: Component.hh:341
virtual void DelayedWeightingField(const double x, const double y, const double z, const double t, double &wx, double &wy, double &wz, const std::string &label)
Definition: Component.cc:49
double IntegrateWeightingFluxParallelogram(const std::string &label, const double x0, const double y0, const double z0, const double dx1, const double dy1, const double dz1, const double dx2, const double dy2, const double dz2, const unsigned int nU=20, const unsigned int nV=20)
Definition: Component.cc:234
virtual bool IsWireCrossed(const double x0, const double y0, const double z0, const double x1, const double y1, const double z1, double &xc, double &yc, double &zc, const bool centre, double &rc)
Definition: Component.cc:110
virtual bool ElectronAttachment(const double, const double, const double, double &eta)
Get the electron attachment coefficient.
Definition: Component.hh:291
void EnablePeriodicityZ(const bool on=true)
Enable simple periodicity in the direction.
Definition: Component.hh:203
virtual bool GetVoltageRange(double &vmin, double &vmax)=0
Calculate the voltage range [V].
Component()=delete
Default constructor.
void EnableRotationSymmetryY(const bool on=true)
Enable rotation symmetry around the axis.
Definition: Component.hh:264
std::array< bool, 3 > m_periodic
Simple periodicity in x, y, z.
Definition: Component.hh:344
void EnableAxialPeriodicityY(const bool on=true)
Enable axial periodicity in the direction.
Definition: Component.hh:242
virtual bool HasVelocityMap() const
Does the component have velocity maps?
Definition: Component.hh:288
void EnableRotationSymmetryZ(const bool on=true)
Enable rotation symmetry around the axis.
Definition: Component.hh:269
void EnableAxialPeriodicityX(const bool on=true)
Enable axial periodicity in the direction.
Definition: Component.hh:237
void EnableMirrorPeriodicityZ(const bool on=true)
Enable mirror periodicity in the direction.
Definition: Component.hh:225
void IsMirrorPeriodic(bool &perx, bool &pery, bool &perz)
Return mirror periodicity flags.
Definition: Component.hh:230
void EnableMirrorPeriodicityY(const bool on=true)
Enable mirror periodicity in the direction.
Definition: Component.hh:220
virtual void Clear()
Reset.
Definition: Component.cc:27
virtual bool HoleAttachment(const double, const double, const double, double &eta)
Get the hole attachment coefficient.
Definition: Component.hh:297
std::string m_className
Class name.
Definition: Component.hh:329
double IntegrateFluxCircle(const double xc, const double yc, const double r, const unsigned int nI=50)
Definition: Component.cc:127
Geometry * m_geometry
Pointer to the geometry.
Definition: Component.hh:332
double IntegrateFluxSphere(const double xc, const double yc, const double zc, const double r, const unsigned int nI=20)
Definition: Component.cc:166
void IsPeriodic(bool &perx, bool &pery, bool &perz)
Return periodicity flags.
Definition: Component.hh:208
virtual void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status)
Definition: Component.cc:81
bool m_ready
Ready for use?
Definition: Component.hh:338
void SetMagneticField(const double bx, const double by, const double bz)
Set a constant magnetic field.
Definition: Component.cc:94
virtual bool HoleVelocity(const double, const double, const double, double &vx, double &vy, double &vz)
Get the hole drift velocity.
Definition: Component.hh:310
virtual bool IsInTrapRadius(const double q0, const double x0, const double y0, const double z0, double &xw, double &yw, double &rw)
Definition: Component.cc:118
std::array< double, 3 > m_b0
Constant magnetic field.
Definition: Component.hh:335
std::array< bool, 3 > m_axiallyPeriodic
Axial periodicity in x, y, z.
Definition: Component.hh:348
virtual bool IsReady()
Ready for use?
Definition: Component.hh:106
virtual bool HasAttachmentMap() const
Does the component have attachment maps?
Definition: Component.hh:286
void EnableAxialPeriodicityZ(const bool on=true)
Enable axial periodicity in the direction.
Definition: Component.hh:247
virtual bool GetElementaryCell(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
Get the coordinates of the elementary cell.
Definition: Component.cc:105
virtual double DelayedWeightingPotential(const double x, const double y, const double z, const double t, const std::string &label)
Definition: Component.cc:68
double IntegrateFluxParallelogram(const double x0, const double y0, const double z0, const double dx1, const double dy1, const double dz1, const double dx2, const double dy2, const double dz2, const unsigned int nU=20, const unsigned int nV=20)
Definition: Component.cc:225
virtual ~Component()
Destructor.
Definition: Component.hh:20
virtual void SetGeometry(Geometry *geo)
Define the geometry.
Definition: Component.cc:13
void EnableRotationSymmetryX(const bool on=true)
Enable rotation symmetry around the axis.
Definition: Component.hh:259
double IntegrateFluxLine(const double x0, const double y0, const double z0, const double x1, const double y1, const double z1, const double xp, const double yp, const double zp, const unsigned int nI, const int isign=0)
Definition: Component.cc:320
Abstract base class for geometry classes.
Definition: Geometry.hh:13
Abstract base class for media.
Definition: Medium.hh:13