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

#include <GeometrySimple.hh>

+ Inheritance diagram for Garfield::GeometrySimple:

Classes

struct  medium
 
struct  solid
 

Public Member Functions

 GeometrySimple ()
 
virtual ~GeometrySimple ()
 
void AddSolid (Solid *s, Medium *m)
 
SolidGetSolid (const double x, const double y, const double z) const
 
MediumGetMedium (const double x, const double y, const double z) const
 
unsigned int GetNumberOfSolids () const
 
unsigned int GetNumberOfMedia () const
 
SolidGetSolid (const unsigned int i) const
 
virtual MediumGetMedium (const unsigned int i) const
 
void Clear ()
 
void PrintSolids ()
 
bool IsInside (const double x, const double y, const double z) const
 
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)
 
void EnableDebugging ()
 
void DisableDebugging ()
 
- Public Member Functions inherited from Garfield::GeometryBase
 GeometryBase ()
 
virtual ~GeometryBase ()
 
virtual MediumGetMedium (const double x, const double y, const double z) const =0
 
virtual bool IsInside (const double x, const double y, const double z) const =0
 
virtual bool GetBoundingBox (double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)=0
 

Protected Attributes

unsigned int m_nMedia
 
std::vector< mediumm_media
 
unsigned int m_nSolids
 
std::vector< solidm_solids
 
bool m_hasBoundingBox
 
double m_xMinBoundingBox
 
double m_yMinBoundingBox
 
double m_zMinBoundingBox
 
double m_xMaxBoundingBox
 
double m_yMaxBoundingBox
 
double m_zMaxBoundingBox
 
bool m_debug
 
- Protected Attributes inherited from Garfield::GeometryBase
std::string m_className
 

Detailed Description

Definition at line 13 of file GeometrySimple.hh.

Constructor & Destructor Documentation

◆ GeometrySimple()

Garfield::GeometrySimple::GeometrySimple ( )

Definition at line 6 of file GeometrySimple.cc.

7 : m_nMedia(0), m_nSolids(0),
8 m_hasBoundingBox(false), m_debug(false) {
9
10 m_className = "GeometrySimple";
11
12 m_media.clear();
13 m_solids.clear();
14}
std::vector< medium > m_media
std::vector< solid > m_solids

◆ ~GeometrySimple()

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

Definition at line 19 of file GeometrySimple.hh.

19{}

Member Function Documentation

◆ AddSolid()

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

Definition at line 16 of file GeometrySimple.cc.

16 {
17
18 // Make sure the solid and the medium are defined.
19 if (!s) {
20 std::cerr << m_className << "::AddSolid:\n";
21 std::cerr << " Solid pointer is null.\n";
22 return;
23 }
24
25 if (!m) {
26 std::cerr << m_className << "::AddSolid:\n";
27 std::cerr << " Medium pointer is null.\n";
28 return;
29 }
30
31 int n = -1;
32 int id = m->GetId();
33 // Check if this medium is already in the list
34 for (unsigned int i = 0; i < m_nMedia; ++i) {
35 if (id == m_media[i].medium->GetId()) {
36 n = i;
37 break;
38 }
39 }
40 // If the medium does not exist yet, add it to the list
41 if (n < 0) {
42 medium newMedium;
43 newMedium.medium = m;
44 m_media.push_back(newMedium);
45 n = m_nMedia;
46 ++m_nMedia;
47 }
48
49 // Update the bounding box ranges
50 double xmin, ymin, zmin;
51 double xmax, ymax, zmax;
52 if (!s->GetBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax)) {
53 std::cerr << m_className << "::AddSolid:\n";
54 std::cerr << " Solid has no bounding box.\n";
55 return;
56 }
57
58 if (m_hasBoundingBox) {
59 if (xmin < m_xMinBoundingBox) m_xMinBoundingBox = xmin;
60 if (ymin < m_yMinBoundingBox) m_yMinBoundingBox = ymin;
61 if (zmin < m_zMinBoundingBox) m_zMinBoundingBox = zmin;
62 if (xmax > m_xMaxBoundingBox) m_xMaxBoundingBox = xmax;
63 if (ymax > m_yMaxBoundingBox) m_yMaxBoundingBox = ymax;
64 if (zmax > m_zMaxBoundingBox) m_zMaxBoundingBox = zmax;
65 } else {
66 m_xMinBoundingBox = xmin;
67 m_yMinBoundingBox = ymin;
68 m_zMinBoundingBox = zmin;
69 m_xMaxBoundingBox = xmax;
70 m_yMaxBoundingBox = ymax;
71 m_zMaxBoundingBox = zmax;
72 m_hasBoundingBox = true;
73 }
74
75 // Add the new solid to the list
76 solid newSolid;
77 newSolid.solid = s;
78 newSolid.medium = n;
79 m_solids.push_back(newSolid);
80 ++m_nSolids;
81}
int GetId() const
Definition: Medium.hh:20

