Classes | Typedefs | Functions | Variables
test_rayclustering.cxx File Reference
#include "WireCellUtil/RayClustering.h"
#include "WireCellUtil/RayTiling.h"
#include "WireCellUtil/Waveform.h"
#include "WireCellUtil/Testing.h"
#include "WireCellUtil/Logging.h"
#include <math.h>
#include <random>
#include <fstream>
#include <string>
#include "raygrid.h"
#include "raygrid_dump.h"

Go to the source code of this file.

Classes

struct  Chirp
 

Typedefs

typedef std::vector< Activity::value_tmeasure_t
 

Functions

static std::vector< Pointmake_points (std::default_random_engine &generator, double x)
 
static std::vector< measure_tmake_measures (Coordinates &coords, const std::vector< Point > &points)
 
static activities_t make_activities (Coordinates &coords, std::vector< measure_t > &measures)
 
static void test_blobs (const blobs_t &blobs)
 
int main (int argc, char *argv[])
 

Variables

const int ndepos = 10
 
const int neles = 10
 
const double pitch_magnitude = 5
 
const double gaussian = 3
 
const double border = 10
 
const double width = 100
 
const double height = 100
 

Typedef Documentation

Definition at line 58 of file test_rayclustering.cxx.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 244 of file test_rayclustering.cxx.

245 {
246  auto raypairs = make_raypairs(width, height, pitch_magnitude);
247 
248  Coordinates coords(raypairs);
249 
250  Tiling tiling(coords);
251 
252  std::default_random_engine generator;
253  std::vector<Point> pts1 = make_points(generator, 10.0);
254  std::vector<Point> pts2 = make_points(generator, 20.0);
255 
256  std::vector<measure_t> meas1 = make_measures(coords, pts1);
257  std::vector<measure_t> meas2 = make_measures(coords, pts2);
258 
259  auto act1 = make_activities(coords, meas1);
260  auto act2 = make_activities(coords, meas2);
261 
262  auto blobs1 = make_blobs(coords, act1);
263  auto blobs2 = make_blobs(coords, act2);
264 
265  test_blobs(blobs1);
266  test_blobs(blobs2);
267 
268  // fixme: blobs are missing these features:
269  // - sort corners
270  // - apply X offset
271  // - assign some value
272  // this is maybe best done converting from Blob to another rep
273 
274  JsonEvent dumper(coords);
275  for (const auto& pt : pts1) { dumper(pt); }
276  for (const auto& pt : pts2) { dumper(pt); }
277  Chirp chirp(blobs1, blobs2, coords, dumper);
278  associator_t chirpf = chirp;
279  associate(blobs1, blobs2, chirpf);
280 
281  chirp.dump(dumper);
282 
283  std::string fout = argv[0];
284  fout += ".json";
285  dumper.dump(fout);
286 
287  return 0;
288 }
const double width
std::string string
Definition: nybbler.cc:12
const double height
static std::vector< Point > make_points(std::default_random_engine &generator, double x)
const double pitch_magnitude
std::function< void(blobref_t &a, blobref_t &b)> associator_t
Definition: RayClustering.h:44
static std::vector< measure_t > make_measures(Coordinates &coords, const std::vector< Point > &points)
generator
Definition: train.py:468
static activities_t make_activities(Coordinates &coords, std::vector< measure_t > &measures)
static void test_blobs(const blobs_t &blobs)
blobs_t make_blobs(const Coordinates &coords, const activities_t &activities)
Definition: RayTiling.cxx:371
bool associate(const std::string &classname, WireCell::INamedFactory *factory)
Associate a factory with the type it makes.
Definition: NamedFactory.h:210
ray_pair_vector_t make_raypairs(double width=100, double height=100, double pitch_mag=3, double angle=60.0 *M_PI/180.0)
Definition: raygrid.h:5
static activities_t make_activities ( Coordinates coords,
std::vector< measure_t > &  measures 
)
static

Definition at line 107 of file test_rayclustering.cxx.

108 {
109  int nlayers = coords.nlayers();
110  activities_t activities;
111  for (int ilayer = 0; ilayer<nlayers; ++ilayer) {
112  auto& m = measures[ilayer];
113  info("Make activity for layer: {}: {}", ilayer, m.size());
114  Activity activity(ilayer, {m.begin(), m.end()});
115  Assert(!activity.empty());
116  activities.push_back(activity);
117  }
118  return activities;
119 }
static const double m
Definition: Units.h:79
#define Assert
Definition: Testing.h:7
def activity(output, slices, slice_line, cluster_tap_file)
Definition: main.py:144
std::vector< Activity > activities_t
Definition: RayTiling.h:105
static std::vector<measure_t> make_measures ( Coordinates coords,
const std::vector< Point > &  points 
)
static

