LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar::example::PointIsolationAlg< Coord > Class Template Reference

Algorithm to detect isolated space points. More...

#include "PointIsolationAlg.h"

Classes

struct  Configuration_t
 Type containing all configuration parameters of the algorithm. More...
 

Public Types

using Coord_t = Coord
 Type of coordinate. More...
 
using Range_t = CoordRange< Coord_t >
 

Public Member Functions

template<typename PointIter >
std::vector< size_t > removeIsolatedPoints (PointIter begin, PointIter end) const
 Returns the set of points that are not isolated. More...
 
template<typename Cont >
std::vector< size_t > removeIsolatedPoints (Cont const &points) const
 Returns the set of points that are not isolated. More...
 
template<typename PointIter >
std::vector< size_t > bruteRemoveIsolatedPoints (PointIter begin, PointIter end) const
 Brute-force reference algorithm. More...
 
template<typename PointIter >
Coord computeCellSize () const
 

Static Public Member Functions

static Coord_t maximumOptimalCellSize (Coord_t radius)
 Returns the maximum optimal cell size when using a isolation radius. More...
 

Private Types

using Indexer_t = util::GridContainer3DIndices
 type managing cell indices More...
 
using NeighAddresses_t = std::vector< Indexer_t::CellIndexOffset_t >
 type of neighbourhood cell offsets More...
 
template<typename PointIter >
using Partition_t = SpacePartition< PointIter >
 
template<typename PointIter >
using Point_t = decltype(*PointIter())
 

Private Member Functions

template<typename PointIter = std::array<double, 3> const*>
Coord_t computeCellSize () const
 Computes the cell size to be used. More...
 
NeighAddresses_t buildNeighborhood (Indexer_t const &indexer, unsigned int neighExtent) const
 Returns a list of cell offsets for the neighbourhood of given radius. More...
 
template<typename PointIter >
bool isPointIsolatedFrom (Point_t< PointIter > const &point, typename Partition_t< PointIter >::Cell_t const &otherPoints) const
 Returns whether a point is isolated with respect to all the others. More...
 
template<typename PointIter >
bool isPointIsolatedWithinNeighborhood (Partition_t< PointIter > const &partition, Indexer_t::CellIndex_t cellIndex, Point_t< PointIter > const &point, NeighAddresses_t const &neighList) const
 Returns whether a point is isolated in the specified neighbourhood. More...
 
template<typename Point >
bool closeEnough (Point const &A, Point const &B) const
 Returns whether A and B are close enough to be considered non-isolated. More...
 

Static Private Member Functions

static std::string rangeString (Coord_t from, Coord_t to)
 Helper function. Returns a string "(\<from\> to \<to\>)" More...
 
static std::string rangeString (Range_t range)
 Helper function. Returns a string "(\<from\> to \<to\>)" More...
 

Private Attributes

Configuration_t config
 all configuration data More...
 

Configuration

 PointIsolationAlg (Configuration_t const &first_config)
 Constructor with configuration validation. More...
 
void reconfigure (Configuration_t const &new_config)
 
Configuration_tconfiguration () const
 
static void validateConfiguration (Configuration_t const &config)
 

Detailed Description

template<typename Coord = double>
class lar::example::PointIsolationAlg< Coord >

Algorithm to detect isolated space points.

Template Parameters
Coordtype of the coordinate
See also
RemoveIsolatedSpacePoints example overview

This algorithm returns a selection of the input points which are not isolated. Point $ i $ is defined as isolated if: $ \min \left\{ \left| \vec{r}_{i} - \vec{r_{j}} \right| \right\}_{i \neq j} < R $ where $ \vec{r_{k}} $ describes the position of the point $ k $ in space and $ R $ is the isolation radius.

This class must be configured by providing a complete Configuration_t object. Configuration can be changed at any time after that.

