14 : m_className(
"ViewGeometry"),
17 m_hasExternalCanvas(false),
26 if (!m_hasExternalCanvas && m_canvas)
delete m_canvas;
33 std::cerr << m_className <<
"::SetGeometry: Null pointer.\n";
43 if (!m_hasExternalCanvas && m_canvas) {
48 m_hasExternalCanvas =
true;
54 std::cerr << m_className <<
"::Plot: Geometry is not defined.\n";
59 m_canvas =
new TCanvas();
60 if (m_hasExternalCanvas) m_hasExternalCanvas =
false;
66 std::cerr << m_className <<
"::Plot: Geometry is empty.\n";
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";
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);
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);
91 for (
unsigned int i = 0; i < nSolids; ++i) {
94 std::cerr << m_className <<
"::Plot:\n"
95 <<
" Could not get solid " << i <<
" from geometry.\n";
99 double x0 = 0., y0 = 0., z0 = 0.;
101 std::cerr << m_className <<
"::Plot:\n"
102 <<
" Could not determine solid center.\n";
106 double ctheta = 1., stheta = 0.;
107 double cphi = 1., sphi = 0.;
109 std::cerr << m_className <<
"::Plot:\n"
110 <<
" Could not determine solid orientation.\n";
113 double matrix[9] = {cphi * ctheta, -sphi, cphi * stheta,
114 sphi * ctheta, cphi, sphi * stheta,
116 TGeoVolume* volume = NULL;
118 double rmin = 0., rmax = 0., lz = 0.;
120 std::cerr << m_className <<
"::Plot:\n"
121 <<
" Could not determine tube dimensions.\n";
124 volume = m_geoManager->MakeTube(
"Tube", medDefault, rmin, rmax, lz);
125 }
else if (solid->
IsBox()) {
126 double dx = 0., dy = 0., dz = 0.;
128 std::cerr << m_className <<
"::Plot:\n"
129 <<
" Could not determine box dimensions.\n";
132 volume = m_geoManager->MakeBox(
"Box", medDefault, dx, dy, dz);
134 double rmin = 0., rmax = 0., dummy = 0.;
136 std::cerr << m_className <<
"::Plot:\n"
137 <<
" Could not determine sphere dimensions.\n";
140 volume = m_geoManager->MakeSphere(
"Sphere", medDefault, rmin, rmax);
142 std::cerr << m_className <<
"::Plot: Unknown type of solid.\n";
147 volume->SetLineColor(kGreen + 2);
148 volume->SetTransparency(50);
149 }
else if (medium->
IsGas()) {
150 volume->SetLineColor(kBlue + medium->
GetId());
151 volume->SetTransparency(50);
153 volume->SetLineColor(kRed + medium->
GetId());
154 volume->SetTransparency(50);
156 volume->SetLineColor(kViolet + medium->
GetId());
157 volume->SetTransparency(0);
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);
166 m_geoManager->CloseGeometry();
167 m_geoManager->GetTopNode()->Draw(
"ogl");
171void ViewGeometry::Reset() {
173 for (std::vector<TGeoVolume*>::iterator it = m_volumes.begin();
174 it != m_volumes.end(); ++it) {
176 TGeoShape* shape = (*it)->GetShape();
177 if (shape)
delete shape;
182 for (std::vector<TGeoMedium*>::iterator it = m_media.begin();
183 it != m_media.end(); ++it) {
185 TGeoMaterial* material = (*it)->GetMaterial();
186 if (material)
delete material;
"Native" geometry, using simple shapes.
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)
Abstract base class for media.
virtual bool IsSemiconductor() const
virtual bool IsGas() const
Abstract base class for solids.
virtual bool IsTube() const
Return true if the solid is a tube.
virtual bool IsBox() const
Return true if the solid is a box.
virtual bool GetOrientation(double &ctheta, double &stheta, double &cphi, double &shpi) const =0
virtual bool GetCenter(double &x, double &y, double &z) const =0
virtual bool GetDimensions(double &l1, double &l2, double &l3) const =0
virtual bool IsSphere() const
Return true if the solid is a sphere.
void Plot()
Draw the geometry.
void SetCanvas(TCanvas *c)
Set the canvas to be painted on.
void SetGeometry(GeometrySimple *geo)
Set the geometry to be drawn.
~ViewGeometry()
Destructor.
ViewGeometry()
Constructor.
PlottingEngineRoot plottingEngine