test_anodeplane_draw.cxx
Go to the documentation of this file.
1 #include "WireCellUtil/Pimpos.h"
2 
3 #include "TCanvas.h"
4 #include "TArrow.h"
5 #include "TH1F.h"
6 #include "TLine.h"
7 
8 #include <iostream>
9 
10 
11 #include "anode_loader.h" // ignore everything in this file
12 
13 using namespace WireCell;
14 using namespace std;
15 
16 void draw_pimpos(TCanvas& canvas, const std::string& detector, std::vector<const Pimpos*>& pimposes)
17 {
18  canvas.SetFixedAspectRatio(true);
19  canvas.SetGridx();
20  canvas.SetGridy();
21 
22  const double wire_extent = 5*units::cm; // half-length of wires
23  const double fsize_mm = 1.5*wire_extent/units::mm;
24 
25  const Point worigin = pimposes[2]->origin();
26 
27  TH1F* frame = canvas.DrawFrame(worigin[2]-fsize_mm, worigin[1]-fsize_mm,
28  worigin[2]+fsize_mm, worigin[1]+fsize_mm);
29  frame->SetTitle(Form("%s: Pitch (thick) and wire (thin) red=U, blue=V, xorigin=%.3fcm",
30  detector.c_str(), worigin[0]/units::cm));
31  frame->SetXTitle("Transverse Z [mm]");
32  frame->SetYTitle("Transverse Y [mm]");
33  int colors[3] = {2, 4, 1};
34 
35  for (int iplane=0; iplane<3; ++iplane) {
36  const Pimpos* pimpos = pimposes[iplane];
37 
38  const Vector wiredir = pimpos->axis(1);
39  const Vector pitchdir = pimpos->axis(2);
40  const Point origin = pimpos->origin();
41  const Binning& binning = pimpos->region_binning();
42  const double middle = binning.min() + 0.5*binning.span();
43 
44 
45  for (int ipitch = 0; ipitch <= binning.nbins(); ++ipitch) {
46  const double pitch1 = binning.edge(ipitch);
47  const double pitch2 = binning.edge(ipitch+1);
48 
49  if (std::abs(middle-pitch1) > wire_extent) {
50  continue; // stupid way to limit the drawing
51  }
52  if (std::abs(middle-pitch2) > wire_extent) {
53  continue; // stupid way to limit the drawing
54  }
55 
56  const Vector vpitch1 = origin + pitchdir * pitch1;
57  const Vector vpitch2 = origin + pitchdir * pitch2;
58  const Ray r_pitch(vpitch1, vpitch2);
59  const Vector vwire = 1.2*wiredir * wire_extent;
60  const Ray r_wire(vpitch1 - vwire,
61  vpitch1 + vwire);
62 
63  if (ipitch < binning.nbins()) { // pitch is bin, wire is edge
64  TArrow* a_pitch = new TArrow(r_pitch.first.z()/units::mm, r_pitch.first.y()/units::mm,
65  r_pitch.second.z()/units::mm, r_pitch.second.y()/units::mm,
66  0.01, "|>");
67  a_pitch->SetLineColor(colors[iplane]);
68  a_pitch->SetLineWidth(2);
69  a_pitch->Draw();
70  }
71  TArrow* a_wire = new TArrow(r_wire.first.z()/units::mm, r_wire.first.y()/units::mm,
72  r_wire.second.z()/units::mm, r_wire.second.y()/units::mm, 0.01);
73  a_wire->SetLineColor(colors[iplane]);
74 
75  a_wire->Draw();
76  }
77  }
78 
79 }
80 
81 
82 int main(int argc, char* argv[])
83 {
84  std::string detector = "uboone";
85  if (argc > 1) {
86  detector = argv[1];
87  }
88  auto anode_tns = anode_loader(detector);
89 
90 
91  // output PDF
92  std::string pdffile = argv[0];
93  pdffile += "-" + detector + ".pdf";
94  cerr << "Drawing to " << pdffile << endl;
95 
96  TCanvas canvas("c","c",500,500);
97 
98  canvas.Print((pdffile+"[").c_str(), "pdf");
99 
100  for (const auto& anode_tn : anode_tns) {
101  cerr << "Getting: " << anode_tn << "\n";
102  auto iap = Factory::find_tn<IAnodePlane>(anode_tn);
103 
104  for (auto face : iap->faces()) {
105  std::vector<const Pimpos*> pimposes;
106  for (auto plane : face->planes()) {
107  pimposes.push_back(plane->pimpos());
108  }
109  draw_pimpos(canvas, detector, pimposes);
110  canvas.Print(pdffile.c_str(), "pdf");
111  }
112  }
113 
114  canvas.Print((pdffile+"]").c_str(), "pdf");
115  return 0;
116 }
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
D3Vector< double > Point
A 3D Cartesian point in double precision.
Definition: Point.h:15
std::string string
Definition: nybbler.cc:12
double span() const
Return the max-min.
Definition: Binning.h:57
const Point & origin() const
Return given 3-point origin for plane pitch.
Definition: Pimpos.h:85
const Binning & region_binning() const
Definition: Pimpos.h:109
STL namespace.
static Ray pitch2(const IWire::vector &wires)
Definition: WireSummary.cxx:13
std::vector< std::string > anode_loader(std::string detector)
Definition: anode_loader.h:35
void draw_pimpos(TCanvas &canvas, const std::string &detector, std::vector< const Pimpos * > &pimposes)
int main(int argc, char *argv[])
T abs(T value)
double min() const
Definition: Binning.h:47
static const double cm
Definition: Units.h:59
static const double mm
Definition: Units.h:55
Definition: Main.h:22
std::vector< float > Vector
Pimpos pimpos(nwires, min_wire_pitch, max_wire_pitch)
Pitch-Impact-Position.
Definition: Pimpos.h:36
double edge(int ind) const
Definition: Binning.h:99
int nbins() const
Definition: Binning.h:42
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
const Vector & axis(int i) const
Definition: Pimpos.h:89
QTextStream & endl(QTextStream &s)