Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
avalanche.cc
Go to the documentation of this file.
1/**
2 * avalanche.cc
3 * General program flow based on example code from the Garfield++ website.
4 *
5 * Demonstrates electron avalanche and induced signal readout with
6 * 2D finite-element visualization in Garfield++ with a LEM.
7 * LEM parameters are from:
8 * C. Shalem et. al. Nucl. Instr. Meth. A, 558, 475 (2006).
9 *
10*/
11#include <iostream>
12#include <cmath>
13
14#include <TCanvas.h>
15#include <TApplication.h>
16#include <TFile.h>
17
20#include "Garfield/Sensor.hh"
21#include "Garfield/ViewField.hh"
22#include "Garfield/Plotting.hh"
26#include "Garfield/Random.hh"
28
29using namespace Garfield;
30
31int main(int argc, char* argv[]) {
32
33 TApplication app("app", &argc, argv);
34
35 // Set relevant LEM parameters.
36 // LEM thickness in cm
37 const double lem_th = 0.04;
38 // Copper thickness
39 const double lem_cpth = 0.0035;
40 // LEM pitch in cm
41 const double lem_pitch = 0.07;
42 // X-width of drift simulation will cover between +/- axis_x
43 const double axis_x = 0.1;
44 // Y-width of drift simulation will cover between +/- axis_y
45 const double axis_y = 0.1;
46 const double axis_z = 0.25 + lem_th / 2 + lem_cpth;
47
48
49 // Define the medium.
50 MediumMagboltz* gas = new MediumMagboltz();
51 // Set the temperature (K)
52 gas->SetTemperature(293.15);
53 // Set the pressure (Torr)
54 gas->SetPressure(740.);
55 // Allow for drifting in this medium
56 gas->EnableDrift();
57 // Specify the gas mixture (Ar/CO2 70:30)
58 gas->SetComposition("ar", 70., "co2", 30.);
59
60 // Import an Elmer-created field map.
62 "gemcell/mesh.header", "gemcell/mesh.elements", "gemcell/mesh.nodes",
63 "gemcell/dielectrics.dat", "gemcell/gemcell.result", "cm");
64 elm->EnablePeriodicityX();
66 elm->SetMedium(0, gas);
67 // Import the weighting field for the readout electrode.
68 // elm->SetWeightingField("gemcell/gemcell_WTlel.result", "wtlel");
69
70 // Set up a sensor object.
71 Sensor* sensor = new Sensor();
72 sensor->AddComponent(elm);
73 sensor->SetArea(-axis_x, -axis_y, -axis_z, axis_x, axis_y, axis_z);
74 // sensor->AddElectrode(elm, "wtlel");
75 // Set the signal binning.
76 const double tEnd = 500.0;
77 const int nsBins = 500;
78 // sensor->SetTimeWindow(0., tEnd / nsBins, nsBins);
79
80 // Create an avalanche object
82 aval->SetSensor(sensor);
83 aval->SetCollisionSteps(100);
84 // aval->EnableSignalCalculation();
85
86 // Set up the object for drift line visualization.
87 ViewDrift* viewDrift = new ViewDrift();
88 viewDrift->SetArea(-axis_x, -axis_y, -axis_z, axis_x, axis_y, axis_z);
89 aval->EnablePlotting(viewDrift);
90
91 // Set the electron start parameters.
92 // Starting z position for electron drift
93 const double zi = 0.5 * lem_th + lem_cpth + 0.1;
94 double ri = (lem_pitch / 2) * RndmUniform();
95 double thetai = RndmUniform() * TwoPi;
96 double xi = ri * cos(thetai);
97 double yi = ri * sin(thetai);
98 // Calculate the avalanche.
99 aval->AvalancheElectron(xi, yi, zi, 0., 0., 0., 0., 0.);
100 std::cout << "... avalanche complete with "
101 << aval->GetNumberOfElectronEndpoints() << " electron tracks.\n";
102
103 // Extract the calculated signal.
104 double bscale = tEnd / nsBins; // time per bin
105 double sum = 0.; // to keep a running sum of the integrated signal
106
107 // Create ROOT histograms of the signal and a file in which to store them.
108 TFile* f = new TFile("avalanche_signals.root", "RECREATE");
109 TH1F* hS = new TH1F("hh", "hh", nsBins, 0, tEnd); // total signal
110 TH1F* hInt = new TH1F("hInt", "hInt", nsBins, 0, tEnd); // integrated signal
111
112 // Fill the histograms with the signals.
113 // Note that the signals will be in C/(ns*binWidth), and we will divide by e
114 // to give a signal in e/(ns*binWidth).
115 // The total signal is then the integral over all bins multiplied by the bin
116 // width in ns.
117 for (int i = 0; i < nsBins; i++) {
118 double wt = sensor->GetSignal("wtlel", i) / ElementaryCharge;
119 sum += wt;
120 hS->Fill(i * bscale, wt);
121 hInt->Fill(i * bscale, sum);
122 }
123
124 // Write the histograms to the TFile.
125 hS->Write();
126 hInt->Write();
127 f->Close();
128
129 // Plot the signal.
130 const bool plotSignal = false;
131 if (plotSignal) {
132 TCanvas* cSignal = new TCanvas("signal", "Signal");
133 ViewSignal* vSignal = new ViewSignal();
134 vSignal->SetSensor(sensor);
135 vSignal->SetCanvas(cSignal);
136 vSignal->PlotSignal("wtlel");
137 }
138
139 // Plot the geometry, field and drift lines.
140 TCanvas* cGeom = new TCanvas("geom", "Geometry/Avalanche/Fields");
141 cGeom->SetLeftMargin(0.14);
142 const bool plotContours = false;
143 if (plotContours) {
144 ViewField* vf = new ViewField();
145 vf->SetSensor(sensor);
146 vf->SetCanvas(cGeom);
147 vf->SetArea(-axis_x, -axis_y, axis_x, axis_y);
148 vf->SetNumberOfContours(40);
149 vf->SetNumberOfSamples2d(30, 30);
150 vf->SetPlane(0, -1, 0, 0, 0, 0);
151 vf->PlotContour("v");
152 }
153
154 // Set up the object for FE mesh visualization.
155 ViewFEMesh* vFE = new ViewFEMesh();
156 vFE->SetArea(-axis_x, -axis_z, -axis_y, axis_x, axis_z, axis_y);
157 vFE->SetCanvas(cGeom);
158 vFE->SetComponent(elm);
159 vFE->SetPlane(0, -1, 0, 0, 0, 0);
160 vFE->SetFillMesh(true);
161 vFE->SetColor(1, kGray);
162 vFE->SetColor(2, kYellow + 3);
163 vFE->SetColor(3, kYellow + 3);
164 if (!plotContours) {
165 vFE->EnableAxes();
166 vFE->SetXaxisTitle("x (cm)");
167 vFE->SetYaxisTitle("z (cm)");
168 vFE->SetViewDrift(viewDrift);
169 vFE->Plot();
170 }
171
172 app.Run(kTRUE);
173
174 return 0;
175}
int main(int argc, char *argv[])
Definition: avalanche.cc:31
Calculate electron drift lines and avalanches using microscopic tracking.
void EnablePlotting(ViewDrift *view)
Switch on drift line plotting.
void SetCollisionSteps(const unsigned int n)
Set number of collisions to be skipped for plotting.
void SetSensor(Sensor *sensor)
Set the sensor.
bool AvalancheElectron(const double x0, const double y0, const double z0, const double t0, const double e0, const double dx0=0., const double dy0=0., const double dz0=0.)
Calculate an avalanche initiated by a given electron.
unsigned int GetNumberOfElectronEndpoints() const
void EnablePeriodicityX(const bool on=true)
Enable simple periodicity in the direction.
void EnableMirrorPeriodicityY(const bool on=true)
Enable mirror periodicity in the direction.
Component for importing field maps computed by Elmer.
void SetMedium(const unsigned int imat, Medium *medium)
Associate a field map material with a Medium class.
bool SetComposition(const std::string &gas1, const double f1=1., const std::string &gas2="", const double f2=0., const std::string &gas3="", const double f3=0., const std::string &gas4="", const double f4=0., const std::string &gas5="", const double f5=0., const std::string &gas6="", const double f6=0.)
Set the gas mixture.
Definition: MediumGas.cc:134
void SetTemperature(const double t)
Set the temperature [K].
Definition: Medium.cc:71
virtual void EnableDrift(const bool on=true)
Switch electron/ion/hole on/off.
Definition: Medium.hh:67
void SetPressure(const double p)
Definition: Medium.cc:81
bool SetArea()
Set the user area to the default.
Definition: Sensor.cc:189
double GetSignal(const std::string &label, const unsigned int bin)
Retrieve the total signal for a given electrode and time bin.
Definition: Sensor.cc:788
void AddComponent(ComponentBase *comp)
Add a component.
Definition: Sensor.cc:301
void SetCanvas(TCanvas *c)
Set the canvas to be painted on.
Definition: ViewBase.cc:20
Visualize drift lines and tracks.
Definition: ViewDrift.hh:19
void SetArea(const double xmin, const double ymin, const double zmin, const double xmax, const double ymax, const double zmax)
Set the region to be plotted.
Definition: ViewDrift.cc:26
Draw the mesh of a field-map component.
Definition: ViewFEMesh.hh:26
void SetXaxisTitle(const char *xtitle)
Definition: ViewFEMesh.cc:184
void SetComponent(ComponentFieldMap *comp)
Set the component from which to retrieve the mesh and field.
Definition: ViewFEMesh.cc:40
void SetViewDrift(ViewDrift *vd)
Set the optional associated ViewDrift.
Definition: ViewFEMesh.hh:76
void SetYaxisTitle(const char *ytitle)
Definition: ViewFEMesh.cc:189
bool Plot()
Plot method to be called by user.
Definition: ViewFEMesh.cc:71
void SetPlane(double fx, double fy, double fz, double x0, double y0, double z0)
Set the projection plane.
Definition: ViewFEMesh.cc:120
void SetArea()
Set area to be plotted to the default.
Definition: ViewFEMesh.cc:67
void SetColor(int matID, int colorID)
Definition: ViewFEMesh.hh:70
void SetFillMesh(const bool f)
Element fill switch; 2D only, set false for wireframe mesh.
Definition: ViewFEMesh.hh:62
Visualize the potential or electric field of a component or sensor.
Definition: ViewField.hh:16
void SetPlane(const double fx, const double fy, const double fz, const double x0, const double y0, const double z0)
Definition: ViewField.cc:612
void SetNumberOfSamples2d(const unsigned int nx, const unsigned int ny)
Set the number of points used for drawing 2D functions.
Definition: ViewField.cc:134
void PlotContour(const std::string &option="v")
Definition: ViewField.cc:155
void SetNumberOfContours(const unsigned int n)
Set the number of contour levels (at most 50).
Definition: ViewField.cc:112
void SetArea(const double xmin, const double ymin, const double xmax, const double ymax)
Set the viewing area (in local coordinates of the current viewing plane).
Definition: ViewField.cc:78
void SetSensor(Sensor *s)
Set the sensor from which to retrieve the field.
Definition: ViewField.cc:58
Plot the signal computed by a sensor as a ROOT histogram.
Definition: ViewSignal.hh:18
void SetSensor(Sensor *s)
Set the sensor from which to retrieve the signal.
Definition: ViewSignal.cc:14
void PlotSignal(const std::string &label, const bool total=true, const bool electron=false, const bool ion=false, const bool delayed=false)
Definition: ViewSignal.cc:44
double RndmUniform()
Draw a random number uniformly distributed in the range [0, 1).
Definition: Random.hh:14