LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
BoxBoundedGeo.h
Go to the documentation of this file.
1 
10 #ifndef LARCOREALG_GEOMETRY_BOXBOUNDEDGEO_H
11 #define LARCOREALG_GEOMETRY_BOXBOUNDEDGEO_H
12 
13 // LArSoft libraries
15 
16 // ROOT library
17 #include "TVector3.h"
18 
19 // C/C++ standard library
20 #include <algorithm>
21 #include <vector>
22 
23 namespace geo {
33  class BoxBoundedGeo {
34  public:
36  using Coord_t = Coords_t::Scalar;
37 
46  BoxBoundedGeo() = default;
47 
62  Coord_t x_max,
63  Coord_t y_min,
64  Coord_t y_max,
65  Coord_t z_min,
66  Coord_t z_max)
67  : c_min{x_min, y_min, z_min}, c_max{x_max, y_max, z_max}
68  {
70  }
71 
81  BoxBoundedGeo(Coords_t lower, Coords_t upper) : c_min(lower), c_max(upper)
82  {
84  }
85 
88 
90  double MinX() const { return c_min.X(); }
91 
93  double MaxX() const { return c_max.X(); }
94 
96  double CenterX() const { return (MinX() + MaxX()) / 2.; }
97 
99  double SizeX() const { return MaxX() - MinX(); }
100 
102  double HalfSizeX() const { return SizeX() / 2.0; }
103 
105  double MinY() const { return c_min.Y(); }
106 
108  double MaxY() const { return c_max.Y(); }
109 
111  double CenterY() const { return (MinY() + MaxY()) / 2.; }
112 
114  double SizeY() const { return MaxY() - MinY(); }
115 
117  double HalfSizeY() const { return SizeY() / 2.0; }
118 
120  double MinZ() const { return c_min.Z(); }
121 
123  double MaxZ() const { return c_max.Z(); }
124 
126  double CenterZ() const { return (MinZ() + MaxZ()) / 2.; }
127 
129  double SizeZ() const { return MaxZ() - MinZ(); }
130 
132  double HalfSizeZ() const { return SizeZ() / 2.0; }
133 
135  geo::Point_t Min() const { return c_min; }
136 
138  geo::Point_t Max() const { return c_max; }
139 
141  geo::Point_t Center() const { return {CenterX(), CenterY(), CenterZ()}; }
142 
144 
147 
158  bool ContainsX(double x, double const wiggle = 1) const
159  {
160  return CoordinateContained(x, MinX(), MaxX(), wiggle);
161  }
162 
170  bool ContainsY(double y, double const wiggle = 1) const
171  {
172  return CoordinateContained(y, MinY(), MaxY(), wiggle);
173  }
174 
182  bool ContainsZ(double z, double const wiggle = 1) const
183  {
184  return CoordinateContained(z, MinZ(), MaxZ(), wiggle);
185  }
186 
195  bool ContainsYZ(double y, double z, double const wiggle = 1) const
196  {
197  return ContainsY(y, wiggle) && ContainsZ(z, wiggle);
198  }
199 
210  bool ContainsPosition(geo::Point_t const& point, double wiggle = 1.0) const
211  {
212  return ContainsX(point.X(), wiggle) && ContainsYZ(point.Y(), point.Z(), wiggle);
213  } // ContainsPosition()
215  bool ContainsPosition(TVector3 const& point, double wiggle = 1.0) const;
217  bool ContainsPosition(double const* point, double wiggle = 1.0) const;
218 
220 
223 
243  bool InFiducialX(double x, double neg_margin, double pos_margin) const
244  {
245  return CoordinateContained(x, MinX() + neg_margin, MaxX() - pos_margin);
246  }
253  bool InFiducialX(double x, double margin) const { return InFiducialX(x, margin, margin); }
254 
273  bool InFiducialY(double y, double neg_margin, double pos_margin) const
274  {
275  return CoordinateContained(y, MinY() + neg_margin, MaxY() - pos_margin);
276  }
283  bool InFiducialY(double y, double margin) const { return InFiducialY(y, margin, margin); }
284 
303  bool InFiducialZ(double z, double neg_margin, double pos_margin) const
304  {
305  return CoordinateContained(z, MinZ() + neg_margin, MaxZ() - pos_margin);
306  }
313  bool InFiducialZ(double z, double margin) const { return InFiducialZ(z, margin, margin); }
314 
316 
317  // -- BEGIN -- Overlaps ----------------------------------------------------
320 
322  bool OverlapsX(geo::BoxBoundedGeo const& other) const
323  {
324  return std::min(MaxX(), other.MaxX()) > std::max(MinX(), other.MinX());
325  }
326 
328  bool OverlapsY(geo::BoxBoundedGeo const& other) const
329  {
330  return std::min(MaxY(), other.MaxY()) > std::max(MinY(), other.MinY());
331  }
332 
334  bool OverlapsZ(geo::BoxBoundedGeo const& other) const
335  {
336  return std::min(MaxZ(), other.MaxZ()) > std::max(MinZ(), other.MinZ());
337  }
338 
340  bool Overlaps(geo::BoxBoundedGeo const& other) const
341  {
342  return OverlapsX(other) && OverlapsY(other) && OverlapsZ(other);
343  }
344 
346  // -- END -- Overlaps ------------------------------------------------------
347 
359  static bool CoordinateContained(double c, double min, double max, double wiggle = 1.)
360  {
361  return (c >= (min > 0 ? min / wiggle : min * wiggle)) &&
362  (c <= (max < 0 ? max / wiggle : max * wiggle));
363  } // CoordinateContained()
364 
376  static bool CoordinateContained(double c, double const* range, double wiggle = 1.)
377  {
378  return CoordinateContained(c, range[0], range[1], wiggle);
379  }
380 
383 
394  Coord_t x_max,
395  Coord_t y_min,
396  Coord_t y_max,
397  Coord_t z_min,
398  Coord_t z_max)
399  {
400  c_min.SetXYZ(x_min, y_min, z_min);
401  c_max.SetXYZ(x_max, y_max, z_max);
402  SortCoordinates();
403  }
404 
410  void SetBoundaries(Coords_t lower, Coords_t upper)
411  {
412  c_min = lower;
413  c_max = upper;
414  SortCoordinates();
415  }
416 
424  {
425  ExtendToInclude(geo::Point_t(x, y, z));
426  }
427 
432  void ExtendToInclude(geo::Point_t const& point)
433  {
434  set_min(c_min, point);
435  set_max(c_max, point);
436  }
437 
445  {
446  set_min(c_min, box.Min());
447  set_max(c_max, box.Max());
448  } // ExtendToInclude()
449 
451 
453 
466  std::vector<TVector3> GetIntersections(TVector3 const& TrajectoryStart,
467  TVector3 const& TrajectoryDirect) const;
468  std::vector<geo::Point_t> GetIntersections(geo::Point_t const& TrajectoryStart,
469  geo::Vector_t const& TrajectoryDirect) const;
471 
473  static void set_min(Coord_t& var, Coord_t value)
474  {
475  if (value < var) var = value;
476  }
477 
479  static void set_max(Coord_t& var, Coord_t value)
480  {
481  if (value > var) var = value;
482  }
483 
485  static void set_min(Coords_t& var, geo::Point_t const& value)
486  {
487  if (value.X() < var.X()) var.SetX(value.X());
488  if (value.Y() < var.Y()) var.SetY(value.Y());
489  if (value.Z() < var.Z()) var.SetZ(value.Z());
490  }
491 
493  static void set_max(Coords_t& var, geo::Point_t const& value)
494  {
495  if (value.X() > var.X()) var.SetX(value.X());
496  if (value.Y() > var.Y()) var.SetY(value.Y());
497  if (value.Z() > var.Z()) var.SetZ(value.Z());
498  }
499 
500  private:
501  // we don't allow the derived classes to mess with the boundaries
504 
506  void SortCoordinates();
507 
508  }; // class BoxBoundedGeo
509 
510 } // namespace geo
511 
512 #endif // LARCOREALG_GEOMETRY_BOXBOUNDEDGEO_H
Float_t x
Definition: compare.C:6
bool OverlapsX(geo::BoxBoundedGeo const &other) const
Returns if the x coordinates covered by this and other box overlap.
static void set_min(Coords_t &var, geo::Point_t const &value)
Sets each coordinate of var to the one in value if the latter is smaller.
void SetBoundaries(Coords_t lower, Coords_t upper)
Sets the boundaries in world coordinates as specified.
Coords_t::Scalar Coord_t
Type of the coordinate.
Definition: BoxBoundedGeo.h:36
double SizeX() const
Returns the full size in the X dimension.
Definition: BoxBoundedGeo.h:99
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:160
bool InFiducialX(double x, double margin) const
Returns whether TPC fiducial volume contains world x coordinate.
BoxBoundedGeo(Coord_t x_min, Coord_t x_max, Coord_t y_min, Coord_t y_max, Coord_t z_min, Coord_t z_max)
Constructor: sets the boundaries in world coordinates as specified.
Definition: BoxBoundedGeo.h:61
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
bool OverlapsZ(geo::BoxBoundedGeo const &other) const
Returns if the z coordinates covered by this and other box overlap.
BoxBoundedGeo()=default
Default constructor: sets an empty volume.
double CenterX() const
Returns the world x coordinate of the center of the box.
Definition: BoxBoundedGeo.h:96
double CenterZ() const
Returns the world z coordinate of the center of the box.
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:93
bool InFiducialZ(double z, double margin) const
Returns whether TPC fiducial volume contains world z coordinate.
double SizeY() const
Returns the full size in the Y dimension.
double x_min
Definition: berger.C:15
static void set_min(Coord_t &var, Coord_t value)
Sets var to value if value is smaller than the current var value.
bool OverlapsY(geo::BoxBoundedGeo const &other) const
Returns if the y coordinates covered by this and other box overlap.
double HalfSizeZ() const
Returns the size from the center to the border on Z dimension.
Definitions of geometry vector data types.
double MinZ() const
Returns the world z coordinate of the start of the box.
static void set_max(Coord_t &var, Coord_t value)
Sets var to value if value is larger than the current var value.
geo::Point_t Coords_t
Type of the coordinate triplet.
Definition: BoxBoundedGeo.h:35
geo::Point_t Min() const
Returns the corner point with the smallest coordinates.
void ExtendToInclude(geo::Point_t const &point)
Extends the current box to also include the specified point.
bool InFiducialY(double y, double margin) const
Returns whether TPC fiducial volume contains world y coordinate.
double value
Definition: spectrum.C:18
bool Overlaps(geo::BoxBoundedGeo const &other) const
Returns if this and other box overlap.
double MaxY() const
Returns the world y coordinate of the end of the box.
Coords_t c_max
maximum coordinates (x, y, z)
double x_max
Definition: berger.C:16
double SizeZ() const
Returns the full size in the Z dimension.
double HalfSizeX() const
Returns the size from the center to the border on X dimension.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
bool InFiducialY(double y, double neg_margin, double pos_margin) const
Returns whether TPC fiducial volume contains world y coordinate.
bool ContainsX(double x, double const wiggle=1) const
Returns whether this TPC contains the specified world x coordinate.
Coords_t c_min
minimum coordinates (x, y, z)
A base class aware of world box coordinatesAn object describing a simple shape can inherit from this ...
Definition: BoxBoundedGeo.h:33
void ExtendToInclude(BoxBoundedGeo const &box)
Extends the current box to also include the specified one.
void SortCoordinates()
Makes sure each coordinate of the minimum point is smaller than maximum.
double CenterY() const
Returns the world y coordinate of the center of the box.
void SetBoundaries(Coord_t x_min, Coord_t x_max, Coord_t y_min, Coord_t y_max, Coord_t z_min, Coord_t z_max)
Sets the boundaries in world coordinates as specified.
double MaxZ() const
Returns the world z coordinate of the end of the box.
BoxBoundedGeo(Coords_t lower, Coords_t upper)
Constructor: sets the boundaries in world coordinates as specified.
Definition: BoxBoundedGeo.h:81
void ExtendToInclude(Coord_t x, Coord_t y, Coord_t z)
Extends the current box to also include the specified point.
double HalfSizeY() const
Returns the size from the center to the border on Y dimension.
std::vector< TVector3 > GetIntersections(TVector3 const &TrajectoryStart, TVector3 const &TrajectoryDirect) const
Calculates the entry and exit points of a trajectory on the box surface.
static bool CoordinateContained(double c, double min, double max, double wiggle=1.)
Returns whether the specified coordinate is in a range.
bool ContainsYZ(double y, double z, double const wiggle=1) const
Returns if TPC contains the specified world y and z coordinates.
static bool CoordinateContained(double c, double const *range, double wiggle=1.)
Returns whether the specified coordinate is in a range.
bool InFiducialX(double x, double neg_margin, double pos_margin) const
Returns whether TPC fiducial volume contains world x coordinate.
bool InFiducialZ(double z, double neg_margin, double pos_margin) const
Returns whether TPC fiducial volume contains world z coordinate.
Namespace collecting geometry-related classes utilities.
double MinY() const
Returns the world y coordinate of the start of the box.
bool ContainsY(double y, double const wiggle=1) const
Returns whether this TPC contains the specified world y coordinate.
static void set_max(Coords_t &var, geo::Point_t const &value)
Sets each coordinate of var to the one in value if the latter is larger.
geo::Point_t Max() const
Returns the corner point with the largest coordinates.
bool ContainsPosition(geo::Point_t const &point, double wiggle=1.0) const
Returns whether this volume contains the specified point.
bool ContainsZ(double z, double const wiggle=1) const
Returns whether this TPC contains the specified world z coordinate.
geo::Point_t Center() const
Returns the center point of the box.