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

"Native" geometry, using simple shapes. More...

#include <GeometrySimple.hh>

+ Inheritance diagram for Garfield::GeometrySimple:

Public Member Functions

 GeometrySimple ()
 Constructor.
 
virtual ~GeometrySimple ()
 Destructor.
 
MediumGetMedium (const double x, const double y, const double z, const bool tesselated=false) const override
 Retrieve the medium at a given point.
 
size_t GetNumberOfSolids () const override
 Return the number of solids in the geometry.
 
SolidGetSolid (const size_t i) const override
 Get a solid from the list.
 
SolidGetSolid (const size_t i, Medium *&medium) const override
 Get a solid from the list, together with the associated medium.
 
void AddSolid (Solid *s, Medium *m)
 Add a solid to the geometry, together with the medium inside.
 
SolidGetSolid (const double x, const double y, const double z, const bool tesselated=false) const
 Get the solid at a given location (x, y, z).
 
void SetMedium (Medium *medium)
 Set a background medium.
 
void Clear ()
 Reset the geometry.
 
void PrintSolids ()
 Print a summary of the solids present in the geometry.
 
bool IsInside (const double x, const double y, const double z, const bool tesselated=false) const override
 Check if a point is inside the geometry.
 
bool IsInBoundingBox (const double x, const double y, const double z) const
 Determine whether a point is inside the envelope of the geometry.
 
bool GetBoundingBox (double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
 Get the bounding box (envelope of the geometry).
 
void EnableDebugging (const bool on=true)
 Switch on/off debugging and warning messages.
 
- Public Member Functions inherited from Garfield::Geometry
 Geometry ()=delete
 Default constructor.
 
 Geometry (const std::string &name)
 Constructor.
 
virtual ~Geometry ()
 Destructor.
 
virtual MediumGetMedium (const double x, const double y, const double z, const bool tesselated=false) const =0
 Retrieve the medium at a given point.
 
virtual size_t GetNumberOfSolids () const
 Return the number of solids in the geometry.
 
virtual SolidGetSolid (const size_t) const
 Get a solid from the list.
 
virtual SolidGetSolid (const size_t, Medium *&medium) const
 Get a solid from the list, together with the associated medium.
 
virtual bool IsInside (const double x, const double y, const double z, const bool tesselated=false) const =0
 Check if a point is inside the geometry.
 
virtual bool GetBoundingBox (double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)=0
 Get the bounding box (envelope of the geometry).
 

Protected Attributes

std::vector< std::pair< Solid *, Medium * > > m_solids
 List of solids and associated media.
 
Mediumm_medium = nullptr
 Background medium.
 
bool m_hasBoundingBox = false
 
std::array< double, 3 > m_bbMin = {{0., 0., 0.}}
 
std::array< double, 3 > m_bbMax = {{0., 0., 0.}}
 
bool m_debug = false
 Switch on/off debugging messages.
 
- Protected Attributes inherited from Garfield::Geometry
std::string m_className = "Geometry"
 

Detailed Description

"Native" geometry, using simple shapes.

Definition at line 13 of file GeometrySimple.hh.

Constructor & Destructor Documentation

◆ GeometrySimple()

Garfield::GeometrySimple::GeometrySimple ( )

Constructor.

Definition at line 8 of file GeometrySimple.cc.

8: Geometry("GeometrySimple") {}
Geometry()=delete
Default constructor.

◆ ~GeometrySimple()

virtual Garfield::GeometrySimple::~GeometrySimple ( )
inlinevirtual

Destructor.

Definition at line 18 of file GeometrySimple.hh.

18{}

Member Function Documentation

◆ AddSolid()

void Garfield::GeometrySimple::AddSolid ( Solid s,
Medium m 
)

Add a solid to the geometry, together with the medium inside.

Definition at line 10 of file GeometrySimple.cc.

10 {
11 // Make sure the solid and the medium are defined.
12 if (!solid || !medium) {
13 std::cerr << m_className << "::AddSolid: Null pointer.\n";
14 return;
15 }
16
17 // Update the bounding box ranges
18 double xmin, ymin, zmin;
19 double xmax, ymax, zmax;
20 if (!solid->GetBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax)) {
21 std::cerr << m_className << "::AddSolid: Solid has no bounding box.\n";
22 return;
23 }
24
25 if (m_hasBoundingBox) {
26 m_bbMin[0] = std::min(m_bbMin[0], xmin);
27 m_bbMin[1] = std::min(m_bbMin[1], ymin);
28 m_bbMin[2] = std::min(m_bbMin[2], zmin);
29 m_bbMax[0] = std::max(m_bbMax[0], xmax);
30 m_bbMax[1] = std::max(m_bbMax[1], ymax);
31 m_bbMax[2] = std::max(m_bbMax[2], zmax);
32 } else {
33 m_bbMin[0] = xmin;
34 m_bbMin[1] = ymin;
35 m_bbMin[2] = zmin;
36 m_bbMax[0] = xmax;
37 m_bbMax[1] = ymax;
38 m_bbMax[2] = zmax;
39 m_hasBoundingBox = true;
40 }
41
42 // Add the new solid to the list.
43 m_solids.emplace_back(std::make_pair(solid, medium));
44}
std::array< double, 3 > m_bbMin
std::array< double, 3 > m_bbMax
std::vector< std::pair< Solid *, Medium * > > m_solids
List of solids and associated media.
std::string m_className
Definition: Geometry.hh:44

