test_raytiling_speed.cxx
Go to the documentation of this file.
2 #include "WireCellUtil/Testing.h"
3 #include "WireCellUtil/ExecMon.h"
4 
5 #include <random>
6 #include <iostream>
7 
8 using namespace WireCell;
9 using namespace WireCell::RayGrid;
10 
11 #include "raygrid.h"
12 
13 const double pitch_magnitude = 5;
14 const double gaussian = 3;
15 const double width = 4000;
16 const double height = 4000;
17 
18 
19 std::vector<Point> random_points(int ndepos = 1000, int neles = 10)
20 {
21  std::vector<Point> points;
22  std::default_random_engine generator;
23  std::uniform_real_distribution<double> position(0,std::max(width,height));
24  std::normal_distribution<double> spread(0.0, gaussian);
25  for (int idepo=0;idepo<ndepos;++idepo) {
26  Point cp(0, position(generator), position(generator));
27  for (int iele=0; iele<neles; ++iele) {
28  Point delta(0, spread(generator), spread(generator));
29  points.push_back(cp+delta);
30  }
31  }
32  return points;
33 }
34 
35 int main()
36 {
37  ExecMon em("starting");
38 
39  auto raypairs = make_raypairs(width, height, pitch_magnitude);
40  const int nlayers = raypairs.size();
41 
42  em("make ray pairs");
43 
44  std::vector<Point> points = random_points();
45 
46  Coordinates coords(raypairs);
47  const auto& pitches = coords.pitch_dirs();
48  const auto& centers = coords.centers();
49  const auto& pitch_mags = coords.pitch_mags();
50 
51  em("make coordinates");
52 
53  std::vector< std::vector<Activity::value_t> > measures(nlayers);
54  for (size_t ipt=0; ipt<points.size(); ++ipt ) {
55  const auto& p = points[ipt];
56  for (int ilayer = 0; ilayer<nlayers; ++ilayer) {
57  const auto& pit = pitches[ilayer];
58  const auto& cen = centers[ilayer];
59  const auto rel = p-cen;
60  const int pit_ind = pit.dot(rel)/pitch_mags[ilayer];
61  auto& m = measures[ilayer];
62  if (pit_ind < 0) {
63  std::cerr << "Generated negative pitch index: " << pit_ind
64  << " on L" << ilayer << " p=" << p
65  << std::endl;
66  continue;
67  }
68  if ((int)m.size() <= pit_ind) {
69  m.resize(pit_ind+1, 0.0);
70  }
71  m[pit_ind] += 1.0;
72  }
73  }
74 
75  em("generated activity");
76 
77  activities_t activities;
78  for (int ilayer = 0; ilayer<nlayers; ++ilayer) {
79  auto& m = measures[ilayer];
80  std::cerr << ilayer << ": " << m.size() << std::endl;
81  Activity activity(ilayer, {m.begin(), m.end()});
82  Assert(!activity.empty());
83  activities.push_back(activity);
84  }
85 
86  em("filled activity");
87 
88  blobs_t blobs;
89  for (int i=0; i<100; ++i) {
90  blobs = make_blobs(coords, activities);
91  }
92  em("made clusers 100 times");
93  std::cerr << blobs.size() << " blobs\n";
94 
95  std::cerr << em.summary() << std::endl;
96  return 0;
97 }
static const double m
Definition: Units.h:79
D3Vector< double > Point
A 3D Cartesian point in double precision.
Definition: Point.h:15
const double height
def blobs(cm, hist)
Definition: plots.py:79
const double width
int main()
const int neles
const vector_array1d_t & pitch_dirs() const
Definition: RayGrid.h:88
#define Assert
Definition: Testing.h:7
const double pitch_magnitude
def activity(output, slices, slice_line, cluster_tap_file)
Definition: main.py:144
const int ndepos
const double gaussian
const vector_array1d_t & centers() const
Definition: RayGrid.h:89
const std::vector< double > & pitch_mags() const
Definition: RayGrid.h:87
static int max(int a, int b)
generator
Definition: train.py:468
Definition: Main.h:22
p
Definition: test.py:223
std::vector< Blob > blobs_t
Definition: RayTiling.h:134
blobs_t make_blobs(const Coordinates &coords, const activities_t &activities)
Definition: RayTiling.cxx:371
std::vector< Activity > activities_t
Definition: RayTiling.h:105
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
std::string summary() const
Return summary up to now.
Definition: ExecMon.cxx:21
def points(jdat)
Definition: rendertvtk.py:105
std::vector< Point > random_points(int ndepos=1000, int neles=10)
QTextStream & endl(QTextStream &s)