LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
StandardDrawer_tool.cc
Go to the documentation of this file.
1 
7 
9 
10 #include "fhiclcpp/ParameterSet.h"
16 
17 #include "TPolyLine3D.h"
18 
19 #include <algorithm> // std::min()
20 #include <array>
21 #include <cmath> // std::abs()
22 
23 namespace evd_tool {
24 
26  public:
27  explicit StandardDrawer(const fhicl::ParameterSet& pset);
28 
29  virtual void DetOutline3D(evdb::View3D* view) override;
30 
31  protected:
34  geo::BoxBoundedGeo const& bb,
35  Color_t color,
36  Width_t width,
37  Style_t style) const;
38 
41  geo::TPCGeo const& TPC,
42  Color_t color,
43  Width_t width,
44  Style_t style) const
45  {
46  DrawBoxBoundedGeoOutline(view, TPC, color, width, style);
47  }
48 
51  geo::TPCGeo const& TPC,
52  Color_t color,
53  Width_t width,
54  Style_t style) const;
55 
57  double const* coordsLo,
58  double const* coordsHi,
59  int color = kGray,
60  int width = 1,
61  int style = 1) const;
62  void DrawGrids(evdb::View3D* view,
63  double const* coordsLo,
64  double const* coordsHi,
65  int color = kGray,
66  int width = 1,
67  int style = 1) const;
68  void DrawAxes(evdb::View3D* view,
69  double const* coordsLo,
70  double const* coordsHi,
71  int color = kGray,
72  int width = 1,
73  int style = 1) const;
74 
75  private:
76  void configure(const fhicl::ParameterSet& pset);
77  // Member variables from the fhicl file
78  bool fDrawGrid;
79  bool fDrawAxes;
80  bool fDrawActive;
81  };
82 
83  //----------------------------------------------------------------------
84  // Constructor.
86  {
87  configure(pset);
88  }
89 
91  {
92  // Start by recovering the parameters
93  fDrawGrid = pset.get<bool>("DrawGrid", true);
94  fDrawAxes = pset.get<bool>("DrawAxes", true);
95  fDrawActive = pset.get<bool>("DrawActive", true);
96 
97  return;
98  }
99 
100  //......................................................................
102  {
103  auto const& geom = *(lar::providerFrom<geo::Geometry>());
104 
105  // we compute the total volume of the detector, to be used for the axes;
106  // we do include the origin by choice
107  geo::BoxBoundedGeo detector({0.0, 0.0, 0.0}, {0.0, 0.0, 0.0});
108 
109  // Draw a box for each cryostat, and, within it, for each TPC;
110  // the outlined volumes are the ones from the geometry boxes
111  for (geo::CryostatGeo const& cryo : geom.Iterate<geo::CryostatGeo>()) {
112 
113  // include this cryostat in the detector volume
114  detector.ExtendToInclude(cryo);
115 
116  // draw the cryostat box
117  DrawBoxBoundedGeoOutline(view, cryo.Boundaries(), kRed + 2, 1, kSolid);
118 
119  // draw all TPC boxes
120  for (geo::TPCGeo const& TPC : cryo.IterateTPCs()) {
121 
122  DrawTPCoutline(view, TPC, kRed, 2, kSolid);
123 
124  // BUG the double brace syntax is required to work around clang bug 21629
125  // optionally draw the grid
126  if (fDrawGrid) {
127  std::array<double, 3U> const tpcLow{{TPC.MinX(), TPC.MinY(), TPC.MinZ()}},
128  tpcHigh{{TPC.MaxX(), TPC.MaxY(), TPC.MaxZ()}};
129  DrawGrids(view, tpcLow.data(), tpcHigh.data(), kGray + 2, 1, kSolid);
130  }
131 
132  // optionally draw the active volume
133  if (fDrawActive) DrawActiveTPCoutline(view, TPC, kCyan + 2, 1, kDotted);
134 
135  } // for TPCs in cryostat
136 
137  } // for cryostats
138 
139  // draw axes if requested
140  if (fDrawAxes) {
141  // BUG the double brace syntax is required to work around clang bug 21629
142  std::array<double, 3U> const detLow = {{detector.MinX(), detector.MinY(), detector.MinZ()}},
143  detHigh = {{detector.MaxX(), detector.MaxY(), detector.MaxZ()}};
144  DrawAxes(view, detLow.data(), detHigh.data(), kBlue, 1, kSolid);
145  } // if draw axes
146  }
147 
149  geo::BoxBoundedGeo const& bb,
150  Color_t color,
151  Width_t width,
152  Style_t style) const
153  {
154  // BUG the double brace syntax is required to work around clang bug 21629
155  std::array<double, 3U> const low{{bb.MinX(), bb.MinY(), bb.MinZ()}},
156  high{{bb.MaxX(), bb.MaxY(), bb.MaxZ()}};
157  ;
158  DrawRectangularBox(view, low.data(), high.data(), color, width, style);
159  } // StandardDrawer::DrawBoxBoundedGeoOutline()
160 
162  geo::TPCGeo const& TPC,
163  Color_t color,
164  Width_t width,
165  Style_t style) const
166  {
167  auto const& activeCenter = TPC.GetActiveVolumeCenter();
169  {{activeCenter.X() - TPC.ActiveHalfWidth(),
170  activeCenter.Y() - TPC.ActiveHalfHeight(),
171  activeCenter.Z() - TPC.ActiveHalfLength()},
172  {activeCenter.X() + TPC.ActiveHalfWidth(),
173  activeCenter.Y() + TPC.ActiveHalfHeight(),
174  activeCenter.Z() + TPC.ActiveHalfLength()}},
175  color,
176  width,
177  style);
178  }
179 
181  double const* coordsLo,
182  double const* coordsHi,
183  int color,
184  int width,
185  int style) const
186  {
187  TPolyLine3D& top = view->AddPolyLine3D(5, color, width, style);
188  top.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
189  top.SetPoint(1, coordsHi[0], coordsHi[1], coordsLo[2]);
190  top.SetPoint(2, coordsHi[0], coordsHi[1], coordsHi[2]);
191  top.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
192  top.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
193 
194  TPolyLine3D& side = view->AddPolyLine3D(5, color, width, style);
195  side.SetPoint(0, coordsHi[0], coordsHi[1], coordsLo[2]);
196  side.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
197  side.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
198  side.SetPoint(3, coordsHi[0], coordsHi[1], coordsHi[2]);
199  side.SetPoint(4, coordsHi[0], coordsHi[1], coordsLo[2]);
200 
201  TPolyLine3D& side2 = view->AddPolyLine3D(5, color, width, style);
202  side2.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
203  side2.SetPoint(1, coordsLo[0], coordsLo[1], coordsLo[2]);
204  side2.SetPoint(2, coordsLo[0], coordsLo[1], coordsHi[2]);
205  side2.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
206  side2.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
207 
208  TPolyLine3D& bottom = view->AddPolyLine3D(5, color, width, style);
209  bottom.SetPoint(0, coordsLo[0], coordsLo[1], coordsLo[2]);
210  bottom.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
211  bottom.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
212  bottom.SetPoint(3, coordsLo[0], coordsLo[1], coordsHi[2]);
213  bottom.SetPoint(4, coordsLo[0], coordsLo[1], coordsLo[2]);
214 
215  return;
216  }
217 
219  double const* coordsLo,
220  double const* coordsHi,
221  int color,
222  int width,
223  int style) const
224  {
225  // uniform step size, each 25 cm except that at least 5 per plane
226  double const gridStep = std::min(25.0,
227  std::min({std::abs(coordsHi[0] - coordsLo[0]),
228  std::abs(coordsHi[1] - coordsLo[1]),
229  std::abs(coordsHi[2] - coordsLo[2])}) /
230  5);
231 
232  // Grid running along x and y at constant z
233  for (double z = coordsLo[2]; z <= coordsHi[2]; z += gridStep) {
234 
235  // across x, on bottom plane, fixed z
236  TPolyLine3D& gridt = view->AddPolyLine3D(2, color, style, width);
237  gridt.SetPoint(0, coordsLo[0], coordsLo[1], z);
238  gridt.SetPoint(1, coordsHi[0], coordsLo[1], z);
239 
240  // on right plane, across y, fixed z
241  TPolyLine3D& grids = view->AddPolyLine3D(2, color, style, width);
242  grids.SetPoint(0, coordsHi[0], coordsLo[1], z);
243  grids.SetPoint(1, coordsHi[0], coordsHi[1], z);
244  }
245 
246  // Grid running along z at constant x
247  for (double x = coordsLo[0]; x <= coordsHi[0]; x += gridStep) {
248  // fixed x, on bottom plane, across z
249  TPolyLine3D& gridt = view->AddPolyLine3D(2, color, style, width);
250  gridt.SetPoint(0, x, coordsLo[1], coordsLo[2]);
251  gridt.SetPoint(1, x, coordsLo[1], coordsHi[2]);
252  }
253 
254  // Grid running along z at constant y
255  for (double y = coordsLo[1]; y <= coordsHi[1]; y += gridStep) {
256  // on right plane, fixed y, across z
257  TPolyLine3D& grids = view->AddPolyLine3D(2, color, style, width);
258  grids.SetPoint(0, coordsHi[0], y, coordsLo[2]);
259  grids.SetPoint(1, coordsHi[0], y, coordsHi[2]);
260  }
261 
262  return;
263  }
264 
266  double const* coordsLo,
267  double const* coordsHi,
268  int color,
269  int width,
270  int style) const
271  {
272  /*
273  * Axes are drawn encompassing the whole detector volume,
274  * the axis length being a fraction of the detector dimensions
275  */
276  double const vertexMargin = 0.06;
277  double const axisLength = 0.40; // 20% of the shortest
278 
279  double const dx = (coordsHi[0] - coordsLo[0]);
280  double const dy = (coordsHi[1] - coordsLo[1]);
281  double const dz = (coordsHi[2] - coordsLo[2]);
282 
283  // axes origin
284  double const x0 = coordsLo[0] - dx * vertexMargin;
285  double const y0 = coordsLo[1] - dy * vertexMargin;
286  double const z0 = coordsLo[2] - dz * vertexMargin;
287  // axis length
288  double const sz = axisLength * std::min({std::abs(dx), std::abs(dy), std::abs(dz)});
289 
290  TPolyLine3D& xaxis = view->AddPolyLine3D(2, color, style, width);
291  TPolyLine3D& yaxis = view->AddPolyLine3D(2, color, style, width);
292  TPolyLine3D& zaxis = view->AddPolyLine3D(2, color, style, width);
293  xaxis.SetPoint(0, x0, y0, z0);
294  xaxis.SetPoint(1, sz + x0, y0, z0);
295 
296  yaxis.SetPoint(0, x0, y0, z0);
297  yaxis.SetPoint(1, x0, y0 + sz, z0);
298 
299  zaxis.SetPoint(0, x0, y0, z0);
300  zaxis.SetPoint(1, x0, y0, z0 + sz);
301 
302  TPolyLine3D& xpoint = view->AddPolyLine3D(3, color, style, width);
303  TPolyLine3D& ypoint = view->AddPolyLine3D(3, color, style, width);
304  TPolyLine3D& zpoint = view->AddPolyLine3D(3, color, style, width);
305 
306  xpoint.SetPoint(0, 0.95 * sz + x0, y0, z0 - 0.05 * sz);
307  xpoint.SetPoint(1, 1.00 * sz + x0, y0, z0);
308  xpoint.SetPoint(2, 0.95 * sz + x0, y0, z0 + 0.05 * sz);
309 
310  ypoint.SetPoint(0, x0, 0.95 * sz + y0, z0 - 0.05 * sz);
311  ypoint.SetPoint(1, x0, 1.00 * sz + y0, z0);
312  ypoint.SetPoint(2, x0, 0.95 * sz + y0, z0 + 0.05 * sz);
313 
314  zpoint.SetPoint(0, x0 - 0.05 * sz, y0, 0.95 * sz + z0);
315  zpoint.SetPoint(1, x0 + 0.00 * sz, y0, 1.00 * sz + z0);
316  zpoint.SetPoint(2, x0 + 0.05 * sz, y0, 0.95 * sz + z0);
317 
318  TPolyLine3D& zleg = view->AddPolyLine3D(4, color, style, width);
319  zleg.SetPoint(0, x0 - 0.05 * sz, y0 + 0.05 * sz, z0 + 1.05 * sz);
320  zleg.SetPoint(1, x0 + 0.05 * sz, y0 + 0.05 * sz, z0 + 1.05 * sz);
321  zleg.SetPoint(2, x0 - 0.05 * sz, y0 - 0.05 * sz, z0 + 1.05 * sz);
322  zleg.SetPoint(3, x0 + 0.05 * sz, y0 - 0.05 * sz, z0 + 1.05 * sz);
323 
324  TPolyLine3D& yleg = view->AddPolyLine3D(5, color, style, width);
325  yleg.SetPoint(0, x0 - 0.05 * sz, y0 + 1.15 * sz, z0);
326  yleg.SetPoint(1, x0 + 0.00 * sz, y0 + 1.10 * sz, z0);
327  yleg.SetPoint(2, x0 + 0.00 * sz, y0 + 1.05 * sz, z0);
328  yleg.SetPoint(3, x0 + 0.00 * sz, y0 + 1.10 * sz, z0);
329  yleg.SetPoint(4, x0 + 0.05 * sz, y0 + 1.15 * sz, z0);
330 
331  TPolyLine3D& xleg = view->AddPolyLine3D(7, color, style, width);
332  xleg.SetPoint(0, x0 + 1.05 * sz, y0 + 0.05 * sz, z0 - 0.05 * sz);
333  xleg.SetPoint(1, x0 + 1.05 * sz, y0 + 0.00 * sz, z0 - 0.00 * sz);
334  xleg.SetPoint(2, x0 + 1.05 * sz, y0 + 0.05 * sz, z0 + 0.05 * sz);
335  xleg.SetPoint(3, x0 + 1.05 * sz, y0 + 0.00 * sz, z0 - 0.00 * sz);
336  xleg.SetPoint(4, x0 + 1.05 * sz, y0 - 0.05 * sz, z0 - 0.05 * sz);
337  xleg.SetPoint(5, x0 + 1.05 * sz, y0 + 0.00 * sz, z0 - 0.00 * sz);
338  xleg.SetPoint(6, x0 + 1.05 * sz, y0 - 0.05 * sz, z0 + 0.05 * sz);
339 
340  return;
341  }
342 
344 }
Float_t x
Definition: compare.C:6
void DrawAxes(evdb::View3D *view, double const *coordsLo, double const *coordsHi, int color=kGray, int width=1, int style=1) const
void configure(const fhicl::ParameterSet &pset)
bool fDrawActive
true to outline TPC sensitive volumes
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
Utilities related to art service access.
Encapsulate the construction of a single cyostat.
double ActiveHalfHeight() const
Half height (associated with y coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:88
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:276
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:90
Geometry information for a single TPC.
Definition: TPCGeo.h:36
constexpr auto abs(T v)
Returns the absolute value of the argument.
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:93
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
TGaxis * xaxis
Definition: plot_hist.C:61
StandardDrawer(const fhicl::ParameterSet &pset)
TPolyLine3D & AddPolyLine3D(int n, int c, int w, int s)
Definition: View3D.cxx:105
double ActiveHalfLength() const
Length (associated with z coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:94
double ActiveHalfWidth() const
Half width (associated with x coordinate) of active TPC volume [cm].
Definition: TPCGeo.h:84
T get(std::string const &key) const
Definition: ParameterSet.h:314
void DrawActiveTPCoutline(evdb::View3D *view, geo::TPCGeo const &TPC, Color_t color, Width_t width, Style_t style) const
Draw the outline of the TPC active volume.
void DrawBoxBoundedGeoOutline(evdb::View3D *view, geo::BoxBoundedGeo const &bb, Color_t color, Width_t width, Style_t style) const
Draw the outline of an object bounded by a box.
double MinZ() const
Returns the world z coordinate of the start of the box.
void DrawRectangularBox(evdb::View3D *view, double const *coordsLo, double const *coordsHi, int color=kGray, int width=1, int style=1) const
bool fDrawGrid
true to draw backing grid
void DrawGrids(evdb::View3D *view, double const *coordsLo, double const *coordsHi, int color=kGray, int width=1, int style=1) const
Point_t GetActiveVolumeCenter() const
Returns the center of the TPC active volume in world coordinates [cm].
Definition: TPCGeo.h:250
double MaxY() const
Returns the world y coordinate of the end of the box.
std::size_t color(std::string const &procname)
void DrawTPCoutline(evdb::View3D *view, geo::TPCGeo const &TPC, Color_t color, Width_t width, Style_t style) const
Draw the outline of the TPC volume.
bool fDrawAxes
true to draw coordinate axes
A base class aware of world box coordinatesAn object describing a simple shape can inherit from this ...
Definition: BoxBoundedGeo.h:33
double MaxZ() const
Returns the world z coordinate of the end of the box.
void ExtendToInclude(Coord_t x, Coord_t y, Coord_t z)
Extends the current box to also include the specified point.
virtual void DetOutline3D(evdb::View3D *view) override
A collection of 3D drawable objects.
This is the interface class for drawing 3D detector geometries.
double MinY() const
Returns the world y coordinate of the start of the box.
art framework interface to geometry description
Encapsulate the construction of a single detector plane.