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