TQPad.cxx
Go to the documentation of this file.
1 ///
2 /// \file TQPad.cxx
3 /// \brief Drawing pad for time or charge histograms
4 /// \author messier@indiana.edu
5 ///
7 #include "TH1F.h"
8 #include "TPad.h"
9 
11 #include "cetlib_except/exception.h"
12 
20 #include "nuevdb/EventDisplayBase/EventHolder.h"
21 #include "nuevdb/EventDisplayBase/View2D.h"
22 
23 // C/C++ standard libraries
24 #include <algorithm> // std::min(), std::max()
25 
26 namespace evd {
27 
28  static const int kRAW = 0;
29  static const int kCALIB = 1;
30  //static const int kRAWCALIB = 2;
31  static const int kQ = 0;
32  static const int kTQ = 1;
33 
34  //......................................................................
35 
36  TQPad::TQPad(const char* nm,
37  const char* ti,
38  double x1,
39  double y1,
40  double x2,
41  double y2,
42  const char* opt,
43  unsigned int plane,
44  unsigned int wire)
45  : DrawingPad(nm, ti, x1, y1, x2, y2), fWire(wire), fPlane(plane), fFrameHist(0)
46  {
48  unsigned int planes = geo->Nplanes();
49 
50  this->Pad()->cd();
51 
52  this->Pad()->SetLeftMargin(0.050);
53  this->Pad()->SetRightMargin(0.050);
54 
55  this->Pad()->SetTopMargin(0.005);
56  this->Pad()->SetBottomMargin(0.110);
57 
58  // there has to be a better way of doing this that does
59  // not have a case for each number of planes in a detector
60  if (planes == 2 && fPlane > 0) {
61  this->Pad()->SetTopMargin(0.110);
62  this->Pad()->SetBottomMargin(0.010);
63  }
64  else if (planes > 2) {
65  if (fPlane == 1) {
66  this->Pad()->SetTopMargin(0.005);
67  this->Pad()->SetBottomMargin(0.010);
68  }
69  else if (fPlane == 2) {
70  this->Pad()->SetTopMargin(0.110);
71  this->Pad()->SetBottomMargin(0.010);
72  }
73  }
74 
75  std::string opts(opt);
76  if (opts == "TQ") {
77  fTQ = kTQ;
78  // BB adjust the vertical spacing
79  this->Pad()->SetTopMargin(0);
80  this->Pad()->SetBottomMargin(0.2);
81  }
82  if (opts == "Q") { fTQ = kQ; }
83 
84  this->BookHistogram();
85  fView = new evdb::View2D();
86 
89 
90  fHitDrawerTool = art::make_tool<evdb_tool::IWFHitDrawer>(recoOptions->fHitDrawerParams);
92  art::make_tool<evdb_tool::IWaveformDrawer>(rawOptions->fRawDigitDrawerParams);
93  fWireDrawerTool = art::make_tool<evdb_tool::IWaveformDrawer>(recoOptions->fWireDrawerParams);
94  }
95 
96  //......................................................................
97 
99  {
100  if (fView) {
101  delete fView;
102  fView = 0;
103  }
104  if (fFrameHist) {
105  delete fFrameHist;
106  fFrameHist = 0;
107  }
108  }
109 
110  //......................................................................
111  void
113  {
115 
116  //grab the singleton with the event
117  const art::Event* evt = evdb::EventHolder::Instance()->GetEvent();
118  if (!evt) return;
119 
121 
122  fPad->Clear();
123  fPad->cd();
124 
125  // Note this handles drawing waveforms for both SP and DP where the difference is handled by the tools
126  if (fTQ == kTQ) {
127  // Recover a channel number from current information
129  geoSvc->PlaneWireToChannel(fPlane, fWire, drawopt->fTPC, drawopt->fCryostat);
130 
131  // Call the tools to fill the histograms for RawDigits and Wire data
132  fRawDigitDrawerTool->Fill(
133  *fView, channel, this->RawDataDraw()->StartTick(), this->RawDataDraw()->TotalClockTicks());
134  fWireDrawerTool->Fill(
135  *fView, channel, this->RawDataDraw()->StartTick(), this->RawDataDraw()->TotalClockTicks());
136 
137  // Vertical limits set for the enclosing histogram, then draw it with axes only
138  float maxLowVal = std::min(fRawDigitDrawerTool->getMinimum(), fWireDrawerTool->getMinimum());
139  float maxHiVal = std::max(fRawDigitDrawerTool->getMaximum(), fWireDrawerTool->getMaximum());
140 
141  if (drawopt->fDrawRawDataOrCalibWires == kCALIB) {
142  maxLowVal = fWireDrawerTool->getMinimum();
143  maxHiVal = fWireDrawerTool->getMaximum();
144  }
145 
146  if (maxLowVal < std::numeric_limits<float>::max())
147  maxLowVal -= 5.;
148  else
149  maxLowVal = -10.;
150  if (maxHiVal > std::numeric_limits<float>::lowest())
151  maxHiVal += 5.;
152  else
153  maxHiVal = 10.;
154 
155  fFrameHist->SetMaximum(maxHiVal);
156  fFrameHist->SetMinimum(maxLowVal);
157  fFrameHist->Draw("AXIS");
158 
159  // draw with histogram style, only (square) lines, no errors
160  static const std::string defaultDrawOptions = "HIST same";
161 
162  // Draw the desired histograms
163  // If its not just the raw hists then we output the wire histograms
164  if (drawopt->fDrawRawDataOrCalibWires != kRAW) {
165  fWireDrawerTool->Draw(defaultDrawOptions.c_str(), maxLowVal, maxHiVal);
166 
167  fHitDrawerTool->Draw(*fView, channel);
168  }
169 
170  // Likewise, if it is not just the calib hists then we output the raw histogram
171  if (drawopt->fDrawRawDataOrCalibWires != kCALIB)
172  fRawDigitDrawerTool->Draw(defaultDrawOptions.c_str(), maxLowVal, maxHiVal);
173 
174  // This is a remnant from a time long past...
175  fFrameHist->SetTitleOffset(0.2, "Y");
176  } // end if fTQ == kTQ
177 
178  // I am not sure what the block below is trying to do... I don't see where the hists are actually filled.
179  // ** remove this for now until someone can explain what it is **
180  // else if(fTQ == kQ && fTQ == -1)
181  // {
182  // // figure out the signal type for this plane, assume that
183  // // plane n in each TPC/cryostat has the same type
184  // geo::PlaneID planeid(drawopt->CurrentTPC(), fPlane);
185  // geo::SigType_t sigType = geoSvc->SignalType(planeid);
186  //
187  // art::ServiceHandle<evd::ColorDrawingOptions const> cst;
188  //
189  // TH1F *hist;
190  //
191  // int ndiv = 0;
192  // if(drawopt->fDrawRawDataOrCalibWires != kCALIB){
193  // hist = fRawHisto;
194  // hist->SetMinimum(cst->fRawQLow [(size_t)sigType]);
195  // hist->SetMaximum(cst->fRawQHigh[(size_t)sigType]);
196  // ndiv = cst->fRawDiv[(size_t)sigType];
197  // }
198  // if(drawopt->fDrawRawDataOrCalibWires == kCALIB){
199  // hist = fRecoHisto;
200  // hist->SetMinimum(cst->fRecoQLow [(size_t)sigType]);
201  // hist->SetMaximum(cst->fRecoQHigh[(size_t)sigType]);
202  // ndiv = cst->fRecoDiv[(size_t)sigType];
203  // }
204  //
205  // hist->SetLabelSize(0, "X");
206  // hist->SetLabelSize(0, "Y");
207  // hist->SetTickLength(0, "X");
208  // hist->SetTickLength(0, "Y");
209  // hist->Draw("pY+");
210  //
211  // //
212  // // Use this to fill the histogram with colors from the color scale
213  // //
214  // double x1, x2, y1, y2;
215  // x1 = 0.;
216  // x2 = 1.;
217  //
218  // for(int i = 0; i < ndiv; ++i){
219  // y1 = hist->GetMinimum() + i*(hist->GetMaximum()-hist->GetMinimum())/(1.*ndiv);
220  // y2 = hist->GetMinimum() + (i + 1)*(hist->GetMaximum()-hist->GetMinimum())/(1.*ndiv);
221  //
222  // int c = 1;
223  // if (drawopt->fDrawRawDataOrCalibWires==kRAW) {
224  // c = cst->RawQ(sigType).GetColor(0.5*(y1+y2));
225  // }
226  // if (drawopt->fDrawRawDataOrCalibWires!=kRAW) {
227  // c= cst->CalQ(sigType).GetColor(0.5*(y1+y2));
228  // }
229  //
230  // TBox& b = fView->AddBox(x1,y1,x2,y2);
231  // b.SetFillStyle(1001);
232  // b.SetFillColor(c);
233  // b.Draw();
234  // } // end loop over Q histogram bins
235  //
236  // hist->Draw("same");
237  // } // end if fTQ == kQ
238 
239  return;
240  }
241 
242  //......................................................................
243  void
245  {
246  if (fFrameHist) {
247  delete fFrameHist;
248  fFrameHist = 0;
249  }
250 
253 
254  // figure out the signal type for this plane, assume that
255  // plane n in each TPC/cryostat has the same type
256  geo::PlaneID planeid(drawopt->CurrentTPC(), fPlane);
258  geo::SigType_t sigType = geo->SignalType(planeid);
259 
260  /// \todo decide if ndivraw and ndivreco are useful
261  double qxloraw = cst->fRawQLow[(size_t)sigType];
262  double qxhiraw = cst->fRawQHigh[(size_t)sigType];
263  double tqxlo = 1. * this->RawDataDraw()->StartTick();
264  double tqxhi = 1. * this->RawDataDraw()->TotalClockTicks();
265 
266  switch (fTQ) {
267  case kQ:
268  fFrameHist = new TH1F("fFrameHist", ";t [ticks];[ADC]", 2, 0., 1.);
269  fFrameHist->SetMaximum(qxhiraw);
270  fFrameHist->SetMinimum(qxloraw);
271  break; // kQ
272  case kTQ:
273  fFrameHist = new TH1F("fFrameHist", ";t [ticks];q [ADC]", (int)tqxhi, tqxlo, tqxhi + tqxlo);
274  break;
275  default: throw cet::exception("TQPad") << __func__ << ": unexpected quantity #" << fTQ << "\n";
276  } //end if fTQ == kTQ
277 
278  // Set the label, title size and offsets
279  // Note this is the base histogram so this control these for both the raw and wire histograms
280  fFrameHist->GetXaxis()->SetLabelSize(0.10);
281  fFrameHist->GetXaxis()->SetLabelOffset(0.00);
282  fFrameHist->GetXaxis()->SetTitleSize(0.10);
283  fFrameHist->GetXaxis()->SetTitleOffset(0.80);
284 
285  fFrameHist->GetYaxis()->SetLabelSize(0.10);
286  fFrameHist->GetYaxis()->SetLabelOffset(0.01);
287  fFrameHist->GetYaxis()->SetTitleSize(0.10);
288  fFrameHist->GetYaxis()->SetTitleOffset(0.80);
289  }
290 
291 }
292 //////////////////////////////////////////////////////////////////////////
IWFHitDrawerPtr fHitDrawerTool
An instance of the tool to draw hits.
Definition: TQPad.h:54
std::vector< double > fRawQLow
low edge of ADC values for drawing raw digits
unsigned int fTPC
TPC number to draw, typically set by TWQProjectionView.
unsigned int fPlane
Which plane in the detector.
Definition: TQPad.h:50
TH1F * fFrameHist
A dummy histogram to define the axes.
Definition: TQPad.h:52
std::string string
Definition: nybbler.cc:12
void BookHistogram()
Definition: TQPad.cxx:244
int fDrawRawDataOrCalibWires
0 for raw
IWaveformDrawerPtr fWireDrawerTool
An instance of the tool to draw hits.
Definition: TQPad.h:56
opt
Definition: train.py:196
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
fhicl::ParameterSet fRawDigitDrawerParams
FHICL parameters for the RawDigit waveform display.
Drawing pad for time or charge histograms.
static const int kRAW
Definition: TQPad.cxx:28
static const int kCALIB
Definition: TQPad.cxx:29
uint8_t channel
Definition: CRTFragment.hh:201
void Draw()
Definition: TQPad.cxx:112
art framework interface to geometry description
unsigned int fWire
Definition: TQPad.h:49
evdb::View2D * fView
Superimpose scale on 1D histo.
Definition: TQPad.h:53
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
LArSoft includes.
Definition: InfoTransfer.h:33
RawDataDrawer * RawDataDraw()
Definition: DrawingPad.cxx:106
unsigned int fCryostat
Cryostat number to draw, typically set by TWQProjectionView.
enum geo::_plane_sigtype SigType_t
fhicl::ParameterSet fWireDrawerParams
FHICL parameters for the wire drawing.
Base class for event display drawing pads.
Definition: DrawingPad.h:29
This provides an interface for tools which are tasked with drawing the "wire" data (deconvolved wavef...
TPad * Pad()
Definition: DrawingPad.h:37
geo::TPCID CurrentTPC() const
Returns the current TPC as a TPCID.
double TotalClockTicks() const
Definition: RawDataDrawer.h:82
static const int kQ
Definition: TQPad.cxx:31
static int max(int a, int b)
static const int kTQ
Definition: TQPad.cxx:32
std::vector< double > fRawQHigh
high edge of ADC values for drawing raw digits
IWaveformDrawerPtr fRawDigitDrawerTool
An instance of the tool to draw hits.
Definition: TQPad.h:55
int fTQ
0 = plot shows charge only, 1 = plot shows charge vs time for a wire
Definition: TQPad.h:51
double StartTick() const
Definition: RawDataDrawer.h:77
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
~TQPad()
Definition: TQPad.cxx:98
opts
Definition: ECLAPI.py:241
TPad * fPad
The ROOT graphics pad.
Definition: DrawingPad.h:52
fhicl::ParameterSet fHitDrawerParams
FHICL parameters for the hit drawing.
TCEvent evt
Definition: DataStructs.cxx:7
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
LArSoft geometry interface.
Definition: ChannelGeo.h:16
TQPad(const char *nm, const char *ti, double x1, double y1, double x2, double y2, const char *opt, unsigned int plane, unsigned int wire)
Definition: TQPad.cxx:36
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33