143 TString optionString = option;
145 if (optionString.
Contains(
"divsym")) {
148 }
else if (optionString.
Contains(
"diffsig")) {
153 if (optionString.
Contains(
"errasym")) {
158 if (optionString.
Contains(
"errfunc")) {
162 }
else if (optionString.
Contains(
"diff")) {
196 Warning(
"TRatioPlot",
"Need two histograms.");
203 if (!h1IsTH1 && !h2IsTH1) {
204 Warning(
"TRatioPlot",
"Need two histograms deriving from TH2 or TH3.");
225 Warning(
"TRatioPlot",
"Need a histogram and a stack");
231 if (stackHists->
GetSize() == 0) {
232 Warning(
"TRatioPlot",
"Stack does not have histograms");
236 auto tmpHist =
static_cast<TH1 *
>(stackHists->
At(0)->
Clone());
239 for (
int i = 0; i < stackHists->
GetSize(); ++i) {
240 tmpHist->Add(
static_cast<TH1 *
>(stackHists->
At(i)));
244 fHistDrawProxyStack =
kTRUE;
246 Init(tmpHist, h2, option);
261 Warning(
"TRatioPlot",
"Need a histogram and a stack");
267 if (stackHists->
GetSize() == 0) {
268 Warning(
"TRatioPlot",
"Stack does not have histograms");
272 auto tmpHist =
static_cast<TH1 *
>(stackHists->
At(0)->
Clone());
275 for (
int i = 0; i < stackHists->
GetSize(); ++i) {
276 tmpHist->Add(
static_cast<TH1 *
>(stackHists->
At(i)));
281 Init(
h1, tmpHist, option);
296 Warning(
"TRatioPlot",
"Need a histogram.");
303 Warning(
"TRatioPlot",
"Need a histogram deriving from TH2 or TH3.");
307 TList *h1Functions = fH1->GetListOfFunctions();
309 if (h1Functions->
GetSize() < 1) {
310 Warning(
"TRatioPlot",
"Histogram given needs to have a (fit) function associated with it");
319 fMode = CalculationMode::kFitResidual;
325 fErrorMode = ErrorMode::kErrorAsymmetric;
326 optionString.ReplaceAll(
"errasym",
"");
330 fErrorMode = ErrorMode::kErrorFunc;
331 optionString.ReplaceAll(
"errfunc",
"");
334 fOption = optionString;
336 if (!BuildLowerPlot())
return;
339 if (fH1->GetSumw2N() > 0) {
344 fGraphDrawOpt =
"LX";
346 fSharedXAxis =
static_cast<TAxis *
>(fH1->GetXaxis()->Clone());
347 fUpYaxis =
static_cast<TAxis *
>(fH1->GetYaxis()->Clone());
348 fLowYaxis =
static_cast<TAxis *
>(fRatioGraph->GetYaxis()->Clone());
369 TString optString = opt;
410 Error(
"SetupPads",
"need to create a canvas first");
415 double width =
gPad->GetWNDC();
416 double height =
gPad->GetHNDC();
417 double f = height/width;
431 fTopPad =
new TPad(
"top_pad",
"", pm*
f, pm, 1-pm*
f, 1-pm);
442 static const char *rangeSignal =
"RangeAxisChanged()";
572 TString drawOpt = option;
577 }
else if (drawOpt.
Contains(
"grid")) {
582 if (drawOpt.
Contains(
"noconfint")) {
585 }
else if (drawOpt.
Contains(
"confint")) {
592 }
else if (drawOpt.
Contains(
"fhidelow")) {
594 }
else if (drawOpt.
Contains(
"hideup")) {
596 }
else if (drawOpt.
Contains(
"hidelow")) {
598 }
else if (drawOpt.
Contains(
"nohide")) {
605 Error(
"Draw",
"need to create a canvas first");
640 for (
int i =
fH1->GetListOfFunctions()->GetSize()-1; i >= 0; i--) {
641 auto obj =
fH1->GetListOfFunctions()->At(i);
643 func =
dynamic_cast<TF1*
>(obj);
649 Error(
"Draw",
"h1 does not have a fit function");
671 Warning(
"Draw",
"Draw proxy not of type TH1 or THStack, not drawing it");
714 Error(
"GetLowerRefGraph",
"Lower pad has not been defined");
718 TList *primlist =
fLowerPad->GetListOfPrimitives();
719 if (primlist->
GetSize() == 0) {
720 Error(
"GetLowerRefGraph",
"Lower pad does not have primitives");
730 return static_cast<TGraph *
>(obj);
735 Error(
"GetLowerRefGraph",
"Did not find graph in list");
746 TList *primlist =
fUpperPad->GetListOfPrimitives();
748 auto refobj = primlist->
At(i);
754 Error(
"GetUpperRefObject",
"No upper ref object of TH1 or THStack type found");
769 return static_cast<TH1 *
>(refobj)->
GetXaxis();
771 return static_cast<THStack *
>(refobj)->
GetXaxis();
788 return static_cast<TH1 *
>(refobj)->GetYaxis();
790 return static_cast<THStack *
>(refobj)->GetYaxis();
834 TLine *newline =
new TLine(0, 0, 0, 0);
854 for (
size_t i = 0; i <
fGridlines.size(); ++i) {
860 visible = (
y >= lowYFirst &&
y <= lowYLast);
920 static const char *thisMethod =
"BuildLowerPlot";
934 static Double_t divideGridlines[] = {0.7, 1.0, 1.3};
935 static Double_t diffGridlines[] = {0.0};
936 static Double_t signGridlines[] = {1.0, 0.0, -1.0};
945 TH1 *tmpH1 =
static_cast<TH1 *
>(
fH1->Clone());
946 TH1 *tmpH2 =
static_cast<TH1 *
>(
fH2->Clone());
951 TGraphAsymmErrors *ratioGraph =
new TGraphAsymmErrors();
961 TH1 *tmpHist =
static_cast<TH1 *
>(
fH1->Clone());
976 for (
Int_t i = 0; i <=
fH1->GetNbinsX(); ++i) {
986 if (val - val2 > 0) {
995 error =
fH1->GetBinError(i);
997 Warning(thisMethod,
"error mode is invalid");
1002 Double_t res = (val - val2) / error;
1004 ((TGraphAsymmErrors*)
fRatioGraph)->SetPoint(ipoint,
fH1->GetBinCenter(i), res);
1005 ((TGraphAsymmErrors*)
fRatioGraph)->SetPointError(ipoint,
fH1->GetBinWidth(i)/2.,
fH1->GetBinWidth(i)/2., 0.5, 0.5);
1016 TF1 *func =
dynamic_cast<TF1*
>(
fH1->GetListOfFunctions()->At(0));
1020 Error(thisMethod,
"h1 does not have a fit function");
1027 std::vector<double> ci1, ci2;
1031 std::vector<Double_t> x_arr(nbinsx, 0.), ci_arr1(nbinsx, 0.), ci_arr2(nbinsx, 0);
1032 for (
Int_t i = 0; i < nbinsx; ++i)
1033 x_arr[i] =
fH1->GetBinCenter(i+1);
1040 fFitResult->GetConfidenceIntervals(nbinsx, 1, 1, x_arr.data(), ci_arr1.data(), cl1);
1041 for (
Int_t i = 1; i <= nbinsx; ++i)
1042 ci1.push_back(ci_arr1[i - 1]);
1044 fFitResult->GetConfidenceIntervals(nbinsx, 1, 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]);
1049 for (
Int_t i = 1; i <= nbinsx; ++i)
1050 ci1.push_back(ci_arr1[i - 1]);
1052 for (
Int_t i = 1; i <= nbinsx; ++i)
1053 ci2.push_back(ci_arr2[i - 1]);
1056 for (
Int_t i = 1; i <= nbinsx; ++i) {
1066 if (val - func->
Eval(
fH1->GetBinCenter(i)) > 0) {
1076 error =
fH1->GetBinError(i);
1084 Warning(thisMethod,
"error mode is invalid");
1092 ((TGraphAsymmErrors*)
fRatioGraph)->SetPoint(ipoint,
fH1->GetBinCenter(i), res);
1093 ((TGraphAsymmErrors*)
fRatioGraph)->SetPointError(ipoint,
fH1->GetBinWidth(i)/2.,
fH1->GetBinWidth(i)/2., 0.5, 0.5);
1108 TH1 *tmpHist =
static_cast<TH1 *
>(
fH1->Clone());
1117 Error(thisMethod,
"Invalid fMode value");
1125 Error(thisMethod,
"Error creating lower graph");
1154 fUpperGXaxis =
new TGaxis(0, 0, 1, 1, 0, 1, 510,
"+U");
1159 fUpperGYaxis =
new TGaxis(0, 0, 1, 1, upYFirst, upYLast, 510,
"S");
1164 fLowerGXaxis =
new TGaxis(0, 0, 1, 1, first, last, 510,
"+S");
1169 fLowerGYaxis =
new TGaxis(0, 0, 1, 1, lowYFirst, lowYLast, 510,
"-S");
1206 static const char *thisMethod =
"UpdateVisualAxes";
1239 if (upYFirst <= 0 || upYLast <= 0) {
1240 Error(thisMethod,
"Cannot set upper Y axis to log scale");
1248 if (lowYFirst <= 0 || lowYLast <= 0) {
1249 Error(thisMethod,
"Cannot set lower Y axis to log scale");
1256 if (first <= 0 || last <= 0) {
1257 Error(thisMethod,
"Cannot set X axis to log scale");
1262 TString xopt = logx ?
"G" :
"";
1263 TString upyopt = uplogy ?
"G" :
"";
1264 TString lowyopt = lowlogy ?
"G" :
"";
1318 Double_t ratio = ( (upBM-(1-upTM))*(1-sf) ) / ( (lowBM-(1-lowTM))*sf );
1440 horizontalChanged =
kTRUE;
1443 horizontalChanged =
kTRUE;
1448 horizontalChanged =
kTRUE;
1451 horizontalChanged =
kTRUE;
1457 verticalChanged =
kTRUE;
1462 verticalChanged =
kTRUE;
1467 verticalChanged =
kTRUE;
1475 if (horizontalChanged || verticalChanged)
1478 return horizontalChanged || verticalChanged;
1526 if (upFirst != globFirst || upLast != globLast) {
1529 }
else if (lowFirst != globFirst || lowLast != globLast) {
1534 if (upChanged || lowChanged)
1540 if (upChanged || lowChanged || marginsChanged) {
1589 Float_t lowyup = lowylow + lowh;
1615 Warning(
"SetSplitFraction",
"Can only be used after TRatioPlot has been drawn.");
1619 if ((sf < 0.0001) || (sf > 0.9999)) {
1620 Warning(
"SetSplitFraction",
"Value %f is out of allowed range", sf);
1628 double f = height/width;
1641 Warning(
"SetInsetWidth",
"Can only be used after TRatioPlot has been drawn.");
1652 fTopPad->SetPad(pm*
f, pm, 1-pm*
f, 1-pm);
1692 for (
Int_t i = 0; i < numGridlines; ++i)
int Int_t
Signed integer 4 bytes (int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
short Color_t
Color number (short).
float Float_t
Float 4 bytes (float).
const char Option_t
Option string (const char).
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
virtual Color_t GetTitleColor() const
virtual Color_t GetLabelColor() const
virtual Color_t GetAxisColor() const
virtual Style_t GetTitleFont() const
virtual Float_t GetLabelOffset() const
virtual Style_t GetLabelFont() const
virtual Float_t GetTitleSize() const
virtual Float_t GetLabelSize() const
virtual Float_t GetTickLength() const
virtual Float_t GetTitleOffset() const
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Class to manage histogram axis.
const char * GetTitle() const override
Returns title of object.
@ kCenterLabels
Bit 13 is used by TObject.
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Bool_t GetDecimals() const
Int_t GetLast() const
Return last bin on the axis i.e.
virtual void SetLimits(Double_t xmin, Double_t xmax)
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,...
virtual const char * GetTimeFormat() const
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Int_t GetFirst() const
Return first bin on the axis i.e.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
void Draw(Option_t *option="") override
Default Draw method for all objects.
Extends the ROOT::Fit::Result class with a TNamed inheritance providing easy possibility for I/O.
void SetTimeFormat(const char *tformat)
void SetTitleOffset(Float_t titleoffset=1)
void SetLabelFont(Int_t labelfont)
void SetTitleSize(Float_t titlesize)
void SetLabelOffset(Float_t labeloffset)
void SetLabelColor(Int_t labelcolor)
void SetTickSize(Float_t ticksize)
void SetLabelSize(Float_t labelsize)
virtual void SetTitle(const char *title="")
virtual void Divide(const TH1 *pass, const TH1 *total, Option_t *opt="cp")
TH1 is the base class of all histogram classes in ROOT.
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="")
Performs the operation: this = this + c1*f1 if errors are defined (see TH1::Sumw2),...
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
virtual Bool_t Divide(TF1 *f1, Double_t c1=1)
Performs the operation: this = this/(c1*f1) if errors are defined (see TH1::Sumw2),...
virtual void SetY2(Double_t y2)
virtual void SetX2(Double_t x2)
virtual void SetX1(Double_t x1)
virtual void SetY1(Double_t y1)
virtual TObjLink * FirstLink() const
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
TObject * GetObject() const
Mother of all ROOT objects.
Bool_t TestBit(UInt_t f) const
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TObject()
TObject constructor.
@ kCannotPick
if object in a pad cannot be picked
@ kForceHideUp
Always hide the first label of the upper y axis.
@ kHideUp
Hide the first label of the upper y axis when there is low space.
@ kNoHide
Do not hide labels when there is low space.
@ kHideLow
Hide the last label of the lower y axis when there is low space.
@ kForceHideLow
Always hide the last label of the lower y axis.
TGraphErrors * fConfidenceInterval2
Stores the graph for the 2 sigma band.
TAxis * GetLowerRefXaxis() const
virtual void SetGridlines(Double_t *gridlines, Int_t numGridlines)
Int_t fErrorMode
Stores the error mode, sym, asym or func.
TAxis * GetLowerRefYaxis() const
TGaxis * fUpperGXaxisMirror
Upper mirror of the x axis.
TGaxis * fLowerGXaxisMirror
Lower mirror of the x axis.
virtual Bool_t SyncPadMargins()
TAxis * GetUpperRefYaxis() const
Float_t fLowBottomMargin
Stores the bottom margin of the lower pad.
void SetUpBottomMargin(Float_t margin)
Float_t fUpBottomMargin
Stores the bottom margin of the upper pad.
TH1 * fH1
Stores the primary histogram.
void SetH2DrawOpt(Option_t *opt)
virtual void CreateVisualAxes()
TFitResult * fFitResult
Stores the explicit fit result given in the fit residual case. Can be 0.
virtual void Init(TH1 *h1, TH1 *h2, Option_t *option="")
Color_t fCi1Color
Stores the color for the 1 sigma band.
TGaxis * fUpperGYaxis
Upper graphical y axis.
Double_t fC2
Stores the scale factor for h2.
virtual void ConnectPadsSignals()
void SetLowBottomMargin(Float_t margin)
void SetConfidenceIntervalColors(Color_t ci1=kYellow, Color_t ci2=kGreen)
Double_t fC1
Stores the scale factor for h1 (or THStack sum).
Float_t fLowTopMargin
Stores the top margin of the lower pad.
TString fH2DrawOpt
Stores draw option for h2 given in constructor.
void SetUpTopMargin(Float_t margin)
TGaxis * fLowerGXaxis
Lower graphical x axis.
Bool_t fIsUpdating
! Keeps track of whether its currently updating to reject other calls until done
virtual void SyncAxesRanges()
void SetGraphDrawOpt(Option_t *opt)
Double_t fCl1
Stores the confidence level for the inner confidence interval band.
@ kErrorAsymmetric
Use TH1::GetBinErrorUp and TH1::GetBinErrorLow for the error, depending on y values.
@ kErrorFunc
Use the square root of the function value as the error.
@ kErrorSymmetric
Use the regular TH1::GetBinError as the error.
Float_t GetSeparationMargin() const
void ImportAxisAttributes(TGaxis *gaxis, TAxis *axis)
void SetFitDrawOpt(Option_t *opt)
std::vector< TLine * > fGridlines
Keeps TLine objects for the gridlines.
TPad * fLowerPad
The pad which contains the calculated lower plot part.
TAxis * fSharedXAxis
X axis that stores the range for both plots.
TString fFitDrawOpt
Stores draw option for the fit function in the fit residual case.
TGaxis * fUpperGYaxisMirror
Upper mirror of the y axis.
TAxis * fUpYaxis
Clone of the upper y axis.
TVirtualPad * fParentPad
Stores the pad the ratio plot was created in.
Float_t fUpTopMargin
Stores the top margin of the upper pad.
void SetH1DrawOpt(Option_t *opt)
TGraph * fRatioGraph
Stores the lower plot's graph.
Int_t fMode
Stores which calculation is supposed to be performed as specified by user option.
void SetSplitFraction(Float_t sf)
TObject * fHistDrawProxy
The object which is actually drawn, this might be TH1 or THStack.
virtual TObject * GetUpperRefObject() const
Float_t fRightMargin
Stores the common right margin of both pads.
virtual void UpdateVisualAxes()
TGaxis * fLowerGYaxisMirror
Lower mirror of the y axis.
Int_t fHideLabelMode
Stores which label to hide if the margin is to narrow, if at all.
TPad * fTopPad
The Pad that drawn on top on the others to have consistent coordinates.
void SetInsetWidth(Double_t width)
@ kDifference
Calculate the difference between the histograms.
@ kDivideHist
Use TH1::Divide to create the ratio.
@ kFitResidual
Calculate the fit residual between the histogram and a fit stored within it.
@ kDifferenceSign
Calculate the difference divided by the error.
@ kDivideGraph
Use TGraphAsymmErrors::Divide to create the ratio.
TH1 * fH2
Stores the secondary histogram, if there is one.
Double_t fCl2
Stores the confidence level for the outer confidence interval band.
TAxis * fLowYaxis
Clone of the lower y axis.
TString fOption
Stores the option which is given in the constructor as a string.
TPad * fUpperPad
The pad which contains the upper plot part.
Bool_t fShowConfidenceIntervals
Stores whether to show the confidence interval bands. From Draw option.
void SetLowTopMargin(Float_t margin)
void SetSeparationMargin(Float_t)
Bool_t fHistDrawProxyStack
If stack was assigned as proxy.
void SetLeftMargin(Float_t margin)
Float_t fLeftMargin
Stores the common left margin of both pads.
TAxis * GetUpperRefXaxis() const
Float_t fSplitFraction
Stores the fraction at which the upper and lower pads meet.
void Paint(Option_t *opt="") override
This method must be overridden if a class wants to paint itself.
TGraphErrors * fConfidenceInterval1
Stores the graph for the 1 sigma band.
TGaxis * fUpperGXaxis
Upper graphical x axis.
virtual TGraph * GetLowerRefGraph() const
std::vector< double > fGridlinePositions
Stores the y positions for the gridlines.
TString fH1DrawOpt
Stores draw option for h1 given in constructor.
Bool_t fShowGridlines
Stores whether to show the gridlines at all.
void Draw(Option_t *chopt="") override
Default Draw method for all objects.
TString fGraphDrawOpt
Stores draw option for the lower plot graph given in constructor.
Color_t fCi2Color
Stores the color for the 2 sigma band.
void SetRightMargin(Float_t margin)
TGaxis * fLowerGYaxis
Lower graphical y axis.
void SetConfidenceLevels(Double_t cl1, Double_t cl2)
TString & ReplaceAll(const TString &s1, const TString &s2)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual void GetConfidenceIntervals(Int_t n, Int_t ndim, const Double_t *x, Double_t *ci, Double_t cl=0.95)
return confidence intervals in array x of dimension ndim implemented in TFitter and TLinearFitter
static TVirtualFitter * GetFitter()
static: return the current Fitter
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
double ratio(double numerator, double denominator)
void Init(TClassEdit::TInterpreterLookupHelper *helper)
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.