The configuration information (Configuration_t) defines the volume the points span and the square of the isolation radius. The information on the volume may be used to optimise the algorithm, and it is not checked. If that information is wrong (that means input points lie outside that volume), the result is undefined. No check is automatically performed to assess if the configuration is valid.

The algorithm can be run on any collection of points, as long as the point class supports the PositionExtractor class. A typical cycle of use is:

// creation and configuration
lar::examples::PointIsolationAlg<float>::Configuration_t config;
config.rangeX = { -1., 1. };
config.rangeY = { -1., 1. };
config.rangeZ = { -5., 5. };
config.radius2 = 0.25;
lar::examples::PointIsolationAlg<float> algo(config);
// preparation/retrieval of input
std::vector<std::array<float, 3>> points;
// points are filled here
// execution
std::vector<size_t> indices
= algo.removeIsolatedPoints(points.begin(), points.end());
// utilization of the result;
// - e.g., create a collection of non-isolated points...
std::vector<std::array<float, 3>> nonIsolatedPoints;
nonIsolatedPoints.reserve(indices.size());
for (size_t index: indices)
nonIsolatedPoints.push_back(points[index]);
// - ... or their pointers
std::vector<std::array<float, 3> const*> nonIsolatedPointPtrs;
nonIsolatedPointPtrs.reserve(indices.size());
for (size_t index: indices)
nonIsolatedPointPtrs.push_back(&(points[index]));

The point type here is std::array<float, 3>, for which a lar::examples::PositionExtractor<std::array<float, 3>> is defined in this same library. The algorithm can be executed multiple times, and the configuration can be changed at any time (reconfigure()).

Validation of the configuration is optional, and needs to be explicitly called if desired (validateConfiguration()).

Description of the algorithm

The basic method to determine the isolation of a point is by brute force, by computing the distance with all others and, as soon as one of them is found too close, declare the point non-isolated.

A refinement is implemented: the points are grouped in cubic "cells" and points in cells that are farther than isolation radius are not checked against each other. This requires some memory to allocate the structure, that can become huge. The maximum memory parameter keeps this sane.

Other refinements are not implemented. When a point is found non-isolated also the point that makes it non-isolated should also be marked so. Cell radius might be tuned to be smaller. Some of the neighbour cells may be too far and should not be checked. The grid allocates a vector for each cell, whether it's empty or not; using a sparse structure might reduce the memory; also if the grid contains pointers to vectors instead of vectors, and the grid is very sparse, there should still be some memory saving.

Definition at line 128 of file PointIsolationAlg.h.

Member Typedef Documentation

template<typename Coord = double>
using lar::example::PointIsolationAlg< Coord >::Coord_t = Coord

Type of coordinate.

Definition at line 132 of file PointIsolationAlg.h.

template<typename Coord = double>
using lar::example::PointIsolationAlg< Coord >::Indexer_t = util::GridContainer3DIndices
private

type managing cell indices

Definition at line 242 of file PointIsolationAlg.h.

template<typename Coord = double>
using lar::example::PointIsolationAlg< Coord >::NeighAddresses_t = std::vector<Indexer_t::CellIndexOffset_t>
private

type of neighbourhood cell offsets

Definition at line 245 of file PointIsolationAlg.h.

template<typename Coord = double>
template<typename PointIter >
using lar::example::PointIsolationAlg< Coord >::Partition_t = SpacePartition<PointIter>
private

Definition at line 248 of file PointIsolationAlg.h.

template<typename Coord = double>
template<typename PointIter >
using lar::example::PointIsolationAlg< Coord >::Point_t = decltype(*PointIter())
private

Definition at line 251 of file PointIsolationAlg.h.

template<typename Coord = double>
using lar::example::PointIsolationAlg< Coord >::Range_t = CoordRange<Coord_t>

Definition at line 133 of file PointIsolationAlg.h.

Constructor & Destructor Documentation

template<typename Coord = double>
lar::example::PointIsolationAlg< Coord >::PointIsolationAlg ( Configuration_t const &  first_config)
inline

Constructor with configuration validation.

Parameters
first_configconfiguration parameter structure

For the configuration, see SpacePointIsolationAlg documentation. No validation is performed on the configuration.

Definition at line 156 of file PointIsolationAlg.h.

157  : config(first_config)
158  {}
Configuration_t config
all configuration data

Member Function Documentation

template<typename Coord >
template<typename PointIter >
std::vector< size_t > lar::example::PointIsolationAlg< Coord >::bruteRemoveIsolatedPoints ( PointIter  begin,
PointIter  end 
) const

Brute-force reference algorithm.

Template Parameters
PointIterrandom access iterator to a point type
Parameters
beginiterator to the first point to be considered
enditerator after the last point to be considered
Returns
a list of indices of non-isolated points in the input range
See also
removeIsolatedPoints

This algorithm executes the task in a $ N^{2} $ way, slow and supposedly reliable. The interface is the same as removeIsolatedPoints. Use this only for tests.

Definition at line 576 of file PointIsolationAlg.h.

References lar::example::PointIsolationAlg< Coord >::closeEnough(), and evd::details::end().

Referenced by lar::example::PointIsolationAlg< Coord >::isPointIsolatedWithinNeighborhood(), and lar::example::PointIsolationAlg< Coord >::removeIsolatedPoints().

577 {
578  //
579  // reference implementation: brute force dumb one
580  //
581 
582  std::vector<size_t> nonIsolated;
583 
584  size_t i = 0;
585  for (auto it = begin; it != end; ++it, ++i) {
586 
587  for (auto ioth = begin; ioth != end; ++ioth) {
588  if (it == ioth) continue;
589 
590  if (closeEnough(*it, *ioth)) {
591  nonIsolated.push_back(i);
592  break;
593  }
594 
595  } // for oth
596 
597  } // for (it)
598 
599  return nonIsolated;
600 } // lar::example::PointIsolationAlg::bruteRemoveIsolatedPoints()
bool closeEnough(Point const &A, Point const &B) const
Returns whether A and B are close enough to be considered non-isolated.
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
template<typename Coord >
lar::example::PointIsolationAlg< Coord >::NeighAddresses_t lar::example::PointIsolationAlg< Coord >::buildNeighborhood ( Indexer_t const &  indexer,
unsigned int  neighExtent 
) const
private

Returns a list of cell offsets for the neighbourhood of given radius.

Definition at line 483 of file PointIsolationAlg.h.

References util::details::GridContainerIndicesBase< DIMS >::offset().

Referenced by lar::example::PointIsolationAlg< Coord >::computeCellSize(), and lar::example::PointIsolationAlg< Coord >::removeIsolatedPoints().

484 {
485  unsigned int const neighSize = 1 + 2 * neighExtent;
486  NeighAddresses_t neighList;
487  neighList.reserve(neighSize * neighSize * neighSize - 1);
488 
489  using CellID_t = Indexer_t::CellID_t;
490  using CellDimIndex_t = Indexer_t::CellDimIndex_t;
491 
492  //
493  // optimisation (speed): reshape the neighbourhood
494  // neighbourhood might cut out cells close to the vertices
495  //
496 
497  // TODO
498 
499  CellDimIndex_t const ext = neighExtent; // convert into the right signedness
500 
501  CellID_t center{{ 0, 0, 0 }}, cellID;
502  for (CellDimIndex_t ixOfs = -ext; ixOfs <= ext; ++ixOfs) {
503  cellID[0] = ixOfs;
504  for (CellDimIndex_t iyOfs = -ext; iyOfs <= ext; ++iyOfs) {
505  cellID[1] = iyOfs;
506  for (CellDimIndex_t izOfs = -ext; izOfs <= ext; ++izOfs) {
507  if ((ixOfs == 0) && (iyOfs == 0) && (izOfs == 0)) continue;
508  cellID[2] = izOfs;
509 
510  neighList.push_back(indexer.offset(center, cellID));
511 
512  } // for ixOfs
513  } // for iyOfs
514  } // for izOfs
515 
516  return neighList;
517 } // lar::example::PointIsolationAlg<Coord>::buildNeighborhood()
CellIndexOffset_t CellDimIndex_t
type of difference between indices along a dimension
std::array< CellDimIndex_t, dims()> CellID_t
type of cell coordinate (x, y, z)
std::vector< Indexer_t::CellIndexOffset_t > NeighAddresses_t
type of neighbourhood cell offsets
template<typename Coord >
template<typename Point >
bool lar::example::PointIsolationAlg< Coord >::closeEnough ( Point const &  A,
Point const &  B 
) const
private

