Logo ROOT  
Reference Guide
TRatioPlot.cxx
Go to the documentation of this file.
1 // @(#)root/gpad:$Id$
2 // Author: Paul Gessinger 25/08/2016
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2016, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TRatioPlot.h"
13 #include "TROOT.h"
14 #include "TBrowser.h"
15 #include "TH1.h"
16 #include "TF1.h"
17 #include "TPad.h"
18 #include "TString.h"
19 #include "TMath.h"
20 #include "TGraphAsymmErrors.h"
21 #include "TGraphErrors.h"
22 #include "TGaxis.h"
23 #include "TLine.h"
24 #include "TVirtualFitter.h"
25 #include "TFitResult.h"
26 #include "THStack.h"
27 
28 /** \class TRatioPlot
29  \ingroup gpad
30 Class for displaying ratios, differences and fit residuals.
31 
32 TRatioPlot has two constructors, one which accepts two histograms, and is responsible
33 for setting up the calculation of ratios and differences. This calculation is in part
34 delegated to `TEfficiency`. A single option can be given as a parameter, that is
35 used to determine which procedure is chosen. The remaining option string is then
36 passed through to the calculation, if applicable. The other constructor uses a
37 fitted histogram to calculate the fit residual and plot it with the histogram
38 and the fit function.
39 
40 ## Ratios and differences
41 The simplest case is passing two histograms without specifying any options. This defaults to using
42 `TGraphAsymmErrors::Divide`. The `option` variable is passed through, as are the parameters
43 `c1` and `c2`, that you can set via `TRatioPlot::SetC1` and `TRatioPlot::SetC1`. If you set the
44 `option` to `divsym` the method `TH1::Divide` will be used instead, also receiving all the parameters.
45 
46 Using the `option` `diff` or `diffsig`, both histograms will be subtracted, and in the case of diffsig,
47 the difference will be divided by the uncertainty. `c1` and `c2` will only be used to
48 scale the histograms using `TH1::Scale` prior to subtraction.
49 
50 Available options are for `option`:
51 | Option | Description |
52 | ---------- | ------------------------------------------------------------ |
53 | divsym | uses the histogram `TH1::Divide` method, yields symmetric errors |
54 | diff | subtracts the histograms |
55 | diffsig | subtracts the histograms and divides by the uncertainty |
56 
57 Begin_Macro(source)
58 ../../../tutorials/hist/ratioplot1.C
59 End_Macro
60 
61 ## Fit residuals
62 A second constructor only accepts a single histogram, but expects it to have a fitted
63 function. The function is used to calculate the residual between the fit and the
64 histogram. Here, it is expected that h1 has a fit function in it's list of functions. The class calculates the
65 difference between the histogram and the fit function at each point and divides it by the uncertainty. There
66 are a few option to steer which error is used (as is the case for `diffsig`). The default is to use
67 the statistical uncertainty from h1 using `TH1::GetBinError`. If the `option` string contains `errasym`, asymmetric
68 errors will be used. The type of error can be steered by `TH1::SetBinErrorOption`. The corresponding error will be used,
69 depending on if the function is below or above the bin content. The third option `errfunc` uses the square root of
70 the function value as the error.
71 
72 
73 Begin_Macro(source)
74 ../../../tutorials/hist/ratioplot2.C
75 End_Macro
76 
77 ## Error options for difference divided by uncertainty and fit residual
78 The uncertainty that is used in the calculation can be steered by providing
79 options to the `option` argument.
80 
81 | Option | Description |
82 | ---------- | ------------------------------------------------------------ |
83 | errasym | Uses calculated asymmetric errors from `TH1::GetBinErrorUp`/`TH1::GetBinErrorLow`. Note that you need to set `TH1::SetBinErrorOption` first |
84 | errfunc | Uses \f$ \sqrt{f(x)} \f$ as the error |
85 
86 The asymmetric error case uses the upper or lower error depending on the relative size
87 of the bin contents, or the bin content and the function value.
88 
89 ## Access to internal parts
90 You can access the internal objects that are used to construct the plot via a series of
91 methods. `TRatioPlot::GetUpperPad` and `TRatioPlot::GetLowerPad` can be used to draw additional
92 elements on top of the existing ones.
93 `TRatioPlot::GetLowerRefGraph` returns a reference to the lower pad's graph that
94 is responsible for the range, which enables you to modify the range.
95 
96 \image html gpad_ratioplot.png
97 */
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// TRatioPlot default constructor
101 
103 {
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Destructor
108 
110 {
111 
112  gROOT->GetListOfCleanups()->Remove(this);
113 
117 
118  for (unsigned int i=0;i<fGridlines.size();++i) {
119  delete (fGridlines[i]);
120  }
121 
131 
132  if (fUpYaxis && fUpYaxis->TestBit(kNotDeleted)) delete fUpYaxis;
134 }
135 
136 ////////////////////////////////////////////////////////////////////////////////
137 /// Internal method that shares constructor logic
138 
139 void TRatioPlot::Init(TH1* h1, TH1* h2,Option_t *option)
140 {
141 
142  fH1 = h1;
143  fH2 = h2;
144 
145  SetupPads();
146 
147  TString optionString = TString(option);
148 
149  if (optionString.Contains("divsym")) {
150  optionString.ReplaceAll("divsym", "");
151  fMode = TRatioPlot::CalculationMode::kDivideHist;
152  } else if (optionString.Contains("diffsig")) {
153  optionString.ReplaceAll("diffsig", "");
154  fMode = TRatioPlot::CalculationMode::kDifferenceSign;
155 
156  // determine which error style
157  if (optionString.Contains("errasym")) {
158  fErrorMode = TRatioPlot::ErrorMode::kErrorAsymmetric;
159  optionString.ReplaceAll("errasym", "");
160  }
161 
162  if (optionString.Contains("errfunc")) {
163  fErrorMode = TRatioPlot::ErrorMode::kErrorFunc;
164  optionString.ReplaceAll("errfunc", "");
165  }
166  } else if (optionString.Contains("diff")) {
167  optionString.ReplaceAll("diff", "");
168  fMode = TRatioPlot::CalculationMode::kDifference;
169  } else {
170  fMode = TRatioPlot::CalculationMode::kDivideGraph; // <- default
171  }
172 
173  fOption = optionString;
174 
175 
176  fH1DrawOpt = "hist";
177  fH2DrawOpt = "E";
178  fGraphDrawOpt = "AP";
179 
180 
181  // build ratio, everything is ready
182  if (!BuildLowerPlot()) return;
183 
184  // taking x axis information from h1 by cloning it x axis
185  fSharedXAxis = (TAxis*)(fH1->GetXaxis()->Clone());
186  fUpYaxis = (TAxis*)(fH1->GetYaxis()->Clone());
188 }
189 
190 ////////////////////////////////////////////////////////////////////////////////
191 /// Constructor for two histograms
192 ///
193 /// \param h1 First histogram
194 /// \param h2 Second histogram
195 /// \param option Steers the error calculation, as well as ratio / difference
196 
198  : fGridlines()
199 {
200  gROOT->GetListOfCleanups()->Add(this);
201 
202  if (!h1 || !h2) {
203  Warning("TRatioPlot", "Need two histograms.");
204  return;
205  }
206 
207  Bool_t h1IsTH1=h1->IsA()->InheritsFrom(TH1::Class());
208  Bool_t h2IsTH1=h2->IsA()->InheritsFrom(TH1::Class());
209 
210  if (!h1IsTH1 && !h2IsTH1) {
211  Warning("TRatioPlot", "Need two histograms deriving from TH2 or TH3.");
212  return;
213  }
214 
215  fHistDrawProxy = h1;
216 
217  Init(h1, h2, option);
218 
219 }
220 
221 ////////////////////////////////////////////////////////////////////////////////
222 /// Constructor which accepts a `THStack` and a histogram. Converts the
223 /// stack to a regular sum of its containing histograms for processing.
224 ///
225 /// \param st The THStack object
226 /// \param h2 The other histogram
227 /// \param option Steers the calculation of the lower plot
228 
230 {
231  if (!st || !h2) {
232  Warning("TRatioPlot", "Need a histogram and a stack");
233  return;
234  }
235 
236  TList *stackHists = st->GetHists();
237 
238  if (stackHists->GetSize() == 0) {
239  Warning("TRatioPlot", "Stack does not have histograms");
240  return;
241  }
242 
243  TH1* tmpHist = (TH1*)stackHists->At(0)->Clone();
244  tmpHist->Reset();
245 
246  for (int i=0;i<stackHists->GetSize();++i) {
247  tmpHist->Add((TH1*)stackHists->At(i));
248  }
249 
250  fHistDrawProxy = st;
251 
252  Init(tmpHist, h2, option);
253 
254 }
255 
256 ////////////////////////////////////////////////////////////////////////////////
257 /// Constructor for one histogram and a fit.
258 ///
259 /// \param h1 The histogram
260 /// \param option Steers the error calculation
261 /// \param fitres Explicit fit result to be used for calculation. Uses last fit if left empty
262 
264  : fH1(h1),
265  fGridlines()
266 {
267  gROOT->GetListOfCleanups()->Add(this);
268 
269  if (!fH1) {
270  Warning("TRatioPlot", "Need a histogram.");
271  return;
272  }
273 
274  Bool_t h1IsTH1=fH1->IsA()->InheritsFrom(TH1::Class());
275 
276  if (!h1IsTH1) {
277  Warning("TRatioPlot", "Need a histogram deriving from TH2 or TH3.");
278  return;
279  }
280 
281  TList *h1Functions = fH1->GetListOfFunctions();
282 
283  if (h1Functions->GetSize() < 1) {
284  Warning("TRatioPlot", "Histogram given needs to have a (fit) function associated with it");
285  return;
286  }
287 
288 
289  fHistDrawProxy = h1;
290 
291  fFitResult = fitres;
292 
293  fMode = TRatioPlot::CalculationMode::kFitResidual;
294 
295  TString optionString = TString(option);
296 
297  // determine which error style
298  if (optionString.Contains("errasym")) {
299  fErrorMode = TRatioPlot::ErrorMode::kErrorAsymmetric;
300  optionString.ReplaceAll("errasym", "");
301  }
302 
303  if (optionString.Contains("errfunc")) {
304  fErrorMode = TRatioPlot::ErrorMode::kErrorFunc;
305  optionString.ReplaceAll("errfunc", "");
306  }
307 
308  fOption = optionString;
309 
310  if (!BuildLowerPlot()) return;
311 
312  // emulate option behaviour of TH1
313  if (fH1->GetSumw2N() > 0) {
314  fH1DrawOpt = "E";
315  } else {
316  fH1DrawOpt = "hist";
317  }
318  fGraphDrawOpt = "LX"; // <- default
319 
320  fSharedXAxis = (TAxis*)(fH1->GetXaxis()->Clone());
321  fUpYaxis = (TAxis*)(fH1->GetYaxis()->Clone());
323 
324  //SyncAxesRanges();
325 
326  SetupPads();
327 
328 }
329 
330 ////////////////////////////////////////////////////////////////////////////////
331 /// Sets the drawing option for h1
332 
334 {
335  fH1DrawOpt = opt;
336 }
337 
338 ////////////////////////////////////////////////////////////////////////////////
339 /// Sets the drawing option for h2
340 
342 {
343  TString optString = TString(opt);
344  optString.ReplaceAll("same", "");
345  optString.ReplaceAll("SAME", "");
346 
347  fH2DrawOpt = optString;
348 }
349 
350 ////////////////////////////////////////////////////////////////////////////////
351 /// Sets the drawing option for the lower graph
352 
354 {
355  fGraphDrawOpt = opt;
356 }
357 
358 ////////////////////////////////////////////////////////////////////////////////
359 /// Sets the drawing option for the fit in the fit residual case
360 
362 {
363  fFitDrawOpt = opt;
364 }
365 
366 ////////////////////////////////////////////////////////////////////////////////
367 /// Setup the pads.
368 
370 
371  // this method will delete all the pads before recreating them
372 
373  if (fUpperPad != 0) {
374  delete fUpperPad;
375  fUpperPad = 0;
376  }
377 
378  if (fLowerPad != 0) {
379  delete fLowerPad;
380  fLowerPad = 0;
381  }
382 
383  if (!gPad) {
384  Error("SetupPads", "need to create a canvas first");
385  return;
386  }
387 
388  double pm = fInsetWidth;
389  double width = gPad->GetWNDC();
390  double height = gPad->GetHNDC();
391  double f = height/width;
392 
393  fUpperPad = new TPad("upper_pad", "", pm*f, fSplitFraction, 1.-pm*f, 1.-pm);
394  fLowerPad = new TPad("lower_pad", "", pm*f, pm, 1.-pm*f, fSplitFraction);
395 
396  SetPadMargins();
397 
398  // connect to the pads signal
399  fUpperPad->Connect("RangeAxisChanged()", "TRatioPlot", this, "RangeAxisChanged()");
400  fLowerPad->Connect("RangeAxisChanged()", "TRatioPlot", this, "RangeAxisChanged()");
401 
402  fUpperPad->Connect("UnZoomed()", "TRatioPlot", this, "UnZoomed()");
403  fLowerPad->Connect("UnZoomed()", "TRatioPlot", this, "UnZoomed()");
404 
405  fUpperPad->Connect("Resized()", "TRatioPlot", this, "SubPadResized()");
406  fLowerPad->Connect("Resized()", "TRatioPlot", this, "SubPadResized()");
407 
408  if (fTopPad != 0) {
409  delete fTopPad;
410  fTopPad = 0;
411  }
412 
413  fTopPad = new TPad("top_pad", "", pm*f, pm, 1-pm*f, 1-pm);
414 
416 
417 }
418 
419 ////////////////////////////////////////////////////////////////////////////////
420 /// Browse.
421 
423 {
424  Draw(b ? b->GetDrawOption() : "");
425  gPad->Update();
426 }
427 
428 ////////////////////////////////////////////////////////////////////////////////
429 /// Sets the top margin of the upper pad.
430 ///
431 /// \param margin The new margin
432 
434 {
435  fUpTopMargin = margin;
436  SetPadMargins();
437 }
438 
439 ////////////////////////////////////////////////////////////////////////////////
440 /// Sets the bottom margin of the upper pad.
441 ///
442 /// \param margin The new margin
443 
445 {
446  fUpBottomMargin = margin;
447  SetPadMargins();
448 }
449 
450 ////////////////////////////////////////////////////////////////////////////////
451 /// Sets the top margin of the lower pad.
452 ///
453 /// \param margin The new margin
454 
456 {
457  fLowTopMargin = margin;
458  SetPadMargins();
459 }
460 
461 ////////////////////////////////////////////////////////////////////////////////
462 /// Sets the bottom margin of the lower pad.
463 ///
464 /// \param margin The new margin
465 
467 {
468  fLowBottomMargin = margin;
469  SetPadMargins();
470 }
471 
472 ////////////////////////////////////////////////////////////////////////////////
473 /// Sets the left margin of both pads.
474 /// \param margin The new margin
475 
477 {
478  fLeftMargin = margin;
479  SetPadMargins();
480 }
481 
482 ////////////////////////////////////////////////////////////////////////////////
483 /// Sets the right margin of both pads.
484 ///
485 /// \param margin The new margin
486 
488 {
489  fRightMargin = margin;
490  SetPadMargins();
491 }
492 
493 ////////////////////////////////////////////////////////////////////////////////
494 /// Sets the margin that separates the two pads. The margin is split according
495 /// to the relative sizes of the pads
496 ///
497 /// \param margin The new margin
498 ///
499 /// Begin_Macro(source)
500 /// ../../../tutorials/hist/ratioplot6.C
501 /// End_Macro
502 
504 {
505  Float_t sf = fSplitFraction;
506  fUpBottomMargin = margin/2./(1-sf);
507  fLowTopMargin = margin/2./sf;
508  SetPadMargins();
509 }
510 
511 ////////////////////////////////////////////////////////////////////////////////
512 /// Return the separation margin value.
513 
515 {
516  Float_t sf = fSplitFraction;
517  Float_t up = fUpBottomMargin * (1-sf);
518  Float_t down = fLowTopMargin * sf;
519  return up+down;
520 }
521 
522 ////////////////////////////////////////////////////////////////////////////////
523 /// Draws the ratio plot to the currently active pad. Therefore it requires that
524 /// a TCanvas has been created first.
525 ///
526 /// It takes the following options
527 ///
528 /// | Option | Description |
529 /// | ---------- | ------------------------------------------------------------ |
530 /// | grid / nogrid | enable (default) or disable drawing of dashed lines on lower plot |
531 /// | hideup | hides the first label of the upper axis if there is not enough space |
532 /// | fhideup | always hides the first label of the upper axis |
533 /// | hidelow (default) | hides the last label of the lower axis if there is not enough space |
534 /// | fhidelow | always hides the last label of the lower axis |
535 /// | nohide | does not hide a label if there is not enough space |
536 /// | noconfint | does not draw the confidence interval bands in the fit residual case |
537 /// | confint | draws the confidence interval bands in the fit residual case (default) |
538 
540 {
541 
542  TString drawOpt = option;
543 
544  if (drawOpt.Contains("nogrid")) {
545  drawOpt.ReplaceAll("nogrid", "");
547  } else if (drawOpt.Contains("grid")) {
548  drawOpt.ReplaceAll("grid", "");
550  }
551 
552  if (drawOpt.Contains("noconfint")) {
553  drawOpt.ReplaceAll("noconfint", "");
555  } else if (drawOpt.Contains("confint")) {
556  drawOpt.ReplaceAll("confint", "");
557  fShowConfidenceIntervals = kTRUE; // <- default
558  }
559 
560  if (drawOpt.Contains("fhideup")) {
561  fHideLabelMode = TRatioPlot::HideLabelMode::kForceHideUp;
562  } else if (drawOpt.Contains("fhidelow")) {
563  fHideLabelMode = TRatioPlot::HideLabelMode::kForceHideLow;
564  } else if (drawOpt.Contains("hideup")) {
565  fHideLabelMode = TRatioPlot::HideLabelMode::kHideUp;
566  } else if (drawOpt.Contains("hidelow")) {
567  fHideLabelMode = TRatioPlot::HideLabelMode::kHideLow;
568  } else if (drawOpt.Contains("nohide")) {
569  fHideLabelMode = TRatioPlot::HideLabelMode::kNoHide;
570  } else {
571  fHideLabelMode = TRatioPlot::HideLabelMode::kHideLow; // <- default
572  }
573 
574  if (!gPad) {
575  Error("Draw", "need to create a canvas first");
576  return;
577  }
578 
579  TVirtualPad *padsav = gPad;
580  fParentPad = gPad;
581 
585 
590 
591  // we are a TPad
592 
593  fUpperPad->Draw();
594  fLowerPad->Draw();
595 
596  fTopPad->SetFillStyle(0);
597  fTopPad->Draw();
598 
599  fUpperPad->cd();
600 
601  fConfidenceInterval2->SetFillColor(fCi1Color);
602  fConfidenceInterval1->SetFillColor(fCi2Color);
603 
604  if (fMode == TRatioPlot::CalculationMode::kFitResidual) {
605  TF1 *func = dynamic_cast<TF1*>(fH1->GetListOfFunctions()->At(0));
606 
607  if (func == 0) {
608  // this is checked in constructor and should thus not occur
609  Error("BuildLowerPlot", "h1 does not have a fit function");
610  return;
611  }
612 
613  fH1->Draw("A"+fH1DrawOpt);
614  func->Draw(fFitDrawOpt+"same");
615 
616  fLowerPad->cd();
617 
619  fConfidenceInterval2->Draw("IA3");
621  fRatioGraph->Draw(fGraphDrawOpt+"SAME");
622  } else {
623  fRatioGraph->Draw("IA"+fGraphDrawOpt+"SAME");
624  }
625  } else {
626 
627  if (fHistDrawProxy) {
629  ((TH1*)fHistDrawProxy)->Draw("A"+fH1DrawOpt);
630  } else if (fHistDrawProxy->InheritsFrom(THStack::Class())) {
631  ((THStack*)fHistDrawProxy)->Draw("A"+fH1DrawOpt);
632  } else {
633  Warning("Draw", "Draw proxy not of type TH1 or THStack, not drawing it");
634  }
635  }
636 
637  fH2->Draw("A"+fH2DrawOpt+"same");
638 
639  fLowerPad->cd();
640 
641  TString opt = fGraphDrawOpt;
643 
644  }
645 
646  // assign same axis ranges to lower pad as in upper pad
647  // the visual axes will be created on paint
648  SyncAxesRanges();
649 
650  CreateGridline();
651 
652  padsav->cd();
653  AppendPad();
654 }
655 
656 ////////////////////////////////////////////////////////////////////////////////
657 /// Returns the reference graph for the lower pad, which means the graph that
658 /// is responsible for setting the coordinate system. It is the first graph
659 /// added to the primitive list of the lower pad.
660 /// This reference can be used to set the minimum and maximum of the lower pad.
661 /// Note that `TRatioPlot::Draw` needs to have been called first, since the
662 /// graphs are only created then.
663 ///
664 /// Begin_Macro(source)
665 /// ../../../tutorials/hist/ratioplot3.C
666 /// End_Macro
667 
669 {
670  if (fLowerPad == 0) {
671  Error("GetLowerRefGraph", "Lower pad has not been defined");
672  return 0;
673  }
674 
675  TList *primlist = fLowerPad->GetListOfPrimitives();
676  if (primlist->GetSize() == 0) {
677  Error("GetLowerRefGraph", "Lower pad does not have primitives");
678  return 0;
679  }
680 
681  TObjLink *lnk = primlist->FirstLink();
682 
683  while (lnk) {
684  TObject *obj = lnk->GetObject();
685 
686  if (obj->InheritsFrom(TGraph::Class())) {
687  return (TGraph*)obj;
688  }
689 
690  lnk = lnk->Next();
691  }
692 
693  Error("GetLowerRefGraph", "Did not find graph in list");
694  return 0;
695 }
696 
697 ////////////////////////////////////////////////////////////////////////////////
698 /// Return the reference object. Its the first TH1 or THStack type object
699 /// in the upper pads list of primitives.
700 /// Note that it returns a `TObject`, so you need to test and cast it to use it.
701 
703 {
704  TList *primlist = fUpperPad->GetListOfPrimitives();
705  TObject *refobj = 0;
706  for (Int_t i=0;i<primlist->GetSize();++i) {
707  refobj = primlist->At(i);
708  if (refobj->InheritsFrom(TH1::Class()) || refobj->InheritsFrom(THStack::Class())) {
709  return refobj;
710  }
711  }
712 
713  Error("GetUpperRefObject", "No upper ref object of TH1 or THStack type found");
714  return 0;
715 }
716 
717 ////////////////////////////////////////////////////////////////////////////////
718 /// Gets the x axis of the object returned by `TRatioPlot::GetUpperRefObject`.
719 
721 {
722  TObject *refobj = GetUpperRefObject();
723 
724  if (!refobj) return 0;
725 
726  if (refobj->InheritsFrom(TH1::Class())) {
727  return ((TH1*)refobj)->GetXaxis();
728  } else if (refobj->InheritsFrom(THStack::Class())) {
729  return ((THStack*)refobj)->GetXaxis();
730  }
731 
732  return 0;
733 }
734 
735 ////////////////////////////////////////////////////////////////////////////////
736 /// Gets the y axis of the object returned by `TRatioPlot::GetUpperRefObject`.
737 
739 {
740  TObject *refobj = GetUpperRefObject();
741 
742  if (!refobj) return 0;
743 
744  if (refobj->InheritsFrom(TH1::Class())) {
745  return ((TH1*)refobj)->GetYaxis();
746  } else if (refobj->InheritsFrom(THStack::Class())) {
747  return ((THStack*)refobj)->GetYaxis();
748  }
749 
750  return 0;
751 }
752 
753 ////////////////////////////////////////////////////////////////////////////////
754 /// Create a grid line
755 
757 {
758 
759  if (!fShowGridlines) {
760  return; // don't draw them
761  }
762 
763  TVirtualPad *padsav = gPad;
764 
765  fLowerPad->cd();
766 
767  unsigned int dest = fGridlinePositions.size();
768 
769  Double_t lowYFirst = fLowerPad->GetUymin();
770  Double_t lowYLast = fLowerPad->GetUymax();
771 
772  double y;
773  int outofrange = 0;
774  for (unsigned int i=0;i<fGridlinePositions.size();++i) {
775  y = fGridlinePositions.at(i);
776 
777  if (y < lowYFirst || lowYLast < y) {
778  ++outofrange;
779  }
780 
781  }
782 
783  dest = dest - outofrange;
784 
785  // clear all
786  for (unsigned int i=0;i<fGridlines.size();++i) {
787  delete fGridlines.at(i);
788  }
789 
790  fGridlines.erase(fGridlines.begin(), fGridlines.end());
791 
792  for (unsigned int i=0;i<dest;++i) {
793  TLine *newline = new TLine(0, 0, 0, 0);
794  newline->SetLineStyle(2);
795  newline->Draw();
796  fGridlines.push_back(newline);
797  }
798 
801 
802  TLine *line;
803  unsigned int skipped = 0;
804  for (unsigned int i=0;i<fGridlinePositions.size();++i) {
805  y = fGridlinePositions[i];
806 
807  if (y < lowYFirst || lowYLast < y) {
808  // this is one of the ones that was out of range
809  ++skipped;
810  continue;
811  }
812 
813  line = fGridlines.at(i-skipped);
814 
815  line->SetX1(first);
816  line->SetX2(last);
817  line->SetY1(y);
818  line->SetY2(y);
819  }
820 
821  padsav->cd();
822 }
823 
824 ////////////////////////////////////////////////////////////////////////////////
825 /// Creates the visual axes when painting.
826 
828 {
829  // create the visual axes
831  CreateGridline();
832 
834 }
835 
836 ////////////////////////////////////////////////////////////////////////////////
837 /// Syncs the axes ranges from the shared ones to the actual ones.
838 
840 {
841  // get ranges from the shared axis clone
844 
845  // set range on computed graph, have to set it twice because
846  // TGraph's axis looks strange otherwise
847  TAxis *ref = GetLowerRefXaxis();
848  ref->SetLimits(first, last);
849  ref->SetRangeUser(first, last);
850 
852 
853 }
854 
855 ////////////////////////////////////////////////////////////////////////////////
856 /// Build the lower plot according to which constructor was called, and
857 /// which options were passed.
858 
860 {
861  // Clear and delete the graph if not exists
862  if (fRatioGraph != 0) {
863  fRatioGraph->IsA()->Destructor(fRatioGraph);
864  fRatioGraph = 0;
865  }
866 
867  if (fConfidenceInterval1 == 0) {
869  }
870 
871  if (fConfidenceInterval2 == 0) {
873  }
874 
875  static Double_t divideGridlines[] = {0.7, 1.0, 1.3};
876  static Double_t diffGridlines[] = {0.0};
877  static Double_t signGridlines[] = {1.0, 0.0, -1.0};
878 
879  // Determine the divide mode and create the lower graph accordingly
880  // Pass divide options given in constructor
881  if (fMode == TRatioPlot::CalculationMode::kDivideGraph) {
882  // use TGraphAsymmErrors Divide method to create
883 
884  SetGridlines(divideGridlines, 3);
885 
886  TH1 *tmpH1 = (TH1*)fH1->Clone();
887  TH1 *tmpH2 = (TH1*)fH2->Clone();
888 
889  tmpH1->Scale(fC1);
890  tmpH2->Scale(fC2);
891 
892  TGraphAsymmErrors *ratioGraph = new TGraphAsymmErrors();
893  ratioGraph->Divide(tmpH1, tmpH2, fOption.Data());
894  fRatioGraph = ratioGraph;
895 
896  delete tmpH1;
897  delete tmpH2;
898 
899  } else if (fMode == TRatioPlot::CalculationMode::kDifference) {
900  SetGridlines(diffGridlines, 3);
901 
902  TH1 *tmpHist = (TH1*)fH1->Clone();
903 
904  tmpHist->Reset();
905 
906  tmpHist->Add(fH1, fH2, fC1, -1*fC2);
907  fRatioGraph = new TGraphErrors(tmpHist);
908 
909  delete tmpHist;
910  } else if (fMode == TRatioPlot::CalculationMode::kDifferenceSign) {
911 
912  SetGridlines(signGridlines, 3);
913 
915  Int_t ipoint = 0;
916  Double_t res;
917  Double_t error;
918 
919  Double_t val;
920  Double_t val2;
921 
922  for (Int_t i=0; i<=fH1->GetNbinsX();++i) {
923  val = fH1->GetBinContent(i);
924  val2 = fH2->GetBinContent(i);
925 
926  if (fErrorMode == TRatioPlot::ErrorMode::kErrorAsymmetric) {
927 
928  Double_t errUp = fH1->GetBinErrorUp(i);
929  Double_t errLow = fH1->GetBinErrorLow(i);
930 
931  if (val - val2 > 0) {
932  // h1 > h2
933  error = errLow;
934  } else {
935  // h1 < h2
936  error = errUp;
937  }
938 
939  } else if (fErrorMode == TRatioPlot::ErrorMode::kErrorSymmetric) {
940  error = fH1->GetBinError(i);
941  } else {
942  Warning("BuildLowerPlot", "error mode is invalid");
943  error = 0;
944  }
945 
946  if (error != 0) {
947 
948  res = (val - val2) / error;
949 
950  ((TGraphAsymmErrors*)fRatioGraph)->SetPoint(ipoint, fH1->GetBinCenter(i), res);
951  ((TGraphAsymmErrors*)fRatioGraph)->SetPointError(ipoint, fH1->GetBinWidth(i)/2., fH1->GetBinWidth(i)/2., 0.5, 0.5);
952 
953  ++ipoint;
954 
955  }
956  }
957 
958  } else if (fMode == TRatioPlot::CalculationMode::kFitResidual) {
959 
960  SetGridlines(signGridlines, 3);
961 
962  TF1 *func = dynamic_cast<TF1*>(fH1->GetListOfFunctions()->At(0));
963 
964  if (func == 0) {
965  // this is checked in constructor and should thus not occur
966  Error("BuildLowerPlot", "h1 does not have a fit function");
967  return 0;
968  }
969 
971  Int_t ipoint = 0;
972 
973  Double_t res;
974  Double_t error;
975 
976  std::vector<double> ci1;
977  std::vector<double> ci2;
978 
979  Double_t *x_arr = new Double_t[fH1->GetNbinsX()];
980  std::fill_n(x_arr, fH1->GetNbinsX(), 0);
981  Double_t *ci_arr1 = new Double_t[fH1->GetNbinsX()];
982  std::fill_n(ci_arr1, fH1->GetNbinsX(), 0);
983  Double_t *ci_arr2 = new Double_t[fH1->GetNbinsX()];
984  std::fill_n(ci_arr2, fH1->GetNbinsX(), 0);
985  for (Int_t i=0; i<fH1->GetNbinsX();++i) {
986  x_arr[i] = fH1->GetBinCenter(i+1);
987  }
988 
989  Double_t cl1 = fCl1;
990  Double_t cl2 = fCl2;
991 
992  if (fFitResult != 0) {
993  // use this to get conf int
994 
995  fFitResult->GetConfidenceIntervals(fH1->GetNbinsX(), 1, 1, x_arr, ci_arr1, cl1);
996  for (Int_t i=1; i<=fH1->GetNbinsX();++i) {
997  ci1.push_back(ci_arr1[i-1]);
998  }
999 
1000  fFitResult->GetConfidenceIntervals(fH1->GetNbinsX(), 1, 1, x_arr, ci_arr2, cl2);
1001  for (Int_t i=1; i<=fH1->GetNbinsX();++i) {
1002  ci2.push_back(ci_arr2[i-1]);
1003  }
1004  } else {
1005  (TVirtualFitter::GetFitter())->GetConfidenceIntervals(fH1->GetNbinsX(), 1, x_arr, ci_arr1, cl1);
1006  for (Int_t i=1; i<=fH1->GetNbinsX();++i) {
1007  ci1.push_back(ci_arr1[i-1]);
1008  }
1009  (TVirtualFitter::GetFitter())->GetConfidenceIntervals(fH1->GetNbinsX(), 1, x_arr, ci_arr2, cl2);
1010  for (Int_t i=1; i<=fH1->GetNbinsX();++i) {
1011  ci2.push_back(ci_arr2[i-1]);
1012  }
1013 
1014  }
1015 
1016  Double_t x;
1017  Double_t val;
1018 
1019  for (Int_t i=0; i<=fH1->GetNbinsX();++i) {
1020  val = fH1->GetBinContent(i);
1021  x = fH1->GetBinCenter(i+1);
1022 
1023  if (fErrorMode == TRatioPlot::ErrorMode::kErrorAsymmetric) {
1024 
1025  Double_t errUp = fH1->GetBinErrorUp(i);
1026  Double_t errLow = fH1->GetBinErrorLow(i);
1027 
1028  if (val - func->Eval(fH1->GetBinCenter(i)) > 0) {
1029  // h1 > fit
1030  error = errLow;
1031  } else {
1032  // h1 < fit
1033  error = errUp;
1034  }
1035 
1036  } else if (fErrorMode == TRatioPlot::ErrorMode::kErrorSymmetric) {
1037  error = fH1->GetBinError(i);
1038  } else if (fErrorMode == TRatioPlot::ErrorMode::kErrorFunc) {
1039 
1040  error = sqrt(func->Eval(x));
1041 
1042  } else {
1043  Warning("BuildLowerPlot", "error mode is invalid");
1044  error = 0;
1045  }
1046 
1047  if (error != 0) {
1048 
1049  res = (fH1->GetBinContent(i)- func->Eval(fH1->GetBinCenter(i) ) ) / error;
1050  //__("x="<< x << " y=" << res << " err=" << error);
1051 
1052  ((TGraphAsymmErrors*)fRatioGraph)->SetPoint(ipoint, fH1->GetBinCenter(i), res);
1053  ((TGraphAsymmErrors*)fRatioGraph)->SetPointError(ipoint, fH1->GetBinWidth(i)/2., fH1->GetBinWidth(i)/2., 0.5, 0.5);
1054 
1055  fConfidenceInterval1->SetPoint(ipoint, x, 0);
1056  fConfidenceInterval1->SetPointError(ipoint, x, i < (Int_t)ci1.size() ? ci1[i] / error : 0);
1057  fConfidenceInterval2->SetPoint(ipoint, x, 0);
1058  fConfidenceInterval2->SetPointError(ipoint, x, i < (Int_t)ci2.size() ? ci2[i] / error : 0);
1059 
1060  ++ipoint;
1061 
1062  }
1063 
1064  }
1065  delete [] x_arr;
1066  delete [] ci_arr1;
1067  delete [] ci_arr2;
1068  } else if (fMode == TRatioPlot::CalculationMode::kDivideHist){
1069  SetGridlines(divideGridlines, 3);
1070 
1071  // Use TH1's Divide method
1072  TH1 *tmpHist = (TH1*)fH1->Clone();
1073  tmpHist->Reset();
1074 
1075  tmpHist->Divide(fH1, fH2, fC1, fC2, fOption.Data());
1076  fRatioGraph = new TGraphErrors(tmpHist);
1077 
1078  delete tmpHist;
1079  } else {
1080  // this should not occur
1081  Error("BuildLowerPlot", "Invalid fMode value");
1082  return 0;
1083  }
1084 
1085  // need to set back to "" since recreation. we don't ever want
1086  // title on lower graph
1087 
1088  if (fRatioGraph == 0) {
1089  Error("BuildLowerPlot", "Error creating lower graph");
1090  return 0;
1091  }
1092 
1093  fRatioGraph->SetTitle("");
1096 
1097  return 1;
1098 }
1099 
1100 ////////////////////////////////////////////////////////////////////////////////
1101 /// (Re-)Creates the TGAxis objects that are used for consistent display of the
1102 /// axes.
1103 
1105 {
1106  TVirtualPad *padsav = gPad;
1107  fTopPad->cd();
1108 
1109  // this is for errors
1110  TString thisfunc = "CreateVisualAxes";
1111 
1112  // figure out where the axis has to go.
1113  // Implicit assumption is, that the top pad spans the full other pads
1114  Double_t upTM = fUpperPad->GetTopMargin();
1116  Double_t upLM = fUpperPad->GetLeftMargin();
1117  Double_t upRM = fUpperPad->GetRightMargin();
1118 
1119  Double_t lowTM = fLowerPad->GetTopMargin();
1120  Double_t lowBM = fLowerPad->GetBottomMargin();
1121  Double_t lowLM = fLowerPad->GetLeftMargin();
1122  Double_t lowRM = fLowerPad->GetRightMargin();
1123 
1126 
1127  Double_t upYFirst = fUpperPad->GetUymin();
1128  Double_t upYLast = fUpperPad->GetUymax();
1129  Double_t lowYFirst = fLowerPad->GetUymin();
1130  Double_t lowYLast = fLowerPad->GetUymax();
1131 
1132  Float_t sf = fSplitFraction;
1133 
1134  // check if gPad has the all sides axis set
1135  Bool_t mirroredAxes = fParentPad->GetFrameFillStyle() == 0;
1136  Bool_t axistop = fParentPad->GetTickx() == 1 || mirroredAxes;
1137  Bool_t axisright = fParentPad->GetTicky() == 1 || mirroredAxes;
1138 
1139  Bool_t logx = fUpperPad->GetLogx() || fLowerPad->GetLogx();
1140  Bool_t uplogy = fUpperPad->GetLogy();
1141  Bool_t lowlogy = fLowerPad->GetLogy();
1142 
1143  if (uplogy) {
1144 
1145  upYFirst = TMath::Power(10, upYFirst);
1146  upYLast = TMath::Power(10, upYLast);
1147 
1148  if (upYFirst <= 0 || upYLast <= 0) {
1149  Error(thisfunc, "Cannot set upper Y axis to log scale");
1150  }
1151  }
1152 
1153  if (lowlogy) {
1154  lowYFirst = TMath::Power(10, lowYFirst);
1155  lowYLast = TMath::Power(10, lowYLast);
1156 
1157  if (lowYFirst <= 0 || lowYLast <= 0) {
1158  Error(thisfunc, "Cannot set lower Y axis to log scale");
1159  }
1160 
1161  }
1162 
1163  // this is different than in y, y already has pad coords converted, x not...
1164  if (logx) {
1165  if (first <= 0 || last <= 0) {
1166  Error(thisfunc, "Cannot set X axis to log scale");
1167  }
1168  }
1169 
1170  // determine axes options to create log axes if needed
1171  TString xopt = "";
1172  if (logx) xopt.Append("G");
1173  TString upyopt = "";
1174  if (uplogy) upyopt.Append("G");
1175  TString lowyopt = "";
1176  if (lowlogy) lowyopt.Append("G");
1177 
1178  // only actually create them once, reuse otherwise b/c memory
1179  if (fUpperGXaxis == 0) {
1180  fUpperGXaxis = new TGaxis(0, 0, 1, 1, 0, 1, 510, "+U"+xopt);
1181  fUpperGXaxis->Draw();
1182  }
1183 
1184  if (fUpperGYaxis == 0) {
1185  fUpperGYaxis = new TGaxis(0, 0, 1, 1, upYFirst, upYLast, 510, "S"+upyopt);
1186  fUpperGYaxis->Draw();
1187  }
1188 
1189  if (fLowerGXaxis == 0) {
1190  fLowerGXaxis = new TGaxis(0, 0, 1, 1, first, last, 510, "+S"+xopt);
1191  fLowerGXaxis->Draw();
1192  }
1193 
1194  if (fLowerGYaxis == 0) {
1195  fLowerGYaxis = new TGaxis(0, 0, 1, 1, lowYFirst, lowYLast, 510, "-S"+lowyopt);
1196  fLowerGYaxis->Draw();
1197  }
1198 
1199  // import infos from TAxis
1204 
1205  // lower x axis needs to get title from upper x
1207 
1208  // (re)set all the axes properties to what we want them
1209  fUpperGXaxis->SetTitle("");
1210 
1211  fUpperGXaxis->SetX1(upLM);
1212  fUpperGXaxis->SetX2(1-upRM);
1213  fUpperGXaxis->SetY1(upBM*(1-sf)+sf);
1214  fUpperGXaxis->SetY2(upBM*(1-sf)+sf);
1216  fUpperGXaxis->SetWmax(last);
1217 
1218  fUpperGYaxis->SetX1(upLM);
1219  fUpperGYaxis->SetX2(upLM);
1220  fUpperGYaxis->SetY1(upBM*(1-sf)+sf);
1221  fUpperGYaxis->SetY2( (1-upTM)*(1-sf)+sf );
1222  fUpperGYaxis->SetWmin(upYFirst);
1223  fUpperGYaxis->SetWmax(upYLast);
1224 
1225  fLowerGXaxis->SetX1(lowLM);
1226  fLowerGXaxis->SetX2(1-lowRM);
1227  fLowerGXaxis->SetY1(lowBM*sf);
1228  fLowerGXaxis->SetY2(lowBM*sf);
1230  fLowerGXaxis->SetWmax(last);
1231 
1232  fLowerGYaxis->SetX1(lowLM);
1233  fLowerGYaxis->SetX2(lowLM);
1234  fLowerGYaxis->SetY1(lowBM*sf);
1235  fLowerGYaxis->SetY2((1-lowTM)*sf);
1236  fLowerGYaxis->SetWmin(lowYFirst);
1237  fLowerGYaxis->SetWmax(lowYLast);
1238 
1243 
1244  fUpperGXaxis->SetOption("+U"+xopt);
1245  fUpperGYaxis->SetOption("S"+upyopt);
1246  fLowerGXaxis->SetOption("+S"+xopt);
1247  fLowerGYaxis->SetOption("-S"+lowyopt);
1248 
1249  // normalize the tick sizes. y axis ticks should be consistent
1250  // even if their length is different
1251  Double_t ratio = ( (upBM-(1-upTM))*(1-sf) ) / ( (lowBM-(1-lowTM))*sf ) ;
1253  Double_t ticksize = fUpperGYaxis->GetTickSize()*ratio;
1254  fLowerGYaxis->SetTickSize(ticksize);
1255 
1256  if (fHideLabelMode == TRatioPlot::HideLabelMode::kForceHideUp) {
1257 
1258  fUpperGYaxis->ChangeLabel(1, -1, 0);
1259 
1260  } else if (fHideLabelMode == TRatioPlot::HideLabelMode::kForceHideLow) {
1261 
1262  fLowerGYaxis->ChangeLabel(-1, -1, 0);
1263 
1264  } else {
1265  if (GetSeparationMargin() < 0.025) {
1266 
1267  if (fHideLabelMode != TRatioPlot::HideLabelMode::kNoHide) {
1268  if (fHideLabelMode == TRatioPlot::HideLabelMode::kHideUp) {
1269  fUpperGYaxis->ChangeLabel(1, -1, 0);
1270  } else if (fHideLabelMode == TRatioPlot::HideLabelMode::kHideLow) {
1271  fLowerGYaxis->ChangeLabel(-1, -1, 0);
1272  }
1273  }
1274 
1275  } else {
1276  // reset
1277  if (fHideLabelMode == TRatioPlot::HideLabelMode::kHideUp) {
1279  } else if (fHideLabelMode == TRatioPlot::HideLabelMode::kHideLow) {
1281  }
1282 
1283  }
1284  }
1285 
1286  // Create the axes on the other sides of the graphs
1287  // This is steered by an option on the containing pad or self
1288  if (axistop || axisright) {
1289 
1290  // only actually create them once, reuse otherwise b/c memory
1291  if (fUpperGXaxisMirror == 0) {
1293  if (axistop) fUpperGXaxisMirror->Draw();
1294  }
1295 
1296  if (fLowerGXaxisMirror == 0) {
1298  if (axistop) fLowerGXaxisMirror->Draw();
1299  }
1300 
1301  if (fUpperGYaxisMirror == 0) {
1303  if (axisright) fUpperGYaxisMirror->Draw();
1304  }
1305 
1306  if (fLowerGYaxisMirror == 0) {
1308  if (axisright) fLowerGYaxisMirror->Draw();
1309  }
1310 
1311  // import attributes from shared axes
1316 
1317  // remove titles
1322 
1323  // move them about and set required positions
1324  fUpperGXaxisMirror->SetX1(upLM);
1325  fUpperGXaxisMirror->SetX2(1-upRM);
1326  fUpperGXaxisMirror->SetY1((1-upTM)*(1-sf)+sf);
1327  fUpperGXaxisMirror->SetY2((1-upTM)*(1-sf)+sf);
1329  fUpperGXaxisMirror->SetWmax(last);
1330 
1331  fUpperGYaxisMirror->SetX1(1-upRM);
1332  fUpperGYaxisMirror->SetX2(1-upRM);
1333  fUpperGYaxisMirror->SetY1(upBM*(1-sf)+sf);
1334  fUpperGYaxisMirror->SetY2( (1-upTM)*(1-sf)+sf );
1335  fUpperGYaxisMirror->SetWmin(upYFirst);
1336  fUpperGYaxisMirror->SetWmax(upYLast);
1337 
1338  fLowerGXaxisMirror->SetX1(lowLM);
1339  fLowerGXaxisMirror->SetX2(1-lowRM);
1340  fLowerGXaxisMirror->SetY1((1-lowTM)*sf);
1341  fLowerGXaxisMirror->SetY2((1-lowTM)*sf);
1343  fLowerGXaxisMirror->SetWmax(last);
1344 
1345  fLowerGYaxisMirror->SetX1(1-lowRM);
1346  fLowerGYaxisMirror->SetX2(1-lowRM);
1347  fLowerGYaxisMirror->SetY1(lowBM*sf);
1348  fLowerGYaxisMirror->SetY2((1-lowTM)*sf);
1349  fLowerGYaxisMirror->SetWmin(lowYFirst);
1350  fLowerGYaxisMirror->SetWmax(lowYLast);
1351 
1352  // also needs normalized tick size
1353  fLowerGYaxisMirror->SetTickSize(ticksize);
1354 
1355  fUpperGXaxisMirror->SetOption("-S"+xopt);
1356  fUpperGYaxisMirror->SetOption("+S"+upyopt);
1357  fLowerGXaxisMirror->SetOption("-S"+xopt);
1358  fLowerGYaxisMirror->SetOption("+S"+lowyopt);
1359 
1364 
1369  }
1370 
1371  padsav->cd();
1372 
1373 }
1374 
1375 ////////////////////////////////////////////////////////////////////////////////
1376 /// Sets the margins of all the pads to the value specified in class members.
1377 /// This one is called whenever those are changed, e.g. in setters
1378 
1380 {
1389 }
1390 
1391 ////////////////////////////////////////////////////////////////////////////////
1392 /// Figures out which pad margin has deviated from the stored ones,
1393 /// to figure out what the new nominal is and set the other pad to it
1394 /// subsequently.
1395 
1397 {
1398 
1399  Bool_t changed = kFALSE;
1400 
1401  if (fUpperPad->GetLeftMargin() != fLeftMargin) {
1403  changed = kTRUE;
1404  }
1405  else if (fLowerPad->GetLeftMargin() != fLeftMargin) {
1407  changed = kTRUE;
1408  }
1409 
1412  changed = kTRUE;
1413  }
1414  else if (fLowerPad->GetRightMargin() != fRightMargin) {
1416  changed = kTRUE;
1417  }
1418 
1419  // only reset margins, if any of the margins changed
1420  if (changed) {
1421  SetPadMargins();
1422  }
1423 
1424  Bool_t verticalChanged = kFALSE;
1425 
1427 
1428  verticalChanged = kTRUE;
1430 
1431  }
1432 
1433  if (fLowerPad->GetTopMargin() != fLowTopMargin) {
1434 
1435  verticalChanged = kTRUE;
1437 
1438  }
1439 
1441 
1443 
1444  }
1445 
1446  if (fUpperPad->GetTopMargin() != fUpTopMargin) {
1447 
1449 
1450  }
1451 
1452  // only reset margins, if any of the margins changed
1453  if (verticalChanged) {
1454  SetPadMargins();
1455  }
1456 
1457  return changed || verticalChanged;
1458 
1459 }
1460 
1461 ////////////////////////////////////////////////////////////////////////////////
1462 /// Slot that receives the RangeAxisChanged signal from any of the pads and
1463 /// reacts correspondingly.
1464 
1466 {
1467  // check if the ratio plot is already drawn.
1468  if (!IsDrawn()) {
1469  // not drawn yet
1470  return;
1471  }
1472 
1473  // Only run this concurrently once, in case it's called async
1474  if (fIsUpdating) {
1475  return;
1476  }
1477 
1478  fIsUpdating = kTRUE;
1479 
1480  // find out if logx has changed
1481  if (fParentPad->GetLogx()) {
1482  if (!fUpperPad->GetLogx() || !fLowerPad->GetLogx()) {
1484  }
1485  } else {
1486  if (fUpperPad->GetLogx() || fLowerPad->GetLogx()) {
1488  }
1489  }
1490 
1491  // set log to pad
1494 
1495  // get axis ranges for upper and lower
1496  TAxis *uprefx = GetUpperRefXaxis();
1497  Double_t upFirst = uprefx->GetBinLowEdge(uprefx->GetFirst());
1498  Double_t upLast = uprefx->GetBinUpEdge(uprefx->GetLast());
1499 
1500  TAxis *lowrefx = GetLowerRefXaxis();
1501  Double_t lowFirst = lowrefx->GetBinLowEdge(lowrefx->GetFirst());
1502  Double_t lowLast = lowrefx->GetBinUpEdge(lowrefx->GetLast());
1503 
1506 
1507  Bool_t upChanged = kFALSE;
1508  Bool_t lowChanged = kFALSE;
1509 
1510  // determine which one has changed
1511  if (upFirst != globFirst || upLast != globLast) {
1512  fSharedXAxis->SetRangeUser(upFirst, upLast);
1513  upChanged = kTRUE;
1514  }
1515  else if (lowFirst != globFirst || lowLast != globLast) {
1516  fSharedXAxis->SetRangeUser(lowFirst, lowLast);
1517  lowChanged = kTRUE;
1518  }
1519 
1520  if (upChanged || lowChanged) {
1521  SyncAxesRanges();
1522  CreateVisualAxes();
1523  CreateGridline();
1524 
1525  // @TODO: Updating is not working when zooming on the lower plot. Axes update, but upper hist only on resize
1526  fUpperPad->Modified();
1527  fLowerPad->Modified();
1528  fTopPad->Modified();
1529  fParentPad->Modified();
1530  }
1531 
1532  // sync the margins in case the user has dragged one of them
1533  Bool_t marginsChanged = SyncPadMargins();
1534 
1535  if (marginsChanged) {
1536  fUpperPad->Modified();
1537  fLowerPad->Modified();
1538  fTopPad->Modified();
1539  fParentPad->Modified();
1540  }
1541 
1542  CreateVisualAxes();
1543  CreateGridline();
1544  fIsUpdating = kFALSE;
1545 }
1546 
1547 ////////////////////////////////////////////////////////////////////////////////
1548 /// Slot for the UnZoomed signal that was introduced to TAxis.
1549 /// Unzoom both pads
1550 
1552 {
1553  // this is what resets the range
1554  fSharedXAxis->SetRange(0, 0);
1555  SyncAxesRanges();
1556 
1557  // Flushing
1558  fUpperPad->Modified();
1559  fLowerPad->Modified();
1560  fTopPad->Modified();
1561  fParentPad->Modified();
1562 }
1563 
1564 ////////////////////////////////////////////////////////////////////////////////
1565 /// Slot that handles common resizing of upper and lower pad.
1566 
1568 {
1569 
1570  if (fIsPadUpdating) {
1571  return;
1572  }
1573 
1575 
1576  Float_t upylow = fUpperPad->GetYlowNDC();
1577  Float_t lowylow = fLowerPad->GetYlowNDC();
1578  Float_t lowh = fLowerPad->GetHNDC();
1579  Float_t lowyup = lowylow + lowh;
1580 
1581  Bool_t changed = kFALSE;
1582 
1583  if (upylow != fSplitFraction) {
1584  // up changed
1585  SetSplitFraction(upylow);
1586  changed = kTRUE;
1587  }
1588  else if (lowyup != fSplitFraction) {
1589  // low changed
1590  SetSplitFraction(lowyup);
1591  changed = kTRUE;
1592  }
1593 
1594  if (changed) {
1595  CreateVisualAxes();
1596  }
1597 
1599 
1600 }
1601 
1602 ////////////////////////////////////////////////////////////////////////////////
1603 /// Check if ... is drawn.
1604 
1606 {
1607  TList *siblings = fParentPad->GetListOfPrimitives();
1608  return siblings->FindObject(this) != 0;
1609 }
1610 
1611 ////////////////////////////////////////////////////////////////////////////////
1612 /// Set the fraction of the parent pad, at which the to sub pads should meet
1613 
1615 {
1616  if (fParentPad == 0) {
1617  Warning("SetSplitFraction", "Can only be used after TRatioPlot has been drawn.");
1618  return;
1619  }
1620 
1621  fSplitFraction = sf;
1622  double pm = fInsetWidth;
1623  double width = fParentPad->GetWNDC();
1624  double height = fParentPad->GetHNDC();
1625  double f = height/width;
1626 
1627  fUpperPad->SetPad(pm*f, fSplitFraction, 1.-pm*f, 1.-pm);
1628  fLowerPad->SetPad(pm*f, pm, 1.-pm*f, fSplitFraction);
1629 }
1630 
1631 ////////////////////////////////////////////////////////////////////////////////
1632 /// Set the inset on the outer sides of all the pads. It's used to make the outer
1633 /// pad draggable.
1634 
1636 {
1637  if (fParentPad == 0) {
1638  Warning("SetInsetWidth", "Can only be used after TRatioPlot has been drawn.");
1639  return;
1640  }
1641 
1642  fInsetWidth = width;
1644 
1645  double pm = fInsetWidth;
1646  double w = fParentPad->GetWNDC();
1647  double h = fParentPad->GetHNDC();
1648  double f = h/w;
1649  fTopPad->SetPad(pm*f, pm, 1-pm*f, 1-pm);
1650 }
1651 
1652 ////////////////////////////////////////////////////////////////////////////////
1653 /// Sets the confidence levels used to calculate the bands in the fit residual
1654 /// case. Defaults to 1 and 2 sigma.
1655 
1657 {
1658  fCl1 = c1;
1659  fCl2 = c2;
1660  if (!BuildLowerPlot()) return;
1661 }
1662 
1663 ////////////////////////////////////////////////////////////////////////////////
1664 /// Set where horizontal, dashed lines are drawn on the lower pad.
1665 /// Can be used to override existing default lines (or disable them).
1666 ///
1667 /// \param gridlines Vector of y positions for the dashes lines
1668 ///
1669 /// Begin_Macro(source)
1670 /// ../../../tutorials/hist/ratioplot4.C
1671 /// End_Macro
1672 
1673 void TRatioPlot::SetGridlines(std::vector<double> gridlines)
1674 {
1675  fGridlinePositions = gridlines;
1676 }
1677 
1678 ////////////////////////////////////////////////////////////////////////////////
1679 /// Set where horizontal, dashed lines are drawn on the lower pad.
1680 /// Can be used to override existing default lines (or disable them).
1681 ///
1682 /// \param gridlines Double_t array of y positions for the dashed lines
1683 /// \param numGridlines Length of gridlines
1684 
1685 void TRatioPlot::SetGridlines(Double_t *gridlines, Int_t numGridlines)
1686 {
1687  fGridlinePositions.clear();
1688 
1689  for (Int_t i=0;i<numGridlines;++i) {
1690  fGridlinePositions.push_back(gridlines[i]);
1691  }
1692 }
1693 
1694 ////////////////////////////////////////////////////////////////////////////////
1695 /// Set the confidence interval colors.
1696 ///
1697 /// \param ci1 Color of the 1 sigma band
1698 /// \param ci2 Color of the 2 sigma band
1699 /// Sets the color of the 1 and 2 sigma bands in the fit residual case.
1700 /// Begin_Macro(source)
1701 /// ../../../tutorials/hist/ratioplot5.C
1702 /// End_Macro
1703 
1705 {
1706  fCi1Color = ci1;
1707  fCi2Color = ci2;
1708 }
1709 
1710 ////////////////////////////////////////////////////////////////////////////////
1711 /// Internal method to import TAxis attributes to a TGaxis. Copied from
1712 /// `TGaxis::ImportAxisAttributes`
1713 
1715 {
1716  gaxis->SetLineColor(axis->GetAxisColor());
1717  gaxis->SetTextColor(axis->GetTitleColor());
1718  gaxis->SetTextFont(axis->GetTitleFont());
1719  gaxis->SetLabelColor(axis->GetLabelColor());
1720  gaxis->SetLabelFont(axis->GetLabelFont());
1721  gaxis->SetLabelSize(axis->GetLabelSize());
1722  gaxis->SetLabelOffset(axis->GetLabelOffset());
1723  gaxis->SetTickSize(axis->GetTickLength());
1724  gaxis->SetTitle(axis->GetTitle());
1725  gaxis->SetTitleOffset(axis->GetTitleOffset());
1726  gaxis->SetTitleSize(axis->GetTitleSize());
1734  if (axis->GetDecimals()) gaxis->SetBit(TAxis::kDecimals); //the bit is in TAxis::fAxis2
1735  gaxis->SetTimeFormat(axis->GetTimeFormat());
1736 }
TAxis::kNoExponent
@ kNoExponent
Definition: TAxis.h:66
TRatioPlot::SetGraphDrawOpt
void SetGraphDrawOpt(Option_t *opt)
Sets the drawing option for the lower graph.
Definition: TRatioPlot.cxx:353
TRatioPlot::fUpBottomMargin
Float_t fUpBottomMargin
Stores the bottom margin of the upper pad.
Definition: TRatioPlot.h:130
TPad::GetYlowNDC
Double_t GetYlowNDC() const
Definition: TPad.h:207
TRatioPlot::GetUpperRefXaxis
TAxis * GetUpperRefXaxis() const
Gets the x axis of the object returned by TRatioPlot::GetUpperRefObject.
Definition: TRatioPlot.cxx:720
TAxis
Class to manage histogram axis.
Definition: TAxis.h:30
TRatioPlot::fMode
Int_t fMode
Stores which calculation is supposed to be performed as specified by user option.
Definition: TRatioPlot.h:83
TH1::GetSumw2N
virtual Int_t GetSumw2N() const
Definition: TH1.h:311
first
Definition: first.py:1
TRatioPlot::SetupPads
virtual void SetupPads()
Setup the pads.
Definition: TRatioPlot.cxx:369
TRatioPlot::SetFitDrawOpt
void SetFitDrawOpt(Option_t *opt)
Sets the drawing option for the fit in the fit residual case.
Definition: TRatioPlot.cxx:361
TLine::SetY2
virtual void SetY2(Double_t y2)
Definition: TLine.h:68
TAttPad::SetTopMargin
virtual void SetTopMargin(Float_t topmargin)
Set Pad top margin in fraction of the pad height.
Definition: TAttPad.cxx:129
TBrowser
Definition: TBrowser.h:37
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TVirtualPad::GetGridx
virtual Bool_t GetGridx() const =0
TObject::kCannotPick
@ kCannotPick
if object in a pad cannot be picked
Definition: TObject.h:63
TObject::TestBit
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
TGaxis::SetWmin
void SetWmin(Double_t wmin)
Definition: TGaxis.h:128
TRatioPlot::SetConfidenceIntervalColors
void SetConfidenceIntervalColors(Color_t ci1=kGreen, Color_t ci2=kYellow)
Set the confidence interval colors.
Definition: TRatioPlot.cxx:1704
TLine.h
TRatioPlot::fH1DrawOpt
TString fH1DrawOpt
Stores draw option for h1 given in constructor.
Definition: TRatioPlot.h:86
TAxis::GetBinLowEdge
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition: TAxis.cxx:518
TH1::GetBinErrorLow
virtual Double_t GetBinErrorLow(Int_t bin) const
Return lower error associated to bin number bin.
Definition: TH1.cxx:8534
TRatioPlot::fConfidenceInterval2
TGraphErrors * fConfidenceInterval2
Stores the graph for the 2 sigma band.
Definition: TRatioPlot.h:95
TGraph::SetTitle
virtual void SetTitle(const char *title="")
Change (i.e.
Definition: TGraph.cxx:2324
TGraph::Draw
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:760
TGaxis::SetTitleOffset
void SetTitleOffset(Float_t titleoffset=1)
Definition: TGaxis.h:124
TFitResult.h
f
#define f(i)
Definition: RSha256.hxx:122
TRatioPlot::fUpTopMargin
Float_t fUpTopMargin
Stores the top margin of the upper pad.
Definition: TRatioPlot.h:129
TRatioPlot::fUpperGXaxisMirror
TGaxis * fUpperGXaxisMirror
Upper mirror of the x axis.
Definition: TRatioPlot.h:114
TLine
Definition: TLine.h:22
TRatioPlot::fShowConfidenceIntervals
Bool_t fShowConfidenceIntervals
Stores whether to show the confidence interval bands. From Draw option.
Definition: TRatioPlot.h:99
TGaxis::SetWmax
void SetWmax(Double_t wmax)
Definition: TGaxis.h:129
TRatioPlot::~TRatioPlot
virtual ~TRatioPlot()
Destructor.
Definition: TRatioPlot.cxx:109
TRatioPlot::fOption
TString fOption
Stores the option which is given in the constructor as a string.
Definition: TRatioPlot.h:85
TRatioPlot::SetSeparationMargin
void SetSeparationMargin(Float_t)
Sets the margin that separates the two pads.
Definition: TRatioPlot.cxx:503
dest
#define dest(otri, vertexptr)
Definition: triangle.c:1040
TPad
Definition: TPad.h:26
TRatioPlot::SyncPadMargins
virtual Bool_t SyncPadMargins()
Figures out which pad margin has deviated from the stored ones, to figure out what the new nominal is...
Definition: TRatioPlot.cxx:1396
TRatioPlot::UnZoomed
void UnZoomed()
Slot for the UnZoomed signal that was introduced to TAxis.
Definition: TRatioPlot.cxx:1551
TAxis::GetDecimals
Bool_t GetDecimals() const
Definition: TAxis.h:116
TList::FindObject
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:577
TAxis::SetLimits
virtual void SetLimits(Double_t xmin, Double_t xmax)
Definition: TAxis.h:154
TString::Data
const char * Data() const
Definition: TString.h:369
TRatioPlot::fCi1Color
Color_t fCi1Color
Stores the color for the 1 sigma band.
Definition: TRatioPlot.h:96
TRatioPlot::fSharedXAxis
TAxis * fSharedXAxis
X axis that stores the range for both plots.
Definition: TRatioPlot.h:109
TRatioPlot::SetRightMargin
void SetRightMargin(Float_t margin)
Sets the right margin of both pads.
Definition: TRatioPlot.cxx:487
THStack
Definition: THStack.h:38
TRatioPlot::SetH2DrawOpt
void SetH2DrawOpt(Option_t *opt)
Sets the drawing option for h2.
Definition: TRatioPlot.cxx:341
TH1::Divide
virtual Bool_t Divide(TF1 *f1, Double_t c1=1)
Performs the operation: this = this/(c1*f1) if errors are defined (see TH1::Sumw2),...
Definition: TH1.cxx:2752
TRatioPlot::Paint
virtual void Paint(Option_t *opt="")
Creates the visual axes when painting.
Definition: TRatioPlot.cxx:827
TRatioPlot::fUpperGYaxis
TGaxis * fUpperGYaxis
Upper graphical y axis.
Definition: TRatioPlot.h:112
TAxis::SetRangeUser
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
Set the viewing range for the axis from ufirst to ulast (in user coordinates, that is,...
Definition: TAxis.cxx:946
TGaxis::SetTitleSize
void SetTitleSize(Float_t titlesize)
Definition: TGaxis.h:125
TRatioPlot::fC2
Double_t fC2
Stores the scale factor for h2.
Definition: TRatioPlot.h:105
TRatioPlot::ImportAxisAttributes
void ImportAxisAttributes(TGaxis *gaxis, TAxis *axis)
Internal method to import TAxis attributes to a TGaxis.
Definition: TRatioPlot.cxx:1714
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TRatioPlot::SubPadResized
void SubPadResized()
Slot that handles common resizing of upper and lower pad.
Definition: TRatioPlot.cxx:1567
TAttPad::GetBottomMargin
Float_t GetBottomMargin() const
Definition: TAttPad.h:49
TFitResult
Definition: TFitResult.h:34
TAttAxis::GetLabelSize
virtual Float_t GetLabelSize() const
Definition: TAttAxis.h:47
TVirtualPad::GetHNDC
virtual Double_t GetHNDC() const =0
TAxis::GetFirst
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:458
Float_t
float Float_t
Definition: RtypesCore.h:57
width
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
TVirtualPad::GetLogy
virtual Int_t GetLogy() const =0
TVirtualPad::cd
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
TVirtualPad::GetLogx
virtual Int_t GetLogx() const =0
TH1::GetBinErrorUp
virtual Double_t GetBinErrorUp(Int_t bin) const
Return upper error associated to bin number bin.
Definition: TH1.cxx:8565
TRatioPlot::Browse
virtual void Browse(TBrowser *b)
Browse.
Definition: TRatioPlot.cxx:422
TRatioPlot::SetLowTopMargin
void SetLowTopMargin(Float_t margin)
Sets the top margin of the lower pad.
Definition: TRatioPlot.cxx:455
TH1::GetBinError
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition: TH1.cxx:8518
TRatioPlot::fLeftMargin
Float_t fLeftMargin
Stores the common left margin of both pads.
Definition: TRatioPlot.h:134
TH1::GetBinWidth
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width for 1D histogram.
Definition: TH1.cxx:8618
TRatioPlot::fHideLabelMode
Int_t fHideLabelMode
Stores which label to hide if the margin is to narrow, if at all.
Definition: TRatioPlot.h:125
TBrowser.h
TAxis::GetBinUpEdge
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition: TAxis.cxx:528
TObject::AppendPad
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:107
TString::Contains
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
TRatioPlot::fC1
Double_t fC1
Stores the scale factor for h1 (or THStack sum)
Definition: TRatioPlot.h:104
TAxis::kCenterTitle
@ kCenterTitle
Definition: TAxis.h:62
TPad.h
TGaxis::SetLabelOffset
void SetLabelOffset(Float_t labeloffset)
Definition: TGaxis.h:106
x
Double_t x[n]
Definition: legend1.C:17
TAttAxis::GetAxisColor
virtual Color_t GetAxisColor() const
Definition: TAttAxis.h:43
TPad::SetFillStyle
virtual void SetFillStyle(Style_t fstyle)
Override TAttFill::FillStyle for TPad because we want to handle style=0 as style 4000.
Definition: TPad.cxx:5879
TPad::SetGridy
virtual void SetGridy(Int_t value=1)
Definition: TPad.h:329
TVirtualPad::GetTicky
virtual Int_t GetTicky() const =0
TRatioPlot::TRatioPlot
TRatioPlot()
TRatioPlot default constructor.
Definition: TRatioPlot.cxx:102
TRatioPlot::fRightMargin
Float_t fRightMargin
Stores the common right margin of both pads.
Definition: TRatioPlot.h:135
TH1::GetListOfFunctions
TList * GetListOfFunctions() const
Definition: TH1.h:240
TH1::Add
virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="")
Performs the operation: this = this + c1*f1 if errors are defined (see TH1::Sumw2),...
Definition: TH1.cxx:777
TRatioPlot::Init
virtual void Init(TH1 *h1, TH1 *h2, Option_t *option="")
Internal method that shares constructor logic.
Definition: TRatioPlot.cxx:139
TAttPad::GetTopMargin
Float_t GetTopMargin() const
Definition: TAttPad.h:52
TRatioPlot::BuildLowerPlot
Int_t BuildLowerPlot()
Build the lower plot according to which constructor was called, and which options were passed.
Definition: TRatioPlot.cxx:859
TRatioPlot::SetUpTopMargin
void SetUpTopMargin(Float_t margin)
Sets the top margin of the upper pad.
Definition: TRatioPlot.cxx:433
TString
Definition: TString.h:136
TAttAxis::GetLabelOffset
virtual Float_t GetLabelOffset() const
Definition: TAttAxis.h:46
TVirtualFitter.h
TGraph::GetYaxis
TAxis * GetYaxis() const
Get y axis of the graph.
Definition: TGraph.cxx:1636
Color_t
short Color_t
Definition: RtypesCore.h:83
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
TRatioPlot::CreateGridline
void CreateGridline()
Create a grid line.
Definition: TRatioPlot.cxx:756
b
#define b(i)
Definition: RSha256.hxx:118
TString.h
h1
TH1F * h1
Definition: legend1.C:5
TRatioPlot::fH1
TH1 * fH1
Stores the primary histogram.
Definition: TRatioPlot.h:79
TRatioPlot::SetPadMargins
void SetPadMargins()
Sets the margins of all the pads to the value specified in class members.
Definition: TRatioPlot.cxx:1379
bool
TString::ReplaceAll
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
TPad::GetUymax
Double_t GetUymax() const
Returns the maximum y-coordinate value visible on the pad. If log axis the returned value is in decad...
Definition: TPad.h:228
TRatioPlot::GetUpperRefYaxis
TAxis * GetUpperRefYaxis() const
Gets the y axis of the object returned by TRatioPlot::GetUpperRefObject.
Definition: TRatioPlot.cxx:738
TAxis::GetTitle
const char * GetTitle() const
Returns title of object.
Definition: TAxis.h:129
TGaxis::SetTickSize
void SetTickSize(Float_t ticksize)
Definition: TGaxis.h:118
TRatioPlot::fConfidenceInterval1
TGraphErrors * fConfidenceInterval1
Stores the graph for the 1 sigma band.
Definition: TRatioPlot.h:94
TRatioPlot::fLowerGYaxisMirror
TGaxis * fLowerGYaxisMirror
Lower mirror of the y axis.
Definition: TRatioPlot.h:117
TROOT.h
TGaxis::SetNdivisions
virtual void SetNdivisions(Int_t ndiv)
Definition: TGaxis.h:114
TVirtualPad::GetGridy
virtual Bool_t GetGridy() const =0
TH1::Clone
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
Definition: TH1.cxx:2664
TPad::Modified
void Modified(Bool_t flag=1)
Definition: TPad.h:414
TRatioPlot::SetUpBottomMargin
void SetUpBottomMargin(Float_t margin)
Sets the bottom margin of the upper pad.
Definition: TRatioPlot.cxx:444
TGaxis::ChangeLabel
void ChangeLabel(Int_t labNum=0, Double_t labAngle=-1., Double_t labSize=-1., Int_t labAlign=-1, Int_t labColor=-1, Int_t labFont=-1, TString labText="")
Define new text attributes for the label number "labNum".
Definition: TGaxis.cxx:2559
TAxis::kCenterLabels
@ kCenterLabels
Definition: TAxis.h:63
TRatioPlot::fLowBottomMargin
Float_t fLowBottomMargin
Stores the bottom margin of the lower pad.
Definition: TRatioPlot.h:132
THStack::GetHists
TList * GetHists() const
Definition: THStack.h:67
TList::At
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:356
ROOT::Fit::GetConfidenceIntervals
bool GetConfidenceIntervals(const TH1 *h1, const ROOT::Fit::FitResult &r, TGraphErrors *gr, double cl=0.95)
compute confidence intervals at level cl for a fitted histogram h1 in a TGraphErrors gr
Definition: HFitInterface.cxx:972
TRatioPlot::fHistDrawProxy
TObject * fHistDrawProxy
The object which is actually drawn, this might be TH1 or THStack.
Definition: TRatioPlot.h:81
TRatioPlot::fUpYaxis
TAxis * fUpYaxis
Clone of the upper y axis.
Definition: TRatioPlot.h:119
TAxis::kTickMinus
@ kTickMinus
Definition: TAxis.h:60
TGraphAsymmErrors::Divide
virtual void Divide(const TH1 *pass, const TH1 *total, Option_t *opt="cp")
Fill this TGraphAsymmErrors by dividing two 1-dimensional histograms pass/total.
Definition: TGraphAsymmErrors.cxx:581
TAxis::kMoreLogLabels
@ kMoreLogLabels
Definition: TAxis.h:72
TPad::SetLogy
virtual void SetLogy(Int_t value=1)
Set Lin/Log scale for Y.
Definition: TPad.cxx:5905
TAxis::SetRange
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition: TAxis.cxx:920
TRatioPlot::GetLowerRefYaxis
TAxis * GetLowerRefYaxis() const
Shortcut for:
Definition: TRatioPlot.h:207
TRatioPlot::fIsUpdating
Bool_t fIsUpdating
Keeps track of whether its currently updating to reject other calls until done.
Definition: TRatioPlot.h:139
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TPad::SetGridx
virtual void SetGridx(Int_t value=1)
Definition: TPad.h:328
TH1::GetBinContent
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4906
TList::FirstLink
virtual TObjLink * FirstLink() const
Definition: TList.h:108
TAttPad::SetBottomMargin
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition: TAttPad.cxx:99
TPad::GetUymin
Double_t GetUymin() const
Returns the minimum y-coordinate value visible on the pad. If log axis the returned value is in decad...
Definition: TPad.h:224
TH1::GetYaxis
TAxis * GetYaxis()
Definition: TH1.h:318
TRatioPlot::fLowYaxis
TAxis * fLowYaxis
Clone of the lower y axis.
Definition: TRatioPlot.h:120
TRatioPlot::fCi2Color
Color_t fCi2Color
Stores the color for the 2 sigma band.
Definition: TRatioPlot.h:97
TLine::SetX2
virtual void SetX2(Double_t x2)
Definition: TLine.h:66
TAttAxis::GetTitleColor
virtual Color_t GetTitleColor() const
Definition: TAttAxis.h:52
h
#define h(i)
Definition: RSha256.hxx:124
TRatioPlot::fInsetWidth
Float_t fInsetWidth
Definition: TRatioPlot.h:137
TAttAxis::GetTickLength
virtual Float_t GetTickLength() const
Definition: TAttAxis.h:51
TObject::SetBit
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
TRatioPlot::GetLowerRefGraph
virtual TGraph * GetLowerRefGraph() const
Returns the reference graph for the lower pad, which means the graph that is responsible for setting ...
Definition: TRatioPlot.cxx:668
TRatioPlot::SetLowBottomMargin
void SetLowBottomMargin(Float_t margin)
Sets the bottom margin of the lower pad.
Definition: TRatioPlot.cxx:466
TAttAxis::GetLabelColor
virtual Color_t GetLabelColor() const
Definition: TAttAxis.h:44
TRatioPlot::SetInsetWidth
void SetInsetWidth(Double_t width)
Set the inset on the outer sides of all the pads.
Definition: TRatioPlot.cxx:1635
TRatioPlot::Draw
virtual void Draw(Option_t *chopt="")
Draws the ratio plot to the currently active pad.
Definition: TRatioPlot.cxx:539
TGaxis::SetOption
void SetOption(Option_t *option="")
To set axis options.
Definition: TGaxis.cxx:2686
TRatioPlot::SetSplitFraction
void SetSplitFraction(Float_t sf)
Set the fraction of the parent pad, at which the to sub pads should meet.
Definition: TRatioPlot.cxx:1614
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
TVirtualPad::SetLogx
virtual void SetLogx(Int_t value=1)=0
TRatioPlot::fIsPadUpdating
Bool_t fIsPadUpdating
Keeps track whether pads are updating during resizing.
Definition: TRatioPlot.h:140
TH1::GetBinCenter
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
Definition: TH1.cxx:8596
TNamed::Clone
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:74
TRatioPlot::GetUpperRefObject
virtual TObject * GetUpperRefObject() const
Return the reference object.
Definition: TRatioPlot.cxx:702
TVirtualPad::GetListOfPrimitives
virtual TList * GetListOfPrimitives() const =0
TAxis::kTickPlus
@ kTickPlus
Definition: TAxis.h:59
TLine::SetX1
virtual void SetX1(Double_t x1)
Definition: TLine.h:65
TMath::Power
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition: TMath.h:735
TRatioPlot::SetH1DrawOpt
void SetH1DrawOpt(Option_t *opt)
Sets the drawing option for h1.
Definition: TRatioPlot.cxx:333
THStack.h
TObject::Clone
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:146
TLine::SetY1
virtual void SetY1(Double_t y1)
Definition: TLine.h:67
TAxis::GetLast
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:469
TPad::SetPad
virtual void SetPad(const char *name, const char *title, Double_t xlow, Double_t ylow, Double_t xup, Double_t yup, Color_t color=35, Short_t bordersize=5, Short_t bordermode=-1)
Set all pad parameters.
Definition: TPad.cxx:5958
TGaxis::SetLabelFont
void SetLabelFont(Int_t labelfont)
Definition: TGaxis.h:105
TRatioPlot.h
TRatioPlot::fTopPad
TPad * fTopPad
The Pad that drawn on top on the others to have consistent coordinates.
Definition: TRatioPlot.h:77
TAxis::GetTimeFormat
virtual const char * GetTimeFormat() const
Definition: TAxis.h:127
TVirtualPad::GetWNDC
virtual Double_t GetWNDC() const =0
TGaxis::SetLabelSize
void SetLabelSize(Float_t labelsize)
Definition: TGaxis.h:107
y
Double_t y[n]
Definition: legend1.C:17
TRatioPlot::fCl1
Double_t fCl1
Stores the confidence level for the inner confidence interval band.
Definition: TRatioPlot.h:101
sqrt
double sqrt(double)
TRatioPlot::fGraphDrawOpt
TString fGraphDrawOpt
Stores draw option for the lower plot graph given in constructor.
Definition: TRatioPlot.h:88
TPad::GetListOfPrimitives
TList * GetListOfPrimitives() const
Definition: TPad.h:239
TAttPad::GetLeftMargin
Float_t GetLeftMargin() const
Definition: TAttPad.h:50
TGraphAsymmErrors
Definition: TGraphAsymmErrors.h:26
line
TLine * line
Definition: entrylistblock_figure1.C:235
TObject::Warning
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:876
TRatioPlot::fLowerGYaxis
TGaxis * fLowerGYaxis
Lower graphical y axis.
Definition: TRatioPlot.h:113
TGaxis::SetLabelColor
void SetLabelColor(Int_t labelcolor)
Definition: TGaxis.h:104
TRatioPlot::fUpperPad
TPad * fUpperPad
The pad which contains the upper plot part.
Definition: TRatioPlot.h:75
TRatioPlot::GetLowerRefXaxis
TAxis * GetLowerRefXaxis() const
Shortcut for:
Definition: TRatioPlot.h:198
TGraph::SetPoint
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition: TGraph.cxx:2269
TGaxis::SetTitle
virtual void SetTitle(const char *title="")
Change the title of the axis.
Definition: TGaxis.cxx:2694
TGaxis.h
TAttPad::SetLeftMargin
virtual void SetLeftMargin(Float_t leftmargin)
Set Pad left margin in fraction of the pad width.
Definition: TAttPad.cxx:109
TRatioPlot::fLowerGXaxisMirror
TGaxis * fLowerGXaxisMirror
Lower mirror of the x axis.
Definition: TRatioPlot.h:115
TRatioPlot::fFitDrawOpt
TString fFitDrawOpt
Stores draw option for the fit function in the fit residual case.
Definition: TRatioPlot.h:89
TGraphErrors::SetPointError
virtual void SetPointError(Double_t ex, Double_t ey)
Set ex and ey values for point pointed by the mouse.
Definition: TGraphErrors.cxx:792
TRatioPlot::fCl2
Double_t fCl2
Stores the confidence level for the outer confidence interval band.
Definition: TRatioPlot.h:102
TAttPad::GetRightMargin
Float_t GetRightMargin() const
Definition: TAttPad.h:51
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:197
Double_t
double Double_t
Definition: RtypesCore.h:59
TRatioPlot::SetGridlines
virtual void SetGridlines(Double_t *gridlines, Int_t numGridlines)
Set where horizontal, dashed lines are drawn on the lower pad.
Definition: TRatioPlot.cxx:1685
TQObject::Connect
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:864
TGraph
Definition: TGraph.h:41
TVirtualPad
Definition: TVirtualPad.h:50
TAttPad::SetRightMargin
virtual void SetRightMargin(Float_t rightmargin)
Set Pad right margin in fraction of the pad width.
Definition: TAttPad.cxx:119
TGraphErrors
Definition: TGraphErrors.h:26
TObject::kNotDeleted
@ kNotDeleted
object has not been deleted
Definition: TObject.h:78
TF1.h
TRatioPlot::GetSeparationMargin
Float_t GetSeparationMargin() const
Return the separation margin value.
Definition: TRatioPlot.cxx:514
TRatioPlot::IsDrawn
Bool_t IsDrawn()
Check if ... is drawn.
Definition: TRatioPlot.cxx:1605
TRatioPlot::RangeAxisChanged
void RangeAxisChanged()
Slot that receives the RangeAxisChanged signal from any of the pads and reacts correspondingly.
Definition: TRatioPlot.cxx:1465
TF1::Eval
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Evaluate this function.
Definition: TF1.cxx:1450
TCollection::GetSize
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TGaxis
Definition: TGaxis.h:23
TGaxis::GetTickSize
Float_t GetTickSize() const
Definition: TGaxis.h:91
TRatioPlot::fH2
TH1 * fH2
Stores the secondary histogram, if there is one.
Definition: TRatioPlot.h:80
TF1::Draw
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1338
TPad::cd
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:594
TRatioPlot::fParentPad
TVirtualPad * fParentPad
Stores the pad the ratio plot was created in.
Definition: TRatioPlot.h:74
TRatioPlot::fUpperGYaxisMirror
TGaxis * fUpperGYaxisMirror
Upper mirror of the y axis.
Definition: TRatioPlot.h:116
TAttAxis::GetTitleFont
virtual Style_t GetTitleFont() const
Definition: TAttAxis.h:53
TGraphAsymmErrors.h
TObject
Definition: TObject.h:37
TH1::Reset
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
Definition: TH1.cxx:6735
TH1
Definition: TH1.h:57
TRatioPlot::fRatioGraph
TGraph * fRatioGraph
Stores the lower plot's graph.
Definition: TRatioPlot.h:93
TVirtualPad::Modified
virtual void Modified(Bool_t flag=1)=0
c2
return c2
Definition: legend2.C:14
TRatioPlot::fShowGridlines
Bool_t fShowGridlines
Stores whether to show the gridlines at all.
Definition: TRatioPlot.h:124
TAxis::kRotateTitle
@ kRotateTitle
Definition: TAxis.h:64
gPad
#define gPad
Definition: TVirtualPad.h:287
TRatioPlot::fSplitFraction
Float_t fSplitFraction
Stores the fraction at which the upper and lower pads meet.
Definition: TRatioPlot.h:91
TRatioPlot::fUpperGXaxis
TGaxis * fUpperGXaxis
Upper graphical x axis.
Definition: TRatioPlot.h:110
TRatioPlot::fLowTopMargin
Float_t fLowTopMargin
Stores the top margin of the lower pad.
Definition: TRatioPlot.h:131
TRatioPlot::SetConfidenceLevels
void SetConfidenceLevels(Double_t cl1, Double_t cl2)
Sets the confidence levels used to calculate the bands in the fit residual case.
Definition: TRatioPlot.cxx:1656
TRatioPlot::SetLeftMargin
void SetLeftMargin(Float_t margin)
Sets the left margin of both pads.
Definition: TRatioPlot.cxx:476
TPad::GetHNDC
Double_t GetHNDC() const
Get height of pad along Y in Normalized Coordinates (NDC)
Definition: TPad.h:211
TAttAxis::GetLabelFont
virtual Style_t GetLabelFont() const
Definition: TAttAxis.h:45
TPad::GetLogx
Int_t GetLogx() const
Definition: TPad.h:250
TPad::GetLogy
Int_t GetLogy() const
Definition: TPad.h:251
TGraphErrors.h
TVirtualFitter::GetFitter
static TVirtualFitter * GetFitter()
static: return the current Fitter
Definition: TVirtualFitter.cxx:209
TPad::SetLogx
virtual void SetLogx(Int_t value=1)
Set Lin/Log scale for X.
Definition: TPad.cxx:5891
TRatioPlot::CreateVisualAxes
virtual void CreateVisualAxes()
(Re-)Creates the TGAxis objects that are used for consistent display of the axes.
Definition: TRatioPlot.cxx:1104
TF1
1-Dim function class
Definition: TF1.h:212
TRatioPlot::SyncAxesRanges
virtual void SyncAxesRanges()
Syncs the axes ranges from the shared ones to the actual ones.
Definition: TRatioPlot.cxx:839
TVirtualPad::GetTickx
virtual Int_t GetTickx() const =0
Class
void Class()
Definition: Class.C:29
TH1::GetXaxis
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:317
TRatioPlot::fGridlines
std::vector< TLine * > fGridlines
Keeps TLine objects for the gridlines.
Definition: TRatioPlot.h:122
TGaxis::SetTimeFormat
void SetTimeFormat(const char *tformat)
Change the format used for time plotting.
Definition: TGaxis.cxx:2721
TRatioPlot::fLowerGXaxis
TGaxis * fLowerGXaxis
Lower graphical x axis.
Definition: TRatioPlot.h:111
TH1.h
TRatioPlot::fH2DrawOpt
TString fH2DrawOpt
Stores draw option for h2 given in constructor.
Definition: TRatioPlot.h:87
TRatioPlot::fFitResult
TFitResult * fFitResult
Stores the explicit fit result given in the fit residual case. Can be 0.
Definition: TRatioPlot.h:107
TRatioPlot::fLowerPad
TPad * fLowerPad
The pad which contains the calculated lower plot part.
Definition: TRatioPlot.h:76
TGaxis::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TGaxis.h:86
TH1::Scale
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition: TH1.cxx:6245
TAttAxis::GetNdivisions
virtual Int_t GetNdivisions() const
Definition: TAttAxis.h:42
TAttAxis::GetTitleSize
virtual Float_t GetTitleSize() const
Definition: TAttAxis.h:50
TRatioPlot::fErrorMode
Int_t fErrorMode
Stores the error mode, sym, asym or func.
Definition: TRatioPlot.h:84
TList
Definition: TList.h:44
TRatioPlot::fGridlinePositions
std::vector< double > fGridlinePositions
Stores the y positions for the gridlines.
Definition: TRatioPlot.h:123
TMath.h
TH1::GetNbinsX
virtual Int_t GetNbinsX() const
Definition: TH1.h:293
TAxis::kDecimals
@ kDecimals
Definition: TAxis.h:58
TAttPad::GetFrameFillStyle
Style_t GetFrameFillStyle() const
Definition: TAttPad.h:61
gROOT
#define gROOT
Definition: TROOT.h:406
int
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997
c1
return c1
Definition: legend1.C:41
TPad::Draw
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1285
ROOT::Fit::FitResult::GetConfidenceIntervals
void GetConfidenceIntervals(unsigned int n, unsigned int stride1, unsigned int stride2, const double *x, double *ci, double cl=0.95, bool norm=false) const
get confidence intervals for an array of n points x.
Definition: FitResult.cxx:555
TAttAxis::GetTitleOffset
virtual Float_t GetTitleOffset() const
Definition: TAttAxis.h:49