PlotViewer.cxx
Go to the documentation of this file.
1 ///
2 /// \file PlotViewer.cxx
3 /// \brief Canvas on which reports are drawn
4 /// \version $Id: PlotViewer.cxx,v 1.40 2012-12-12 17:04:13 messier Exp $
5 /// \author messier@indiana.edu
6 ///
8 #include <iostream>
9 #include "TMath.h"
10 #include "TPad.h"
11 #include "TCanvas.h"
12 #include "TStyle.h"
13 #include "TH1F.h"
14 #include "TH2F.h"
25 using namespace om;
26 
27 // ROOT events must be handled globally so I need to provide some
28 // global access to the plot viewer
30 
31 //......................................................................
32 
34  TRootEmbeddedCanvas("onmon_report",
35  m,
36  Layout::fPlotViewerSizeX,
37  Layout::fPlotViewerSizeY),
39 {
40  //
41  // Send global root mouse events to this PlotViewer
42  //
43  gsPlotViewer = this;
44 
45  this->GetCanvas()->SetRightMargin(0.12);
46  this->GetCanvas()->Draw();
47  this->GetCanvas()->AddExec("ex1","om::PlotViewer::Exec()");
48 
49  this->Resize();
50 }
51 
52 //......................................................................
53 
55 {
56  int evti = gPad->GetEvent();
57  bool single_click = (evti==1); // Single click mouse down
58  bool double_click = (evti==61); // Double click mouse down
59  if (!(single_click||double_click)) return;
60 
61  static PlotClickHandler handler;
62  if (single_click) {
63  handler.SingleClick(gsPlotViewer->fPlotOpt);
64  }
65  if (double_click) {
66  handler.DoubleClick(gsPlotViewer->fPlotOpt);
67  }
68 }
69 
70 //......................................................................
71 
73 {
74  if (fHistogramSource =="") return;
75  if (fCurrentHistogram=="") return;
76 
78 
79  const HistoData* hd =
81  if (hd==0) {
82  om::cout << "ERROR: Could not get histogram data "
84  << "";
85  return;
86  }
87 
88  //
89  // Parse out the options for how the plot should be displayed
90  //
91  fPlotOpt.Set(hd->fOption);
92 
93  //
94  // Check if we want a content projection
95  //
97  if (model.fContentProjection==1) {
98 
99  if (hd->fType==kTH1F) {
100  TH1F* h = f.GetTH1FCopy(fCurrentHistogram.c_str());
101  this->ContentProjectionTH1F(hd,h);
102  delete h;
103  }
104 
105  if (hd->fType==kTH2F) {
106  TH2F* h = f.GetTH2FCopy(fCurrentHistogram.c_str());
107  this->ContentProjectionTH2F(hd,h);
108  delete h;
109  }
110 
111  return;
112  }
113 
114  // If "alert" mode = true, set the color pad for this mode.
115  if(fPlotOpt.fAlert) {
116  Int_t palette[2];
117  palette[0] = 3;
118  palette[1] = 2;
119  gStyle->SetPalette(2,palette);
120  }
121  else gStyle->SetPalette(1);
122 
123  this->GetCanvas()->cd();
124  this->GetCanvas()->Clear();
125  fPlotOpt.SetPad(this->GetCanvas());
126 
127  //
128  // Plot 1D histograms
129  //
130  if (hd->fType==kTH1F) {
131  TH1F* h = f.GetTH1FCopy(fCurrentHistogram.c_str());
132  if (h==0) {
133  om::cout << "ERROR: Could not get copy of histogram "
135  << "";
136  return;
137  }
138 
139  fPlotOpt.AutoScale(h);
140  h->SetLineColor(kBlack);
141  h->SetFillColor(kGreen-10);
142  h->DrawCopy(fPlotOpt.fDrawOpt.c_str());
143  fPlotOpt.MakeLabels(h, hd);
144  this->GetCanvas()->Update();
145 
146  delete h;
147  }
148 
149  //
150  // Plot 2D histograms
151  //
152  if (hd->fType==kTH2F) {
153  TH2F* h = f.GetTH2FCopy(fCurrentHistogram.c_str());
154  if (h==0) {
155  om::cout << "ERROR: Could not get copy of histogram "
157  << "";
158  return;
159  }
160 
162  // Clear the Y-axis labels for the "special" labels
163  h->SetYTitle("");
164  h->GetYaxis()->SetTickLength(0);
165  h->GetYaxis()->SetLabelColor(0);
166  }
167 
168  if (fPlotOpt.fAlert) h->SetAxisRange(0,2,"Z");
169 
170  fPlotOpt.AutoScale(h);
171  h->DrawCopy(fPlotOpt.fDrawOpt.c_str());
172  fPlotOpt.MakeLabels(h, hd);
173  this->GetCanvas()->Update();
174 
175  delete h;
176  }
177 }
178 
179 //......................................................................
180 
182 {
183  if (fHistogramSource =="") {
184  om::cout << "ERROR: Histogram Source not defined"
185  << "";
186  return;
187  }
188  if (fCurrentHistogram=="") {
189  om::cout << "ERROR: Current Histogram not defined"
190  << "";
191  return;
192  }
193 
194  if(COpt.fWhich == ComparisonOptions::kNone) {
195  this->Update();
196  return;
197  }
198 
199  // Define the sources for the histograms to be compared.
201  HistoSource f2(COpt.fReferenceFile.c_str());
202 
203  const HistoData* hd =
205  if (hd==0) return;
206 
207  //
208  // Parse out the options for how the plot should be displayed and reset the
209  // palette in case the previous histogram was an alert histogram.
210  //
211  fPlotOpt.Set(hd->fOption);
212  gStyle->SetPalette(1);
213 
214  this->GetCanvas()->cd();
215  this->GetCanvas()->Clear();
216  fPlotOpt.SetPad(this->GetCanvas());
217 
218  //
219  // Plot 1D histograms
220  //
221  if (hd->fType==kTH1F) {
222 
223  // POSSIBLY MOVE THIS MAKING THE H2 NAME SECTION OUTSIDE BOTH THE
224  // TH1F AND TH2F IF STATEMENTS
225 
226  // Create the name string for the comparison histo. If we are comparing to
227  // a reference file, just use the same histo name. Otherwise, add to the
228  // histo name things like "_prev_10min_02".
229  std::string CompareHistoName = fCurrentHistogram;
230  if(COpt.fWhich == ComparisonOptions::kRecent) {
231  CompareHistoName += "_prev_";
232  const char* tag = 0;
233  switch (hd->fReset) {
234  case TickerSubscriber::kRun: tag = "run"; break;
235  case TickerSubscriber::kSubrun: tag = "subrun"; break;
236  case TickerSubscriber::k5min: tag = "5min"; break;
237  case TickerSubscriber::k10min: tag = "10min"; break;
238  case TickerSubscriber::k30min: tag = "30min"; break;
239  default: abort();
240  }
241  CompareHistoName += tag;
242 
243  char LB[64];
244  sprintf(LB, "_%.2d", COpt.fLookBack);
245  CompareHistoName += LB;
246  }
247 
248  // Get the current histo and rename it. Otherwise ROOT will have major
249  // problems with two histos that have the same name.
250  TH1F* h1 = f1.GetTH1FCopy(fCurrentHistogram.c_str());
251  if(h1 == 0) {
252  om::cout << "ERROR: Could not get copy of current histogram "
254  << "";
255  return;
256  }
257  h1->SetName("ComparisonHistogram");
258 
259  TH1F* h2 = 0;
261  h2 = f1.GetTH1FCopy(CompareHistoName.c_str());
263  h2 = f2.GetTH1FCopy(CompareHistoName.c_str());
264  if(h2 == 0) {
265  om::cout << "ERROR: Could not get copy of reference histogram "
266  << CompareHistoName
267  << "";
268  delete h1;
269  return;
270  }
271 
272  // Calculate the requested normalization (if different from "Absolute") and
273  // rescale the reference histo.
274  double scale = 1.0;
275 
277  double area1 = h1->Integral();
278  double area2 = h2->Integral();
279  scale = area1/area2;
280  h2->Scale(scale);
281  }
283  unsigned int NXbins = h1->GetNbinsX();
284  double bin1;
285  double bin2;
286  double peak1 = -1.0e9;
287  double peak2 = -1.0e9;
288 
289  for(unsigned int i = 1; i <= NXbins; ++i) {
290  bin1 = h1->GetBinContent(i);
291  bin2 = h2->GetBinContent(i);
292  if(bin1 > peak1) peak1 = bin1;
293  if(bin2 > peak2) peak2 = bin2;
294  }
295 
296  scale = peak1/peak2;
297  h2->Scale(scale);
298 
299  }
300  /*
301  if(COpt.fNormalize == ComparisonOptions::kIntegral) {
302  // THIS OPTION IS NOT CURRENTLY IMPLEMENTED.
303  double area1 = h1->Integral();
304  double area2 = h2->Integral();
305  scale = area1/area2;
306  h2->Scale(scale);
307  }
308  */
309 
310 
311 
313  h1->SetTitle("Overlay Plot: (black = current histo, red = comparison histo)");
314  fPlotOpt.AutoScale(h1);
315  h1->SetLineColor(kBlack);
316  h2->SetLineColor(kRed);
317 
318  // h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
319  // h2->DrawCopy("same");
320  // fPlotOpt.MakeLabels(h1, hd);
321  // this->GetCanvas()->Update();
322  }
324 
325  // (see note in difference section for TH2Fs...)
326 
327  unsigned int NXbins = h1->GetNbinsX();
328  double bin1;
329  double bin2;
330  double fill = 0.0;
331  double err = 0.0;
332 
333  for(unsigned int i = 1; i <= NXbins; ++i) {
334  bin1 = h1->GetBinContent(i);
335  bin2 = h2->GetBinContent(i);
336  fill = bin1 - bin2;
337  err = sqrt(bin1+bin2);
338  h1->SetBinContent(i,fill);
339  h1->SetBinError(i,err);
340  }
341 
342  fPlotOpt.fLogy = false;
343  fPlotOpt.SetPad(this->GetCanvas());
344 
345  // fPlotOpt.AutoScale(h1);
346  h1->SetTitle("Difference Comparison: (current - reference)");
347 
348  // h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
349 
350  // fPlotOpt.MakeLabels(h1, hd);
351  // this->GetCanvas()->Update();
352  }
353  if(COpt.fMethod == ComparisonOptions::kRatio) {
354 
355  // (see note in difference section for TH2Fs...)
356 
357  unsigned int NXbins = h1->GetNbinsX();
358  double bin1;
359  double bin2;
360  double fill = 0.0;
361  double err = 0.0;
362 
363  for(unsigned int i = 1; i <= NXbins; ++i) {
364  bin1 = h1->GetBinContent(i);
365  bin2 = h2->GetBinContent(i);
366  if(bin2 == 0.0) fill = 0.0;
367  else fill = bin1/bin2;
368  err = sqrt(bin1+bin2);
369  h1->SetBinContent(i,fill);
370  h1->SetBinError(i,err);
371  }
372 
373  fPlotOpt.fLogy = false;
374  fPlotOpt.SetPad(this->GetCanvas());
375 
376  h1->SetTitle("Ratio Comparison: (current/reference)");
377  // fPlotOpt.AutoScale(h1);
378  // h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
379 
380  // fPlotOpt.MakeLabels(h1, hd);
381  // this->GetCanvas()->Update();
382 
383  }
385  unsigned int NXbins = h1->GetNbinsX();
386  double bin1;
387  double bin2;
388  double fill = 0.0;
389  double err = 0.0;
390 
391  for(unsigned int i = 1; i <= NXbins; ++i) {
392  bin1 = h1->GetBinContent(i);
393  bin2 = h2->GetBinContent(i);
394  if(bin1 == 0.0 && bin2 == 0.0) fill = 0.0;
395  else fill = (bin1-bin2)/(bin1+bin2);
396  err = sqrt(bin1+bin2);
397  h1->SetBinContent(i,fill);
398  h1->SetBinError(i,err);
399  }
400  fPlotOpt.fLogy = false;
401  fPlotOpt.SetPad(this->GetCanvas());
402 
403  // fPlotOpt.AutoScale(h1);
404  h1->SetTitle("Asymmetry Comparison: (current - reference)/(current + reference)");
405  // h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
406 
407  // fPlotOpt.MakeLabels(h1, hd);
408  // this->GetCanvas()->Update();
409 
410  }
411  if(COpt.fMethod == ComparisonOptions::kChi) {
412  unsigned int NXbins = h1->GetNbinsX();
413  double bin1;
414  double bin2;
415  double fill = 0.0;
416  double err = 0.0;
417 
418  for(unsigned int i = 1; i <= NXbins; ++i) {
419  bin1 = h1->GetBinContent(i);
420  bin2 = h2->GetBinContent(i);
421  if(bin2 == 0.0) fill = 0.0;
422  else fill = (bin1-bin2)/sqrt(bin2);
423  err = sqrt(bin1+bin2);
424  h1->SetBinContent(i,fill);
425  h1->SetBinError(i,err);
426  }
427 
428  fPlotOpt.fLogy = false;
429  fPlotOpt.SetPad(this->GetCanvas());
430 
431  // fPlotOpt.AutoScale(h1);
432  h1->SetTitle("Chi Comparison: (current - reference)/Sqrt(reference)");
433  // h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
434 
435  // fPlotOpt.MakeLabels(h1, hd);
436  // this->GetCanvas()->Update();
437 
438  }
440 
441  unsigned int NXbins = h1->GetNbinsX();
442 
443  for(unsigned int i = 1; i <= NXbins; ++i) {
444  h1->SetBinContent(i,h2->GetBinContent(i));
445  }
446 
447  fPlotOpt.SetPad(this->GetCanvas());
448 
449  fPlotOpt.AutoScale(h1);
450  h1->SetTitle("Reference Histogram");
451  // h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
452 
453  // fPlotOpt.MakeLabels(h1, hd);
454  // this->GetCanvas()->Update();
455  }
456 
457  //
458  // Check if we want a content projection
459  //
461  if (model.fContentProjection==1)
462  this->ContentProjectionTH1F(hd,h1);
463  else {
464  h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
466  h2->DrawCopy("same");
467  fPlotOpt.MakeLabels(h1, hd);
468  this->GetCanvas()->Update();
469  }
470 
471  delete h1;
472  delete h2;
473 
474  }
475 
476 
477 
478  //
479  // Plot 2D histograms
480  //
481  if (hd->fType==kTH2F) {
482 
483  // Create the name string for the comparison histo. If we are comparing to
484  // a reference file, just use the same histo name. Otherwise, add to the
485  // histo name things like "_prev_10min_02".
486  std::string CompareHistoName = fCurrentHistogram;
487  if(COpt.fWhich == ComparisonOptions::kRecent) {
488  CompareHistoName += "_prev_";
489  const char* tag = 0;
490  switch (hd->fReset) {
491  case TickerSubscriber::kRun: tag = "run"; break;
492  case TickerSubscriber::kSubrun: tag = "subrun"; break;
493  case TickerSubscriber::k5min: tag = "5min"; break;
494  case TickerSubscriber::k10min: tag = "10min"; break;
495  case TickerSubscriber::k30min: tag = "30min"; break;
496  default: abort();
497  }
498  CompareHistoName += tag;
499 
500  char LB[64];
501  sprintf(LB, "_%.2d", COpt.fLookBack);
502  CompareHistoName += LB;
503  }
504 
505  // Get the current histo and rename it. Otherwise ROOT will have major
506  // problems with two histos that have the same name.
507  TH2F* h1 = f1.GetTH2FCopy(fCurrentHistogram.c_str());
508  if(h1 == 0) {
509  om::cout << "ERROR: Could not get copy of current histogram "
511  << "";
512  return;
513  }
514  h1->SetName("ComparisonHistogram");
515 
516  TH2F* h2 = 0;
518  h2 = f1.GetTH2FCopy(CompareHistoName.c_str());
520  h2 = f2.GetTH2FCopy(CompareHistoName.c_str());
521  if(h2 == 0) {
522  om::cout << "ERROR: Could not get copy of reference histogram "
523  << CompareHistoName
524  << "";
525  delete h1;
526  return;
527  }
528 
529  // Calculate the requested normalization (if different from "Absolute") and
530  // rescale the reference histo.
531  double scale = 1.0;
532 
534  double area1 = h1->Integral();
535  double area2 = h2->Integral();
536  scale = area1/area2;
537  h2->Scale(scale);
538  }
540  unsigned int NXbins = h1->GetNbinsX();
541  unsigned int NYbins = h1->GetNbinsY();
542  double bin1;
543  double bin2;
544  double peak1 = -1.0e9;
545  double peak2 = -1.0e9;
546 
547  for(unsigned int i = 1; i <= NXbins; ++i) {
548  for(unsigned int j = 1; j <= NYbins; ++j) {
549  bin1 = h1->GetBinContent(i,j);
550  bin2 = h2->GetBinContent(i,j);
551  if(bin1 > peak1) peak1 = bin1;
552  if(bin2 > peak2) peak2 = bin2;
553  }
554  }
555 
556  scale = peak1/peak2;
557  h2->Scale(scale);
558 
559  }
560  /*
561  if(COpt.fNormalize == ComparisonOptions::kIntegral) {
562  // THIS OPTION IS NOT CURRENTLY IMPLEMENTED.
563  double area1 = h1->Integral();
564  double area2 = h2->Integral();
565  scale = area1/area2;
566  h2->Scale(scale);
567  }
568  */
569 
571 
572  h2->GetXaxis()->SetAxisColor(0);
573  h2->GetYaxis()->SetAxisColor(0);
574  h2->GetXaxis()->SetLabelColor(0);
575  h2->GetYaxis()->SetLabelColor(0);
576  h2->GetXaxis()->SetTickLength(0);
577  h2->GetYaxis()->SetTickLength(0);
578 
579  fPlotOpt.AutoScale(h1);
580  h2->SetLineWidth(4);
581  h2->SetLineColor(kRed);
582 
583  h1->SetTitle("Overlay Plot: (colz = current histo, box = comparison histo)");
584 
585  // h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
586  // h2->DrawCopy("box:same");
587  // fPlotOpt.MakeLabels(h1, hd);
588  // this->GetCanvas()->Update();
589  }
590 
592 
593  // NOTE: You may be thinking that I could have just used
594  // hComp->Add(hComp,h2,1.0,-1.0) instead of adding the
595  // two histos bin by bin. BUT I discovered a serious
596  // flaw in Root that causes the drawing of the resulting
597  // histo to be blank. This is a Root problem and I'm not
598  // going to explain it here, but adding bin by bin is
599  // currently the only way to do this correctly.
600 
601  unsigned int NXbins = h1->GetNbinsX();
602  unsigned int NYbins = h1->GetNbinsY();
603  double bin1;
604  double bin2;
605  double fill = 0.0;
606  double err = 0.0;
607 
608  for(unsigned int i = 1; i <= NXbins; ++i) {
609  for(unsigned int j = 1; j <= NYbins; ++j) {
610  bin1 = h1->GetBinContent(i,j);
611  bin2 = h2->GetBinContent(i,j);
612  fill = bin1 - bin2;
613  err = sqrt(bin1+bin2);
614  h1->SetBinContent(i,j,fill);
615  h1->SetBinError(i,j,err);
616  }
617  }
618  fPlotOpt.fLogz = false;
619  fPlotOpt.SetPad(this->GetCanvas());
620 
621  // fPlotOpt.AutoScale(h1);
622  h1->SetTitle("Difference Comparison: (current - reference)");
623  // h1->DrawCopy("colz");
624  // h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
625 
626  // fPlotOpt.MakeLabels(h1, hd);
627  // this->GetCanvas()->Update();
628  }
629  if(COpt.fMethod == ComparisonOptions::kRatio) {
630 
631  // (See the long note about 20 lines up...)
632  unsigned int NXbins = h1->GetNbinsX();
633  unsigned int NYbins = h1->GetNbinsY();
634  double bin1;
635  double bin2;
636  double fill = 0.0;
637  double err = 0.0;
638 
639  for(unsigned int i = 1; i <= NXbins; ++i) {
640  for(unsigned int j = 1; j <= NYbins; ++j) {
641  bin1 = h1->GetBinContent(i,j);
642  bin2 = h2->GetBinContent(i,j);
643  if(bin2 == 0.0) fill = 0.0;
644  else fill = bin1/bin2;
645  err = sqrt(bin1+bin2);
646  h1->SetBinContent(i,j,fill);
647  h1->SetBinError(i,j,err);
648  }
649  }
650 
651  fPlotOpt.fLogz = false;
652  fPlotOpt.SetPad(this->GetCanvas());
653  // fPlotOpt.AutoScale(h1);
654  h1->SetTitle("Ratio Comparison: (current/reference)");
655  // h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
656  // fPlotOpt.MakeLabels(h1, hd);
657  // this->GetCanvas()->Update();
658  }
660  unsigned int NXbins = h1->GetNbinsX();
661  unsigned int NYbins = h1->GetNbinsY();
662  double bin1;
663  double bin2;
664  double fill = 0.0;
665  double err = 0.0;
666 
667  for(unsigned int i = 1; i <= NXbins; ++i) {
668  for(unsigned int j = 1; j <= NYbins; ++j) {
669  bin1 = h1->GetBinContent(i,j);
670  bin2 = h2->GetBinContent(i,j);
671  if(bin1 == 0.0 && bin2 == 0.0) fill = 0.0;
672  else fill = (bin1-bin2)/(bin1+bin2);
673  err = sqrt(bin1+bin2);
674  h1->SetBinContent(i,j,fill);
675  h1->SetBinError(i,j,err);
676  }
677  }
678  fPlotOpt.fLogz = false;
679  fPlotOpt.SetPad(this->GetCanvas());
680 
681  // fPlotOpt.AutoScale(h1);
682  h1->SetTitle("Asymmetry Comparison: (current - reference)/(current + reference)");
683  // h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
684 
685  // fPlotOpt.MakeLabels(h1, hd);
686  // this->GetCanvas()->Update();
687 
688  }
689  if(COpt.fMethod == ComparisonOptions::kChi) {
690  unsigned int NXbins = h1->GetNbinsX();
691  unsigned int NYbins = h1->GetNbinsY();
692  double bin1;
693  double bin2;
694  double fill = 0.0;
695  double err = 0.0;
696 
697  for(unsigned int i = 1; i <= NXbins; ++i) {
698  for(unsigned int j = 1; j <= NYbins; ++j) {
699  bin1 = h1->GetBinContent(i,j);
700  bin2 = h2->GetBinContent(i,j);
701  if(bin2 == 0.0) fill = 0.0;
702  else fill = (bin1-bin2)/sqrt(bin2);
703  err = sqrt(bin1+bin2);
704  h1->SetBinContent(i,j,fill);
705  h1->SetBinError(i,j,err);
706  }
707  }
708 
709  fPlotOpt.fLogz = false;
710  fPlotOpt.SetPad(this->GetCanvas());
711 
712  // fPlotOpt.AutoScale(h1);
713  h1->SetTitle("Chi Comparison: (current - reference)/Sqrt(reference)");
714  // h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
715 
716  // fPlotOpt.MakeLabels(h1, hd);
717  // this->GetCanvas()->Update();
718 
719  }
721 
722  unsigned int NXbins = h1->GetNbinsX();
723  unsigned int NYbins = h1->GetNbinsY();
724 
725  for(unsigned int i = 1; i <= NXbins; ++i) {
726  for(unsigned int j = 1; j <= NYbins; ++j) {
727  h1->SetBinContent(i,j,h2->GetBinContent(i,j));
728  }
729  }
730 
731  fPlotOpt.SetPad(this->GetCanvas());
732 
733  fPlotOpt.AutoScale(h1);
734  h1->SetTitle("Reference Histogram");
735  // h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
736 
737  // fPlotOpt.MakeLabels(h1, hd);
738  // this->GetCanvas()->Update();
739  }
740 
741  //
742  // Check if we want a content projection
743  //
745  if (model.fContentProjection==1)
746  this->ContentProjectionTH2F(hd,h1);
747  else {
748  h1->DrawCopy(fPlotOpt.fDrawOpt.c_str());
750  h2->DrawCopy("box:same");
751  fPlotOpt.MakeLabels(h1, hd);
752  this->GetCanvas()->Update();
753  }
754 
755  delete h1;
756  delete h2;
757 
758  }
759 }
760 
761 //......................................................................
762 
764 {
765 
766  HistoSource f(fHistogramSource.c_str());
767 
768  TH1F* htmp = 0;
769 
770  this->GetCanvas()->cd();
771  this->GetCanvas()->Clear();
772 
773  if (h==0) {
774  om::cout << "ERROR: Could not get copy of histogram "
776  << "";
777  return;
778  }
779 
780  bool dolog = fPlotOpt.fLogy;
781 
782  double mx = h->GetMaximum();
783  double mn = h->GetMinimum();
784 
785  if(mx > 0.0) mx = 1.3*mx;
786  else mx = 0.7*mx;
787  if(mn > 0.0) mn = 0.7*mn;
788  else mn = 1.3*mn;
789 
790  if (dolog) {
791  if (mx>0.0) mx = log10(mx);
792  else mx = 0;
793  if (mn>0.0) mn = log10(mn);
794  else mn = 0;
795  }
796 
797  if(mx == mn) {
798  mx += 1.0;
799  mn -= 1.0;
800  }
801 
802  char buff[256];
803  if (dolog) {
804  sprintf(buff, "%s;log10(content);number of bins",hd->fName.c_str());
805  }
806  else {
807  sprintf(buff, "%s;content;number of bins",hd->fName.c_str());
808  }
809  htmp = new TH1F("htmp",buff,100,mn,mx);
810  htmp->SetLineColor(kBlack);
811  htmp->SetFillColor(kGreen-10);
812 
813  int i;
814  for (i=1; i<=h->GetNbinsX(); ++i) {
815  double c = h->GetBinContent(i);
816  double e = h->GetBinError(i);
817  if (c > 0.0)
818  if (dolog) c = log10(c);
819 
820  // NOTE: If the bin content is zero but the error is NOT zero,
821  // then we do NOT want to supress this zero. This is to distinguish
822  // an empty bin from a bin filled with a value that was computed to
823  // be zero from at least one non-zero value.
824  if (c != 0.0 || e != 0.0)
825  htmp->Fill(c);
826  }
827  htmp->DrawCopy();
828  this->GetCanvas()->Update();
829 
830  delete htmp;
831 
832 }
833 
834 //......................................................................
835 
837 {
838 
839  HistoSource f(fHistogramSource.c_str());
840 
841  TH1F* htmp = 0;
842 
843  this->GetCanvas()->cd();
844  this->GetCanvas()->Clear();
845 
846  if (h==0) {
847  om::cout << "ERROR: Could not get copy of histogram "
849  << "";
850  return;
851  }
852 
853  bool dolog = fPlotOpt.fLogz;
854 
855  double mx = h->GetMaximum();
856  double mn = h->GetMinimum();
857 
858  if(mx > 0.0) mx = 1.3*mx;
859  else mx = 0.7*mx;
860  if(mn > 0.0) mn = 0.7*mn;
861  else mn = 1.3*mn;
862 
863  if (dolog) {
864  if (mx>0.0) mx = log10(mx);
865  else mx = 0;
866  if (mn>0.0) mn = log10(mn);
867  else mn = 0;
868  }
869 
870  if(mx == mn) {
871  mx += 1.0;
872  mn -= 1.0;
873  }
874 
875  char buff[256];
876  if (dolog) {
877  sprintf(buff, "%s;log10(content);number of bins",hd->fName.c_str());
878  }
879  else {
880  sprintf(buff, "%s;content;number of bins",hd->fName.c_str());
881  }
882 
883  int nBins = abs(mx - mn);
884 
885  htmp = new TH1F("htmp",buff,nBins,mn,mx);
886  htmp->SetFillColor(kGreen-10);
887 
888  int i, j;
889  for (i=1; i<=h->GetNbinsX(); ++i) {
890  for (j=1; j<=h->GetNbinsY(); ++j) {
891  double c = h->GetBinContent(i,j);
892  double e = h->GetBinError(i,j);
893  if (c > 0.0)
894  if (dolog) c = log10(c);
895 
896  // NOTE: If the bin content is zero but the error is NOT zero,
897  // then we do NOT want to supress this zero. This is to distinguish
898  // an empty bin from a bin filled with a value that was computed to
899  // be zero from at least one non-zero value.
900  if (c != 0.0 || e != 0.0)
901  htmp->Fill(c);
902  }
903  }
904  htmp->DrawCopy();
905  this->GetCanvas()->Update();
906 
907  delete htmp;
908 
909 }
910 
911 //......................................................................
912 
914  unsigned int which)
915 {
916  if (this->GetLock()==false) return;
917 
918  if ( ((which & kPlotViewRefreshID ) ||
919  (which & kCurrentHistogramID) ||
920  (which & kHistogramSourceID ))
921  && !(which & kComparisonUpdateID) ) {
924  this->Update();
925  }
926 
927  if ( (which & kComparisonUpdateID) ) {
930  this->UpdateCompare(m.fComparisonOpt);
931  }
932 
933  if ( (which & kPrintID) ) {
935  n += ".png";
936  this->GetCanvas()->Print(n.c_str());
937  om::cout << "Printed to file " << n << "";
938  }
939 
940  this->ReleaseLock();
941 }
942 
943 //......................................................................
944 
946 
947 ////////////////////////////////////////////////////////////////////////
unsigned int fWhich
Which histo. to compare to?
int nBins
Definition: plotROC.py:16
enum BeamMode kRed
void DoubleClick(const PlotOptions &plotopt)
unsigned int fLookBack
Which "look back" histogram to compare to?
const HistoData * LookUp(const char *nm) const
Definition: HistoTable.cxx:293
static const unsigned int kCurrentHistogramID
Definition: GUIModelData.h:15
bool fFEButc
Draw lines for FEB vs. hour plots.
Definition: PlotOptions.h:56
void UpdateCompare(const ComparisonOptions &COpt)
Definition: PlotViewer.cxx:181
T sqrt(T number)
Definition: d0nt_math.hpp:156
void abs(TH1 *hist)
Float_t f2
std::string fDrawOpt
Definition: PlotOptions.h:82
PlotViewer(TGWindow *m)
Definition: PlotViewer.cxx:33
void ContentProjectionTH2F(const HistoData *hd, TH2F *h)
Definition: PlotViewer.cxx:836
Base class for subscribers to ticker updates.
void ContentProjectionTH1F(const HistoData *hd, TH1F *h)
Definition: PlotViewer.cxx:763
Class to read, hold, and deliver histogram data.
static const unsigned int kPrintID
Definition: GUIModelData.h:27
bool fLogy
Log Y axis.
Definition: PlotOptions.h:65
Double_t scale
Definition: plot.C:25
static const unsigned int kComparisonUpdateID
Definition: GUIModelData.h:24
void SetPad(TPad *p)
ComparisonOptions fComparisonOpt
Definition: GUIModelData.h:41
static GUIModel & Instance()
Definition: GUIModel.cxx:11
void AutoScale(TH1F *h)
bool fLogz
Log Z axis.
Definition: PlotOptions.h:66
static PlotViewer * gsPlotViewer
Definition: PlotViewer.cxx:29
void Set(const std::vector< std::string > &opt)
std::string fName
C++ name of this histogram.
Definition: HistoData.h:47
Float_t f1
const double j
Definition: BetheBloch.cxx:29
void SingleClick(const PlotOptions &plotopt)
std::string fCurrentHistogram
What histogram is being shown?
Definition: PlotViewer.h:45
std::string fHistogramSource
Source to pull histograms from.
Definition: PlotViewer.h:44
OStream cout
Definition: OStream.cxx:6
unsigned int fMethod
How to show the comparison?
TH1F * h2
Definition: plot.C:45
bool fAlert
Draw histo in "alert" mode.
Definition: PlotOptions.h:58
const char * Current() const
static const unsigned int kHistogramSourceID
Definition: GUIModelData.h:22
TH1F * h1
PlotOptions fPlotOpt
Options for plotting.
Definition: PlotViewer.h:43
std::string fHistogramSource
Definition: GUIModelData.h:35
CurrentHistogram fCurrentHistogram
Definition: GUIModelData.h:37
T log10(T number)
Definition: d0nt_math.hpp:120
bool fDCMutc
Draw lines for DCM vs. hour plots.
Definition: PlotOptions.h:57
bool fSpecial
Draw a special case histo label.
Definition: PlotOptions.h:59
void fill(std::vector< T > &x, const S &y)
Definition: fill.hpp:22
void GUIModelDataIssue(const GUIModelData &m, unsigned int which)
Definition: PlotViewer.cxx:913
unsigned int fContentProjection
Definition: GUIModelData.h:42
static HistoTable & Instance(const char *f=0, Detector_t d=kALLDET)
Definition: HistoTable.cxx:21
Float_t e
Definition: plot.C:35
unsigned int fNormalize
How to normalize the histos?
static void Exec()
Definition: PlotViewer.cxx:54
enum BeamMode kGreen
TH1F * hd
Definition: Xdiff_gwt.C:57
std::string fReferenceFile
Reference file for comparison histograms.
const XML_Char XML_Content * model
Definition: expat.h:151
const GUIModelData & Data() const
Definition: GUIModel.h:15
Canvas on which plots and reports are drawn.
Online Monitoring package header.
static const unsigned int kPlotViewRefreshID
Definition: GUIModelData.h:17
void MakeLabels(const TH1 *h, const HistoData *hd)
enum BeamMode string