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 /// \version $Id: TQPad.cxx,v 1.19 2012-03-03 05:42:28 messier Exp $
6 /////////////////////////////////////////////////////////////////////////
7 #include "EventDisplay/TQPad.h"
8 
9 #include <cassert>
10 #include <algorithm>
11 
12 #include "TBox.h"
13 #include "TH1F.h"
14 #include "TPad.h"
15 
24 #include "RecoBase/CellHit.h"
25 
26 namespace evd
27 {
28  //................................................................
29 
30  static const int kTPAD = 0;
31  static const int kQPAD = 1;
32  // static const int kRAW = 0;
33  // static const int kCALIB = 1;
34  // static const int kPE = 2;
35  // static const int kTNS = 3;
36 
37  //......................................................................
38 
39  TQPad::TQPad(const char* nm, const char* ti,
40  double x1, double y1,
41  double x2, double y2,
42  const char* opt) :
43  DrawingPad(nm, ti, x1, y1, x2, y2),
44  fHisto(0)
45  {
46  this->Pad()->cd();
47  this->Pad()->SetLogy();
48 
49  std::string opts(opt);
50  if (opts=="T") fTorQ = kTPAD;
51  if (opts=="Q") fTorQ = kQPAD;
52 
53  fView = new evdb::View2D();
54 
55  this->Pad()->Connect("RangeChanged()",
56  "evd::TQPad", this, "RangeChanged()");
57 
58  this->BookHistogram();
59  }
60 
61  //......................................................................
62 
64  {
65  if (fView) { delete fView; fView = 0; }
66  if (fHisto) { delete fHisto; fHisto = 0; }
67  }
68 
69  //......................................................................
71  {
73 
74  static int iloqlast = -1;
75  static int ihiqlast = -1;
76  static int ilotlast = -1;
77  static int ihitlast = -1;
78 
79  int ilo = fHisto->GetXaxis()->GetFirst();
80  int ihi = fHisto->GetXaxis()->GetLast();
81  double lo = fHisto->GetXaxis()->GetBinLowEdge(ilo);
82  double hi = fHisto->GetXaxis()->GetBinUpEdge(ihi);
83 
84  if (fTorQ==kTPAD) {
85  if ((ilo==ilotlast) && (ihi==ihitlast)) return;
86  ilotlast = ilo;
87  ihitlast = ihi;
89  switch (drawopt->fWhichHits) {
91  colors->Scale("RawT").SetBounds(lo, hi);
92  break;
94  colors->Scale("CawT").SetBounds(lo, hi);
95  break;
96  default: break;
97  }
98 
99  ilotlast = ilo;
100  ihitlast = ihi;
101  }
102 
103  if (fTorQ == kQPAD) {
104  if ((ilo==iloqlast) && (ihi==ihiqlast)) return;
105  /** \todo what to do with colors when axis zooms?
106  switch (drawopt->fWhichHits) {
107  case evd::RawDrawingOptions::kRAW_HITS:
108  ColorScaleTable::MakeRawQ(lo, hi);
109  break;
110  case evd::RawDrawingOptions::kCAL_HITS:
111  ColorScaleTable::MakeCalQ(lo, hi);
112  break;
113  default: break;
114  }
115  */
116  iloqlast = ilo;
117  ihiqlast = ihi;
118  }
119  }
120 
121  //......................................................................
122 
123  void TQPad::Draw()
124  {
125  static const double kHistoFloor = 0.3;
126  static const double kColorScaleLevel = 0.6;
127 
128  if (fHisto==0) return;
129 
131 
132  if ( !drawopt->fTHistogram && fTorQ == kTPAD ) {
133  this->Pad()->Clear();
134  return;
135  }
136 
137  //grab the singleton with the event
139  if (!evt) return;
140 
141  fView-> Clear();
142  this->BookHistogram();
143 
145  if (fTorQ == kTPAD) {
146  this->RawDataDraw()->FillTQHisto(*evt, fHisto, 0);
147  }
148  if (fTorQ == kQPAD) {
149  this->RawDataDraw()->FillTQHisto(*evt, 0, fHisto);
150  }
151  }
152 
154  if (fTorQ == kTPAD) {
155  this->RecoBaseDraw()->FillTQHisto(*evt, fHisto, 0);
156  }
157  if (fTorQ == kQPAD) {
158  this->RecoBaseDraw()->FillTQHisto(*evt, 0, fHisto);
159  }
160  }
161 
162  if (drawopt->fTimeAutoZoomTruth && fTorQ == kTPAD){
163  double tmin, tmax;
164  this->SimulationDraw()->GetTimeLimits(evt, tmin, tmax);
165  fHisto->GetXaxis()->SetRangeUser(tmin*1e-3-1, tmax*1e-3+2);
166  this->RangeChanged();
167  }
168 
169  this->Pad()->Clear();
170  this->Pad()->cd();
171 
172  //
173  // Play some defense against empty histograms
174  //
175  double hmax = 0.0;
176  for (int i=1; i<=fHisto->GetNbinsX(); ++i) {
177  double hc = fHisto->GetBinContent(i);
178  if (hc>hmax) hmax = hc;
179  }
180  if (hmax>kHistoFloor){
181  this->Pad()->SetLogy(kTRUE);
182  fHisto->SetMinimum(kHistoFloor);
183  fHisto->SetMaximum(2.0*hmax);
184  }
185  else {
186  fHisto->SetMinimum(0.0);
187  fHisto->SetMaximum(1.0);
188  this->Pad()->SetLogy(kFALSE);
189  }
190  if (fTorQ == kQPAD){
191  this->Pad()->SetLogx(kTRUE);
192  }
193  fHisto->Draw();
194 
195  //
196  // Use this to fill the histogram with colors from the color scale
197  //
199  for (int i=1; i<=fHisto->GetNbinsX(); ++i) {
200  if (i<fHisto->GetXaxis()->GetFirst()) continue;
201  if (i>fHisto->GetXaxis()->GetLast()) continue;
202 
203  double x1, x2, y1, y2;
204  x1 = fHisto->GetBinLowEdge(i);
205  x2 = x1 + fHisto->GetBinWidth(i);
206  y1 = 0.0;
207  y2 = fHisto->GetBinContent(i);
208  if (y2==0.0) y2 += kColorScaleLevel;
209  if (y2>y1) {
210  int c=1;
211  if (fTorQ==kTPAD&&drawopt->fColor==evd::RawDrawingOptions::kCOLOR_BY_TIME) {
213  c = colors->Scale("RawT").GetColor(0.5*(x1+x2));
214  }
216  c = colors->Scale("CalT").GetColor(0.5*(x1+x2));
217  }
218  TBox& b = fView->AddBox(x1,y1,x2,y2);
219  b.SetFillStyle(1001);
220  b.SetFillColor(c);
221  b.Draw();
222  }
223  if (fTorQ==kQPAD&&drawopt->fColor==evd::RawDrawingOptions::kCOLOR_BY_CHARGE) {
225  c = colors->Scale("RawQ").GetColor(0.5*(x1+x2));
226  }
228  c = colors->Scale("CalQ").GetColor(0.5*(x1+x2));
229  }
230  TBox& b = fView->AddBox(x1,y1,x2,y2);
231  b.SetFillStyle(1001);
232  b.SetFillColor(c);
233  b.Draw();
234  }
235  }
236  }
237  fHisto->Draw("same");
238  }
239 
240  //......................................................................
241 
243  {
244  if (fHisto) {
245  delete fHisto;
246  fHisto = 0;
247  }
248 
251  if (fTorQ==kTPAD&&drawopt->fWhichHits==evd::RawDrawingOptions::kRAW_HITS) {
252  float lo = drawopt->fTimeRange[0];
253  float hi = drawopt->fTimeRange[1];
254  int n = std::max(1, int(rint((hi-lo)/drawopt->fTimeBinSize)));
255  fHisto = new TH1F("fRAWTHisto",";t (#musec);hits",n,lo,hi);
256  colors->Scale("RawT").SetBounds(lo, hi);
257  }
258  if (fTorQ==kTPAD&&drawopt->fWhichHits==evd::RawDrawingOptions::kCAL_HITS) {
259  float lo = drawopt->fTimeRange[0];
260  float hi = drawopt->fTimeRange[1];
261  int n = std::max(1, int(rint((hi-lo)/drawopt->fTimeBinSize)));
262  fHisto = new TH1F("fCALTHisto",";t (#musec);hits",n,lo,hi);
263  colors->Scale("CalT").SetBounds(lo, hi);
264  }
265  if (fTorQ==kQPAD&&drawopt->fWhichHits==evd::RawDrawingOptions::kRAW_HITS) {
266  float lo = drawopt->fADCRange[0];
267  float hi = drawopt->fADCRange[1];
268  int n = std::max(1, int(rint((hi-lo)/drawopt->fADCBinSize)));
269  fHisto = new TH1F("fRAWQHisto",";q (ADC);hits",n,lo,hi);
270  }
271  if (fTorQ==kQPAD&&drawopt->fWhichHits==evd::RawDrawingOptions::kCAL_HITS) {
272  // Even though this histo is filled with PE values, we can still use
273  // the values below so that the user can maintain control over how the
274  // histo is binned.
275  float lo = drawopt->fADCRange[0];
276  float hi = drawopt->fADCRange[1];
277  int n = std::max(1, int(rint((hi-lo)/drawopt->fADCBinSize)));
278  fHisto = new TH1F("fCALQHisto",";q (pe);hits",n,lo,hi);
279  }
280 
281  // By this time I must have a histogram booked
282  assert(fHisto);
283 
284  fHisto->SetLabelSize (0.180,"X");
285  fHisto->SetLabelOffset(0.002,"X");
286  fHisto->SetTitleSize (0.200,"X");
287  fHisto->SetTitleOffset(0.850,"X");
288 
289  fHisto->SetLabelSize (0.180,"Y");
290  fHisto->SetLabelOffset(0.002,"Y");
291  fHisto->SetTitleSize (0.200,"Y");
292  fHisto->SetTitleOffset(0.230,"Y");
293  }
294 
295 } // end namespace evd
296 //////////////////////////////////////////////////////////////////////////
std::vector< float > fTimeRange
T max(const caf::Proxy< T > &a, T b)
void FillTQHisto(art::Event const &evt, TH1F *thisto, TH1F *qhisto)
TSpline3 lo("lo", xlo, ylo, 12,"0")
const art::Event * GetEvent() const
Definition: EventHolder.cxx:45
Float_t y1[n_points_granero]
Definition: compare.C:5
void BookHistogram()
Definition: TQPad.cxx:242
Float_t x1[n_points_granero]
Definition: compare.C:5
Define a color scale for displaying numeric data.
Drawing pad for time or charge histograms.
static constexpr Double_t nm
Definition: Munits.h:133
A collection of drawable 2-D objects.
int GetColor(double x) const
Definition: ColorScale.cxx:126
void RangeChanged()
Definition: TQPad.cxx:70
void Draw()
Definition: TQPad.cxx:123
Singleton to hold the current art::Event for the event display.
void GetTimeLimits(const art::Event *evt, double &tmin, double &tmax)
static const int kCOLOR_BY_TIME
evdb::View2D * fView
Superimpose scale on 1D histo.
Definition: TQPad.h:32
TBox & AddBox(double x1, double y1, double x2, double y2)
Definition: View2D.cxx:263
TSpline3 hi("hi", xhi, yhi, 18,"0")
int colors[6]
Definition: tools.h:1
nova event display
void SetBounds(double xlo, double xhi)
Definition: ColorScale.h:57
static const int kCAL_HITS
RawDataDrawer * RawDataDraw()
Definition: DrawingPad.cxx:91
static EventHolder * Instance()
Definition: EventHolder.cxx:15
correl_xv GetXaxis() -> SetDecimals()
ColorScale & Scale(const std::string &nm)
int evt
Base class for event display drawing pads.
Definition: DrawingPad.h:20
RecoBaseDrawer * RecoBaseDraw()
Definition: DrawingPad.cxx:101
void FillTQHisto(const art::Event &evt, TH1F *thisto, TH1F *qhisto)
TPad * Pad()
Definition: DrawingPad.h:27
static const int kTPAD
Definition: TQPad.cxx:30
static const int kCOLOR_BY_CHARGE
SimulationDrawer * SimulationDraw()
Definition: DrawingPad.cxx:82
TH1F * fHisto
1-D Histogram of time or charge
Definition: TQPad.h:31
Class to aid in the rendering of RecoBase objects.
Class to aid in the rendering of RawData objects.
~TQPad()
Definition: TQPad.cxx:63
Render the objects from the Simulation package.
const hit & b
Definition: hits.cxx:21
TQPad(const char *nm, const char *ti, double x1, double y1, double x2, double y2, const char *opt)
Definition: TQPad.cxx:39
assert(nhit_max >=nhit_nbins)
Global drawing options that apply to all displays.
std::vector< float > fADCRange
int fTorQ
0 = plot shows time, 1 = plot shows charge
Definition: TQPad.h:30
Float_t e
Definition: plot.C:35
static const int kRAW_HITS
static const int kQPAD
Definition: TQPad.cxx:31
enum BeamMode string