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::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 override
 Retrieve the medium at a given point.
 
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)
 Associate a ROOT material with Garfield medium.
 
void SetMedium (const char *mat, Medium *med)
 Associate a ROOT material with Garfield medium.
 
bool IsInside (const double x, const double y, const double z) const override
 Check if a point is inside 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 debugging and warning messages on/off.
 
- 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 Member Functions

void PrintGeoNotDefined (const std::string &fcn) const
 

Protected Attributes

TGeoManager * m_geoManager = nullptr
 
std::vector< materialm_materials
 
bool m_debug = false
 
- Protected Attributes inherited from Garfield::GeometryBase
std::string m_className = "GeometryBase"
 

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.

12: GeometryBase() { m_className = "GeometryRoot"; }
GeometryBase()=default
Constructor.

◆ ~GeometryRoot()

Garfield::GeometryRoot::~GeometryRoot ( )
inline

Destructor.

Definition at line 20 of file GeometryRoot.hh.

20{}

Member Function Documentation

◆ EnableDebugging()

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

Switch debugging and warning messages on/off.

Definition at line 50 of file GeometryRoot.hh.

50{ m_debug = on; }

◆ GetBoundingBox()

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

Get the bounding box (envelope of the geometry).

Implements Garfield::GeometryBase.

Definition at line 141 of file GeometryRoot.cc.

142 {
143 if (!m_geoManager) return false;
144 auto top = m_geoManager->GetTopVolume();
145 if (!top) return false;
146 if (!top->GetShape()) return false;
147 TGeoBBox* box = (TGeoBBox*)m_geoManager->GetTopVolume()->GetShape();
148 if (!box) return false;
149 const double dx = box->GetDX();
150 const double dy = box->GetDY();
151 const double dz = box->GetDZ();
152 const double ox = box->GetOrigin()[0];
153 const double oy = box->GetOrigin()[1];
154 const double oz = box->GetOrigin()[2];
155 xmin = ox - dx;
156 xmax = ox + dx;
157 ymin = oy - dy;
158 ymax = oy + dy;
159 zmin = oz - dz;
160 zmax = oz + dz;
161 return true;
162}
TGeoManager * m_geoManager
Definition: GeometryRoot.hh:54

◆ GetMaterial() [1/2]

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

Get pointer to ROOT material with given name.

Definition at line 59 of file GeometryRoot.cc.

59 {
60 if (!m_geoManager) {
61 PrintGeoNotDefined("GetMaterial");
62 return nullptr;
63 }
64
65 return m_geoManager->GetMaterial(name);
66}
void PrintGeoNotDefined(const std::string &fcn) const

◆ GetMaterial() [2/2]

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

Get pointer to ROOT material with given index.

Definition at line 50 of file GeometryRoot.cc.

50 {
51 if (!m_geoManager) {
52 PrintGeoNotDefined("GetMaterial");
53 return nullptr;
54 }
55
56 return m_geoManager->GetMaterial(i);
57}

◆ GetMedium()

Medium * Garfield::GeometryRoot::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 24 of file GeometryRoot.cc.

25 {
26 if (!m_geoManager) return nullptr;
27 m_geoManager->SetCurrentPoint(x, y, z);
28 if (m_geoManager->IsOutside()) return nullptr;
29 TGeoNode* cnode = m_geoManager->GetCurrentNode();
30 std::string name(cnode->GetMedium()->GetMaterial()->GetName());
31
32 const unsigned int nMaterials = m_materials.size();
33 for (unsigned int i = 0; i < nMaterials; ++i) {
34 if (m_materials[i].name == name) {
35 return m_materials[i].medium;
36 }
37 }
38 return nullptr;
39}
std::vector< material > m_materials
Definition: GeometryRoot.hh:61

◆ GetNumberOfMaterials()

unsigned int Garfield::GeometryRoot::GetNumberOfMaterials ( )

Get the number of materials defined in the ROOT geometry.

Definition at line 41 of file GeometryRoot.cc.

41 {
42 if (!m_geoManager) {
43 PrintGeoNotDefined("GetNumberOfMaterials");
44 return 0;
45 }
46
47 return m_geoManager->GetListOfMaterials()->GetEntries();
48}

