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