Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
remove draw opts from constructors and add setters
  • Loading branch information
paulgessinger committed Aug 31, 2016
commit 77d69cfec1472e33b9bfe0b2da1aea3ebe208ec0
12 changes: 7 additions & 5 deletions graf2d/gpad/inc/TRatioPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,21 @@ class TRatioPlot : public TObject {

Bool_t IsDrawn();

virtual void Init(TH1* h1, TH1* h2, Option_t *option = "", Option_t *h1DrawOpt = "hist", Option_t *h2DrawOpt = "E", Option_t *graphDrawOpt = "AP");
virtual void Init(TH1* h1, TH1* h2, Option_t *option = "");

public:

TRatioPlot();
virtual ~TRatioPlot();
TRatioPlot(TH1* h1, TH1* h2, Option_t *option = "pois", Option_t *h1DrawOpt = "hist", Option_t *h2DrawOpt = "E", Option_t *graphDrawOpt = "AP");
TRatioPlot(TH1* h1, TH1* h2, Option_t *option = "pois");

TRatioPlot(THStack* st, TH1* h2, Option_t *option = "pois", Option_t *h1DrawOpt = "hist", Option_t *h2DrawOpt = "E", Option_t *graphDrawOpt = "AP");

TRatioPlot(TH1* h1, Option_t *option = "", Option_t *h1DrawOpt = "", Option_t *graphDrawOpt = "LX", TFitResult *fitres = 0);
TRatioPlot(THStack* st, TH1* h2, Option_t *option = "pois");

TRatioPlot(TH1* h1, Option_t *option = "", TFitResult *fitres = 0);

void SetH1DrawOpt(Option_t *opt);
void SetH2DrawOpt(Option_t *opt);
void SetGraphDrawOpt(Option_t *opt);

virtual void Draw(Option_t *chopt="");
virtual void Browse(TBrowser *b);
Expand Down
58 changes: 38 additions & 20 deletions graf2d/gpad/src/TRatioPlot.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ TRatioPlot::~TRatioPlot()
////////////////////////////////////////////////////////////////////////////////
/// Internal method that shares constructor logic

void TRatioPlot::Init(TH1* h1, TH1* h2,
Option_t *option, Option_t *h1DrawOpt, Option_t *h2DrawOpt, Option_t *graphDrawOpt)
void TRatioPlot::Init(TH1* h1, TH1* h2,Option_t *option)
{

fH1 = h1;
Expand Down Expand Up @@ -185,16 +184,10 @@ void TRatioPlot::Init(TH1* h1, TH1* h2,

fOption = optionString;

TString h1DrawOptString = TString(h1DrawOpt);
TString h2DrawOptString = TString(h2DrawOpt);
TString graphDrawOptString = TString(graphDrawOpt);

h2DrawOptString.ReplaceAll("same", "");
h2DrawOptString.ReplaceAll("SAME", "");

fH1DrawOpt = h1DrawOptString;
fH2DrawOpt = h2DrawOptString;
fGraphDrawOpt = graphDrawOptString;
fH1DrawOpt = "hist";
fH2DrawOpt = "E";
fGraphDrawOpt = "AP";


// build ratio, everything is ready
Expand All @@ -218,8 +211,7 @@ void TRatioPlot::Init(TH1* h1, TH1* h2,
/// \param name Name for the object
/// \param title Title for the object

TRatioPlot::TRatioPlot(TH1* h1, TH1* h2, Option_t *option, Option_t *h1DrawOpt, Option_t *h2DrawOpt,
Option_t *graphDrawOpt)
TRatioPlot::TRatioPlot(TH1* h1, TH1* h2, Option_t *option)
: fGridlines()
{
gROOT->GetListOfCleanups()->Add(this);
Expand All @@ -239,7 +231,7 @@ TRatioPlot::TRatioPlot(TH1* h1, TH1* h2, Option_t *option, Option_t *h1DrawOpt,

fHistDrawProxy = h1;

Init(h1, h2, option, h1DrawOpt, h2DrawOpt, graphDrawOpt);
Init(h1, h2, option);

}

Expand All @@ -256,8 +248,7 @@ TRatioPlot::TRatioPlot(TH1* h1, TH1* h2, Option_t *option, Option_t *h1DrawOpt,
/// \param name The name of the object
/// \param title The title of the object

TRatioPlot::TRatioPlot(THStack* st, TH1* h2, Option_t *option, Option_t *h1DrawOpt, Option_t *h2DrawOpt,
Option_t *graphDrawOpt)
TRatioPlot::TRatioPlot(THStack* st, TH1* h2, Option_t *option)
{
if (!st || !h2) {
Warning("TRatioPlot", "Need a histogram and a stack");
Expand All @@ -280,7 +271,7 @@ TRatioPlot::TRatioPlot(THStack* st, TH1* h2, Option_t *option, Option_t *h1DrawO

fHistDrawProxy = st;

Init(tmpHist, h2, option, h1DrawOpt, h2DrawOpt, graphDrawOpt);
Init(tmpHist, h2, option);

}

Expand All @@ -294,7 +285,7 @@ TRatioPlot::TRatioPlot(THStack* st, TH1* h2, Option_t *option, Option_t *h1DrawO
/// \param name Name for the object
/// \param title Title for the object

TRatioPlot::TRatioPlot(TH1* h1, Option_t *option, Option_t *h1DrawOpt, Option_t *graphDrawOpt, TFitResult *fitres)
TRatioPlot::TRatioPlot(TH1* h1, Option_t *option, TFitResult *fitres)
: fH1(h1),
fGridlines()
{
Expand Down Expand Up @@ -343,8 +334,7 @@ TRatioPlot::TRatioPlot(TH1* h1, Option_t *option, Option_t *h1DrawOpt, Option_t

BuildLowerPlot();

fH1DrawOpt = h1DrawOpt;
fGraphDrawOpt = graphDrawOpt;
fGraphDrawOpt = "LX"; // <- default

fSharedXAxis = (TAxis*)(fH1->GetXaxis()->Clone());
fUpYaxis = (TAxis*)(fH1->GetYaxis()->Clone());
Expand All @@ -356,6 +346,34 @@ TRatioPlot::TRatioPlot(TH1* h1, Option_t *option, Option_t *h1DrawOpt, Option_t

}

////////////////////////////////////////////////////////////////////////////////
/// Sets the drawing option for h1

void TRatioPlot::SetH1DrawOpt(Option_t *opt)
{
fH1DrawOpt = opt;
}

////////////////////////////////////////////////////////////////////////////////
/// Sets the drawing option for h2

void TRatioPlot::SetH2DrawOpt(Option_t *opt)
{
TString optString = TString(opt);
optString.ReplaceAll("same", "");
optString.ReplaceAll("SAME", "");

fH2DrawOpt = optString;
}

////////////////////////////////////////////////////////////////////////////////
/// Sets the drawing option for the lower graph

void TRatioPlot::SetGraphDrawOpt(Option_t *opt)
{
fGraphDrawOpt = opt;
}

////////////////////////////////////////////////////////////////////////////////
/// Setup the pads.

Expand Down
3 changes: 2 additions & 1 deletion tutorials/hist/ratioplot6.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

c1->Clear();

auto rp1 = new TRatioPlot(h1, "errfunc", "", "L");
auto rp1 = new TRatioPlot(h1, "errfunc");
rp1->SetGraphDrawOpt("L");
rp1->SetSeparationMargin(0.0);
rp1->Draw();
rp1->GetLowerRefGraph()->SetMinimum(-2);
Expand Down