12 #ifndef LAREXAMPLES_ALGORITHMS_REMOVEISOLATEDSPACEPOINTS_POINTISOLATIONALG_H 13 #define LAREXAMPLES_ALGORITHMS_REMOVEISOLATEDSPACEPOINTS_POINTISOLATIONALG_H 19 #include "cetlib/pow.h" 27 #include <type_traits> 127 template <
typename Coord =
double>
191 template <
typename Po
intIter>
193 (PointIter
begin, PointIter
end)
const;
202 template <
typename Cont>
220 template <
typename Po
intIter>
222 (PointIter begin, PointIter end)
const;
237 {
return radius / std::sqrt(3.); }
247 template <
typename Po
intIter>
250 template <
typename Po
intIter>
258 template <
typename Po
intIter = std::array<
double, 3> const*>
264 (
Indexer_t const& indexer,
unsigned int neighExtent)
const;
267 template <
typename Po
intIter>
274 template <
typename Po
intIter>
283 template <
typename Po
int>
309 template <
typename Coord>
310 template <
typename Po
intIter>
315 std::vector<size_t> nonIsolated;
328 Coord_t cellSize = computeCellSize<PointIter>();
329 assert(cellSize > 0);
337 bool const cellContainedInIsolationSphere
347 unsigned int const neighExtent = (int) std::ceil(R / cellSize);
354 if (!cellContainedInIsolationSphere)
355 neighList.insert(neighList.begin(), { 0, 0, 0 });
360 partition.fill(begin, end);
365 size_t const nCells = partition.indexManager().size();
367 auto const& cellPoints = partition[cellIndex];
373 if (cellContainedInIsolationSphere && (cellPoints.size() > 1)) {
374 for (
auto const& pointPtr: cellPoints)
375 nonIsolated.push_back(std::distance(begin, pointPtr));
383 for (
auto const pointPtr: cellPoints) {
392 (partition, cellIndex, *pointPtr, neighList)
395 nonIsolated.push_back(std::distance(begin, pointPtr));
406 template <
typename Coord>
410 std::vector<std::string> errors;
425 if (errors.empty())
return;
431 for (
auto const&
error: errors) message +=
"\n * " +
error;
432 throw std::runtime_error(message);
438 template <
typename Coord>
439 template <
typename PointIter >
455 if (config.
maxMemory == 0)
return cellSize;
464 size_t const nCells = partition[0] * partition[1] * partition[2];
465 if (nCells <= 1)
break;
480 template <
typename Coord>
483 (
Indexer_t const& indexer,
unsigned int neighExtent)
const 485 unsigned int const neighSize = 1 + 2 * neighExtent;
487 neighList.reserve(neighSize * neighSize * neighSize - 1);
499 CellDimIndex_t
const ext = neighExtent;
501 CellID_t center{{ 0, 0, 0 }}, cellID;
502 for (CellDimIndex_t ixOfs = -ext; ixOfs <= ext; ++ixOfs) {
504 for (CellDimIndex_t iyOfs = -ext; iyOfs <= ext; ++iyOfs) {
506 for (CellDimIndex_t izOfs = -ext; izOfs <= ext; ++izOfs) {
507 if ((ixOfs == 0) && (iyOfs == 0) && (izOfs == 0))
continue;
510 neighList.push_back(indexer.
offset(center, cellID));
521 template <
typename Coord>
522 template <
typename Po
intIter>
529 for (
auto const& otherPointPtr: otherPoints) {
531 if (
closeEnough(point, *otherPointPtr) && (&point != &*otherPointPtr))
541 template <
typename Coord>
542 template <
typename Po
intIter>
559 if (!partition.
has(cellIndex + neighOfs))
continue;
560 auto const& neighCellPoints = partition[cellIndex + neighOfs];
562 if (!isPointIsolatedFrom<PointIter>(point, neighCellPoints))
return false;
572 template <
typename Coord>
573 template <
typename Po
intIter>
576 (PointIter begin, PointIter end)
const 582 std::vector<size_t> nonIsolated;
585 for (
auto it = begin; it !=
end; ++it, ++i) {
587 for (
auto ioth = begin; ioth !=
end; ++ioth) {
588 if (it == ioth)
continue;
591 nonIsolated.push_back(i);
604 template <
typename Coord>
605 template <
typename Po
int>
609 return cet::sum_of_squares(
618 template <
typename Coord>
626 #endif // LAREXAMPLES_ALGORITHMS_REMOVEISOLATEDSPACEPOINTS_POINTISOLATIONALG_H Algorithm to detect isolated space points.
A container of points sorted in cells.
std::ptrdiff_t CellIndexOffset_t
type of difference between indices
CellIndexOffset_t CellDimIndex_t
type of difference between indices along a dimension
static std::string rangeString(Range_t range)
Helper function. Returns a string "(<from> to <to>)"
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)
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
static std::string rangeString(Coord_t from, Coord_t to)
Helper function. Returns a string "(<from> to <to>)"
bool closeEnough(Point const &A, Point const &B) const
Returns whether A and B are close enough to be considered non-isolated.
NeighAddresses_t buildNeighborhood(Indexer_t const &indexer, unsigned int neighExtent) const
Returns a list of cell offsets for the neighbourhood of given radius.
Class to organise data into a 3D grid.
Range_t rangeX
range in X of the covered volume
bool has(CellIndexOffset_t ofs) const
Returns whether there is a cell with the specified index (signed!)
Coord_t upper
upper boundary
std::array< CellDimIndex_t, dims()> CellID_t
type of cell coordinate (x, y, z)
GridContainerIndicesBase3D<> GridContainer3DIndices
Index manager for a container of data arranged on a 3D grid.
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.
Coord_t lower
lower boundary
auto extractPositionY(Point const &point)
std::vector< Indexer_t::CellIndexOffset_t > NeighAddresses_t
type of neighbourhood cell offsets
bool valid() const
Returns whether the range is valid (empty is also valid)
std::vector< size_t > bruteRemoveIsolatedPoints(PointIter begin, PointIter end) const
Brute-force reference algorithm.
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
decltype(*PointIter()) Point_t
PointIsolationAlg(Configuration_t const &first_config)
Constructor with configuration validation.
Type containing all configuration parameters of the algorithm.
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
Configuration_t & configuration() const
typename Grid_t::Cell_t Cell_t
type of cell
Index manager for a container of data arranged on a >=3-dim grid.
CellIndexOffset_t offset(CellID_t const &origin, CellID_t const &cellID) const
Returns the difference in index of cellID respect to origin.
static void validateConfiguration(Configuration_t const &config)
std::vector< size_t > removeIsolatedPoints(Cont const &points) const
Returns the set of points that are not isolated.
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
LArSoft-specific namespace.
Range_t rangeZ
range in Z of the covered volume
auto extractPositionX(Point const &point)
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.
Configuration_t config
all configuration data
std::vector< size_t > removeIsolatedPoints(PointIter begin, PointIter end) const
Returns the set of points that are not isolated.
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.
void reconfigure(Configuration_t const &new_config)
static Coord_t maximumOptimalCellSize(Coord_t radius)
Returns the maximum optimal cell size when using a isolation radius.
Coord_t computeCellSize() const
Computes the cell size to be used.
auto extractPositionZ(Point const &point)