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