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 File Reference
#include <iostream>
#include <fstream>
#include <cmath>
#include <TCanvas.h>
#include <TROOT.h>
#include <TApplication.h>
#include <TSystem.h>
#include "Garfield/MediumSilicon.hh"
#include "Garfield/ComponentTcad3d.hh"
#include "Garfield/Sensor.hh"
#include "Garfield/TrackHeed.hh"
#include "Garfield/AvalancheMC.hh"
#include "Garfield/ViewDrift.hh"
#include "Garfield/ViewField.hh"
#include "Garfield/FundamentalConstants.hh"
#include "Garfield/Random.hh"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 22 of file diode.cpp.

22 {
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}
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
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
double RndmUniform()
Draw a random number uniformly distributed in the range [0, 1).
Definition Random.hh:14
DoubleAc cos(const DoubleAc &f)
Definition DoubleAc.cpp:432
DoubleAc sin(const DoubleAc &f)
Definition DoubleAc.cpp:384