Functions
test_iwireprovider.cxx File Reference
#include "WireCellIface/IConfigurable.h"
#include "WireCellIface/IWire.h"
#include "WireCellIface/IWireGenerator.h"
#include "WireCellIface/IWireSelectors.h"
#include "WireCellIface/IWireSummarizer.h"
#include "WireCellIface/IWireSummary.h"
#include "WireCellUtil/Testing.h"
#include "WireCellUtil/TimeKeeper.h"
#include "WireCellUtil/MemUsage.h"
#include "WireCellUtil/BoundingBox.h"
#include "WireCellUtil/Point.h"
#include "WireCellUtil/PluginManager.h"
#include "WireCellUtil/NamedFactory.h"
#include "TH1F.h"
#include "TLine.h"
#include "TMarker.h"
#include "MultiPdf.h"
#include <iostream>
#include <iterator>

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 31 of file test_iwireprovider.cxx.

32 {
33  TimeKeeper tk("test wires");
34  MemUsage mu("test wires");
35 
37  pm.add("WireCellGen");
38 
39 
40  // fixme: this C++ dance to wire up the interfaces may eventually
41  // be done inside a workflow engine.
42 
43  // fixme: this needs to be done by a configuration service
44  auto wp_cfg = WireCell::Factory::lookup<IConfigurable>("WireParams");
45  AssertMsg(wp_cfg, "Failed to get IConfigurable from default WireParams");
46 
47  auto cfg = wp_cfg->default_configuration();
48  double pitch = 10.0;
49  put(cfg, "pitch_mm.u", pitch);
50  put(cfg, "pitch_mm.v", pitch);
51  put(cfg, "pitch_mm.w", pitch);
52  wp_cfg->configure(cfg);
53 
54  auto wp = WireCell::Factory::lookup<IWireParameters>("WireParams");
55  AssertMsg(wp, "Failed to get IWireParameters from default WireParams");
56  cout << "Got WireParams IWireParameters interface @ " << wp << endl;
57 
58  cout << tk("Configured WireParams") << endl;
59  cout << mu("Configured WireParams") << endl;
60 
61  cout << "Wire Parameters:\n"
62  << "Bounds: " << wp->bounds() << "\n"
63  << "Upitch: " << wp->pitchU() << "\n"
64  << "Vpitch: " << wp->pitchV() << "\n"
65  << "Wpitch: " << wp->pitchW() << "\n"
66  << endl;
67 
68 
69  auto wg = WireCell::Factory::lookup<IWireGenerator>("WireGenerator");
70  AssertMsg(wg, "Failed to get IWireGenerator from default WireGenerator");
71  cout << "Got WireGenerator IWireGenerator interface @ " << wg << endl;
72 
73  IWireGenerator::output_pointer wires;
74  bool ok = (*wg)(wp, wires);
75  Assert(ok);
76  Assert(wires);
77 
78  cout << tk("Generated ParamWires") << endl;
79  cout << mu("Generated ParamWires") << endl;
80 
81  int nwires = wires->size();
82  cout << "Got " << nwires << " wires" << endl;
83  //Assert(1103 == nwires);
84 
85  cout << tk("Made local wire collection") << endl;
86  cout << mu("Made local wire collection") << endl;
87 
88  auto wser = WireCell::Factory::lookup<IWireSummarizer>("WireSummarizer");
90  ok = (*wser)(wires, ws);
91  Assert(ok);
92  WireCell::BoundingBox bb2 = ws->box();
93 
94  cout << tk("Made wire summary") << endl;
95  cout << mu("Made wire summary") << endl;
96 
97  WireCell::BoundingBox boundingbox;
98  for (size_t ind = 0; ind < wires->size(); ++ind) {
99  boundingbox(wires->at(ind)->ray());
100  }
101  const Ray& bbox = boundingbox.bounds();
102 
103  cout << tk("Made bounding box") << endl;
104  cout << mu("Made bounding box") << endl;
105 
106  vector<IWire::pointer> u_wires, v_wires, w_wires;
107  copy_if(wires->begin(), wires->end(), back_inserter(u_wires), select_u_wires);
108  copy_if(wires->begin(), wires->end(), back_inserter(v_wires), select_v_wires);
109  copy_if(wires->begin(), wires->end(), back_inserter(w_wires), select_w_wires);
110 
111  size_t n_wires[3] = {
112  u_wires.size(),
113  v_wires.size(),
114  w_wires.size()
115  };
116 
117  MultiPdf pdf(argv[0]);
118 
119  TLine l;
120  TMarker m;
121  m.SetMarkerSize(1);
122  m.SetMarkerStyle(20);
123  int colors[] = {2,4,1};
124  double max_width = 5.0;
125 
126  cout << tk("Made TCanvas") << endl;
127  cout << mu("Made TCanvas") << endl;
128 
129  TH1F* frame = pdf.canvas.DrawFrame(bbox.first.z(), bbox.first.y(),
130  bbox.second.z(), bbox.second.y());
131  frame->SetTitle("Wires, red=U, blue=V, thicker=increasing index");
132  frame->SetXTitle("Z transverse direction");
133  frame->SetYTitle("Y transverse direction");
134  for (auto wit = wires->begin(); wit != wires->end(); ++wit) {
135  IWire::pointer wire = *wit;
136 
137  Ray wray = wire->ray();
138 
139  int iplane = wire->planeid().index();
140  int index = wire->index();
141  double width = ((index+1)*max_width)/n_wires[iplane];
142 
143  l.SetLineColor(colors[iplane]);
144  l.SetLineWidth(width);
145  l.DrawLine(wray.first.z(), wray.first.y(), wray.second.z(), wray.second.y());
146  Point cent = wire->center();
147  m.SetMarkerColor(colors[iplane]);
148  m.DrawMarker(cent.z(), cent.y());
149  }
150  cout << tk("Canvas drawn") << endl;
151  cout << mu("Canvas drawn") << endl;
152 
153  pdf();
154 
155  cout << "Timing summary:\n" << tk.summary() << endl;
156  cout << "Memory summary:\n" << mu.summary() << endl;
157 
158  return 0;
159 }
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
static const double m
Definition: Units.h:79
const std::string instance
void put(Configuration &cfg, const std::string &dotpath, const T &val)
Put value in configuration at the dotted path.
cfg
Definition: dbjson.py:29
static QStrList * l
Definition: config.cpp:1044
#define Assert
Definition: Testing.h:7
const double width
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:34
wire_selector select_u_wires
wire_selector select_w_wires
wire_selector select_v_wires
#define AssertMsg
Definition: Testing.h:8
Plugin * add(const std::string &plugin_name, const std::string &libname="")
Add a plugin. If libname is not given, try to derive it.
const GenericPointer< typename T::ValueType > & pointer
Definition: pointer.h:1124
const Ray & bounds() const
Return the ray representing the bounds.
Definition: BoundingBox.h:36
QTextStream & endl(QTextStream &s)