Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Sensor.hh
Go to the documentation of this file.
1// Sensor
2
3#ifndef G_SENSOR_H
4#define G_SENSOR_H
5
6#include <vector>
7
8#include "ComponentBase.hh"
9
10namespace Garfield {
11
12class Sensor {
13
14 public:
15 // Constructor
16 Sensor();
17 // Destructor
19
20 // Add a component
21 void AddComponent(ComponentBase* comp);
22 int GetNumberOfComponents() { return m_nComponents; }
23 // Add an electrode
24 void AddElectrode(ComponentBase* comp, std::string label);
25 int GetNumberOfElectrodes() { return m_nElectrodes; }
26 // Remove all components, electrodes and reset the sensor
27 void Clear();
28
29 // Get the drift field at (x, y, z)
30 void ElectricField(const double x, const double y, const double z, double& ex,
31 double& ey, double& ez, double& v, Medium*& medium,
32 int& status);
33 void ElectricField(const double x, const double y, const double z, double& ex,
34 double& ey, double& ez, Medium*& medium, int& status);
35
36 // Get the magnetic field at (x, y, z)
37 void MagneticField(const double x, const double y, const double z, double& bx,
38 double& by, double& bz, int& status);
39
40 // Get the weighting field at (x, y, z)
41 void WeightingField(const double x, const double y, const double z,
42 double& wx, double& wy, double& wz,
43 const std::string label);
44 // Get the weighting potential at (x, y, z)
45 double WeightingPotential(const double x, const double y, const double z,
46 const std::string label);
47
48 // Get the medium at (x, y, z)
49 bool GetMedium(const double x, const double y, const double z,
50 Medium*& medium);
51
52 // Set the user area
53 bool SetArea();
54 bool SetArea(const double xmin, const double ymin, const double zmin,
55 const double xmax, const double ymax, const double zmax);
56 // Return the current user area
57 bool GetArea(double& xmin, double& ymin, double& zmin, double& xmax,
58 double& ymax, double& zmax);
59 // Check if a point is inside the user area
60 bool IsInArea(const double x, const double y, const double z);
61
62 bool IsWireCrossed(const double x0, const double y0, const double z0,
63 const double x1, const double y1, const double z1,
64 double& xc, double& yc, double& zc);
65
66 bool IsInTrapRadius(double x0, double y0, double z0, double& xw, double& yw,
67 double& rw);
68
69 // Return the voltage range
70 bool GetVoltageRange(double& vmin, double& vmax);
71
72 // Signal calculation
73 void NewSignal() { ++m_nEvents; }
74 // Reset signals and induced charges of all electrodes
75 void ClearSignal();
76 void AddSignal(const double& q, const double& t, const double& dt,
77 const double& x, const double& y, const double& z,
78 const double& vx, const double& vy, const double& vz);
79 void AddInducedCharge(const double q, const double x0, const double y0,
80 const double z0, const double x1, const double y1,
81 const double z1);
82 // Set/get the time window and binning for the signal calculation
83 void SetTimeWindow(const double tstart, const double tstep, const int nsteps);
84 void GetTimeWindow(double& tstart, double& tstep, int& nsteps) {
85 tstart = m_tStart;
86 tstep = m_tStep;
87 nsteps = m_nTimeBins;
88 }
89 double GetSignal(const std::string label, const int bin);
90 double GetElectronSignal(const std::string label, const int bin);
91 double GetIonSignal(const std::string label, const int bin);
92 double GetInducedCharge(const std::string label);
93 void SetTransferFunction(double (*f)(double t));
94 void SetTransferFunction(std::vector<double> times,
95 std::vector<double> values);
96 double GetTransferFunction(const double t);
97 bool ConvoluteSignal();
98 bool IntegrateSignal();
99 void SetNoiseFunction(double (*f)(double t));
100 void AddNoise();
101 bool ComputeThresholdCrossings(const double thr, const std::string label,
102 int& n);
103 int GetNumberOfThresholdCrossings() { return m_nThresholdCrossings; }
104 bool GetThresholdCrossing(const int i, double& time, double& level,
105 bool& rise);
106
107 // Switch on/off debugging messages
108 void EnableDebugging() { m_debug = true; }
109 void DisableDebugging() { m_debug = false; }
110
111 private:
112 std::string m_className;
113
114 // Components
115 int m_nComponents;
116 struct component {
117 ComponentBase* comp;
118 };
119 std::vector<component> m_components;
120 int m_lastComponent;
121
122 // Electrodes
123 int m_nElectrodes;
124 struct electrode {
125 ComponentBase* comp;
126 std::string label;
127 std::vector<double> signal;
128 std::vector<double> electronsignal;
129 std::vector<double> ionsignal;
130 double charge;
131 };
132 std::vector<electrode> m_electrodes;
133
134 // Time window for signals
135 int m_nTimeBins;
136 double m_tStart, m_tStep;
137 int m_nEvents;
138 static double m_signalConversion;
139
140 // Transfer function
141 bool m_hasTransferFunction;
142 double (*m_fTransfer)(double t);
143 std::vector<double> m_transferFunctionTimes;
144 std::vector<double> m_transferFunctionValues;
145
146 // Noise
147 bool m_hasNoiseFunction;
148 double (*m_fNoise)(double t);
149
150 int m_nThresholdCrossings;
151 struct thresholdCrossing {
152 double time;
153 bool rise;
154 };
155 std::vector<thresholdCrossing> m_thresholdCrossings;
156 double m_thresholdLevel;
157
158 // User bounding box
159 bool m_hasUserArea;
160 double m_xMinUser, m_yMinUser, m_zMinUser;
161 double m_xMaxUser, m_yMaxUser, m_zMaxUser;
162
163 // Switch on/off debugging messages
164 bool m_debug;
165
166 // Return the current sensor size
167 bool GetBoundingBox(double& xmin, double& ymin, double& zmin, double& xmax,
168 double& ymax, double& zmax);
169
170 double InterpolateTransferFunctionTable(double t);
171};
172}
173
174#endif
void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status)
Definition: Sensor.cc:95
bool GetVoltageRange(double &vmin, double &vmax)
Definition: Sensor.cc:363
bool ComputeThresholdCrossings(const double thr, const std::string label, int &n)
Definition: Sensor.cc:809
void AddElectrode(ComponentBase *comp, std::string label)
Definition: Sensor.cc:317
bool IntegrateSignal()
Definition: Sensor.cc:752
bool GetThresholdCrossing(const int i, double &time, double &level, bool &rise)
Definition: Sensor.cc:961
double GetTransferFunction(const double t)
Definition: Sensor.cc:684
void AddSignal(const double &q, const double &t, const double &dt, const double &x, const double &y, const double &z, const double &vx, const double &vy, const double &vz)
Definition: Sensor.cc:409
double WeightingPotential(const double x, const double y, const double z, const std::string label)
Definition: Sensor.cc:128
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string label)
Definition: Sensor.cc:110
int GetNumberOfComponents()
Definition: Sensor.hh:22
double GetInducedCharge(const std::string label)
Definition: Sensor.cc:608
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&medium, int &status)
Definition: Sensor.cc:44
int GetNumberOfElectrodes()
Definition: Sensor.hh:25
bool SetArea()
Definition: Sensor.cc:165
void SetNoiseFunction(double(*f)(double t))
Definition: Sensor.cc:776
bool IsInArea(const double x, const double y, const double z)
Definition: Sensor.cc:254
bool IsInTrapRadius(double x0, double y0, double z0, double &xw, double &yw, double &rw)
Definition: Sensor.cc:291
bool GetMedium(const double x, const double y, const double z, Medium *&medium)
Definition: Sensor.cc:141
void Clear()
Definition: Sensor.cc:349
double GetElectronSignal(const std::string label, const int bin)
Definition: Sensor.cc:556
void SetTransferFunction(double(*f)(double t))
Definition: Sensor.cc:624
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)
Definition: Sensor.cc:278
bool ConvoluteSignal()
Definition: Sensor.cc:691
void AddComponent(ComponentBase *comp)
Definition: Sensor.cc:302
void DisableDebugging()
Definition: Sensor.hh:109
void EnableDebugging()
Definition: Sensor.hh:108
void SetTimeWindow(const double tstart, const double tstep, const int nsteps)
Definition: Sensor.cc:518
void AddNoise()
Definition: Sensor.cc:787
int GetNumberOfThresholdCrossings()
Definition: Sensor.hh:103
void ClearSignal()
Definition: Sensor.cc:396
void AddInducedCharge(const double q, const double x0, const double y0, const double z0, const double x1, const double y1, const double z1)
Definition: Sensor.cc:493
double GetIonSignal(const std::string label, const int bin)
Definition: Sensor.cc:574
void GetTimeWindow(double &tstart, double &tstep, int &nsteps)
Definition: Sensor.hh:84
double GetSignal(const std::string label, const int bin)
Definition: Sensor.cc:591
void NewSignal()
Definition: Sensor.hh:73
bool GetArea(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
Definition: Sensor.cc:227