14 : m_className(
"ViewGeometry"),
17 m_hasExternalCanvas(false),
26 if (!m_hasExternalCanvas && m_canvas != NULL)
delete m_canvas;
33 std::cerr << m_className <<
"::SetGeometry:\n";
34 std::cerr <<
" Geometry pointer is null.\n";
43 if (c == NULL)
return;
44 if (!m_hasExternalCanvas && m_canvas != NULL) {
49 m_hasExternalCanvas =
true;
54 if (m_geometry == NULL) {
55 std::cerr << m_className <<
"::Plot:\n";
56 std::cerr <<
" Geometry is not defined.\n";
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;
69 std::cerr << m_className <<
"::Plot:\n";
70 std::cerr <<
" Geometry is empty.\n";
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";
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);
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);
96 for (
unsigned int i = 0; i < nSolids; ++i) {
99 std::cerr << m_className <<
"::Plot:\n";
100 std::cerr <<
" Could not get solid " << i <<
" from geometry.\n";
104 double x0 = 0., y0 = 0., z0 = 0.;
106 std::cerr << m_className <<
"::Plot:\n";
107 std::cerr <<
" Could not determine solid center.\n";
111 double ctheta = 1., stheta = 0.;
112 double cphi = 1., sphi = 0.;
114 std::cerr << m_className <<
"::Plot:\n";
115 std::cerr <<
" Could not determine solid orientation.\n";
118 double matrix[9] = {cphi * ctheta, -sphi, cphi * stheta,
119 sphi * ctheta, cphi, sphi * stheta,
121 TGeoVolume* volume = NULL;
123 double rmin = 0., rmax = 0., lz = 0.;
125 std::cerr << m_className <<
"::Plot:\n";
126 std::cerr <<
" Could not determine tube dimensions.\n";
129 volume = m_geoManager->MakeTube(
"Tube", medDefault, rmin, rmax, lz);
130 }
else if (solid->
IsBox()) {
131 double dx = 0., dy = 0., dz = 0.;
133 std::cerr << m_className <<
"::Plot:\n";
134 std::cerr <<
" Could not determine box dimensions.\n";
137 volume = m_geoManager->MakeBox(
"Box", medDefault, dx, dy, dz);
139 double rmin = 0., rmax = 0., dummy = 0.;
141 std::cerr << m_className <<
"::Plot:\n";
142 std::cerr <<
" Could not determine sphere dimensions.\n";
145 volume = m_geoManager->MakeSphere(
"Sphere", medDefault, rmin, rmax);
147 std::cerr << m_className <<
"::Plot:\n";
148 std::cerr <<
" Unknown solid type.\n";
152 if (medium == NULL) {
153 volume->SetLineColor(kGreen + 2);
154 volume->SetTransparency(50);
155 }
else if (medium->
IsGas()) {
156 volume->SetLineColor(kBlue + medium->
GetId());
157 volume->SetTransparency(50);
159 volume->SetLineColor(kRed + medium->
GetId());
160 volume->SetTransparency(50);
162 volume->SetLineColor(kViolet + medium->
GetId());
163 volume->SetTransparency(0);
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);
172 m_geoManager->CloseGeometry();
173 m_geoManager->GetTopNode()->Draw(
"ogl");
177void ViewGeometry::Reset() {
179 for (std::vector<TGeoVolume*>::iterator it = m_volumes.begin();
180 it != m_volumes.end(); ++it) {
182 TGeoShape* shape = (*it)->GetShape();
183 if (shape)
delete shape;
188 for (std::vector<TGeoMedium*>::iterator it = m_media.begin();
189 it != m_media.end(); ++it) {
191 TGeoMaterial* material = (*it)->GetMaterial();
192 if (material)
delete material;
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
virtual bool IsTube() const
virtual bool IsBox() const
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
void SetCanvas(TCanvas *c)
void SetGeometry(GeometrySimple *geo)
PlottingEngineRoot plottingEngine