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

Use a geometry defined using the ROOT TGeo package. More...

#include <GeometryRoot.hh>

+ Inheritance diagram for Garfield::GeometryRoot:

Classes

struct  material
 

Public Member Functions

 GeometryRoot ()
 Constructor.
 
 ~GeometryRoot ()
 Destructor.
 
void SetGeometry (TGeoManager *geoman)
 Set the geometry (pointer to ROOT TGeoManager).
 
MediumGetMedium (const double x, const double y, const double z) const
 
unsigned int GetNumberOfMaterials ()
 Get the number of materials defined in the ROOT geometry.
 
TGeoMaterial * GetMaterial (const unsigned int i)
 Get pointer to ROOT material with given index.
 
TGeoMaterial * GetMaterial (const char *name)
 Get pointer to ROOT material with given name.
 
void SetMedium (const unsigned 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
 
std::vector< materialm_materials
 
bool m_debug
 
- Protected Attributes inherited from Garfield::GeometryBase
std::string m_className
 

Detailed Description

Use a geometry defined using the ROOT TGeo package.

Definition at line 15 of file GeometryRoot.hh.

Constructor & Destructor Documentation

◆ GeometryRoot()

Garfield::GeometryRoot::GeometryRoot ( )

Constructor.

Definition at line 12 of file GeometryRoot.cc.

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

◆ ~GeometryRoot()

Garfield::GeometryRoot::~GeometryRoot ( )
inline

Destructor.

Definition at line 21 of file GeometryRoot.hh.

21{}

Member Function Documentation

◆ DisableDebugging()

void Garfield::GeometryRoot::DisableDebugging ( )
inline

Definition at line 55 of file GeometryRoot.hh.

55{ m_debug = false; }

◆ EnableDebugging()

void Garfield::GeometryRoot::EnableDebugging ( )
inline

Definition at line 54 of file GeometryRoot.hh.

54{ 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 166 of file GeometryRoot.cc.

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

◆ GetMaterial() [1/2]

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

Get pointer to ROOT material with given name.

Definition at line 71 of file GeometryRoot.cc.

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

◆ GetMaterial() [2/2]

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

Get pointer to ROOT material with given index.

Definition at line 59 of file GeometryRoot.cc.

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

◆ GetMedium()

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

Implements Garfield::GeometryBase.

Definition at line 29 of file GeometryRoot.cc.

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

◆ GetNumberOfMaterials()

unsigned int Garfield::GeometryRoot::GetNumberOfMaterials ( )

Get the number of materials defined in the ROOT geometry.

Definition at line 47 of file GeometryRoot.cc.

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

◆ IsInside()

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

Implements Garfield::GeometryBase.

Definition at line 40 of file GeometryRoot.hh.

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

◆ SetGeometry()

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

Set the geometry (pointer to ROOT TGeoManager).

Definition at line 18 of file GeometryRoot.cc.

18 {
19
20 if (!geoman) {
21 std::cerr << m_className << "::SetGeometry:\n Null pointer.";
22 return;
23 }
24
25 m_geoManager = geoman;
26 m_materials.clear();
27}

◆ SetMedium() [1/2]

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

Definition at line 140 of file GeometryRoot.cc.

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

◆ SetMedium() [2/2]

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

Definition at line 83 of file GeometryRoot.cc.

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

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().


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