CombineHarvester
Plotting.h
Go to the documentation of this file.
1 #ifndef Core_Plotting_h
2 #define Core_Plotting_h
3 
4 #include <map>
5 #include <string>
6 #include <iostream>
7 #include <vector>
8 #include <cmath>
9 
10 #include "TStyle.h"
11 #include "TGraph.h"
12 #include "TGraph2D.h"
13 #include "TCanvas.h"
14 #include "TPad.h"
15 #include "TLatex.h"
16 #include "TAxis.h"
17 #include "TList.h"
18 #include "TH1F.h"
19 #include "TLegend.h"
20 #include "TColor.h"
21 #include "TROOT.h"
22 #include "TFrame.h"
23 #include "TTree.h"
24 #include "TFile.h"
25 #include "TLine.h"
26 #include "TMultiGraph.h"
27 #include "THStack.h"
28 
29 
30 
43 std::vector<TPad*> OnePad();
44 
62 std::vector<TPad*> TwoPadSplit(double split_point, double gap_low,
63  double gap_high);
64 
78 TH1* CreateAxisHist(TH1* src, double xmin = 0, double xmax = -1);
79 
91 std::vector<TH1*> CreateAxisHists(unsigned n, TH1* src, double xmin = 0,
92  double xmax = -1);
93 
108 TH1* CreateAxisHist(TGraph* src, bool at_limits);
109 
121 std::vector<TH1*> CreateAxisHists(unsigned n, TGraph* src, bool at_limits);
122 
123 
134 TH1* GetAxisHist(TPad *pad);
157 TH1* MakeRatioHist(TH1* num, TH1* den, bool num_err, bool den_err);
158 
159 
172 TGraph TGraphFromTree(TTree* tree, TString const& xvar, TString const& yvar,
173  TString const& selection = "");
174 
188 TGraph2D TGraph2DFromTree(TTree* tree, TString const& xvar, TString const& yvar,
189  TString const& zvar, TString const& selection = "");
190 
198 void ReZeroTGraph(TGraph *gr);
216 int CreateTransparentColor(int color, float alpha);
217 
238 void SetupTwoPadSplitAsRatio(std::vector<TPad*> const& pads, TH1* upper,
239  TH1* lower, TString y_title, bool y_centered,
240  float y_min, float y_max);
241 
260 void SetupTwoPadSplitAsRatio(std::vector<TPad*> const& pads, TString y_title,
261  bool y_centered, float y_min, float y_max);
262 
275 void StandardAxes(TAxis* xaxis, TAxis* yaxis, TString var, TString units);
276 
289 void UnitAxes(TAxis* xaxis, TAxis* yaxis, TString var, TString units);
290 
310 TLegend* PositionedLegend(double width, double height, int pos, double offset);
311 
327 TLine* DrawHorizontalLine(TPad *pad, TLine* line, double yval);
328 
345 void DrawTitle(TPad* pad, TString text, int align);
346 
372 void DrawCMSLogo(TPad* pad, TString cmsText, TString extraText, int iPosX,
373  float relPosX, float relPosY, float relExtraDY);
374 
383 void DrawCMSLogo(TPad* pad, TString cmsText, TString extraText, int iPosX);
405 double GetPadYMax(TPad* pad, double x_min, double x_max);
406 
411 double GetPadYMax(TPad* pad);
412 
427 void FixTopRange(TPad *pad, double fix_y, double fraction);
428 
429 
446 void FixBoxPadding(TPad *pad, TBox *box, double frac);
447 
451 void FixOverlay();
456 //----------------------------------------------------------------------------
457 // Pad and axis histogram creation
458 //----------------------------------------------------------------------------
459 std::vector<TPad*> OnePad() {
460  TPad* pad = new TPad("pad", "pad", 0., 0., 1., 1.);
461  pad->Draw();
462  pad->cd();
463  std::vector<TPad*> result;
464  result.push_back(pad);
465  return result;
466 }
467 
468 std::vector<TPad*> TwoPadSplit(double split_point, double gap_low,
469  double gap_high) {
470  TPad* upper = new TPad("upper", "upper", 0., 0., 1., 1.);
471  upper->SetBottomMargin(split_point + gap_high);
472  upper->SetFillStyle(4000);
473  upper->Draw();
474  TPad* lower = new TPad("lower", "lower", 0., 0., 1., 1.);
475  lower->SetTopMargin(1 - split_point + gap_low);
476  lower->SetFillStyle(4000);
477  lower->Draw();
478  upper->cd();
479  std::vector<TPad*> result;
480  result.push_back(upper);
481  result.push_back(lower);
482  return result;
483 }
484 
485 TH1* CreateAxisHist(TH1* src, double xmin, double xmax) {
486  TH1 *res = reinterpret_cast<TH1F*>(src->Clone());
487  res->Reset();
488  if (xmax > xmin) {
489  res->SetAxisRange(xmin, xmax);
490  }
491  return res;
492 }
493 
494 std::vector<TH1*> CreateAxisHists(unsigned n, TH1* src, double xmin,
495  double xmax) {
496  std::vector<TH1*> result;
497  for (unsigned i = 0; i < n; ++i) {
498  result.push_back(CreateAxisHist(src, xmin, xmax));
499  }
500  return result;
501 }
502 
503 TH1* CreateAxisHist(TGraph* src, bool at_limits) {
504  TVirtualPad *backup = gPad;
505  TCanvas tmp;
506  tmp.cd();
507  src->Draw("AP");
508  TH1 * result = (TH1*)src->GetHistogram()->Clone();
509  if (at_limits) {
510  double min = 0;
511  double max = 0;
512  double x = 0;
513  double y = 0;
514  src->GetPoint(0, x, y);
515  min = x;
516  max = x;
517  for (int i = 1; i < src->GetN(); ++i) {
518  src->GetPoint(i, x, y);
519  if (x < min) min = x;
520  if (x > max) max = x;
521  }
522  result->GetXaxis()->SetLimits(min, max);
523  }
524  gPad = backup;
525  return result;
526 }
527 
528 std::vector<TH1*> CreateAxisHists(unsigned n, TGraph* src, bool at_limits) {
529  std::vector<TH1*> result;
530  for (unsigned i = 0; i < n; ++i) {
531  result.push_back(CreateAxisHist(src, at_limits));
532  }
533  return result;
534 }
535 
536 TH1* GetAxisHist(TPad *pad) {
537  TList* pad_obs = pad->GetListOfPrimitives();
538  if (!pad_obs) return NULL;
539  TIter next(pad_obs);
540  TObject* obj;
541  TH1 *hobj = 0;
542  while ((obj = next())) {
543  if (obj->InheritsFrom(TH1::Class())) {
544  hobj = reinterpret_cast<TH1*>(obj);
545  break;
546  }
547  if (obj->InheritsFrom(TMultiGraph::Class())) {
548  TMultiGraph *mg = reinterpret_cast<TMultiGraph*>(obj);
549  if (mg) return mg->GetHistogram();
550  }
551  if (obj->InheritsFrom(TGraph::Class())) {
552  TGraph *g = reinterpret_cast<TGraph*>(obj);
553  if (g) return g->GetHistogram();
554  }
555  if (obj->InheritsFrom(THStack::Class())) {
556  THStack *hs = reinterpret_cast<THStack*>(obj);
557  if (hs) return hs->GetHistogram();
558  }
559  }
560  return hobj;
561 }
562 
563 
564 //----------------------------------------------------------------------------
565 // Object extraction and manipulation
566 //----------------------------------------------------------------------------
567 TH1* MakeRatioHist(TH1* num, TH1* den, bool num_err, bool den_err) {
568  TH1* result = reinterpret_cast<TH1*>(num->Clone());
569  if (!num_err) {
570  for (int i = 1; i <= result->GetNbinsX(); ++i) result->SetBinError(i, 0.);
571  }
572  TH1* den_fix = reinterpret_cast<TH1*>(den->Clone());
573  if (!den_err) {
574  for (int i = 1; i <= den_fix->GetNbinsX(); ++i) den_fix->SetBinError(i, 0.);
575  }
576  result->Divide(den_fix);
577  delete den_fix;
578  return result;
579 }
580 
581 TGraph TGraphFromTree(TTree * tree, TString const& xvar, TString const& yvar,
582  TString const& selection) {
583  tree->Draw(xvar+":"+yvar, selection, "goff");
584  TGraph gr(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2());
585  return gr;
586 }
587 
588 TGraph2D TGraph2DFromTree(TTree* tree, TString const& xvar, TString const& yvar,
589  TString const& zvar, TString const& selection) {
590  tree->Draw(xvar+":"+yvar+":"+zvar, selection, "goff");
591  TGraph2D gr(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(), tree->GetV3());
592  return gr;
593 }
594 
595 void ReZeroTGraph(TGraph *gr) {
596  unsigned n = gr->GetN();
597  double min = 0.;
598  double x = 0;
599  double y = 0;
600  for (unsigned i = 0; i < n; ++i) {
601  gr->GetPoint(i, x, y);
602  if (y < min) min = y;
603  }
604  for (unsigned i = 0; i < n; ++i) {
605  gr->GetPoint(i, x, y);
606  y = y - min;
607  gr->SetPoint(i, x, y);
608  }
609 }
610 
611 //----------------------------------------------------------------------------
612 // Plot decoration (colours, styles, text and legends)
613 //----------------------------------------------------------------------------
614 int CreateTransparentColor(int color, float alpha) {
615  TColor* adapt = gROOT->GetColor(color);
616  int new_idx = gROOT->GetListOfColors()->GetSize() + 1;
617  TColor* trans = new TColor(new_idx, adapt->GetRed(), adapt->GetGreen(),
618  adapt->GetBlue(), "", alpha);
619  trans->SetName(Form("userColor%i", new_idx));
620  return new_idx;
621 }
622 
623 void SetupTwoPadSplitAsRatio(std::vector<TPad*> const& pads,
624  TString y_title, bool y_centered, float y_min,
625  float y_max) {
626  TH1 *upper = GetAxisHist(pads[0]);
627  TH1 *lower = GetAxisHist(pads[1]);
628  SetupTwoPadSplitAsRatio(pads, upper, lower, y_title, y_centered, y_min,
629  y_max);
630 }
631 
632 void SetupTwoPadSplitAsRatio(std::vector<TPad*> const& pads, TH1* upper,
633  TH1* lower, TString y_title, bool y_centered,
634  float y_min, float y_max) {
635  upper->GetXaxis()->SetTitle("");
636  upper->GetXaxis()->SetLabelSize(0);
637  double upper_h = 1. - pads[0]->GetTopMargin() - pads[0]->GetBottomMargin();
638  double lower_h = 1. - pads[1]->GetTopMargin() - pads[1]->GetBottomMargin();
639  lower->GetYaxis()->SetTickLength(gStyle->GetTickLength() *
640  (upper_h / lower_h));
641  pads[1]->SetTickx(1);
642  pads[1]->SetTicky(1);
643  lower->GetYaxis()->SetTitle(y_title);
644  lower->GetYaxis()->CenterTitle(y_centered);
645  if (y_max > y_min) {
646  lower->SetMinimum(y_min);
647  lower->SetMaximum(y_max);
648  }
649 }
650 
651 void StandardAxes(TAxis* xaxis, TAxis* yaxis, TString var, TString units) {
652  double width = xaxis->GetBinWidth(1);
653  TString w_label = TString::Format("%.1f", width);
654  if (units == "") {
655  xaxis->SetTitle(var);
656  yaxis->SetTitle("Events / " + w_label);
657  } else {
658  xaxis->SetTitle(var + " (" + units + ")");
659  yaxis->SetTitle("Events / " + w_label + " " + units);
660  }
661 }
662 
663 
664 void UnitAxes(TAxis* xaxis, TAxis* yaxis, TString var, TString units) {
665  xaxis->SetTitle(var + " (" + units + ")");
666  yaxis->SetTitle("dN/d"+ var + " (1/" + units + ")");
667 }
668 
669 TLegend* PositionedLegend(double width, double height, int pos, double offset) {
670  double o = offset;
671  double w = width;
672  double h = height;
673  double l = gPad->GetLeftMargin();
674  double t = gPad->GetTopMargin();
675  double b = gPad->GetBottomMargin();
676  double r = gPad->GetRightMargin();
677  TLegend* leg = 0;
678  if (pos == 1) {
679  leg = new TLegend(l + o, 1 - t - o - h, l + o + w, 1 - t - o, "", "NBNDC");
680  }
681  if (pos == 2) {
682  double c = l + 0.5 * (1 - l - r);
683  leg = new TLegend(c - 0.5 * w, 1 - t - o - h, c + 0.5 * w, 1 - t - o, "",
684  "NBNDC");
685  }
686  if (pos == 3) {
687  leg = new TLegend(1 - r - o - w, 1 - t - o - h, 1 - r - o, 1 - t - o, "",
688  "NBNDC");
689  }
690  if (pos == 4) {
691  leg = new TLegend(l + o, b + o, l + o + w, b + o + h, "", "NBNDC");
692  }
693  if (pos == 5) {
694  double c = l + 0.5 * (1 - l - r);
695  leg = new TLegend(c - 0.5 * w, b + o, c + 0.5 * w, b + o + h, "",
696  "NBNDC");
697  }
698  if (pos == 6) {
699  leg = new TLegend(1 - r - o - w, b + o, 1 - r - o, b + o + h, "",
700  "NBNDC");
701  }
702  return leg;
703 }
704 
705 TLine* DrawHorizontalLine(TPad *pad, TLine* line, double yval) {
706  TH1 *axis = GetAxisHist(pad);
707  std::cout << "pad: " << pad << "\n";
708  double xmin = axis->GetXaxis()->GetXmin();
709  double xmax = axis->GetXaxis()->GetXmax();
710  return line->DrawLine(xmin, yval, xmax, yval);
711 }
712 
713 void DrawTitle(TPad* pad, TString text, int align) {
714  TVirtualPad *pad_backup = gPad;
715  pad->cd();
716  float t = pad->GetTopMargin();
717  float l = pad->GetLeftMargin();
718  float r = pad->GetRightMargin();
719 
720  float pad_ratio = (static_cast<float>(pad->GetWh()) * pad->GetAbsHNDC()) /
721  (static_cast<float>(pad->GetWw()) * pad->GetAbsWNDC());
722  if (pad_ratio < 1.) pad_ratio = 1.;
723 
724  float textSize = 0.6;
725  float textOffset = 0.2;
726 
727  TLatex latex;
728  latex.SetNDC();
729  latex.SetTextAngle(0);
730  latex.SetTextColor(kBlack);
731 
732  latex.SetTextFont(42);
733  latex.SetTextSize(textSize * t * pad_ratio);
734  double y_off = 1 - t + textOffset * t;
735  if (align == 1) latex.SetTextAlign(11);
736  if (align == 1) latex.DrawLatex(l, y_off, text);
737  if (align == 2) latex.SetTextAlign(21);
738  if (align == 2) latex.DrawLatex(l + (1 - l - r) * 0.5, y_off, text);
739  if (align == 3) latex.SetTextAlign(31);
740  if (align == 3) latex.DrawLatex(1 - r, y_off, text);
741  pad_backup->cd();
742 }
743 
744 void DrawCMSLogo(TPad* pad, TString cmsText, TString extraText, int iPosX,
745  float relPosX, float relPosY, float relExtraDY) {
746  TVirtualPad *pad_backup = gPad;
747  pad->cd();
748  float cmsTextFont = 61; // default is helvetic-bold
749 
750  bool writeExtraText = extraText.Length() > 0;
751  float extraTextFont = 52; // default is helvetica-italics
752 
753  // text sizes and text offsets with respect to the top frame
754  // in unit of the top margin size
755  float lumiTextOffset = 0.2;
756  float cmsTextSize = 0.8;
757  // float cmsTextOffset = 0.1; // only used in outOfFrame version
758 
759  // ratio of "CMS" and extra text size
760  float extraOverCmsTextSize = 0.76;
761 
762  TString lumi_13TeV = "20.1 fb^{-1}";
763  TString lumi_8TeV = "19.7 fb^{-1}";
764  TString lumi_7TeV = "5.1 fb^{-1}";
765 
766  bool outOfFrame = false;
767  if (iPosX / 10 == 0) {
768  outOfFrame = true;
769  }
770  int alignY_ = 3;
771  int alignX_ = 2;
772  if (iPosX / 10 == 0) alignX_ = 1;
773  if (iPosX == 0) alignX_ = 1;
774  if (iPosX == 0) alignY_ = 1;
775  if (iPosX / 10 == 1) alignX_ = 1;
776  if (iPosX / 10 == 2) alignX_ = 2;
777  if (iPosX / 10 == 3) alignX_ = 3;
778  if (iPosX == 0) relPosX = 0.14;
779  int align_ = 10 * alignX_ + alignY_;
780 
781  float l = pad->GetLeftMargin();
782  float t = pad->GetTopMargin();
783  float r = pad->GetRightMargin();
784  float b = pad->GetBottomMargin();
785 
786  TLatex latex;
787  latex.SetNDC();
788  latex.SetTextAngle(0);
789  latex.SetTextColor(kBlack);
790 
791  float extraTextSize = extraOverCmsTextSize * cmsTextSize;
792  float pad_ratio = (static_cast<float>(pad->GetWh()) * pad->GetAbsHNDC()) /
793  (static_cast<float>(pad->GetWw()) * pad->GetAbsWNDC());
794  if (pad_ratio < 1.) pad_ratio = 1.;
795 
796 
797  if (outOfFrame) {
798  latex.SetTextFont(cmsTextFont);
799  latex.SetTextAlign(11);
800  latex.SetTextSize(cmsTextSize * t * pad_ratio);
801  latex.DrawLatex(l, 1 - t + lumiTextOffset * t, cmsText);
802  }
803 
804  float posX_ = 0;
805  if (iPosX % 10 <= 1) {
806  posX_ = l + relPosX * (1 - l - r);
807  } else if (iPosX % 10 == 2) {
808  posX_ = l + 0.5 * (1 - l - r);
809  } else if (iPosX % 10 == 3) {
810  posX_ = 1 - r - relPosX * (1 - l - r);
811  }
812  float posY_ = 1 - t - relPosY * (1 - t - b);
813  if (!outOfFrame) {
814  latex.SetTextFont(cmsTextFont);
815  latex.SetTextSize(cmsTextSize * t * pad_ratio);
816  latex.SetTextAlign(align_);
817  latex.DrawLatex(posX_, posY_, cmsText);
818  if (writeExtraText) {
819  latex.SetTextFont(extraTextFont);
820  latex.SetTextAlign(align_);
821  latex.SetTextSize(extraTextSize * t * pad_ratio);
822  latex.DrawLatex(posX_, posY_ - relExtraDY * cmsTextSize * t, extraText);
823  }
824  } else if (writeExtraText) {
825  if (iPosX == 0) {
826  posX_ = l + relPosX * (1 - l - r);
827  posY_ = 1 - t + lumiTextOffset * t;
828  }
829  latex.SetTextFont(extraTextFont);
830  latex.SetTextSize(extraTextSize * t * pad_ratio);
831  latex.SetTextAlign(align_);
832  latex.DrawLatex(posX_, posY_, extraText);
833  }
834  pad_backup->cd();
835 }
836 
837 void DrawCMSLogo(TPad* pad, TString cmsText, TString extraText, int iPosX) {
838  DrawCMSLogo(pad, cmsText, extraText, iPosX, 0.045, 0.035, 1.2);
839 }
840 
841 //----------------------------------------------------------------------------
842 // Axis adjustment and overlap checks
843 //----------------------------------------------------------------------------
844 double GetPadYMax(TPad* pad, double x_min, double x_max) {
845  TList *pad_obs = pad->GetListOfPrimitives();
846  if (!pad_obs) return 0.;
847  TIter next(pad_obs);
848  double h_max = -99999;
849  TObject *obj;
850  while ((obj = next())) {
851  if (obj->InheritsFrom(TH1::Class())) {
852  TH1 *hobj = reinterpret_cast<TH1*>(obj);
853  for (int j = 1; j < hobj->GetNbinsX(); ++j) {
854  if (hobj->GetBinLowEdge(j) + hobj->GetBinWidth(j) < x_min ||
855  hobj->GetBinLowEdge(j) > x_max)
856  continue;
857  if (hobj->GetBinContent(j) + hobj->GetBinError(j) > h_max) {
858  h_max = hobj->GetBinContent(j) + hobj->GetBinError(j);
859  }
860  }
861  }
862  if (obj->InheritsFrom(TGraph::Class())) {
863  TGraph *gobj = reinterpret_cast<TGraph*>(obj);
864  unsigned n = gobj->GetN();
865  double x = 0;
866  double y = 0;
867  for (unsigned k = 0; k < n; ++k) {
868  gobj->GetPoint(k, x, y);
869  if (x < x_min || x > x_max) continue;
870  if (y > h_max) h_max = y;
871  }
872  }
873  }
874  return h_max;
875 }
876 
877 double GetPadYMax(TPad* pad) {
878  TList *pad_obs = pad->GetListOfPrimitives();
879  if (!pad_obs) return 0.;
880  double xmin = GetAxisHist(pad)->GetXaxis()->GetXmin();
881  double xmax = GetAxisHist(pad)->GetXaxis()->GetXmax();
882  return GetPadYMax(pad, xmin, xmax);
883 }
884 
885 void FixTopRange(TPad *pad, double fix_y, double fraction) {
886  TH1* hobj = GetAxisHist(pad);
887  double ymin = hobj->GetMinimum();
888  hobj->SetMaximum((fix_y - fraction * ymin) / (1. - fraction));
889  if (gPad->GetLogy()) {
890  if (ymin == 0.) {
891  std::cout
892  << "Can't adjust log-scale y-axis range if the minimum is zero!\n";
893  return;
894  }
895  double max =
896  (std::log10(fix_y) - fraction * std::log10(ymin)) / (1 - fraction);
897  max = std::pow(10, max);
898  hobj->SetMaximum(max);
899  }
900 }
901 
902 void FixBoxPadding(TPad *pad, TBox *box, double frac) {
903  // Get the bounds of the box - these are in the normalised
904  // Pad co-ordinates.
905  double p_x1 = box->GetX1();
906  double p_x2 = box->GetX2();
907  double p_y1 = box->GetY1();
908  // double p_y2 = box->GetY2();
909 
910  // Convert to normalised co-ordinates in the frame
911  double f_x1 = (p_x1 - pad->GetLeftMargin()) /
912  (1. - pad->GetLeftMargin() - pad->GetRightMargin());
913  double f_x2 = (p_x2 - pad->GetLeftMargin()) /
914  (1. - pad->GetLeftMargin() - pad->GetRightMargin());
915  double f_y1 = (p_y1 - pad->GetBottomMargin()) /
916  (1. - pad->GetTopMargin() - pad->GetBottomMargin());
917 
918  // Extract histogram providing the frame and axes
919  TH1 *hobj = GetAxisHist(pad);
920 
921  double xmin = hobj->GetBinLowEdge(hobj->GetXaxis()->GetFirst());
922  double xmax = hobj->GetBinLowEdge(hobj->GetXaxis()->GetLast()+1);
923  double ymin = hobj->GetMinimum();
924  double ymax = hobj->GetMaximum();
925 
926  // Convert box bounds to x-axis values
927  double a_x1 = xmin + (xmax - xmin) * f_x1;
928  double a_x2 = xmin + (xmax - xmin) * f_x2;
929 
930  // Get the histogram maximum in this range, given as y-axis value
931  double a_max_h = GetPadYMax(pad, a_x1, a_x2);
932 
933  // Convert this to a normalised frame value
934  double f_max_h = (a_max_h - ymin) / (ymax - ymin);
935  if (gPad->GetLogy()) {
936  f_max_h = (log10(a_max_h) - log10(ymin)) / (log10(ymax) - log10(ymin));
937  }
938 
939  if (f_y1 - f_max_h < frac) {
940  double f_target = 1. - (f_y1 - frac);
941  FixTopRange(pad, a_max_h, f_target);
942  }
943 }
944 
945 void FixOverlay() { gPad->GetFrame()->Draw(); gPad->RedrawAxis(); }
946 
947 #endif
void FixBoxPadding(TPad *pad, TBox *box, double frac)
Modify the pad y-axis range to ensure there is at least a given gap between a particular TBox and the...
Definition: Plotting.h:902
void DrawTitle(TPad *pad, TString text, int align)
Draw text in the top-margin region of a TPad.
Definition: Plotting.h:713
void FixOverlay()
Just re-draws the axes on the current TPad.
Definition: Plotting.h:945
void UnitAxes(TAxis *xaxis, TAxis *yaxis, TString var, TString units)
Sets standard x- and y-axis titles when histograms are drawn divided by bin width.
Definition: Plotting.h:664
TH1 * MakeRatioHist(TH1 *num, TH1 *den, bool num_err, bool den_err)
Create a new histogram by dividing one by the other.
Definition: Plotting.h:567
void FixTopRange(TPad *pad, double fix_y, double fraction)
Adjusts the y-axis maximum on the pad such that the specified y-value is positioned a fixed fraction ...
Definition: Plotting.h:885
TLegend * PositionedLegend(double width, double height, int pos, double offset)
Create a legend with fixed height, width and positioning.
Definition: Plotting.h:669
TGraph TGraphFromTree(TTree *tree, TString const &xvar, TString const &yvar, TString const &selection="")
Create a TGraph from entries in a TTree.
Definition: Plotting.h:581
double GetPadYMax(TPad *pad, double x_min, double x_max)
Find the maximum value of all drawn objects in a given x-axis range.
Definition: Plotting.h:844
void StandardAxes(TAxis *xaxis, TAxis *yaxis, TString var, TString units)
Sets standard x- and y-axis titles with given units.
Definition: Plotting.h:651
std::vector< TPad * > OnePad()
Just creates a single pad filling the entire canvas.
Definition: Plotting.h:459
TLine * DrawHorizontalLine(TPad *pad, TLine *line, double yval)
Use an existing TLine to draw a new horizontal line across the current frame.
Definition: Plotting.h:705
std::vector< TH1 * > CreateAxisHists(unsigned n, TH1 *src, double xmin=0, double xmax=-1)
Create multiple axis TH1s from another TH1.
Definition: Plotting.h:494
TH1 * GetAxisHist(TPad *pad)
Finds the TH1 used to draw the axes on a given TPad.
Definition: Plotting.h:536
void SetupTwoPadSplitAsRatio(std::vector< TPad * > const &pads, TH1 *upper, TH1 *lower, TString y_title, bool y_centered, float y_min, float y_max)
Set a few style options for a two-pad setup used to show a data-MC comparison and ratio plot.
Definition: Plotting.h:632
void DrawCMSLogo(TPad *pad, TString cmsText, TString extraText, int iPosX, float relPosX, float relPosY, float relExtraDY)
Draw the CMS logo and subtitle in the new style.
Definition: Plotting.h:744
TH1 * CreateAxisHist(TH1 *src, double xmin=0, double xmax=-1)
Create an empty TH1 from another TH1 for drawing the axes.
Definition: Plotting.h:485
int CreateTransparentColor(int color, float alpha)
Create a transparent version of a colour.
Definition: Plotting.h:614
std::vector< TPad * > TwoPadSplit(double split_point, double gap_low, double gap_high)
Create two pads, split horizontally, on the current canvas split.
Definition: Plotting.h:468
void ReZeroTGraph(TGraph *gr)
Shift all the graph y-values upwards such that there are no negative values and the minimum point is ...
Definition: Plotting.h:595
TGraph2D TGraph2DFromTree(TTree *tree, TString const &xvar, TString const &yvar, TString const &zvar, TString const &selection="")
Create a TGraph2D from entries in a TTree.
Definition: Plotting.h:588