Garfield++ v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Garfield::ViewFEMesh Class Reference

Draw the mesh of a field-map component. More...

#include <ViewFEMesh.hh>

Public Member Functions

 ViewFEMesh ()
 Constructor.
 
 ~ViewFEMesh ()
 Destructor.
 
TCanvas * GetCanvas ()
 
void SetCanvas (TCanvas *c)
 Set the canvas to be painted on.
 
void SetComponent (ComponentFieldMap *comp)
 Set the component from which to retrieve the mesh and field.
 
void SetArea ()
 Set area to be plotted to the default.
 
void SetArea (const double xmin, const double ymin, const double zmin, const double xmax, const double ymax, const double zmax)
 Set area to be plotted explicitly.
 
void SetDefaultProjection ()
 Reset the projection plane.
 
void SetPlane (double fx, double fy, double fz, double x0, double y0, double z0)
 Set the projection plane.
 
void SetXaxis (TGaxis *ax)
 
void SetYaxis (TGaxis *ay)
 
void SetXaxisTitle (const char *xtitle)
 
void SetYaxisTitle (const char *ytitle)
 
void EnableAxes ()
 
void DisableAxes ()
 
bool Plot ()
 Plot method to be called by user.
 
void SetFillMesh (const bool f)
 Element fill switch; 2D only, set false for wireframe mesh.
 
void SetColor (int matID, int colorID)
 
void SetFillColor (int matID, int colorID)
 
void SetViewDrift (ViewDrift *vd)
 Set the optional associated ViewDrift.
 
void SetFillMeshWithBorders ()
 Show filled mesh elements.
 
void EnableDebugging (const bool on=true)
 Switch on/off debugging output.
 
void CreateDefaultAxes ()
 Create a default set of custom-made axes.
 
void DisableMaterial (int materialID)
 Disable a material so that its mesh cells are not drawn.
 

Detailed Description

Draw the mesh of a field-map component.

Definition at line 26 of file ViewFEMesh.hh.

Constructor & Destructor Documentation

◆ ViewFEMesh()

Garfield::ViewFEMesh::ViewFEMesh ( )

Constructor.

Definition at line 13 of file ViewFEMesh.cc.

14 : m_className("ViewFEMesh"),
15 m_label("Mesh"),
16 m_debug(false),
17 m_fillMesh(false),
18 m_canvas(NULL),
19 m_hasExternalCanvas(false),
20 m_hasUserArea(false),
21 m_xMin(-1.),
22 m_yMin(-1.),
23 m_zMin(-1.),
24 m_xMax(1.),
25 m_yMax(1.),
26 m_zMax(1.),
27 m_component(NULL),
28 m_viewDrift(NULL),
29 m_plotMeshBorders(false),
30 m_xaxis(NULL),
31 m_yaxis(NULL),
32 m_axes(NULL),
33 m_drawAxes(false) {
34
37
38 // Create a blank histogram for the axes.
39 m_axes = new TH2D();
40 m_axes->SetStats(false);
41 m_axes->GetXaxis()->SetTitle("x");
42 m_axes->GetYaxis()->SetTitle("y");
43}
void SetDefaultProjection()
Reset the projection plane.
Definition: ViewFEMesh.cc:185
PlottingEngineRoot plottingEngine

◆ ~ViewFEMesh()

Garfield::ViewFEMesh::~ViewFEMesh ( )

Destructor.

Definition at line 45 of file ViewFEMesh.cc.

45 {
46
47 if (!m_hasExternalCanvas && m_canvas) delete m_canvas;
48}

Member Function Documentation

◆ CreateDefaultAxes()

void Garfield::ViewFEMesh::CreateDefaultAxes ( )

Create a default set of custom-made axes.

Definition at line 222 of file ViewFEMesh.cc.

