Logo ROOT   6.10/09
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[fH1->GetNbinsX()];
1001  std::fill_n(x_arr, fH1->GetNbinsX(), 0);
1002  Double_t ci_arr1[fH1->GetNbinsX()];
1003  std::fill_n(ci_arr1, fH1->GetNbinsX(), 0);
1004  Double_t ci_arr2[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 
1087  } else if (fMode == TRatioPlot::CalculationMode::kDivideHist){
1088  SetGridlines(divideGridlines, 3);
1089 
1090  // Use TH1's Divide method
1091  TH1 *tmpHist = (TH1*)fH1->Clone();
1092  tmpHist->Reset();
1093 
1094  tmpHist->Divide(fH1, fH2, fC1, fC2, fOption.Data());
1095  fRatioGraph = new TGraphErrors(tmpHist);
1096 
1097  delete tmpHist;
1098  } else {
1099  // this should not occur
1100  Error("BuildLowerPlot", "Invalid fMode value");
1101  return 0;
1102  }
1103 
1104  // need to set back to "" since recreation. we don't ever want
1105  // title on lower graph
1106 
1107  if (fRatioGraph == 0) {
1108  Error("BuildLowerPlot", "Error creating lower graph");
1109  return 0;
1110  }
1111 
1112  fRatioGraph->SetTitle("");
1115 
1116  return 1;
1117 }
1118 
1119 ////////////////////////////////////////////////////////////////////////////////
1120 /// (Re-)Creates the TGAxis objects that are used for consistent display of the
1121 /// axes.
1122 
1124 {
1125  TVirtualPad *padsav = gPad;
1126  fTopPad->cd();
1128  // this is for errors
1129  TString thisfunc = "CreateVisualAxes";
1130 
1131  // figure out where the axis has to go.
1132  // Implicit assumption is, that the top pad spans the full other pads
1133  Double_t upTM = fUpperPad->GetTopMargin();
1135  Double_t upLM = fUpperPad->GetLeftMargin();
1136  Double_t upRM = fUpperPad->GetRightMargin();
1137 
1138  Double_t lowTM = fLowerPad->GetTopMargin();
1139  Double_t lowBM = fLowerPad->GetBottomMargin();
1140  Double_t lowLM = fLowerPad->GetLeftMargin();
1141  Double_t lowRM = fLowerPad->GetRightMargin();
1142 
1145 
1146  Double_t upYFirst = fUpperPad->GetUymin();
1147  Double_t upYLast = fUpperPad->GetUymax();
1148  Double_t lowYFirst = fLowerPad->GetUymin();
1149  Double_t lowYLast = fLowerPad->GetUymax();
1150 
1151  Float_t sf = fSplitFraction;
1152 
1153  // check if gPad has the all sides axis set
1154  Bool_t mirroredAxes = fParentPad->GetFrameFillStyle() == 0;
1155  Bool_t axistop = fParentPad->GetTickx() == 1 || mirroredAxes;
1156  Bool_t axisright = fParentPad->GetTicky() == 1 || mirroredAxes;
1157 
1158  Bool_t logx = fUpperPad->GetLogx() || fLowerPad->GetLogx();
1159  Bool_t uplogy = fUpperPad->GetLogy();
1160  Bool_t lowlogy = fLowerPad->GetLogy();
1161 
1162  if (uplogy) {
1163 
1164  upYFirst = TMath::Power(10, upYFirst);
1165  upYLast = TMath::Power(10, upYLast);
1166 
1167  if (upYFirst <= 0 || upYLast <= 0) {
1168  Error(thisfunc, "Cannot set upper Y axis to log scale");
1169  }
1170  }
1171 
1172  if (lowlogy) {
1173  lowYFirst = TMath::Power(10, lowYFirst);
1174  lowYLast = TMath::Power(10, lowYLast);
1175 
1176  if (lowYFirst <= 0 || lowYLast <= 0) {
1177  Error(thisfunc, "Cannot set lower Y axis to log scale");
1178  }
1179 
1180  }
1181 
1182  // this is different than in y, y already has pad coords converted, x not...
1183  if (logx) {
1184  if (first <= 0 || last <= 0) {
1185  Error(thisfunc, "Cannot set X axis to log scale");
1186  }
1187  }
1188 
1189  // determine axes options to create log axes if needed
1190  TString xopt = "";
1191  if (logx) xopt.Append("G");
1192  TString upyopt = "";
1193  if (uplogy) upyopt.Append("G");
1194  TString lowyopt = "";
1195  if (lowlogy) lowyopt.Append("G");
1196 
1197  // only actually create them once, reuse otherwise b/c memory
1198  if (fUpperGXaxis == 0) {
1199  fUpperGXaxis = new TGaxis(0, 0, 1, 1, 0, 1, 510, "+U"+xopt);
1200  fUpperGXaxis->Draw();
1201  }
1202 
1203  if (fUpperGYaxis == 0) {
1204  fUpperGYaxis = new TGaxis(0, 0, 1, 1, upYFirst, upYLast, 510, "S"+upyopt);
1205  fUpperGYaxis->Draw();
1206  }
1207 
1208  if (fLowerGXaxis == 0) {
1209  fLowerGXaxis = new TGaxis(0, 0, 1, 1, first, last, 510, "+S"+xopt);
1210  fLowerGXaxis->Draw();
1211  }
1212 
1213  if (fLowerGYaxis == 0) {
1214  fLowerGYaxis = new TGaxis(0, 0, 1, 1, lowYFirst, lowYLast, 510, "-S"+lowyopt);
1215  fLowerGYaxis->Draw();
1216  }
1217 
1218  // import infos from TAxis
1223 
1224  // lower x axis needs to get title from upper x
1226 
1227  // (re)set all the axes properties to what we want them
1228  fUpperGXaxis->SetTitle("");
1229 
1230  fUpperGXaxis->SetX1(upLM);
1231  fUpperGXaxis->SetX2(1-upRM);
1232  fUpperGXaxis->SetY1(upBM*(1-sf)+sf);
1233  fUpperGXaxis->SetY2(upBM*(1-sf)+sf);
1234  fUpperGXaxis->SetWmin(first);
1235  fUpperGXaxis->SetWmax(last);
1236 
1237  fUpperGYaxis->SetX1(upLM);
1238  fUpperGYaxis->SetX2(upLM);
1239  fUpperGYaxis->SetY1(upBM*(1-sf)+sf);
1240  fUpperGYaxis->SetY2( (1-upTM)*(1-sf)+sf );
1241  fUpperGYaxis->SetWmin(upYFirst);
1242  fUpperGYaxis->SetWmax(upYLast);
1243 
1244  fLowerGXaxis->SetX1(lowLM);
1245  fLowerGXaxis->SetX2(1-lowRM);
1246  fLowerGXaxis->SetY1(lowBM*sf);
1247  fLowerGXaxis->SetY2(lowBM*sf);
1248  fLowerGXaxis->SetWmin(first);
1249  fLowerGXaxis->SetWmax(last);
1250 
1251  fLowerGYaxis->SetX1(lowLM);
1252  fLowerGYaxis->SetX2(lowLM);
1253  fLowerGYaxis->SetY1(lowBM*sf);
1254  fLowerGYaxis->SetY2((1-lowTM)*sf);
1255  fLowerGYaxis->SetWmin(lowYFirst);
1256  fLowerGYaxis->SetWmax(lowYLast);
1257 
1262 
1263  fUpperGXaxis->SetOption("+U"+xopt);
1264  fUpperGYaxis->SetOption("S"+upyopt);
1265  fLowerGXaxis->SetOption("+S"+xopt);
1266  fLowerGYaxis->SetOption("-S"+lowyopt);
1267 
1268  // normalize the tick sizes. y axis ticks should be consistent
1269  // even if their length is different
1270  Double_t ratio = ( (upBM-(1-upTM))*(1-sf) ) / ( (lowBM-(1-lowTM))*sf ) ;
1272  Double_t ticksize = fUpperGYaxis->GetTickSize()*ratio;
1273  fLowerGYaxis->SetTickSize(ticksize);
1274 
1275  if (fHideLabelMode == TRatioPlot::HideLabelMode::kForceHideUp) {
1276 
1277  fUpperGYaxis->ChangeLabel(1, -1, 0);
1278 
1279  } else if (fHideLabelMode == TRatioPlot::HideLabelMode::kForceHideLow) {
1280 
1281  fLowerGYaxis->ChangeLabel(-1, -1, 0);
1282 
1283  } else {
1284  if (GetSeparationMargin() < 0.025) {
1285 
1286  if (fHideLabelMode != TRatioPlot::HideLabelMode::kNoHide) {
1287  if (fHideLabelMode == TRatioPlot::HideLabelMode::kHideUp) {
1288  fUpperGYaxis->ChangeLabel(1, -1, 0);
1289  } else if (fHideLabelMode == TRatioPlot::HideLabelMode::kHideLow) {
1290  fLowerGYaxis->ChangeLabel(-1, -1, 0);
1291  }
1292  }
1293 
1294  } else {
1295  // reset
1296  if (fHideLabelMode == TRatioPlot::HideLabelMode::kHideUp) {
1298  } else if (fHideLabelMode == TRatioPlot::HideLabelMode::kHideLow) {
1300  }
1301 
1302  }
1303  }
1304 
1305  // Create the axes on the other sides of the graphs
1306  // This is steered by an option on the containing pad or self
1307  if (axistop || axisright) {
1308 
1309  // only actually create them once, reuse otherwise b/c memory
1310  if (fUpperGXaxisMirror == 0) {
1312  if (axistop) fUpperGXaxisMirror->Draw();
1313  }
1314 
1315  if (fLowerGXaxisMirror == 0) {
1317  if (axistop) fLowerGXaxisMirror->Draw();
1318  }
1319 
1320  if (fUpperGYaxisMirror == 0) {
1322  if (axisright) fUpperGYaxisMirror->Draw();
1323  }
1324 
1325  if (fLowerGYaxisMirror == 0) {
1327  if (axisright) fLowerGYaxisMirror->Draw();
1328  }
1329 
1330  // import attributes from shared axes
1335 
1336  // remove titles
1341 
1342  // move them about and set required positions
1343  fUpperGXaxisMirror->SetX1(upLM);
1344  fUpperGXaxisMirror->SetX2(1-upRM);
1345  fUpperGXaxisMirror->SetY1((1-upTM)*(1-sf)+sf);
1346  fUpperGXaxisMirror->SetY2((1-upTM)*(1-sf)+sf);
1347  fUpperGXaxisMirror->SetWmin(first);
1348  fUpperGXaxisMirror->SetWmax(last);
1349 
1350  fUpperGYaxisMirror->SetX1(1-upRM);
1351  fUpperGYaxisMirror->SetX2(1-upRM);
1352  fUpperGYaxisMirror->SetY1(upBM*(1-sf)+sf);
1353  fUpperGYaxisMirror->SetY2( (1-upTM)*(1-sf)+sf );
1354  fUpperGYaxisMirror->SetWmin(upYFirst);
1355  fUpperGYaxisMirror->SetWmax(upYLast);
1356 
1357  fLowerGXaxisMirror->SetX1(lowLM);
1358  fLowerGXaxisMirror->SetX2(1-lowRM);
1359  fLowerGXaxisMirror->SetY1((1-lowTM)*sf);
1360  fLowerGXaxisMirror->SetY2((1-lowTM)*sf);
1361  fLowerGXaxisMirror->SetWmin(first);
1362  fLowerGXaxisMirror->SetWmax(last);
1363 
1364  fLowerGYaxisMirror->SetX1(1-lowRM);
1365  fLowerGYaxisMirror->SetX2(1-lowRM);
1366  fLowerGYaxisMirror->SetY1(lowBM*sf);
1367  fLowerGYaxisMirror->SetY2((1-lowTM)*sf);
1368  fLowerGYaxisMirror->SetWmin(lowYFirst);
1369  fLowerGYaxisMirror->SetWmax(lowYLast);
1370 
1371  // also needs normalized tick size
1372  fLowerGYaxisMirror->SetTickSize(ticksize);
1373 
1374  fUpperGXaxisMirror->SetOption("-S"+xopt);
1375  fUpperGYaxisMirror->SetOption("+S"+upyopt);
1376  fLowerGXaxisMirror->SetOption("-S"+xopt);
1377  fLowerGYaxisMirror->SetOption("+S"+lowyopt);
1378 
1383 
1388  }
1389 
1390  padsav->cd();
1391 
1392 }
1393 
1394 ////////////////////////////////////////////////////////////////////////////////
1395 /// Sets the margins of all the pads to the value specified in class members.
1396 /// This one is called whenever those are changed, e.g. in setters
1397 
1399 {
1408 }
1409 
1410 ////////////////////////////////////////////////////////////////////////////////
1411 /// Figures out which pad margin has deviated from the stored ones,
1412 /// to figure out what the new nominal is and set the other pad to it
1413 /// subsequently.
1414 
1416 {
1417 
1418  Bool_t changed = kFALSE;
1420  if (fUpperPad->GetLeftMargin() != fLeftMargin) {
1422  changed = kTRUE;
1423  }
1424  else if (fLowerPad->GetLeftMargin() != fLeftMargin) {
1426  changed = kTRUE;
1427  }
1428 
1431  changed = kTRUE;
1432  }
1433  else if (fLowerPad->GetRightMargin() != fRightMargin) {
1435  changed = kTRUE;
1436  }
1437 
1438  // only reset margins, if any of the margins changed
1439  if (changed) {
1440  SetPadMargins();
1441  }
1442 
1443  Bool_t verticalChanged = kFALSE;
1444 
1446 
1447  verticalChanged = kTRUE;
1449 
1450  }
1451 
1452  if (fLowerPad->GetTopMargin() != fLowTopMargin) {
1453 
1454  verticalChanged = kTRUE;
1456 
1457  }
1458 
1460 
1462 
1463  }
1464 
1465  if (fUpperPad->GetTopMargin() != fUpTopMargin) {
1466 
1468 
1469  }
1470 
1471  // only reset margins, if any of the margins changed
1472  if (verticalChanged) {
1473  SetPadMargins();
1474  }
1475 
1476  return changed || verticalChanged;
1477 
1478 }
1479 
1480 ////////////////////////////////////////////////////////////////////////////////
1481 /// Slot that receives the RangeAxisChanged signal from any of the pads and
1482 /// reacts correspondingly.
1483 
1485 {
1486  // check if the ratio plot is already drawn.
1487  if (!IsDrawn()) {
1488  // not drawn yet
1489  return;
1490  }
1491 
1492  // Only run this concurrently once, in case it's called async
1493  if (fIsUpdating) {
1494  return;
1495  }
1496 
1497  fIsUpdating = kTRUE;
1498 
1499  // find out if logx has changed
1500  if (fParentPad->GetLogx()) {
1501  if (!fUpperPad->GetLogx() || !fLowerPad->GetLogx()) {
1503  }
1504  } else {
1505  if (fUpperPad->GetLogx() || fLowerPad->GetLogx()) {
1507  }
1508  }
1509 
1510  // set log to pad
1513 
1514  // get axis ranges for upper and lower
1515  TAxis *uprefx = GetUpperRefXaxis();
1516  Double_t upFirst = uprefx->GetBinLowEdge(uprefx->GetFirst());
1517  Double_t upLast = uprefx->GetBinUpEdge(uprefx->GetLast());
1518 
1519  TAxis *lowrefx = GetLowerRefXaxis();
1520  Double_t lowFirst = lowrefx->GetBinLowEdge(lowrefx->GetFirst());
1521  Double_t lowLast = lowrefx->GetBinUpEdge(lowrefx->GetLast());
1522 
1525 
1526  Bool_t upChanged = kFALSE;
1527  Bool_t lowChanged = kFALSE;
1528 
1529  // determine which one has changed
1530  if (upFirst != globFirst || upLast != globLast) {
1531  fSharedXAxis->SetRangeUser(upFirst, upLast);
1532  upChanged = kTRUE;
1533  }
1534  else if (lowFirst != globFirst || lowLast != globLast) {
1535  fSharedXAxis->SetRangeUser(lowFirst, lowLast);
1536  lowChanged = kTRUE;
1537  }
1538 
1539  if (upChanged || lowChanged) {
1540  SyncAxesRanges();
1541  CreateVisualAxes();
1542  CreateGridline();
1543 
1544  // @TODO: Updating is not working when zooming on the lower plot. Axes update, but upper hist only on resize
1545  fUpperPad->Modified();
1546  fLowerPad->Modified();
1547  fTopPad->Modified();
1548  fParentPad->Modified();
1549  }
1550 
1551  // sync the margins in case the user has dragged one of them
1552  Bool_t marginsChanged = SyncPadMargins();
1553 
1554  if (marginsChanged) {
1555  fUpperPad->Modified();
1556  fLowerPad->Modified();
1557  fTopPad->Modified();
1558  fParentPad->Modified();
1559  }
1560 
1561  CreateVisualAxes();
1562  CreateGridline();
1563  fIsUpdating = kFALSE;
1564 }
1565 
1566 ////////////////////////////////////////////////////////////////////////////////
1567 /// Slot for the UnZoomed signal that was introduced to TAxis.
1568 /// Unzoom both pads
1569 
1570 void TRatioPlot::UnZoomed()
1571 {
1572  // this is what resets the range
1573  fSharedXAxis->SetRange(0, 0);
1575 
1576  // Flushing
1577  fUpperPad->Modified();
1578  fLowerPad->Modified();
1579  fTopPad->Modified();
1580  fParentPad->Modified();
1581 }
1582 
1583 ////////////////////////////////////////////////////////////////////////////////
1584 /// Slot that handles common resizing of upper and lower pad.
1585 
1587 {
1588 
1589  if (fIsPadUpdating) {
1590  return;
1591  }
1592 
1594 
1595  Float_t upylow = fUpperPad->GetYlowNDC();
1596  Float_t lowylow = fLowerPad->GetYlowNDC();
1597  Float_t lowh = fLowerPad->GetHNDC();
1598  Float_t lowyup = lowylow + lowh;
1599 
1600  Bool_t changed = kFALSE;
1601 
1602  if (upylow != fSplitFraction) {
1603  // up changed
1604  SetSplitFraction(upylow);
1605  changed = kTRUE;
1606  }
1607  else if (lowyup != fSplitFraction) {
1608  // low changed
1609  SetSplitFraction(lowyup);
1610  changed = kTRUE;
1611  }
1612 
1613  if (changed) {
1614  CreateVisualAxes();
1615  }
1616 
1618 
1619 }
1620 
1621 ////////////////////////////////////////////////////////////////////////////////
1622 /// Check if ... is drawn.
1623 
1625 {
1626  TList *siblings = fParentPad->GetListOfPrimitives();
1627  return siblings->FindObject(this) != 0;
1629 
1630 ////////////////////////////////////////////////////////////////////////////////
1631 /// Set the fraction of the parent pad, at which the to sub pads should meet
1632 
1634 {
1635  if (fParentPad == 0) {
1636  Warning("SetSplitFraction", "Can only be used after TRatioPlot has been drawn.");
1637  return;
1638  }
1639 
1640  fSplitFraction = sf;
1641  double pm = fInsetWidth;
1642  double width = fParentPad->GetWNDC();
1643  double height = fParentPad->GetHNDC();
1644  double f = height/width;
1645 
1646  fUpperPad->SetPad(pm*f, fSplitFraction, 1.-pm*f, 1.-pm);
1647  fLowerPad->SetPad(pm*f, pm, 1.-pm*f, fSplitFraction);
1648 }
1649 
1650 ////////////////////////////////////////////////////////////////////////////////
1651 /// Set the inset on the outer sides of all the pads. It's used to make the outer
1652 /// pad draggable.
1653 
1655 {
1656  if (fParentPad == 0) {
1657  Warning("SetInsetWidth", "Can only be used after TRatioPlot has been drawn.");
1658  return;
1659  }
1660 
1661  fInsetWidth = width;
1663 
1664  double pm = fInsetWidth;
1665  double w = fParentPad->GetWNDC();
1666  double h = fParentPad->GetHNDC();
1667  double f = h/w;
1668  fTopPad->SetPad(pm*f, pm, 1-pm*f, 1-pm);
1669 }
1670 
1671 ////////////////////////////////////////////////////////////////////////////////
1672 /// Sets the confidence levels used to calculate the bands in the fit residual
1673 /// case. Defaults to 1 and 2 sigma.
1674 
1676 {
1677  fCl1 = c1;
1678  fCl2 = c2;
1679  if (!BuildLowerPlot()) return;
1680 }
1681 
1682 ////////////////////////////////////////////////////////////////////////////////
1683 /// Set where horizontal, dashed lines are drawn on the lower pad.
1684 /// Can be used to override existing default lines (or disable them).
1685 ///
1686 /// \param gridlines Vector of y positions for the dashes lines
1687 ///
1688 /// Begin_Macro(source)
1689 /// ../../../tutorials/hist/ratioplot4.C
1690 /// End_Macro
1691 
1692 void TRatioPlot::SetGridlines(std::vector<double> gridlines)
1693 {
1694  fGridlinePositions = gridlines;
1695 }
1696 
1697 ////////////////////////////////////////////////////////////////////////////////
1698 /// Set where horizontal, dashed lines are drawn on the lower pad.
1699 /// Can be used to override existing default lines (or disable them).
1700 ///
1701 /// \param gridlines Double_t array of y positions for the dashed lines
1702 /// \param numGridlines Length of gridlines
1703 
1704 void TRatioPlot::SetGridlines(Double_t *gridlines, Int_t numGridlines)
1705 {
1706  fGridlinePositions.clear();
1707 
1708  for (Int_t i=0;i<numGridlines;++i) {
1709  fGridlinePositions.push_back(gridlines[i]);
1710  }
1711 }
1712 
1713 ////////////////////////////////////////////////////////////////////////////////
1714 /// Set the confidence interval colors.
1715 ///
1716 /// \param ci1 Color of the 1 sigma band
1717 /// \param ci2 Color of the 2 sigma band
1718 /// Sets the color of the 1 and 2 sigma bands in the fit residual case.
1719 /// Begin_Macro(source)
1720 /// ../../../tutorials/hist/ratioplot5.C
1721 /// End_Macro
1722 
1724 {
1725  fCi1Color = ci1;
1726  fCi2Color = ci2;
1727 }
1728 
1729 ////////////////////////////////////////////////////////////////////////////////
1730 /// Internal method to import TAxis attributes to a TGaxis. Copied from
1731 /// `TGaxis::ImportAxisAttributes`
1732 
1733 void TRatioPlot::ImportAxisAttributes(TGaxis *gaxis, TAxis *axis)
1734 {
1735  gaxis->SetLineColor(axis->GetAxisColor());
1736  gaxis->SetTextColor(axis->GetTitleColor());
1737  gaxis->SetTextFont(axis->GetTitleFont());
1738  gaxis->SetLabelColor(axis->GetLabelColor());
1739  gaxis->SetLabelFont(axis->GetLabelFont());
1740  gaxis->SetLabelSize(axis->GetLabelSize());
1741  gaxis->SetLabelOffset(axis->GetLabelOffset());
1742  gaxis->SetTickSize(axis->GetTickLength());
1743  gaxis->SetTitle(axis->GetTitle());
1744  gaxis->SetTitleOffset(axis->GetTitleOffset());
1745  gaxis->SetTitleSize(axis->GetTitleSize());
1753  if (axis->GetDecimals()) gaxis->SetBit(TAxis::kDecimals); //the bit is in TAxis::fAxis2
1754  gaxis->SetTimeFormat(axis->GetTimeFormat());
1755 }
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:324
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:5937
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:5831
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:8253
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:236
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:640
Float_t GetBottomMargin() const
Definition: TAttPad.h:43
void SetLeftMargin(Float_t margin)
Sets the left margin of both pads.
Definition: TRatioPlot.cxx:499
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:159
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:4639
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:375
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:2468
Float_t fSplitFraction
Stores the fraction at which the upper and lower pads meet.
Definition: TRatioPlot.h:92
Basic string class.
Definition: TString.h:129
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:1087
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:202
virtual void SetTitle(const char *title="")
Set graph title.
Definition: TGraph.cxx:2180
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:628
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:687
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:6419
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:501
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:112
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:927
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:247
TGraph with asymmetric error bars.
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:565
Double_t x[n]
Definition: legend1.C:17
Int_t GetLogy() const
Definition: TPad.h:248
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:2460
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:497
void SetTimeFormat(const char *tformat)
Change the format used for time plotting.
Definition: TGaxis.cxx:2495
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:5766
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:1254
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:2606
virtual Int_t GetNdivisions() const
Definition: TAttAxis.h:36
A doubly linked list.
Definition: TList.h:43
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:889
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:2851
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:436
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:873
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:301
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:315
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:97
const Bool_t kFALSE
Definition: RtypesCore.h:92
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:295
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:1197
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:8275
void CreateGridline()
Create a grid line.
Definition: TRatioPlot.cxx:781
double f(double x)
virtual Double_t GetBinErrorLow(Int_t bin) const
Return lower error associated to bin number bin.
Definition: TH1.cxx:8191
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:325
virtual void SetFillStyle(Style_t fstyle)
Override TAttFill::FillStyle for TPad because we want to handle style=0 as style 4000.
Definition: TPad.cxx:5754
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
double func(double *x, double *p)
Definition: stressTF1.cxx:213
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:572
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:770
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:65
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:151
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
Definition: TPad.h:225
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition: TGraph.cxx:2156
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:150
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:2544
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:284
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:8222
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:277
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:89
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:224
const Bool_t kTRUE
Definition: RtypesCore.h:91
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
Definition: TPad.h:223
Float_t GetRightMargin() const
Definition: TAttPad.h:45
void Modified(Bool_t flag=1)
Definition: TPad.h:410
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:859
TAxis * GetXaxis()
Definition: TH1.h:300
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:8175
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:2333
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:347
virtual void SetLogy(Int_t value=1)
Set Lin/Log scale for Y.
Definition: TPad.cxx:5780