Garfield++ 5.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);
70 drift.EnableAttachmentMap();
71
72 double x0 = pitch * 1.5, y0 = 5.e-5, z0 = 0., t0 = 0.;
73 double dx = 0., dy = 1., dz = 0.;
74 track.NewTrack(x0, y0, z0, t0, dx, dy, dz);
75 // Retrieve the clusters along the track.
76 for (const auto& cluster : track.GetClusters()) {
77 // Loop over the electrons in the cluster.
78 for (const auto& electron : cluster.electrons) {
79 // Simulate the electron and hole drift lines.
80 drift.DriftElectron(electron.x, electron.y, electron.z, electron.t);
81 drift.DriftHole(electron.x, electron.y, electron.z, electron.t);
82 }
83 }
84 constexpr bool plotSignal = true;
85 ViewSignal signalView;
86 signalView.SetSensor(&sensor);
87 signalView.PlotSignal("pixel", "t");
88
89 std::ofstream outfile;
90 outfile.open("signal.txt", std::ios::out);
91 for (unsigned int i = 0; i < nTimeBins; ++i) {
92 const double t = (i + 0.5) * tstep;
93 const double f = sensor.GetSignal(label, i);
94 const double fe = sensor.GetElectronSignal(label, i);
95 const double fh = sensor.GetIonSignal(label, i);
96 outfile << t << " " << f << " " << fe << " " << fh << "\n";
97 }
98 outfile.close();
99 if (plotSignal) app.Run();
100}
int main(int argc, char *argv[])
void SetSensor(Sensor *s)
Set the sensor.
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.
void EnableAttachmentMap(const bool on=true)
Retrieve the attachment coefficient from the component.
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).
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:72
double GetElectronSignal(const std::string &label, const unsigned int bin)
Retrieve the electron signal for a given electrode and time bin.
Definition Sensor.cc:906
void SetTimeWindow(const double tstart, const double tstep, const unsigned int nsteps)
Definition Sensor.cc:869
void AddElectrode(Component *comp, const std::string &label)
Add an electrode.
Definition Sensor.cc:396
void AddComponent(Component *comp)
Add a component.
Definition Sensor.cc:355
double GetSignal(const std::string &label, const unsigned int bin)
Retrieve the total signal for a given electrode and time bin.
Definition Sensor.cc:976
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:917
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 SetSensor(Sensor *s)
Set the sensor through which to transport the particle.
Definition Track.cc:169
void SetMomentum(const double p)
Set the particle momentum.
Definition Track.cc:143
virtual void SetParticle(const std::string &part)
Definition Track.cc:18
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:18
void PlotSignal(const std::string &label, const std::string &optTotal="t", const std::string &optPrompt="", const std::string &optDelayed="", const bool same=false)
Definition ViewSignal.cc:61