7#include <TGeoBoolNode.h>
8#include <TGeoCompositeShape.h>
29 std::cerr <<
m_className <<
"::SetGeometry: Null pointer.\n";
38 std::cerr <<
m_className <<
"::Plot: Geometry is not defined.\n";
50 std::cerr <<
m_className <<
"::Plot: Geometry is empty.\n";
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";
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);
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);
75 for (
unsigned int i = 0; i < nSolids; ++i) {
79 <<
" Could not get solid " << i <<
" from geometry.\n";
83 double x0 = 0., y0 = 0., z0 = 0.;
85 std::cerr <<
m_className <<
"::Plot: Could not determine solid centre.\n";
89 double ctheta = 1., stheta = 0.;
90 double cphi = 1., sphi = 0.;
93 <<
" Could not determine solid orientation.\n";
96 double matrix[9] = {cphi * ctheta, -sphi, cphi * stheta,
97 sphi * ctheta, cphi, sphi * stheta,
99 TGeoVolume* volume =
nullptr;
104 volume = m_geoManager->MakeTube(
"Tube", medDefault, rmin, rmax, lz);
105 }
else if (solid->
IsBox()) {
109 volume = m_geoManager->MakeBox(
"Box", medDefault, dx, dy, dz);
112 volume = m_geoManager->MakeSphere(
"Sphere", medDefault, 0, r);
113 }
else if (solid->
IsHole()) {
116 const double rm = 0.5 * (r1 + r2);
117 const double dr = (r2 - r1);
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);
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);
144 std::cerr <<
m_className <<
"::Plot: Unknown type of solid.\n";
149 volume->SetLineColor(kGreen + 2);
150 volume->SetTransparency(50);
151 }
else if (medium->
IsGas()) {
152 volume->SetLineColor(kBlue + medium->
GetId());
153 volume->SetTransparency(50);
155 volume->SetLineColor(kRed + medium->
GetId());
156 volume->SetTransparency(50);
158 volume->SetLineColor(kViolet + medium->
GetId());
159 volume->SetTransparency(0);
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);
168 m_geoManager->CloseGeometry();
169 m_geoManager->GetTopNode()->Draw(
"ogl");
172void ViewGeometry::Reset() {
173 for (
auto it = m_volumes.begin(), end = m_volumes.end(); it != end; ++it) {
175 TGeoShape* shape = (*it)->GetShape();
176 if (shape)
delete shape;
181 for (
auto it = m_media.begin(), end = m_media.end(); it != end; ++it) {
183 TGeoMaterial* material = (*it)->GetMaterial();
184 if (material)
delete material;
190 m_geoManager.reset(
nullptr);
"Native" geometry, using simple shapes.
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).
Abstract base class for media.
int GetId() const
Return the id number of the class instance.
virtual bool IsSemiconductor() const
Is this medium a semiconductor?
virtual bool IsGas() const
Is this medium a gas?
void SetDefaultStyle()
Apply the default Garfield ROOT style.
Abstract base class for solids.
virtual double GetUpperRadius() const
Return the upper radius (of a hole).
virtual bool IsTube() const
Return true if the solid is a tube.
virtual bool IsRidge() const
Return true if the solid is a ridge.
virtual double GetHalfLengthX() const
Return the half-length along x.
virtual bool IsHole() const
Return true if the solid is a hole.
virtual double GetHalfLengthZ() const
Return the half-length along z.
virtual bool IsBox() const
Return true if the solid is a box.
virtual double GetHalfLengthY() const
Return the half-length along y.
bool GetCentre(double &x, double &y, double &z) const
Retrieve the centre point of the solid.
virtual double GetRidgeOffset() const
Return the x-offset of a ridge.
virtual double GetLowerRadius() const
Return the lower radius (of a hole).
virtual double GetOuterRadius() const
Return the outer radius.
bool GetOrientation(double &ctheta, double &stheta, double &cphi, double &sphi) const
Retrieve the orientation (azimuthal and polar angles) of the solid.
virtual double GetRadius() const
Return the radius.
virtual bool IsSphere() const
Return true if the solid is a sphere.
virtual double GetInnerRadius() const
Return the inner radius.
virtual double GetRidgeHeight() const
Return the height of a ridge.
Base class for visualization classes.
void Plot()
Draw the geometry.
void SetGeometry(GeometrySimple *geo)
Set the geometry to be drawn.
~ViewGeometry()
Destructor.
ViewGeometry()
Constructor.
PlottingEngineRoot plottingEngine