LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
Classes | Public Member Functions | Public Attributes | List of all members
lsst::jointcal::FastFinder Class Reference

This is an auxillary class for matching objects from starlists. More...

#include <FastFinder.h>

Classes

class  Iterator
 Iterator meant to traverse objects within some limiting distance. More...
 

Public Member Functions

 FastFinder (const BaseStarList &list, const unsigned nXSlice=100)
 Constructor. More...
 
std::shared_ptr< const BaseStarfindClosest (const Point &where, const double maxDist, bool(*SkipIt)(const BaseStar &)=nullptr) const
 Find the closest with some rejection capability. More...
 
std::shared_ptr< const BaseStarsecondClosest (const Point &where, const double maxDist, std::shared_ptr< const BaseStar > &closest, bool(*SkipIt)(const BaseStar &)=nullptr) const
 
void dump () const
 mostly for debugging More...
 
Iterator beginScan (const Point &where, double maxDist) const
 
void findRangeInSlice (const int iSlice, const double yStart, const double yEnd, pstar &start, pstar &end) const
 
pstar locateYStart (pstar begin, pstar end, double yVal) const
 
pstar locateYEnd (pstar begin, pstar end, double yVal) const
 

Public Attributes

decltype(stars) typedef ::value_type stars_element
 
decltype(stars) typedef ::const_iterator pstar
 
const BaseStarList baselist
 
unsigned count
 
std::vector< std::shared_ptr< const BaseStar > > stars
 
unsigned nslice
 
std::vector< unsigned > index
 
double xmin
 
double xmax
 
double xstep
 

Detailed Description

This is an auxillary class for matching objects from starlists.

It allows to locate rapidly the closest objects from a given position. The very simple strategy is to sort objects according to 1 coordinate x, and to build an index that allows to select the objects with the x coordinate inside an interval. Then every slice in x is sorted according to y, which enables a fast scan inside a x slice. listMatchCollect takes about 10ms (PC 450 MHz, optimized "-O4") for a match between lists of about 2000 objects each, which is fast enough for our needs. The same "locator" is used in listMatchupShift, to avoid scanning the whole input lists. Timing on listMatchCollect and listMatchupShift indicates a gain in speed by more than one order of magnitude after implementation of this FastFinder.Fast locator in starlists.

Definition at line 54 of file FastFinder.h.

Constructor & Destructor Documentation

◆ FastFinder()

lsst::jointcal::FastFinder::FastFinder ( const BaseStarList list,
const unsigned  nXSlice = 100 
)

Constructor.

Definition at line 38 of file FastFinder.cc.

39  : baselist(list), count(list.size()), stars(count), nslice(nXSlice), index(nslice + 1) {
40  if (count == 0) return;
41 
42  // fill "stars"
43  unsigned j = 0;
44  for (auto const &ci : list) {
45  stars[j] = ci;
46  ++j;
47  }
48 
49  sort(stars.begin(), stars.end(),
50  [](const stars_element &E1, const stars_element &E2) { return (E1->x < E2->x); });
51 
52  xmin = stars[0]->x;
53  xmax = stars[count - 1]->x;
55  if (xmin == xmax) nslice = 1;
56 
57  // the x size of each slice:
58  xstep = (xmax - xmin) / nslice;
59 
60  // fill the index array with the first star beyond the slice limit.
61  index[0] = 0; // first
62  unsigned istar = 0;
63  for (unsigned islice = 1; islice < nslice; ++islice) {
64  double xend = xmin + (islice)*xstep;
65  while (istar < count && stars[istar]->x < xend) ++istar;
66  index[islice] = istar;
67  }
68  index[nslice] = count; // last
69  for (unsigned islice = 0; islice < nslice; ++islice) {
70  sort(stars.begin() + index[islice], stars.begin() + index[islice + 1],
71  [](const stars_element &E1, const stars_element &E2) {
72  return (E1->y < E2->y);
73  }); // sort each slice in y.
74  }
75  // dump();
76 }
std::vector< std::shared_ptr< const BaseStar > > stars
Definition: FastFinder.h:64
T min(T... args)
double x
const BaseStarList baselist
Definition: FastFinder.h:56
std::vector< unsigned > index
Definition: FastFinder.h:66
decltype(stars) typedef ::value_type stars_element
Definition: FastFinder.h:69
T sort(T... args)
daf::base::PropertyList * list
Definition: fits.cc:903

Member Function Documentation

◆ beginScan()

FastFinder::Iterator lsst::jointcal::FastFinder::beginScan ( const Point where,
double  maxDist 
) const

Definition at line 175 of file FastFinder.cc.

175  {
176  return FastFinder::Iterator(*this, where, maxDist);
177 }
FastFinder::Iterator Iterator
Definition: FastFinder.cc:179

◆ dump()

void lsst::jointcal::FastFinder::dump ( ) const

mostly for debugging

Definition at line 78 of file FastFinder.cc.

78  {
79  for (unsigned i = 0; i < count; ++i) {
80  stars[i]->dump();
81  }
82 }
std::vector< std::shared_ptr< const BaseStar > > stars
Definition: FastFinder.h:64

◆ findClosest()

std::shared_ptr< const BaseStar > lsst::jointcal::FastFinder::findClosest ( const Point where,
const double  maxDist,
bool(*)(const BaseStar &)  SkipIt = nullptr 
) const

Find the closest with some rejection capability.

Definition at line 84 of file FastFinder.cc.

