diff --git a/graf2d/gpad/inc/TRatioPlot.h b/graf2d/gpad/inc/TRatioPlot.h index e8cf43c391a01..c65f3eb50ceda 100644 --- a/graf2d/gpad/inc/TRatioPlot.h +++ b/graf2d/gpad/inc/TRatioPlot.h @@ -50,8 +50,8 @@ class TFileMergeInfo; class TRatioPlot : public TObject { private: - TRatioPlot& operator=(const TRatioPlot&); // Not implemented - TRatioPlot(const TRatioPlot &hrp); + TRatioPlot& operator=(const TRatioPlot&) = delete; // Not implemented + TRatioPlot(const TRatioPlot &hrp) = delete; enum CalculationMode { kDivideHist = 1, ///< Use `TH1::Divide` to create the ratio. @@ -141,6 +141,8 @@ class TRatioPlot : public TObject { Float_t fLeftMargin = 0.1; ///< Stores the common left margin of both pads Float_t fRightMargin = 0.1; ///< Stores the common right margin of both pads + Float_t fInsetWidth = 0.0025; + Bool_t fIsUpdating = kFALSE; ///< Keeps track of whether its currently updating to reject other calls until done Bool_t fIsPadUpdating = kFALSE; ///< Keeps track whether pads are updating during resizing @@ -173,6 +175,8 @@ class TRatioPlot : public TObject { void SetGraphDrawOpt(Option_t *opt); void SetFitDrawOpt(Option_t *opt); + void SetInsetWidth(Double_t width); + virtual void Draw(Option_t *chopt=""); virtual void Browse(TBrowser *b); @@ -199,14 +203,14 @@ class TRatioPlot : public TObject { /// ~~~ TAxis *GetLowerRefXaxis() const { return GetLowerRefGraph()->GetXaxis(); } - + //////////////////////////////////////////////////////////////////////////////// /// Shortcut for: /// /// ~~~{.cpp} /// rp->GetLowerRefGraph()->GetYaxis(); /// ~~~ - + TAxis *GetLowerRefYaxis() const { return GetLowerRefGraph()->GetYaxis(); } virtual TObject *GetUpperRefObject() const; @@ -240,8 +244,8 @@ class TRatioPlot : public TObject { void SetSplitFraction(Float_t sf); void SetConfidenceLevels(Double_t cl1, Double_t cl2); - virtual void SetGridlines(Double_t *gridlines, Int_t numGridlines); - virtual void SetGridlines(std::vector gridlines); + virtual void SetGridlines(Double_t *gridlines, Int_t numGridlines); + virtual void SetGridlines(std::vector gridlines); void SetConfidenceIntervalColors(Color_t ci1 = kGreen, Color_t ci2 = kYellow); diff --git a/graf2d/gpad/src/TRatioPlot.cxx b/graf2d/gpad/src/TRatioPlot.cxx index 8b0be86fea373..fdf1831c0db38 100644 --- a/graf2d/gpad/src/TRatioPlot.cxx +++ b/graf2d/gpad/src/TRatioPlot.cxx @@ -127,7 +127,7 @@ Begin_Macro(source) End_Macro ## Error options for difference divided by uncertainty and fit residual -The uncertainty that is used in the calculation can be steered by providing +The uncertainty that is used in the calculation can be steered by providing options to the `option` argument. | Option | Description | @@ -434,8 +434,13 @@ void TRatioPlot::SetupPads() { fLowerPad = 0; } - fUpperPad = new TPad("upper_pad", "", 0., fSplitFraction, 1., 1.); - fLowerPad = new TPad("lower_pad", "", 0., 0., 1., fSplitFraction); + double pm = fInsetWidth; + double width = gPad->GetWNDC(); + double height = gPad->GetHNDC(); + double f = height/width; + + fUpperPad = new TPad("upper_pad", "", pm*f, fSplitFraction, 1.-pm*f, 1.-pm); + fLowerPad = new TPad("lower_pad", "", pm*f, pm, 1.-pm*f, fSplitFraction); SetPadMargins(); @@ -455,22 +460,12 @@ void TRatioPlot::SetupPads() { fTopPad = 0; } - Double_t margin = 0; - fTopPad = new TPad("top_pad", "", margin, margin, 1-margin, 1-margin); + fTopPad = new TPad("top_pad", "", pm*f, pm, 1-pm*f, 1-pm); fTopPad->SetBit(kCannotPick); } -//////////////////////////////////////////////////////////////////////////////// -/// TRatioPlot copy constructor - -TRatioPlot::TRatioPlot(const TRatioPlot &/*hrp*/) : TObject() -{ - Warning("TRatioPlot", "Copy constructor not yet implemented"); - return; -} - //////////////////////////////////////////////////////////////////////////////// /// Browse. @@ -658,11 +653,11 @@ void TRatioPlot::Draw(Option_t *option) fLowerPad->cd(); if (fShowConfidenceIntervals) { - fConfidenceInterval2->Draw("A3"); + fConfidenceInterval2->Draw("IA3"); fConfidenceInterval1->Draw("3"); fRatioGraph->Draw(fGraphDrawOpt+"SAME"); } else { - fRatioGraph->Draw("A"+fGraphDrawOpt+"SAME"); + fRatioGraph->Draw("IA"+fGraphDrawOpt+"SAME"); } } else { @@ -681,7 +676,7 @@ void TRatioPlot::Draw(Option_t *option) fLowerPad->cd(); TString opt = fGraphDrawOpt; - fRatioGraph->Draw("A"+fGraphDrawOpt); + fRatioGraph->Draw("IA"+fGraphDrawOpt); } @@ -876,17 +871,6 @@ void TRatioPlot::CreateGridline() void TRatioPlot::Paint(Option_t * /*opt*/) { - // hide lower axes - TAxis *refx = GetLowerRefXaxis(); - TAxis *refy = GetLowerRefYaxis(); - - refx->SetTickSize(0.); - refx->SetLabelSize(0.); - refx->SetTitleSize(0.); - refy->SetTickSize(0.); - refy->SetLabelSize(0.); - refy->SetTitleSize(0.); - // create the visual axes CreateVisualAxes(); CreateGridline(); @@ -1235,10 +1219,13 @@ void TRatioPlot::CreateVisualAxes() } // import infos from TAxis - ImportAxisAttributes(fUpperGXaxis, fSharedXAxis); - ImportAxisAttributes(fUpperGYaxis, fUpYaxis); - ImportAxisAttributes(fLowerGXaxis, fSharedXAxis); - ImportAxisAttributes(fLowerGYaxis, fLowYaxis); + ImportAxisAttributes(fUpperGXaxis, GetUpperRefXaxis()); + ImportAxisAttributes(fUpperGYaxis, GetUpperRefYaxis()); + ImportAxisAttributes(fLowerGXaxis, GetLowerRefXaxis()); + ImportAxisAttributes(fLowerGYaxis, GetLowerRefYaxis()); + + // lower x axis needs to get title from upper x + fLowerGXaxis->SetTitle(fUpperGXaxis->GetTitle()); // (re)set all the axes properties to what we want them fUpperGXaxis->SetTitle(""); @@ -1345,10 +1332,11 @@ void TRatioPlot::CreateVisualAxes() } // import attributes from shared axes - ImportAxisAttributes(fUpperGXaxisMirror, fSharedXAxis); - ImportAxisAttributes(fUpperGYaxisMirror, fUpYaxis); - ImportAxisAttributes(fLowerGXaxisMirror, fSharedXAxis); - ImportAxisAttributes(fLowerGYaxisMirror, fLowYaxis); + ImportAxisAttributes(fUpperGXaxisMirror, GetUpperRefXaxis()); + ImportAxisAttributes(fUpperGYaxisMirror, GetUpperRefYaxis()); + ImportAxisAttributes(fLowerGXaxisMirror, GetLowerRefXaxis()); + ImportAxisAttributes(fLowerGYaxisMirror, GetLowerRefYaxis()); + // remove titles fUpperGXaxisMirror->SetTitle(""); @@ -1647,10 +1635,42 @@ Bool_t TRatioPlot::IsDrawn() //////////////////////////////////////////////////////////////////////////////// /// Set the fraction of the parent pad, at which the to sub pads should meet -void TRatioPlot::SetSplitFraction(Float_t sf) { +void TRatioPlot::SetSplitFraction(Float_t sf) +{ + if (fParentPad == 0) { + Warning("SetSplitFraction", "Can only be used after TRatioPlot has been drawn."); + return; + } + fSplitFraction = sf; - fUpperPad->SetPad(0., fSplitFraction, 1., 1.); - fLowerPad->SetPad(0., 0., 1., fSplitFraction); + double pm = fInsetWidth; + double width = fParentPad->GetWNDC(); + double height = fParentPad->GetHNDC(); + double f = height/width; + + fUpperPad->SetPad(pm*f, fSplitFraction, 1.-pm*f, 1.-pm); + fLowerPad->SetPad(pm*f, pm, 1.-pm*f, fSplitFraction); +} + +//////////////////////////////////////////////////////////////////////////////// +/// Set the inset on the outer sides of all the pads. It's used to make the outer +/// pad draggable. + +void TRatioPlot::SetInsetWidth(Double_t width) +{ + if (fParentPad == 0) { + Warning("SetInsetWidth", "Can only be used after TRatioPlot has been drawn."); + return; + } + + fInsetWidth = width; + SetSplitFraction(fSplitFraction); + + double pm = fInsetWidth; + double w = fParentPad->GetWNDC(); + double h = fParentPad->GetHNDC(); + double f = h/w; + fTopPad->SetPad(pm*f, pm, 1-pm*f, 1-pm); } //////////////////////////////////////////////////////////////////////////////// diff --git a/tutorials/hist/ratioplot2.C b/tutorials/hist/ratioplot2.C index be3b7008c927d..d3ed9f019667b 100644 --- a/tutorials/hist/ratioplot2.C +++ b/tutorials/hist/ratioplot2.C @@ -24,7 +24,7 @@ void ratioplot2() { c1->Clear(); // Fit does not draw into correct pad auto rp1 = new TRatioPlot(h1); rp1->Draw(); - rp1->GetLowYaxis()->SetTitle("ratio"); - rp1->GetUpYaxis()->SetTitle("entries"); + rp1->GetLowerRefYaxis()->SetTitle("ratio"); + rp1->GetUpperRefYaxis()->SetTitle("entries"); c1->Update(); }