Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions graf2d/gpad/inc/TRatioPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor Author

@paulgessinger paulgessinger Sep 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karies Like this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks!


enum CalculationMode {
kDivideHist = 1, ///< Use `TH1::Divide` to create the ratio.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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<double> gridlines);
virtual void SetGridlines(Double_t *gridlines, Int_t numGridlines);
virtual void SetGridlines(std::vector<double> gridlines);

void SetConfidenceIntervalColors(Color_t ci1 = kGreen, Color_t ci2 = kYellow);

Expand Down
98 changes: 59 additions & 39 deletions graf2d/gpad/src/TRatioPlot.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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();
Expand All @@ -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.

Expand Down Expand Up @@ -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 {

Expand All @@ -681,7 +676,7 @@ void TRatioPlot::Draw(Option_t *option)
fLowerPad->cd();

TString opt = fGraphDrawOpt;
fRatioGraph->Draw("A"+fGraphDrawOpt);
fRatioGraph->Draw("IA"+fGraphDrawOpt);

}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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("");
Expand Down Expand Up @@ -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("");
Expand Down Expand Up @@ -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);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions tutorials/hist/ratioplot2.C
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}