Referenced by GarfieldPhysics::CreateGeometry().

◆ Clear()

void Garfield::GeometrySimple::Clear ( )

Definition at line 127 of file GeometrySimple.cc.

127 {
128
129 m_media.clear();
130 m_solids.clear();
131 m_nMedia = 0;
132 m_nSolids = 0;
133}

◆ DisableDebugging()

void Garfield::GeometrySimple::DisableDebugging ( )
inline

Definition at line 53 of file GeometrySimple.hh.

53{ m_debug = false; }

◆ EnableDebugging()

void Garfield::GeometrySimple::EnableDebugging ( )
inline

Definition at line 52 of file GeometrySimple.hh.

52{ m_debug = true; }

◆ GetBoundingBox()

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

Implements Garfield::GeometryBase.

Definition at line 40 of file GeometrySimple.hh.

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

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

◆ GetMedium() [1/2]

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

Implements Garfield::GeometryBase.

Definition at line 94 of file GeometrySimple.cc.

94 {
95
96 for (unsigned int i = 0; i < m_nSolids; ++i) {
97 if (m_solids[i].solid->IsInside(x, y, z)) {
98 if (m_solids[i].medium < 0) return NULL;
99 return m_media[m_solids[i].medium].medium;
100 }
101 }
102 return NULL;
103}

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

◆ GetMedium() [2/2]

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

Definition at line 116 of file GeometrySimple.cc.

116 {
117
118 if (i >= m_nMedia) {
119 std::cerr << m_className << "::GetMedium:\n";
120 std::cerr << " Requested medium " << i << " does not exist.\n";
121 return NULL;
122 }
123
124 return m_media[i].medium;
125}

◆ GetNumberOfMedia()

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

Definition at line 29 of file GeometrySimple.hh.

29{ return m_nMedia; }

◆ GetNumberOfSolids()

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

Definition at line 28 of file GeometrySimple.hh.

28{ return m_nSolids; }

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

◆ GetSolid() [1/2]

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

Definition at line 83 of file GeometrySimple.cc.

84 {
85
86 for (unsigned int i = 0; i < m_nSolids; ++i) {
87 if (m_solids[i].solid->IsInside(x, y, z)) {
88 return m_solids[i].solid;
89 }
90 }
91 return NULL;
92}

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

◆ GetSolid() [2/2]

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

Definition at line 105 of file GeometrySimple.cc.

105 {
106
107 if (i >= m_nSolids) {
108 std::cerr << m_className << "::GetSolid:\n";
109 std::cerr << " Requested solid " << i << " does not exist.\n";
110 return NULL;
111 }
112
113 return m_solids[i].solid;
114}

◆ IsInBoundingBox()

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

Definition at line 169 of file GeometrySimple.cc.