◆ Clear()

void Garfield::GeometrySimple::Clear ( )

Reset the geometry.

Definition at line 82 of file GeometrySimple.cc.

82 {
83 m_solids.clear();
84 m_medium = nullptr;
85}
Medium * m_medium
Background medium.

◆ EnableDebugging()

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

Switch on/off debugging and warning messages.

Definition at line 57 of file GeometrySimple.hh.

57{ m_debug = on; }
bool m_debug
Switch on/off debugging messages.

◆ GetBoundingBox()

bool Garfield::GeometrySimple::GetBoundingBox ( double &  xmin,
double &  ymin,
double &  zmin,
double &  xmax,
double &  ymax,
double &  zmax 
)
inlineoverridevirtual

Get the bounding box (envelope of the geometry).

Implements Garfield::Geometry.

Definition at line 45 of file GeometrySimple.hh.

46 {
47 xmin = m_bbMin[0];
48 ymin = m_bbMin[1];
49 zmin = m_bbMin[2];
50 xmax = m_bbMax[0];
51 ymax = m_bbMax[1];
52 zmax = m_bbMax[2];
53 return true;
54 }

Referenced by Garfield::ViewGeometry::Plot2d(), and Garfield::ViewGeometry::Plot3d().

◆ GetMedium()

Medium * Garfield::GeometrySimple::GetMedium ( const double  x,
const double  y,
const double  z,
const bool  tesselated = false 
) const
overridevirtual

Retrieve the medium at a given point.

Implements Garfield::Geometry.

Definition at line 54 of file GeometrySimple.cc.

56 {
57 for (const auto& solid : m_solids) {
58 if (solid.first->IsInside(x, y, z, tesselated)) {
59 return solid.second;
60 }
61 }
62 return m_medium;
63}

Referenced by Garfield::ViewGeometry::Plot3d().

◆ GetNumberOfSolids()

size_t Garfield::GeometrySimple::GetNumberOfSolids ( ) const
inlineoverridevirtual

Return the number of solids in the geometry.

Reimplemented from Garfield::Geometry.

Definition at line 23 of file GeometrySimple.hh.

23{ return m_solids.size(); }

Referenced by Garfield::ViewGeometry::Plot2d(), and Garfield::ViewGeometry::Plot3d().

◆ GetSolid() [1/3]

Solid * Garfield::GeometrySimple::GetSolid ( const double  x,
const double  y,
const double  z,
const bool  tesselated = false 
) const

Get the solid at a given location (x, y, z).

Definition at line 46 of file GeometrySimple.cc.

47 {
48 for (const auto& solid : m_solids) {
49 if (solid.first->IsInside(x, y, z, tesselated)) return solid.first;
50 }
51 return nullptr;
52}

◆ GetSolid() [2/3]

Solid * Garfield::GeometrySimple::GetSolid ( const size_t  size_t) const
overridevirtual

Get a solid from the list.

Reimplemented from Garfield::Geometry.

Definition at line 65 of file GeometrySimple.cc.

65 {
66 if (i >= m_solids.size()) {
67 std::cerr << m_className << "::GetSolid: Index out of range.\n";
68 return nullptr;
69 }
70 return m_solids[i].first;
71}

Referenced by Garfield::ViewGeometry::Plot2d(), and Garfield::ViewGeometry::Plot3d().

◆ GetSolid() [3/3]

Solid * Garfield::GeometrySimple::GetSolid ( const size_t  size_t,
Medium *&  medium 
) const
overridevirtual

Get a solid from the list, together with the associated medium.

Reimplemented from Garfield::Geometry.

Definition at line 73 of file GeometrySimple.cc.

73 {
74 if (i >= m_solids.size()) {
75 std::cerr << m_className << "::GetSolid: Index out of range.\n";
76 return nullptr;
77 }
78 medium = m_solids[i].second;
79 return m_solids[i].first;
80}

◆ IsInBoundingBox()

bool Garfield::GeometrySimple::IsInBoundingBox ( const double  x,
const double  y,
const double  z 
) const

