LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
MicroBooNEDrawer_tool.cc
Go to the documentation of this file.
1 
6 #include <cmath>
8 
11 #include "cetlib_except/exception.h"
12 
17 
20 
22 #include "larevt/CalibrationDBI/Interface/ChannelStatusService.h"
23 #include "larevt/CalibrationDBI/Interface/ChannelStatusProvider.h"
24 
25 #include "TPolyLine.h"
26 #include "TPolyLine3D.h"
27 #include "TLine.h"
28 #include "TBox.h"
29 #include "TText.h"
30 
31 #include <fstream>
32 
33 namespace evd_tool
34 {
35 
37 {
38 public:
39  explicit MicroBooNEDrawer(const fhicl::ParameterSet& pset);
40 
41  void DetOutline3D(evdb::View3D* view) override;
42 
44 
45 private:
46  void configure(const fhicl::ParameterSet& pset);
47  void DrawRectangularBox(evdb::View3D* view, double* coordsLo, double* coordsHi, int color=kGray, int width = 1, int style = 1);
48  void DrawGrids(evdb::View3D* view, double* coordsLo, double* coordsHi, int color=kGray, int width = 1, int style = 1);
49  void DrawAxes(evdb::View3D* view, double* coordsLo, double* coordsHi, int color=kGray, int width = 1, int style = 1);
50  void DrawBadChannels(evdb::View3D* view, double* coords, int color, int width, int style);
51 
52  // Member variables from the fhicl file
53  bool fThreeWindow;
54  bool fDrawGrid;
55  bool fDrawAxes;
57 };
58 
59 //----------------------------------------------------------------------
60 // Constructor.
62 {
63  configure(pset);
64 }
65 
67 {
68  // Start by recovering the parameters
69  fThreeWindow = pset.get< bool >("DrawThreeWindow", true);
70  fDrawGrid = pset.get< bool >("DrawGrid", true);
71  fDrawAxes = pset.get< bool >("DrawAxes", true);
72  fDrawBadChannels = pset.get< bool >("DrawBadChannels", true);
73 
74  return;
75 }
76 
77 //......................................................................
79 {
81 
82  // If requested, draw the outer three window volume first
83  if (fThreeWindow)
84  {
85  double threeWinCoordsLo[] = {-2.*geo->DetHalfWidth(), -geo->DetHalfHeight(), 0.};
86  double threeWinCoordsHi[] = { 4.*geo->DetHalfWidth(), geo->DetHalfHeight(), geo->DetLength()};
87 
88  DrawRectangularBox(view, threeWinCoordsLo, threeWinCoordsHi, kGray);
89  }
90 
91  // Now draw the standard volume
92  double coordsLo[] = { 0., -geo->DetHalfHeight(), 0.};
93  double coordsHi[] = {2.*geo->DetHalfWidth(), geo->DetHalfHeight(), geo->DetLength()};
94 
95  DrawRectangularBox(view, coordsLo, coordsHi, kRed, 2, 1);
96 
97  // It could be that we don't want to see the grids
98  if (fDrawGrid) DrawGrids(view, coordsLo, coordsHi, kGray+2, 1, 1);
99 
100  if (fDrawAxes) DrawAxes(view, coordsLo, coordsHi, kBlue, 1, 1);
101 
102  if (fDrawBadChannels) DrawBadChannels(view, coordsHi, kGray, 1, 1);
103 
104  return;
105 }
106 
107 void MicroBooNEDrawer::DrawRectangularBox(evdb::View3D* view, double* coordsLo, double* coordsHi, int color, int width, int style)
108 {
109  TPolyLine3D& top = view->AddPolyLine3D(5, color, width, style);
110  top.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
111  top.SetPoint(1, coordsHi[0], coordsHi[1], coordsLo[2]);
112  top.SetPoint(2, coordsHi[0], coordsHi[1], coordsHi[2]);
113  top.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
114  top.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
115 
116  TPolyLine3D& side = view->AddPolyLine3D(5, color, width, style);
117  side.SetPoint(0, coordsHi[0], coordsHi[1], coordsLo[2]);
118  side.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
119  side.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
120  side.SetPoint(3, coordsHi[0], coordsHi[1], coordsHi[2]);
121  side.SetPoint(4, coordsHi[0], coordsHi[1], coordsLo[2]);
122 
123  TPolyLine3D& side2 = view->AddPolyLine3D(5, color, width, style);
124  side2.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
125  side2.SetPoint(1, coordsLo[0], coordsLo[1], coordsLo[2]);
126  side2.SetPoint(2, coordsLo[0], coordsLo[1], coordsHi[2]);
127  side2.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
128  side2.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
129 
130  TPolyLine3D& bottom = view->AddPolyLine3D(5, color, width, style);
131  bottom.SetPoint(0, coordsLo[0], coordsLo[1], coordsLo[2]);
132  bottom.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
133  bottom.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
134  bottom.SetPoint(3, coordsLo[0], coordsLo[1], coordsHi[2]);
135  bottom.SetPoint(4, coordsLo[0], coordsLo[1], coordsLo[2]);
136 
137  return;
138 }
139 
140 void MicroBooNEDrawer::DrawGrids(evdb::View3D* view, double* coordsLo, double* coordsHi, int color, int width, int style)
141 {
142  double z = coordsLo[2];
143  // Grid running along x and y at constant z
144  for (;;) {
145  TPolyLine3D& gridt = view->AddPolyLine3D(2, color, style, width);
146  gridt.SetPoint(0, coordsLo[0], coordsLo[1], z);
147  gridt.SetPoint(1, coordsHi[0], coordsLo[1], z);
148 
149  TPolyLine3D& grids = view->AddPolyLine3D(2, color, style, width);
150  grids.SetPoint(0, coordsHi[0], coordsLo[1], z);
151  grids.SetPoint(1, coordsHi[0], coordsHi[1], z);
152 
153  z += 10.0;
154  if (z>coordsHi[2]) break;
155  }
156 
157  // Grid running along z at constant x
158  double x = 0.0;
159  for (;;) {
160  TPolyLine3D& gridt = view->AddPolyLine3D(2, color, style, width);
161  gridt.SetPoint(0, x, coordsLo[1], coordsLo[2]);
162  gridt.SetPoint(1, x, coordsLo[1], coordsHi[2]);
163  x += 10.0;
164  if (x>coordsHi[0]) break;
165  }
166 
167  // Grid running along z at constant y
168  double y = 0.0;
169  for (;;) {
170  TPolyLine3D& grids = view->AddPolyLine3D(2, color, style, width);
171  grids.SetPoint(0, coordsHi[0], y, coordsLo[2]);
172  grids.SetPoint(1, coordsHi[0], y, coordsHi[2]);
173  y += 10.0;
174  if (y>coordsHi[1]) break;
175  }
176  y = -10.0;
177  for (;;) {
178  TPolyLine3D& grids = view->AddPolyLine3D(2, color, style, width);
179  grids.SetPoint(0, coordsHi[0], y, coordsLo[2]);
180  grids.SetPoint(1, coordsHi[0], y, coordsHi[2]);
181  y -= 10.0;
182  if (y<coordsLo[1]) break;
183  }
184 
185  return;
186 }
187 
188 void MicroBooNEDrawer::DrawAxes(evdb::View3D* view, double* coordsLo, double* coordsHi, int color, int width, int style)
189 {
190 
191  // Indicate coordinate system
192  double x0 = -0.20; // Center location of the key
193  double y0 = 1.10*coordsLo[1]; // Center location of the key
194  double z0 = -0.10*coordsHi[2]; // Center location of the key
195  double sz = 0.20*coordsHi[2]; // Scale size of the key in z direction
196 
197  TPolyLine3D& xaxis = view->AddPolyLine3D(2, color, style, width);
198  TPolyLine3D& yaxis = view->AddPolyLine3D(2, color, style, width);
199  TPolyLine3D& zaxis = view->AddPolyLine3D(2, color, style, width);
200  xaxis.SetPoint(0, x0, y0, z0);
201  xaxis.SetPoint(1, sz+x0, y0, z0);
202 
203  yaxis.SetPoint(0, x0, y0, z0);
204  yaxis.SetPoint(1, x0, y0+sz, z0);
205 
206  zaxis.SetPoint(0, x0, y0, z0);
207  zaxis.SetPoint(1, x0, y0, z0+sz);
208 
209  TPolyLine3D& xpoint = view->AddPolyLine3D(3, color, style, width);
210  TPolyLine3D& ypoint = view->AddPolyLine3D(3, color, style, width);
211  TPolyLine3D& zpoint = view->AddPolyLine3D(3, color, style, width);
212 
213  xpoint.SetPoint(0, 0.95*sz+x0, y0, z0-0.05*sz);
214  xpoint.SetPoint(1, 1.00*sz+x0, y0, z0);
215  xpoint.SetPoint(2, 0.95*sz+x0, y0, z0+0.05*sz);
216 
217  ypoint.SetPoint(0, x0, 0.95*sz+y0, z0-0.05*sz);
218  ypoint.SetPoint(1, x0, 1.00*sz+y0, z0);
219  ypoint.SetPoint(2, x0, 0.95*sz+y0, z0+0.05*sz);
220 
221  zpoint.SetPoint(0, x0-0.05*sz, y0, 0.95*sz+z0);
222  zpoint.SetPoint(1, x0+0.00*sz, y0, 1.00*sz+z0);
223  zpoint.SetPoint(2, x0+0.05*sz, y0, 0.95*sz+z0);
224 
225  TPolyLine3D& zleg = view->AddPolyLine3D(4, color, style, width);
226  zleg.SetPoint(0, x0-0.05*sz, y0+0.05*sz, z0+1.05*sz);
227  zleg.SetPoint(1, x0+0.05*sz, y0+0.05*sz, z0+1.05*sz);
228  zleg.SetPoint(2, x0-0.05*sz, y0-0.05*sz, z0+1.05*sz);
229  zleg.SetPoint(3, x0+0.05*sz, y0-0.05*sz, z0+1.05*sz);
230 
231  TPolyLine3D& yleg = view->AddPolyLine3D(5, color, style, width);
232  yleg.SetPoint(0, x0-0.05*sz, y0+1.15*sz, z0);
233  yleg.SetPoint(1, x0+0.00*sz, y0+1.10*sz, z0);
234  yleg.SetPoint(2, x0+0.00*sz, y0+1.05*sz, z0);
235  yleg.SetPoint(3, x0+0.00*sz, y0+1.10*sz, z0);
236  yleg.SetPoint(4, x0+0.05*sz, y0+1.15*sz, z0);
237 
238  TPolyLine3D& xleg = view->AddPolyLine3D(7, color, style, width);
239  xleg.SetPoint(0, x0+1.05*sz, y0+0.05*sz, z0-0.05*sz);
240  xleg.SetPoint(1, x0+1.05*sz, y0+0.00*sz, z0-0.00*sz);
241  xleg.SetPoint(2, x0+1.05*sz, y0+0.05*sz, z0+0.05*sz);
242  xleg.SetPoint(3, x0+1.05*sz, y0+0.00*sz, z0-0.00*sz);
243  xleg.SetPoint(4, x0+1.05*sz, y0-0.05*sz, z0-0.05*sz);
244  xleg.SetPoint(5, x0+1.05*sz, y0+0.00*sz, z0-0.00*sz);
245  xleg.SetPoint(6, x0+1.05*sz, y0-0.05*sz, z0+0.05*sz);
246 
247  return;
248 }
249 
250 void MicroBooNEDrawer::DrawBadChannels(evdb::View3D* view, double* coords, int color, int width, int style)
251 {
254 
255  lariov::ChannelStatusProvider const& channelStatus
257 
258  // We want to translate the wire position to the opposite side of the TPC...
259  for(size_t viewNo = 0; viewNo < geo->Nviews(); viewNo++)
260  {
261  for(size_t wireNo = 0; wireNo < geo->Nwires(viewNo); wireNo++)
262  {
263  geo::WireID wireID = geo::WireID(rawOpt->fCryostat, rawOpt->fTPC, viewNo, wireNo);
264 
265  raw::ChannelID_t channel = geo->PlaneWireToChannel(wireID);
266 
267  if (channelStatus.IsBad(channel))
268  {
269  const geo::WireGeo* wireGeo = geo->WirePtr(wireID);
270 
271  double wireStart[3];
272  double wireEnd[3];
273 
274  wireGeo->GetStart(wireStart);
275  wireGeo->GetEnd(wireEnd);
276 
277  TPolyLine3D& pl = view->AddPolyLine3D(2, color, style, width);
278  pl.SetPoint(0, coords[0]-0.5, wireStart[1], wireStart[2]);
279  pl.SetPoint(1, coords[0]-0.5, wireEnd[1], wireEnd[2]);
280  }
281  }
282  }
283 
284  return;
285 }
286 
287 
289 }
Float_t x
Definition: compare.C:6
void GetStart(double *xyz) const
Definition: WireGeo.h:129
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
Definition: WireGeo.h:61
bool fDrawAxes
true to draw coordinate axes
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:45
void DrawGrids(evdb::View3D *view, double *coordsLo, double *coordsHi, int color=kGray, int width=1, int style=1)
unsigned int fTPC
TPC number to draw, typically set by TWQProjectionView.
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
bool fDrawBadChannels
true to draw bad channels
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:279
void DrawAxes(evdb::View3D *view, double *coordsLo, double *coordsHi, int color=kGray, int width=1, int style=1)
A collection of drawable 2-D objects.
TGaxis * xaxis
Definition: plot_hist.C:61
unsigned int Nwires(unsigned int p, unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wires in the specified plane.
TPolyLine3D & AddPolyLine3D(int n, int c, int w, int s)
Definition: View3D.cxx:105
void DetOutline3D(evdb::View3D *view) override
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
unsigned int fCryostat
Cryostat number to draw, typically set by TWQProjectionView.
MicroBooNEDrawer(const fhicl::ParameterSet &pset)
T get(std::string const &key) const
Definition: ParameterSet.h:231
bool fThreeWindow
true to draw rectangular box representing 3 windows
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
void configure(const fhicl::ParameterSet &pset)
void DrawBadChannels(evdb::View3D *view, double *coords, int color, int width, int style)
std::size_t color(std::string const &procname)
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
void GetEnd(double *xyz) const
Definition: WireGeo.h:133
void DrawRectangularBox(evdb::View3D *view, double *coordsLo, double *coordsHi, int color=kGray, int width=1, int style=1)
A collection of 3D drawable objects.
unsigned int Nviews() const
Returns the number of views (different wire orientations)
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:27
bool fDrawGrid
true to draw backing grid
This is the interface class for drawing 3D detector geometries.
Namespace collecting geometry-related classes utilities.
art framework interface to geometry description
WireGeo const * WirePtr(geo::WireID const &wireid) const
Returns the specified wire.