Garfield++ 5.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
diode.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include <cmath>
4
5#include <TCanvas.h>
6#include <TROOT.h>
7#include <TApplication.h>
8#include <TSystem.h>
9
12#include "Garfield/Sensor.hh"
13#include "Garfield/TrackHeed.hh"
15#include "Garfield/ViewDrift.hh"
16#include "Garfield/ViewField.hh"
18#include "Garfield/Random.hh"
19
20using namespace Garfield;
21
22int main(int argc, char * argv[]) {
23
24 TApplication app("app", &argc, argv);
25
26 // Create a drift medium.
28 // Set the temperature [K].
29 si.SetTemperature(266.15);
30
31 // Make a component with three-dimensional TCAD field map.
33 // Load the mesh (.grd file) and electric field profile (.dat).
34 cmp.Initialise("diode_msh.grd", "diode_des.dat");
35 // Associate all regions in the field map with silicon.
36 auto nRegions = cmp.GetNumberOfRegions();
37 for (size_t i = 0; i < nRegions; ++i) {
38 cmp.SetMedium(i, &si);
39 }
40
41 // Make a sensor.
42 Sensor sensor;
43 sensor.AddComponent(&cmp);
44 sensor.SetArea();
45
46 // Plot the electrostatic potential.
47 ViewField fieldView;
48 fieldView.SetSensor(&sensor);
49 fieldView.SetPlaneXZ();
50 fieldView.PlotContour();
51
52 // Use MC transport for drifting the electrons and holes.
53 AvalancheMC drift(&sensor);
54 drift.SetDistanceSteps(1.e-4);
55
56 // Visualize the drift lines.
57 ViewDrift driftView;
58 drift.EnablePlotting(&driftView);
59
60 TrackHeed track(&sensor);
61 track.SetParticle("pi");
62 track.SetMomentum(3.e9);
63
64 // Sample the inclination and starting point of the track.
65 const double theta = (RndmUniform() - 0.5) * 20. * DegreeToRad;
66 const double x0 = (RndmUniform() - 0.5) * 40.e-4;
67 const double y0 = (RndmUniform() - 0.5) * 40.e-4;
68 track.NewTrack(x0, y0, 0., 0., sin(theta), 0., cos(theta));
69 // Retrieve the clusters along the track.
70 for (const auto& cluster : track.GetClusters()) {
71 // Retrieve the electrons in the cluster.
72 for (const auto& electron : cluster.electrons) {
73 // Simulate and plot only a small fraction of the drift lines.
74 constexpr double fPlot = 0.01;
75 if (RndmUniform() > fPlot) continue;
76 drift.DriftElectron(electron.x, electron.y, electron.z, electron.t);
77 drift.DriftHole(electron.x, electron.y, electron.z, electron.t);
78 }
79 }
80 driftView.SetPlaneXZ();
81 driftView.Plot2d(true);
82 app.Run(true);
83}
void EnablePlotting(ViewDrift *view)
Switch on drift line plotting.
bool DriftHole(const double x, const double y, const double z, const double t)
Simulate the drift line of a hole from a given starting point.
bool DriftElectron(const double x, const double y, const double z, const double t)
Simulate the drift line of an electron from a given starting point.
void SetDistanceSteps(const double d=0.001)
Use fixed distance steps (default 10 um).
Interpolation in a three-dimensional field map created by Sentaurus Device.
size_t GetNumberOfRegions() const
Get the number of regions in the device.
bool Initialise(const std::string &gridfilename, const std::string &datafilename)
void SetMedium(const size_t ireg, Medium *m)
Set the medium to be associated to a given region.
Solid crystalline silicon
void SetTemperature(const double t)
Set the temperature [K].
Definition Medium.cc:72
void AddComponent(Component *comp)
Add a component.
Definition Sensor.cc:355
bool SetArea(const bool verbose=false)
Set the user area to the default.
Definition Sensor.cc:187
Generate tracks using Heed++.
Definition TrackHeed.hh:35
bool NewTrack(const double x0, const double y0, const double z0, const double t0, const double dx0, const double dy0, const double dz0) override
Definition TrackHeed.cc:87
const std::vector< Cluster > & GetClusters() const
Definition TrackHeed.hh:80
void SetMomentum(const double p)
Set the particle momentum.
Definition Track.cc:143
virtual void SetParticle(const std::string &part)
Definition Track.cc:18
void SetPlaneXZ()
Set the viewing plane to x-z.
Definition ViewBase.cc:293
Visualize drift lines and tracks.
Definition ViewDrift.hh:19
void Plot2d(const bool axis=true, const bool snapshot=false)
Make a 2D plot of the drift lines in the current viewing plane.
Definition ViewDrift.cc:170
Visualize the potential or electric field of a component or sensor.
Definition ViewField.hh:15
void PlotContour(const std::string &option="v")
Definition ViewField.cc:129
void SetSensor(Sensor *s)
Set the sensor for which to plot the field.
Definition ViewField.cc:73
int main(int argc, char *argv[])
Definition diode.cpp:22
double RndmUniform()
Draw a random number uniformly distributed in the range [0, 1).
Definition Random.hh:14