Determine whether a point is inside the envelope of the geometry.

Definition at line 134 of file GeometrySimple.cc.

135 {
136 if (!m_hasBoundingBox) {
137 if (m_debug) {
138 std::cerr << m_className << "::IsInBoundingBox:\n"
139 << " Bounding box is not defined.\n";
140 }
141 return true;
142 }
143
144 if (x >= m_bbMin[0] && x <= m_bbMax[0] &&
145 y >= m_bbMin[1] && y <= m_bbMax[1] &&
146 z >= m_bbMin[2] && z <= m_bbMax[2])
147 return true;
148 return false;
149}

Referenced by IsInside().

◆ IsInside()

bool Garfield::GeometrySimple::IsInside ( const double  x,
const double  y,
const double  z,
const bool  tesselated = false 
) const
overridevirtual

Check if a point is inside the geometry.

Implements Garfield::Geometry.

Definition at line 124 of file GeometrySimple.cc.

125 {
126 if (!IsInBoundingBox(x, y, z)) return false;
127
128 for (const auto& solid : m_solids) {
129 if (solid.first->IsInside(x, y, z, tesselated)) return true;
130 }
131 return false;
132}
bool IsInBoundingBox(const double x, const double y, const double z) const
Determine whether a point is inside the envelope of the geometry.

◆ PrintSolids()

void Garfield::GeometrySimple::PrintSolids ( )

Print a summary of the solids present in the geometry.

Definition at line 87 of file GeometrySimple.cc.

87 {
88 std::cout << m_className << "::PrintSolids:\n";
89 const auto nSolids = m_solids.size();
90 if (nSolids == 1) {
91 std::cout << " 1 solid\n";
92 } else {
93 std::cout << " " << nSolids << " solids\n";
94 }
95 if (m_solids.empty()) return;
96 std::cout << " Index Type Medium\n";
97 for (size_t i = 0; i < nSolids; ++i) {
98 std::cout << " " << i << " ";
99 if (m_solids[i].first->IsBox()) {
100 std::cout << "box ";
101 } else if (m_solids[i].first->IsTube()) {
102 std::cout << "tube ";
103 } else if (m_solids[i].first->IsSphere()) {
104 std::cout << "sphere ";
105 } else if (m_solids[i].first->IsHole()) {
106 std::cout << "hole ";
107 } else if (m_solids[i].first->IsRidge()) {
108 std::cout << "ridge ";
109 } else if (m_solids[i].first->IsExtrusion()) {
110 std::cout << "extrusion ";
111 } else if (m_solids[i].first->IsWire()) {
112 std::cout << "wire ";
113 } else {
114 std::cout << "unknown ";
115 }
116 if (m_solids[i].second) {
117 std::cout << m_solids[i].second->GetName() << "\n";
118 } else {
119 std::cout << " ---\n";
120 }
121 }
122}

◆ SetMedium()

void Garfield::GeometrySimple::SetMedium ( Medium medium)
inline

Set a background medium.

Definition at line 34 of file GeometrySimple.hh.

34{ m_medium = medium; }

Member Data Documentation

◆ m_bbMax

std::array<double, 3> Garfield::GeometrySimple::m_bbMax = {{0., 0., 0.}}
protected

Definition at line 68 of file GeometrySimple.hh.

Referenced by AddSolid(), GetBoundingBox(), and IsInBoundingBox().

◆ m_bbMin

std::array<double, 3> Garfield::GeometrySimple::m_bbMin = {{0., 0., 0.}}
protected

Definition at line 67 of file GeometrySimple.hh.

Referenced by AddSolid(), GetBoundingBox(), and IsInBoundingBox().

◆ m_debug

bool Garfield::GeometrySimple::m_debug = false
protected

Switch on/off debugging messages.

Definition at line 71 of file GeometrySimple.hh.

Referenced by EnableDebugging(), and IsInBoundingBox().

◆ m_hasBoundingBox

bool Garfield::GeometrySimple::m_hasBoundingBox = false
protected

Definition at line 66 of file GeometrySimple.hh.

Referenced by AddSolid(), and IsInBoundingBox().

◆ m_medium

Medium* Garfield::GeometrySimple::m_medium = nullptr
protected

Background medium.

Definition at line 63 of file GeometrySimple.hh.

Referenced by Clear(), GetMedium(), and SetMedium().

◆ m_solids

std::vector<std::pair<Solid*, Medium*> > Garfield::GeometrySimple::m_solids
protected

List of solids and associated media.

Definition at line 61 of file GeometrySimple.hh.

Referenced by AddSolid(), Clear(), GetMedium(), GetNumberOfSolids(), GetSolid(), IsInside(), and PrintSolids().


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