test_paramwires3d.cxx
Go to the documentation of this file.
4 #include "WireCellUtil/Testing.h"
5 #include "WireCellUtil/Persist.h"
6 
7 #include "TView.h"
8 #include "TPolyLine3D.h"
9 #include "TPolyMarker3D.h"
10 #include "MultiPdf.h"
11 
12 #include <boost/range.hpp>
13 
14 #include <iostream>
15 #include <cmath>
16 
17 using namespace WireCell;
18 using namespace WireCell::Test;
19 using namespace std;
20 
21 void test1()
22 {
23  WireParams *params = new WireParams;
24  IWireParameters::pointer iwp(params);
25 
26  WireGenerator wg;
28  bool ok = wg(iwp, wires);
29  Assert(ok);
30  Assert(wires);
31 
32  cerr << "Got " << wires->size() << " wires" <<endl;
33  Assert(wires->size());
34  int last_plane = -1;
35  int last_index = -1;
36  for (auto wit = wires->begin(); wit != wires->end(); ++wit) {
37  IWire::pointer wire = *wit;
38  int iplane = wire->planeid().index();
39  int ident = (1+iplane)*100000 + wire->index();
40  Assert(ident == wire->ident());
41 
42  if (iplane == last_plane) {
43  ++last_index;
44  }
45  else {
46  last_plane = iplane;
47  last_index = 0;
48  }
49  Assert(last_index == wire->index());
50 
51  }
52 }
53 
54 void test2()
55 {
56  double pitches[] = {10.0, 5.0, 3.0, -1};
57  int want[] = {371, 747, 1243, 0};
58  for (int ind=0; pitches[ind] > 0.0; ++ind) {
59  WireParams *params = new WireParams;
61  put(cfg, "pitch_mm.u", pitches[ind]);
62  put(cfg, "pitch_mm.v", pitches[ind]);
63  put(cfg, "pitch_mm.w", pitches[ind]);
64  params->configure(cfg);
65  IWireParameters::pointer iwp(params);
66  WireGenerator wg;
68  bool ok = wg(iwp, wires);
69  Assert(ok);
70  Assert(wires);
71 
72  int nwires = wires->size();
73  cout << ind << ": pitch=" << pitches[ind] << " nwires=" << nwires << " (want=" << want[ind] << ")" << endl;
74  AssertMsg(nwires == want[ind], "Wrong number of wires");
75  AssertMsg(Persist::dumps(cfg).size(), "Failed to dump cfg");
76  }
77 }
78 
79 void test3D(MultiPdf& pdf, bool interactive)
80 {
81  WireParams* params = new WireParams;
82  IWireParameters::pointer iwp(params);
83  WireGenerator wg;
85  bool ok = wg(iwp, wires);
86  Assert(ok);
87  Assert(wires);
88  AssertMsg(wires->size(), "Got no wires");
89 
90  const Ray& bbox = params->bounds();
91 
92  TView* view = TView::CreateView(1);
93  view->SetRange(bbox.first.x(),bbox.first.y(),bbox.first.z(),
94  bbox.second.x(),bbox.second.y(),bbox.second.z());
95  view->ShowAxis();
96  int colors[3] = {2, 4, 1};
97 
98 
99  IWire::vector u_wires, v_wires, w_wires;
100  copy_if(wires->begin(), wires->end(), back_inserter(u_wires), select_u_wires);
101  copy_if(wires->begin(), wires->end(), back_inserter(v_wires), select_v_wires);
102  copy_if(wires->begin(), wires->end(), back_inserter(w_wires), select_w_wires);
103  size_t n_wires[3] = {
104  u_wires.size(),
105  v_wires.size(),
106  w_wires.size()
107  };
108 
109  double max_width = 5;
110  for (auto wit = wires->begin(); wit != wires->end(); ++wit) {
111  IWire::pointer wire = *wit;
112  int iplane = wire->planeid().index();
113  int index = wire->index();
114 
115  AssertMsg(n_wires[iplane], "Empty plane");
116  double width = ((index+1)*max_width)/n_wires[iplane];
117 
118  const Ray ray = wire->ray();
119  TPolyLine3D* pl = new TPolyLine3D(2);
120  pl->SetPoint(0, ray.first.x(), ray.first.y(), ray.first.z());
121  pl->SetPoint(1, ray.second.x(), ray.second.y(), ray.second.z());
122  pl->SetLineColor(colors[iplane]);
123  pl->SetLineWidth(width);
124  pl->Draw();
125  }
126 
127  pdf();
128 }
129 
130 int main(int argc, char** argv)
131 {
132  MultiPdf pdf(argv[0]);
133  test1();
134  test2();
135  test3D(pdf,argc>1);
136 
137 
138  return 0;
139 }
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
const int nwires
std::shared_ptr< const IWire > pointer
Definition: IData.h:19
void test3D(MultiPdf &pdf, bool interactive)
void test1()
std::shared_ptr< IWireParameters > pointer
Access subclass facet by pointer.
Definition: IComponent.h:33
std::string dumps(const Json::Value &top, bool pretty=false)
As above but dump to a JSON text string.
Definition: Persist.cxx:58
const Ray & bounds() const
Definition: WireParams.cxx:149
STL namespace.
void put(Configuration &cfg, const std::string &dotpath, const T &val)
Put value in configuration at the dotted path.
cfg
Definition: dbjson.py:29
std::vector< pointer > vector
Definition: IData.h:21
virtual void configure(const WireCell::Configuration &config)
Definition: WireParams.cxx:44
#define Assert
Definition: Testing.h:7
const double width
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:87
wire_selector select_u_wires
wire_selector select_w_wires
Definition: Main.h:22
wire_selector select_v_wires
void test2()
Json::Value Configuration
Definition: Configuration.h:50
#define AssertMsg
Definition: Testing.h:8
int main(int argc, char **argv)
virtual WireCell::Configuration default_configuration() const
Optional, override to return a hard-coded default configuration.
Definition: WireParams.cxx:29
std::shared_ptr< const vector > shared_vector
Definition: IData.h:22
QTextStream & endl(QTextStream &s)