85  {
86  if (count == 0) return nullptr;
87  FastFinder::Iterator it = beginScan(where, maxDist);
88  if (*it == nullptr) return nullptr;
90  double minDist2 = maxDist * maxDist;
91  for (; *it != nullptr; ++it) {
92  if (SkipIt && SkipIt(**it)) continue;
93  double dist2 = where.computeDist2(**it);
94  if (dist2 < minDist2) {
95  pbest = *it;
96  minDist2 = dist2;
97  }
98  }
99  return pbest;
100 }
FastFinder::Iterator Iterator
Definition: FastFinder.cc:179
Iterator beginScan(const Point &where, double maxDist) const
Definition: FastFinder.cc:175

◆ findRangeInSlice()

void lsst::jointcal::FastFinder::findRangeInSlice ( const int  iSlice,
const double  yStart,
const double  yEnd,
pstar start,
pstar end 
) const

Definition at line 169 of file FastFinder.cc.

170  {
171  start = locateYStart(stars.begin() + index[iSlice], stars.begin() + index[iSlice + 1], yStart);
172  end = locateYEnd(start, stars.begin() + index[iSlice + 1], yEnd);
173 }
std::vector< std::shared_ptr< const BaseStar > > stars
Definition: FastFinder.h:64
pstar locateYEnd(pstar begin, pstar end, double yVal) const
Definition: FastFinder.cc:153
pstar locateYStart(pstar begin, pstar end, double yVal) const
Definition: FastFinder.cc:135
std::vector< unsigned > index
Definition: FastFinder.h:66
int end

◆ locateYEnd()

FastFinder::pstar lsst::jointcal::FastFinder::locateYEnd ( pstar  begin,
pstar  end,
double  yVal 
) const

Definition at line 153 of file FastFinder.cc.

153  {
154  if (begin == stars.end()) return stars.end();
155  int span = end - begin - 1;
156  while (span > 1) {
157  int half_span = span / 2;
158  pstar middle = end - half_span;
159  if ((*middle)->y > yVal) {
160  end -= half_span;
161  span -= half_span;
162  } else {
163  span -= (span - half_span);
164  }
165  }
166  return end - 1;
167 }
decltype(stars) typedef ::const_iterator pstar
Definition: FastFinder.h:70
std::vector< std::shared_ptr< const BaseStar > > stars
Definition: FastFinder.h:64
T begin(T... args)
int end

◆ locateYStart()

FastFinder::pstar lsst::jointcal::FastFinder::locateYStart ( pstar  begin,
pstar  end,
double  yVal 
) const

Definition at line 135 of file FastFinder.cc.

135  {
136  if (begin == stars.end() || begin == end) return stars.end();
137  int span = end - begin - 1;
138  while (span > 1) {
139  int half_span = span / 2;
140  pstar middle = begin + half_span;
141  if ((*middle)->y < yVal) {
142  begin += half_span;
143  span -= half_span;
144  } else {
145  span -= (span - half_span);
146  }
147  }
148  return begin;
149 }
decltype(stars) typedef ::const_iterator pstar
Definition: FastFinder.h:70
std::vector< std::shared_ptr< const BaseStar > > stars
Definition: FastFinder.h:64
T begin(T... args)
int end

◆ secondClosest()

std::shared_ptr< const BaseStar > lsst::jointcal::FastFinder::secondClosest ( const Point where,
const double  maxDist,
std::shared_ptr< const BaseStar > &  closest,
bool(*)(const BaseStar &)  SkipIt = nullptr 
) const

Definition at line 102 of file FastFinder.cc.

104  {
105  closest = nullptr;
106  if (count == 0) return nullptr;
107  FastFinder::Iterator it = beginScan(where, maxDist);
108  if (*it == nullptr) return nullptr;
109  std::shared_ptr<const BaseStar> pbest1; // closest
110  std::shared_ptr<const BaseStar> pbest2; // second closest
111  double minDist1_2 = maxDist * maxDist;
112  double minDist2_2 = maxDist * maxDist;
113  for (; *it != nullptr; ++it) {
114  if (SkipIt && SkipIt(**it)) continue;
115  double dist2 = where.computeDist2(**it);
116  if (dist2 < minDist1_2) {
117  pbest2 = pbest1;
118  minDist2_2 = minDist1_2;
119  pbest1 = *it;
120  minDist1_2 = dist2;
121  } else if (dist2 < minDist2_2) {
122  pbest2 = *it;
123  minDist2_2 = dist2;
124  }
125  }
126  closest = pbest1;
127  return pbest2;
128 }
FastFinder::Iterator Iterator
Definition: FastFinder.cc:179
Iterator beginScan(const Point &where, double maxDist) const
Definition: FastFinder.cc:175

Member Data Documentation

◆ baselist

const BaseStarList lsst::jointcal::FastFinder::baselist

Definition at line 56 of file FastFinder.h.

◆ count

unsigned lsst::jointcal::FastFinder::count

Definition at line 58 of file FastFinder.h.

◆ index

std::vector<unsigned> lsst::jointcal::FastFinder::index

Definition at line 66 of file FastFinder.h.

◆ nslice

unsigned lsst::jointcal::FastFinder::nslice

Definition at line 65 of file FastFinder.h.

◆ pstar

decltype(stars) typedef ::const_iterator lsst::jointcal::FastFinder::pstar

Definition at line 70 of file FastFinder.h.

◆ stars

std::vector<std::shared_ptr<const BaseStar> > lsst::jointcal::FastFinder::stars

Definition at line 64 of file FastFinder.h.

◆ stars_element

decltype(stars) typedef ::value_type lsst::jointcal::FastFinder::stars_element

Definition at line 69 of file FastFinder.h.

◆ xmax

double lsst::jointcal::FastFinder::xmax

Definition at line 67 of file FastFinder.h.

◆ xmin

double lsst::jointcal::FastFinder::xmin

Definition at line 67 of file FastFinder.h.

◆ xstep

double lsst::jointcal::FastFinder::xstep

Definition at line 67 of file FastFinder.h.


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