LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 <array>
22 #include <vector>
23 
24 
25 namespace geo {
35  class BoxBoundedGeo {
36  public:
38  using Coord_t = Coords_t::Scalar;
39 
48  BoxBoundedGeo() = default;
49 
50 
66  Coord_t y_min, Coord_t y_max,
67  Coord_t z_min, Coord_t z_max
68  ):
69  c_min{ x_min, y_min, z_min }, c_max{ x_max, y_max, z_max }
70  { SortCoordinates(); }
71 
82  c_min(lower), c_max(upper)
83  { SortCoordinates(); }
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 
142  { return { CenterX(), CenterY(), CenterZ() }; }
143 
145 
146 
147 
150 
161  bool ContainsX(double x, double const wiggle = 1) const
162  { return CoordinateContained(x, MinX(), MaxX(), wiggle); }
163 
171  bool ContainsY(double y, double const wiggle = 1) const
172  { return CoordinateContained(y, MinY(), MaxY(), wiggle); }
173 
181  bool ContainsZ(double z, double const wiggle = 1) const
182  { return CoordinateContained(z, MinZ(), MaxZ(), wiggle); }
183 
192  bool ContainsYZ(double y, double z, double const wiggle = 1) const
193  { return ContainsY(y, wiggle) && ContainsZ(z, wiggle); }
194 
195 
206  bool ContainsPosition
207  (geo::Point_t const& point, double wiggle = 1.0) const
208  {
209  return ContainsX(point.X(), wiggle)
210  && ContainsYZ(point.Y(), point.Z(), wiggle);
211  } // ContainsPosition()
213  bool ContainsPosition(TVector3 const& point, double wiggle = 1.0) const;
215  bool ContainsPosition(double const* point, double wiggle = 1.0) const;
216 
217 
219 
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
254  { return InFiducialX(x, margin, margin); }
255 
274  bool InFiducialY(double y, double neg_margin, double pos_margin) const
275  {
276  return CoordinateContained(y, MinY() + neg_margin, MaxY() - pos_margin);
277  }
284  bool InFiducialY(double y, double margin) const
285  { return InFiducialY(y, margin, margin); }
286 
305  bool InFiducialZ(double z, double neg_margin, double pos_margin) const
306  {
307  return CoordinateContained(z, MinZ() + neg_margin, MaxZ() - pos_margin);
308  }
315  bool InFiducialZ(double z, double margin) const
316  { return InFiducialZ(z, margin, margin); }
317 
319 
320 
332  static bool CoordinateContained
333  (double c, double min, double max, double wiggle = 1.)
334  {
335  return (c >= (min > 0? min / wiggle: min * wiggle))
336  && (c <= (max < 0? max / wiggle: max * wiggle));
337  } // CoordinateContained()
338 
350  static bool CoordinateContained
351  (double c, double const* range, double wiggle = 1.)
352  { return CoordinateContained(c, range[0], range[1], wiggle); }
353 
354 
357 
369  Coord_t y_min, Coord_t y_max,
370  Coord_t z_min, Coord_t z_max
371  )
372  {
373  c_min.SetXYZ(x_min, y_min, z_min);
374  c_max.SetXYZ(x_max, y_max, z_max);
375  SortCoordinates();
376  }
377 
383  void SetBoundaries(Coords_t lower, Coords_t upper)
384  { c_min = lower; c_max = upper; SortCoordinates(); }
385 
393  { ExtendToInclude(geo::Point_t(x, y, z)); }
394 
399  void ExtendToInclude(geo::Point_t const& point)
400  {
401  set_min(c_min, point);
402  set_max(c_max, point);
403  }
404 
412  {
413  set_min(c_min, box.Min());
414  set_max(c_max, box.Max());
415  } // ExtendToInclude()
416 
418 
419 
421 
434  std::vector<TVector3> GetIntersections
435  (TVector3 const& TrajectoryStart, TVector3 const& TrajectoryDirect) const;
436  std::vector<geo::Point_t> GetIntersections
437  (geo::Point_t const& TrajectoryStart, geo::Vector_t const& TrajectoryDirect) const;
439 
440 
442  static void set_min(Coord_t& var, Coord_t value)
443  { if (value < var) var = value; }
444 
446  static void set_max(Coord_t& var, Coord_t value)
447  { if (value > var) var = value; }
448 
450  static void set_min(Coords_t& var, geo::Point_t const& value)
451  {
452  if (value.X() < var.X()) var.SetX(value.X());
453  if (value.Y() < var.Y()) var.SetY(value.Y());
454  if (value.Z() < var.Z()) var.SetZ(value.Z());
455  }
456 
458  static void set_max(Coords_t& var, geo::Point_t const& value)
459  {
460  if (value.X() > var.X()) var.SetX(value.X());
461  if (value.Y() > var.Y()) var.SetY(value.Y());
462  if (value.Z() > var.Z()) var.SetZ(value.Z());
463  }
464 
465 
466  private:
467  // we don't allow the derived classes to mess with the boundaries
470 
472  void SortCoordinates();
473 
474  }; // class BoxBoundedGeo
475 
476 } // namespace geo
477 
478 
479 
480 #endif // LARCOREALG_GEOMETRY_BOXBOUNDEDGEO_H
Float_t x
Definition: compare.C:6
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:167
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:38
double SizeX() const
Returns the full size in the X dimension.
Definition: BoxBoundedGeo.h:99
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:64
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:279
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:90
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.
Int_t max
Definition: plot.C:27
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:37
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 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.
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)
std::string value(boost::any const &)
A base class aware of world box coordinatesAn object describing a simple shape can inherit from this ...
Definition: BoxBoundedGeo.h:35
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.
Int_t min
Definition: plot.C:26
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.
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.
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:187
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.