LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TWireProjPad.cxx
Go to the documentation of this file.
1 
9 #include <algorithm>
10 
11 #include "TCanvas.h"
12 #include "TClass.h"
13 #include "TFrame.h"
14 #include "TH1F.h"
15 #include "TList.h"
16 #include "TPad.h"
17 #include "TString.h"
18 #include "TVirtualPad.h"
19 
34 
38 
39 namespace {
40 
41  template <typename Stream>
42  void DumpPad(Stream&& log, TVirtualPad* pPad)
43  {
44  if (!pPad) {
45  log << "pad not available";
46  return;
47  }
48 
49  log << pPad->IsA()->GetName() << "[" << ((void*)pPad) << "](\"" << pPad->GetName() << "\")";
50  TFrame const* pFrame = pPad->GetFrame();
51  if (pFrame) {
52  double const low_wire = pFrame->GetX1(), high_wire = pFrame->GetX2();
53  double const low_tdc = pFrame->GetY1(), high_tdc = pFrame->GetY2();
54  double const wire_pixels = pPad->XtoAbsPixel(high_wire) - pPad->XtoAbsPixel(low_wire);
55  double const tdc_pixels = -(pPad->YtoAbsPixel(high_tdc) - pPad->YtoAbsPixel(low_tdc));
56  log << " has frame spanning wires " << low_wire << "-" << high_wire << " and TDC " << low_tdc
57  << "-" << high_tdc << " in a window " << wire_pixels << "x" << tdc_pixels << " pixel big";
58  }
59  else {
60  log << " has no frame";
61  }
62 
63  } // DumpPad()
64 
65  [[maybe_unused]] void DumpPadsInCanvas(TVirtualPad* pPad,
66  std::string caller,
67  std::string msg = "")
68  {
69  mf::LogDebug log(caller);
70  if (!msg.empty()) log << msg << ": ";
71  if (!pPad) {
72  log << "pad not available";
73  return;
74  }
75 
76  DumpPad(log, pPad);
77 
78  TCanvas const* pCanvas = pPad->GetCanvas();
79  log << "\nCanvas is: (TCanvas*) (" << ((void*)pPad->GetCanvas()) << ") with "
80  << pCanvas->GetListOfPrimitives()->GetSize() << " primitives and the following pads:";
81  TIterator* pIter = pCanvas->GetListOfPrimitives()->MakeIterator();
82  TObject const* pObject;
83  while ((pObject = pIter->Next())) {
84  if (!pObject->InheritsFrom(TVirtualPad::Class())) continue;
85  log << "\n " << ((pObject == pPad) ? '*' : '-') << " ";
86  DumpPad(log, (TVirtualPad*)pObject);
87  }
88  log << "\n";
89  delete pIter;
90  } // DumpPadsInCanvas()
91 
92 } // local namespace
93 
94 namespace evd {
95 
107  const char* ti,
108  double x1,
109  double x2,
110  double y1,
111  double y2,
112  unsigned int plane)
113  : DrawingPad(nm, ti, x1, x2, y1, y2), fPlane(plane)
114  {
115  fCurrentZoom.resize(4);
116 
118 
119  this->Pad()->cd();
120 
121  this->Pad()->SetLeftMargin(0.070);
122  this->Pad()->SetRightMargin(0.010);
123 
124  // how many planes in the detector and
125  // which plane is this one?
126 
127  unsigned int planes = geo->Nplanes();
128  this->Pad()->SetTopMargin(0.005);
129  this->Pad()->SetBottomMargin(0.110);
130 
131  // there has to be a better way of doing this that does
132  // not have a case for each number of planes in a detector
133  if (planes == 2 && fPlane > 0) {
134  this->Pad()->SetTopMargin(0.110);
135  this->Pad()->SetBottomMargin(0.005);
136  }
137  else if (planes > 2) {
138  if (fPlane == 1) {
139  this->Pad()->SetTopMargin(0.055);
140  this->Pad()->SetBottomMargin(0.055);
141  }
142  else if (fPlane == 2) {
143  this->Pad()->SetTopMargin(0.110);
144  this->Pad()->SetBottomMargin(0.005);
145  }
146  }
147 
148  TString planeNo = "fTWirePlane";
149  planeNo += fPlane;
150 
151  // picking the information from the current TPC
153  auto const signalType = geo->SignalType({rawopt->CurrentTPC(), fPlane});
154  TString xtitle = ";Induction Wire;t (tdc)";
155  if (signalType == geo::kCollection) xtitle = ";Collection Wire;t (tdc)";
156 
157  unsigned int const nWires = geo->Nwires({rawopt->CurrentTPC(), fPlane});
158  unsigned int const nTicks = RawDataDraw()->TotalClockTicks();
159 
160  fXLo = -0.005 * (nWires - 1);
161  fXHi = 1.005 * (nWires - 1);
162  fYLo = 0.990 * (unsigned int)(this->RawDataDraw()->StartTick());
163  fYHi = 1.005 * std::min((unsigned int)(this->RawDataDraw()->StartTick() + nTicks), nTicks);
164 
165  fOri = rawopt->fAxisOrientation;
166  if (fOri > 0) {
167  fYLo = -0.005 * (nWires - 1);
168  fYHi = 1.005 * (nWires - 1);
169  fYLo = 0.990 * (unsigned int)(this->RawDataDraw()->StartTick());
170  fYHi = 1.005 * std::min((unsigned int)(this->RawDataDraw()->StartTick() + nTicks), nTicks);
171  fXLo = -0.005 * nTicks;
172  fXHi = 1.010 * nTicks;
173  xtitle = ";t (tdc);InductionWire";
174  if (signalType == geo::kCollection) xtitle = ";t (tdc);Collection Wire";
175  }
176 
177  // make the range of the histogram be the biggest extent
178  // in both directions and then use SetRangeUser() to shrink it down
179  // that will allow us to change the axes on the fly
180  double min = std::min(fXLo, fYLo);
181  double max = std::max(fXHi, fYHi);
182 
183  fHisto = new TH1F(*(fPad->DrawFrame(min, min, max, max)));
184 
185  fHisto->SetTitleOffset(0.5, "Y");
186  fHisto->SetTitleOffset(0.75, "X");
188  fHisto->GetYaxis()->SetLabelSize(0.05);
189  fHisto->GetYaxis()->CenterTitle();
190  fHisto->GetXaxis()->SetLabelSize(0.05);
191  fHisto->GetXaxis()->CenterTitle();
192  fHisto->Draw("AB");
193 
194  fView = new evdb::View2D();
195  }
196 
197  //......................................................................
199  {
200  if (fHisto) {
201  delete fHisto;
202  fHisto = 0;
203  }
204  if (fView) {
205  delete fView;
206  fView = 0;
207  }
208  }
209 
210  //......................................................................
211  void TWireProjPad::Draw(const char* opt)
212  {
213  // DumpPadsInCanvas(fPad, "TWireProjPad", "Draw()");
214  MF_LOG_DEBUG("TWireProjPad") << "Started to draw plane " << fPlane;
215 
217  int kSelectedColor = 4;
218  fView->Clear();
219 
220  // grab the singleton holding the art::Event
221  art::Event const* evtPtr = evdb::EventHolder::Instance()->GetEvent();
222  if (evtPtr) {
223  auto const& evt = *evtPtr;
224  auto const clockData =
226  auto const detProp =
229 
231 
232  // the 2D pads have too much detail to be rendered on screen;
233  // to act smarter, RawDataDrawer needs to know the range being plotted
235  this->RawDataDraw()->RawDigit2D(
236  evt, detProp, fView, fPlane, GetDrawOptions().bZoom2DdrawToRoI);
237 
238  this->RecoBaseDraw()->Wire2D(evt, fView, fPlane);
239  this->RecoBaseDraw()->Hit2D(evt, detProp, fView, fPlane);
240 
241  if (recoOpt->fUseHitSelector)
242  this->RecoBaseDraw()->Hit2D(
243  this->HitSelectorGet()->GetSelectedHits(fPlane), kSelectedColor, fView, true);
244 
245  this->RecoBaseDraw()->Slice2D(evt, detProp, fView, fPlane);
246  this->RecoBaseDraw()->Cluster2D(evt, clockData, detProp, fView, fPlane);
247  this->RecoBaseDraw()->EndPoint2D(evt, fView, fPlane);
248  this->RecoBaseDraw()->Prong2D(evt, clockData, detProp, fView, fPlane);
249  this->RecoBaseDraw()->Vertex2D(evt, detProp, fView, fPlane);
250  this->RecoBaseDraw()->Seed2D(evt, detProp, fView, fPlane);
251  this->RecoBaseDraw()->OpFlash2D(evt, clockData, detProp, fView, fPlane);
252  this->RecoBaseDraw()->Event2D(evt, fView, fPlane);
253  this->RecoBaseDraw()->DrawTrackVertexAssns2D(evt, clockData, detProp, fView, fPlane);
254 
255  UpdatePad();
256  } // if (evt)
257 
259 
260  // check if we need to swap the axis ranges
262  if (fOri != rawopt->fAxisOrientation) {
263  fOri = rawopt->fAxisOrientation;
264  double max = fXHi;
265  double min = fXLo;
266  fXHi = fYHi;
267  fXLo = fYLo;
268  fYHi = max;
269  fYLo = min;
270 
272 
273  TString xtitle = fHisto->GetXaxis()->GetTitle();
274  fHisto->GetXaxis()->SetTitle(fHisto->GetYaxis()->GetTitle());
275  fHisto->GetYaxis()->SetTitle(xtitle);
276  }
277 
278  if (fPlane > 0)
279  fHisto->Draw("X+");
280  else
281  fHisto->Draw("");
282 
283  // Check if we should zoom the displays;
284  // if there is no event, we have no clue about the region of interest
285  // and therefore we don't touch anything
286  if (opt == 0 && evtPtr) { this->ShowFull(); }
287 
288  MF_LOG_DEBUG("TWireProjPad") << "Started rendering plane " << fPlane;
289 
290  fView->Draw();
291 
292  MF_LOG_DEBUG("TWireProjPad") << "Drawing of plane " << fPlane << " completed";
293  }
294 
295  //......................................................................
297  {
299  if (recoOpt->fUseHitSelector) {
301  this->Draw();
302  }
303  }
304 
305  //......................................................................
306  // the override parameter is needed to unzoom to full range when the fAutoZoomInterest is on.
307 
308  void TWireProjPad::ShowFull(int override)
309  {
310  // x values are wire numbers, y values are ticks of the clock
311  int xmin = fXLo;
312  int xmax = fXHi;
313  int ymax = fYHi;
314  int ymin = fYLo;
315 
318 
319  if (GetDrawOptions().bZoom2DdrawToRoI && !override) {
320  int test = 0;
321  if (rawopt->fDrawRawDataOrCalibWires == 0)
322  test = RawDataDraw()->GetRegionOfInterest((int)fPlane, xmin, xmax, ymin, ymax);
323  else
324  test = RecoBaseDraw()->GetRegionOfInterest((int)fPlane, xmin, xmax, ymin, ymax);
325 
326  if (test != 0) return;
327  }
328 
329  SetZoomRange(xmin, xmax, ymin, ymax);
330  }
331 
332  //......................................................................
333  void TWireProjPad::GetWireRange(int* i1, int* i2) const
334  {
335  if (fOri < 1) {
336  *i1 = fHisto->GetXaxis()->GetFirst();
337  *i2 = fHisto->GetXaxis()->GetLast();
338  }
339  else {
340  *i1 = fHisto->GetYaxis()->GetFirst();
341  *i2 = fHisto->GetYaxis()->GetLast();
342  }
343  }
344 
345  //......................................................................
346  // Set the X axis range only
347  //
348  void TWireProjPad::SetWireRange(int i1, int i2)
349  {
350  if (fOri < 1) { fHisto->GetXaxis()->SetRange(i1, i2); }
351  else {
352  fHisto->GetYaxis()->SetRange(i1, i2);
353  }
354  fCurrentZoom[0] = i1;
355  fCurrentZoom[1] = i2;
356  }
357 
358  //......................................................................
359  // Set the visible range of the wire / time view
360  //
361  void TWireProjPad::SetZoomRange(int i1, int i2, int y1, int y2)
362  {
363  MF_LOG_DEBUG("TWireProjPad") << "SetZoomRange(" << i1 << ", " << i2 << ", " << y1 << ", " << y2
364  << ") on plane #" << fPlane;
365 
366  fHisto->GetXaxis()->SetRangeUser(i1, i2);
367  fHisto->GetYaxis()->SetRangeUser(y1, y2);
368  fCurrentZoom[0] = i1;
369  fCurrentZoom[1] = i2;
370  fCurrentZoom[2] = y1;
371  fCurrentZoom[3] = y2;
372  }
373 
374  //......................................................................
375  // Set the visible range of the wire / time view from the view
376  //
378  {
379  TAxis const& xaxis = *(fHisto->GetXaxis());
380  fCurrentZoom[0] = xaxis.GetBinLowEdge(xaxis.GetFirst());
381  fCurrentZoom[1] = xaxis.GetBinUpEdge(xaxis.GetLast());
382  fCurrentZoom[2] = fHisto->GetMinimum();
383  fCurrentZoom[3] = fHisto->GetMaximum();
384  MF_LOG_DEBUG("TWireProjPad") << "Zoom set to wires (" << fCurrentZoom[0] << "; "
385  << fCurrentZoom[1] << " ), tick (" << fCurrentZoom[2] << "; "
386  << fCurrentZoom[3] << ") for plane #" << fPlane;
387  } // TWireProjPad::SetZoomFromView()
388  //......................................................................
390  double i2,
391  double y1,
392  double y2,
393  double distance,
394  const char* zoom_opt,
395  bool good_plane)
396  {
397  const art::Event* evtPtr = evdb::EventHolder::Instance()->GetEvent();
398  if (evtPtr) {
399  auto const& evt = *evtPtr;
401  if (recoopt->fUseHitSelector) {
402  this->HitSelectorGet()->SaveHits(evt, fPlane, i1, i2, y1, y2, distance, good_plane);
403  this->Draw(zoom_opt);
404  }
405  }
406  }
407 
409  // Pass the seed list onwards to InfoTransfer
410  //
411  double TWireProjPad::SaveSeedList(std::vector<util::PxLine> seedlines, double distance)
412  {
413  double KineticEnergy = util::kBogusD;
415  if (evt) {
417  if (recoopt->fUseHitSelector)
418  KineticEnergy = this->HitSelectorGet()->SaveSeedLines(*evt, seedlines, distance);
419  }
420  return KineticEnergy;
421  }
422 
423  //......................................................................
424  void TWireProjPad::SelectOneHit(double x, double y, const char* zoom_opt)
425  {
426 
428  if (evt) {
430  if (recoopt->fUseHitSelector) {
431  this->HitSelectorGet()->ChangeHit(*evt, fPlane, x, y);
432  this->Draw(zoom_opt);
433  }
434  }
435  }
436 
437  //......................................................................
439  {
440  fPad->Clear();
441  this->UpdatePad();
442 
443  return;
444  }
445 
446  //......................................................................
448  {
449  fPad->cd();
450  fPad->Modified();
451  fPad->Update();
452  fPad->GetFrame()->SetBit(TPad::kCannotMove, true);
453  fPad->SetBit(TPad::kCannotMove, true);
454 
455  return;
456  }
457 
458  //......................................................................
459  void TWireProjPad::DrawLinesinView(std::vector<util::PxLine> lines,
460  bool deleting,
461  const char* zoom_opt)
462  {
463  fPad->cd();
464  if (deleting) {
465  fPad->Clear();
466  this->Draw(zoom_opt);
467  }
468  else {
469  fView->Clear();
470  fView->Draw();
471  }
472 
473  mf::LogVerbatim("TWireProjPad") << "Drawing " << lines.size() << " lines";
474 
475  for (size_t is = 0; is < lines.size(); ++is) {
476  if (fPlane != lines[is].plane) continue;
477 
478  TLine& l = fView->AddLine(lines[is].w0, lines[is].t0, lines[is].w1, lines[is].t1);
479 
480  fView->Draw();
481  evd::Style::FromPDG(l, 11);
482  }
483 
484  fView->Draw();
485  UpdatePad();
486  fView->Draw();
487 
488  return;
489  }
490 
491 } // namespace
Float_t x
Definition: compare.C:6
int GetRegionOfInterest(int plane, int &minw, int &maxw, int &mint, int &maxt)
code to link reconstructed objects back to the MC truth information
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const art::Event * GetEvent() const
Definition: EventHolder.cxx:45
TTree * t1
Definition: plottest35.C:26
void SaveHits(const art::Event &evt, unsigned int plane, double x, double y, double x1, double y1, double distance, bool good_plane=true)
Definition: HitSelector.cxx:85
Float_t y1[n_points_granero]
Definition: compare.C:5
Drawing pad showing a single X-Z or Y-Z projection of an event.
int fDrawRawDataOrCalibWires
0 for raw
Float_t x1[n_points_granero]
Definition: compare.C:5
TLine & AddLine(double x1, double y1, double x2, double y2)
Definition: View2D.cxx:187
unsigned int fPlane
Which plane in the detector.
Definition: TWireProjPad.h:92
Float_t y
Definition: compare.C:6
double SaveSeedList(std::vector< util::PxLine > seedlines, double distance)
void Draw(const char *opt=0)
void ShowFull(int override=0)
double fXLo
Low value of x axis.
Definition: TWireProjPad.h:96
void RawDigit2D(art::Event const &evt, detinfo::DetectorPropertiesData const &detProp, evdb::View2D *view, unsigned int plane, bool bZoomToRoI=false)
Draws raw digit content in 2D wire plane representation.
A collection of drawable 2-D objects.
static void FromPDG(TLine &line, int pdgcode)
Definition: Style.cxx:131
void Prong2D(const art::Event &evt, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, evdb::View2D *view, unsigned int plane)
TGaxis * xaxis
Definition: plot_hist.C:61
void Clear()
Definition: View2D.cxx:109
Singleton to hold the current art::Event for the event display.
Float_t y2[n_points_geant4]
Definition: compare.C:26
void Slice2D(const art::Event &evt, detinfo::DetectorPropertiesData const &detProp, evdb::View2D *view, unsigned int plane)
void Cluster2D(const art::Event &evt, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, evdb::View2D *view, unsigned int plane)
void DrawTrackVertexAssns2D(const art::Event &evt, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, evdb::View2D *view, unsigned int plane)
std::vector< double > const & GetCurrentZoom() const
Definition: TWireProjPad.h:83
void SaveHitList(double i1, double i2, double y1, double y2, double distance, const char *zoom_opt, bool good_plane=true)
void ClearHitList(unsigned int plane)
void Seed2D(const art::Event &evt, detinfo::DetectorPropertiesData const &detProp, evdb::View2D *view, unsigned int plane)
void SelectOneHit(double x, double y, const char *zoom_opt)
LArSoft includes.
RawDataDrawer * RawDataDraw()
Definition: DrawingPad.cxx:121
void Draw()
Definition: View2D.cxx:89
int fOri
Orientation of the axes - see RawDrawingOptions for values.
Definition: TWireProjPad.h:100
Class to perform operations needed to select hits and pass them to a cluster.
static EventHolder * Instance()
Definition: EventHolder.cxx:15
double fXHi
High value of x axis.
Definition: TWireProjPad.h:97
DrawOptions_t const & GetDrawOptions() const
Return the current draw options.
Definition: TWireProjPad.h:48
Base class for event display drawing pads.
Definition: DrawingPad.h:27
RecoBaseDrawer * RecoBaseDraw()
Definition: DrawingPad.cxx:132
int Hit2D(const art::Event &evt, detinfo::DetectorPropertiesData const &detProp, evdb::View2D *view, unsigned int plane)
TPad * Pad()
Definition: DrawingPad.h:31
geo::TPCID CurrentTPC() const
Returns the current TPC as a TPCID.
double TotalClockTicks() const
Definition: RawDataDrawer.h:84
double fYLo
Low value of y axis.
Definition: TWireProjPad.h:98
SimulationDrawer * SimulationDraw()
Definition: DrawingPad.cxx:112
Class to aid in the rendering of RecoBase objects.
TH1F * fHisto
Histogram to draw object on.
Definition: TWireProjPad.h:93
Class to aid in the rendering of RawData objects.
void DrawLinesinView(std::vector< util::PxLine > lines, bool deleting=false, const char *zoom_opt=0)
void SetWireRange(int i1, int i2)
double StartTick() const
Definition: RawDataDrawer.h:83
void ChangeHit(const art::Event &evt, unsigned int plane, double x, double y)
SigType_t SignalType(PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
void SetZoomRange(int i1, int i2, int y1, int y2)
void EndPoint2D(const art::Event &evt, evdb::View2D *view, unsigned int plane)
void Wire2D(const art::Event &evt, evdb::View2D *view, unsigned int plane)
#define MF_LOG_DEBUG(id)
Render the objects from the Simulation package.
HitSelector * HitSelectorGet()
Definition: DrawingPad.cxx:155
unsigned int Nwires(PlaneID const &planeid) const
Returns the total number of wires in the specified plane.
int fAxisOrientation
0 = TDC values on y-axis, wire number on x-axis, 1 = swapped
static const char * zoom_opt
unsigned int Nplanes(TPCID const &tpcid=tpc_zero) const
Returns the total number of planes in the specified TPC.
Definition: GeometryCore.h:977
void OpFlash2D(const art::Event &evt, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, evdb::View2D *view, unsigned int plane)
double SaveSeedLines(const art::Event &evt, std::vector< util::PxLine > seedline, double distance)
Definition: HitSelector.cxx:48
int GetRegionOfInterest(int plane, int &minw, int &maxw, int &mint, int &maxt)
void MCTruthVectors2D(const art::Event &evt, evdb::View2D *view, unsigned int plane)
void Event2D(const art::Event &evt, evdb::View2D *view, unsigned int plane)
constexpr double kBogusD
obviously bogus double value
TPad * fPad
The ROOT graphics pad.
Definition: DrawingPad.h:45
void SetZoomFromView()
Sets the zoom parameters from the current histogram view.
TCEvent evt
Definition: DataStructs.cxx:8
void Vertex2D(const art::Event &evt, detinfo::DetectorPropertiesData const &detProp, evdb::View2D *view, unsigned int plane)
void GetWireRange(int *i1, int *i2) const
Float_t x2[n_points_geant4]
Definition: compare.C:26
std::vector< double > fCurrentZoom
Definition: TWireProjPad.h:89
Namespace collecting geometry-related classes utilities.
double fYHi
High value of y axis.
Definition: TWireProjPad.h:99
art framework interface to geometry description
evdb::View2D * fView
Collection of graphics objects to render.
Definition: TWireProjPad.h:94
Signal from collection planes.
Definition: geo_types.h:152
TWireProjPad(const char *nm, const char *ti, double x1, double y1, double x2, double y2, unsigned int plane)
void ExtractRange(TVirtualPad *pPad, std::vector< double > const *zoom=nullptr)
Fills the viewport information from the specified pad.