48 void ElectricField(
const double x,
const double y,
const double z,
double& ex,
49 double& ey,
double& ez,
double& v,
Medium*& medium,
52 void ElectricField(
const double x,
const double y,
const double z,
double& ex,
53 double& ey,
double& ez,
Medium*& medium,
int& status);
56 void MagneticField(
const double x,
const double y,
const double z,
double& bx,
57 double& by,
double& bz,
int& status);
60 void WeightingField(
const double x,
const double y,
const double z,
61 double& wx,
double& wy,
double& wz,
62 const std::string& label);
65 const std::string& label);
69 const double z,
const double t,
70 const std::string& label);
79 bool SetArea(
const bool verbose =
false);
81 bool SetArea(
const double xmin,
const double ymin,
const double zmin,
82 const double xmax,
const double ymax,
const double zmax);
84 bool GetArea(
double& xmin,
double& ymin,
double& zmin,
double& xmax,
85 double& ymax,
double& zmax);
87 bool IsInArea(
const double x,
const double y,
const double z);
90 bool IsInside(
const double x,
const double y,
const double z);
106 const unsigned int nsteps);
109 unsigned int& nsteps)
const {
112 nsteps = m_nTimeBins;
124 m_nAvgDelayedSignal = navg;
128 void SetSignal(
const std::string& label,
const unsigned int bin,
129 const double signal);
132 const std::vector<double>& ts,
133 const std::vector<double>& is);
135 double GetSignal(
const std::string& label,
const unsigned int bin);
137 double GetSignal(
const std::string& label,
const unsigned int bin,
140 double GetPromptSignal(
const std::string& label,
const unsigned int bin);
146 double GetIonSignal(
const std::string& label,
const unsigned int bin);
149 const unsigned int bin);
159 const std::vector<double>& values);
171 m_cacheTransferFunction = on;
175 bool ConvoluteSignal(
const std::string& label,
const bool fft =
false);
194 void AddNoise(
const bool total =
true,
const bool electron =
false,
195 const bool ion =
false);
204 void AddWhiteNoise(
const std::string& label,
const double enc,
205 const bool poisson =
true,
const double q0 = 1.);
207 void AddWhiteNoise(
const double enc,
const bool poisson =
true,
208 const double q0 = 1.);
220 return m_thresholdCrossings.size();
233 void AddSignal(
const double q,
const double t0,
const double t1,
234 const double x0,
const double y0,
const double z0,
235 const double x1,
const double y1,
const double z1,
236 const bool integrateWeightingField,
237 const bool useWeightingPotential =
false);
240 void AddSignal(
const double q,
const std::vector<double>& ts,
241 const std::vector<std::array<double, 3> >& xs,
242 const std::vector<std::array<double, 3> >& vs,
243 const std::vector<double>& ns,
const int navg,
244 const bool useWeightingPotential =
false);
247 void PlotSignal(
const std::string& label, TPad* pad);
249 void ExportSignal(
const std::string& label,
const std::string& filename,
250 const bool chargeCariers =
false)
const;
254 const double z0,
const double x1,
const double y1,
259 bool CrossedWire(
const double x0,
const double y0,
const double z0,
260 const double x1,
const double y1,
const double z1,
261 double& xc,
double& yc,
double& zc,
const bool centre,
264 bool InTrapRadius(
const double q0,
const double x0,
const double y0,
265 const double z0,
double& xw,
double& yw,
double& rw);
268 bool CrossedPlane(
const double x0,
const double y0,
const double z0,
269 const double x1,
const double y1,
const double z1,
270 double& xc,
double& yc,
double& zc);
275 const double x1,
const double y1,
const double z1,
276 const double xp,
const double yp,
const double zp,
277 const unsigned int nI,
const int isign = 0);
284 std::string m_className =
"Sensor";
289 std::vector<std::tuple<Component*, bool, bool> > m_components;
294 std::vector<double> signal;
295 std::vector<double> delayedSignal;
296 std::vector<double> electronSignal;
297 std::vector<double> ionSignal;
298 std::vector<double> delayedElectronSignal;
299 std::vector<double> delayedIonSignal;
304 std::vector<Electrode> m_electrodes;
307 double m_tStart = 0.;
308 double m_tStep = 10.;
309 unsigned int m_nTimeBins = 200;
310 unsigned int m_nEvents = 0;
311 bool m_delayedSignal =
false;
312 std::vector<double> m_delayedSignalTimes;
313 unsigned int m_nAvgDelayedSignal = 0;
316 std::function<double(
double)> m_fTransfer;
317 Shaper* m_shaper =
nullptr;
318 std::vector<std::pair<double, double> > m_fTransferTab;
319 bool m_cacheTransferFunction =
true;
321 double m_fTransferSq = -1.;
323 std::vector<double> m_fTransferFFT;
326 double (*m_fNoise)(
double t) =
nullptr;
328 std::vector<std::pair<double, bool> > m_thresholdCrossings;
329 double m_thresholdLevel = 0.;
332 double m_xMinUser = 0., m_yMinUser = 0., m_zMinUser = 0.;
333 double m_xMaxUser = 0., m_yMaxUser = 0., m_zMaxUser = 0.;
334 bool m_hasUserArea =
false;
337 bool m_debug =
false;
340 bool GetBoundingBox(
double& xmin,
double& ymin,
double& zmin,
double& xmax,
341 double& ymax,
double& zmax);
343 void FillSignal(Electrode& electrode,
const double q,
344 const std::vector<double>& ts,
const std::vector<double>& is,
345 const int navg,
const bool delayed =
false);
346 void FillBin(Electrode& electrode,
const unsigned int bin,
347 const double signal,
const bool electron,
const bool delayed) {
348 std::lock_guard<std::mutex> guard(m_mutex);
349 electrode.signal[bin] += signal;
350 if (delayed) electrode.delayedSignal[bin] += signal;
352 electrode.electronSignal[bin] += signal;
353 if (delayed) electrode.delayedElectronSignal[bin] += signal;
355 electrode.ionSignal[bin] += signal;
356 if (delayed) electrode.delayedIonSignal[bin] += signal;
361 void ConvoluteSignal(Electrode& electrode,
const std::vector<double>& tab);
362 bool ConvoluteSignalFFT();
363 bool ConvoluteSignalFFT(
const std::string& label);
364 void ConvoluteSignalFFT(Electrode& electrode,
const std::vector<double>& tab,
365 const unsigned int nn);
367 double TransferFunctionSq();
368 double InterpolateTransferFunctionTable(
const double t)
const;
369 void MakeTransferFunctionTable(std::vector<double>& tab);
370 void FFT(std::vector<double>& data,
const bool inverse,
const int nn);
Abstract base class for components.
Abstract base class for media.
void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status)
Get the magnetic field at (x, y, z).
void EnableMagneticField(const unsigned int i, const bool on)
Activate/deactivate use of the magnetic field of a given component.
double GetElectronSignal(const std::string &label, const unsigned int bin)
Retrieve the electron signal for a given electrode and time bin.
bool ConvoluteSignal(const std::string &label, const bool fft=false)
Medium * GetMedium(const double x, const double y, const double z)
Get the medium at (x, y, z).
bool GetVoltageRange(double &vmin, double &vmax)
Return the voltage range.
double GetTotalInducedCharge(const std::string &label)
void SetDelayedSignalTimes(const std::vector< double > &ts)
Set the points in time at which to evaluate the delayed weighting field.
void SetTimeWindow(const double tstart, const double tstep, const unsigned int nsteps)
void SetSignal(const std::string &label, const unsigned int bin, const double signal)
Set/override the signal in a given time bin explicitly.
void EnableDelayedSignal(const bool on=true)
Compute the component of the signal due to the delayed weighting field.
double GetDelayedIonSignal(const std::string &label, const unsigned int bin)
Retrieve the delayed ion/hole signal for a given electrode and time bin.
void PlotSignal(const std::string &label, TPad *pad)
Plot the induced signal.
bool DelayAndSubtractFraction(const double td, const double f)
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label)
Get the weighting field at (x, y, z).
double GetTransferFunction(const double t)
Evaluate the transfer function at a given time.
void EnableComponent(const unsigned int i, const bool on)
Activate/deactivate a given component.
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)
void GetTimeWindow(double &tstart, double &tstep, unsigned int &nsteps) const
Retrieve the time window and binning.
void AddElectrode(Component *comp, const std::string &label)
Add an electrode.
bool IntegrateSignal(const std::string &label)
Replace the signal on a given electrode by its integral.
void AddComponent(Component *comp)
Add a component.
void SetTransferFunction(std::function< double(double)>)
Set the function to be used for evaluating the transfer function.
void PrintTransferFunction()
Print some information about the presently set transfer function.
double DelayedWeightingPotential(const double x, const double y, const double z, const double t, const std::string &label)
Get the delayed weighting potential at (x, y, z).
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&medium, int &status)
Get the drift field and potential at (x, y, z).
double GetSignal(const std::string &label, const unsigned int bin)
Retrieve the total signal for a given electrode and time bin.
size_t GetNumberOfComponents() const
Get the number of components attached to the sensor.
void SetNoiseFunction(double(*f)(double t))
Set the function to be used for evaluating the noise component.
double GetPromptSignal(const std::string &label, const unsigned int bin)
Retrieve the prompt signal for a given electrode and time bin.
bool IntegrateSignals()
Replace the signals on all electrodes curve by their integrals.
bool HasMagneticField() const
Does the sensor have a non-zero magnetic field?
bool ConvoluteSignals(const bool fft=false)
Convolute all induced currents with the transfer function.
bool IsInArea(const double x, const double y, const double z)
Check if a point is inside the user area.
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)
double GetInducedCharge(const std::string &label)
Calculated using the weighting potentials at the start and end points.
void AddNoise(const bool total=true, const bool electron=false, const bool ion=false)
Add noise to the induced signal.
size_t GetNumberOfElectrodes() const
Get the number of electrodes attached to the sensor.
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)
double WeightingPotential(const double x, const double y, const double z, const std::string &label)
Get the weighting potential at (x, y, z).
Component * GetComponent(const unsigned int i)
Retrieve the pointer to a given component.
void AddWhiteNoise(const std::string &label, const double enc, const bool poisson=true, const double q0=1.)
bool ComputeThresholdCrossings(const double thr, const std::string &label, int &n)
void Clear()
Remove all components, electrodes and reset the sensor.
bool SetArea(const bool verbose=false)
Set the user area to the default.
void AddSignal(const double q, const double t0, const double t1, const double x0, const double y0, const double z0, const double x1, const double y1, const double z1, const bool integrateWeightingField, const bool useWeightingPotential=false)
Add the signal from a charge-carrier step.
bool GetThresholdCrossing(const unsigned int i, double &time, double &level, bool &rise) const
size_t GetNumberOfThresholdCrossings() const
bool IsInside(const double x, const double y, const double z)
Check if a point is inside an active medium and inside the user area.
Sensor()=default
Constructor.
double GetDelayedElectronSignal(const std::string &label, const unsigned int bin)
Retrieve the delayed electron signal for a given electrode and time bin.
void EnableTransferFunctionCache(const bool on=true)
void ClearSignal()
Reset signals and induced charges of all electrodes.
double GetDelayedSignal(const std::string &label, const unsigned int bin)
Retrieve the delayed signal for a given electrode and time bin.
void ExportSignal(const std::string &label, const std::string &filename, const bool chargeCariers=false) const
Exporting induced signal to a csv file.
void AddInducedCharge(const double q, const double x0, const double y0, const double z0, const double x1, const double y1, const double z1)
Add the induced charge from a charge carrier drift between two points.
void PlotTransferFunction()
Plot the presently set transfer function.
bool InTrapRadius(const double q0, const double x0, const double y0, const double z0, double &xw, double &yw, double &rw)
Determine whether a point is in the trap radius of a wire.
double GetIonSignal(const std::string &label, const unsigned int bin)
Retrieve the ion or hole signal for a given electrode and time bin.
void EnableDebugging(const bool on=true)
Switch debugging messages on/off.
void SetDelayedSignalAveragingOrder(const unsigned int navg)
void NewSignal()
Start a new event, when computing the average signal over multiple events.
bool GetArea(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
Return the current user area.
bool IsIntegrated(const std::string &label) const
Return whether the signal has been integrated/convoluted.
Class for signal processing.