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::ViewGeometry Class Reference

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

#include <ViewGeometry.hh>

+ Inheritance diagram for Garfield::ViewGeometry:

Public Member Functions

 ViewGeometry ()
 Constructor.
 
 ~ViewGeometry ()
 Destructor.
 
void SetGeometry (GeometrySimple *geo)
 Set the geometry to be drawn.
 
void Plot ()
 Draw the geometry.
 
- Public Member Functions inherited from Garfield::ViewBase
 ViewBase ()=delete
 Default constructor.
 
 ViewBase (const std::string &name)
 Constructor.
 
virtual ~ViewBase ()
 Destructor.
 
void SetCanvas (TCanvas *c)
 Set the canvas to be painted on.
 
TCanvas * GetCanvas ()
 Retrieve the canvas.
 
void EnableDebugging (const bool on=true)
 Switch on/off debugging output.
 

Additional Inherited Members

- Protected Member Functions inherited from Garfield::ViewBase
std::string FindUnusedFunctionName (const std::string &s) const
 
std::string FindUnusedHistogramName (const std::string &s) const
 
- Protected Attributes inherited from Garfield::ViewBase
std::string m_className = "ViewBase"
 
bool m_debug = false
 
TCanvas * m_canvas = nullptr
 
bool m_hasExternalCanvas = false
 
double m_proj [3][3]
 

Detailed Description

Visualize a geometry defined using the "native" shapes.

Definition at line 18 of file ViewGeometry.hh.

Constructor & Destructor Documentation

◆ ViewGeometry()

Garfield::ViewGeometry::ViewGeometry ( )

Constructor.

Definition at line 19 of file ViewGeometry.cc.

19 : ViewBase("ViewGeometry") {
21}
void SetDefaultStyle()
Apply the default Garfield ROOT style.
ViewBase()=delete
Default constructor.
PlottingEngineRoot plottingEngine

◆ ~ViewGeometry()

Garfield::ViewGeometry::~ViewGeometry ( )

Destructor.

Definition at line 23 of file ViewGeometry.cc.

23 {
24 Reset();
25}

Member Function Documentation

◆ Plot()

void Garfield::ViewGeometry::Plot ( )

Draw the geometry.

Definition at line 36 of file ViewGeometry.cc.

