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

Visualize a geometry defined using the "native" shapes. More...

#include <ViewGeometry.hh>

Public Member Functions

 ViewGeometry ()
 Constructor.
 
 ~ViewGeometry ()
 Destructor.
 
void SetCanvas (TCanvas *c)
 Set the canvas to be painted on.
 
void SetGeometry (GeometrySimple *geo)
 Set the geometry to be drawn.
 
void Plot ()
 Draw the geometry.
 
void EnableDebugging (const bool on=true)
 Enable/disable debugging messages.
 

Detailed Description

Visualize a geometry defined using the "native" shapes.

Definition at line 15 of file ViewGeometry.hh.

Constructor & Destructor Documentation

◆ ViewGeometry()

Garfield::ViewGeometry::ViewGeometry ( )

Constructor.

Definition at line 13 of file ViewGeometry.cc.

14 : m_className("ViewGeometry"),
15 m_debug(false),
16 m_canvas(NULL),
17 m_hasExternalCanvas(false),
18 m_geometry(NULL),
19 m_geoManager(NULL) {
20
22}
PlottingEngineRoot plottingEngine

◆ ~ViewGeometry()

Garfield::ViewGeometry::~ViewGeometry ( )

Destructor.

Definition at line 24 of file ViewGeometry.cc.

24 {
25
26 if (!m_hasExternalCanvas && m_canvas) delete m_canvas;
27 Reset();
28}

Member Function Documentation

◆ EnableDebugging()

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

Enable/disable debugging messages.

Definition at line 31 of file ViewGeometry.hh.

31{ m_debug = on; }

◆ Plot()

void Garfield::ViewGeometry::Plot ( )

Draw the geometry.

Definition at line 51 of file ViewGeometry.cc.

