Garfield++ 3.0
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>

+ Inheritance diagram for Garfield::ViewFEMesh:

Public Member Functions

 ViewFEMesh ()
 Constructor.
 
 ~ViewFEMesh ()=default
 Destructor.
 
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 SetPlane (double fx, double fy, double fz, double x0, double y0, double z0, double hx, double hy, double hz)
 Set the projection plane specifying hint for in-plane x axis.
 
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 SetDrawViewRegion (bool do_draw)
 Display intersection of projection plane with viewing area.
 
bool GetDrawViewRegion (void) const
 
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 CreateDefaultAxes ()
 Create a default set of custom-made axes.
 
void DisableMaterial (int materialID)
 Disable a material so that its mesh cells are not drawn.
 
- Public Member Functions inherited from Garfield::ViewBase
 ViewBase ()=delete
 Default constructor.
 
 ViewBase (const std::string &name)
 Constructor.
 
virtual ~ViewBase ()
 Destructor.
 
void SetCanvas (TCanvas *c)
 Set the canvas to be painted on.
 
TCanvas * GetCanvas ()
 Retrieve the canvas.
 
void EnableDebugging (const bool on=true)
 Switch on/off debugging output.
 

Additional Inherited Members

- Protected Member Functions inherited from Garfield::ViewBase
std::string FindUnusedFunctionName (const std::string &s) const
 
std::string FindUnusedHistogramName (const std::string &s) const
 
- Protected Attributes inherited from Garfield::ViewBase
std::string m_className = "ViewBase"
 
bool m_debug = false
 
TCanvas * m_canvas = nullptr
 
bool m_hasExternalCanvas = false
 
double m_proj [3][3]
 

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 15 of file ViewFEMesh.cc.

15 : ViewBase("ViewFEMesh") {
17
18 // Create a blank histogram for the axes.
19 m_axes.reset(new TH2D());
20 m_axes->SetStats(false);
21 m_axes->GetXaxis()->SetTitle("x");
22 m_axes->GetYaxis()->SetTitle("y");
23}
ViewBase()=delete
Default constructor.
void SetDefaultProjection()
Reset the projection plane.
Definition: ViewFEMesh.cc:25

◆ ~ViewFEMesh()

Garfield::ViewFEMesh::~ViewFEMesh ( )
default

Destructor.

Member Function Documentation

◆ CreateDefaultAxes()

void Garfield::ViewFEMesh::CreateDefaultAxes ( )

Create a default set of custom-made axes.

Definition at line 194 of file ViewFEMesh.cc.

194 {
195 // Create a new x and y axis.
196 const double dx = std::abs(m_xPlaneMax - m_xPlaneMin) * 0.1;
197 const double dy = std::abs(m_yPlaneMax - m_yPlaneMin) * 0.1;
198 const double x0 = m_xPlaneMin + dx;
199 const double y0 = m_yPlaneMin + dy;
200 const double x1 = m_xPlaneMax - dx;
201 const double y1 = m_yPlaneMax - dy;
202 m_xaxis = new TGaxis(x0, y0, x1, y0, x0, x1, 2405, "x");
203 m_yaxis = new TGaxis(x0, y0, x0, y1, y0, y1, 2405, "y");
204
205 // Label sizes
206 m_xaxis->SetLabelSize(0.025);
207 m_yaxis->SetLabelSize(0.025);
208
209 // Titles
210 m_xaxis->SetTitleSize(0.03);
211 std::string name = CreateAxisTitle(m_proj[0]);
212 m_xaxis->SetTitle(name.c_str());
213 m_yaxis->SetTitleSize(0.03);
214 name = CreateAxisTitle(m_proj[1]);
215 m_yaxis->SetTitle(name.c_str());
216}

◆ DisableAxes()

void Garfield::ViewFEMesh::DisableAxes ( )
inline

Definition at line 56 of file ViewFEMesh.hh.

