Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SurfaceView3DBase.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SurfaceView3DBase.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
30 
31 #include <fstream>
32 #include <sstream>
33 #include <string>
34 
35 namespace Acts {
36 
37 namespace SurfaceView3DTest {
38 
46 static inline std::string run(IVisualization3D& helper, bool triangulate,
47  const std::string& tag) {
48  auto gctx = GeometryContext();
49  auto identity = Transform3::Identity();
50  std::stringstream cStream;
51 
52  double halfPhiSector = M_PI / 4.;
53  double centralPhi = M_PI / 2.;
54 
55  ViewConfig sConfig = s_viewSensitive;
56  sConfig.triangulate = triangulate;
57 
58  //----------------------------------------------------
59  // Cone Surface section
60  std::vector<std::shared_ptr<ConeSurface>> coneSurfaces;
61 
62  double coneAlpha = 0.245;
63  double coneMinZ = 0.;
64  double coneCutZ = 2.;
65  double coneMaxZ = 10.;
66  // Full Cone
67  auto coneBounds =
68  std::make_shared<ConeBounds>(coneAlpha, -coneCutZ, coneMaxZ);
69  auto cone = Surface::makeShared<ConeSurface>(identity, coneBounds);
70  coneSurfaces.push_back(cone);
71  GeometryView3D::drawSurface(helper, *cone, gctx, Transform3::Identity(),
72  sConfig);
73  ;
74  helper.write(std::string("Surfaces_ConeSurface") + tag);
75  helper.write(cStream);
76  helper.clear();
77 
78  // Sectoral Cone
79  coneBounds = std::make_shared<ConeBounds>(coneAlpha, coneMinZ, coneMaxZ,
80  halfPhiSector);
81  cone = Surface::makeShared<ConeSurface>(identity, coneBounds);
82  coneSurfaces.push_back(cone);
83  GeometryView3D::drawSurface(helper, *cone, gctx, Transform3::Identity(),
84  sConfig);
85  ;
86  helper.write(std::string("Surfaces_ConeSurfaceSector") + tag);
87  helper.write(cStream);
88  helper.clear();
89 
90  // Sectoral Cone Shifted
91  coneBounds = std::make_shared<ConeBounds>(coneAlpha, coneCutZ, coneMaxZ,
92  halfPhiSector, centralPhi);
93  cone = Surface::makeShared<ConeSurface>(identity, coneBounds);
94  coneSurfaces.push_back(cone);
95  GeometryView3D::drawSurface(helper, *cone, gctx, Transform3::Identity(),
96  sConfig);
97  ;
98  helper.write(std::string("Surfaces_ConeSurfaceSectorShifted") + tag);
99  helper.write(cStream);
100  helper.clear();
101 
102  // All in one for radial bounds
103  std::vector<Transform3> threeCones = {
104  Transform3(Translation3{-0.5 * coneMaxZ, 0., 0.}),
105  Transform3(Translation3{0., 0., 0.}),
106  Transform3(Translation3{0.75 * coneMaxZ, 0., 0.})};
107 
108  for (size_t ic = 0; ic < coneSurfaces.size(); ++ic) {
109  GeometryView3D::drawSurface(helper, *coneSurfaces[ic], gctx, threeCones[ic],
110  sConfig);
111  }
112  helper.write(std::string("Surfaces_All_ConeSurfaces") + tag);
113  helper.write(cStream);
114  helper.clear();
115 
116  //----------------------------------------------------
117  // Cylinder surface section
118  std::vector<std::shared_ptr<CylinderSurface>> cylinderSurfaces;
119 
120  double cylinderRadius = 5.;
121  double cylinderHalfZ = 10.;
122 
123  // Full Cylinder
124  auto cylinderBounds =
125  std::make_shared<CylinderBounds>(cylinderRadius, cylinderHalfZ);
126  auto cylinder =
127  Surface::makeShared<CylinderSurface>(identity, cylinderBounds);
128  cylinderSurfaces.push_back(cylinder);
129  GeometryView3D::drawSurface(helper, *cylinder, gctx, Transform3::Identity(),
130  sConfig);
131  ;
132  helper.write(std::string("Surfaces_CylinderSurface") + tag);
133  helper.write(cStream);
134  helper.clear();
135 
136  // Sectoral Cone
137  cylinderBounds = std::make_shared<CylinderBounds>(
138  cylinderRadius, cylinderHalfZ, halfPhiSector);
139  cylinder = Surface::makeShared<CylinderSurface>(identity, cylinderBounds);
140  cylinderSurfaces.push_back(cylinder);
141  GeometryView3D::drawSurface(helper, *cylinder, gctx, Transform3::Identity(),
142  sConfig);
143  ;
144  helper.write(std::string("Surfaces_CylinderSurfaceSector") + tag);
145  helper.write(cStream);
146  helper.clear();
147 
148  // Sectoral Cone Shifted
149  cylinderBounds = std::make_shared<CylinderBounds>(
150  cylinderRadius, cylinderHalfZ, halfPhiSector, centralPhi);
151  cylinder = Surface::makeShared<CylinderSurface>(identity, cylinderBounds);
152  cylinderSurfaces.push_back(cylinder);
153  GeometryView3D::drawSurface(helper, *cylinder, gctx, Transform3::Identity(),
154  sConfig);
155  ;
156  helper.write(std::string("Surfaces_CylinderSurfaceSectorShifted") + tag);
157  helper.write(cStream);
158  helper.clear();
159 
160  // All in one for radial bounds
161  std::vector<Transform3> threeCylinders = {
162  Transform3(Translation3{-2 * cylinderRadius, 0., 0.}),
163  Transform3(Translation3{0., 0., 0.}),
164  Transform3(Translation3{2.5 * cylinderRadius, 0., 0.})};
165 
166  for (size_t ic = 0; ic < cylinderSurfaces.size(); ++ic) {
167  GeometryView3D::drawSurface(helper, *cylinderSurfaces[ic], gctx,
168  threeCylinders[ic], sConfig);
169  }
170  helper.write(std::string("Surfaces_All_CylinderSurfaces") + tag);
171  helper.write(cStream);
172  helper.clear();
173 
176  auto writeBoundingBox2D = [&](const RectangleBounds& rBounds,
177  const std::string& path) -> void {
178  std::string bbPath = path + tag + "_bbox";
179 
180  auto bbBounds = std::make_shared<RectangleBounds>(rBounds);
181  auto bbSurface = Surface::makeShared<PlaneSurface>(identity, bbBounds);
182  GeometryView3D::drawSurface(helper, *bbSurface, gctx,
183  Transform3::Identity(), sConfig);
184  ;
185  helper.write(bbPath);
186  helper.write(cStream);
187  helper.clear();
188  };
189 
190  //----------------------------------------------------
191  // Disc Surface section
192 
193  double discRmin = 5.;
194  double discRmax = 10.;
195 
196  std::vector<std::shared_ptr<DiscSurface>> radialSurfaces;
197 
198  // Full Disc
199  auto radialBounds = std::make_shared<RadialBounds>(0., discRmax);
200  auto disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
201  radialSurfaces.push_back(disc);
202  GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
203  sConfig);
204  ;
205  helper.write(std::string("Surfaces_DiscSurfaceFull") + tag);
206  helper.write(cStream);
207  helper.clear();
208 
209  // Full Sectoral Disc
210  radialBounds = std::make_shared<RadialBounds>(0., discRmax, halfPhiSector);
211  disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
212  radialSurfaces.push_back(disc);
213  GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
214  sConfig);
215 
216  helper.write(std::string("Surfaces_DiscSurfaceFullSector") + tag);
217  helper.write(cStream);
218  helper.clear();
219 
220  // Full Sectoral Shifted Disc
221  radialBounds =
222  std::make_shared<RadialBounds>(0., discRmax, halfPhiSector, centralPhi);
223  disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
224  radialSurfaces.push_back(disc);
225  GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
226  sConfig);
227 
228  helper.write(std::string("Surfaces_DiscSurfaceFullSectorShifted") + tag);
229  helper.write(cStream);
230  helper.clear();
231 
232  // Full Ring
233  radialBounds = std::make_shared<RadialBounds>(discRmin, discRmax);
234  disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
235  radialSurfaces.push_back(disc);
236  GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
237  sConfig);
238 
239  helper.write(std::string("Surfaces_DiscSurfaceRing") + tag);
240  helper.write(cStream);
241  helper.clear();
242 
243  // Full Sectoral Rin g
244  radialBounds =
245  std::make_shared<RadialBounds>(discRmin, discRmax, halfPhiSector);
246  disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
247  radialSurfaces.push_back(disc);
248  GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
249  sConfig);
250 
251  helper.write(std::string("Surfaces_DiscSurfaceRingSector") + tag);
252  helper.write(cStream);
253  helper.clear();
254 
255  // Full Sectoral Shifted Ring
256  radialBounds = std::make_shared<RadialBounds>(discRmin, discRmax,
257  halfPhiSector, centralPhi);
258  disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
259  radialSurfaces.push_back(disc);
260  GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
261  sConfig);
262 
263  helper.write(std::string("Surfaces_DiscSurfaceRingSectorShifted") + tag);
264  helper.write(cStream);
265  helper.clear();
266 
267  // All in one for radial bounds
268  std::vector<Transform3> sixDiscs = {
269  Transform3(Translation3{-2.0 * discRmax, 1.5 * discRmax, 0.}),
270  Transform3(Translation3{0., 1.5 * discRmax, 0.}),
271  Transform3(Translation3{2.5 * discRmax, 1.5 * discRmax, 0.}),
272  Transform3(Translation3{-2.0 * discRmax, -1.5 * discRmax, 0.}),
273  Transform3(Translation3{0., -1.5 * discRmax, 0.}),
274  Transform3(Translation3{2.5 * discRmax, -1.5 * discRmax, 0.})};
275  for (size_t ir = 0; ir < radialSurfaces.size(); ++ir) {
276  GeometryView3D::drawSurface(helper, *radialSurfaces[ir], gctx, sixDiscs[ir],
277  sConfig);
278  }
279  helper.write(std::string("Surfaces_All_DiscSurfaces_RadialBounds") + tag);
280  helper.write(cStream);
281  helper.clear();
282 
283  std::vector<std::shared_ptr<DiscSurface>> anomalDiscSurfaces;
284 
285  double annulusMinPhi = 0.75;
286  double annulusMaxPhi = 1.35;
287  Vector2 offset(-4., 2.);
288  auto annulus = std::make_shared<AnnulusBounds>(
289  discRmin, discRmax, annulusMinPhi, annulusMaxPhi, offset);
290  disc = Surface::makeShared<DiscSurface>(identity, annulus);
291  anomalDiscSurfaces.push_back(disc);
292  GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
293  sConfig);
294 
295  helper.write(std::string("Surfaces_DiscAnnulusBounds") + tag);
296  helper.write(cStream);
297  helper.clear();
298 
299  double discTrapezoidHxRmin = 3.;
300  double discTrapezoidHxRmax = 6.;
301  auto discTrapezoid = std::make_shared<DiscTrapezoidBounds>(
302  discTrapezoidHxRmin, discTrapezoidHxRmax, discRmin, discRmax);
303  disc = Surface::makeShared<DiscSurface>(identity, discTrapezoid);
304  anomalDiscSurfaces.push_back(disc);
305  GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
306  sConfig);
307 
308  helper.write(std::string("Surfaces_DiscTrapezoidBounds") + tag);
309  helper.write(cStream);
310  helper.clear();
311 
312  // All in one for radial bounds
313  std::vector<Transform3> twoAnomalDiscs = {
314  Transform3(Translation3{-5., 0., 0.}),
315  Transform3(Translation3{5., 0., 0.})};
316  for (size_t id = 0; id < anomalDiscSurfaces.size(); ++id) {
317  GeometryView3D::drawSurface(helper, *anomalDiscSurfaces[id], gctx,
318  sixDiscs[id], sConfig);
319  }
320  helper.write(std::string("Surfaces_All_DiscSurfaces_AnomalBounds") + tag);
321  helper.write(cStream);
322  helper.clear();
323 
324  //----------------------------------------------------
325  // Plane Surface section
326  std::vector<std::shared_ptr<PlaneSurface>> planarSurfaces;
327 
328  // Ellipse shaped : Full Ellipse
329  double ellipseR0min = 2;
330  double ellipseR0max = 4;
331  double ellipseR1min = 3;
332  double ellipseR1max = 6;
333  std::string name = "Surfaces_PlaneSurfaceEllipse";
334  auto ellipse =
335  std::make_shared<EllipseBounds>(0., 0., ellipseR1min, ellipseR1max);
336  auto plane = Surface::makeShared<PlaneSurface>(identity, ellipse);
337  planarSurfaces.push_back(plane);
338  GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
339  sConfig);
340  ;
341  helper.write(name + tag);
342  helper.write(cStream);
343  helper.clear();
344  writeBoundingBox2D(ellipse->boundingBox(), name);
345 
346  // Ellipse shaped : Ring Ellipse
347  name = "Surfaces_PlaneSurfaceEllipseRing";
348  ellipse = std::make_shared<EllipseBounds>(ellipseR0min, ellipseR0max,
349  ellipseR1min, ellipseR1max);
350  plane = Surface::makeShared<PlaneSurface>(identity, ellipse);
351  planarSurfaces.push_back(plane);
352  GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
353  sConfig);
354  ;
355  helper.write(name + tag);
356  helper.write(cStream);
357  helper.clear();
358  writeBoundingBox2D(ellipse->boundingBox(), name);
359 
360  // Ellipse shaped : Ring Ellipse Sector
361  name = "Surfaces_PlaneSurfaceEllipseRingSector";
362  ellipse = std::make_shared<EllipseBounds>(
363  ellipseR0min, ellipseR0max, ellipseR1min, ellipseR1max, halfPhiSector);
364  plane = Surface::makeShared<PlaneSurface>(identity, ellipse);
365  planarSurfaces.push_back(plane);
366  GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
367  sConfig);
368  ;
369  helper.write(name + tag);
370  helper.write(cStream);
371  helper.clear();
372  writeBoundingBox2D(ellipse->boundingBox(), name);
373 
374  // ConvexPolygon shaped example: Triangle
375  name = "Surfaces_PlaneSurfaceTriangleRegular";
376  std::vector<Vector2> tvertices = {{-3, -1.5}, {3, -1.5}, {0, 4.5}};
377  auto triangle = std::make_shared<ConvexPolygonBounds<3>>(tvertices);
378  plane = Surface::makeShared<PlaneSurface>(identity, triangle);
379  planarSurfaces.push_back(plane);
380  GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
381  sConfig);
382  ;
383  helper.write(name + tag);
384  helper.write(cStream);
385  helper.clear();
386  writeBoundingBox2D(triangle->boundingBox(), name);
387 
388  // ConvexPolygon shaped example: Triangle
389  name = "Surfaces_PlaneSurfaceTriangleGeneral";
390  tvertices = {{-1., 4.5}, {4, 6.5}, {3, 8.5}};
391  triangle = std::make_shared<ConvexPolygonBounds<3>>(tvertices);
392  plane = Surface::makeShared<PlaneSurface>(identity, triangle);
393  planarSurfaces.push_back(plane);
394  GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
395  sConfig);
396 
397  helper.write(name + tag);
398  helper.write(cStream);
399  helper.clear();
400  writeBoundingBox2D(triangle->boundingBox(), name);
401 
402  // ConvexPolygon shaped example: Triangle
403  name = "Surfaces_PlaneSurfaceConvexPolygonGeneral";
404  tvertices = {{-1., 4.5}, {4, 6.5}, {6, 8.5}, {0, 10.5}, {-3, 6.2}};
405  auto dynamicpolygon =
406  std::make_shared<ConvexPolygonBounds<PolygonDynamic>>(tvertices);
407  plane = Surface::makeShared<PlaneSurface>(identity, dynamicpolygon);
408  planarSurfaces.push_back(plane);
409  GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
410  sConfig);
411 
412  helper.write(name + tag);
413  helper.write(cStream);
414  helper.clear();
415  writeBoundingBox2D(dynamicpolygon->boundingBox(), name);
416 
417  // Diamond shaped
418  name = "Surfaces_PlaneSurfaceDiamond";
419  auto diamond = std::make_shared<DiamondBounds>(3., 6., 2., 2., 4.);
420  plane = Surface::makeShared<PlaneSurface>(identity, diamond);
421  planarSurfaces.push_back(plane);
422  GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
423  sConfig);
424 
425  helper.write(name + tag);
426  helper.write(cStream);
427  helper.clear();
428  writeBoundingBox2D(diamond->boundingBox(), name);
429 
430  // Rectangle plane
431  name = "Surfaces_PlaneSurfaceRectangle";
432  auto rectangle = std::make_shared<RectangleBounds>(2., 3.);
433  plane = Surface::makeShared<PlaneSurface>(identity, rectangle);
434  planarSurfaces.push_back(plane);
435  GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
436  sConfig);
437 
438  helper.write(name + tag);
439  helper.write(cStream);
440  helper.clear();
441  writeBoundingBox2D(rectangle->boundingBox(), name);
442 
443  // Off-centered Rectangle plane:
444  name = "Surfaces_PlaneSurfaceRectangleOffcentered";
445  rectangle =
446  std::make_shared<RectangleBounds>(Vector2{1., 2.}, Vector2{15., 12.});
447  plane = Surface::makeShared<PlaneSurface>(identity, rectangle);
448  GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
449  sConfig);
450 
451  helper.write(name + tag);
452  helper.write(cStream);
453  helper.clear();
454  writeBoundingBox2D(rectangle->boundingBox(), name);
455 
456  // Trapezoidal plane:
457  name = "Surfaces_PlaneSurfaceTrapezoid";
458  auto trapezoid = std::make_shared<TrapezoidBounds>(2., 5., 3.);
459  plane = Surface::makeShared<PlaneSurface>(identity, trapezoid);
460  planarSurfaces.push_back(plane);
461  GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
462  sConfig);
463 
464  helper.write(name + tag);
465  helper.write(cStream);
466  helper.clear();
467  writeBoundingBox2D(trapezoid->boundingBox(), name);
468 
469  // All planes
470  std::vector<Transform3> ninePlanes = {
471  Transform3(Translation3{-10., -10., 0.}),
472  Transform3(Translation3{0., -10., 0.}),
473  Transform3(Translation3{10., -10., 0.}),
474  Transform3(Translation3{-10., 0., 0.}),
475  Transform3(Translation3{0., -6., 0.}),
476  Transform3(Translation3{10., -8., 0.}),
477  Transform3(Translation3{-10, 10., 0.}),
478  Transform3(Translation3{0., 10., 0.}),
479  Transform3(Translation3{10., 10., 0.})};
480  for (size_t ip = 0; ip < planarSurfaces.size(); ++ip) {
481  GeometryView3D::drawSurface(helper, *planarSurfaces[ip], gctx,
482  ninePlanes[ip], sConfig);
483  }
484  helper.write(std::string("Surfaces_All_PlaneSurfaces") + tag);
485  helper.write(cStream);
486  helper.clear();
487 
488  //----------------------------------------------------
489  // Straw Surface section
490  name = "Surfaces_StrawSurface";
491  auto tube = std::make_shared<LineBounds>(2., 20.);
492  auto straw = Surface::makeShared<StrawSurface>(identity, tube);
493  GeometryView3D::drawSurface(helper, *straw, gctx, Transform3::Identity(),
494  sConfig);
495 
496  helper.write(name + tag);
497  helper.write(cStream);
498  helper.clear();
499 
500  return cStream.str();
501 }
502 
503 } // namespace SurfaceView3DTest
504 } // namespace Acts