◆ IsInside()

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

Check if a point is inside the geometry.

Implements Garfield::GeometryBase.

Definition at line 38 of file GeometryRoot.hh.

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

◆ PrintGeoNotDefined()

void Garfield::GeometryRoot::PrintGeoNotDefined ( const std::string &  fcn) const
protected

Definition at line 164 of file GeometryRoot.cc.

164 {
165
166 std::cerr << m_className + "::" + fcn << ":\n"
167 << " ROOT geometry is not defined. Call SetGeometry first.\n";
168}

Referenced by GetMaterial(), GetNumberOfMaterials(), and SetMedium().

◆ SetGeometry()

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

Set the geometry (pointer to ROOT TGeoManager).

Definition at line 14 of file GeometryRoot.cc.

14 {
15 if (!geoman) {
16 std::cerr << m_className << "::SetGeometry: Null pointer.\n";
17 return;
18 }
19
20 m_geoManager = geoman;
21 m_materials.clear();
22}

◆ SetMedium() [1/2]

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

Associate a ROOT material with Garfield medium.

Definition at line 120 of file GeometryRoot.cc.

120 {
121 if (!m_geoManager) {
122 PrintGeoNotDefined("SetMedium");
123 return;
124 }
125
126 if (!med) {
127 std::cerr << m_className << "::SetMedium: Null pointer.\n";
128 return;
129 }
130
131 const int imat = m_geoManager->GetMaterialIndex(name);
132 if (imat < 0) {
133 std::cerr << m_className << "::SetMedium:\n"
134 << " ROOT material " << name << " does not exist.\n";
135 return;
136 }
137
138 SetMedium(imat, med);
139}
void SetMedium(const unsigned int imat, Medium *med)
Associate a ROOT material with Garfield medium.
Definition: GeometryRoot.cc:68

◆ SetMedium() [2/2]

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

Associate a ROOT material with Garfield medium.

Definition at line 68 of file GeometryRoot.cc.

68 {
69 if (!m_geoManager) {
70 PrintGeoNotDefined("SetMedium");
71 return;
72 }
73
74 if (!med) {
75 std::cerr << m_className << "::SetMedium: Null pointer.\n";
76 return;
77 }
78
79 TGeoMaterial* mat = m_geoManager->GetMaterial(imat);
80 if (!mat) {
81 std::cerr << m_className << "::SetMedium:\n"
82 << " ROOT material " << imat << " does not exist.\n";
83 return;
84 }
85
86 std::string name(mat->GetName());
87 bool isNew = true;
88 // Check if this material has already been associated with a medium
89 const unsigned int nMaterials = m_materials.size();
90 for (unsigned int i = 0; i < nMaterials; ++i) {
91 if (name != m_materials[i].name) continue;
92 std::cout << m_className << "::SetMedium:\n"
93 << " Current association of material " << name
94 << " with medium " << med->GetName() << " is overwritten.\n";
95 m_materials[i].medium = med;
96 isNew = false;
97 break;
98 }
99
100 if (isNew) {
101 material newMaterial;
102 newMaterial.name = name;
103 newMaterial.medium = med;
104 m_materials.push_back(std::move(newMaterial));
105 }
106
107 // Check if material properties match
108 const double rho1 = mat->GetDensity();
109 const double rho2 = med->GetMassDensity();
110 std::cout << m_className << "::SetMedium:\n"
111 << " ROOT material: " << name << "\n"
112 << " Density: " << rho1 << " g / cm3\n"
113 << " Medium: " << med->GetName() << "\n"
114 << " Density: " << rho2 << " g / cm3\n";
115 if (rho1 > 0 && fabs(rho1 - rho2) / rho1 > 0.01) {
116 std::cout << " WARNING: Densities differ by > 1%.\n";
117 }
118}
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:615

Referenced by SetMedium().

Member Data Documentation

◆ m_debug

bool Garfield::GeometryRoot::m_debug = false
protected

Definition at line 64 of file GeometryRoot.hh.

Referenced by EnableDebugging().

◆ m_geoManager

TGeoManager* Garfield::GeometryRoot::m_geoManager = nullptr
protected

◆ m_materials

std::vector<material> Garfield::GeometryRoot::m_materials
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: