@@ -194,16 +194,17 @@ BandDetector::setEnergy(const double ES,const double EE)
194
194
}
195
195
196
196
void
197
- BandDetector::setDataSize (const int Hpts,const int Vpts,
198
- const int Epts)
197
+ BandDetector::setDataSize (const size_t Hpts,const size_t Vpts,
198
+ const size_t Epts)
199
199
/* !
200
200
Set the data Size
201
201
\param Hpts :: Horizontal size
202
202
\param Vpts :: Vertical size
203
203
\param Epts :: Energy size
204
204
*/
205
205
{
206
- if (Hpts>0 && Vpts>0 && (Hpts!=nH || Vpts!=nV) )
206
+ if (Hpts>0 && Vpts>0 &&
207
+ (Hpts!=nH || Vpts!=nV || Epts!=nE) )
207
208
{
208
209
nH=Hpts;
209
210
nV=Vpts;
@@ -227,7 +228,7 @@ BandDetector::getAxis() const
227
228
228
229
int
229
230
BandDetector::calcCell (const MonteCarlo::particle& N,
230
- int & NH,int & NV) const
231
+ size_t & NH,size_t & NV) const
231
232
/* !
232
233
Calc a cell
233
234
Tracks from the point to the detector.
@@ -242,19 +243,24 @@ BandDetector::calcCell(const MonteCarlo::particle& N,
242
243
243
244
const double OdotN=N.Pos .dotProd (PlnNorm);
244
245
const double DdotN=N.uVec .dotProd (PlnNorm);
245
- if (fabs (DdotN)<Geometry::parallelTol) // Plane and line parallel
246
+ if (std::abs (DdotN)<Geometry::parallelTol) // Plane and line parallel
246
247
return 0 ;
247
248
const double u=(PlnDist-OdotN)/DdotN;
248
249
Geometry::Vec3D Pnt=N.Pos +N.uVec *u;
249
250
// Now determine if Pnt is within detector:
250
251
Pnt-=(Cent-H*0.5 *hSize-V*0.5 *vSize);
251
- NH=static_cast <int >(nH*Pnt.dotProd (H)/hSize);
252
- NV=static_cast <int >(nV*Pnt.dotProd (V)/vSize);
252
+ const double hFrac (Pnt.dotProd (H)/hSize);
253
+ const double vFrac (Pnt.dotProd (V)/vSize);
254
+ if (hFrac<0.0 || hFrac>=1.0 || vFrac<0.0 || vFrac>1.0 )
255
+ return 0 ;
256
+ NH=static_cast <size_t >(static_cast <double >(nH)*hFrac);
257
+ NV=static_cast <size_t >(static_cast <double >(nV)*vFrac);
258
+
253
259
ELog::EM<<" Point == " <<Pnt<<" (" <<NH<<" ," <<NV<<" )" <<ELog::endDebug;
254
260
ELog::EM<<" Det == " <<Cent<<" (" <<H<<" ," <<V<<" )::" <<PlnNorm<<ELog::endDebug;
255
261
ELog::EM<<" U == " <<u<<" " <<PlnDist<<" " <<hSize<<" " <<vSize<<ELog::endDebug;
256
262
ELog::EM<<ELog::endDebug;
257
- return (NH< 0 || NV< 0 || NH>=nH || NV>=nV) ? 0 : 1 ;
263
+ return 1 ;
258
264
}
259
265
260
266
@@ -278,24 +284,23 @@ BandDetector::addEvent(const MonteCarlo::particle& N)
278
284
Geometry::Vec3D Pnt=N.Pos +N.uVec *u;
279
285
// Now determine if Pnt is within detector:
280
286
Pnt-=(Cent-H*(hSize/2.0 )-V*(vSize/2.0 ));
281
- const int hpt=static_cast <int >(static_cast <double >(nH)*
282
- Pnt.dotProd (H)/hSize);
283
- const int vpt=static_cast <int >(nV*Pnt.dotProd (V)/vSize);
284
- if (hpt<0 || vpt<0 || hpt>=nH || vpt>=nV) return ;
287
+ const size_t hpt=static_cast <size_t >
288
+ (static_cast <double >(nH)*Pnt.dotProd (H)/hSize);
289
+ const size_t vpt=static_cast <size_t >
290
+ (static_cast <double >(nV)*Pnt.dotProd (V)/vSize);
291
+ if (hpt>=nH || vpt>=nV) return ;
285
292
// Scale for (i) distance to scattering point:
286
293
// (ii) solid angle
287
294
// Distance is u + travel
288
- const long int ePoint=calcWavePoint (N.wavelength );
289
- if (ePoint>=0 || ePoint<static_cast <long int >(EGrid.size ())-1 )
290
- {
291
- EData.get ()[vpt][hpt][ePoint]+=
292
- N.weight /((N.travel +u)*(N.travel +u)*fabs (DdotN));
293
- nps++;
294
- }
295
+ const size_t ePoint=calcWavePoint (N.wavelength );
296
+ EData.get ()[vpt][hpt][ePoint]+=
297
+ N.weight /((N.travel +u)*(N.travel +u)*std::abs (DdotN));
298
+ nps++;
299
+
295
300
return ;
296
301
}
297
302
298
- long int
303
+ size_t
299
304
BandDetector::calcWavePoint (const double W) const
300
305
/* !
301
306
Given the wavelength calculate the
@@ -308,16 +313,11 @@ BandDetector::calcWavePoint(const double W) const
308
313
309
314
if (EGrid.empty ()) return 0 ;
310
315
const double E ((0.5 *RefCon::h2_mneV*1e20 )/(W*W));
311
- const long int res=indexPos (EGrid,E);
312
- if (res<0 || res>=static_cast <long int >(EData.shape ()[0 ]))
313
- {
314
- ELog::EM<<" Bins failed on : " <<W<<" " <<
315
- E<<" == " <<EGrid.front ()<<" " <<EGrid.back ()<<ELog::endCrit;
316
- }
316
+ const size_t res=rangePos (EGrid,E);
317
317
return res;
318
318
}
319
319
320
- long int
320
+ size_t
321
321
BandDetector::calcEnergyPoint (const double E) const
322
322
/* !
323
323
Given the wavelength calculate the
@@ -327,7 +327,7 @@ BandDetector::calcEnergyPoint(const double E) const
327
327
*/
328
328
{
329
329
if (EGrid.empty ()) return 0 ;
330
- return indexPos (EGrid,E);
330
+ return rangePos (EGrid,E);
331
331
}
332
332
333
333
double
@@ -392,9 +392,9 @@ BandDetector::write(std::ostream& OX) const
392
392
OX<<" #hvn " <<nH<<" " <<nV<<" from " <<nps<<std::endl;
393
393
OX<<" #cvh " <<Cent<<" : " <<H*hSize<<" : " <<V*vSize<<std::endl;
394
394
395
- for (int i=0 ;i<nV;i++)
395
+ for (size_t i=0 ;i<nV;i++)
396
396
{
397
- for (int j=0 ;j<nH;j++)
397
+ for (size_t j=0 ;j<nH;j++)
398
398
{
399
399
const double E=EData.get ()[i][j][EBin];
400
400
OX<<E<<" " ;
0 commit comments