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::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 override
 Retrieve the medium at a given point.
 
unsigned int GetNumberOfMedia () const
 Get the number of media in the geometry.
 
MediumGetMedium (const unsigned int i) const
 Get a medium from the list.
 
unsigned int GetNumberOfSolids () const override
 Return the number of solids in the geometry.
 
SolidGetSolid (const unsigned int i) const override
 Get a solid from the list.
 
SolidGetSolid (const unsigned int 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
 Get the solid at a given location (x, y, z).
 
void Clear ()
 Reset the geometry.
 
void PrintSolids ()
 
bool IsInside (const double x, const double y, const double z) const override
 Check if a point is inside the geometry.
 
bool IsInBoundingBox (const double x, const double y, const double z) const
 
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)
 
- Public Member Functions inherited from Garfield::GeometryBase
 GeometryBase ()=default
 Constructor.
 
virtual ~GeometryBase ()
 Destructor.
 
virtual MediumGetMedium (const double x, const double y, const double z) const =0
 Retrieve the medium at a given point.
 
virtual unsigned int GetNumberOfSolids () const
 Return the number of solids in the geometry.
 
virtual SolidGetSolid (const unsigned int) const
 Get a solid from the list.
 
virtual SolidGetSolid (const unsigned int, 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 =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< Medium * > m_media
 List of media.
 
std::vector< std::pair< Solid *, int > > m_solids
 List of solids.
 
bool m_hasBoundingBox = false
 
double m_xMinBoundingBox
 
double m_yMinBoundingBox
 
double m_zMinBoundingBox
 
double m_xMaxBoundingBox
 
double m_yMaxBoundingBox
 
double m_zMaxBoundingBox
 
bool m_debug = false
 Switch on/off debugging messages.
 
- Protected Attributes inherited from Garfield::GeometryBase
std::string m_className = "GeometryBase"
 

Detailed Description

"Native" geometry, using simple shapes.

Definition at line 12 of file GeometrySimple.hh.

Constructor & Destructor Documentation

◆ GeometrySimple()

Garfield::GeometrySimple::GeometrySimple ( )

Constructor.

Definition at line 7 of file GeometrySimple.cc.

7 : GeometryBase() {
8 m_className = "GeometrySimple";
9}
GeometryBase()=default
Constructor.

◆ ~GeometrySimple()

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

Destructor.

Definition at line 17 of file GeometrySimple.hh.

17{}

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 11 of file GeometrySimple.cc.

11 {
12 // Make sure the solid and the medium are defined.
13 if (!s || !m) {
14 std::cerr << m_className << "::AddSolid: Null pointer.\n";
15 return;
16 }
17
18 // Check if this medium is already in the list
19 const unsigned int nMedia = m_media.size();
20 unsigned int n = nMedia;
21 const int id = m->GetId();
22 for (unsigned int i = 0; i < nMedia; ++i) {
23 if (id == m_media[i]->GetId()) {
24 n = i;
25 break;
26 }
27 }
28 // If the medium does not exist yet, add it to the list
29 if (n == nMedia) m_media.push_back(m);
30
31 // Update the bounding box ranges
32 double xmin, ymin, zmin;
33 double xmax, ymax, zmax;
34 if (!s->GetBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax)) {
35 std::cerr << m_className << "::AddSolid: Solid has no bounding box.\n";
36 return;
37 }
38
39 if (m_hasBoundingBox) {
40 m_xMinBoundingBox = std::min(m_xMinBoundingBox, xmin);
41 m_yMinBoundingBox = std::min(m_yMinBoundingBox, ymin);
42 m_zMinBoundingBox = std::min(m_zMinBoundingBox, zmin);
43 m_xMaxBoundingBox = std::max(m_xMaxBoundingBox, xmax);
44 m_yMaxBoundingBox = std::max(m_yMaxBoundingBox, ymax);
45 m_zMaxBoundingBox = std::max(m_zMaxBoundingBox, zmax);
46 } else {
47 m_xMinBoundingBox = xmin;
48 m_yMinBoundingBox = ymin;
49 m_zMinBoundingBox = zmin;
50 m_xMaxBoundingBox = xmax;
51 m_yMaxBoundingBox = ymax;
52 m_zMaxBoundingBox = zmax;
53 m_hasBoundingBox = true;
54 }
55
56 // Add the new solid to the list.
57 m_solids.emplace_back(std::make_pair(s, n));
58}
std::vector< std::pair< Solid *, int > > m_solids
List of solids.
std::vector< Medium * > m_media
List of media.

