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

#include <GeometryRoot.hh>

+ Inheritance diagram for Garfield::GeometryRoot:

Classes

struct  material
 

Public Member Functions

 GeometryRoot ()
 
 ~GeometryRoot ()
 
void SetGeometry (TGeoManager *geoman)
 
MediumGetMedium (const double x, const double y, const double z) const
 
int GetNumberOfMaterials ()
 
TGeoMaterial * GetMaterial (const int i)
 
TGeoMaterial * GetMaterial (const char *name)
 
void SetMedium (const int imat, Medium *med)
 
void SetMedium (const char *mat, Medium *med)
 
bool IsInside (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

TGeoManager * m_geoManager
 
int m_nMaterials
 
std::vector< materialm_materials
 
bool m_debug
 
- Protected Attributes inherited from Garfield::GeometryBase
std::string m_className
 

Detailed Description

Definition at line 15 of file GeometryRoot.hh.

Constructor & Destructor Documentation

◆ GeometryRoot()

Garfield::GeometryRoot::GeometryRoot ( )

Definition at line 12 of file GeometryRoot.cc.

13 : m_geoManager(NULL), m_nMaterials(0), m_debug(false) {
14
15 m_className = "GeometryRoot";
16}
TGeoManager * m_geoManager
Definition: GeometryRoot.hh:58

◆ ~GeometryRoot()

Garfield::GeometryRoot::~GeometryRoot ( )
inline

Definition at line 21 of file GeometryRoot.hh.

21{}

Member Function Documentation

◆ DisableDebugging()

void Garfield::GeometryRoot::DisableDebugging ( )
inline

Definition at line 54 of file GeometryRoot.hh.

54{ m_debug = false; }

◆ EnableDebugging()

void Garfield::GeometryRoot::EnableDebugging ( )
inline

Definition at line 53 of file GeometryRoot.hh.

53{ m_debug = true; }

◆ GetBoundingBox()

bool Garfield::GeometryRoot::GetBoundingBox ( double &  xmin,
double &  ymin,
double &  zmin,
double &  xmax,
double &  ymax,
double &  zmax 
)
virtual

Implements Garfield::GeometryBase.

Definition at line 168 of file GeometryRoot.cc.

169 {
170
171 if (!m_geoManager) return false;
172 TGeoBBox* box = (TGeoBBox*)m_geoManager->GetTopVolume()->GetShape();
173 const double dx = box->GetDX();
174 const double dy = box->GetDY();
175 const double dz = box->GetDZ();
176 const double ox = box->GetOrigin()[0];
177 const double oy = box->GetOrigin()[1];
178 const double oz = box->GetOrigin()[2];
179 xmin = ox - dx;
180 xmax = ox + dx;
181 ymin = oy - dy;
182 ymax = oy + dy;
183 zmin = oz - dz;
184 zmax = oz + dz;
185 return true;
186}

◆ GetMaterial() [1/2]

TGeoMaterial * Garfield::GeometryRoot::GetMaterial ( const char *  name)

Definition at line 72 of file GeometryRoot.cc.

72 {
73
74 if (!m_geoManager) {
75 std::cerr << "GeometryRoot::GetMaterial:\n";
76 std::cerr << " ROOT geometry is not defined.\n";
77 std::cerr << " Call SetGeometry first.\n";
78 return NULL;
79 }
80
81 return m_geoManager->GetMaterial(name);
82}

◆ GetMaterial() [2/2]

TGeoMaterial * Garfield::GeometryRoot::GetMaterial ( const int  i)

Definition at line 60 of file GeometryRoot.cc.

60 {
61
62 if (!m_geoManager) {
63 std::cerr << "GeometryRoot::GetMaterial:\n";
64 std::cerr << " ROOT geometry is not defined.\n";
65 std::cerr << " Call SetGeometry first.\n";
66 return NULL;
67 }
68
69 return m_geoManager->GetMaterial(i);
70}

◆ GetMedium()

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

Implements Garfield::GeometryBase.

Definition at line 31 of file GeometryRoot.cc.

32 {
33
34 if (!m_geoManager) return NULL;
35 m_geoManager->SetCurrentPoint(x, y, z);
36 if (m_geoManager->IsOutside()) return NULL;
37 TGeoNode* cnode = m_geoManager->GetCurrentNode();
38 std::string name(cnode->GetMedium()->GetMaterial()->GetName());
39
40 for (int i = m_nMaterials; i--;) {
41 if (m_materials[i].name == name) {
42 return m_materials[i].medium;
43 }
44 }
45 return NULL;
46}
std::vector< material > m_materials
Definition: GeometryRoot.hh:66

◆ GetNumberOfMaterials()

int Garfield::GeometryRoot::GetNumberOfMaterials ( )

Definition at line 48 of file GeometryRoot.cc.

48 {
49
50 if (!m_geoManager) {
51 std::cerr << "GeometryRoot::GetNumberOfMaterials:\n";
52 std::cerr << " ROOT geometry is not defined.\n";
53 std::cerr << " Call SetGeometry first.\n";
54 return 0;
55 }
56
57 return m_geoManager->GetListOfMaterials()->GetEntries();
58}

◆ IsInside()

bool Garfield::GeometryRoot::IsInside ( const double  x,
const double  y,
const double  z 
) const
inlinevirtual

Implements Garfield::GeometryBase.

Definition at line 39 of file GeometryRoot.hh.

39 {
40
41 if (m_geoManager) {
42 m_geoManager->SetCurrentPoint(x, y, z);
43 return !m_geoManager->IsOutside();
44 }
45 return false;
46 }

◆ SetGeometry()

void Garfield::GeometryRoot::SetGeometry ( TGeoManager *  geoman)

Definition at line 18 of file GeometryRoot.cc.

18 {
19
20 if (geoman == NULL) {
21 std::cerr << "GeometryRoot::SetGeometry:\n";
22 std::cerr << " Pointer to TGeoManager is null.\n";
23 return;
24 }
25
26 m_geoManager = geoman;
27 m_materials.clear();
28 m_nMaterials = 0;
29}

◆ SetMedium() [1/2]

void Garfield::GeometryRoot::SetMedium ( const char *  mat,
Medium med 
)

Definition at line 142 of file GeometryRoot.cc.

142 {
143
144 if (!m_geoManager) {
145 std::cerr << "GeometryRoot::SetMedium:\n";
146 std::cerr << " ROOT geometry is not defined.\n";
147 std::cerr << " Call SetGeometry first.\n";
148 return;
149 }
150
151 if (!med) {
152 std::cerr << "GeometryRoot::SetMedium:\n";
153 std::cerr << " Medium pointer is null.\n";
154 return;
155 }
156
157 const int imat = m_geoManager->GetMaterialIndex(name);
158 if (imat < 0) {
159 std::cerr << "GeometryRoot::SetMedium:" << std::endl;
160 std::cerr << " ROOT material " << name << " does not exist."
161 << std::endl;
162 return;
163 }
164
165 SetMedium(imat, med);
166}
void SetMedium(const int imat, Medium *med)
Definition: GeometryRoot.cc:84

◆ SetMedium() [2/2]

void Garfield::GeometryRoot::SetMedium ( const int  imat,
Medium med 
)

Definition at line 84 of file GeometryRoot.cc.

84 {
85
86 if (!m_geoManager) {
87 std::cerr << "GeometryRoot::SetMedium:\n";
88 std::cerr << " ROOT geometry is not defined.\n";
89 std::cerr << " Call SetGeometry first.\n";
90 return;
91 }
92
93 if (!med) {
94 std::cerr << "GeometryRoot::SetMedium:\n";
95 std::cerr << " Medium pointer is null.\n";
96 return;
97 }
98
99 TGeoMaterial* mat = m_geoManager->GetMaterial(imat);
100 if (!mat) {
101 std::cerr << "GeometryRoot::SetMedium:\n";
102 std::cerr << " ROOT material with index " << imat
103 << " does not exist.\n";
104 return;
105 }
106
107 std::string name(mat->GetName());
108 bool isNew = true;
109 // Check if this material has already been associated with a medium
110 for (int i = m_nMaterials; i--;) {
111 if (name == m_materials[i].name) {
112 std::cout << "GeometryRoot::SetMedium:\n";
113 std::cout << " Current association of material " << name
114 << " with medium " << med->GetName() << " is overwritten.\n";
115 m_materials[i].medium = med;
116 isNew = false;
117 break;
118 }
119 }
120
121 if (isNew) {
122 material newMaterial;
123 newMaterial.name = name;
124 newMaterial.medium = med;
125 m_materials.push_back(newMaterial);
126 ++m_nMaterials;
127 }
128
129 // Check if material properties match
130 const double rho1 = mat->GetDensity();
131 const double rho2 = med->GetMassDensity();
132 std::cout << "GeometryROOT::SetMedium:\n";
133 std::cout << " ROOT material: " << name << "\n";
134 std::cout << " Density: " << rho1 << " g / cm3\n";
135 std::cout << " Medium: " << med->GetName() << "\n";
136 std::cout << " Density: " << rho2 << " g / cm3\n";
137 if (rho1 > 0 && fabs(rho1 - rho2) / rho1 > 0.01) {
138 std::cout << " WARNING: Densities differ by > 1%.\n";
139 }
140}
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:616

Referenced by SetMedium().

Member Data Documentation

◆ m_debug

bool Garfield::GeometryRoot::m_debug
protected

Definition at line 69 of file GeometryRoot.hh.

Referenced by DisableDebugging(), and EnableDebugging().

◆ m_geoManager

TGeoManager* Garfield::GeometryRoot::m_geoManager
protected

◆ m_materials

std::vector<material> Garfield::GeometryRoot::m_materials
protected

Definition at line 66 of file GeometryRoot.hh.

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

◆ m_nMaterials

int Garfield::GeometryRoot::m_nMaterials
protected

Definition at line 61 of file GeometryRoot.hh.

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


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