LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
sim::PhotonVoxelDef Class Reference

#include "PhotonVoxels.h"

Classes

struct  NeiInfo
 

Public Member Functions

 PhotonVoxelDef (double xMin, double xMax, int xN, double yMin, double yMax, int yN, double zMin, double zMax, int z)
 
 PhotonVoxelDef ()
 
TVector3 GetRegionUpperCorner () const
 
TVector3 GetRegionLowerCorner () const
 
TVector3 GetSteps () const
 
TVector3 GetVoxelSize () const
 
int GetNVoxels () const
 
int GetVoxelID (const TVector3 &) const
 
int GetVoxelID (double const *) const
 
bool IsLegalVoxelID (int) const
 
void GetNeighboringVoxelIDs (const TVector3 &v, std::vector< NeiInfo > &ret) const
 
PhotonVoxel GetPhotonVoxel (int ID) const
 
std::vector< int > GetVoxelCoords (int ID) const
 
PhotonVoxel GetContainingVoxel (TVector3) const
 
bool operator== (const PhotonVoxelDef &rhs) const
 
bool operator!= (const PhotonVoxelDef &rhs) const
 

Private Attributes

TVector3 fLowerCorner
 
TVector3 fUpperCorner
 
int fxSteps
 
int fySteps
 
int fzSteps
 

Detailed Description

Definition at line 42 of file PhotonVoxels.h.

Constructor & Destructor Documentation

sim::PhotonVoxelDef::PhotonVoxelDef ( double  xMin,
double  xMax,
int  xN,
double  yMin,
double  yMax,
int  yN,
double  zMin,
double  zMax,
int  z 
)

Definition at line 57 of file PhotonVoxels.cxx.

66  {
67  fxSteps = xN;
68  fySteps = yN;
69  fzSteps = zN;
70 
71 
72  fLowerCorner = TVector3(xMin,yMin,zMin);
73  fUpperCorner = TVector3(xMax,yMax,zMax);
74  }
sim::PhotonVoxelDef::PhotonVoxelDef ( )

Definition at line 77 of file PhotonVoxels.cxx.

78  {
79  }

Member Function Documentation

PhotonVoxel sim::PhotonVoxelDef::GetContainingVoxel ( TVector3  ) const
void sim::PhotonVoxelDef::GetNeighboringVoxelIDs ( const TVector3 &  v,
std::vector< NeiInfo > &  ret 
) const

Definition at line 146 of file PhotonVoxels.cxx.

References d, e, max, min, n, and w.

Referenced by phot::PhotonVisibilityService::GetVisibility(), and GetVoxelID().