222 {
223
224 // Create a new x and y axis
225 m_xaxis = new TGaxis(m_xMin + std::abs(m_xMax - m_xMin) * 0.1,
226 m_yMin + std::abs(m_yMax - m_yMin) * 0.1,
227 m_xMax - std::abs(m_xMax - m_xMin) * 0.1,
228 m_yMin + std::abs(m_yMax - m_yMin) * 0.1,
229 m_xMin + std::abs(m_xMax - m_xMin) * 0.1,
230 m_xMax - std::abs(m_xMax - m_xMin) * 0.1, 2405, "x");
231 m_yaxis = new TGaxis(m_xMin + std::abs(m_xMax - m_xMin) * 0.1,
232 m_yMin + std::abs(m_yMax - m_yMin) * 0.1,
233 m_xMin + std::abs(m_xMax - m_xMin) * 0.1,
234 m_yMax - std::abs(m_yMax - m_yMin) * 0.1,
235 m_yMin + std::abs(m_yMax - m_yMin) * 0.1,
236 m_yMax - std::abs(m_yMax - m_yMin) * 0.1, 2405, "y");
237
238 // Label sizes
239 m_xaxis->SetLabelSize(0.025);
240 m_yaxis->SetLabelSize(0.025);
241
242 // Titles
243 m_xaxis->SetTitleSize(0.03);
244 m_xaxis->SetTitle("x [cm]");
245 m_yaxis->SetTitleSize(0.03);
246 m_yaxis->SetTitle("y [cm]");
247}

◆ DisableAxes()

void Garfield::ViewFEMesh::DisableAxes ( )
inline

Definition at line 59 of file ViewFEMesh.hh.

59{ m_drawAxes = false; }

◆ DisableMaterial()

void Garfield::ViewFEMesh::DisableMaterial ( int  materialID)
inline

Disable a material so that its mesh cells are not drawn.

Definition at line 90 of file ViewFEMesh.hh.

90 {
91 m_disabledMaterial[materialID] = true;
92 }

◆ EnableAxes()

void Garfield::ViewFEMesh::EnableAxes ( )
inline

Definition at line 58 of file ViewFEMesh.hh.

58{ m_drawAxes = true; }

◆ EnableDebugging()

void Garfield::ViewFEMesh::EnableDebugging ( const bool  on = true)
inline

Switch on/off debugging output.

Definition at line 84 of file ViewFEMesh.hh.

84{ m_debug = on; }

◆ GetCanvas()

TCanvas * Garfield::ViewFEMesh::GetCanvas ( )

Definition at line 72 of file ViewFEMesh.cc.

72{ return m_canvas; }

◆ Plot()

bool Garfield::ViewFEMesh::Plot ( )

Plot method to be called by user.

Definition at line 97 of file ViewFEMesh.cc.

97 {
98
99 if (!m_component) {
100 std::cerr << m_className << "::Plot:\n";
101 std::cerr << " Component is not defined.\n";
102 return false;
103 }
104
105 double pmin = 0., pmax = 0.;
106 if (!m_component->GetVoltageRange(pmin, pmax)) {
107 std::cerr << m_className << "::Plot:\n";
108 std::cerr << " Component is not ready.\n";
109 return false;
110 }
111
112 // Get the bounding box.
113 if (!m_hasUserArea) {
114 std::cerr << m_className << "::Plot:\n";
115 std::cerr << " Bounding box cannot be determined.\n";
116 std::cerr << " Call SetArea first.\n";
117 return false;
118 }
119
120 // Set up a canvas if one does not already exist.
121 if (!m_canvas) {
122 m_canvas = new TCanvas();
123 m_canvas->SetTitle(m_label.c_str());
124 if (m_hasExternalCanvas) m_hasExternalCanvas = false;
125 }
126 m_canvas->Range(m_xMin, m_yMin, m_xMax, m_yMax);
127
128 // Plot the elements
129 ComponentCST* componentCST = dynamic_cast<ComponentCST*>(m_component);
130 if (componentCST) {
131 std::cout << m_className << "::Plot:\n";
132 std::cout << " The given component is a CST component.\n";
133 std::cout << " Method PlotCST is called now!.\n";
134 DrawCST(componentCST);
135 } else {
136 DrawElements();
137 }
138 m_canvas->Update();
139
140 return true;
141}
virtual bool GetVoltageRange(double &vmin, double &vmax)
Calculate the voltage range [V].

