LArSoft  v10_04_05
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 
117  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout const>()->Get();
118  Pad()->cd();
119 
120  Pad()->SetLeftMargin(0.070);
121  Pad()->SetRightMargin(0.010);
122 
123  // how many planes in the detector and
124  // which plane is this one?
125 
126  unsigned int planes = wireReadoutGeom.Nplanes();
127  Pad()->SetTopMargin(0.005);
128  Pad()->SetBottomMargin(0.110);
129 
130  // there has to be a better way of doing this that does
131  // not have a case for each number of planes in a detector
132  if (planes == 2 && fPlane > 0) {
133  Pad()->SetTopMargin(0.110);
134  Pad()->SetBottomMargin(0.005);
135  }
136  else if (planes > 2) {
137  if (fPlane == 1) {
138  Pad()->SetTopMargin(0.055);
139  Pad()->SetBottomMargin(0.055);
140  }
141  else if (fPlane == 2) {
142  Pad()->SetTopMargin(0.110);
143  Pad()->SetBottomMargin(0.005);
144  }
145  }
146 
147  TString planeNo = "fTWirePlane";
148  planeNo += fPlane;
149 
150  // picking the information from the current TPC
152  auto const signalType = wireReadoutGeom.SignalType({rawopt->CurrentTPC(), fPlane});
153  TString xtitle = ";Induction Wire;t (tdc)";
154  if (signalType == geo::kCollection) xtitle = ";Collection Wire;t (tdc)";
155 
156  unsigned int const nWires = wireReadoutGeom.Nwires({rawopt->CurrentTPC(), fPlane});
157  unsigned int const nTicks = RawDataDraw()->TotalClockTicks();
158 
159  fXLo = -0.005 * (nWires - 1);
160  fXHi = 1.005 * (nWires - 1);
161  fYLo = 0.990 * (unsigned int)(RawDataDraw()->StartTick());
162  fYHi = 1.005 * std::min((unsigned int)(RawDataDraw()->StartTick() + nTicks), nTicks);
163 
164  fOri = rawopt->fAxisOrientation;
165  if (fOri > 0) {
166  fYLo = -0.005 * (nWires - 1);
167  fYHi = 1.005 * (nWires - 1);
168  fYLo = 0.990 * (unsigned int)(RawDataDraw()->StartTick());
169  fYHi = 1.005 * std::min((unsigned int)(RawDataDraw()->StartTick() + nTicks), nTicks);
170  fXLo = -0.005 * nTicks;
171  fXHi = 1.010 * nTicks;
172  xtitle = ";t (tdc);InductionWire";
173  if (signalType == geo::kCollection) xtitle = ";t (tdc);Collection Wire";
174  }
175 
176  // make the range of the histogram be the biggest extent
177  // in both directions and then use SetRangeUser() to shrink it down
178  // that will allow us to change the axes on the fly
179  double min = std::min(fXLo, fYLo);
180  double max = std::max(fXHi, fYHi);
181 
182  fHisto = new TH1F(*(fPad->DrawFrame(min, min, max, max)));
183 
184  fHisto->SetTitleOffset(0.5, "Y");
185  fHisto->SetTitleOffset(0.75, "X");
187  fHisto->GetYaxis()->SetLabelSize(0.05);
188  fHisto->GetYaxis()->CenterTitle();
189  fHisto->GetXaxis()->SetLabelSize(0.05);
190  fHisto->GetXaxis()->CenterTitle();
191  fHisto->Draw("AB");
192 
193  fView = new evdb::View2D();
194  }
195 
196  //......................................................................
198  {
199  if (fHisto) {
200  delete fHisto;
201  fHisto = 0;
202  }
203  if (fView) {
204  delete fView;
205  fView = 0;
206  }
207  }
208 
209  //......................................................................
210  void TWireProjPad::Draw(const char* opt)
211  {
212  // DumpPadsInCanvas(fPad, "TWireProjPad", "Draw()");
213  MF_LOG_DEBUG("TWireProjPad") << "Started to draw plane " << fPlane;
214 
216  int kSelectedColor = 4;
217  fView->Clear();
218 
219  // grab the singleton holding the art::Event
220  art::Event const* evtPtr = evdb::EventHolder::Instance()->GetEvent();
221  if (evtPtr) {
222  auto const& evt = *evtPtr;
223  auto const clockData =
225  auto const detProp =
228 
230 
231  // the 2D pads have too much detail to be rendered on screen;
232  // to act smarter, RawDataDrawer needs to know the range being plotted
234  RawDataDraw()->RawDigit2D(evt, detProp, fView, fPlane, GetDrawOptions().bZoom2DdrawToRoI);
235 
237  RecoBaseDraw()->Hit2D(evt, detProp, fView, fPlane);
238 
239  if (recoOpt->fUseHitSelector)
240  RecoBaseDraw()->Hit2D(
241  HitSelectorGet()->GetSelectedHits(fPlane), kSelectedColor, fView, true);
242 
243  RecoBaseDraw()->Slice2D(evt, detProp, fView, fPlane);
244  RecoBaseDraw()->Cluster2D(evt, clockData, detProp, fView, fPlane);
246  RecoBaseDraw()->Prong2D(evt, clockData, detProp, fView, fPlane);
247  RecoBaseDraw()->Vertex2D(evt, detProp, fView, fPlane);
248  RecoBaseDraw()->Seed2D(evt, detProp, fView, fPlane);
249  RecoBaseDraw()->OpFlash2D(evt, clockData, detProp, fView, fPlane);
251  RecoBaseDraw()->DrawTrackVertexAssns2D(evt, clockData, detProp, fView, fPlane);
252 
253  UpdatePad();
254  } // if (evt)
255 
257 
258  // check if we need to swap the axis ranges
260  if (fOri != rawopt->fAxisOrientation) {
261  fOri = rawopt->fAxisOrientation;
262  double max = fXHi;
263  double min = fXLo;
264  fXHi = fYHi;
265  fXLo = fYLo;
266  fYHi = max;
267  fYLo = min;
268 
270 
271  TString xtitle = fHisto->GetXaxis()->GetTitle();
272  fHisto->GetXaxis()->SetTitle(fHisto->GetYaxis()->GetTitle());
273  fHisto->GetYaxis()->SetTitle(xtitle);
274  }
275 
276  if (fPlane > 0)
277  fHisto->Draw("X+");
278  else
279  fHisto->Draw("");
280 
281  // Check if we should zoom the displays;
282  // if there is no event, we have no clue about the region of interest
283  // and therefore we don't touch anything
284  if (opt == 0 && evtPtr) { ShowFull(); }
285 
286  MF_LOG_DEBUG("TWireProjPad") << "Started rendering plane " << fPlane;
287 
288  fView->Draw();
289 
290  MF_LOG_DEBUG("TWireProjPad") << "Drawing of plane " << fPlane << " completed";
291  }
292 
293  //......................................................................
295  {
297  if (recoOpt->fUseHitSelector) {
299  Draw();
300  }
301  }
302 
303  //......................................................................
304  // the override parameter is needed to unzoom to full range when the fAutoZoomInterest is on.
305 
306  void TWireProjPad::ShowFull(int override)
307  {
308  // x values are wire numbers, y values are ticks of the clock
309  int xmin = fXLo;
310  int xmax = fXHi;
311  int ymax = fYHi;
312  int ymin = fYLo;
313 
316 
317  if (GetDrawOptions().bZoom2DdrawToRoI && !override) {
318  int test = 0;
319  if (rawopt->fDrawRawDataOrCalibWires == 0)
320  test = RawDataDraw()->GetRegionOfInterest((int)fPlane, xmin, xmax, ymin, ymax);
321  else
322  test = RecoBaseDraw()->GetRegionOfInterest((int)fPlane, xmin, xmax, ymin, ymax);
323 
324  if (test != 0) return;
325  }
326 
327  SetZoomRange(xmin, xmax, ymin, ymax);
328  }
329 
330  //......................................................................
331  void TWireProjPad::GetWireRange(int* i1, int* i2) const
332  {
333  if (fOri < 1) {
334  *i1 = fHisto->GetXaxis()->GetFirst();
335  *i2 = fHisto->GetXaxis()->GetLast();
336  }
337  else {
338  *i1 = fHisto->GetYaxis()->GetFirst();
339  *i2 = fHisto->GetYaxis()->GetLast();
340  }
341  }
342 
343  //......................................................................
344  // Set the X axis range only
345  //
346  void TWireProjPad::SetWireRange(int i1, int i2)
347  {
348  if (fOri < 1) { fHisto->GetXaxis()->SetRange(i1, i2); }
349  else {
350  fHisto->GetYaxis()->SetRange(i1, i2);
351  }
352  fCurrentZoom[0] = i1;
353  fCurrentZoom[1] = i2;
354  }
355 
356  //......................................................................
357  // Set the visible range of the wire / time view
358  //
359  void TWireProjPad::SetZoomRange(int i1, int i2, int y1, int y2)
360  {
361  MF_LOG_DEBUG("TWireProjPad") << "SetZoomRange(" << i1 << ", " << i2 << ", " << y1 << ", " << y2
362  << ") on plane #" << fPlane;
363 
364  fHisto->GetXaxis()->SetRangeUser(i1, i2);
365  fHisto->GetYaxis()->SetRangeUser(y1, y2);
366  fCurrentZoom[0] = i1;
367  fCurrentZoom[1] = i2;
368  fCurrentZoom[2] = y1;
369  fCurrentZoom[3] = y2;
370  }
371 
372  //......................................................................
373  // Set the visible range of the wire / time view from the view
374  //
376  {
377  TAxis const& xaxis = *(fHisto->GetXaxis());
378  fCurrentZoom[0] = xaxis.GetBinLowEdge(xaxis.GetFirst());
379  fCurrentZoom[1] = xaxis.GetBinUpEdge(xaxis.GetLast());
380  fCurrentZoom[2] = fHisto->GetMinimum();
381  fCurrentZoom[3] = fHisto->GetMaximum();
382  MF_LOG_DEBUG("TWireProjPad") << "Zoom set to wires (" << fCurrentZoom[0] << "; "
383  << fCurrentZoom[1] << " ), tick (" << fCurrentZoom[2] << "; "
384  << fCurrentZoom[3] << ") for plane #" << fPlane;
385  } // TWireProjPad::SetZoomFromView()
386  //......................................................................
388  double i2,
389  double y1,
390  double y2,
391  double distance,
392  const char* zoom_opt,
393  bool good_plane)
394  {
395  const art::Event* evtPtr = evdb::EventHolder::Instance()->GetEvent();
396  if (evtPtr) {
397  auto const& evt = *evtPtr;
399  if (recoopt->fUseHitSelector) {
400  HitSelectorGet()->SaveHits(evt, fPlane, i1, i2, y1, y2, distance, good_plane);
401  Draw(zoom_opt);
402  }
403  }
404  }
405 
407  // Pass the seed list onwards to InfoTransfer
408  //
409  double TWireProjPad::SaveSeedList(std::vector<util::PxLine> seedlines, double distance)
410  {
411  double KineticEnergy = util::kBogusD;
413  if (evt) {
415  if (recoopt->fUseHitSelector)
416  KineticEnergy = HitSelectorGet()->SaveSeedLines(*evt, seedlines, distance);
417  }
418  return KineticEnergy;
419  }
420 
421  //......................................................................
422  void TWireProjPad::SelectOneHit(double x, double y, const char* zoom_opt)
423  {
424 
426  if (evt) {
428  if (recoopt->fUseHitSelector) {
429  HitSelectorGet()->ChangeHit(*evt, fPlane, x, y);
430  Draw(zoom_opt);
431  }
432  }
433  }
434 
435  //......................................................................
437  {
438  fPad->Clear();
439  UpdatePad();
440 
441  return;
442  }
443 
444  //......................................................................
446  {
447  fPad->cd();
448  fPad->Modified();
449  fPad->Update();
450  fPad->GetFrame()->SetBit(TPad::kCannotMove, true);
451  fPad->SetBit(TPad::kCannotMove, true);
452 
453  return;
454  }
455 
456  //......................................................................
457  void TWireProjPad::DrawLinesinView(std::vector<util::PxLine> lines,
458  bool deleting,
459  const char* zoom_opt)
460  {
461  fPad->cd();
462  if (deleting) {
463  fPad->Clear();
464  Draw(zoom_opt);
465  }
466  else {
467  fView->Clear();
468  fView->Draw();
469  }
470 
471  mf::LogVerbatim("TWireProjPad") << "Drawing " << lines.size() << " lines";
472 
473  for (size_t is = 0; is < lines.size(); ++is) {
474  if (fPlane != lines[is].plane) continue;
475 
476  TLine& l = fView->AddLine(lines[is].w0, lines[is].t0, lines[is].w1, lines[is].t1);
477 
478  fView->Draw();
479  evd::Style::FromPDG(l, 11);
480  }
481 
482  fView->Draw();
483  UpdatePad();
484  fView->Draw();
485 
486  return;
487  }
488 
489 } // 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:86
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.
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
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:26
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:30
geo::TPCID CurrentTPC() const
Returns the current TPC as a TPCID.
double TotalClockTicks() const
Definition: RawDataDrawer.h:78
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:77
void ChangeHit(const art::Event &evt, unsigned int plane, double x, double y)
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
int fAxisOrientation
0 = TDC values on y-axis, wire number on x-axis, 1 = swapped
static const char * zoom_opt
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:49
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:44
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
double fYHi
High value of y axis.
Definition: TWireProjPad.h:99
evdb::View2D * fView
Collection of graphics objects to render.
Definition: TWireProjPad.h:94
Signal from collection planes.
Definition: geo_types.h:148
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.