Returns whether A and B are close enough to be considered non-isolated.

Definition at line 607 of file PointIsolationAlg.h.

References lar::example::details::extractPositionX(), lar::example::details::extractPositionY(), lar::example::details::extractPositionZ(), lar::example::PointIsolationAlg< Coord >::Configuration_t::radius2, and lar::example::PointIsolationAlg< Coord >::rangeString().

Referenced by lar::example::PointIsolationAlg< Coord >::bruteRemoveIsolatedPoints(), and lar::example::PointIsolationAlg< Coord >::isPointIsolatedFrom().

608 {
609  return cet::sum_of_squares(
613  ) <= config.radius2;
614 } // lar::example::PointIsolationAlg<Point>::closeEnough()
Int_t B
Definition: plot.C:25
Coord_t radius2
square of isolation radius [cm^2]
auto extractPositionY(Point const &point)
auto extractPositionX(Point const &point)
Configuration_t config
all configuration data
auto extractPositionZ(Point const &point)
template<typename Coord = double>
template<typename PointIter = std::array<double, 3> const*>
Coord_t lar::example::PointIsolationAlg< Coord >::computeCellSize ( ) const
private

Computes the cell size to be used.

template<typename Coord = double>
template<typename PointIter >
Coord lar::example::PointIsolationAlg< Coord >::computeCellSize ( ) const

Definition at line 440 of file PointIsolationAlg.h.

References lar::example::PointIsolationAlg< Coord >::buildNeighborhood(), lar::example::details::diceVolume(), lar::example::PointIsolationAlg< Coord >::maximumOptimalCellSize(), lar::example::PointIsolationAlg< Coord >::Configuration_t::maxMemory, R, lar::example::PointIsolationAlg< Coord >::Configuration_t::radius2, lar::example::PointIsolationAlg< Coord >::Configuration_t::rangeX, lar::example::PointIsolationAlg< Coord >::Configuration_t::rangeY, and lar::example::PointIsolationAlg< Coord >::Configuration_t::rangeZ.

440  {
441 
442  Coord_t const R = std::sqrt(config.radius2);
443 
444  // maximum: the maximum distance between two points in the cell (that is,
445  // the diagonal of the cell) must be no larger than the isolation radius R;
446  // minimum: needs tuning
447  Coord_t cellSize = maximumOptimalCellSize(R); // try the minimum for now
448 
449  //
450  // optimisation (memory): determine minimum size of box
451  //
452 
453  // TODO
454 
455  if (config.maxMemory == 0) return cellSize;
456 
457  do {
458  std::array<size_t, 3> partition = details::diceVolume(
459  CoordRangeCells<Coord_t>{ config.rangeX, cellSize },
460  CoordRangeCells<Coord_t>{ config.rangeY, cellSize },
461  CoordRangeCells<Coord_t>{ config.rangeZ, cellSize }
462  );
463 
464  size_t const nCells = partition[0] * partition[1] * partition[2];
465  if (nCells <= 1) break; // we can't reduce it any further
466 
467  // is memory low enough?
468  size_t const memory
469  = nCells * sizeof(typename SpacePartition<PointIter>::Cell_t);
470  if (memory < config.maxMemory) break;
471 
472  cellSize *= 2;
473  } while (true);
474 
475  return cellSize;
476 } // lar::example::PointIsolationAlg<Coord>::computeCellSize()
Coord Coord_t
Type of coordinate.
Coord_t radius2
square of isolation radius [cm^2]
size_t maxMemory
grid smaller than this number of bytes (100 MiB)
Range_t rangeY
range in Y of the covered volume
Range_t rangeX
range in X of the covered volume
std::array< size_t, 3 > diceVolume(CoordRangeCells< Coord > const &rangeX, CoordRangeCells< Coord > const &rangeY, CoordRangeCells< Coord > const &rangeZ)
Returns the dimensions of a grid diced with the specified size.
Double_t R
typename Grid_t::Cell_t Cell_t
type of cell
Range_t rangeZ
range in Z of the covered volume
Configuration_t config
all configuration data
static Coord_t maximumOptimalCellSize(Coord_t radius)
Returns the maximum optimal cell size when using a isolation radius.
template<typename Coord = double>
Configuration_t& lar::example::PointIsolationAlg< Coord >::configuration ( ) const
inline

Returns a constant reference to the current configuration

See also
reconfigure()

Definition at line 169 of file PointIsolationAlg.h.

References evd::details::begin(), lar::example::PointIsolationAlg< Coord >::config, evd::details::end(), and lar::example::PointIsolationAlg< Coord >::removeIsolatedPoints().

169 { return config; }
Configuration_t config
all configuration data
template<typename Coord >
template<typename PointIter >
bool lar::example::PointIsolationAlg< Coord >::isPointIsolatedFrom ( Point_t< PointIter > const &  point,
typename Partition_t< PointIter >::Cell_t const &  otherPoints 
) const
private

Returns whether a point is isolated with respect to all the others.

Definition at line 523 of file PointIsolationAlg.h.

References lar::example::PointIsolationAlg< Coord >::closeEnough().

527 {
528 
529  for (auto const& otherPointPtr: otherPoints) {
530  // make sure that we did not compare the point with itself
531  if (closeEnough(point, *otherPointPtr) && (&point != &*otherPointPtr))
532  return false;
533  }
534 
535  return true;
536 
537 } // lar::example::PointIsolationAlg<Coord>::isPointIsolatedFrom()
bool closeEnough(Point const &A, Point const &B) const
Returns whether A and B are close enough to be considered non-isolated.
template<typename Coord >
template<typename PointIter >
bool lar::example::PointIsolationAlg< Coord >::isPointIsolatedWithinNeighborhood ( Partition_t< PointIter > const &  partition,
Indexer_t::CellIndex_t  cellIndex,
Point_t< PointIter > const &  point,
NeighAddresses_t const &  neighList 
) const
private

Returns whether a point is isolated in the specified neighbourhood.

Definition at line 543 of file PointIsolationAlg.h.

References lar::example::PointIsolationAlg< Coord >::bruteRemoveIsolatedPoints(), and lar::example::SpacePartition< PointIter >::has().

Referenced by lar::example::PointIsolationAlg< Coord >::removeIsolatedPoints().

549 {
550 
551  // check in all cells of the neighbourhood
552  for (Indexer_t::CellIndexOffset_t neighOfs: neighList) {
553 
554  //
555  // optimisation (speed): have neighbour offsets so that the invalid ones
556  // are all at the beginning and at the end, so that skipping is faster
557  //
558 
559  if (!partition.has(cellIndex + neighOfs)) continue;
560  auto const& neighCellPoints = partition[cellIndex + neighOfs];
561 
562  if (!isPointIsolatedFrom<PointIter>(point, neighCellPoints)) return false;
563 
564  } // for neigh cell
565 
566  return true;
567 
568 } // lar::example::PointIsolationAlg<Coord>::isPointIsolatedWithinNeighborhood()
std::ptrdiff_t CellIndexOffset_t
type of difference between indices
template<typename Coord = double>
static Coord_t lar::example::PointIsolationAlg< Coord >::maximumOptimalCellSize ( Coord_t  radius)
inlinestatic

Returns the maximum optimal cell size when using a isolation radius.

Definition at line 236 of file PointIsolationAlg.h.

Referenced by lar::example::PointIsolationAlg< Coord >::computeCellSize(), and lar::example::PointIsolationAlg< Coord >::removeIsolatedPoints().

237  { return radius / std::sqrt(3.); }
Double_t radius
template<typename Coord >
std::string lar::example::PointIsolationAlg< Coord >::rangeString ( Coord_t  from,
Coord_t  to 
)
staticprivate

Helper function. Returns a string "(\<from\> to \<to\>)"

Definition at line 620 of file PointIsolationAlg.h.

References util::flags::to_string().

Referenced by lar::example::PointIsolationAlg< Coord >::closeEnough(), lar::example::PointIsolationAlg< Coord >::rangeString(), and lar::example::PointIsolationAlg< Coord >::validateConfiguration().

621  { return "(" + std::to_string(from) + " to " + std::to_string(to) + ")"; }
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
Definition: BitMask.h:187
template<typename Coord = double>
static std::string lar::example::PointIsolationAlg< Coord >::rangeString ( Range_t  range)
inlinestaticprivate

Helper function. Returns a string "(\<from\> to \<to\>)"

Definition at line 291 of file PointIsolationAlg.h.

References lar::example::CoordRange< Coord >::lower, lar::example::PointIsolationAlg< Coord >::rangeString(), lar::example::PointIsolationAlg< Coord >::removeIsolatedPoints(), and lar::example::CoordRange< Coord >::upper.

292  { return rangeString(range.lower, range.upper); }
static std::string rangeString(Coord_t from, Coord_t to)
Helper function. Returns a string "(<from> to <to>)"
template<typename Coord = double>
void lar::example::PointIsolationAlg< Coord >::reconfigure ( Configuration_t const &  new_config)
inline

Reconfigures the algorithm with the specified configuration (no validation is performed)

See also
configuration()

Definition at line 163 of file PointIsolationAlg.h.

References lar::example::PointIsolationAlg< Coord >::config.

164  { config = new_config; }
Configuration_t config
all configuration data
template<typename Coord >
template<typename PointIter >
std::vector< size_t > lar::example::PointIsolationAlg< Coord >::removeIsolatedPoints ( PointIter  begin,
PointIter  end 
) const

Returns the set of points that are not isolated.

Template Parameters
PointIterrandom access iterator to a point type
Parameters
beginiterator to the first point to be considered
enditerator after the last point to be considered
Returns
a list of indices of non-isolated points in the input range

This method is the operating core of the algorithm.

The input is two iterators. The output is a collection of the indices of the elements that are not isolated. The index is equivalent to std::distance(begin, point). The order of the elements in the collection is not specified.

This method can use any collection of input data, as long as a PositionExtractor object is available for it.

Definition at line 312 of file PointIsolationAlg.h.

References lar::example::PointIsolationAlg< Coord >::buildNeighborhood(), lar::example::PointIsolationAlg< Coord >::config, lar::example::PointIsolationAlg< Coord >::isPointIsolatedWithinNeighborhood(), lar::example::PointIsolationAlg< Coord >::maximumOptimalCellSize(), R, lar::example::PointIsolationAlg< Coord >::Configuration_t::radius2, lar::example::PointIsolationAlg< Coord >::Configuration_t::rangeX, lar::example::PointIsolationAlg< Coord >::Configuration_t::rangeY, lar::example::PointIsolationAlg< Coord >::Configuration_t::rangeZ, and lar::example::PointIsolationAlg< Coord >::validateConfiguration().

Referenced by lar::example::PointIsolationAlg< Coord >::configuration(), lar::example::PointIsolationAlg< Coord >::rangeString(), and lar::example::PointIsolationAlg< Coord >::removeIsolatedPoints().

313 {
314 
315  std::vector<size_t> nonIsolated;
316 
317  Coord_t const R = std::sqrt(config.radius2);
318 
319  //
320  // determine space partition settings: cell size
321  //
322  // maximum: the volume of a single cell must be contained in a sphere with
323  // radius equal to the isolation radius R
324  //
325  // minimum: needs tuning
326  //
327 
328  Coord_t cellSize = computeCellSize<PointIter>();
329  assert(cellSize > 0);
330  Partition_t<PointIter> partition(
331  { config.rangeX, cellSize },
332  { config.rangeY, cellSize },
333  { config.rangeZ, cellSize }
334  );
335 
336  // if a cell is contained in a sphere with
337  bool const cellContainedInIsolationSphere
338  = (cellSize <= maximumOptimalCellSize(R));
339 
340  //
341  // determine neighbourhood
342  // the neighbourhood is the number of cells that might contain points closer
343  // than R to a cell; it is equal to R in cell size units, rounded up;
344  // it's expressed as a list of coordinate shifts from a base cell to all the
345  // others in the neighbourhood; it is contained in a cube
346  //
347  unsigned int const neighExtent = (int) std::ceil(R / cellSize);
348  NeighAddresses_t neighList
349  = buildNeighborhood(partition.indexManager(), neighExtent);
350 
351  // if a cell is not fully contained in a isolation radius, we need to check
352  // the points of the cell with each other: their cell becomes part of the
353  // neighbourhood
354  if (!cellContainedInIsolationSphere)
355  neighList.insert(neighList.begin(), { 0, 0, 0 });
356 
357  //
358  // populate the partition
359  //
360  partition.fill(begin, end);
361 
362  //
363  // for each cell in the partition:
364  //
365  size_t const nCells = partition.indexManager().size();
366  for (Indexer_t::CellIndex_t cellIndex = 0; cellIndex < nCells; ++cellIndex) {
367  auto const& cellPoints = partition[cellIndex];
368 
369  //
370  // if the cell has more than one element, mark all points as non-isolated;
371  // true only if the cell is completely contained within a R rßadius
372  //
373  if (cellContainedInIsolationSphere && (cellPoints.size() > 1)) {
374  for (auto const& pointPtr: cellPoints)
375  nonIsolated.push_back(std::distance(begin, pointPtr));
376  continue;
377  } // if all non-isolated
378 
379  //
380  // brute force approach: try all the points in this cell against all the
381  // points in the neighbourhood
382  //
383  for (auto const pointPtr: cellPoints) {
384  //
385  // optimisation (speed): mark the points from other cells as non-isolated
386  // when they trigger non-isolation in points of the current one
387  //
388 
389  // TODO
390 
392  (partition, cellIndex, *pointPtr, neighList)
393  )
394  {
395  nonIsolated.push_back(std::distance(begin, pointPtr));
396  }
397  } // for points in cell
398 
399  } // for cell
400 
401  return nonIsolated;
402 } // lar::example::PointIsolationAlg::removeIsolatedPoints()
Coord Coord_t
Type of coordinate.
Coord_t radius2
square of isolation radius [cm^2]
typename IndexManager_t::LinIndex_t CellIndex_t
type of index for direct access to the cell
Range_t rangeY
range in Y of the covered volume
NeighAddresses_t buildNeighborhood(Indexer_t const &indexer, unsigned int neighExtent) const
Returns a list of cell offsets for the neighbourhood of given radius.
Range_t rangeX
range in X of the covered volume
std::vector< Indexer_t::CellIndexOffset_t > NeighAddresses_t
type of neighbourhood cell offsets
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
Double_t R
Range_t rangeZ
range in Z of the covered volume
Configuration_t config
all configuration data
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
bool isPointIsolatedWithinNeighborhood(Partition_t< PointIter > const &partition, Indexer_t::CellIndex_t cellIndex, Point_t< PointIter > const &point, NeighAddresses_t const &neighList) const
Returns whether a point is isolated in the specified neighbourhood.
static Coord_t maximumOptimalCellSize(Coord_t radius)
Returns the maximum optimal cell size when using a isolation radius.
template<typename Coord = double>
template<typename Cont >
std::vector<size_t> lar::example::PointIsolationAlg< Coord >::removeIsolatedPoints ( Cont const &  points) const
inline

