All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbncode/sbncode/OpT0Finder/flashmatch/Base/FMWKTools/PhotonVoxels.cxx
Go to the documentation of this file.
1 
2 #include "PhotonVoxels.h"
3 
4 #include "iostream"
5 
6 
7 
8 namespace sim {
9 
10 
11  // PhotonVoxel class
12  //----------------------------------------------------------------------------
14  double xMax,
15  double yMin,
16  double yMax,
17  double zMin,
18  double zMax,
19  int N)
20  {
21  xVoxelMin = xMin;
22  xVoxelMax = xMax;
23  yVoxelMin = yMin;
24  yVoxelMax = yMax;
25  zVoxelMin = zMin;
26  zVoxelMax = zMax;
27  NPhotons = N;
28  }
29 
30  //----------------------------------------------------------------------------
32  {
33  }
34 
35  //----------------------------------------------------------------------------
36  TVector3 PhotonVoxel::GetLowerCorner() const
37  {
38  TVector3 LowerCorner = TVector3(xVoxelMin, yVoxelMin, zVoxelMin);
39  return LowerCorner;
40  }
41 
42 
43  //----------------------------------------------------------------------------
44  TVector3 PhotonVoxel::GetUpperCorner() const
45  {
46  TVector3 UpperCorner = TVector3(xVoxelMax, yVoxelMax, zVoxelMax);
47  return UpperCorner;
48  }
49 
50 
51  //----------------------------------------------------------------------------
52  TVector3 PhotonVoxel::GetCenter() const
53  {
54  TVector3 Center = TVector3((xVoxelMin+xVoxelMax)/2.0, (yVoxelMin+yVoxelMax)/2.0, (zVoxelMin+zVoxelMax)/2.0);
55  return Center;
56  }
57 
58 
59  //----------------------------------------------------------------------------
60  PhotonVoxelDef::PhotonVoxelDef(double xMin,
61  double xMax,
62  int xN,
63  double yMin,
64  double yMax,
65  int yN,
66  double zMin,
67  double zMax,
68  int zN)
69  {
70  fxSteps = xN;
71  fySteps = yN;
72  fzSteps = zN;
73 
74 
75  fLowerCorner = TVector3(xMin,yMin,zMin);
76  fUpperCorner = TVector3(xMax,yMax,zMax);
77  }
78 
79  //----------------------------------------------------------------------------
81  {
82  }
83 
84  //----------------------------------------------------------------------------
86  {
87  return fLowerCorner;
88  }
89 
90  //----------------------------------------------------------------------------
92  {
93  return fUpperCorner;
94  }
95 
96  //----------------------------------------------------------------------------
97  TVector3 PhotonVoxelDef::GetSteps() const
98  {
99  TVector3 Steps = TVector3(fxSteps, fySteps, fzSteps);
100  return Steps;
101  }
102 
103  //----------------------------------------------------------------------------
104  bool PhotonVoxelDef::operator==(const PhotonVoxelDef & right) const
105  {
106  return ( ( GetRegionUpperCorner() == right.GetRegionUpperCorner() ) &&
107  ( GetRegionLowerCorner() == right.GetRegionLowerCorner() ) &&
108  ( GetSteps() == right.GetSteps()) );
109  }
110 
111  //----------------------------------------------------------------------------
112  int PhotonVoxelDef::GetNVoxels() const
113  {
114  return fxSteps * fySteps * fzSteps;
115  }
116 
117  //----------------------------------------------------------------------------
118  int PhotonVoxelDef::GetVoxelID(TVector3 Position) const
119  {
120 
121  // figure out how many steps this point is in the x,y,z directions
122  int xStep = int ((Position[0]-fLowerCorner[0]) / (fUpperCorner[0]-fLowerCorner[0]) * fxSteps );
123  int yStep = int ((Position[1]-fLowerCorner[1]) / (fUpperCorner[1]-fLowerCorner[1]) * fySteps );
124  int zStep = int ((Position[2]-fLowerCorner[2]) / (fUpperCorner[2]-fLowerCorner[2]) * fzSteps );
125 
126  int ID;
127 
128  // check if point lies within the voxelized region
129  if((0 <= xStep) && (xStep < fxSteps) &&
130  (0 <= yStep) && (yStep < fySteps) &&
131  (0 <= zStep) && (zStep < fzSteps) )
132  {
133  // if within bounds, generate the voxel ID
134  ID = xStep
135  + yStep * (fxSteps)
136  + zStep * (fxSteps * fySteps);
137  }
138  else
139  {
140  // if out of bounds, print warning and return -1
141  ID = -1;
142  }
143 
144  return ID;
145 
146  }
147 
148  //----------------------------------------------------------------------------
149  int PhotonVoxelDef::GetVoxelID(double x, double y, double z) const
150  {
151 
152  // figure out how many steps this point is in the x,y,z directions
153  int xStep = int ((x-fLowerCorner[0]) / (fUpperCorner[0]-fLowerCorner[0]) * fxSteps );
154  int yStep = int ((y-fLowerCorner[1]) / (fUpperCorner[1]-fLowerCorner[1]) * fySteps );
155  int zStep = int ((z-fLowerCorner[2]) / (fUpperCorner[2]-fLowerCorner[2]) * fzSteps );
156 
157  int ID;
158 
159  // check if point lies within the voxelized region
160  if((0 <= xStep) && (xStep < fxSteps) &&
161  (0 <= yStep) && (yStep < fySteps) &&
162  (0 <= zStep) && (zStep < fzSteps) )
163  {
164  // if within bounds, generate the voxel ID
165  ID = xStep
166  + yStep * (fxSteps)
167  + zStep * (fxSteps * fySteps);
168  }
169  else
170  {
171  // if out of bounds, print warning and return -1
172  ID = -1;
173  }
174 
175  return ID;
176 
177  }
178 
179  int PhotonVoxelDef::GetVoxelID(double* Position) const
180  {
181 
182  // figure out how many steps this point is in the x,y,z directions
183  int xStep = int ((Position[0]-fLowerCorner[0]) / (fUpperCorner[0]-fLowerCorner[0]) * fxSteps );
184  int yStep = int ((Position[1]-fLowerCorner[1]) / (fUpperCorner[1]-fLowerCorner[1]) * fySteps );
185  int zStep = int ((Position[2]-fLowerCorner[2]) / (fUpperCorner[2]-fLowerCorner[2]) * fzSteps );
186 
187  int ID;
188 
189  // check if point lies within the voxelized region
190  if((0 <= xStep) && (xStep < fxSteps) &&
191  (0 <= yStep) && (yStep < fySteps) &&
192  (0 <= zStep) && (zStep < fzSteps) )
193  {
194  // if within bounds, generate the voxel ID
195  ID = xStep
196  + yStep * (fxSteps)
197  + zStep * (fxSteps * fySteps);
198  }
199  else
200  {
201  // if out of bounds, print warning and return -1
202  ID = -1;
203  }
204 
205  return ID;
206 
207  }
208 
209  //----------------------------------------------------------------------------
210  TVector3 PhotonVoxelDef::GetVoxelSize() const
211  {
212  TVector3 TheSize = TVector3((GetRegionUpperCorner()[0]-GetRegionLowerCorner()[0]) / fxSteps,
215  return TheSize;
216  }
217 
218 
219  //----------------------------------------------------------------------------
220  PhotonVoxel PhotonVoxelDef::GetPhotonVoxel(int ID) const
221  {
222  // float TempID = (float) ID;
223 
224  // Decompose ID into steps in each direction
225  int xStep = ID % fxSteps ;
226  int yStep = ((ID - xStep ) / fxSteps) % fySteps ;
227  int zStep = ((ID - xStep - (yStep * fxSteps)) / (fySteps * fxSteps)) % fzSteps ;
228 
229 
230  TVector3 VoxelSize = GetVoxelSize();
231 
232  double xMin = VoxelSize[0] * (xStep) + fLowerCorner[0];
233  double xMax = VoxelSize[0] * (xStep+1) + fLowerCorner[0];
234  double yMin = VoxelSize[1] * (yStep) + fLowerCorner[1];
235  double yMax = VoxelSize[1] * (yStep+1) + fLowerCorner[1];
236  double zMin = VoxelSize[2] * (zStep) + fLowerCorner[2];
237  double zMax = VoxelSize[2] * (zStep+1) + fLowerCorner[2];
238 
239 
240 
241  return PhotonVoxel(xMin, xMax, yMin, yMax, zMin, zMax);
242  }
243 
244  //----------------------------------------------------------------------------
245  bool PhotonVoxelDef::IsLegalVoxelID(int ID) const
246  {
247  return (( ID > -1) && (ID<GetNVoxels()));
248  }
249 
250  std::vector<int> PhotonVoxelDef::GetVoxelCoords(int ID) const
251  {
252  std::vector<int> ReturnVector;
253  ReturnVector.resize(3);
254  ReturnVector.at(0) = ID % fxSteps ;
255  ReturnVector.at(1) = ((ID - ReturnVector.at(0) ) / fxSteps) % fySteps ;
256  ReturnVector.at(2) = ((ID - ReturnVector.at(0) - (ReturnVector.at(1) * fxSteps)) / (fySteps * fxSteps)) % fzSteps ;
257  return ReturnVector;
258 
259  }
260 }
process_name opflash particleana ie ie ie z
Vector GetVoxelSize() const
Returns a vector describing the span of a single voxel in x, y an z [cm].
process_name opflash particleana ie x
walls no right
Definition: selectors.fcl:105
std::array< unsigned int, 3U > GetSteps() const
Returns the number of voxels along each of the three dimensions.
bool operator==(const PhotonVoxelDef &rhs) const
int GetVoxelID(Point const &p) const
Returns the ID of the voxel containing p, or -1 if none.
unsigned int GetNVoxels() const
Returns the total number of voxels in the volume.
process_name opflash particleana ie ie y
decltype(auto) GetRegionLowerCorner() const
Returns the volume vertex (type Point) with the lowest coordinates.
Point GetCenter() const
Returns the center of the voxel (type Point).
decltype(auto) GetLowerCorner() const
Returns the voxel vertex (type Point) with the lowest coordinates.
decltype(auto) GetRegionUpperCorner() const
Returns the volume vertex (type Point) with the highest coordinates.
std::array< int, 3U > GetVoxelCoords(int ID) const
process_name largeant stream1 can override from command line with o or output physics producers generator N
decltype(auto) GetUpperCorner() const
Returns the voxel vertex (type Point) with the highest coordinates.