◆ SetArea() [1/2]

void Garfield::ViewFEMesh::SetArea ( )

Set area to be plotted to the default.

Definition at line 93 of file ViewFEMesh.cc.

93{ m_hasUserArea = false; }

◆ SetArea() [2/2]

void Garfield::ViewFEMesh::SetArea ( const double  xmin,
const double  ymin,
const double  zmin,
const double  xmax,
const double  ymax,
const double  zmax 
)

Set area to be plotted explicitly.

Definition at line 74 of file ViewFEMesh.cc.

75 {
76
77 // Check range, assign if non-null
78 if (xmin == xmax || ymin == ymax) {
79 std::cout << m_className << "::SetArea:\n";
80 std::cout << " Null area range not permitted.\n";
81 return;
82 }
83 m_xMin = std::min(xmin, xmax);
84 m_yMin = std::min(ymin, ymax);
85 m_zMin = std::min(zmin, zmax);
86 m_xMax = std::max(xmin, xmax);
87 m_yMax = std::max(ymin, ymax);
88 m_zMax = std::max(zmin, zmax);
89
90 m_hasUserArea = true;
91}

◆ SetCanvas()

void Garfield::ViewFEMesh::SetCanvas ( TCanvas *  c)

Set the canvas to be painted on.

Definition at line 61 of file ViewFEMesh.cc.

61 {
62
63 if (!c) return;
64 if (!m_hasExternalCanvas && m_canvas) {
65 delete m_canvas;
66 m_canvas = NULL;
67 }
68 m_canvas = c;
69 m_hasExternalCanvas = true;
70}

◆ SetColor()

void Garfield::ViewFEMesh::SetColor ( int  matID,
int  colorID 
)
inline

Associate a color with each element material map ID; Uses ROOT color numberings

Definition at line 69 of file ViewFEMesh.hh.

69{ m_colorMap[matID] = colorID; }

◆ SetComponent()

void Garfield::ViewFEMesh::SetComponent ( ComponentFieldMap comp)

Set the component from which to retrieve the mesh and field.

Definition at line 50 of file ViewFEMesh.cc.

50 {
51
52 if (!comp) {
53 std::cerr << m_className << "::SetComponent:\n";
54 std::cerr << " Component pointer is null.\n";
55 return;
56 }
57
58 m_component = comp;
59}

◆ SetDefaultProjection()

void Garfield::ViewFEMesh::SetDefaultProjection ( )

Reset the projection plane.

Definition at line 185 of file ViewFEMesh.cc.

185 {
186
187 // Default projection: x-y at z=0
188 project[0][0] = 1;
189 project[1][0] = 0;
190 project[2][0] = 0;
191 project[0][1] = 0;
192 project[1][1] = 1;
193 project[2][1] = 0;
194 project[0][2] = 0;
195 project[1][2] = 0;
196 project[2][2] = 0;
197
198 // Plane description
199 plane[0] = 0;
200 plane[1] = 0;
201 plane[2] = 1;
202 plane[3] = 0;
203}

Referenced by ViewFEMesh().

◆ SetFillColor()

void Garfield::ViewFEMesh::SetFillColor ( int  matID,
int  colorID 
)
inline

Definition at line 70 of file ViewFEMesh.hh.

70 {
71 m_colorMap_fill[matID] = colorID;
72 }

◆ SetFillMesh()

void Garfield::ViewFEMesh::SetFillMesh ( const bool  f)
inline

Element fill switch; 2D only, set false for wireframe mesh.

Definition at line 65 of file ViewFEMesh.hh.

65{ m_fillMesh = f; }

◆ SetFillMeshWithBorders()