56{ 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 88 of file ViewFEMesh.hh.

88 {
89 m_disabledMaterial[materialID] = true;
90 }

◆ EnableAxes()

void Garfield::ViewFEMesh::EnableAxes ( )
inline

Definition at line 55 of file ViewFEMesh.hh.

55{ m_drawAxes = true; }

Referenced by main().

◆ GetDrawViewRegion()

bool Garfield::ViewFEMesh::GetDrawViewRegion ( void  ) const
inline

Definition at line 66 of file ViewFEMesh.hh.

66{ return m_drawViewRegion; }

◆ Plot()

bool Garfield::ViewFEMesh::Plot ( )

Plot method to be called by user.

Definition at line 71 of file ViewFEMesh.cc.

71 {
72 if (!m_component) {
73 std::cerr << m_className << "::Plot: Component is not defined.\n";
74 return false;
75 }
76
77 double pmin = 0., pmax = 0.;
78 if (!m_component->GetVoltageRange(pmin, pmax)) {
79 std::cerr << m_className << "::Plot: Component is not ready.\n";
80 return false;
81 }
82
83 // Get the bounding box.
84 if (!m_hasUserArea) {
85 std::cerr << m_className << "::Plot:\n"
86 << " Bounding box cannot be determined. Call SetArea first.\n";
87 return false;
88 }
89
90 if (m_viewRegionLines.empty()) {
91 std::cerr << m_className << "::Plot:\n"
92 << " Empty view. Make sure the viewing plane (SetPlane)\n"
93 << " intersects with the bounding box.\n";
94 return false;
95 }
96
97 // Set up a canvas if one does not already exist.
98 if (!m_canvas) {
99 m_canvas = new TCanvas();
100 m_canvas->SetTitle(m_label.c_str());
102 }
103 m_canvas->Range(m_xPlaneMin, m_yPlaneMin, m_xPlaneMax, m_yPlaneMax);
104
105 // Plot the elements
106 ComponentCST* componentCST = dynamic_cast<ComponentCST*>(m_component);
107 if (componentCST) {
108 std::cout << m_className << "::Plot: CST component. Calling DrawCST.\n";
109 DrawCST(componentCST);
110 } else {
111 DrawElements();
112 }
113 m_canvas->Update();
114
115 return true;
116}
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
std::string m_className
Definition: ViewBase.hh:28
bool m_hasExternalCanvas
Definition: ViewBase.hh:35
TCanvas * m_canvas
Definition: ViewBase.hh:34

Referenced by main().

◆ SetArea() [1/2]

void Garfield::ViewFEMesh::SetArea ( )

Set area to be plotted to the default.

Definition at line 67 of file ViewFEMesh.cc.

67{ m_hasUserArea = false; }

Referenced by main().

◆ 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 49 of file ViewFEMesh.cc.

50 {
51 // Check range, assign if non-null
52 if (xmin == xmax || ymin == ymax || zmin == zmax) {
53 std::cerr << m_className << "::SetArea: Null area range not permitted.\n";
54 return;
55 }
56 m_xMin = std::min(xmin, xmax);
57 m_yMin = std::min(ymin, ymax);
58 m_zMin = std::min(zmin, zmax);
59 m_xMax = std::max(xmin, xmax);
60 m_yMax = std::max(ymin, ymax);
61 m_zMax = std::max(zmin, zmax);
62
63 m_hasUserArea = true;
64 IntersectPlaneArea();
65}

◆ 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 70 of file ViewFEMesh.hh.

70{ m_colorMap[matID] = colorID; }

Referenced by main().

◆ SetComponent()

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

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

Definition at line 40 of file ViewFEMesh.cc.

40 {
41 if (!comp) {
42 std::cerr << m_className << "::SetComponent: Null pointer.\n";
43 return;
44 }
45
46 m_component = comp;
47}

Referenced by main().

◆ SetDefaultProjection()

void Garfield::ViewFEMesh::SetDefaultProjection ( )

Reset the projection plane.

Definition at line 25 of file ViewFEMesh.cc.

25 {
26 // Default projection: x-y at z=0
27 m_proj[0][0] = 1;
28 m_proj[0][1] = 0;
29 m_proj[0][2] = 0;
30 m_proj[1][0] = 0;
31 m_proj[1][1] = 1;
32 m_proj[1][2] = 0;
33 m_proj[2][0] = 0;
34 m_proj[2][1] = 0;
35 m_proj[2][2] = 1;
36 // Plane distance to (0,0,0)
37 m_dist = 0;
38}

Referenced by ViewFEMesh().

◆ SetDrawViewRegion()

void Garfield::ViewFEMesh::SetDrawViewRegion ( bool  do_draw)
inline

Display intersection of projection plane with viewing area.

Definition at line 65 of file ViewFEMesh.hh.

65{ m_drawViewRegion = do_draw; }

◆ SetFillColor()

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

Definition at line 71 of file ViewFEMesh.hh.

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

◆ SetFillMesh()

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

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

Definition at line 62 of file ViewFEMesh.hh.

62{ m_fillMesh = f; }

Referenced by main().

◆ SetFillMeshWithBorders()

void Garfield::ViewFEMesh::SetFillMeshWithBorders ( )
inline

Show filled mesh elements.

Definition at line 79 of file ViewFEMesh.hh.

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

◆ SetPlane() [1/2]

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

Set the projection plane.

Definition at line 120 of file ViewFEMesh.cc.

121 {
122 if (fy * fy + fz * fz > 0) {
123 SetPlane(fx, fy, fz, x0, y0, z0, 1, 0, 0);
124 } else {
125 SetPlane(fx, fy, fz, x0, y0, z0, 0, 1, 0);
126 }
127}
void SetPlane(double fx, double fy, double fz, double x0, double y0, double z0)
Set the projection plane.
Definition: ViewFEMesh.cc:120

Referenced by main(), and SetPlane().

◆ SetPlane() [2/2]

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

Set the projection plane specifying hint for in-plane x axis.

Definition at line 130 of file ViewFEMesh.cc.

132 {
133 // Calculate 2 in-plane vectors for the normal vector
134 double fnorm = sqrt(fx * fx + fy * fy + fz * fz);
135 if (fnorm < Small) {
136 std::cout << m_className << "::SetPlane:\n"
137 << " Normal vector has zero norm. No new projection set.\n";
138 return;
139 }
140 double dist = (fx * x0 + fy * y0 + fz * z0) / fnorm;
141 // Store the plane description
142 m_proj[2][0] = fx / fnorm;
143 m_proj[2][1] = fy / fnorm;
144 m_proj[2][2] = fz / fnorm;
145 m_dist = dist;
146
147 double xx = hx, xy = hy, xz = hz;
148 PlaneVector(xx, xy, xz);
149 double vecx_norm = std::sqrt(xx * xx + xy * xy + xz * xz);
150 if (vecx_norm < 1.0e-10) {
151 // Wrong in-plane x hint (close to norm).
152 if (fy * fy + fz * fz > 0) {
153 // Taking global x as in-plane x hint.
154 xx = 1;
155 xy = 0;
156 xz = 0;
157 } else {
158 // Taking global y as in-plane x hint.
159 xx = 0;
160 xy = 1;
161 xz = 0;
162 }
163 PlaneVector(xx, xy, xz);
164 vecx_norm = std::sqrt(xx * xx + xy * xy + xz * xz);
165 }
166 m_proj[0][0] = xx / vecx_norm;
167 m_proj[0][1] = xy / vecx_norm;
168 m_proj[0][2] = xz / vecx_norm;
169 // in-plane y === m_proj[1] = cross product [z,x];
170 m_proj[1][0] = m_proj[2][1] * m_proj[0][2] - m_proj[2][2] * m_proj[0][1];
171 m_proj[1][1] = m_proj[2][2] * m_proj[0][0] - m_proj[2][0] * m_proj[0][2];
172 m_proj[1][2] = m_proj[2][0] * m_proj[0][1] - m_proj[2][1] * m_proj[0][0];
173
174 IntersectPlaneArea();
175}
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 76 of file ViewFEMesh.hh.

76{ m_viewDrift = vd; }

Referenced by main().

◆ SetXaxis()

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

Definition at line 178 of file ViewFEMesh.cc.

178{ m_xaxis = ax; }

◆ SetXaxisTitle()

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

Definition at line 184 of file ViewFEMesh.cc.

184 {
185 if (m_axes) m_axes->GetXaxis()->SetTitle(xtitle);
186}

Referenced by main().

◆ SetYaxis()

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

Definition at line 181 of file ViewFEMesh.cc.

181{ m_yaxis = ay; }

◆ SetYaxisTitle()

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

Definition at line 189 of file ViewFEMesh.cc.

189 {
190 if (m_axes) m_axes->GetYaxis()->SetTitle(ytitle);
191}

Referenced by main().


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