Returns the set of points that are not isolated.

Parameters
pointslist of the reconstructed space points
Returns
a list of indices of non-isolated points in the vector
See also
removeIsolatedPoints(PointIter begin, PointIter end) const

Definition at line 203 of file PointIsolationAlg.h.

References lar::example::PointIsolationAlg< Coord >::bruteRemoveIsolatedPoints(), lar::example::PointIsolationAlg< Coord >::config, lar::example::PointIsolationAlg< Coord >::removeIsolatedPoints(), and lar::example::PointIsolationAlg< Coord >::validateConfiguration().

204  { return removeIsolatedPoints(std::cbegin(points), std::cend(points)); }
std::vector< size_t > removeIsolatedPoints(PointIter begin, PointIter end) const
Returns the set of points that are not isolated.
template<typename Coord >
void lar::example::PointIsolationAlg< Coord >::validateConfiguration ( Configuration_t const &  config)
static

Throws an exception if the configuration is invalid

Exceptions
std::runtime_errorif configuration is invalid

Definition at line 408 of file PointIsolationAlg.h.

References lar::example::PointIsolationAlg< Coord >::Configuration_t::radius2, lar::example::PointIsolationAlg< Coord >::rangeString(), lar::example::PointIsolationAlg< Coord >::Configuration_t::rangeX, lar::example::PointIsolationAlg< Coord >::Configuration_t::rangeY, lar::example::PointIsolationAlg< Coord >::Configuration_t::rangeZ, util::flags::to_string(), and lar::example::CoordRange< Coord >::valid().

Referenced by lar::example::SpacePointIsolationAlg::initialize(), and lar::example::PointIsolationAlg< Coord >::removeIsolatedPoints().

409 {
410  std::vector<std::string> errors;
411  if (config.radius2 < Coord_t(0)) {
412  errors.push_back
413  ("invalid radius squared (" + std::to_string(config.radius2) + ")");
414  }
415  if (!config.rangeX.valid()) {
416  errors.push_back("invalid x range " + rangeString(config.rangeX));
417  }
418  if (!config.rangeY.valid()) {
419  errors.push_back("invalid y range " + rangeString(config.rangeY));
420  }
421  if (!config.rangeZ.valid()) {
422  errors.push_back("invalid z range " + rangeString(config.rangeZ));
423  }
424 
425  if (errors.empty()) return;
426 
427  // compose the full error message as concatenation:
428  std::string message
429  (std::to_string(errors.size()) + " configuration errors found:");
430 
431  for (auto const& error: errors) message += "\n * " + error;
432  throw std::runtime_error(message);
433 
434 } // lar::example::PointIsolationAlg::validateConfiguration()
Coord Coord_t
Type of coordinate.
Coord_t radius2
square of isolation radius [cm^2]
Range_t rangeY
range in Y of the covered volume
static std::string rangeString(Coord_t from, Coord_t to)
Helper function. Returns a string "(<from> to <to>)"
Range_t rangeX
range in X of the covered volume
bool valid() const
Returns whether the range is valid (empty is also valid)
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
Definition: BitMask.h:187
Range_t rangeZ
range in Z of the covered volume
Configuration_t config
all configuration data

Member Data Documentation


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