Functions
test_drifter.cxx File Reference
#include "WireCellGen/TrackDepos.h"
#include "WireCellUtil/BoundingBox.h"
#include "WireCellUtil/PluginManager.h"
#include "WireCellUtil/NamedFactory.h"
#include "WireCellUtil/Units.h"
#include "WireCellUtil/Testing.h"
#include "WireCellIface/IDrifter.h"
#include "WireCellIface/IRandom.h"
#include "TCanvas.h"
#include "TView.h"
#include "TPolyLine3D.h"
#include "TPolyMarker3D.h"
#include "TColor.h"

Go to the source code of this file.

Functions

Gen::TrackDepos make_tracks ()
 
IDepo::shared_vector get_depos ()
 
std::vector< IDepo::pointertrack_depos (double t, const Ray &ray)
 
std::deque< IDepo::pointertest_depos (const std::vector< IDepo::pointer > &depos, std::string tn="Drifter")
 
void test_tracks (std::string tn="Drifter")
 
void test_time (std::string tn="Drifter")
 
void test_order (std::string tn="Drifter")
 
IDepo::vector test_drifted (std::string tn)
 
Ray make_bbox ()
 
int main (int argc, char *argv[])
 

Function Documentation

IDepo::shared_vector get_depos ( )

Definition at line 29 of file test_drifter.cxx.

30 {
32  IDepo::vector* ret = new IDepo::vector;
33  while (true) {
34  IDepo::pointer depo;
35  bool ok = td(depo);
36  if (!ok or !depo) {
37  break;
38  }
39  ret->push_back(depo);
40  }
41  return IDepo::shared_vector(ret);
42 }
Gen::TrackDepos make_tracks()
struct vector vector
A producer of depositions created from some number of simple, linear tracks.
Definition: TrackDepos.h:17
const GenericPointer< typename T::ValueType > & pointer
Definition: pointer.h:1124
int main ( int  argc,
char *  argv[] 
)

Definition at line 208 of file test_drifter.cxx.

