Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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-2024, 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 "TColor.h"
14#include "TROOT.h"
15#include "TBrowser.h"
16#include "TH1.h"
17#include "TF1.h"
18#include "TPad.h"
19#include "TString.h"
20#include "TMath.h"
21#include "TGraphAsymmErrors.h"
22#include "TGraphErrors.h"
23#include "TGaxis.h"
24#include "TLine.h"
25#include "TVirtualFitter.h"
26#include "TFitResult.h"
27#include "THStack.h"
28#include "TStyle.h"
29
30/** \class TRatioPlot
31 \ingroup gpad
32Class for displaying ratios, differences and fit residuals.
33
34TRatioPlot has two constructors, one which accepts two histograms, and is responsible
35for setting up the calculation of ratios and differences. This calculation is in part
36delegated to `TEfficiency`. A single option can be given as a parameter, that is
37used to determine which procedure is chosen. The remaining option string is then
38passed through to the calculation, if applicable. The other constructor uses a
39fitted histogram to calculate the fit residual and plot it with the histogram
40and the fit function.
41
42## Ratios and differences
43The simplest case is passing two histograms without specifying any options. This defaults to using
44`TGraphAsymmErrors::Divide`. The `option` variable is passed through, as are the parameters
45`c1` and `c2`, that you can set via `TRatioPlot::SetC1` and `TRatioPlot::SetC1`. If you set the
46`option` to `divsym` the method `TH1::Divide` will be used instead, also receiving all the parameters.
47
48Using the `option` `diff` or `diffsig`, both histograms will be subtracted, and in the case of diffsig,
49the difference will be divided by the uncertainty. `c1` and `c2` will only be used to
50scale the histograms using `TH1::Scale` prior to subtraction.
51
52Available options are for `option`:
53| Option | Description |
54| ---------- | ------------------------------------------------------------ |
55| divsym | uses the histogram `TH1::Divide` method, yields symmetric errors |
56| diff | subtracts the histograms |
57| diffsig | subtracts the histograms and divides by the uncertainty |
58
59Begin_Macro(source)
60../../../tutorials/hist/hist029_TRatioPlot_simple.C
61End_Macro
62
63## Fit residuals
64A second constructor only accepts a single histogram, but expects it to have a fitted
65function. The function is used to calculate the residual between the fit and the
66histogram. Here, it is expected that h1 has a fit function in it's list of functions. The class calculates the
67difference between the histogram and the fit function at each point and divides it by the uncertainty. There
68are a few option to steer which error is used (as is the case for `diffsig`). The default is to use
69the statistical uncertainty from h1 using `TH1::GetBinError`. If the `option` string contains `errasym`, asymmetric
70errors will be used. The type of error can be steered by `TH1::SetBinErrorOption`. The corresponding error will be used,
71depending on if the function is below or above the bin content. The third option `errfunc` uses the square root of
72the function value as the error.
73
74
75Begin_Macro(source)
76../../../tutorials/hist/hist030_TRatioPlot_residual.C
77End_Macro
78
79## Error options for difference divided by uncertainty and fit residual
80The uncertainty that is used in the calculation can be steered by providing
81options to the `option` argument.
82
83| Option | Description |
84| ---------- | ------------------------------------------------------------ |
85| errasym | Uses calculated asymmetric errors from `TH1::GetBinErrorUp`/`TH1::GetBinErrorLow`. Note that you need to
86set `TH1::SetBinErrorOption` first | | errfunc | Uses \f$ \sqrt{f(x)} \f$ as the error |
87
88The asymmetric error case uses the upper or lower error depending on the relative size
89of the bin contents, or the bin content and the function value.
90
91## Access to internal parts
92You can access the internal objects that are used to construct the plot via a series of
93methods. `TRatioPlot::GetUpperPad` and `TRatioPlot::GetLowerPad` can be used to draw additional
94elements on top of the existing ones.
95`TRatioPlot::GetLowerRefGraph` returns a reference to the lower pad's graph that
96is responsible for the range, which enables you to modify the range.
97
98\image html gpad_ratioplot.png
99*/
100
101////////////////////////////////////////////////////////////////////////////////
102/// TRatioPlot default constructor
103
104TRatioPlot::TRatioPlot() : fLeftMargin(gStyle->GetPadLeftMargin()), fRightMargin(gStyle->GetPadRightMargin()) {}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Destructor
108
110{
111 delete fSharedXAxis;
112 delete fUpYaxis;
113 delete fLowYaxis;
114
118 }
119
120 // special case when fH1 created from the stack but not drawn - need to delete it
122 delete fH1;
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Internal method that shares constructor logic
127
129{
130
131 fH1 = h1;
132 fH2 = h2;
133
134 SetupPads();
135
137
138 if (optionString.Contains("divsym")) {
139 optionString.ReplaceAll("divsym", "");
141 } else if (optionString.Contains("diffsig")) {
142 optionString.ReplaceAll("diffsig", "");
144
145 // determine which error style
146 if (optionString.Contains("errasym")) {
148 optionString.ReplaceAll("errasym", "");
149 }
150
151 if (optionString.Contains("errfunc")) {
153 optionString.ReplaceAll("errfunc", "");
154 }
155 } else if (optionString.Contains("diff")) {
156 optionString.ReplaceAll("diff", "");
158 } else {
159 fMode = CalculationMode::kDivideGraph; // <- default
160 }
161
163
164
165 fH1DrawOpt = "hist";
166 fH2DrawOpt = "E";
167 fGraphDrawOpt = "AP";
168
169
170 // build ratio, everything is ready
171 if (!BuildLowerPlot()) return;
172
173 // taking x axis information from h1 by cloning it x axis
174 fSharedXAxis = static_cast<TAxis *>(fH1->GetXaxis()->Clone());
175 fUpYaxis = static_cast<TAxis *>(fH1->GetYaxis()->Clone());
176 fLowYaxis = static_cast<TAxis *>(fRatioGraph->GetYaxis()->Clone());
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Constructor for two histograms
181///
182/// \param h1 First histogram
183/// \param h2 Second histogram
184/// \param option Steers the error calculation, as well as ratio / difference
185
187{
188 if (!h1 || !h2) {
189 Warning("TRatioPlot", "Need two histograms.");
190 return;
191 }
192
194 Bool_t h2IsTH1 = h2->InheritsFrom(TH1::Class());
195
196 if (!h1IsTH1 && !h2IsTH1) {
197 Warning("TRatioPlot", "Need two histograms deriving from TH2 or TH3.");
198 return;
199 }
200
202
203 Init(h1, h2, option);
204
205}
206
207////////////////////////////////////////////////////////////////////////////////
208/// Constructor which accepts a `THStack` and a histogram. Converts the
209/// stack to a regular sum of its containing histograms for processing.
210///
211/// \param st The THStack object
212/// \param h2 The other histogram
213/// \param option Steers the calculation of the lower plot
214
216{
217 if (!st || !h2) {
218 Warning("TRatioPlot", "Need a histogram and a stack");
219 return;
220 }
221
222 TList *stackHists = st->GetHists();
223
224 if (stackHists->GetSize() == 0) {
225 Warning("TRatioPlot", "Stack does not have histograms");
226 return;
227 }
228
229 auto tmpHist = static_cast<TH1 *>(stackHists->At(0)->Clone());
230 tmpHist->Reset();
231
232 for (int i = 0; i < stackHists->GetSize(); ++i) {
233 tmpHist->Add(static_cast<TH1 *>(stackHists->At(i)));
234 }
235
238
239 Init(tmpHist, h2, option);
240
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// Constructor which accepts a `THStack` and a histogram. Converts the
245/// stack to a regular sum of its containing histograms for processing.
246///
247/// \param h1 The other histogram
248/// \param st The THStack object
249/// \param option Steers the calculation of the lower plot
250
252{
253 if (!st || !h1) {
254 Warning("TRatioPlot", "Need a histogram and a stack");
255 return;
256 }
257
258 TList *stackHists = st->GetHists();
259
260 if (stackHists->GetSize() == 0) {
261 Warning("TRatioPlot", "Stack does not have histograms");
262 return;
263 }
264
265 auto tmpHist = static_cast<TH1 *>(stackHists->At(0)->Clone());
266 tmpHist->Reset();
267
268 for (int i = 0; i < stackHists->GetSize(); ++i) {
269 tmpHist->Add(static_cast<TH1 *>(stackHists->At(i)));
270 }
271
273
275
276}
277
278////////////////////////////////////////////////////////////////////////////////
279/// Constructor for one histogram and a fit.
280///
281/// \param h1 The histogram
282/// \param option Steers the error calculation
283/// \param fitres Explicit fit result to be used for calculation. Uses last fit if left empty
284
286{
287 fH1 = h1;
288 if (!fH1) {
289 Warning("TRatioPlot", "Need a histogram.");
290 return;
291 }
292
294
295 if (!h1IsTH1) {
296 Warning("TRatioPlot", "Need a histogram deriving from TH2 or TH3.");
297 return;
298 }
299
301
302 if (h1Functions->GetSize() < 1) {
303 Warning("TRatioPlot", "Histogram given needs to have a (fit) function associated with it");
304 return;
305 }
306
307
309
311
313
315
316 // determine which error style
317 if (optionString.Contains("errasym")) {
319 optionString.ReplaceAll("errasym", "");
320 }
321
322 if (optionString.Contains("errfunc")) {
324 optionString.ReplaceAll("errfunc", "");
325 }
326
328
329 if (!BuildLowerPlot()) return;
330
331 // emulate option behaviour of TH1
332 if (fH1->GetSumw2N() > 0) {
333 fH1DrawOpt = "E";
334 } else {
335 fH1DrawOpt = "hist";
336 }
337 fGraphDrawOpt = "LX"; // <- default
338
339 fSharedXAxis = static_cast<TAxis *>(fH1->GetXaxis()->Clone());
340 fUpYaxis = static_cast<TAxis *>(fH1->GetYaxis()->Clone());
341 fLowYaxis = static_cast<TAxis *>(fRatioGraph->GetYaxis()->Clone());
342
343 //SyncAxesRanges();
344
345 SetupPads();
346
347}
348
349////////////////////////////////////////////////////////////////////////////////
350/// Sets the drawing option for h1
351
353{
354 fH1DrawOpt = opt;
355}
356
357////////////////////////////////////////////////////////////////////////////////
358/// Sets the drawing option for h2
359
361{
362 TString optString = opt;
363 optString.ReplaceAll("same", "");
364 optString.ReplaceAll("SAME", "");
365
367}
368
369////////////////////////////////////////////////////////////////////////////////
370/// Sets the drawing option for the lower graph
371
373{
374 fGraphDrawOpt = opt;
375}
376
377////////////////////////////////////////////////////////////////////////////////
378/// Sets the drawing option for the fit in the fit residual case
379
381{
382 fFitDrawOpt = opt;
383}
384
385////////////////////////////////////////////////////////////////////////////////
386/// Setup the pads.
387
389{
390 // this method will delete all the pads before recreating them
391
392 if (fUpperPad) {
393 delete fUpperPad;
394 fUpperPad = nullptr;
395 }
396
397 if (fLowerPad) {
398 delete fLowerPad;
399 fLowerPad = nullptr;
400 }
401
402 if (!gPad) {
403 Error("SetupPads", "need to create a canvas first");
404 return;
405 }
406
407 double pm = fInsetWidth;
408 double width = gPad->GetWNDC();
409 double height = gPad->GetHNDC();
410 double f = height/width;
411
412 fUpperPad = new TPad("upper_pad", "", pm*f, fSplitFraction, 1.-pm*f, 1.-pm);
413 fLowerPad = new TPad("lower_pad", "", pm*f, pm, 1.-pm*f, fSplitFraction);
414
416
417 // connect to the pads signal
418
419 if (fTopPad) {
420 delete fTopPad;
421 fTopPad = nullptr;
422 }
423
424 fTopPad = new TPad("top_pad", "", pm*f, pm, 1-pm*f, 1-pm);
425
427}
428
429////////////////////////////////////////////////////////////////////////////////
430/// Connect some signals from the pads to handle them
431/// Allows correctly work also after reading ratioplot from the file
432
434{
435 static const char *rangeSignal = "RangeAxisChanged()";
436
438 return;
439
440 fUpperPad->Connect(rangeSignal, ClassName(), this, "RangeAxisChanged()");
441 fLowerPad->Connect(rangeSignal, ClassName(), this, "RangeAxisChanged()");
442
443 fUpperPad->Connect("UnZoomed()", ClassName(), this, "UnZoomed()");
444 fLowerPad->Connect("UnZoomed()", ClassName(), this, "UnZoomed()");
445
446 fUpperPad->Connect("Resized()", ClassName(), this, "SubPadResized()");
447 fLowerPad->Connect("Resized()", ClassName(), this, "SubPadResized()");
448
449}
450
451////////////////////////////////////////////////////////////////////////////////
452/// Sets the top margin of the upper pad.
453///
454/// \param margin The new margin
455
457{
458 fUpTopMargin = margin;
460}
461
462////////////////////////////////////////////////////////////////////////////////
463/// Sets the bottom margin of the upper pad.
464///
465/// \param margin The new margin
466
468{
469 fUpBottomMargin = margin;
471}
472
473////////////////////////////////////////////////////////////////////////////////
474/// Sets the top margin of the lower pad.
475///
476/// \param margin The new margin
477
479{
480 fLowTopMargin = margin;
482}
483
484////////////////////////////////////////////////////////////////////////////////
485/// Sets the bottom margin of the lower pad.
486///
487/// \param margin The new margin
488
490{
491 fLowBottomMargin = margin;
493}
494
495////////////////////////////////////////////////////////////////////////////////
496/// Sets the left margin of both pads.
497/// \param margin The new margin
498
500{
501 fLeftMargin = margin;
503}
504
505////////////////////////////////////////////////////////////////////////////////
506/// Sets the right margin of both pads.
507///
508/// \param margin The new margin
509
511{
512 fRightMargin = margin;
514}
515
516////////////////////////////////////////////////////////////////////////////////
517/// Sets the margin that separates the two pads. The margin is split according
518/// to the relative sizes of the pads
519///
520/// \param margin The new margin
521///
522/// Begin_Macro(source)
523/// ../../../tutorials/hist/hist034_TRatioPlot_fit_margin.C
524/// End_Macro
525
527{
529 fUpBottomMargin = margin/2./(1-sf);
530 fLowTopMargin = margin/2./sf;
532}
533
534////////////////////////////////////////////////////////////////////////////////
535/// Return the separation margin value.
536
544
545////////////////////////////////////////////////////////////////////////////////
546/// Draws the ratio plot to the currently active pad. Therefore it requires that
547/// a TCanvas has been created first.
548///
549/// It takes the following options
550///
551/// | Option | Description |
552/// | ---------- | ------------------------------------------------------------ |
553/// | grid / nogrid | enable (default) or disable drawing of dashed lines on lower plot |
554/// | hideup | hides the first label of the upper axis if there is not enough space |
555/// | fhideup | always hides the first label of the upper axis |
556/// | hidelow (default) | hides the last label of the lower axis if there is not enough space |
557/// | fhidelow | always hides the last label of the lower axis |
558/// | nohide | does not hide a label if there is not enough space |
559/// | noconfint | does not draw the confidence interval bands in the fit residual case |
560/// | confint | draws the confidence interval bands in the fit residual case (default) |
561
563{
564
566
567 if (drawOpt.Contains("nogrid")) {
568 drawOpt.ReplaceAll("nogrid", "");
570 } else if (drawOpt.Contains("grid")) {
571 drawOpt.ReplaceAll("grid", "");
573 }
574
575 if (drawOpt.Contains("noconfint")) {
576 drawOpt.ReplaceAll("noconfint", "");
578 } else if (drawOpt.Contains("confint")) {
579 drawOpt.ReplaceAll("confint", "");
580 fShowConfidenceIntervals = kTRUE; // <- default
581 }
582
583 if (drawOpt.Contains("fhideup")) {
585 } else if (drawOpt.Contains("fhidelow")) {
587 } else if (drawOpt.Contains("hideup")) {
589 } else if (drawOpt.Contains("hidelow")) {
591 } else if (drawOpt.Contains("nohide")) {
593 } else {
595 }
596
597 if (!gPad) {
598 Error("Draw", "need to create a canvas first");
599 return;
600 }
601
603
604 // draw ratio plot as very first object
605 // when painting one can update all attributes before other objects are painted
606 AppendPad();
607
611
616
617 // we are a TPad
618
619 fUpperPad->Draw();
620 fLowerPad->Draw();
621
623 fTopPad->Draw();
624
625 fUpperPad->cd();
626
629
631 // use last function in the list
632 TF1 *func = nullptr;
633 for (int i = fH1->GetListOfFunctions()->GetSize()-1; i >= 0; i--) {
634 auto obj = fH1->GetListOfFunctions()->At(i);
635 if (obj->InheritsFrom(TF1::Class()) ) {
636 func = dynamic_cast<TF1*>(obj);
637 break;
638 }
639 }
640 if (!func) {
641 // this is checked in constructor and should thus not occur
642 Error("Draw", "h1 does not have a fit function");
643 return;
644 }
645
646 fH1->Draw("A"+fH1DrawOpt);
647 func->Draw(fFitDrawOpt+"same");
648
649 fLowerPad->cd();
650
655 } else {
656 fRatioGraph->Draw("IA"+fGraphDrawOpt+"SAME");
657 }
658 } else {
659
660 if (fHistDrawProxy) {
663 } else {
664 Warning("Draw", "Draw proxy not of type TH1 or THStack, not drawing it");
665 }
666 }
667
668 fH2->Draw("A"+fH2DrawOpt+"same");
669
670 fLowerPad->cd();
671
674
675 }
676
677 // assign same axis ranges to lower pad as in upper pad
678 // the visual axes will be created on paint
680
682
684
685 // restore active pad at the end
686 fParentPad->cd();
687
688 // only after object drawn connect signals
690}
691
692////////////////////////////////////////////////////////////////////////////////
693/// Returns the reference graph for the lower pad, which means the graph that
694/// is responsible for setting the coordinate system. It is the first graph
695/// added to the primitive list of the lower pad.
696/// This reference can be used to set the minimum and maximum of the lower pad.
697/// Note that `TRatioPlot::Draw` needs to have been called first, since the
698/// graphs are only created then.
699///
700/// Begin_Macro(source)
701/// ../../../tutorials/hist/hist031_TRatioPlot_residual_fit.C
702/// End_Macro
703
705{
706 if (!fLowerPad) {
707 Error("GetLowerRefGraph", "Lower pad has not been defined");
708 return nullptr;
709 }
710
712 if (primlist->GetSize() == 0) {
713 Error("GetLowerRefGraph", "Lower pad does not have primitives");
714 return nullptr;
715 }
716
717 TObjLink *lnk = primlist->FirstLink();
718
719 while (lnk) {
720 TObject *obj = lnk->GetObject();
721
722 if (obj->InheritsFrom(TGraph::Class()))
723 return static_cast<TGraph *>(obj);
724
725 lnk = lnk->Next();
726 }
727
728 Error("GetLowerRefGraph", "Did not find graph in list");
729 return nullptr;
730}
731
732////////////////////////////////////////////////////////////////////////////////
733/// Return the reference object. Its the first TH1 or THStack type object
734/// in the upper pads list of primitives.
735/// Note that it returns a `TObject`, so you need to test and cast it to use it.
736
738{
740 for (Int_t i = 0; i < primlist->GetSize(); ++i) {
741 auto refobj = primlist->At(i);
742 if (refobj->InheritsFrom(TH1::Class()) || refobj->InheritsFrom(THStack::Class())) {
743 return refobj;
744 }
745 }
746
747 Error("GetUpperRefObject", "No upper ref object of TH1 or THStack type found");
748 return nullptr;
749}
750
751////////////////////////////////////////////////////////////////////////////////
752/// Gets the x axis of the object returned by `TRatioPlot::GetUpperRefObject`.
753
755{
757
758 if (!refobj)
759 return nullptr;
760
761 if (refobj->InheritsFrom(TH1::Class())) {
762 return static_cast<TH1 *>(refobj)->GetXaxis();
763 } else if (refobj->InheritsFrom(THStack::Class())) {
764 return static_cast<THStack *>(refobj)->GetXaxis();
765 }
766
767 return nullptr;
768}
769
770////////////////////////////////////////////////////////////////////////////////
771/// Gets the y axis of the object returned by `TRatioPlot::GetUpperRefObject`.
772
774{
776
777 if (!refobj)
778 return nullptr;
779
780 if (refobj->InheritsFrom(TH1::Class())) {
781 return static_cast<TH1 *>(refobj)->GetYaxis();
782 } else if (refobj->InheritsFrom(THStack::Class())) {
783 return static_cast<THStack *>(refobj)->GetYaxis();
784 }
785
786 return nullptr;
787}
788
789////////////////////////////////////////////////////////////////////////////////
790/// Gets the x axis of the lower ref graph.
791/// Shortcut for:
792///
793/// ~~~{.cpp}
794/// rp->GetLowerRefGraph()->GetXaxis();
795/// ~~~
796
798{
799 auto gr = GetLowerRefGraph();
800 return gr ? gr->GetXaxis() : nullptr;
801}
802
803////////////////////////////////////////////////////////////////////////////////
804/// Gets the y axis of the lower ref graph.
805/// Shortcut for:
806///
807/// ~~~{.cpp}
808/// rp->GetLowerRefGraph()->GetYaxis();
809/// ~~~
810
812{
813 auto gr = GetLowerRefGraph();
814 return gr ? gr->GetYaxis() : nullptr;
815}
816
817////////////////////////////////////////////////////////////////////////////////
818/// Create a grid lines
819
821{
822
823 if (!fShowGridlines)
824 return; // don't draw them
825
826 while (fGridlines.size() < fGridlinePositions.size()) {
827 TLine *newline = new TLine(0, 0, 0, 0);
828 newline->SetLineStyle(2);
830 fGridlines.emplace_back(newline);
831 }
832
834}
835
836////////////////////////////////////////////////////////////////////////////////
837/// Update positions of grid lines
838
840{
843
846
847 for (size_t i = 0; i < fGridlines.size(); ++i) {
848 auto line = fGridlines.at(i);
849 Bool_t visible = kFALSE;
850 Double_t y = 0.;
851 if (i < fGridlinePositions.size()) {
853 visible = (y >= lowYFirst && y <= lowYLast);
854 }
855
856 if (visible) {
857 line->SetX1(first);
858 line->SetX2(last);
859 line->SetY1(y);
860 line->SetY2(y);
861 } else {
862 line->SetX1(first);
863 line->SetX2(first);
866 }
867 }
868}
869
870
871////////////////////////////////////////////////////////////////////////////////
872/// Update the visual axes and grid lines when painting
873
875{
876 // painting invoked before object drawn to the end - just ignore here
877 if (!fUpperGXaxis)
878 return;
879
881
884
885 // in any case reset flag after painting
887}
888
889////////////////////////////////////////////////////////////////////////////////
890/// Syncs the axes ranges from the shared ones to the actual ones.
891
893{
894 // get ranges from the shared axis clone
897
898 // set range on computed graph, have to set it twice because
899 // TGraph's axis looks strange otherwise
901 ref->SetLimits(first, last);
902 ref->SetRangeUser(first, last);
903
904 GetUpperRefXaxis()->SetRangeUser(first, last);
905}
906
907////////////////////////////////////////////////////////////////////////////////
908/// Build the lower plot according to which constructor was called, and
909/// which options were passed.
910
912{
913 static const char *thisMethod = "BuildLowerPlot";
914
915 // Clear and delete the graph if not exists
916 if (fRatioGraph) {
917 delete fRatioGraph;
918 fRatioGraph = nullptr;
919 }
920
923
926
927 static Double_t divideGridlines[] = {0.7, 1.0, 1.3};
928 static Double_t diffGridlines[] = {0.0};
929 static Double_t signGridlines[] = {1.0, 0.0, -1.0};
930
931 // Determine the divide mode and create the lower graph accordingly
932 // Pass divide options given in constructor
934 // use TGraphAsymmErrors Divide method to create
935
937
938 TH1 *tmpH1 = static_cast<TH1 *>(fH1->Clone());
939 TH1 *tmpH2 = static_cast<TH1 *>(fH2->Clone());
940
941 tmpH1->Scale(fC1);
942 tmpH2->Scale(fC2);
943
945 ratioGraph->Divide(tmpH1, tmpH2, fOption.Data());
947
948 delete tmpH1;
949 delete tmpH2;
950
951 } else if (fMode == CalculationMode::kDifference) {
953
954 TH1 *tmpHist = static_cast<TH1 *>(fH1->Clone());
955
956 tmpHist->Reset();
957
958 tmpHist->Add(fH1, fH2, fC1, -1*fC2);
960
961 delete tmpHist;
963
965
967 Int_t ipoint = 0;
968
969 for (Int_t i = 0; i <= fH1->GetNbinsX(); ++i) {
970 Double_t val = fH1->GetBinContent(i);
972 Double_t error = 0.;
973
975
978
979 if (val - val2 > 0) {
980 // h1 > h2
981 error = errLow;
982 } else {
983 // h1 < h2
984 error = errUp;
985 }
986
988 error = fH1->GetBinError(i);
989 } else {
990 Warning(thisMethod, "error mode is invalid");
991 }
992
993 if (error != 0.) {
994
995 Double_t res = (val - val2) / error;
996
997 ((TGraphAsymmErrors*)fRatioGraph)->SetPoint(ipoint, fH1->GetBinCenter(i), res);
998 ((TGraphAsymmErrors*)fRatioGraph)->SetPointError(ipoint, fH1->GetBinWidth(i)/2., fH1->GetBinWidth(i)/2., 0.5, 0.5);
999
1000 ++ipoint;
1001
1002 }
1003 }
1004
1005 } else if (fMode == CalculationMode::kFitResidual) {
1006
1008
1009 TF1 *func = dynamic_cast<TF1*>(fH1->GetListOfFunctions()->At(0));
1010
1011 if (!func) {
1012 // this is checked in constructor and should thus not occur
1013 Error(thisMethod, "h1 does not have a fit function");
1014 return 0;
1015 }
1016
1018 Int_t ipoint = 0;
1019
1020 std::vector<double> ci1, ci2;
1021
1023
1024 std::vector<Double_t> x_arr(nbinsx, 0.), ci_arr1(nbinsx, 0.), ci_arr2(nbinsx, 0);
1025 for (Int_t i = 0; i < nbinsx; ++i)
1026 x_arr[i] = fH1->GetBinCenter(i+1);
1027
1028 Double_t cl1 = fCl1, cl2 = fCl2;
1029
1030 if (fFitResult) {
1031 // use this to get conf int
1032
1033 fFitResult->GetConfidenceIntervals(nbinsx, 1, 1, x_arr.data(), ci_arr1.data(), cl1);
1034 for (Int_t i = 1; i <= nbinsx; ++i)
1035 ci1.push_back(ci_arr1[i - 1]);
1036
1037 fFitResult->GetConfidenceIntervals(nbinsx, 1, 1, x_arr.data(), ci_arr2.data(), cl2);
1038 for (Int_t i = 1; i <= nbinsx; ++i)
1039 ci2.push_back(ci_arr2[i - 1]);
1040 } else {
1041 TVirtualFitter::GetFitter()->GetConfidenceIntervals(nbinsx, 1, x_arr.data(), ci_arr1.data(), cl1);
1042 for (Int_t i = 1; i <= nbinsx; ++i)
1043 ci1.push_back(ci_arr1[i - 1]);
1044 TVirtualFitter::GetFitter()->GetConfidenceIntervals(nbinsx, 1, x_arr.data(), ci_arr2.data(), cl2);
1045 for (Int_t i = 1; i <= nbinsx; ++i)
1046 ci2.push_back(ci_arr2[i - 1]);
1047 }
1048
1049 for (Int_t i = 1; i <= nbinsx; ++i) {
1050 Double_t val = fH1->GetBinContent(i);
1051 Double_t x = fH1->GetBinCenter(i);
1052 Double_t error = 0.;
1053
1055
1058
1059 if (val - func->Eval(fH1->GetBinCenter(i)) > 0) {
1060 // h1 > fit
1061 error = errLow;
1062 } else {
1063 // h1 < fit
1064 error = errUp;
1065 }
1066
1067 } else if (fErrorMode == ErrorMode::kErrorSymmetric) {
1068
1069 error = fH1->GetBinError(i);
1070
1071 } else if (fErrorMode == ErrorMode::kErrorFunc) {
1072
1073 error = sqrt(func->Eval(x));
1074
1075 } else {
1076
1077 Warning(thisMethod, "error mode is invalid");
1078
1079 }
1080
1081 if (error != 0.) {
1082
1083 Double_t res = (fH1->GetBinContent(i) - func->Eval(fH1->GetBinCenter(i))) / error;
1084
1085 ((TGraphAsymmErrors*)fRatioGraph)->SetPoint(ipoint, fH1->GetBinCenter(i), res);
1086 ((TGraphAsymmErrors*)fRatioGraph)->SetPointError(ipoint, fH1->GetBinWidth(i)/2., fH1->GetBinWidth(i)/2., 0.5, 0.5);
1087
1089 fConfidenceInterval1->SetPointError(ipoint, x, i <= (Int_t)ci1.size() ? ci1[i-1] / error : 0);
1091 fConfidenceInterval2->SetPointError(ipoint, x, i <= (Int_t)ci2.size() ? ci2[i-1] / error : 0);
1092
1093 ++ipoint;
1094
1095 }
1096 }
1097 } else if (fMode == CalculationMode::kDivideHist){
1099
1100 // Use TH1's Divide method
1101 TH1 *tmpHist = static_cast<TH1 *>(fH1->Clone());
1102 tmpHist->Reset();
1103
1104 tmpHist->Divide(fH1, fH2, fC1, fC2, fOption.Data());
1106
1107 delete tmpHist;
1108 } else {
1109 // this should not occur
1110 Error(thisMethod, "Invalid fMode value");
1111 return 0;
1112 }
1113
1114 // need to set back to "" since recreation. we don't ever want
1115 // title on lower graph
1116
1117 if (!fRatioGraph) {
1118 Error(thisMethod, "Error creating lower graph");
1119 return 0;
1120 }
1121
1122 fRatioGraph->SetTitle("");
1125
1126 return 1;
1127}
1128
1129////////////////////////////////////////////////////////////////////////////////
1130/// Creates the TGaxis objects that are used for consistent display of the axes.
1131
1133{
1137
1140
1145
1146 if (!fUpperGXaxis) {
1147 fUpperGXaxis = new TGaxis(0, 0, 1, 1, 0, 1, 510, "+U");
1149 }
1150
1151 if (!fUpperGYaxis) {
1152 fUpperGYaxis = new TGaxis(0, 0, 1, 1, upYFirst, upYLast, 510, "S");
1154 }
1155
1156 if (!fLowerGXaxis) {
1157 fLowerGXaxis = new TGaxis(0, 0, 1, 1, first, last, 510, "+S");
1159 }
1160
1161 if (!fLowerGYaxis) {
1162 fLowerGYaxis = new TGaxis(0, 0, 1, 1, lowYFirst, lowYLast, 510, "-S");
1164 }
1165
1166 // Create the axes on the other sides of the graphs
1167 // This is steered by an option on the containing pad or self
1168
1169 if (!fUpperGXaxisMirror && axistop) {
1170 fUpperGXaxisMirror = static_cast<TGaxis *>(fUpperGXaxis->Clone());
1172 }
1173
1174 if (!fLowerGXaxisMirror && axistop) {
1175 fLowerGXaxisMirror = static_cast<TGaxis *>(fLowerGXaxis->Clone());
1177 }
1178
1179 if (!fUpperGYaxisMirror && axisright) {
1180 fUpperGYaxisMirror = static_cast<TGaxis *>(fUpperGYaxis->Clone());
1182 }
1183
1184 if (!fLowerGYaxisMirror && axisright) {
1185 fLowerGYaxisMirror = static_cast<TGaxis *>(fLowerGYaxis->Clone());
1187 }
1188
1190}
1191
1192
1193////////////////////////////////////////////////////////////////////////////////
1194/// Update TGaxis attributes
1195
1197{
1198 // this is for errors
1199 static const char *thisMethod = "UpdateVisualAxes";
1200
1201 // figure out where the axis has to go.
1202 // Implicit assumption is, that the top pad spans the full other pads
1207
1212
1215
1220
1222
1223 Bool_t logx = fUpperPad->GetLogx() || fLowerPad->GetLogx();
1226
1227 if (uplogy) {
1228
1231
1232 if (upYFirst <= 0 || upYLast <= 0) {
1233 Error(thisMethod, "Cannot set upper Y axis to log scale");
1234 }
1235 }
1236
1237 if (lowlogy) {
1240
1241 if (lowYFirst <= 0 || lowYLast <= 0) {
1242 Error(thisMethod, "Cannot set lower Y axis to log scale");
1243 }
1244
1245 }
1246
1247 // this is different than in y, y already has pad coords converted, x not...
1248 if (logx) {
1249 if (first <= 0 || last <= 0) {
1250 Error(thisMethod, "Cannot set X axis to log scale");
1251 }
1252 }
1253
1254 // determine axes options to create log axes if needed
1255 TString xopt = logx ? "G" : "";
1256 TString upyopt = uplogy ? "G" : "";
1257 TString lowyopt = lowlogy ? "G" : "";
1258
1259 // import infos from TAxis
1264
1265 // lower x axis needs to get title from upper x
1267
1268 // (re)set all the axes properties to what we want them
1270
1273 fUpperGXaxis->SetY1(upBM*(1-sf)+sf);
1274 fUpperGXaxis->SetY2(upBM*(1-sf)+sf);
1275 fUpperGXaxis->SetWmin(first);
1276 fUpperGXaxis->SetWmax(last);
1277
1280 fUpperGYaxis->SetY1(upBM*(1-sf)+sf);
1281 fUpperGYaxis->SetY2( (1-upTM)*(1-sf)+sf );
1284
1289 fLowerGXaxis->SetWmin(first);
1290 fLowerGXaxis->SetWmax(last);
1291
1295 fLowerGYaxis->SetY2((1-lowTM)*sf);
1298
1303
1308
1309 // normalize the tick sizes. y axis ticks should be consistent
1310 // even if their length is different
1311 Double_t ratio = ( (upBM-(1-upTM))*(1-sf) ) / ( (lowBM-(1-lowTM))*sf );
1315
1317
1318 fUpperGYaxis->ChangeLabel(1, -1, 0);
1319
1321
1322 fLowerGYaxis->ChangeLabel(-1, -1, 0);
1323
1324 } else {
1325 if (GetSeparationMargin() < 0.025) {
1326
1329 fUpperGYaxis->ChangeLabel(1, -1, 0);
1331 fLowerGYaxis->ChangeLabel(-1, -1, 0);
1332 }
1333 }
1334
1335 } else {
1336 // reset
1341 }
1342
1343 }
1344 }
1345
1346 // move them about and set required positions
1347 if (fUpperGXaxisMirror) {
1352 fUpperGXaxisMirror->SetY1((1-upTM)*(1-sf)+sf);
1353 fUpperGXaxisMirror->SetY2((1-upTM)*(1-sf)+sf);
1359 }
1360
1361 if (fUpperGYaxisMirror) {
1367 fUpperGYaxisMirror->SetY2( (1-upTM)*(1-sf)+sf );
1373 }
1374
1375 if (fLowerGXaxisMirror) {
1387 }
1388
1389 if (fLowerGYaxisMirror) {
1402 }
1403
1404}
1405
1406////////////////////////////////////////////////////////////////////////////////
1407/// Sets the margins of all the pads to the value specified in class members.
1408/// This one is called whenever those are changed, e.g. in setters
1409
1421
1422////////////////////////////////////////////////////////////////////////////////
1423/// Figures out which pad margin has deviated from the stored ones,
1424/// to figure out what the new nominal is and set the other pad to it
1425/// subsequently.
1426
1473
1474////////////////////////////////////////////////////////////////////////////////
1475/// Slot that receives the RangeAxisChanged signal from any of the pads and
1476/// reacts correspondingly.
1477
1479{
1480 // Only run this concurrently once, in case it's called async
1481 if (fIsUpdating)
1482 return;
1483
1485
1486 // find out if logx has changed
1487 if (fParentPad->GetLogx()) {
1488 if (!fUpperPad->GetLogx() || !fLowerPad->GetLogx()) {
1490 }
1491 } else {
1492 if (fUpperPad->GetLogx() || fLowerPad->GetLogx()) {
1494 }
1495 }
1496
1497 // set log to pads
1498 if (fUpperPad->GetLogx() != fParentPad->GetLogx())
1500 if (fLowerPad->GetLogx() != fParentPad->GetLogx())
1502
1503 // get axis ranges for upper and lower
1505 Double_t upFirst = uprefx->GetBinLowEdge(uprefx->GetFirst());
1506 Double_t upLast = uprefx->GetBinUpEdge(uprefx->GetLast());
1507
1509 Double_t lowFirst = lowrefx->GetBinLowEdge(lowrefx->GetFirst());
1510 Double_t lowLast = lowrefx->GetBinUpEdge(lowrefx->GetLast());
1511
1514
1517
1518 // determine which one has changed
1519 if (upFirst != globFirst || upLast != globLast) {
1521 upChanged = kTRUE;
1522 } else if (lowFirst != globFirst || lowLast != globLast) {
1524 lowChanged = kTRUE;
1525 }
1526
1527 if (upChanged || lowChanged)
1529
1530 // sync the margins in case the user has dragged one of them
1532
1536 fTopPad->Modified();
1538 }
1539
1543}
1544
1545////////////////////////////////////////////////////////////////////////////////
1546/// Slot for the UnZoomed signal that was introduced to TPad.
1547/// Unzoom both pads
1548
1550{
1551 if (fIsUpdating)
1552 return;
1553
1555
1556 // this is what resets the range
1557 fSharedXAxis->SetRange(0, 0);
1559
1560 // Flushing
1563 fTopPad->Modified();
1565
1567}
1568
1569////////////////////////////////////////////////////////////////////////////////
1570/// Slot that handles common resizing of upper and lower pad.
1571
1573{
1574 if (fIsUpdating)
1575 return;
1576
1578
1583
1585
1586 if (upylow != fSplitFraction) {
1587 // up changed
1589 changed = kTRUE;
1590 } else if (lowyup != fSplitFraction) {
1591 // low changed
1593 changed = kTRUE;
1594 }
1595
1596 if (changed)
1598
1600}
1601
1602////////////////////////////////////////////////////////////////////////////////
1603/// Set the fraction of the parent pad, at which the to sub pads should meet
1604
1606{
1607 if (!fParentPad) {
1608 Warning("SetSplitFraction", "Can only be used after TRatioPlot has been drawn.");
1609 return;
1610 }
1611
1612 if ((sf < 0.0001) || (sf > 0.9999)) {
1613 Warning("SetSplitFraction", "Value %f is out of allowed range", sf);
1614 return;
1615 }
1616
1618 double pm = fInsetWidth;
1619 double width = fParentPad->GetWNDC();
1620 double height = fParentPad->GetHNDC();
1621 double f = height/width;
1622
1623 fUpperPad->SetPad(pm*f, fSplitFraction, 1.-pm*f, 1.-pm);
1625}
1626
1627////////////////////////////////////////////////////////////////////////////////
1628/// Set the inset on the outer sides of all the pads. It's used to make the outer
1629/// pad draggable.
1630
1632{
1633 if (!fParentPad) {
1634 Warning("SetInsetWidth", "Can only be used after TRatioPlot has been drawn.");
1635 return;
1636 }
1637
1640
1641 double pm = fInsetWidth;
1642 double w = fParentPad->GetWNDC();
1643 double h = fParentPad->GetHNDC();
1644 double f = h/w;
1645 fTopPad->SetPad(pm*f, pm, 1-pm*f, 1-pm);
1646}
1647
1648////////////////////////////////////////////////////////////////////////////////
1649/// Sets the confidence levels used to calculate the bands in the fit residual
1650/// case. Defaults to 1 and 2 sigma.
1651
1653{
1654 fCl1 = c1;
1655 fCl2 = c2;
1656 if (!BuildLowerPlot()) return;
1657}
1658
1659////////////////////////////////////////////////////////////////////////////////
1660/// Set where horizontal, dashed lines are drawn on the lower pad.
1661/// Can be used to override existing default lines (or disable them).
1662///
1663/// \param gridlines Vector of y positions for the dashes lines
1664///
1665/// Begin_Macro(source)
1666/// ../../../tutorials/hist/hist032_TRatioPlot_fit_lines.C
1667/// End_Macro
1668
1669void TRatioPlot::SetGridlines(std::vector<double> gridlines)
1670{
1672}
1673
1674////////////////////////////////////////////////////////////////////////////////
1675/// Set where horizontal, dashed lines are drawn on the lower pad.
1676/// Can be used to override existing default lines (or disable them).
1677///
1678/// \param gridlines Double_t array of y positions for the dashed lines
1679/// \param numGridlines Length of gridlines
1680
1682{
1683 fGridlinePositions.clear();
1684
1685 for (Int_t i = 0; i < numGridlines; ++i)
1686 fGridlinePositions.emplace_back(gridlines[i]);
1687}
1688
1689////////////////////////////////////////////////////////////////////////////////
1690/// Set the confidence interval colors.
1691///
1692/// \param ci1 Color of the 1 sigma band
1693/// \param ci2 Color of the 2 sigma band
1694/// Sets the color of the 1 and 2 sigma bands in the fit residual case.
1695/// Begin_Macro(source)
1696/// ../../../tutorials/hist/hist033_TRatioPlot_fit_confidence.C
1697/// End_Macro
1698
1704
1705
1706////////////////////////////////////////////////////////////////////////////////
1707/// Set the confidence interval colors.
1708
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
Color number (short)
Definition RtypesCore.h:99
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t option
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
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define gPad
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.
virtual Color_t GetTitleColor() const
Definition TAttAxis.h:47
virtual Color_t GetLabelColor() const
Definition TAttAxis.h:39
virtual Int_t GetNdivisions() const
Definition TAttAxis.h:37
virtual Color_t GetAxisColor() const
Definition TAttAxis.h:38
virtual Style_t GetTitleFont() const
Definition TAttAxis.h:48
virtual Float_t GetLabelOffset() const
Definition TAttAxis.h:41
virtual Style_t GetLabelFont() const
Definition TAttAxis.h:40
virtual Float_t GetTitleSize() const
Definition TAttAxis.h:45
virtual Float_t GetLabelSize() const
Definition TAttAxis.h:42
virtual Float_t GetTickLength() const
Definition TAttAxis.h:46
virtual Float_t GetTitleOffset() const
Definition TAttAxis.h:44
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:38
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition TAttPad.cxx:98
virtual void SetLeftMargin(Float_t leftmargin)
Set Pad left margin in fraction of the pad width.
Definition TAttPad.cxx:108
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:118
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:128
Float_t GetTopMargin() const
Definition TAttPad.h:46
Class to manage histogram axis.
Definition TAxis.h:32
const char * GetTitle() const override
Returns title of object.
Definition TAxis.h:137
@ kTickMinus
Definition TAxis.h:65
@ kCenterTitle
Definition TAxis.h:67
@ kRotateTitle
Definition TAxis.h:69
@ kNoExponent
Definition TAxis.h:71
@ kMoreLogLabels
Definition TAxis.h:77
@ kTickPlus
Definition TAxis.h:64
@ kDecimals
Definition TAxis.h:63
@ kCenterLabels
Bit 13 is used by TObject.
Definition TAxis.h:68
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition TAxis.cxx:521
Bool_t GetDecimals() const
Definition TAxis.h:122
Int_t GetLast() const
Return last bin on the axis i.e.
Definition TAxis.cxx:472
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:1074
virtual const char * GetTimeFormat() const
Definition TAxis.h:134
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition TAxis.cxx:1045
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition TAxis.cxx:531
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition TAxis.cxx:461
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
1-Dim function class
Definition TF1.h:182
static TClass * Class()
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition TF1.cxx:1340
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:26
virtual void SetTitle(const char *title="")
Change the title of the axis.
Definition TGaxis.cxx:2916
const char * GetTitle() const override
Returns title of object.
Definition TGaxis.h:88
virtual void SetNdivisions(Int_t ndiv)
Definition TGaxis.h:120
void SetWmax(Double_t wmax)
Definition TGaxis.h:135
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, const TString &labText="")
Define new text attributes for the label number "labNum".
Definition TGaxis.cxx:2708
Float_t GetTickSize() const
Definition TGaxis.h:93
void SetWmin(Double_t wmin)
Definition TGaxis.h:134
void SetTickSize(Float_t ticksize)
Definition TGaxis.h:124
void SetLabelSize(Float_t labelsize)
Definition TGaxis.h:109
void SetOption(Option_t *option="")
To set axis options.
Definition TGaxis.cxx:2908
TGraph with asymmetric error bars.
A TGraphErrors is a TGraph with error bars.
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:2290
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition TGraph.cxx:832
TAxis * GetXaxis() const
Get x axis of the graph.
Definition TGraph.cxx:1566
TAxis * GetYaxis() const
Get y axis of the graph.
Definition TGraph.cxx:1575
void SetTitle(const char *title="") override
Change (i.e.
Definition TGraph.cxx:2345
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
Definition TH1.cxx:9166
static TClass * Class()
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
Definition TH1.cxx:9088
TAxis * GetXaxis()
Definition TH1.h:572
virtual Int_t GetNbinsX() const
Definition TH1.h:542
TAxis * GetYaxis()
Definition TH1.h:573
virtual Double_t GetBinErrorLow(Int_t bin) const
Return lower error associated to bin number bin.
Definition TH1.cxx:9104
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3037
TList * GetListOfFunctions() const
Definition TH1.h:489
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5063
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width for 1D histogram.
Definition TH1.cxx:9188
virtual Double_t GetBinErrorUp(Int_t bin) const
Return upper error associated to bin number bin.
Definition TH1.cxx:9135
virtual Int_t GetSumw2N() const
Definition TH1.h:563
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
Definition TH1.cxx:2723
The Histogram stack class.
Definition THStack.h:40
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:70
virtual void SetX2(Double_t x2)
Definition TLine.h:68
virtual void SetX1(Double_t x1)
Definition TLine.h:67
virtual void SetY1(Double_t y1)
Definition TLine.h:69
A doubly linked list.
Definition TList.h:38
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:354
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
Definition TNamed.cxx:73
Mother of all ROOT objects.
Definition TObject.h:41
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TObject.cxx:242
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:226
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:203
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:864
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:543
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:293
@ kCannotPick
if object in a pad cannot be picked
Definition TObject.h:73
The most important graphics class in the ROOT system.
Definition TPad.h:28
void SetGridx(Int_t value=1) override
Definition TPad.h:337
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:235
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:231
TList * GetListOfPrimitives() const override
Definition TPad.h:246
void SetFillStyle(Style_t fstyle) override
Override TAttFill::FillStyle for TPad because we want to handle style=0 as style 4000.
Definition TPad.cxx:6145
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:6242
void SetLogy(Int_t value=1) override
Set Lin/Log scale for Y.
Definition TPad.cxx:6171
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7459
void Add(TObject *obj, Option_t *opt="", Bool_t modified=kTRUE) override
Add an object to list of primitives with speicified draw option When.
Definition TPad.cxx:416
void SetGridy(Int_t value=1) override
Definition TPad.h:338
Double_t GetYlowNDC() const override
Definition TPad.h:214
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition TPad.cxx:691
Int_t GetLogy() const override
Definition TPad.h:258
void Draw(Option_t *option="") override
Draw Pad in Current pad (re-parent pad if necessary).
Definition TPad.cxx:1475
void SetLogx(Int_t value=1) override
Set Lin/Log scale for X.
Definition TPad.cxx:6157
Int_t GetLogx() const override
Definition TPad.h:257
Double_t GetHNDC() const override
Get height of pad along Y in Normalized Coordinates (NDC)
Definition TPad.h:218
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:865
virtual Bool_t HasConnection(const char *signal_name) const
Return true if there is any object connected to this signal.
Definition TQObject.cxx:523
Class for displaying ratios, differences and fit residuals.
Definition TRatioPlot.h:44
void SubPadResized()
Slot that handles common resizing of upper and lower pad.
@ kForceHideUp
Always hide the first label of the upper y axis.
Definition TRatioPlot.h:68
@ kHideUp
Hide the first label of the upper y axis when there is low space.
Definition TRatioPlot.h:65
@ kNoHide
Do not hide labels when there is low space.
Definition TRatioPlot.h:67
@ kHideLow
Hide the last label of the lower y axis when there is low space.
Definition TRatioPlot.h:66
@ kForceHideLow
Always hide the last label of the lower y axis.
Definition TRatioPlot.h:69
TGraphErrors * fConfidenceInterval2
Stores the graph for the 2 sigma band.
Definition TRatioPlot.h:97
TAxis * GetLowerRefXaxis() const
Gets the x axis of the lower ref graph.
Int_t fErrorMode
Stores the error mode, sym, asym or func.
Definition TRatioPlot.h:86
TAxis * GetLowerRefYaxis() const
Gets the y axis of the lower ref graph.
TGaxis * fUpperGXaxisMirror
Upper mirror of the x axis.
Definition TRatioPlot.h:116
TGaxis * fLowerGXaxisMirror
Lower mirror of the x axis.
Definition TRatioPlot.h:117
TAxis * GetUpperRefYaxis() const
Gets the y axis of the object returned by TRatioPlot::GetUpperRefObject.
Float_t fLowBottomMargin
Stores the bottom margin of the lower pad.
Definition TRatioPlot.h:134
void CreateGridlines()
Create a grid lines.
Int_t BuildLowerPlot()
Build the lower plot according to which constructor was called, and which options were passed.
void SetUpBottomMargin(Float_t margin)
Sets the bottom margin of the upper pad.
Float_t fUpBottomMargin
Stores the bottom margin of the upper pad.
Definition TRatioPlot.h:132
TH1 * fH1
Stores the primary histogram.
Definition TRatioPlot.h:80
void SetH2DrawOpt(Option_t *opt)
Sets the drawing option for h2.
TFitResult * fFitResult
Stores the explicit fit result given in the fit residual case. Can be 0.
Definition TRatioPlot.h:109
virtual Bool_t SyncPadMargins()
Figures out which pad margin has deviated from the stored ones, to figure out what the new nominal is...
virtual void UpdateVisualAxes()
Update TGaxis attributes.
Color_t fCi1Color
Stores the color for the 1 sigma band.
Definition TRatioPlot.h:98
TGaxis * fUpperGYaxis
Upper graphical y axis.
Definition TRatioPlot.h:114
Double_t fC2
Stores the scale factor for h2.
Definition TRatioPlot.h:107
void UpdateGridlines()
Update positions of grid lines.
void SetLowBottomMargin(Float_t margin)
Sets the bottom margin of the lower pad.
void SetConfidenceIntervalColors(Color_t ci1=kYellow, Color_t ci2=kGreen)
Set the confidence interval colors.
Double_t fC1
Stores the scale factor for h1 (or THStack sum)
Definition TRatioPlot.h:106
virtual void CreateVisualAxes()
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:133
TString fH2DrawOpt
Stores draw option for h2 given in constructor.
Definition TRatioPlot.h:89
void SetUpTopMargin(Float_t margin)
Sets the top margin of the upper pad.
TGaxis * fLowerGXaxis
Lower graphical x axis.
Definition TRatioPlot.h:113
TRatioPlot()
TRatioPlot default constructor.
Bool_t fIsUpdating
! Keeps track of whether its currently updating to reject other calls until done
Definition TRatioPlot.h:141
void SetGraphDrawOpt(Option_t *opt)
Sets the drawing option for the lower graph.
Double_t fCl1
Stores the confidence level for the inner confidence interval band.
Definition TRatioPlot.h:103
@ kErrorAsymmetric
Use TH1::GetBinErrorUp and TH1::GetBinErrorLow for the error, depending on y values.
Definition TRatioPlot.h:60
@ kErrorFunc
Use the square root of the function value as the error.
Definition TRatioPlot.h:61
@ kErrorSymmetric
Use the regular TH1::GetBinError as the error.
Definition TRatioPlot.h:59
Float_t GetSeparationMargin() const
Return the separation margin value.
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.
std::vector< TLine * > fGridlines
Keeps TLine objects for the gridlines.
Definition TRatioPlot.h:124
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:77
TAxis * fSharedXAxis
X axis that stores the range for both plots.
Definition TRatioPlot.h:111
TString fFitDrawOpt
Stores draw option for the fit function in the fit residual case.
Definition TRatioPlot.h:91
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:118
virtual void SetupPads()
Setup the pads.
TAxis * fUpYaxis
Clone of the upper y axis.
Definition TRatioPlot.h:121
TVirtualPad * fParentPad
Stores the pad the ratio plot was created in.
Definition TRatioPlot.h:75
Float_t fUpTopMargin
Stores the top margin of the upper pad.
Definition TRatioPlot.h:131
void SetH1DrawOpt(Option_t *opt)
Sets the drawing option for h1.
TGraph * fRatioGraph
Stores the lower plot's graph.
Definition TRatioPlot.h:95
virtual TGraph * GetLowerRefGraph() const
Returns the reference graph for the lower pad, which means the graph that is responsible for setting ...
virtual void ConnectPadsSignals()
Connect some signals from the pads to handle them Allows correctly work also after reading ratioplot ...
Int_t fMode
Stores which calculation is supposed to be performed as specified by user option.
Definition TRatioPlot.h:85
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:82
Float_t fRightMargin
Stores the common right margin of both pads.
Definition TRatioPlot.h:137
TGaxis * fLowerGYaxisMirror
Lower mirror of the y axis.
Definition TRatioPlot.h:119
Int_t fHideLabelMode
Stores which label to hide if the margin is to narrow, if at all.
Definition TRatioPlot.h:127
TPad * fTopPad
The Pad that drawn on top on the others to have consistent coordinates.
Definition TRatioPlot.h:78
void SetInsetWidth(Double_t width)
Set the inset on the outer sides of all the pads.
virtual void SyncAxesRanges()
Syncs the axes ranges from the shared ones to the actual ones.
void RangeAxisChanged()
Slot that receives the RangeAxisChanged signal from any of the pads and reacts correspondingly.
@ kDifference
Calculate the difference between the histograms.
Definition TRatioPlot.h:53
@ kDivideHist
Use TH1::Divide to create the ratio.
Definition TRatioPlot.h:51
@ kFitResidual
Calculate the fit residual between the histogram and a fit stored within it.
Definition TRatioPlot.h:54
@ kDifferenceSign
Calculate the difference divided by the error.
Definition TRatioPlot.h:55
@ kDivideGraph
Use TGraphAsymmErrors::Divide to create the ratio.
Definition TRatioPlot.h:52
void UnZoomed()
Slot for the UnZoomed signal that was introduced to TPad.
TH1 * fH2
Stores the secondary histogram, if there is one.
Definition TRatioPlot.h:81
Double_t fCl2
Stores the confidence level for the outer confidence interval band.
Definition TRatioPlot.h:104
TAxis * fLowYaxis
Clone of the lower y axis.
Definition TRatioPlot.h:122
TString fOption
Stores the option which is given in the constructor as a string.
Definition TRatioPlot.h:87
TPad * fUpperPad
The pad which contains the upper plot part.
Definition TRatioPlot.h:76
Bool_t fShowConfidenceIntervals
Stores whether to show the confidence interval bands. From Draw option.
Definition TRatioPlot.h:101
void SetLowTopMargin(Float_t margin)
Sets the top margin of the lower pad.
void SetSeparationMargin(Float_t)
Sets the margin that separates the two pads.
Bool_t fHistDrawProxyStack
If stack was assigned as proxy.
Definition TRatioPlot.h:83
Float_t fInsetWidth
Definition TRatioPlot.h:139
TAxis * GetXaxis() const
Definition TRatioPlot.h:187
void SetLeftMargin(Float_t margin)
Sets the left margin of both pads.
Float_t fLeftMargin
Stores the common left margin of both pads.
Definition TRatioPlot.h:136
TAxis * GetUpperRefXaxis() const
Gets the x axis of the object returned by TRatioPlot::GetUpperRefObject.
Float_t fSplitFraction
Stores the fraction at which the upper and lower pads meet.
Definition TRatioPlot.h:93
void Paint(Option_t *opt="") override
Update the visual axes and grid lines when painting.
virtual TObject * GetUpperRefObject() const
Return the reference object.
TGraphErrors * fConfidenceInterval1
Stores the graph for the 1 sigma band.
Definition TRatioPlot.h:96
TGaxis * fUpperGXaxis
Upper graphical x axis.
Definition TRatioPlot.h:112
std::vector< double > fGridlinePositions
Stores the y positions for the gridlines.
Definition TRatioPlot.h:125
TString fH1DrawOpt
Stores draw option for h1 given in constructor.
Definition TRatioPlot.h:88
virtual void Init(TH1 *h1, TH1 *h2, Option_t *option="")
Internal method that shares constructor logic.
Bool_t fShowGridlines
Stores whether to show the gridlines at all.
Definition TRatioPlot.h:126
void Draw(Option_t *chopt="") override
Draws the ratio plot to the currently active pad.
TString fGraphDrawOpt
Stores draw option for the lower plot graph given in constructor.
Definition TRatioPlot.h:90
~TRatioPlot() override
Destructor.
Color_t fCi2Color
Stores the color for the 2 sigma band.
Definition TRatioPlot.h:99
void SetRightMargin(Float_t margin)
Sets the right margin of both pads.
TGaxis * fLowerGYaxis
Lower graphical y axis.
Definition TRatioPlot.h:115
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:138
const char * Data() const
Definition TString.h:384
static TVirtualFitter * GetFitter()
static: return the current Fitter
virtual void Modified(Bool_t flag=1)=0
virtual void SetLogx(Int_t value=1)=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
TGraphErrors * gr
Definition legend1.C:25
TH1F * h1
Definition legend1.C:5
return c2
Definition legend2.C:14
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:727