36 {
37 if (!m_geometry) {
38 std::cerr << m_className << "::Plot: Geometry is not defined.\n";
39 return;
40 }
41
42 if (!m_canvas) {
43 m_canvas = new TCanvas();
45 }
46 m_canvas->cd();
47
48 const unsigned int nSolids = m_geometry->GetNumberOfSolids();
49 if (nSolids == 0) {
50 std::cerr << m_className << "::Plot: Geometry is empty.\n";
51 return;
52 }
53
54 // Get the bounding box.
55 double xMin = 0., yMin = 0., zMin = 0.;
56 double xMax = 0., yMax = 0., zMax = 0.;
57 if (!m_geometry->GetBoundingBox(xMin, yMin, zMin, xMax, yMax, zMax)) {
58 std::cerr << m_className << "::Plot: Cannot retrieve bounding box.\n";
59 return;
60 }
61 gGeoManager = nullptr;
62 m_geoManager.reset(new TGeoManager("ViewGeometryGeoManager", ""));
63 TGeoMaterial* matVacuum = new TGeoMaterial("Vacuum", 0., 0., 0.);
64 TGeoMedium* medVacuum = new TGeoMedium("Vacuum", 1, matVacuum);
65 m_media.push_back(medVacuum);
66 // Use silicon as "default" material.
67 TGeoMaterial* matDefault = new TGeoMaterial("Default", 28.085, 14., 2.329);
68 TGeoMedium* medDefault = new TGeoMedium("Default", 1, matDefault);
69 TGeoVolume* world = m_geoManager->MakeBox(
70 "World", medVacuum, std::max(fabs(xMin), fabs(xMax)),
71 std::max(fabs(yMin), fabs(yMax)), std::max(fabs(zMin), fabs(zMax)));
72 m_geoManager->SetTopVolume(world);
73 m_volumes.push_back(world);
74
75 for (unsigned int i = 0; i < nSolids; ++i) {
76 Solid* solid = m_geometry->GetSolid(i);
77 if (!solid) {
78 std::cerr << m_className << "::Plot:\n"
79 << " Could not get solid " << i << " from geometry.\n";
80 continue;
81 }
82 // Get the center coordinates.
83 double x0 = 0., y0 = 0., z0 = 0.;
84 if (!solid->GetCentre(x0, y0, z0)) {
85 std::cerr << m_className << "::Plot: Could not determine solid centre.\n";
86 continue;
87 }
88 // Get the rotation.
89 double ctheta = 1., stheta = 0.;
90 double cphi = 1., sphi = 0.;
91 if (!solid->GetOrientation(ctheta, stheta, cphi, sphi)) {
92 std::cerr << m_className << "::Plot:\n"
93 << " Could not determine solid orientation.\n";
94 continue;
95 }
96 double matrix[9] = {cphi * ctheta, -sphi, cphi * stheta,
97 sphi * ctheta, cphi, sphi * stheta,
98 -stheta, 0, ctheta};
99 TGeoVolume* volume = nullptr;
100 if (solid->IsTube()) {
101 const double rmin = solid->GetInnerRadius();
102 const double rmax = solid->GetOuterRadius();
103 const double lz = solid->GetHalfLengthZ();
104 volume = m_geoManager->MakeTube("Tube", medDefault, rmin, rmax, lz);
105 } else if (solid->IsBox()) {
106 const double dx = solid->GetHalfLengthX();
107 const double dy = solid->GetHalfLengthY();
108 const double dz = solid->GetHalfLengthZ();
109 volume = m_geoManager->MakeBox("Box", medDefault, dx, dy, dz);
110 } else if (solid->IsSphere()) {
111 const double r = solid->GetRadius();
112 volume = m_geoManager->MakeSphere("Sphere", medDefault, 0, r);
113 } else if (solid->IsHole()) {
114 const double r1 = solid->GetLowerRadius();
115 const double r2 = solid->GetUpperRadius();
116 const double rm = 0.5 * (r1 + r2);
117 const double dr = (r2 - r1);
118 const double dx = solid->GetHalfLengthX();
119 const double dy = solid->GetHalfLengthY();
120 const double dz = solid->GetHalfLengthZ();
121 TGeoBBox* box = new TGeoBBox("HoleBox", dx, dy, dz);
122 TGeoCone* cone = new TGeoCone("HoleCone", 2 * dz, 0, rm - dr, 0, rm + dr);
123 TGeoCompositeShape* hole = new TGeoCompositeShape("Hole",
124 new TGeoSubtraction(box, cone));
125 hole->RegisterYourself();
126 volume = new TGeoVolume("Hole", hole, medDefault);
127 } else if (solid->IsRidge()) {
128 const double dx = solid->GetHalfLengthX();
129 const double dy = solid->GetHalfLengthY();
130 const double dz = 0.5 * solid->GetRidgeHeight();
131 const double xr = solid->GetRidgeOffset();
132 volume = m_geoManager->MakeArb8("Ridge", medDefault, dz);
133 auto arb = (TGeoArb8*)volume->GetShape();
134 arb->SetVertex(0, -dx, -dy);
135 arb->SetVertex(1, -dx, +dy);
136 arb->SetVertex(2, +dx, +dy);
137 arb->SetVertex(3, +dx, -dy);
138 arb->SetVertex(4, xr, -dy);
139 arb->SetVertex(5, xr, +dy);
140 arb->SetVertex(6, xr, +dy);
141 arb->SetVertex(7, xr, -dy);
142 z0 += dz;
143 } else {
144 std::cerr << m_className << "::Plot: Unknown type of solid.\n";
145 continue;
146 }
147 Medium* medium = m_geometry->GetMedium(x0, y0, z0);
148 if (!medium) {
149 volume->SetLineColor(kGreen + 2);
150 volume->SetTransparency(50);
151 } else if (medium->IsGas()) {
152 volume->SetLineColor(kBlue + medium->GetId());
153 volume->SetTransparency(50);
154 } else if (medium->IsSemiconductor()) {
155 volume->SetLineColor(kRed + medium->GetId());
156 volume->SetTransparency(50);
157 } else {
158 volume->SetLineColor(kViolet + medium->GetId());
159 volume->SetTransparency(0);
160 }
161 TGeoRotation r;
162 r.SetMatrix(matrix);
163 TGeoTranslation t(x0, y0, z0);
164 TGeoCombiTrans* transform = new TGeoCombiTrans(t, r);
165 m_volumes.push_back(volume);
166 m_geoManager->GetTopVolume()->AddNode(volume, 1, transform);
167 }
168 m_geoManager->CloseGeometry();
169 m_geoManager->GetTopNode()->Draw("ogl");
170}
Solid * GetSolid(const unsigned int i) const override
Get a solid from the list.
unsigned int GetNumberOfSolids() const override
Return the number of solids in the geometry.
Medium * GetMedium(const double x, const double y, const double z) const override
Retrieve the medium at a given point.
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the bounding box (envelope of the geometry).
std::string m_className
Definition: ViewBase.hh:28
bool m_hasExternalCanvas
Definition: ViewBase.hh:35
TCanvas * m_canvas
Definition: ViewBase.hh:34
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:615

◆ SetGeometry()

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

Set the geometry to be drawn.

Definition at line 27 of file ViewGeometry.cc.

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

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