209 {
211  pm.add("WireCellGen");
212  {
213  auto icfg = Factory::lookup<IConfigurable>("Random");
214  auto cfg = icfg->default_configuration();
215  icfg->configure(cfg);
216  }
217  {
218  auto icfg = Factory::lookup<IConfigurable>("Drifter");
219  auto cfg = icfg->default_configuration();
220  //cerr << cfg << endl;
221  cfg["drift_speed"] = 1.0 * units::mm/units::us;
222  cfg["xregions"][0]["cathode"] = 2*units::m;
223  cfg["xregions"][0]["anode"] = 10*units::cm;
224  cfg["xregions"][1]["anode"] = -10*units::cm;
225  cfg["xregions"][1]["cathode"] = -2*units::m;
226  icfg->configure(cfg);
227  }
228 
229  test_tracks("Drifter");
230  test_time("Drifter");
231  test_order("Drifter");
232 
233  IDepo::vector drifted = test_drifted("Drifter");
234 
235  Ray bb = make_bbox();
236 
237 
238  TCanvas c("c","c",800,800);
239 
240  TView* view = TView::CreateView(1);
241  view->SetRange(bb.first.x(),bb.first.y(),bb.first.z(),
242  bb.second.x(),bb.second.y(),bb.second.z());
243  view->ShowAxis();
244 
245 
246  // draw raw activity
248  TPolyMarker3D orig(activity.size(), 6);
249  orig.SetMarkerColor(2);
250  int indx=0;
251  for (auto depo : activity) {
252  const Point& p = depo->pos();
253  orig.SetPoint(indx++, p.x(), p.y(), p.z());
254  }
255  orig.Draw();
256 
257  // draw drifted
258  double tmin=-1, tmax=-1;
259  for (auto depo : drifted) {
260  if (!depo) {
261  cerr << "Reached EOI"<< endl;
262  break;
263  }
264  auto history = depo_chain(depo);
265  Assert(history.size() > 1);
266 
267  if (tmin<0 && tmax<0) {
268  tmin = tmax = depo->time();
269  continue;
270  }
271  tmin = min(tmin, depo->time());
272  tmax = max(tmax, depo->time());
273  }
274  cerr << "Time bounds: " << tmin << " < " << tmax << endl;
275 
276  for (auto depo : drifted) {
277  if (!depo) {
278  cerr << "Reached EOI"<< endl;
279  break;
280  }
281 
282 
283  TPolyMarker3D* pm = new TPolyMarker3D(1,8);
284  const Point& p = depo->pos();
285  pm->SetPoint(0, p.x(), p.y(), p.z());
286 
287  double rel = depo->time()/(tmax-tmin);
288  int col = TColor::GetColorPalette( int(rel*TColor::GetNumberOfColors()) );
289  pm->SetMarkerColor(col);
290 
291  pm->Draw();
292  }
293 
294  c.Print(String::format("%s.pdf", argv[0]).c_str());
295 
296 
297  return 0;
298 }
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
static const double m
Definition: Units.h:79
IDepo::vector depo_chain(IDepo::pointer recent)
Definition: IDepo.cxx:4
Ray make_bbox()
IDepo::vector test_drifted(std::string tn)
struct vector vector
const std::string instance
void test_order(std::string tn="Drifter")
cfg
Definition: dbjson.py:29
#define Assert
Definition: Testing.h:7
def activity(output, slices, slice_line, cluster_tap_file)
Definition: main.py:144
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)
void test_tracks(std::string tn="Drifter")
static const double mm
Definition: Units.h:73
void test_time(std::string tn="Drifter")
p
Definition: test.py:223
static const double us
Definition: Units.h:101
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
static const double cm
Definition: Units.h:76
Plugin * add(const std::string &plugin_name, const std::string &libname="")
Add a plugin. If libname is not given, try to derive it.
IDepo::shared_vector get_depos()
QTextStream & endl(QTextStream &s)
Ray make_bbox ( )

Definition at line 196 of file test_drifter.cxx.

197 {
198  BoundingBox bbox(Ray(Point(-1,-1,-1), Point(1,1,1)));
200  for (auto depo : activity) {
201  bbox(depo->pos());
202  }
203  Ray bb = bbox.bounds();
204  cout << "Bounds: " << bb.first << " --> " << bb.second << endl;
205  return bb;
206 }
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
struct vector vector
def activity(output, slices, slice_line, cluster_tap_file)
Definition: main.py:144
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:34
IDepo::shared_vector get_depos()
QTextStream & endl(QTextStream &s)
Gen::TrackDepos make_tracks ( )

Definition at line 21 of file test_drifter.cxx.

21  {
22  // warning, this bipases some logic in TrackDepos::configure().
23  Gen::TrackDepos td;
24  td.add_track( 10*units::us, Ray(Point(-10,0,0)*units::cm, Point(-100,0,10)*units::cm));
25  td.add_track(120*units::us, Ray(Point( -1,0,0)*units::cm, Point( -2,-100,0)*units::cm));
26  td.add_track( 99*units::us, Ray(Point(-130,50,50)*units::cm, Point(-11, -50,-30)*units::cm));
27  return td;
28 }
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
void add_track(double time, const WireCell::Ray &ray, double dedx=-1.0)
Definition: TrackDepos.cxx:85
A producer of depositions created from some number of simple, linear tracks.
Definition: TrackDepos.h:17
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:34
static const double us
Definition: Units.h:101
static const double cm
Definition: Units.h:76
std::deque< IDepo::pointer > test_depos ( const std::vector< IDepo::pointer > &  depos,
std::string  tn = "Drifter" 
)

Definition at line 60 of file test_drifter.cxx.