Referenced by GarfieldPhysics::CreateGeometry().

◆ Clear()

void Garfield::GeometrySimple::Clear ( )

Reset the geometry.

Definition at line 109 of file GeometrySimple.cc.

109 {
110 m_media.clear();
111 m_solids.clear();
112}

◆ EnableDebugging()

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

Definition at line 54 of file GeometrySimple.hh.

54{ 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::GeometryBase.

Definition at line 42 of file GeometrySimple.hh.

43 {
44 xmin = m_xMinBoundingBox;
45 ymin = m_yMinBoundingBox;
46 zmin = m_zMinBoundingBox;
47 xmax = m_xMaxBoundingBox;
48 ymax = m_yMaxBoundingBox;
49 zmax = m_zMaxBoundingBox;
50 return true;
51 }

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

◆ GetMedium() [1/2]

Medium * Garfield::GeometrySimple::GetMedium ( const double  x,
const double  y,
const double  z 
) const
overridevirtual

Retrieve the medium at a given point.

Implements Garfield::GeometryBase.

Definition at line 68 of file GeometrySimple.cc.

69 {
70 for (const auto& solid : m_solids) {
71 if (solid.first->IsInside(x, y, z)) {
72 if (solid.second < 0) return nullptr;
73 return m_media[solid.second];
74 }
75 }
76 return nullptr;
77}

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

◆ GetMedium() [2/2]

Medium * Garfield::GeometrySimple::GetMedium ( const unsigned int  i) const

Get a medium from the list.

Definition at line 100 of file GeometrySimple.cc.

100 {
101 if (i >= m_media.size()) {
102 std::cerr << m_className << "::GetMedium:\n"
103 << " Requested medium " << i << " does not exist.\n";
104 return nullptr;
105 }
106 return m_media[i];
107}

◆ GetNumberOfMedia()

unsigned int Garfield::GeometrySimple::GetNumberOfMedia ( ) const
inline

Get the number of media in the geometry.

Definition at line 22 of file GeometrySimple.hh.

22{ return m_media.size(); }

◆ GetNumberOfSolids()

unsigned int Garfield::GeometrySimple::GetNumberOfSolids ( ) const
inlineoverridevirtual

Return the number of solids in the geometry.

Reimplemented from Garfield::GeometryBase.

Definition at line 26 of file GeometrySimple.hh.

26{ return m_solids.size(); }

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

◆ GetSolid() [1/3]

Solid * Garfield::GeometrySimple::GetSolid ( const double  x,
const double  y,
const double  z 
) const

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

Definition at line 60 of file GeometrySimple.cc.

61 {
62 for (const auto& solid : m_solids) {
63 if (solid.first->IsInside(x, y, z)) return solid.first;
64 }
65 return nullptr;
66}

◆ GetSolid() [2/3]

Solid * Garfield::GeometrySimple::GetSolid ( const unsigned int  ) const
overridevirtual

Get a solid from the list.

Reimplemented from Garfield::GeometryBase.

Definition at line 79 of file GeometrySimple.cc.

79 {
80 if (i >= m_solids.size()) {
81 std::cerr << m_className << "::GetSolid:\n"
82 << " Requested solid " << i << " does not exist.\n";
83 return nullptr;
84 }
85
86 return m_solids[i].first;
87}

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

◆ GetSolid() [3/3]

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

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

Reimplemented from Garfield::GeometryBase.

Definition at line 89 of file GeometrySimple.cc.

89 {
90 if (i >= m_solids.size()) {
91 std::cerr << m_className << "::GetSolid:\n"
92 << " Requested solid " << i << " does not exist.\n";
93 return nullptr;
94 }
95
96 medium = m_media[m_solids[i].second];
97 return m_solids[i].first;
98}

◆ IsInBoundingBox()

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

Definition at line 149 of file GeometrySimple.cc.

150 {
151 if (!m_hasBoundingBox) {
152 if (m_debug) {
153 std::cerr << m_className << "::IsInBoundingBox:\n"
154 << " Bounding box is not defined.\n";
155 }
156 return true;
157 }
158
159 if (x >= m_xMinBoundingBox && x <= m_xMaxBoundingBox &&
162 return true;
163 return false;
164}

Referenced by IsInside().

◆ IsInside()

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

Check if a point is inside the geometry.

Implements Garfield::GeometryBase.

Definition at line 139 of file GeometrySimple.cc.

140 {
141 if (!IsInBoundingBox(x, y, z)) return false;
142
143 for (const auto& solid : m_solids) {
144 if (solid.first->IsInside(x, y, z)) return true;
145 }
146 return false;
147}
bool IsInBoundingBox(const double x, const double y, const double z) const

◆ PrintSolids()

void Garfield::GeometrySimple::PrintSolids ( )

Definition at line 114 of file GeometrySimple.cc.

114 {
115 std::cout << m_className << "::PrintSolids:\n";
116 const unsigned int nSolids = m_solids.size();
117 if (nSolids == 1) {
118 std::cout << " 1 solid\n";
119 } else {
120 std::cout << " " << nSolids << " solids\n";
121 }
122 if (m_solids.empty()) return;
123 std::cout << " Index Type Medium\n";
124 for (unsigned int i = 0; i < nSolids; ++i) {
125 std::cout << " " << i << " ";
126 if (m_solids[i].first->IsBox()) {
127 std::cout << "box ";
128 } else if (m_solids[i].first->IsTube()) {
129 std::cout << "tube ";
130 } else if (m_solids[i].first->IsSphere()) {
131 std::cout << "sphere ";
132 } else {
133 std::cout << "unknown ";
134 }
135 std::cout << m_media[m_solids[i].second]->GetName() << "\n";
136 }
137}

Member Data Documentation

◆ m_debug

bool Garfield::GeometrySimple::m_debug = false
protected

Switch on/off debugging messages.

Definition at line 69 of file GeometrySimple.hh.

Referenced by EnableDebugging(), and IsInBoundingBox().

◆ m_hasBoundingBox

bool Garfield::GeometrySimple::m_hasBoundingBox = false
protected

Definition at line 64 of file GeometrySimple.hh.

Referenced by AddSolid(), and IsInBoundingBox().

◆ m_media

std::vector<Medium*> Garfield::GeometrySimple::m_media
protected

List of media.

Definition at line 58 of file GeometrySimple.hh.

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

◆ m_solids

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

List of solids.

Definition at line 61 of file GeometrySimple.hh.

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

◆ m_xMaxBoundingBox

double Garfield::GeometrySimple::m_xMaxBoundingBox
protected

Definition at line 66 of file GeometrySimple.hh.

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

◆ m_xMinBoundingBox

double Garfield::GeometrySimple::m_xMinBoundingBox
protected

Definition at line 65 of file GeometrySimple.hh.

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

◆ m_yMaxBoundingBox

double Garfield::GeometrySimple::m_yMaxBoundingBox
protected

Definition at line 66 of file GeometrySimple.hh.

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

◆ m_yMinBoundingBox

double Garfield::GeometrySimple::m_yMinBoundingBox
protected

Definition at line 65 of file GeometrySimple.hh.

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

◆ m_zMaxBoundingBox

double Garfield::GeometrySimple::m_zMaxBoundingBox
protected

Definition at line 66 of file GeometrySimple.hh.

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

◆ m_zMinBoundingBox

double Garfield::GeometrySimple::m_zMinBoundingBox
protected

Definition at line 65 of file GeometrySimple.hh.

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


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