147  {
148  ret.clear();
149  ret.reserve(8);
150 
151  // Position in voxel coordinates including floating point part
152  double rStepD[3];
153  for(int i = 0; i < 3; ++i){
154  // If we're outside the cuboid we have values for, return empty vector,
155  // ie failure.
156  if(v[i] < fLowerCorner[i] || v[i] > fUpperCorner[i]) return;// {};
157  // Figure out our position wrt to the centres of the voxels
158  rStepD[i] = ((v[i]-fLowerCorner[i]) / (fUpperCorner[i]-fLowerCorner[i]) * GetSteps()[i] ) - 0.5;
159  }
160 
161  // The neighbours are the 8 corners of a cube around this point
162  for(int dx = 0; dx <= 1; ++dx){
163  for(int dy = 0; dy <= 1; ++dy){
164  for(int dz = 0; dz <= 1; ++dz){
165  // The full 3D step
166  const int dr[3] = {dx, dy, dz};
167 
168  // The integer-only position of the current corner
169  int rStepI[3];
170  for(int d = 0; d < 3; ++d){
171  // Round down to get the "lower left" corner
172  rStepI[d] = int(rStepD[d]);
173  // Ensure we'll stay in-bounds
174  rStepI[d] = std::max(0, rStepI[d]);
175  rStepI[d] = std::min(rStepI[d], int(GetSteps()[d])-2);
176  // Adjust to the corner we're actually considering
177  rStepI[d] += dr[d];
178  }
179 
180  double w = 1;
181  for(int d = 0; d < 3; ++d){
182  // These expressions will interpolate when between the 8 corners,
183  // and extrapolate in the half-voxel space around the edges.
184  if(dr[d] == 0)
185  w *= 1+rStepI[d]-rStepD[d];
186  else
187  w *= 1-rStepI[d]+rStepD[d];
188  }
189 
190  const int id = (rStepI[0] +
191  rStepI[1] * (fxSteps) +
192  rStepI[2] * (fxSteps * fySteps));
193 
194  ret.emplace_back(id, w);
195  }
196  }
197  }
198 
199  // Sanity check the weights sum to 1
200  double wSum = 0;
201  for(const NeiInfo& n: ret) wSum += n.weight;
202  if(fabs(wSum-1) > 1e-3){
203  std::cout << "PhotonVoxelDef::GetNeighboringVoxelIDs(): "
204  << "Weights sum to " << wSum << " (should be 1). "
205  << "Weights are:";
206  for(const NeiInfo& n: ret) std::cout << " " << n.weight;
207  std::cout << " Aborting." << std::endl;
208  abort();
209  }
210  }
TVector3 GetSteps() const
Int_t max
Definition: plot.C:27
Float_t d
Definition: plot.C:237
Int_t min
Definition: plot.C:26
Char_t n[5]
Float_t e
Definition: plot.C:34
Float_t w
Definition: plot.C:23
PhotonVoxel sim::PhotonVoxelDef::GetPhotonVoxel ( int  ID) const

Definition at line 223 of file PhotonVoxels.cxx.

References sim::PhotonVoxel::PhotonVoxel().

Referenced by phot::CreateHybridLibrary::CreateHybridLibrary(), phot::PhotonLibraryHybrid::GetCount(), and evgen::LightSource::produce().

224  {
225  // float TempID = (float) ID;
226 
227  // Decompose ID into steps in each direction
228  int xStep = ID % fxSteps ;
229  int yStep = ((ID - xStep ) / fxSteps) % fySteps ;
230  int zStep = ((ID - xStep - (yStep * fxSteps)) / (fySteps * fxSteps)) % fzSteps ;
231 
232 
233  TVector3 VoxelSize = GetVoxelSize();
234 
235  double xMin = VoxelSize[0] * (xStep) + fLowerCorner[0];
236  double xMax = VoxelSize[0] * (xStep+1) + fLowerCorner[0];
237  double yMin = VoxelSize[1] * (yStep) + fLowerCorner[1];
238  double yMax = VoxelSize[1] * (yStep+1) + fLowerCorner[1];
239  double zMin = VoxelSize[2] * (zStep) + fLowerCorner[2];
240  double zMax = VoxelSize[2] * (zStep+1) + fLowerCorner[2];
241 
242 
243 
244  return PhotonVoxel(xMin, xMax, yMin, yMax, zMin, zMax);
245  }
TVector3 GetVoxelSize() const
TVector3 sim::PhotonVoxelDef::GetRegionLowerCorner ( ) const

Definition at line 82 of file PhotonVoxels.cxx.

Referenced by phot::PhotonLibraryAnalyzer::beginJob(), and operator==().

83  {
84  return fLowerCorner;
85  }
TVector3 sim::PhotonVoxelDef::GetRegionUpperCorner ( ) const

Definition at line 88 of file PhotonVoxels.cxx.

Referenced by phot::PhotonLibraryAnalyzer::beginJob(), and operator==().

89  {
90  return fUpperCorner;
91  }
TVector3 sim::PhotonVoxelDef::GetSteps ( ) const

Definition at line 94 of file PhotonVoxels.cxx.

Referenced by phot::PhotonLibraryAnalyzer::beginJob(), and operator==().

95  {
96  TVector3 Steps = TVector3(fxSteps, fySteps, fzSteps);
97  return Steps;
98  }
std::vector< int > sim::PhotonVoxelDef::GetVoxelCoords ( int  ID) const

Definition at line 253 of file PhotonVoxels.cxx.