61 {
62  AssertMsg(depos.back() == nullptr, "Not given EOS terminated stream of depos");
63  auto drifter = Factory::find_tn<IDrifter>(tn);
65  for (auto depo: depos) {
67  if (!depo) {
68  cerr << "test_depos: sending EOS to drifter\n";
69  }
70  bool ok = (*drifter)(depo, outq);
71  Assert(ok);
72  if (outq.size()) {
73  cerr << "test_depos: got " << outq.size() << " drifted\n";
74  }
75  drifted.insert(drifted.end(), outq.begin(), outq.end());
76  }
77  AssertMsg(drifted.back() == nullptr, "Drifter did not pass on EOS");
78 
79  for (auto out : drifted) {
80  if (!out) { break; }
82  AssertMsg(vec.size() > 1, "The history of the drifted deposition is truncated.");
83  }
84 
85  cerr << "test_depos: start with: " << depos.size()
86  << ", after drifting have: " << drifted.size() << endl;
87  return drifted;
88 }
IDepo::vector depo_chain(IDepo::pointer recent)
Definition: IDepo.cxx:4
std::vector< pointer > vector
Definition: IData.h:21
std::deque< output_pointer > output_queue
#define Assert
Definition: Testing.h:7
#define AssertMsg
Definition: Testing.h:8
QTextStream & endl(QTextStream &s)
IDepo::vector test_drifted ( std::string  tn)

Definition at line 162 of file test_drifter.cxx.

163 {
165  activity.push_back(nullptr); // EOS
166 
167  auto drifter = Factory::find_tn<IDrifter>(tn);
168 
170  for (auto in : activity) {
171  outq.clear();
172  if (!in) {
173  cerr << "test_drifter: sending EOS to drifter\n";
174  }
175  bool ok = (*drifter)(in, outq);
176  Assert(ok);
177  for (auto d : outq) {
178  result.push_back(d);
179  }
180  }
181  Assert(!result.back());
182 
183  for (auto out : result) {
184  if (!out) { break; }
186  AssertMsg(vec.size() > 1, "The history of the drifted deposition is truncated.");
187  }
188 
189  cerr << "test_drifter: start with: " << activity.size()
190  << ", after drifting have: " << result.size() << endl;
191 
192  return result;
193 }
IDepo::vector depo_chain(IDepo::pointer recent)
Definition: IDepo.cxx:4
static QCString result
struct vector vector
std::vector< pointer > vector
Definition: IData.h:21
std::deque< output_pointer > output_queue
#define Assert
Definition: Testing.h:7
def activity(output, slices, slice_line, cluster_tap_file)
Definition: main.py:144
#define AssertMsg
Definition: Testing.h:8
IDepo::shared_vector get_depos()
QTextStream & endl(QTextStream &s)
void test_order ( std::string  tn = "Drifter")

Definition at line 127 of file test_drifter.cxx.

128 {
129  const double x1 = 1*units::m;
130  const double x2 = 12*units::cm;
131  const double t1 = 1*units::us;
132  const double t2 = (x1-x2)/(1.0*units::mm/units::us) - 3*units::us;
133  const double t3 = 3*units::ms;
134 
135  Ray ray1(Point(x1, 0,0), Point(x1+1*units::cm, 0,0));
136  Ray ray2(Point(x2, 0,0), Point(x2+1*units::cm, 0,0));
137 
138  auto depos1 = track_depos(t1, ray1);
139  auto depos2 = track_depos(t2, ray2);
140  auto depos3 = track_depos(t3, ray1);
141  std::vector<IDepo::pointer> alldepos;
142  for (auto depos : {depos1, depos2, depos3}) {
143  Assert(depos.back() == nullptr);
144  depos.pop_back();
145  alldepos.insert(alldepos.end(), depos.begin(), depos.end());
146  }
147  alldepos.push_back(nullptr);
148  auto drifted = test_depos(alldepos, tn);
149  for (auto& depo : drifted) {
150  if (!depo) {
151  break;
152  }
153  cerr << "t="<<depo->time()/units::us
154  << "("<<depo->prior()->time()/units::us<<")"
155  <<"us, x="<<depo->pos().x()/units::cm
156  << "(" <<depo->prior()->pos().x()/units::cm<<")cm\n";
157  }
158 }
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
static const double m
Definition: Units.h:79
std::deque< IDepo::pointer > test_depos(const std::vector< IDepo::pointer > &depos, std::string tn="Drifter")
#define Assert
Definition: Testing.h:7
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:34
static const double mm
Definition: Units.h:73
static const double us
Definition: Units.h:101
static const double ms
Definition: Units.h:100
static const double cm
Definition: Units.h:76
std::vector< IDepo::pointer > track_depos(double t, const Ray &ray)
void test_time ( std::string  tn = "Drifter")

Definition at line 111 of file test_drifter.cxx.

112 {
113  Ray ray(Point(1*units::m, 0,0), Point(1*units::m+1*units::cm, 0,0));
114  std::vector<IDepo::pointer> alldepos;
115  for (double t : {0.0, 10.0*units::us, 3*units::ms} ) {
116  auto depos = track_depos(t, ray);
117  Assert(depos.back() == nullptr);
118  depos.pop_back();
119  cerr << "test_time: " << t/units::us << "us produces "<<depos.size()<<"depos\n";
120  alldepos.insert(alldepos.end(), depos.begin(), depos.end());
121  }
122  alldepos.push_back(nullptr);
123  test_depos(alldepos, tn);
124 }
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
static const double m
Definition: Units.h:79
std::deque< IDepo::pointer > test_depos(const std::vector< IDepo::pointer > &depos, std::string tn="Drifter")
#define Assert
Definition: Testing.h:7
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:34
static const double us
Definition: Units.h:101
static const double ms
Definition: Units.h:100
static const double cm
Definition: Units.h:76
std::vector< IDepo::pointer > track_depos(double t, const Ray &ray)
void test_tracks ( std::string  tn = "Drifter")

Definition at line 91 of file test_drifter.cxx.

92 {
93  std::vector<std::pair<double, double> > endpoints = {
94  std::pair<double,double>{-1*units::cm, 1*units::cm },
95  { 20*units::cm, 21*units::cm},
96  { -20*units::cm, -21*units::cm},
97  { -10*units::cm+3*units::mm, -10*units::cm-3*units::mm},
98  { +10*units::cm+3*units::mm, +10*units::cm-3*units::mm},
99  { -2*units::m+3*units::mm, -2*units::m-3*units::mm},
100  { +2*units::m+3*units::mm, +2*units::m-3*units::mm}};
101 
102  for (auto& ends : endpoints) {
103  Ray ray(Point(ends.first, 0,0), Point(ends.second, 0,0));
104  auto depos = track_depos(0, ray);
105  cerr << "test_tracks: " << ray/units::cm << "cm produces "<<depos.size()<<"depos\n";
106  test_depos(depos, tn);
107  }
108 }
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
static const double m
Definition: Units.h:79
std::deque< IDepo::pointer > test_depos(const std::vector< IDepo::pointer > &depos, std::string tn="Drifter")
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:34
static const double mm
Definition: Units.h:73
static const double cm
Definition: Units.h:76
std::vector< IDepo::pointer > track_depos(double t, const Ray &ray)
std::vector<IDepo::pointer> track_depos ( double  t,
const Ray ray 
)

Definition at line 44 of file test_drifter.cxx.

45 {
46  Gen::TrackDepos td;
47  td.add_track(t, ray);
48  std::vector<IDepo::pointer> ret;
49  while (true) {
50  IDepo::pointer depo;
51  bool ok = td(depo);
52  ret.push_back(depo);
53  if (!ok or !depo) {
54  return ret;
55  }
56  }
57 }
void add_track(double time, const WireCell::Ray &ray, double dedx=-1.0)
Definition: TrackDepos.cxx:85
A producer of depositions created from some number of simple, linear tracks.
Definition: TrackDepos.h:17
const GenericPointer< typename T::ValueType > & pointer
Definition: pointer.h:1124