LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PhotonVoxels.h
Go to the documentation of this file.
1 
6 #ifndef LARSIM_SIMULATION_PHOTONVOXELS_H
7 #define LARSIM_SIMULATION_PHOTONVOXELS_H
8 
9 // LArSoft libraries
12 
13 // C/C++ standard libraries
14 #include <array>
15 #include <optional>
16 
17 namespace sim {
18 
20  class PhotonVoxel {
21  public:
22  PhotonVoxel() = default;
23  PhotonVoxel(geo::Point_t const& min, geo::Point_t const& max) : fVoxelMin(min), fVoxelMax(max)
24  {}
25  PhotonVoxel(double xMin, double xMax, double yMin, double yMax, double zMin, double zMax)
26  : PhotonVoxel({xMin, yMin, zMin}, {xMax, yMax, zMax})
27  {}
28 
29  private:
32 
33  public:
35 
37  // the choice of `decltype(auto)` is because in case `geo::Point_t` is the
38  // requested `Point` type, a reference to the data member is returned
39  // instead of a copy.
40 
42  template <typename Point = DefaultPoint>
43  decltype(auto) GetLowerCorner() const;
44 
46  template <typename Point = DefaultPoint>
47  decltype(auto) GetUpperCorner() const;
48 
50  template <typename Point = DefaultPoint>
51  Point GetCenter() const;
52 
54 
55  }; // class PhotonVoxel
56 
61 
64  unsigned int fxSteps = 1U;
65  unsigned int fySteps = 1U;
66  unsigned int fzSteps = 1U;
67 
68  public:
69  PhotonVoxelDef() = default;
70  PhotonVoxelDef(double xMin,
71  double xMax,
72  int xN,
73  double yMin,
74  double yMax,
75  int yN,
76  double zMin,
77  double zMax,
78  int zN);
79 
81  template <typename Point = DefaultPoint>
82  decltype(auto) GetRegionLowerCorner() const;
83 
85  template <typename Point = DefaultPoint>
86  decltype(auto) GetRegionUpperCorner() const;
87 
89  std::array<unsigned int, 3U> GetSteps() const;
90 
92  template <typename Vector = DefaultVector>
93  Vector GetVoxelSize() const;
94 
96  template <typename Vector = DefaultVector, typename Point = DefaultPoint>
97  Vector GetVolumeSize() const
98  {
99  return GetRegionUpperCorner<Point>() - GetRegionLowerCorner<Point>();
100  }
101 
103  unsigned int GetNVoxels() const;
104 
106  template <typename Point>
107  int GetVoxelID(Point const& p) const;
108 
109  int GetVoxelID(double const*) const;
110  bool IsLegalVoxelID(int) const;
111 
112  struct NeiInfo {
113  NeiInfo() = default;
114  NeiInfo(int i, double w) : id(i), weight(w) {}
115  int id = -1;
116  double weight = 0.0;
117  };
118 
130  template <typename Point>
131  std::optional<std::array<NeiInfo, 8U>> GetNeighboringVoxelIDs(Point const& v) const;
132 
133  PhotonVoxel GetPhotonVoxel(int ID) const;
134  std::array<int, 3U> GetVoxelCoords(int ID) const;
135 
137  bool isInside(geo::Point_t const& p) const { return isInsideImpl(p); }
138 
139  bool operator==(const PhotonVoxelDef& rhs) const;
140  bool operator!=(const PhotonVoxelDef& rhs) const { return !((*this) == rhs); }
141 
142  private:
143  int GetVoxelIDImpl(geo::Point_t const& p) const;
144 
145  std::optional<std::array<NeiInfo, 8U>> GetNeighboringVoxelIDsImpl(geo::Point_t const& v) const;
146 
148  std::array<double, 3U> GetVoxelStepCoordsUnchecked(geo::Point_t const& p) const;
149 
151  bool isInsideImpl(geo::Point_t const& point) const
152  {
153  return isInsideVolume(point, fLowerCorner, fUpperCorner);
154  }
155 
156  static bool isInsideVolume(geo::Point_t const& point,
157  geo::Point_t const& lower,
158  geo::Point_t const& upper);
159  static bool isInsideRange(double value, double lower, double upper);
160 
161  }; // class PhotonVoxelDef
162 
164  std::ostream& operator<<(std::ostream& out, sim::PhotonVoxelDef const& voxelDef);
165 
166 } // namespace sim
167 
168 //------------------------------------------------------------------------------
169 //--- template implementation
170 //------------------------------------------------------------------------------
171 //--- sim::PhotonVoxel
172 //------------------------------------------------------------------------------
173 template <typename Point /* = DefaultPoint */>
174 decltype(auto) sim::PhotonVoxel::GetLowerCorner() const
175 {
176  return geo::vect::convertTo<Point>(fVoxelMin);
177 }
178 
179 template <typename Point /* = DefaultPoint */>
180 decltype(auto) sim::PhotonVoxel::GetUpperCorner() const
181 {
182  return geo::vect::convertTo<Point>(fVoxelMax);
183 }
184 
185 template <typename Point /* = DefaultPoint */>
187 {
188  return geo::vect::convertTo<Point>(geo::vect::middlePoint({fVoxelMin, fVoxelMax}));
189 }
190 
191 //------------------------------------------------------------------------------
192 //--- sim::PhotonVoxelDef
193 //------------------------------------------------------------------------------
194 template <typename Point /* = DefaultPoint */>
195 decltype(auto) sim::PhotonVoxelDef::GetRegionLowerCorner() const
196 {
197  return geo::vect::convertTo<Point>(fLowerCorner);
198 }
199 
200 template <typename Point /* = DefaultPoint */>
201 decltype(auto) sim::PhotonVoxelDef::GetRegionUpperCorner() const
202 {
203  return geo::vect::convertTo<Point>(fUpperCorner);
204 }
205 
206 //------------------------------------------------------------------------------
207 template <typename Vector /* = DefaultVector */>
209 {
210  return {(fUpperCorner.X() - fLowerCorner.X()) / fxSteps,
211  (fUpperCorner.Y() - fLowerCorner.Y()) / fySteps,
212  (fUpperCorner.Z() - fLowerCorner.Z()) / fzSteps};
213 } // sim::PhotonVoxelDef::GetVoxelSize()
214 
215 //------------------------------------------------------------------------------
216 template <typename Point>
218 {
219  return GetVoxelIDImpl(geo::vect::toPoint(p));
220 }
221 
222 //------------------------------------------------------------------------------
223 template <typename Point>
224 std::optional<std::array<sim::PhotonVoxelDef::NeiInfo, 8U>>
226 {
227  return GetNeighboringVoxelIDsImpl(geo::vect::toPoint(v));
228 }
229 
230 //------------------------------------------------------------------------------
231 
232 #endif // LARSIM_SIMULATION_PHOTONVOXELS_H
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
geo::Point_t fVoxelMin
Definition: PhotonVoxels.h:30
geo::Point_t fVoxelMax
Definition: PhotonVoxels.h:31
Vector GetVoxelSize() const
Returns a vector describing the span of a single voxel in x, y an z [cm].
Definition: PhotonVoxels.h:208
PhotonVoxel()=default
PhotonVoxel(geo::Point_t const &min, geo::Point_t const &max)
Definition: PhotonVoxels.h:23
Representation of a region of space diced into voxels.
Definition: PhotonVoxels.h:58
::geo::Point_t toPoint(Point const &p)
Convert the specified point into a geo::Point_t.
STL namespace.
int GetVoxelID(Point const &p) const
Returns the ID of the voxel containing p, or -1 if none.
Definition: PhotonVoxels.h:217
bool isInside(geo::Point_t const &p) const
Returns whether point p is inside the region (upper border excluded).
Definition: PhotonVoxels.h:137
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:250
Definitions of geometry vector data types.
geo::Vector_t DefaultVector
Definition: PhotonVoxels.h:60
decltype(auto) GetUpperCorner() const
Returns the voxel vertex (type Point) with the highest coordinates.
decltype(auto) GetRegionUpperCorner() const
Returns the volume vertex (type Point) with the highest coordinates.
Utilities to extend the interface of geometry vectors.
Monte Carlo Simulation.
double value
Definition: spectrum.C:18
geo::Point_t fLowerCorner
Definition: PhotonVoxels.h:62
geo::Point_t DefaultPoint
Definition: PhotonVoxels.h:59
bool operator!=(const PhotonVoxelDef &rhs) const
Definition: PhotonVoxels.h:140
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
double weight
Definition: plottest35.C:25
PhotonVoxel(double xMin, double xMax, double yMin, double yMax, double zMin, double zMax)
Definition: PhotonVoxels.h:25
std::optional< std::array< NeiInfo, 8U > > GetNeighboringVoxelIDs(Point const &v) const
Returns IDs of the eight neighboring voxels around v.
Representation of a single small volume (voxel).
Definition: PhotonVoxels.h:20
geo::Point_t DefaultPoint
Definition: PhotonVoxels.h:34
geo::Point_t fUpperCorner
Definition: PhotonVoxels.h:63
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:42
Point GetCenter() const
Returns the center of the voxel (type Point).
Definition: PhotonVoxels.h:186
bool isInsideImpl(geo::Point_t const &point) const
Returns whether the specified point is within the volume.
Definition: PhotonVoxels.h:151
std::ostream & operator<<(std::ostream &output, const LArVoxelData &data)
Float_t w
Definition: plot.C:20
bool operator==(infinite_endcount_iterator< T > const &, count_iterator< T > const &)
Definition: counter.h:278
geo::Point_t middlePoint(BeginIter begin, EndIter end)
Returns the middle of the specified points.
decltype(auto) GetLowerCorner() const
Returns the voxel vertex (type Point) with the lowest coordinates.
decltype(auto) GetRegionLowerCorner() const
Returns the volume vertex (type Point) with the lowest coordinates.