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