Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Simulation.cpp
Go to the documentation of this file.
1#include <cmath>
2#include <fstream>
3#include <iostream>
4
5#include <TApplication.h>
6#include <TCanvas.h>
7#include <TH1D.h>
8#include <TROOT.h>
9#include <TSystem.h>
10
12#include "Garfield/SolidBox.hh"
15#include "Garfield/Sensor.hh"
16#include "Garfield/TrackHeed.hh"
18#include "Garfield/Plotting.hh"
21#include "Garfield/Random.hh"
22
23using namespace Garfield;
24
25int main(int argc, char* argv[]) {
26 TApplication app("app", &argc, argv);
27
28 constexpr double d = 199.5e-04;
29 constexpr double pitch = 55e-4;
30 // Define the medium.
32 si.SetTemperature(293.);
33
34 ComponentGrid efield;
35 efield.LoadElectricField("Efield.txt", "XY", true, false);
36 efield.EnablePeriodicityX();
37 efield.SetMedium(&si);
38
39 efield.LoadElectronAttachment("Attachment.txt", "XY", 2);
40 efield.LoadHoleAttachment("Attachment.txt", "XY", 3);
41
42 ComponentGrid wfield;
43 wfield.LoadWeightingField("Wfield.txt", "XY", true);
44
45 wfield.Print();
46 Sensor sensor;
47 sensor.AddComponent(&efield);
48 const std::string label = "pixel";
49 sensor.AddElectrode(&wfield, label);
50
51 // Set the time bins.
52 const unsigned int nTimeBins = 1000;
53 const double tmin = 0.;
54 const double tmax = 10.;
55 const double tstep = (tmax - tmin) / nTimeBins;
56 sensor.SetTimeWindow(tmin, tstep, nTimeBins);
57
58 // Set up Heed.
59 TrackHeed track;
60 track.SetSensor(&sensor);
61 // Set the particle type and momentum [eV/c].
62 track.SetParticle("pion");
63 track.SetMomentum(180.e9);
64
65 // Simulate electron/hole drift lines using MC integration.
66 AvalancheMC drift;
67 drift.SetSensor(&sensor);
68 // Use steps of 1 micron.
69 drift.SetDistanceSteps(1.e-4);
71 drift.EnableAttachmentMap();
72
73 double x0 = pitch * 1.5, y0 = 5.e-5, z0 = 0., t0 = 0.;
74 double dx = 0., dy = 1., dz = 0.;
75 track.NewTrack(x0, y0, z0, t0, dx, dy, dz);
76 double xc = 0., yc = 0., zc = 0., tc = 0., ec = 0., extra = 0.;
77 int ne = 0;
78 // Retrieve the clusters along the track.
79 while (track.GetCluster(xc, yc, zc, tc, ne, ec, extra)) {
80 // Loop over the electrons in the cluster.
81 for (int j = 0; j < ne; ++j) {
82 double xe = 0., ye = 0., ze = 0., te = 0., ee = 0.;
83 double dxe = 0., dye = 0., dze = 0.;
84 track.GetElectron(j, xe, ye, ze, te, ee, dxe, dye, dze);
85 // Simulate the electron and hole drift lines.
86 drift.DriftElectron(xe, ye, ze, te);
87 drift.DriftHole(xe, ye, ze, te);
88 }
89 }
90 constexpr bool plotSignal = true;
91 ViewSignal signalView;
92 signalView.SetSensor(&sensor);
93 constexpr bool plotTotalSignal = true;
94 constexpr bool plotElectronSignal = false;
95 constexpr bool plotHoleSignal = false;
96 signalView.PlotSignal("pixel", plotTotalSignal, plotElectronSignal,
97 plotHoleSignal);
98
99 std::ofstream outfile;
100 outfile.open("signal.txt", std::ios::out);
101 for (unsigned int i = 0; i < nTimeBins; ++i) {
102 const double t = (i + 0.5) * tstep;
103 const double f = sensor.GetSignal(label, i);
104 const double fe = sensor.GetElectronSignal(label, i);
105 const double fh = sensor.GetIonSignal(label, i);
106 outfile << t << " " << f << " " << fe << " " << fh << "\n";
107 }
108 outfile.close();
109 if (plotSignal) {
110 app.Run(kTRUE);
111 }
112}
int main(int argc, char *argv[])
Definition: Simulation.cpp:25
void EnableSignalCalculation(const bool on=true)
Switch on calculation of induced currents (default: disabled).
Definition: AvalancheMC.hh:33
bool DriftElectron(const double x0, const double y0, const double z0, const double t0)
Simulate the drift line of an electron from a given starting point.
Definition: AvalancheMC.cc:186
void SetSensor(Sensor *s)
Set the sensor.
Definition: AvalancheMC.cc:29
void EnableAttachmentMap(const bool on=true)
Retrieve the attachment coefficient from the component.
Definition: AvalancheMC.hh:72
void SetDistanceSteps(const double d=0.001)
Use fixed distance steps (default 10 um).
Definition: AvalancheMC.cc:62
bool DriftHole(const double x0, const double y0, const double z0, const double t0)
Simulate the drift line of a hole from a given starting point.
Definition: AvalancheMC.cc:205
Component for interpolating field maps on a regular mesh.
void Print()
Print information about the mesh and the available data.
bool LoadWeightingField(const std::string &filename, const std::string &format, const bool withPotential, const double scaleX=1., const double scaleE=1., const double scaleP=1.)
Import (prompt) weighting field from file.
Solid crystalline silicon
void SetTemperature(const double t)
Set the temperature [K].
Definition: Medium.cc:71
double GetElectronSignal(const std::string &label, const unsigned int bin)
Retrieve the electron signal for a given electrode and time bin.
Definition: Sensor.cc:857
void SetTimeWindow(const double tstart, const double tstep, const unsigned int nsteps)
Definition: Sensor.cc:820
void AddElectrode(Component *comp, const std::string &label)
Add an electrode.
Definition: Sensor.cc:349
void AddComponent(Component *comp)
Add a component.
Definition: Sensor.cc:316
double GetSignal(const std::string &label, const unsigned int bin)
Retrieve the total signal for a given electrode and time bin.
Definition: Sensor.cc:912
double GetIonSignal(const std::string &label, const unsigned int bin)
Retrieve the ion or hole signal for a given electrode and time bin.
Definition: Sensor.cc:868
Generate tracks using Heed++.
Definition: TrackHeed.hh:35
bool GetCluster(double &xcls, double &ycls, double &zcls, double &tcls, int &n, double &e, double &extra) override
Definition: TrackHeed.cc:222
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:59
bool GetElectron(const unsigned int i, double &x, double &y, double &z, double &t, double &e, double &dx, double &dy, double &dz)
Definition: TrackHeed.cc:354
void SetSensor(Sensor *s)
Set the sensor through which to transport the particle.
Definition: Track.cc:166
void SetMomentum(const double p)
Set the particle momentum.
Definition: Track.cc:140
virtual void SetParticle(const std::string &part)
Definition: Track.cc:15
Plot the signal computed by a sensor as a ROOT histogram.
Definition: ViewSignal.hh:19
void SetSensor(Sensor *s)
Set the sensor from which to retrieve the signal.
Definition: ViewSignal.cc:17
void PlotSignal(const std::string &label, const bool total=true, const bool electron=false, const bool ion=false, const bool delayed=false, const bool same=false)
Definition: ViewSignal.cc:45