Definition at line 61 of file test_rayclustering.cxx.

62 {
63  int nlayers = coords.nlayers();
64  std::vector<measure_t> measures(nlayers);
65  const auto& pitches = coords.pitch_dirs();
66  const auto& centers = coords.centers();
67  const auto& pitch_mags = coords.pitch_mags();
68 
69  for (size_t ipt=0; ipt<points.size(); ++ipt ) {
70  const auto& p = points[ipt];
71  for (int ilayer = 0; ilayer<nlayers; ++ilayer) {
72  const auto& pit = pitches[ilayer];
73  const auto& cen = centers[ilayer];
74  const auto rel = p-cen;
75  const int pit_ind = pit.dot(rel)/pitch_mags[ilayer];
76  if (pit_ind < 0) {
77  warn("Negative pitch indices not allowed, got {} from ilayer {} ipt {} for point {}",
78  pit_ind, ilayer, ipt, p);
79  continue;
80  }
81  if (ilayer <= 1) {
82  if (pit_ind >= 1 or pit_ind < 0) {
83  debug("mm: pit_ind={} with ipt={}", pit_ind, ipt);
84  if (pit_ind == 1) {
85  debug("\tpit={} cen={} rel={}", pit, cen, rel);
86  }
87  continue;
88  }
89  }
90  measure_t& m = measures[ilayer];
91  if ((int)m.size() <= pit_ind) {
92  debug("resize for ipt {} ilayer {} from {} to {}", ipt, ilayer, m.size(), pit_ind+1);
93  m.resize(pit_ind+1, 0.0);
94  debug("done");
95  }
96 
97  debug("adding to pit_ind {} ilayer {} ipt {}", pit_ind, ilayer, ipt);
98  m[pit_ind] += 1.0;
99  debug("valud: {}", m[pit_ind]);
100  }
101  }
102 
103  return measures;
104 }
static const double m
Definition: Units.h:79
std::vector< Activity::value_t > measure_t
const vector_array1d_t & pitch_dirs() const
Definition: RayGrid.h:88
const vector_array1d_t & centers() const
Definition: RayGrid.h:89
const std::vector< double > & pitch_mags() const
Definition: RayGrid.h:87
p
Definition: test.py:223
static std::vector<Point> make_points ( std::default_random_engine &  generator,
double  x 
)
static

Definition at line 36 of file test_rayclustering.cxx.

37 {
38  std::vector<Point> points;
39  std::uniform_real_distribution<double> position(0,std::max(width,height));
40  std::normal_distribution<double> spread(0.0, gaussian);
41  for (int idepo=0;idepo<ndepos;++idepo) {
43  for (int iele=0; iele<neles; ++iele) {
44  const Point delta(x, spread(generator), spread(generator));
45  const Point pt = cp + delta;
46  if (pt.y() < -border or pt.y() > height+border or
47  pt.z() < -border or pt.z() > width+border) {
48  warn("Rejecting far away point: {} + {}" , cp, delta);
49  continue;
50  }
51  points.push_back(cp+delta);
52  }
53  }
54  return points;
55 }
const double width
const double gaussian
const double height
const int neles
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:34
static int max(int a, int b)
const double border
generator
Definition: train.py:468
list x
Definition: train.py:276
const int ndepos
def points(jdat)
Definition: rendertvtk.py:105
static void test_blobs ( const blobs_t blobs)
static

Definition at line 232 of file test_rayclustering.cxx.

233 {
234  for (const auto& blob : blobs) {
235  const auto& strips = blob.strips();
236  Assert(strips[0].bounds.first == 0);
237  Assert(strips[0].bounds.second == 1);
238  Assert(strips[1].bounds.first == 0);
239  Assert(strips[1].bounds.second == 1);
240  }
241 }
def blobs(cm, hist)
Definition: plots.py:79
#define Assert
Definition: Testing.h:7
BoundingBox bounds(int x, int y, int w, int h)
Definition: main.cpp:37

Variable Documentation

const double border = 10

Definition at line 26 of file test_rayclustering.cxx.

const double gaussian = 3

Definition at line 25 of file test_rayclustering.cxx.

const double height = 100

Definition at line 28 of file test_rayclustering.cxx.

const int ndepos = 10

Definition at line 22 of file test_rayclustering.cxx.

const int neles = 10

Definition at line 23 of file test_rayclustering.cxx.

const double pitch_magnitude = 5

Definition at line 24 of file test_rayclustering.cxx.

const double width = 100

Definition at line 27 of file test_rayclustering.cxx.