void Garfield::ViewFEMesh::SetFillMeshWithBorders ( )
inline

Show filled mesh elements.

Definition at line 78 of file ViewFEMesh.hh.

78 {
79 m_plotMeshBorders = true;
80 m_fillMesh = true;
81 }

◆ SetPlane()

void Garfield::ViewFEMesh::SetPlane ( double  fx,
double  fy,
double  fz,
double  x0,
double  y0,
double  z0 
)

Set the projection plane.

Definition at line 145 of file ViewFEMesh.cc.

146 {
147
148 // Calculate 2 in-plane vectors for the normal vector
149 double fnorm = sqrt(fx * fx + fy * fy + fz * fz);
150 double dist = fx * x0 + fy * y0 + fz * z0;
151 if (fnorm > 0 && fx * fx + fz * fz > 0) {
152 project[0][0] = fz / sqrt(fx * fx + fz * fz);
153 project[0][1] = 0;
154 project[0][2] = -fx / sqrt(fx * fx + fz * fz);
155 project[1][0] = -fx * fy / (sqrt(fx * fx + fz * fz) * fnorm);
156 project[1][1] = (fx * fx + fz * fz) / (sqrt(fx * fx + fz * fz) * fnorm);
157 project[1][2] = -fy * fz / (sqrt(fx * fx + fz * fz) * fnorm);
158 project[2][0] = dist * fx / (fnorm * fnorm);
159 project[2][1] = dist * fy / (fnorm * fnorm);
160 project[2][2] = dist * fz / (fnorm * fnorm);
161 } else if (fnorm > 0 && fy * fy + fz * fz > 0) {
162 project[0][0] = (fy * fy + fz * fz) / (sqrt(fy * fy + fz * fz) * fnorm);
163 project[0][1] = -fx * fz / (sqrt(fy * fy + fz * fz) * fnorm);
164 project[0][2] = -fy * fz / (sqrt(fy * fy + fz * fz) * fnorm);
165 project[1][0] = 0;
166 project[1][1] = fz / sqrt(fy * fy + fz * fz);
167 project[1][2] = -fy / sqrt(fy * fy + fz * fz);
168 project[2][0] = dist * fx / (fnorm * fnorm);
169 project[2][1] = dist * fy / (fnorm * fnorm);
170 project[2][2] = dist * fz / (fnorm * fnorm);
171 } else {
172 std::cout << m_className << "::SetPlane:\n";
173 std::cout << " Normal vector has zero norm.\n";
174 std::cout << " No new projection set.\n";
175 }
176
177 // Store the plane description
178 plane[0] = fx;
179 plane[1] = fy;
180 plane[2] = fz;
181 plane[3] = dist;
182}
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:314

◆ SetViewDrift()

void Garfield::ViewFEMesh::SetViewDrift ( ViewDrift vd)
inline

Set the optional associated ViewDrift.

Definition at line 75 of file ViewFEMesh.hh.

75{ m_viewDrift = vd; }

◆ SetXaxis()

void Garfield::ViewFEMesh::SetXaxis ( TGaxis *  ax)

Definition at line 206 of file ViewFEMesh.cc.

206{ m_xaxis = ax; }

◆ SetXaxisTitle()

void Garfield::ViewFEMesh::SetXaxisTitle ( const char *  xtitle)

Definition at line 212 of file ViewFEMesh.cc.

212 {
213 m_axes->GetXaxis()->SetTitle(xtitle);
214}

◆ SetYaxis()

void Garfield::ViewFEMesh::SetYaxis ( TGaxis *  ay)

Definition at line 209 of file ViewFEMesh.cc.

209{ m_yaxis = ay; }

◆ SetYaxisTitle()

void Garfield::ViewFEMesh::SetYaxisTitle ( const char *  ytitle)

Definition at line 217 of file ViewFEMesh.cc.

217 {
218 m_axes->GetYaxis()->SetTitle(ytitle);
219}

The documentation for this class was generated from the following files: