Garfield++ 5.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 drift field [V/cm] at (x, y, z).
55 std::array<double, 3> ElectricField(const double x, const double y,
56 const double z);
57 /// Calculate the (drift) electrostatic potential [V] at (x, y, z).
58 virtual double ElectricPotential(const double x, const double y,
59 const double z);
60 /// Calculate the voltage range [V].
61 virtual bool GetVoltageRange(double& vmin, double& vmax) = 0;
62
63 /** Calculate the weighting field at a given point and for a given electrode.
64 * \param x,y,z coordinates [cm].
65 * \param wx,wy,wz components of the weighting field [1/cm].
66 * \param label name of the electrode
67 */
68 virtual void WeightingField(const double x, const double y, const double z,
69 double& wx, double& wy, double& wz,
70 const std::string& label);
71 /** Calculate the weighting potential at a given point.
72 * \param x,y,z coordinates [cm].
73 * \param label name of the electrode.
74 * \return weighting potential [dimensionless].
75 */
76 virtual double WeightingPotential(const double x, const double y,
77 const double z, const std::string& label);
78 /** Calculate the delayed weighting field at a given point and time
79 * and for a given electrode.
80 * \param x,y,z coordinates [cm].
81 * \param t time [ns].
82 * \param wx,wy,wz components of the weighting field [1/cm].
83 * \param label name of the electrode
84 */
85 virtual void DelayedWeightingField(const double x, const double y,
86 const double z, const double t, double& wx,
87 double& wy, double& wz,
88 const std::string& label);
89
90 /** Calculate the delayed weighting potential at a given point and time
91 * and for a given electrode.
92 * \param x,y,z coordinates [cm].
93 * \param t time [ns].
94 * \param label name of the electrode
95 */
96 virtual double DelayedWeightingPotential(const double x, const double y,
97 const double z, const double t,
98 const std::string& label);
99
100 /** Calculate the magnetic field at a given point.
101 *
102 * \param x,y,z coordinates [cm].
103 * \param bx,by,bz components of the magnetic field [Tesla].
104 * \param status status flag.
105 */
106 virtual void MagneticField(const double x, const double y, const double z,
107 double& bx, double& by, double& bz, int& status);
108 /// Set a constant magnetic field.
109 void SetMagneticField(const double bx, const double by, const double bz);
110
111 /// Ready for use?
112 virtual bool IsReady() { return m_ready; }
113
114 /// Get the bounding box coordinates.
115 virtual bool GetBoundingBox(double& xmin, double& ymin, double& zmin,
116 double& xmax, double& ymax, double& zmax);
117
118 /// Get the coordinates of the elementary cell.
119 virtual bool GetElementaryCell(double& xmin, double& ymin, double& zmin,
120 double& xmax, double& ymax, double& zmax);
121
122 /** Integrate the normal component of the electric field over a circle.
123 * \param xc,yc centre of the circle [cm]
124 * \param r radius [cm]
125 * \param nI number of intervals for the integration
126 *
127 * \return charge enclosed in the circle [fC / cm]
128 */
129 double IntegrateFluxCircle(const double xc, const double yc, const double r,
130 const unsigned int nI = 50);
131 /** Integrate the normal component of the electric field over a sphere.
132 * \param xc,yc,zc centre of the sphere [cm]
133 * \param r radius of the sphere [cm]
134 * \param nI number of integration intervals in phi and theta
135 *
136 * \return charge enclosed in the sphere [fC]
137 */
138 double IntegrateFluxSphere(const double xc, const double yc, const double zc,
139 const double r, const unsigned int nI = 20);
140
141 /** Integrate the normal component of the electric field over a parallelogram.
142 * \param x0,y0,z0 coordinates of one of the corners [cm]
143 * \param dx1,dy1,dz1 vector to one of the adjacent corners [cm]
144 * \param dx2,dy2,dz2 vector to the other adjacent corner [cm]
145 * \param nU,nV number of integration points in the two directions
146 *
147 * \return flux [V cm]
148 */
150 const double x0, const double y0, const double z0, const double dx1,
151 const double dy1, const double dz1, const double dx2, const double dy2,
152 const double dz2, const unsigned int nU = 20, const unsigned int nV = 20);
153
154 /// Integrate the normal component of the weighting field
155 /// over a parallelogram.
156 double IntegrateWeightingFluxParallelogram(const std::string& label,
157 const double x0, const double y0, const double z0, const double dx1,
158 const double dy1, const double dz1, const double dx2, const double dy2,
159 const double dz2, const unsigned int nU = 20, const unsigned int nV = 20);
160
161 /** Integrate the electric field flux through a line from
162 * (x0,y0,z0) to (x1,y1,z1) along a direction (xp,yp,zp).
163 * \param x0,y0,z0 coordinates of the starting point
164 * \param x1,y1,z1 coordinates of the end point
165 * \param xp,yp,zp normal vector
166 * \param nI number of intervals for the integration
167 * \param isign include both negative and positive contributions (0)
168 or only contributions with a given polarity (+1,-1)
169 */
170 double IntegrateFluxLine(const double x0, const double y0, const double z0,
171 const double x1, const double y1, const double z1,
172 const double xp, const double yp, const double zp,
173 const unsigned int nI, const int isign = 0);
174
175 /** Determine whether the line between two points crosses a wire.
176 * \param x0,y0,z0 first point [cm].
177 * \param x1,y1,z1 second point [cm]
178 * \param xc,yc,zc point [cm] where the line crosses the wire or the
179 coordinates of the wire centre.
180 * \param centre flag whether to return the coordinates of the line-wire
181 * crossing point or of the wire centre.
182 * \param rc radius [cm] of the wire.
183 */
184 virtual bool CrossedWire(const double x0, const double y0, const double z0,
185 const double x1, const double y1, const double z1,
186 double& xc, double& yc, double& zc,
187 const bool centre, double& rc);
188 /** Determine whether a particle is inside the trap radius of a wire.
189 * \param q0 charge of the particle [in elementary charges].
190 * \param x0,y0,z0 position [cm] of the particle.
191 * \param xw,yw coordinates of the wire (if applicable).
192 * \param rw radius of the wire (if applicable).
193 */
194 virtual bool InTrapRadius(const double q0, const double x0, const double y0,
195 const double z0, double& xw, double& yw,
196 double& rw);
197 /** Determine whether the line between two points crosses a plane.
198 */
199 virtual bool CrossedPlane(const double x0, const double y0, const double z0,
200 const double x1, const double y1, const double z1,
201 double& xc, double& yc, double& zc);
202
203 /// Enable simple periodicity in the \f$x\f$ direction.
204 void EnablePeriodicityX(const bool on = true) {
205 m_periodic[0] = on;
207 }
208 /// Enable simple periodicity in the \f$y\f$ direction.
209 void EnablePeriodicityY(const bool on = true) {
210 m_periodic[1] = on;
212 }
213 /// Enable simple periodicity in the \f$z\f$ direction.
214 void EnablePeriodicityZ(const bool on = true) {
215 m_periodic[2] = on;
217 }
218 /// Return periodicity flags.
219 void IsPeriodic(bool& perx, bool& pery, bool& perz) {
220 perx = m_periodic[0];
221 pery = m_periodic[1];
222 perz = m_periodic[2];
223 }
224
225 /// Enable mirror periodicity in the \f$x\f$ direction.
226 void EnableMirrorPeriodicityX(const bool on = true) {
227 m_mirrorPeriodic[0] = on;
229 }
230 /// Enable mirror periodicity in the \f$y\f$ direction.
231 void EnableMirrorPeriodicityY(const bool on = true) {
232 m_mirrorPeriodic[1] = on;
234 }
235 /// Enable mirror periodicity in the \f$y\f$ direction.
236 void EnableMirrorPeriodicityZ(const bool on = true) {
237 m_mirrorPeriodic[2] = on;
239 }
240 /// Return mirror periodicity flags.
241 void IsMirrorPeriodic(bool& perx, bool& pery, bool& perz) {
242 perx = m_mirrorPeriodic[0];
243 pery = m_mirrorPeriodic[1];
244 perz = m_mirrorPeriodic[2];
245 }
246
247 /// Enable axial periodicity in the \f$x\f$ direction.
248 void EnableAxialPeriodicityX(const bool on = true) {
249 m_axiallyPeriodic[0] = on;
251 }
252 /// Enable axial periodicity in the \f$y\f$ direction.
253 void EnableAxialPeriodicityY(const bool on = true) {
254 m_axiallyPeriodic[1] = on;
256 }
257 /// Enable axial periodicity in the \f$z\f$ direction.
258 void EnableAxialPeriodicityZ(const bool on = true) {
259 m_axiallyPeriodic[2] = on;
261 }
262 /// Return axial periodicity flags.
263 void IsAxiallyPeriodic(bool& perx, bool& pery, bool& perz) {
264 perx = m_axiallyPeriodic[0];
265 pery = m_axiallyPeriodic[1];
266 perz = m_axiallyPeriodic[2];
267 }
268
269 /// Enable rotation symmetry around the \f$x\f$ axis.
270 void EnableRotationSymmetryX(const bool on = true) {
271 m_rotationSymmetric[0] = on;
273 }
274 /// Enable rotation symmetry around the \f$y\f$ axis.
275 void EnableRotationSymmetryY(const bool on = true) {
276 m_rotationSymmetric[1] = on;
278 }
279 /// Enable rotation symmetry around the \f$z\f$ axis.
280 void EnableRotationSymmetryZ(const bool on = true) {
281 m_rotationSymmetric[2] = on;
283 }
284 /// Return rotation symmetry flags.
285 void IsRotationSymmetric(bool& rotx, bool& roty, bool& rotz) {
286 rotx = m_rotationSymmetric[0];
287 roty = m_rotationSymmetric[1];
288 rotz = m_rotationSymmetric[2];
289 }
290
291 /// Switch on debugging messages.
292 void EnableDebugging() { m_debug = true; }
293 /// Switch off debugging messages.
294 void DisableDebugging() { m_debug = false; }
295
296 /// Does the component have a non-zero magnetic field?
297 virtual bool HasMagneticField() const;
298
299 /// Does the component have maps of the Townsend coefficient?
300 virtual bool HasTownsendMap() const { return false; }
301 /// Does the component have attachment maps?
302 virtual bool HasAttachmentMap() const { return false; }
303 /// Does the component have velocity maps?
304 virtual bool HasVelocityMap() const { return false; }
305
306 /// Get the electron attachment coefficient.
307 virtual bool ElectronAttachment(const double /*x*/, const double /*y*/,
308 const double /*z*/, double& eta) {
309 eta = 0;
310 return false;
311 }
312 /// Get the hole attachment coefficient.
313 virtual bool HoleAttachment(const double /*x*/, const double /*y*/,
314 const double /*z*/, double& eta) {
315 eta = 0;
316 return false;
317 }
318 /// Get the electron Townsend coefficient.
319 virtual bool ElectronTownsend(const double /*x*/, const double /*y*/,
320 const double /*z*/, double& alpha) {
321 alpha = 0;
322 return false;
323 }
324 /// Get the hole Townsend coefficient.
325 virtual bool HoleTownsend(const double /*x*/, const double /*y*/,
326 const double /*z*/, double& alpha) {
327 alpha = 0;
328 return false;
329 }
330 /// Get the electron drift velocity.
331 virtual bool ElectronVelocity(const double /*x*/, const double /*y*/,
332 const double /*z*/, double& vx, double& vy,
333 double& vz) {
334 vx = vy = vz = 0;
335 return false;
336 }
337 /// Get the hole drift velocity.
338 virtual bool HoleVelocity(const double /*x*/, const double /*y*/,
339 const double /*z*/, double& vx, double& vy,
340 double& vz) {
341 vx = vy = vz = 0;
342 return false;
343 }
344 virtual bool GetElectronLifetime(const double /*x*/, const double /*y*/,
345 const double /*z*/, double& etau) {
346 etau = -1;
347 return false;
348 }
349 virtual bool GetHoleLifetime(const double /*x*/, const double /*y*/,
350 const double /*z*/, double& htau) {
351 htau = -1;
352 return false;
353 }
354
355 virtual double StepSizeHint() { return -1.; }
356
357 protected:
358 /// Class name.
359 std::string m_className = "Component";
360
361 /// Pointer to the geometry.
363
364 /// Constant magnetic field.
365 std::array<double, 3> m_b0 = {{0., 0., 0.}};
366
367 /// Ready for use?
368 bool m_ready = false;
369
370 /// Switch on/off debugging messages
371 bool m_debug = false;
372
373 /// Simple periodicity in x, y, z.
374 std::array<bool, 3> m_periodic = {{false, false, false}};
375 /// Mirror periodicity in x, y, z.
376 std::array<bool, 3> m_mirrorPeriodic = {{false, false, false}};
377 /// Axial periodicity in x, y, z.
378 std::array<bool, 3> m_axiallyPeriodic = {{false, false, false}};
379 /// Rotation symmetry around x-axis, y-axis, z-axis.
380 std::array<bool, 3> m_rotationSymmetric = {{false, false, false}};
381
382 /// Reset the component.
383 virtual void Reset() = 0;
384 /// Verify periodicities.
385 virtual void UpdatePeriodicity() = 0;
386 private:
387
389 const double x0, const double y0, const double z0, const double dx1,
390 const double dy1, const double dz1, const double dx2, const double dy2,
391 const double dz2, const unsigned int nU, const unsigned int nV,
392 const bool wfield, const std::string& label);
393
394};
395} // namespace Garfield
396
397#endif
virtual void UpdatePeriodicity()=0
Verify periodicities.
void IsAxiallyPeriodic(bool &perx, bool &pery, bool &perz)
Return axial periodicity flags.
Definition Component.hh:263
virtual double WeightingPotential(const double x, const double y, const double z, const std::string &label)
Definition Component.cc:80
virtual bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
Get the bounding box coordinates.
Definition Component.cc:120
virtual bool GetHoleLifetime(const double, const double, const double, double &htau)
Definition Component.hh:349
std::array< bool, 3 > m_rotationSymmetric
Rotation symmetry around x-axis, y-axis, z-axis.
Definition Component.hh:380
void EnableMirrorPeriodicityX(const bool on=true)
Enable mirror periodicity in the direction.
Definition Component.hh:226
std::array< bool, 3 > m_mirrorPeriodic
Mirror periodicity in x, y, z.
Definition Component.hh:376
virtual void Reset()=0
Reset the component.
void DisableDebugging()
Switch off debugging messages.
Definition Component.hh:294
void EnablePeriodicityX(const bool on=true)
Enable simple periodicity in the direction.
Definition Component.hh:204
void IsRotationSymmetric(bool &rotx, bool &roty, bool &rotz)
Return rotation symmetry flags.
Definition Component.hh:285
void EnableDebugging()
Switch on debugging messages.
Definition Component.hh:292
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:24
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:61
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:331
virtual bool CrossedWire(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:131
void EnablePeriodicityY(const bool on=true)
Enable simple periodicity in the direction.
Definition Component.hh:209
virtual bool GetElectronLifetime(const double, const double, const double, double &etau)
Definition Component.hh:344
bool m_debug
Switch on/off debugging messages.
Definition Component.hh:371
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:70
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:259
virtual bool InTrapRadius(const double q0, const double x0, const double y0, const double z0, double &xw, double &yw, double &rw)
Definition Component.cc:139
virtual bool ElectronAttachment(const double, const double, const double, double &eta)
Get the electron attachment coefficient.
Definition Component.hh:307
virtual bool CrossedPlane(const double x0, const double y0, const double z0, const double x1, const double y1, const double z1, double &xc, double &yc, double &zc)
Definition Component.cc:148
void EnablePeriodicityZ(const bool on=true)
Enable simple periodicity in the direction.
Definition Component.hh:214
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:275
std::array< bool, 3 > m_periodic
Simple periodicity in x, y, z.
Definition Component.hh:374
void EnableAxialPeriodicityY(const bool on=true)
Enable axial periodicity in the direction.
Definition Component.hh:253
virtual bool ElectronTownsend(const double, const double, const double, double &alpha)
Get the electron Townsend coefficient.
Definition Component.hh:319
virtual bool HasVelocityMap() const
Does the component have velocity maps?
Definition Component.hh:304
void EnableRotationSymmetryZ(const bool on=true)
Enable rotation symmetry around the axis.
Definition Component.hh:280
void EnableAxialPeriodicityX(const bool on=true)
Enable axial periodicity in the direction.
Definition Component.hh:248
void EnableMirrorPeriodicityZ(const bool on=true)
Enable mirror periodicity in the direction.
Definition Component.hh:236
void IsMirrorPeriodic(bool &perx, bool &pery, bool &perz)
Return mirror periodicity flags.
Definition Component.hh:241
virtual bool HasMagneticField() const
Does the component have a non-zero magnetic field?
Definition Component.cc:155
void EnableMirrorPeriodicityY(const bool on=true)
Enable mirror periodicity in the direction.
Definition Component.hh:231
virtual void Clear()
Reset.
Definition Component.cc:29
virtual bool HasTownsendMap() const
Does the component have maps of the Townsend coefficient?
Definition Component.hh:300
virtual bool HoleAttachment(const double, const double, const double, double &eta)
Get the hole attachment coefficient.
Definition Component.hh:313
virtual double ElectricPotential(const double x, const double y, const double z)
Calculate the (drift) electrostatic potential [V] at (x, y, z).
Definition Component.cc:52
std::string m_className
Class name.
Definition Component.hh:359
double IntegrateFluxCircle(const double xc, const double yc, const double r, const unsigned int nI=50)
Definition Component.cc:160
Geometry * m_geometry
Pointer to the geometry.
Definition Component.hh:362
virtual bool HoleTownsend(const double, const double, const double, double &alpha)
Get the hole Townsend coefficient.
Definition Component.hh:325
double IntegrateFluxSphere(const double xc, const double yc, const double zc, const double r, const unsigned int nI=20)
Definition Component.cc:195
void IsPeriodic(bool &perx, bool &pery, bool &perz)
Return periodicity flags.
Definition Component.hh:219
virtual void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status)
Definition Component.cc:102
bool m_ready
Ready for use?
Definition Component.hh:368
void SetMagneticField(const double bx, const double by, const double bz)
Set a constant magnetic field.
Definition Component.cc:115
virtual bool HoleVelocity(const double, const double, const double, double &vx, double &vy, double &vz)
Get the hole drift velocity.
Definition Component.hh:338
std::array< double, 3 > m_b0
Constant magnetic field.
Definition Component.hh:365
std::array< bool, 3 > m_axiallyPeriodic
Axial periodicity in x, y, z.
Definition Component.hh:378
virtual bool IsReady()
Ready for use?
Definition Component.hh:112
virtual double StepSizeHint()
Definition Component.hh:355
virtual bool HasAttachmentMap() const
Does the component have attachment maps?
Definition Component.hh:302
void EnableAxialPeriodicityZ(const bool on=true)
Enable axial periodicity in the direction.
Definition Component.hh:258
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:126
virtual double DelayedWeightingPotential(const double x, const double y, const double z, const double t, const std::string &label)
Definition Component.cc:89
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:250
virtual ~Component()
Destructor.
Definition Component.hh:20
virtual void SetGeometry(Geometry *geo)
Define the geometry.
Definition Component.cc:15
void EnableRotationSymmetryX(const bool on=true)
Enable rotation symmetry around the axis.
Definition Component.hh:270
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:341
Abstract base class for geometry classes.
Definition Geometry.hh:13
Abstract base class for media.
Definition Medium.hh:16