170 {
171
172 if (!m_hasBoundingBox) {
173 if (m_debug) {
174 std::cerr << m_className << "::IsInBoundingBox:\n";
175 std::cerr << " Bounding box is not defined.\n";
176 }
177 return true;
178 }
179
180 if (x >= m_xMinBoundingBox && x <= m_xMaxBoundingBox &&
181 y >= m_yMinBoundingBox && y <= m_yMaxBoundingBox &&
183 return true;
184 return false;
185}

Referenced by IsInside().

◆ IsInside()

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

Implements Garfield::GeometryBase.

Definition at line 158 of file GeometrySimple.cc.

159 {
160
161 if (!IsInBoundingBox(x, y, z)) return false;
162
163 for (unsigned int i = 0; i < m_nSolids; ++i) {
164 if (m_solids[i].solid->IsInside(x, y, z)) return true;
165 }
166 return false;
167}
bool IsInBoundingBox(const double x, const double y, const double z) const

◆ PrintSolids()

void Garfield::GeometrySimple::PrintSolids ( )

Definition at line 135 of file GeometrySimple.cc.

135 {
136
137 std::cout << m_className << "::PrintSolids:\n";
138 if (m_nSolids == 1) {
139 std::cout << " 1 solid\n";
140 } else {
141 std::cout << " " << m_nSolids << " solids\n";
142 }
143 if (m_nSolids == 0) return;
144 std::cout << " Index Type Medium\n";
145 for (unsigned int i = 0; i < m_nSolids; ++i) {
146 std::cout << " " << i << " ";
147 if (m_solids[i].solid->IsBox()) {
148 std::cout << "box ";
149 } else if (m_solids[i].solid->IsTube()) {
150 std::cout << "tube ";
151 } else {
152 std::cout << "unknown ";
153 }
154 std::cout << m_media[m_solids[i].medium].medium->GetName() << "\n";
155 }
156}

Member Data Documentation

◆ m_debug

bool Garfield::GeometrySimple::m_debug
protected

Definition at line 77 of file GeometrySimple.hh.

Referenced by DisableDebugging(), EnableDebugging(), and IsInBoundingBox().

◆ m_hasBoundingBox

bool Garfield::GeometrySimple::m_hasBoundingBox
protected

Definition at line 72 of file GeometrySimple.hh.

Referenced by AddSolid(), and IsInBoundingBox().

◆ m_media

std::vector<medium> Garfield::GeometrySimple::m_media
protected

Definition at line 61 of file GeometrySimple.hh.

Referenced by AddSolid(), Clear(), GeometrySimple(), GetMedium(), and PrintSolids().

◆ m_nMedia

unsigned int Garfield::GeometrySimple::m_nMedia
protected

Definition at line 57 of file GeometrySimple.hh.

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

◆ m_nSolids

unsigned int Garfield::GeometrySimple::m_nSolids
protected

◆ m_solids

std::vector<solid> Garfield::GeometrySimple::m_solids
protected

◆ m_xMaxBoundingBox

double Garfield::GeometrySimple::m_xMaxBoundingBox
protected

Definition at line 74 of file GeometrySimple.hh.

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

◆ m_xMinBoundingBox

double Garfield::GeometrySimple::m_xMinBoundingBox
protected

Definition at line 73 of file GeometrySimple.hh.

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

◆ m_yMaxBoundingBox

double Garfield::GeometrySimple::m_yMaxBoundingBox
protected

Definition at line 74 of file GeometrySimple.hh.

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

◆ m_yMinBoundingBox

double Garfield::GeometrySimple::m_yMinBoundingBox
protected

Definition at line 73 of file GeometrySimple.hh.

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

◆ m_zMaxBoundingBox

double Garfield::GeometrySimple::m_zMaxBoundingBox
protected

Definition at line 74 of file GeometrySimple.hh.

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

◆ m_zMinBoundingBox

double Garfield::GeometrySimple::m_zMinBoundingBox
protected

Definition at line 73 of file GeometrySimple.hh.

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


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