Garfield++ 4.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:

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 bool tesselated=false) 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 a pointer to the ROOT material with a given index.
 
TGeoMaterial * GetMaterial (const char *name)
 Get a pointer to the ROOT material with a given name.
 
void SetMedium (const unsigned int imat, Medium *med)
 Associate a ROOT material with a Garfield medium.
 
void SetMedium (const char *mat, Medium *med)
 Associate a ROOT material with a Garfield medium.
 
bool IsInside (const double x, const double y, const double z, const bool tesselated=false) 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::Geometry
 Geometry ()=delete
 Default constructor.
 
 Geometry (const std::string &name)
 Constructor.
 
virtual ~Geometry ()
 Destructor.
 
virtual MediumGetMedium (const double x, const double y, const double z, const bool tesselated=false) const =0
 Retrieve the medium at a given point.
 
virtual size_t GetNumberOfSolids () const
 Return the number of solids in the geometry.
 
virtual SolidGetSolid (const size_t) const
 Get a solid from the list.
 
virtual SolidGetSolid (const size_t, 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 bool tesselated=false) 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::map< std::string, Medium * > m_materials
 
bool m_debug = false
 
- Protected Attributes inherited from Garfield::Geometry
std::string m_className = "Geometry"
 

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: Geometry("GeometryRoot") {}
Geometry()=delete
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 45 of file GeometryRoot.hh.

45{ 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::Geometry.

Definition at line 134 of file GeometryRoot.cc.

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

◆ GetMaterial() [1/2]

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

Get a pointer to the ROOT material with a given name.

Definition at line 54 of file GeometryRoot.cc.

54 {
55 if (!m_geoManager) {
56 PrintGeoNotDefined("GetMaterial");
57 return nullptr;
58 }
59
60 return m_geoManager->GetMaterial(name);
61}
void PrintGeoNotDefined(const std::string &fcn) const

◆ GetMaterial() [2/2]

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

Get a pointer to the ROOT material with a given index.

Definition at line 45 of file GeometryRoot.cc.

45 {
46 if (!m_geoManager) {
47 PrintGeoNotDefined("GetMaterial");
48 return nullptr;
49 }
50
51 return m_geoManager->GetMaterial(i);
52}

◆ GetMedium()

Medium * Garfield::GeometryRoot::GetMedium ( const double  x,
const double  y,
const double  z,
const bool  tesselated = false 
) const
overridevirtual

Retrieve the medium at a given point.

Implements Garfield::Geometry.

Definition at line 23 of file GeometryRoot.cc.

24 {
25 if (!m_geoManager) return nullptr;
26 m_geoManager->SetCurrentPoint(x, y, z);
27 if (m_geoManager->IsOutside()) return nullptr;
28 TGeoNode* cnode = m_geoManager->GetCurrentNode();
29 std::string name(cnode->GetMedium()->GetMaterial()->GetName());
30
31 const auto it = m_materials.find(name);
32 if (it == m_materials.end()) return nullptr;
33 return it->second;
34}
std::map< std::string, Medium * > m_materials
Definition: GeometryRoot.hh:52

◆ GetNumberOfMaterials()

unsigned int Garfield::GeometryRoot::GetNumberOfMaterials ( )

Get the number of materials defined in the ROOT geometry.

Definition at line 36 of file GeometryRoot.cc.

36 {
37 if (!m_geoManager) {
38 PrintGeoNotDefined("GetNumberOfMaterials");
39 return 0;
40 }
41
42 return m_geoManager->GetListOfMaterials()->GetEntries();
43}

◆ IsInside()

bool Garfield::GeometryRoot::IsInside ( const double  x,
const double  y,
const double  z,
const bool  tesselated = false 
) const
overridevirtual

Check if a point is inside the geometry.

Implements Garfield::Geometry.

Definition at line 125 of file GeometryRoot.cc.

126 {
127 if (m_geoManager) {
128 m_geoManager->SetCurrentPoint(x, y, z);
129 return !m_geoManager->IsOutside();
130 }
131 return false;
132}

◆ PrintGeoNotDefined()

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

Definition at line 157 of file GeometryRoot.cc.

157 {
158
159 std::cerr << m_className + "::" + fcn << ":\n"
160 << " ROOT geometry is not defined. Call SetGeometry first.\n";
161}
std::string m_className
Definition: Geometry.hh:44

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 m_geoManager = geoman;
20 m_materials.clear();
21}

◆ SetMedium() [1/2]

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

Associate a ROOT material with a Garfield medium.

Definition at line 104 of file GeometryRoot.cc.

104 {
105 if (!m_geoManager) {
106 PrintGeoNotDefined("SetMedium");
107 return;
108 }
109
110 if (!med) {
111 std::cerr << m_className << "::SetMedium: Null pointer.\n";
112 return;
113 }
114
115 const int imat = m_geoManager->GetMaterialIndex(name);
116 if (imat < 0) {
117 std::cerr << m_className << "::SetMedium:\n"
118 << " ROOT material " << name << " does not exist.\n";
119 return;
120 }
121
122 SetMedium(imat, med);
123}
void SetMedium(const unsigned int imat, Medium *med)
Associate a ROOT material with a Garfield medium.
Definition: GeometryRoot.cc:63

◆ SetMedium() [2/2]

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

Associate a ROOT material with a Garfield medium.

Definition at line 63 of file GeometryRoot.cc.

63 {
64 if (!m_geoManager) {
65 PrintGeoNotDefined("SetMedium");
66 return;
67 }
68
69 if (!med) {
70 std::cerr << m_className << "::SetMedium: Null pointer.\n";
71 return;
72 }
73
74 TGeoMaterial* mat = m_geoManager->GetMaterial(imat);
75 if (!mat) {
76 std::cerr << m_className << "::SetMedium:\n"
77 << " ROOT material " << imat << " does not exist.\n";
78 return;
79 }
80
81 std::string name(mat->GetName());
82
83 // Check if this material has already been associated with a medium.
84 if (m_materials.count(name) > 0) {
85 std::cout << m_className << "::SetMedium:\n"
86 << " Replacing existing association of material " << name
87 << " with medium " << med->GetName() << ".\n";
88 }
89 m_materials[name] = med;
90
91 // Check if material properties match
92 const double rho1 = mat->GetDensity();
93 const double rho2 = med->GetMassDensity();
94 std::cout << m_className << "::SetMedium:\n"
95 << " ROOT material: " << name << "\n"
96 << " Density: " << rho1 << " g / cm3\n"
97 << " Medium: " << med->GetName() << "\n"
98 << " Density: " << rho2 << " g / cm3\n";
99 if (rho1 > 0 && fabs(rho1 - rho2) / rho1 > 0.01) {
100 std::cout << " WARNING: Densities differ by > 1%.\n";
101 }
102}
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 55 of file GeometryRoot.hh.

Referenced by EnableDebugging().

◆ m_geoManager

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

◆ m_materials

std::map<std::string, Medium*> Garfield::GeometryRoot::m_materials
protected

Definition at line 52 of file GeometryRoot.hh.

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


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