Draw the geometry.
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
65 if (nSolids == 0) {
66 std::cerr << m_className << "::Plot: Geometry is empty.\n";
67 return;
68 }
69
70
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
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,
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
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
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)