Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
37 changes: 22 additions & 15 deletions graf2d/gpad/inc/TRatioPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@
// //
//////////////////////////////////////////////////////////////////////////

class TObject;
#ifndef ROOT_TObject
#include "TObject.h"
#endif

#ifndef ROOT_TString
#include "TString.h"
#endif

class TH1;
class TPad;
class TVirtualPad;
class TGraphAsymmErrors;
class TGraphErrors;
class TGraph;
Expand Down Expand Up @@ -138,6 +146,7 @@ class TRatioPlot : public TObject {
virtual Bool_t SyncPadMargins();
void SetPadMargins();
void CreateGridline();
void BuildLowerPlot();

void ImportAxisAttributes(TGaxis* gaxis, TAxis* axis);

Expand All @@ -162,7 +171,6 @@ class TRatioPlot : public TObject {
virtual void Draw(Option_t *chopt="");
virtual void Browse(TBrowser *b);

virtual void BuildLowerPlot();

virtual void Paint(Option_t *opt = "");

Expand All @@ -172,24 +180,23 @@ class TRatioPlot : public TObject {
void SubPadResized();

// Getters
TAxis *GetXaxis() { return fSharedXAxis; }
TAxis *GetUpYaxis() { return fUpYaxis; }
TAxis *GetLowYaxis() { return fLowYaxis; }
TAxis *GetXaxis() const { return fSharedXAxis; }
TAxis *GetUpYaxis() const { return fUpYaxis; }
TAxis *GetLowYaxis() const { return fLowYaxis; }

virtual TGraph *GetLowerRefGraph();
TAxis *GetLowerRefXaxis();
TAxis *GetLowerRefYaxis();
virtual TGraph *GetLowerRefGraph() const;
TAxis *GetLowerRefXaxis() const;
TAxis *GetLowerRefYaxis() const;

virtual TObject *GetUpperRefObject();
TAxis *GetUpperRefXaxis();
TAxis *GetUpperRefYaxis();
virtual TObject *GetUpperRefObject() const;
TAxis *GetUpperRefXaxis() const;
TAxis *GetUpperRefYaxis() const;

TPad * GetUpperPad() { return fUpperPad; }
TPad * GetLowerPad() { return fLowerPad; }
TPad * GetUpperPad() const { return fUpperPad; }
TPad * GetLowerPad() const { return fLowerPad; }

// Setters
void SetFitResult(TFitResultPtr fitres);
void SetFitResult(TFitResult *fitres);

// Setters for margins
void SetUpTopMargin(Float_t margin);
Expand All @@ -200,7 +207,7 @@ class TRatioPlot : public TObject {
void SetRightMargin(Float_t margin);

void SetSeparationMargin(Float_t);
Float_t GetSeparationMargin();
Float_t GetSeparationMargin() const;
void SetSplitFraction(Float_t sf);
void SetConfidenceLevels(Double_t cl1, Double_t cl2);

Expand Down
104 changes: 61 additions & 43 deletions graf2d/gpad/src/TRatioPlot.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,74 @@
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

#include <iostream>
#include "TRatioPlot.h"

#ifndef ROOT_TROOT
#include "TROOT.h"
#endif

#ifndef ROOT_TClassRef
#include "TClassRef.h"
#endif

#ifndef ROOT_TVirtualPad
#include "TVirtualPad.h"
#include "TRatioPlot.h"
#endif

#ifndef ROOT_TBrowser
#include "TBrowser.h"
#endif

#ifndef ROOT_TH1
#include "TH1.h"
#endif

#ifndef ROOT_TF1
#include "TF1.h"
#endif

#ifndef ROOT_TPad
#include "TPad.h"
#endif

#ifndef ROOT_TString
#include "TString.h"
#endif

#ifndef ROOT_TMath
#include "TMath.h"
#endif

#ifndef ROOT_TGraphAsymmErrors
#include "TGraphAsymmErrors.h"
#endif

#ifndef ROOT_TGraphErrors
#include "TGraphErrors.h"
#endif

#ifndef ROOT_TGaxis
#include "TGaxis.h"
#include "TCanvas.h"
#include "TFrame.h"
#include "TMath.h"
#endif

#ifndef ROOT_TLine
#include "TLine.h"
#endif

#ifndef ROOT_TVirtualFitter
#include "TVirtualFitter.h"
#endif

#ifndef ROOT_TFitResult
#include "TFitResult.h"
#endif

#ifndef ROOT_THStack
#include "THStack.h"
#endif

#include <iostream>

#define _(x) std::cout << #x;
#define __(x) std::cout << "[" << std::string(__FILE__).substr(std::string(__FILE__).find_last_of("/\\") + 1) << ":" <<__LINE__ << "] " << x << std::endl ;
#define var_dump(v) __(#v << "=" << (v));

/** \class TRatioPlot
\ingroup gpad
Expand Down Expand Up @@ -203,11 +247,6 @@ void TRatioPlot::Init(TH1* h1, TH1* h2,Option_t *option)
/// \param h1 First histogram
/// \param h2 Second histogram
/// \param option Steers the error calculation, as well as ratio / difference
/// \param h1DrawOpt Drawing option for first histogram
/// \param h2DrawOpt Drawing option for second histogram
/// \param graphDrawOpt Drawing option the lower graph
/// \param name Name for the object
/// \param title Title for the object

TRatioPlot::TRatioPlot(TH1* h1, TH1* h2, Option_t *option)
: fGridlines()
Expand Down Expand Up @@ -240,11 +279,6 @@ TRatioPlot::TRatioPlot(TH1* h1, TH1* h2, Option_t *option)
/// \param st The THStack object
/// \param h2 The other histogram
/// \param option Steers the calculation of the lower plot
/// \param h1DrawOpt Drawing option for the stack
/// \param h2DrawOpt Drawing options for the other histogram
/// \param graphDrawOpt Drawing option for the lower plot graph
/// \param name The name of the object
/// \param title The title of the object

TRatioPlot::TRatioPlot(THStack* st, TH1* h2, Option_t *option)
{
Expand Down Expand Up @@ -277,11 +311,7 @@ TRatioPlot::TRatioPlot(THStack* st, TH1* h2, Option_t *option)
/// Constructor for one histogram and a fit.
/// \param h1 The histogram
/// \param option Steers the error calculation
/// \param h1DrawOpt Drawing option for the histogram
/// \param graphDrawOpt Drawing option the lower graph
/// \param fitres Explicit fit result to be used for calculation. Uses last fit if left empty
/// \param name Name for the object
/// \param title Title for the object

TRatioPlot::TRatioPlot(TH1* h1, Option_t *option, TFitResult *fitres)
: fH1(h1),
Expand Down Expand Up @@ -521,7 +551,7 @@ void TRatioPlot::SetSeparationMargin(Float_t margin)
////////////////////////////////////////////////////////////////////////////////
/// Return the separation margin value.

Float_t TRatioPlot::GetSeparationMargin()
Float_t TRatioPlot::GetSeparationMargin() const
{
Float_t sf = fSplitFraction;
Float_t up = fUpBottomMargin * (1-sf);
Expand Down Expand Up @@ -666,7 +696,7 @@ void TRatioPlot::Draw(Option_t *option)
/// ../../../tutorials/hist/ratioplot3.C
/// End_Macro

TGraph* TRatioPlot::GetLowerRefGraph()
TGraph* TRatioPlot::GetLowerRefGraph() const
{
if (fLowerPad == 0) {
Error("GetLowerRefGraph", "Lower pad has not been defined");
Expand Down Expand Up @@ -702,7 +732,7 @@ TGraph* TRatioPlot::GetLowerRefGraph()
/// rp->GetLowerRefGraph()->GetXaxis();
/// ~~~

TAxis* TRatioPlot::GetLowerRefXaxis()
TAxis* TRatioPlot::GetLowerRefXaxis() const
{
return GetLowerRefGraph()->GetXaxis();
}
Expand All @@ -714,7 +744,7 @@ TAxis* TRatioPlot::GetLowerRefXaxis()
/// rp->GetLowerRefGraph()->GetYaxis();
/// ~~~

TAxis* TRatioPlot::GetLowerRefYaxis()
TAxis* TRatioPlot::GetLowerRefYaxis() const
Copy link
Member

Choose a reason for hiding this comment

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

These trivial one-liners could be inlined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@karies But can I write doxygen comments if they're inline? That's why I put them out-of-line

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you can write doxygen also for inline funcs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok. I'll inline them then.

{
return GetLowerRefGraph()->GetYaxis();
}
Expand All @@ -724,7 +754,7 @@ TAxis* TRatioPlot::GetLowerRefYaxis()
/// in the upper pads list of primitives.
/// Note that it returns a `TObject`, so you need to test and cast it to use it.

TObject* TRatioPlot::GetUpperRefObject()
TObject* TRatioPlot::GetUpperRefObject() const
{
TList *primlist = fUpperPad->GetListOfPrimitives();
TObject *refobj = 0;
Expand All @@ -742,7 +772,7 @@ TObject* TRatioPlot::GetUpperRefObject()
////////////////////////////////////////////////////////////////////////////////
/// Gets the x axis of the object returned by `TRatioPlot::GetUpperRefObject`.

TAxis* TRatioPlot::GetUpperRefXaxis()
TAxis* TRatioPlot::GetUpperRefXaxis() const
{
TObject *refobj = GetUpperRefObject();

Expand All @@ -760,7 +790,7 @@ TAxis* TRatioPlot::GetUpperRefXaxis()
////////////////////////////////////////////////////////////////////////////////
/// Gets the y axis of the object returned by `TRatioPlot::GetUpperRefObject`.

TAxis* TRatioPlot::GetUpperRefYaxis()
TAxis* TRatioPlot::GetUpperRefYaxis() const
{
TObject *refobj = GetUpperRefObject();

Expand Down Expand Up @@ -1674,13 +1704,13 @@ void TRatioPlot::SetSplitFraction(Float_t sf) {

////////////////////////////////////////////////////////////////////////////////
/// Sets the confidence levels used to calculate the bands in the fit residual
/// case. Defaults to 1 and 2 sigma. You have to call TRatioPlot::BuildLowerPlot
/// to rebuild the bands.
/// case. Defaults to 1 and 2 sigma.

void TRatioPlot::SetConfidenceLevels(Double_t c1, Double_t c2)
{
fCl1 = c1;
fCl2 = c2;
BuildLowerPlot();
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1739,18 +1769,6 @@ void TRatioPlot::SetFitResult(TFitResultPtr fitres)
fFitResult = fitres.Get();
}

////////////////////////////////////////////////////////////////////////////////
/// Explicitly specify the fit result that is to be used for fit residual calculation.
/// If it is not provided, the last fit registered in the global fitter is used.
/// The fit result can also be specified in the constructor.
///
/// \param fitres The fit result coming from the fit function call

void TRatioPlot::SetFitResult(TFitResult* fitres)
{
fFitResult = fitres;
}

////////////////////////////////////////////////////////////////////////////////
/// Internal method to import TAxis attributes to a TGaxis. Copied from
/// `TGaxis::ImportAxisAttributes`
Expand Down