Referenced by phot::PhotonLibraryAnalyzer::beginJob().

254  {
255  std::vector<int> ReturnVector;
256  ReturnVector.resize(3);
257  ReturnVector.at(0) = ID % fxSteps ;
258  ReturnVector.at(1) = ((ID - ReturnVector.at(0) ) / fxSteps) % fySteps ;
259  ReturnVector.at(2) = ((ID - ReturnVector.at(0) - (ReturnVector.at(1) * fxSteps)) / (fySteps * fxSteps)) % fzSteps ;
260  return ReturnVector;
261 
262  }
int sim::PhotonVoxelDef::GetVoxelID ( const TVector3 &  p) const
int sim::PhotonVoxelDef::GetVoxelID ( double const *  Position) const

Definition at line 122 of file PhotonVoxels.cxx.

References GetNeighboringVoxelIDs().

123  {
124  // figure out how many steps this point is in the x,y,z directions
125  int xStep = int ((Position[0]-fLowerCorner[0]) / (fUpperCorner[0]-fLowerCorner[0]) * fxSteps );
126  int yStep = int ((Position[1]-fLowerCorner[1]) / (fUpperCorner[1]-fLowerCorner[1]) * fySteps );
127  int zStep = int ((Position[2]-fLowerCorner[2]) / (fUpperCorner[2]-fLowerCorner[2]) * fzSteps );
128 
129  // check if point lies within the voxelized region
130  if((0 <= xStep) && (xStep < fxSteps) &&
131  (0 <= yStep) && (yStep < fySteps) &&
132  (0 <= zStep) && (zStep < fzSteps) ){
133  // if within bounds, generate the voxel ID
134  return (xStep
135  + yStep * (fxSteps)
136  + zStep * (fxSteps * fySteps));
137  }
138  else{
139  // out of bounds
140  return -1;
141  }
142  }
TVector3 sim::PhotonVoxelDef::GetVoxelSize ( ) const

Definition at line 213 of file PhotonVoxels.cxx.

Referenced by evgen::LightSource::LightSource().

214  {
215  TVector3 TheSize = TVector3((GetRegionUpperCorner()[0]-GetRegionLowerCorner()[0]) / fxSteps,
218  return TheSize;
219  }
TVector3 GetRegionLowerCorner() const
TVector3 GetRegionUpperCorner() const
bool sim::PhotonVoxelDef::IsLegalVoxelID ( int  ID) const

Definition at line 248 of file PhotonVoxels.cxx.

249  {
250  return (( ID > -1) && (ID<GetNVoxels()));
251  }
int GetNVoxels() const
bool sim::PhotonVoxelDef::operator!= ( const PhotonVoxelDef rhs) const
inline

Definition at line 95 of file PhotonVoxels.h.

96  { return ! ((*this)==rhs); }
bool sim::PhotonVoxelDef::operator== ( const PhotonVoxelDef rhs) const

Definition at line 101 of file PhotonVoxels.cxx.

References GetRegionLowerCorner(), GetRegionUpperCorner(), and GetSteps().

102  {
103  return ( ( GetRegionUpperCorner() == right.GetRegionUpperCorner() ) &&
104  ( GetRegionLowerCorner() == right.GetRegionLowerCorner() ) &&
105  ( GetSteps() == right.GetSteps()) );
106  }
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:112
TVector3 GetSteps() const
TVector3 GetRegionLowerCorner() const
TVector3 GetRegionUpperCorner() const

Member Data Documentation

TVector3 sim::PhotonVoxelDef::fLowerCorner
private

Definition at line 57 of file PhotonVoxels.h.

TVector3 sim::PhotonVoxelDef::fUpperCorner
private

Definition at line 58 of file PhotonVoxels.h.

int sim::PhotonVoxelDef::fxSteps
private

Definition at line 59 of file PhotonVoxels.h.

int sim::PhotonVoxelDef::fySteps
private

Definition at line 60 of file PhotonVoxels.h.

int sim::PhotonVoxelDef::fzSteps
private

Definition at line 61 of file PhotonVoxels.h.


The documentation for this class was generated from the following files: