LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ICARUSDrawer_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 ICARUSDrawer(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, bool verticalGrid, 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 fDrawGrid;
54  bool fDrawAxes;
56 };
57 
58 //----------------------------------------------------------------------
59 // Constructor.
61 {
62  configure(pset);
63 }
64 
66 {
67  // Start by recovering the parameters
68  fDrawGrid = pset.get< bool >("DrawGrid", true);
69  fDrawAxes = pset.get< bool >("DrawAxes", true);
70  fDrawBadChannels = pset.get< bool >("DrawBadChannels", true);
71 
72  return;
73 }
74 
75 //......................................................................
77 {
79 
80  bool axesNotDrawn(true);
81 
82  double xl,xu,yl,yu,zl,zu;
83 
84  geo->WorldBox(&xl,&xu,&yl,&yu,&zl,&zu);
85 
86  std::cout << "--- building ICARUS 3D display, low coord: " << xl << ", " << yl << ", " << zl << ", hi coord: " << xu << ", " << yu << ", " << zu << std::endl;
87 
88  // Loop over the number of cryostats
89  for(geo::cryostat_iterator cryoItr = geo->begin_cryostat(); cryoItr != geo->end_cryostat(); cryoItr++)
90  {
91  const geo::CryostatGeo& cryoGeo = *cryoItr;
92 
93  double cryoCoordsLo[] = {cryoGeo.MinX(), cryoGeo.MinY(), cryoGeo.MinZ()};
94  double cryoCoordsHi[] = {cryoGeo.MaxX(), cryoGeo.MaxY(), cryoGeo.MaxZ()};
95 
96  std::cout << " - cryostat: " << cryoGeo.ID() << ", low coord: " << cryoCoordsLo[0] << ", " << cryoCoordsLo[1] << ", " << cryoCoordsLo[2] << ", hi coord: " << cryoCoordsHi[0] << ", " << cryoCoordsHi[1] << ", " << cryoCoordsHi[2] << std::endl;
97 
98  DrawRectangularBox(view, cryoCoordsLo, cryoCoordsHi, kWhite, 2, 1);
99 
100  if (fDrawAxes && axesNotDrawn)
101  {
102  DrawAxes(view, cryoCoordsLo, cryoCoordsHi, kBlue, 1, 1);
103  axesNotDrawn = true;
104  }
105 
106  // Now draw the TPC's associated to this cryostat
107  for(size_t tpcIdx = 0; tpcIdx < cryoGeo.NTPC(); tpcIdx++)
108  {
109  const geo::TPCGeo& tpcGeo = cryoGeo.TPC(tpcIdx);
110 
111  // Find the center of the current TPC
112  TVector3 tpcCenter = tpcGeo.GetCenter();
113 
114  // Now draw the standard volume
115  double coordsLo[] = {tpcCenter.X() - tpcGeo.HalfWidth(), tpcCenter.Y() - tpcGeo.HalfHeight(), tpcCenter.Z() - 0.5 * tpcGeo.Length()};
116  double coordsHi[] = {tpcCenter.X() + tpcGeo.HalfWidth(), tpcCenter.Y() + tpcGeo.HalfHeight(), tpcCenter.Z() + 0.5 * tpcGeo.Length()};
117 
118  std::cout << " - TPC: " << tpcGeo.ID() << ", low coord: " << coordsLo[0] << ", " << coordsLo[1] << ", " << coordsLo[2] << ", hi coord: " << coordsHi[0] << ", " << coordsHi[1] << ", " << coordsHi[2] << std::endl;
119 
120  DrawRectangularBox(view, coordsLo, coordsHi, kRed, 2, 1);
121 
122  // It could be that we don't want to see the grids
123  if (fDrawGrid) DrawGrids(view, coordsLo, coordsHi, tpcIdx > 0, kGray+2, 1, 1);
124 
125  if (fDrawBadChannels) DrawBadChannels(view, coordsHi, kGray, 1, 1);
126  }
127  }
128 
129  return;
130 }
131 
132 void ICARUSDrawer::DrawRectangularBox(evdb::View3D* view, double* coordsLo, double* coordsHi, int color, int width, int style)
133 {
134  TPolyLine3D& top = view->AddPolyLine3D(5, color, width, style);
135  top.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
136  top.SetPoint(1, coordsHi[0], coordsHi[1], coordsLo[2]);
137  top.SetPoint(2, coordsHi[0], coordsHi[1], coordsHi[2]);
138  top.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
139  top.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
140 
141  TPolyLine3D& side = view->AddPolyLine3D(5, color, width, style);
142  side.SetPoint(0, coordsHi[0], coordsHi[1], coordsLo[2]);
143  side.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
144  side.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
145  side.SetPoint(3, coordsHi[0], coordsHi[1], coordsHi[2]);
146  side.SetPoint(4, coordsHi[0], coordsHi[1], coordsLo[2]);
147 
148  TPolyLine3D& side2 = view->AddPolyLine3D(5, color, width, style);
149  side2.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
150  side2.SetPoint(1, coordsLo[0], coordsLo[1], coordsLo[2]);
151  side2.SetPoint(2, coordsLo[0], coordsLo[1], coordsHi[2]);
152  side2.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
153  side2.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
154 
155  TPolyLine3D& bottom = view->AddPolyLine3D(5, color, width, style);
156  bottom.SetPoint(0, coordsLo[0], coordsLo[1], coordsLo[2]);
157  bottom.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
158  bottom.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
159  bottom.SetPoint(3, coordsLo[0], coordsLo[1], coordsHi[2]);
160  bottom.SetPoint(4, coordsLo[0], coordsLo[1], coordsLo[2]);
161 
162  return;
163 }
164 
165 void ICARUSDrawer::DrawGrids(evdb::View3D* view, double* coordsLo, double* coordsHi, bool verticalGrid, int color, int width, int style)
166 {
167  double z = coordsLo[2];
168  // Grid running along x and y at constant z
169  while(1)
170  {
171  TPolyLine3D& gridt = view->AddPolyLine3D(2, color, style, width);
172  gridt.SetPoint(0, coordsLo[0], coordsLo[1], z);
173  gridt.SetPoint(1, coordsHi[0], coordsLo[1], z);
174 
175  if (verticalGrid)
176  {
177  TPolyLine3D& grids = view->AddPolyLine3D(2, color, style, width);
178  grids.SetPoint(0, coordsHi[0], coordsLo[1], z);
179  grids.SetPoint(1, coordsHi[0], coordsHi[1], z);
180  }
181 
182  z += 10.0;
183  if (z>coordsHi[2]) break;
184  }
185 
186  // Grid running along z at constant x
187  double x = coordsLo[0];
188  while(1)
189  {
190  TPolyLine3D& gridt = view->AddPolyLine3D(2, color, style, width);
191  gridt.SetPoint(0, x, coordsLo[1], coordsLo[2]);
192  gridt.SetPoint(1, x, coordsLo[1], coordsHi[2]);
193  x += 10.0;
194  if (x>coordsHi[0]) break;
195  }
196 
197  // Grid running along z at constant y
198  if (verticalGrid)
199  {
200  double y = coordsLo[1];
201  while(1)
202  {
203  TPolyLine3D& grids = view->AddPolyLine3D(2, color, style, width);
204  grids.SetPoint(0, coordsHi[0], y, coordsLo[2]);
205  grids.SetPoint(1, coordsHi[0], y, coordsHi[2]);
206  y += 10.0;
207  if (y>coordsHi[1]) break;
208  }
209  }
210 
211  return;
212 }
213 
214 void ICARUSDrawer::DrawAxes(evdb::View3D* view, double* coordsLo, double* coordsHi, int color, int width, int style)
215 {
216 
217  // Indicate coordinate system
218  double x0 = -0.20; // Center location of the key
219  double y0 = 1.10*coordsLo[1]; // Center location of the key
220  double z0 = -0.10*coordsHi[2]; // Center location of the key
221  double sz = 0.20*coordsHi[2]; // Scale size of the key in z direction
222 
223  TPolyLine3D& xaxis = view->AddPolyLine3D(2, color, style, width);
224  TPolyLine3D& yaxis = view->AddPolyLine3D(2, color, style, width);
225  TPolyLine3D& zaxis = view->AddPolyLine3D(2, color, style, width);
226  xaxis.SetPoint(0, x0, y0, z0);
227  xaxis.SetPoint(1, sz+x0, y0, z0);
228 
229  yaxis.SetPoint(0, x0, y0, z0);
230  yaxis.SetPoint(1, x0, y0+sz, z0);
231 
232  zaxis.SetPoint(0, x0, y0, z0);
233  zaxis.SetPoint(1, x0, y0, z0+sz);
234 
235  TPolyLine3D& xpoint = view->AddPolyLine3D(3, color, style, width);
236  TPolyLine3D& ypoint = view->AddPolyLine3D(3, color, style, width);
237  TPolyLine3D& zpoint = view->AddPolyLine3D(3, color, style, width);
238 
239  xpoint.SetPoint(0, 0.95*sz+x0, y0, z0-0.05*sz);
240  xpoint.SetPoint(1, 1.00*sz+x0, y0, z0);
241  xpoint.SetPoint(2, 0.95*sz+x0, y0, z0+0.05*sz);
242 
243  ypoint.SetPoint(0, x0, 0.95*sz+y0, z0-0.05*sz);
244  ypoint.SetPoint(1, x0, 1.00*sz+y0, z0);
245  ypoint.SetPoint(2, x0, 0.95*sz+y0, z0+0.05*sz);
246 
247  zpoint.SetPoint(0, x0-0.05*sz, y0, 0.95*sz+z0);
248  zpoint.SetPoint(1, x0+0.00*sz, y0, 1.00*sz+z0);
249  zpoint.SetPoint(2, x0+0.05*sz, y0, 0.95*sz+z0);
250 
251  TPolyLine3D& zleg = view->AddPolyLine3D(4, color, style, width);
252  zleg.SetPoint(0, x0-0.05*sz, y0+0.05*sz, z0+1.05*sz);
253  zleg.SetPoint(1, x0+0.05*sz, y0+0.05*sz, z0+1.05*sz);
254  zleg.SetPoint(2, x0-0.05*sz, y0-0.05*sz, z0+1.05*sz);
255  zleg.SetPoint(3, x0+0.05*sz, y0-0.05*sz, z0+1.05*sz);
256 
257  TPolyLine3D& yleg = view->AddPolyLine3D(5, color, style, width);
258  yleg.SetPoint(0, x0-0.05*sz, y0+1.15*sz, z0);
259  yleg.SetPoint(1, x0+0.00*sz, y0+1.10*sz, z0);
260  yleg.SetPoint(2, x0+0.00*sz, y0+1.05*sz, z0);
261  yleg.SetPoint(3, x0+0.00*sz, y0+1.10*sz, z0);
262  yleg.SetPoint(4, x0+0.05*sz, y0+1.15*sz, z0);
263 
264  TPolyLine3D& xleg = view->AddPolyLine3D(7, color, style, width);
265  xleg.SetPoint(0, x0+1.05*sz, y0+0.05*sz, z0-0.05*sz);
266  xleg.SetPoint(1, x0+1.05*sz, y0+0.00*sz, z0-0.00*sz);
267  xleg.SetPoint(2, x0+1.05*sz, y0+0.05*sz, z0+0.05*sz);
268  xleg.SetPoint(3, x0+1.05*sz, y0+0.00*sz, z0-0.00*sz);
269  xleg.SetPoint(4, x0+1.05*sz, y0-0.05*sz, z0-0.05*sz);
270  xleg.SetPoint(5, x0+1.05*sz, y0+0.00*sz, z0-0.00*sz);
271  xleg.SetPoint(6, x0+1.05*sz, y0-0.05*sz, z0+0.05*sz);
272 
273  return;
274 }
275 
276 void ICARUSDrawer::DrawBadChannels(evdb::View3D* view, double* coords, int color, int width, int style)
277 {
280 
281  lariov::ChannelStatusProvider const& channelStatus
283 
284  // We want to translate the wire position to the opposite side of the TPC...
285  for(size_t viewNo = 0; viewNo < geo->Nviews(); viewNo++)
286  {
287  for(size_t wireNo = 0; wireNo < geo->Nwires(viewNo); wireNo++)
288  {
289  geo::WireID wireID = geo::WireID(rawOpt->fCryostat, rawOpt->fTPC, viewNo, wireNo);
290 
291  raw::ChannelID_t channel = geo->PlaneWireToChannel(wireID);
292 
293  if (channelStatus.IsBad(channel))
294  {
295  const geo::WireGeo* wireGeo = geo->WirePtr(wireID);
296 
297  double wireStart[3];
298  double wireEnd[3];
299 
300  wireGeo->GetStart(wireStart);
301  wireGeo->GetEnd(wireEnd);
302 
303  TPolyLine3D& pl = view->AddPolyLine3D(2, color, style, width);
304  pl.SetPoint(0, coords[0]-0.5, wireStart[1], wireStart[2]);
305  pl.SetPoint(1, coords[0]-0.5, wireEnd[1], wireEnd[2]);
306  }
307  }
308  }
309 
310  return;
311 }
312 
313 
315 }
Float_t x
Definition: compare.C:6
geo::TPCID const & ID() const
Returns the identifier of this TPC.
Definition: TPCGeo.h:278
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
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:45
unsigned int fTPC
TPC number to draw, typically set by TWQProjectionView.
void WorldBox(double *xlo, double *xhi, double *ylo, double *yhi, double *zlo, double *zhi) const
Fills the arguments with the boundaries of the world.
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:279
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:90
cryostat_iterator end_cryostat() const
Returns an iterator pointing after the last cryostat.
Geometry information for a single TPC.
Definition: TPCGeo.h:37
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:93
bool fDrawBadChannels
true to draw bad channels
A collection of drawable 2-D objects.
Geometry information for a single cryostat.
Definition: CryostatGeo.h:36
bool fDrawAxes
true to draw coordinate axes
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.
double Length() const
Length is associated with z coordinate [cm].
Definition: TPCGeo.h:107
TPolyLine3D & AddPolyLine3D(int n, int c, int w, int s)
Definition: View3D.cxx:105
void DrawGrids(evdb::View3D *view, double *coordsLo, double *coordsHi, bool verticalGrid, int color=kGray, int width=1, int style=1)
void DrawRectangularBox(evdb::View3D *view, double *coordsLo, double *coordsHi, int color=kGray, int width=1, int style=1)
void DrawBadChannels(evdb::View3D *view, double *coords, int color, int width, int style)
unsigned int fCryostat
Cryostat number to draw, typically set by TWQProjectionView.
T get(std::string const &key) const
Definition: ParameterSet.h:231
double MinZ() const
Returns the world z coordinate of the start of the box.
unsigned int NTPC() const
Number of TPCs in this cryostat.
Definition: CryostatGeo.h:155
void configure(const fhicl::ParameterSet &pset)
bool fDrawGrid
true to draw backing grid
double MaxY() const
Returns the world y coordinate of the end of the box.
double HalfHeight() const
Height is associated with y coordinate [cm].
Definition: TPCGeo.h:103
cryostat_iterator begin_cryostat() const
Returns an iterator pointing to the first cryostat.
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.
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc&#39;th TPC in the cryostat.
void GetEnd(double *xyz) const
Definition: WireGeo.h:133
double MaxZ() const
Returns the world z coordinate of the end of the box.
void DrawAxes(evdb::View3D *view, double *coordsLo, double *coordsHi, int color=kGray, int width=1, int style=1)
void DetOutline3D(evdb::View3D *view) override
A collection of 3D drawable objects.
ICARUSDrawer(const fhicl::ParameterSet &pset)
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
Forward iterator browsing all geometry elements in the detector.
Definition: GeometryCore.h:688
This is the interface class for drawing 3D detector geometries.
Namespace collecting geometry-related classes utilities.
double MinY() const
Returns the world y coordinate of the start of the box.
art framework interface to geometry description
double HalfWidth() const
Width is associated with x coordinate [cm].
Definition: TPCGeo.h:99
geo::CryostatID const & ID() const
Returns the identifier of this cryostat.
Definition: CryostatGeo.h:116
Point GetCenter() const
Returns the center of the TPC volume in world coordinates [cm].
Definition: TPCGeo.h:693
WireGeo const * WirePtr(geo::WireID const &wireid) const
Returns the specified wire.