51 {
52
53 if (!m_geometry) {
54 std::cerr << m_className << "::Plot: Geometry is not defined.\n";
55 return;
56 }
57
58 if (!m_canvas) {
59 m_canvas = new TCanvas();
60 if (m_hasExternalCanvas) m_hasExternalCanvas = false;
61 }
62 m_canvas->cd();
63
64 const unsigned int nSolids = m_geometry->GetNumberOfSolids();
65 if (nSolids == 0) {
66 std::cerr << m_className << "::Plot: Geometry is empty.\n";
67 return;
68 }
69
70 // Get the bounding box.
71 double xMin = 0., yMin = 0., zMin = 0.;
72 double xMax = 0., yMax = 0., zMax = 0.;
73 if (!m_geometry->GetBoundingBox(xMin, yMin, zMin, xMax, yMax, zMax)) {
74 std::cerr << m_className << "::Plot: Cannot retrieve bounding box.\n";
75 return;
76 }
77 m_geoManager = new TGeoManager("ViewGeometryGeoManager", "");
78 TGeoMaterial* matVacuum = new TGeoMaterial("Vacuum", 0., 0., 0.);
79 TGeoMedium* medVacuum = new TGeoMedium("Vacuum", 1, matVacuum);
80 m_media.push_back(medVacuum);
81 // Use silicon as "default" material.
82 TGeoMaterial* matDefault = new TGeoMaterial("Default", 28.085, 14., 2.329);
83 TGeoMedium* medDefault = new TGeoMedium("Default", 1, matDefault);
84 TGeoVolume* world = m_geoManager->MakeBox("World", medVacuum,
85 std::max(fabs(xMin), fabs(xMax)),
86 std::max(fabs(yMin), fabs(yMax)),
87 std::max(fabs(zMin), fabs(zMax)));
88 m_geoManager->SetTopVolume(world);
89 m_volumes.push_back(world);
90
91 for (unsigned int i = 0; i < nSolids; ++i) {
92 Solid* solid = m_geometry->GetSolid(i);
93 if (!solid) {
94 std::cerr << m_className << "::Plot:\n"
95 << " Could not get solid " << i << " from geometry.\n";
96 continue;
97 }
98 // Get the center coordinates.
99 double x0 = 0., y0 = 0., z0 = 0.;
100 if (!solid->GetCenter(x0, y0, z0)) {
101 std::cerr << m_className << "::Plot:\n"
102 << " Could not determine solid center.\n";
103 continue;
104 }
105 // Get the rotation.
106 double ctheta = 1., stheta = 0.;
107 double cphi = 1., sphi = 0.;
108 if (!solid->GetOrientation(ctheta, stheta, cphi, sphi)) {
109 std::cerr << m_className << "::Plot:\n"
110 << " Could not determine solid orientation.\n";
111 continue;
112 }
113 double matrix[9] = {cphi * ctheta, -sphi, cphi * stheta,
114 sphi * ctheta, cphi, sphi * stheta,
115 -stheta, 0, ctheta};
116 TGeoVolume* volume = NULL;
117 if (solid->IsTube()) {
118 double rmin = 0., rmax = 0., lz = 0.;
119 if (!solid->GetDimensions(rmin, rmax, lz)) {
120 std::cerr << m_className << "::Plot:\n"
121 << " Could not determine tube dimensions.\n";
122 continue;
123 }
124 volume = m_geoManager->MakeTube("Tube", medDefault, rmin, rmax, lz);
125 } else if (solid->IsBox()) {
126 double dx = 0., dy = 0., dz = 0.;
127 if (!solid->GetDimensions(dx, dy, dz)) {
128 std::cerr << m_className << "::Plot:\n"
129 << " Could not determine box dimensions.\n";
130 continue;
131 }
132 volume = m_geoManager->MakeBox("Box", medDefault, dx, dy, dz);
133 } else if (solid->IsSphere()) {
134 double rmin = 0., rmax = 0., dummy = 0.;
135 if (!solid->GetDimensions(rmin, rmax, dummy)) {
136 std::cerr << m_className << "::Plot:\n"
137 << " Could not determine sphere dimensions.\n";
138 continue;
139 }
140 volume = m_geoManager->MakeSphere("Sphere", medDefault, rmin, rmax);
141 } else {
142 std::cerr << m_className << "::Plot: Unknown type of solid.\n";
143 continue;
144 }
145 Medium* medium = m_geometry->GetMedium(x0, y0, z0);
146 if (!medium) {
147 volume->SetLineColor(kGreen + 2);
148 volume->SetTransparency(50);
149 } else if (medium->IsGas()) {
150 volume->SetLineColor(kBlue + medium->GetId());
151 volume->SetTransparency(50);
152 } else if (medium->IsSemiconductor()) {
153 volume->SetLineColor(kRed + medium->GetId());
154 volume->SetTransparency(50);
155 } else {
156 volume->SetLineColor(kViolet + medium->GetId());
157 volume->SetTransparency(0);
158 }
159 TGeoRotation r;
160 r.SetMatrix(matrix);
161 TGeoTranslation t(x0, y0, z0);
162 TGeoCombiTrans* transform = new TGeoCombiTrans(t, r);
163 m_volumes.push_back(volume);
164 m_geoManager->GetTopVolume()->AddNode(volume, 1, transform);
165 }
166 m_geoManager->CloseGeometry();
167 m_geoManager->GetTopNode()->Draw("ogl");
168
169}
unsigned int GetNumberOfSolids() const
Medium * GetMedium(const double x, const double y, const double z) const
Solid * GetSolid(const double x, const double y, const double z) const
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:615

◆ SetCanvas()

void Garfield::ViewGeometry::SetCanvas ( TCanvas *  c)

Set the canvas to be painted on.

Definition at line 40 of file ViewGeometry.cc.

40 {
41
42 if (!c) return;
43 if (!m_hasExternalCanvas && m_canvas) {
44 delete m_canvas;
45 m_canvas = NULL;
46 }
47 m_canvas = c;
48 m_hasExternalCanvas = true;
49}

◆ SetGeometry()

void Garfield::ViewGeometry::SetGeometry ( GeometrySimple geo)

Set the geometry to be drawn.

Definition at line 30 of file ViewGeometry.cc.

30 {
31
32 if (!geo) {
33 std::cerr << m_className << "::SetGeometry: Null pointer.\n";
34 return;
35 }
36
37 m_geometry = geo;
38}

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