Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentBase.hh
Go to the documentation of this file.
1#ifndef G_COMPONENT_BASE_H
2#define G_COMPONENT_BASE_H
3
4#include <array>
5#include <string>
6
7#include "GeometryBase.hh"
8
9namespace Garfield {
10
11/// Abstract base class for components.
12
14 public:
15 /// Constructor
17 /// Destructor
18 virtual ~ComponentBase() {}
19
20 /// Define the geometry.
21 virtual void SetGeometry(GeometryBase* geo);
22 /// Reset.
23 virtual void Clear();
24
25 /// Get the medium at a given location (x, y, z).
26 virtual Medium* GetMedium(const double x, const double y, const double z);
27
28 /** Calculate the drift field at given point.
29 *
30 * \param x,y,z coordinates [cm].
31 * \param ex,ey,ez components of the electric field [V/cm].
32 * \param m pointer to the medium at this location.
33 * \param status status flag
34 *
35 * Status flags:
36 *
37 * 0: Inside an active medium
38 * > 0: Inside a wire of type X
39 * -4 ... -1: On the side of a plane where no wires are
40 * -5: Inside the mesh but not in an active medium
41 * -6: Outside the mesh
42 * -10: Unknown potential type (should not occur)
43 * other: Other cases (should not occur)
44 */
45 virtual void ElectricField(const double x, const double y, const double z,
46 double& ex, double& ey, double& ez, Medium*& m,
47 int& status) = 0;
48 /// Calculate the drift field [V/cm] and potential [V] at (x, y, z).
49 virtual void ElectricField(const double x, const double y, const double z,
50 double& ex, double& ey, double& ez, double& v,
51 Medium*& m, int& status) = 0;
52 /// Calculate the voltage range [V].
53 virtual bool GetVoltageRange(double& vmin, double& vmax) = 0;
54
55 /** Calculate the weighting field at a given point and for a given electrode.
56 * \param x,y,z coordinates [cm].
57 * \param wx,wy,wz components of the weighting field [1/cm].
58 * \param label name of the electrode
59 */
60 virtual void WeightingField(const double x, const double y, const double z,
61 double& wx, double& wy, double& wz,
62 const std::string& label);
63 /** Calculate the weighting potential at a given point.
64 * \param x,y,z coordinates [cm].
65 * \param label name of the electrode.
66 * \return weighting potential [dimensionless].
67 */
68 virtual double WeightingPotential(const double x, const double y,
69 const double z, const std::string& label);
70 /** Calculate the delayed weighting field at a given point and time
71 * and for a given electrode.
72 * \param x,y,z coordinates [cm].
73 * \param t time [ns].
74 * \param wx,wy,wz components of the weighting field [1/cm].
75 * \param label name of the electrode
76 */
77 virtual void DelayedWeightingField(const double x, const double y,
78 const double z, const double t,
79 double& wx, double& wy, double& wz,
80 const std::string& label);
81
82 /** Calculate the magnetic field at a given point.
83 *
84 * \param x,y,z coordinates [cm].
85 * \param bx,by,bz components of the magnetic field [Tesla].
86 * \param status status flag.
87 */
88 virtual void MagneticField(const double x, const double y, const double z,
89 double& bx, double& by, double& bz, int& status);
90 /// Set a constant magnetic field.
91 void SetMagneticField(const double bx, const double by, const double bz);
92
93 /// Ready for use?
94 virtual bool IsReady() { return m_ready; }
95
96 /// Get the bounding box coordinates.
97 virtual bool GetBoundingBox(double& xmin, double& ymin, double& zmin,
98 double& xmax, double& ymax, double& zmax);
99
100 /** Integrate the normal component of the electric field over a circle.
101 * \param xc,yc centre of the circle [cm]
102 * \param r radius [cm]
103 * \param nI number of intervals for the integration
104 *
105 * \return charge enclosed in the circle [fC / cm]
106 */
107 double IntegrateFluxCircle(const double xc, const double yc, const double r,
108 const unsigned int nI = 50);
109 /** Integrate the normal component of the electric field over a sphere.
110 * \param xc,yc,zc centre of the sphere [cm]
111 * \param r radius of the sphere [cm]
112 * \param nI number of integration intervals in phi and theta
113 *
114 * \return charge enclosed in the sphere [fC]
115 */
116 double IntegrateFluxSphere(const double xc, const double yc, const double zc,
117 const double r, const unsigned int nI = 20);
118
119 /** Integrate the normal component of the electric field over a parallelogram.
120 * \param x0,y0,z0 coordinates of one of the corners [cm]
121 * \param dx1,dy1,dz1 vector to one of the adjacent corners [cm]
122 * \param dx2,dy2,dz2 vector to the other adjacent corner [cm]
123 * \param nU,nV number of integration points in the two directions
124 *
125 * \return flux [V cm]
126 */
127 double IntegrateFlux(const double x0, const double y0, const double z0,
128 const double dx1, const double dy1, const double dz1,
129 const double dx2, const double dy2, const double dz2,
130 const unsigned int nU = 20, const unsigned int nV = 20);
131
132 /** Determine whether the line between two points crosses a wire.
133 * \param x0,y0,z0 first point [cm].
134 * \param x1,y1,z1 second point [cm]
135 * \param xc,yc,zc point [cm] where the line crosses the wire or the
136 coordinates of the wire centre.
137 * \param centre flag whether to return the coordinates of the line-wire
138 * crossing point or of the wire centre.
139 * \param rc radius [cm] of the wire.
140 */
141 virtual bool IsWireCrossed(const double x0, const double y0, const double z0,
142 const double x1, const double y1, const double z1,
143 double& xc, double& yc, double& zc,
144 const bool centre, double& rc);
145 /** Determine whether a particle is inside the trap radius of a wire.
146 * \param q0 charge of the particle [in elementary charges].
147 * \param x0,y0,z0 position [cm] of the particle.
148 * \param xw,yw coordinates of the wire (if applicable).
149 * \param rw radius of the wire (if applicable).
150 */
151 virtual bool IsInTrapRadius(const double q0, const double x0, const double y0,
152 const double z0, double& xw, double& yw,
153 double& rw);
154
155 /// Enable simple periodicity in the \f$x\f$ direction.
156 void EnablePeriodicityX(const bool on = true) {
157 m_periodic[0] = on;
159 }
161 /// Enable simple periodicity in the \f$y\f$ direction.
162 void EnablePeriodicityY(const bool on = true) {
163 m_periodic[1] = on;
165 }
167 /// Enable simple periodicity in the \f$z\f$ direction.
168 void EnablePeriodicityZ(const bool on = true) {
169 m_periodic[2] = on;
171 }
173
174 /// Enable mirror periodicity in the \f$x\f$ direction.
175 void EnableMirrorPeriodicityX(const bool on = true) {
176 m_mirrorPeriodic[0] = on;
178 }
180 /// Enable mirror periodicity in the \f$y\f$ direction.
181 void EnableMirrorPeriodicityY(const bool on = true) {
182 m_mirrorPeriodic[1] = on;
184 }
186 /// Enable mirror periodicity in the \f$y\f$ direction.
187 void EnableMirrorPeriodicityZ(const bool on = true) {
188 m_mirrorPeriodic[2] = on;
190 }
192
193 /// Enable axial periodicity in the \f$x\f$ direction.
194 void EnableAxialPeriodicityX(const bool on = true) {
195 m_axiallyPeriodic[0] = on;
197 }
199 /// Enable axial periodicity in the \f$y\f$ direction.
200 void EnableAxialPeriodicityY(const bool on = true) {
201 m_axiallyPeriodic[1] = on;
203 }
205 /// Enable axial periodicity in the \f$z\f$ direction.
206 void EnableAxialPeriodicityZ(const bool on = true) {
207 m_axiallyPeriodic[2] = on;
209 }
211
212 /// Enable rotation symmetry around the \f$x\f$ axis.
213 void EnableRotationSymmetryX(const bool on = true) {
214 m_rotationSymmetric[0] = on;
216 }
218 /// Enable rotation symmetry around the \f$y\f$ axis.
219 void EnableRotationSymmetryY(const bool on = true) {
220 m_rotationSymmetric[1] = on;
222 }
224 /// Enable rotation symmetry around the \f$z\f$ axis.
225 void EnableRotationSymmetryZ(const bool on = true) {
226 m_rotationSymmetric[2] = on;
228 }
230
231 /// Switch on debugging messages.
232 void EnableDebugging() { m_debug = true; }
233 /// Switch off debugging messages.
234 void DisableDebugging() { m_debug = false; }
235
236 /// Request trapping to be taken care of by the component (for TCAD).
237 void ActivateTraps() { m_activeTraps = true; }
238 void DeactivateTraps() { m_activeTraps = false; }
239 bool IsTrapActive() { return m_activeTraps; }
240
241 /// Request velocity to be taken care of by the component (for TCAD).
245
246 /// Get the electron attachment coefficient.
247 virtual bool ElectronAttachment(const double /*x*/, const double /*y*/,
248 const double /*z*/, double& eta) {
249 eta = 0;
250 return false;
251 }
252 /// Get the hole attachment coefficient.
253 virtual bool HoleAttachment(const double /*x*/, const double /*y*/,
254 const double /*z*/, double& eta) {
255 eta = 0;
256 return false;
257 }
258 /// Get the electron drift velocity.
259 virtual void ElectronVelocity(const double /*x*/, const double /*y*/,
260 const double /*z*/, double& vx, double& vy,
261 double& vz, Medium*& /*m*/, int& status) {
262 vx = vy = vz = 0;
263 status = -100;
264 }
265 /// Get the hole drift velocity.
266 virtual void HoleVelocity(const double /*x*/, const double /*y*/,
267 const double /*z*/, double& vx, double& vy,
268 double& vz, Medium*& /*m*/, int& status) {
269 vx = vy = vz = 0;
270 status = -100;
271 }
272 virtual bool GetElectronLifetime(const double /*x*/, const double /*y*/,
273 const double /*z*/, double& etau) {
274 etau = -1;
275 return false;
276 }
277 virtual bool GetHoleLifetime(const double /*x*/, const double /*y*/,
278 const double /*z*/, double& htau) {
279 htau = -1;
280 return false;
281 }
282
283 protected:
284 /// Class name.
285 std::string m_className = "ComponentBase";
286
287 /// Pointer to the geometry.
289
290 /// Ready for use?
291 bool m_ready = false;
292
293 /// Does the component have traps?
294 bool m_activeTraps = false;
295 /// Does the component have velocity maps?
296 bool m_hasVelocityMap = false;
297
298 /// Simple periodicity in x, y, z.
299 std::array<bool, 3> m_periodic = {{false, false, false}};
300 /// Mirror periodicity in x, y, z.
301 std::array<bool, 3> m_mirrorPeriodic = {{false, false, false}};
302 /// Axial periodicity in x, y, z.
303 std::array<bool, 3> m_axiallyPeriodic = {{false, false, false}};
304 /// Rotation symmetry around x-axis, y-axis, z-axis.
305 std::array<bool, 3> m_rotationSymmetric = {{false, false, false}};
306
307 double m_bx0 = 0., m_by0 = 0., m_bz0 = 0.; //< Constant magnetic field.
308
309 /// Switch on/off debugging messages
310 bool m_debug = false;
311
312 /// Reset the component.
313 virtual void Reset() = 0;
314 /// Verify periodicities.
315 virtual void UpdatePeriodicity() = 0;
316};
317}
318
319#endif
Abstract base class for components.
double IntegrateFluxSphere(const double xc, const double yc, const double zc, const double r, const unsigned int nI=20)
std::array< bool, 3 > m_periodic
Simple periodicity in x, y, z.
virtual void ElectronVelocity(const double, const double, const double, double &vx, double &vy, double &vz, Medium *&, int &status)
Get the electron drift velocity.
virtual void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)=0
ComponentBase()
Constructor.
Definition: ComponentBase.cc:9
double IntegrateFluxCircle(const double xc, const double yc, const double r, const unsigned int nI=50)
void EnableDebugging()
Switch on debugging messages.
virtual ~ComponentBase()
Destructor.
virtual void HoleVelocity(const double, const double, const double, double &vx, double &vy, double &vz, Medium *&, int &status)
Get the hole drift velocity.
std::array< bool, 3 > m_rotationSymmetric
Rotation symmetry around x-axis, y-axis, z-axis.
void ActivateVelocityMap()
Request velocity to be taken care of by the component (for TCAD).
void EnableAxialPeriodicityX(const bool on=true)
Enable axial periodicity in the direction.
virtual double WeightingPotential(const double x, const double y, const double z, const std::string &label)
virtual void Clear()
Reset.
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)
std::array< bool, 3 > m_axiallyPeriodic
Axial periodicity in x, y, z.
GeometryBase * m_geometry
Pointer to the geometry.
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).
void EnableRotationSymmetryX(const bool on=true)
Enable rotation symmetry around the axis.
virtual void UpdatePeriodicity()=0
Verify periodicities.
virtual bool IsReady()
Ready for use?
void SetMagneticField(const double bx, const double by, const double bz)
Set a constant magnetic field.
bool m_activeTraps
Does the component have traps?
void ActivateTraps()
Request trapping to be taken care of by the component (for TCAD).
virtual bool GetElectronLifetime(const double, const double, const double, double &etau)
void EnableMirrorPeriodicityZ(const bool on=true)
Enable mirror periodicity in the direction.
virtual void Reset()=0
Reset the component.
void EnablePeriodicityZ(const bool on=true)
Enable simple periodicity in the direction.
void EnablePeriodicityX(const bool on=true)
Enable simple periodicity in the direction.
virtual void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status)
void DisableDebugging()
Switch off debugging messages.
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)
bool m_ready
Ready for use?
std::array< bool, 3 > m_mirrorPeriodic
Mirror periodicity in x, y, z.
virtual bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
Get the bounding box coordinates.
virtual bool HoleAttachment(const double, const double, const double, double &eta)
Get the hole attachment coefficient.
void EnableMirrorPeriodicityY(const bool on=true)
Enable mirror periodicity in the direction.
virtual bool GetHoleLifetime(const double, const double, const double, double &htau)
void EnableMirrorPeriodicityX(const bool on=true)
Enable mirror periodicity in the direction.
virtual void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label)
void EnableRotationSymmetryY(const bool on=true)
Enable rotation symmetry around the axis.
void EnableAxialPeriodicityY(const bool on=true)
Enable axial periodicity in the direction.
void EnablePeriodicityY(const bool on=true)
Enable simple periodicity in the direction.
double IntegrateFlux(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)
void EnableAxialPeriodicityZ(const bool on=true)
Enable axial periodicity in the direction.
std::string m_className
Class name.
virtual void SetGeometry(GeometryBase *geo)
Define the geometry.
virtual bool IsInTrapRadius(const double q0, const double x0, const double y0, const double z0, double &xw, double &yw, double &rw)
bool m_debug
Switch on/off debugging messages.
virtual bool ElectronAttachment(const double, const double, const double, double &eta)
Get the electron attachment coefficient.
bool m_hasVelocityMap
Does the component have velocity maps?
virtual Medium * GetMedium(const double x, const double y, const double z)
Get the medium at a given location (x, y, z).
void EnableRotationSymmetryZ(const bool on=true)
Enable rotation symmetry around the axis.
virtual bool GetVoltageRange(double &vmin, double &vmax)=0
Calculate the voltage range [V].
Abstract base class for geometry classes.
Definition: GeometryBase.hh:13
Abstract base class for media.
Definition: Medium.hh:13