MaCh3  2.6.1
Reference Guide
Classes | Enumerations | Functions
M3::Plotting Namespace Reference

Flexible, experiment-agnostic plotting utilities for MaCh3. More...

Classes

struct  InputFile
 Struct which wraps around the actual input file and also holds general information, and data from the file to be used by other classes. More...
 
class  InputManager
 This guy talks to the input files and is intended to smooth over the fact that our OA fitters use such a beautiful and diverse range of output file structures. More...
 
class  PlottingManager
 The main class to be used in plotting scripts. More...
 
class  StyleManager
 EW: provides centralized styling utilities for plots, including name prettification and style application. More...
 

Enumerations

enum  fileTypeEnum {
  kLLH , kPostFit , kMCMC , kSigmaVar ,
  kNFileTypes
}
 Types of possible file that can be read. More...
 

Functions

TH1D TGraphToTH1D (const TGraph &graph, const std::string &newName="", const std::string &newTitle="")
 This handy little function lets you interpret a TGraph as a TH1D. More...
 
std::vector< std::vector< double > > TGraphToVector (const TGraph &graph)
 This handy little function lets you interpret a TGraph as a vector containing the same data. More...
 
std::vector< std::vector< double > > TGraphToVector (const TGraph2D &graph)
 This handy little function lets you interpret a 2d TGraph as a vector containing the same data. More...
 
void SetSymmetricRatioRange (const std::vector< std::unique_ptr< TH1D >> &RatioPlot)
 Set a symmetric Y-axis range around 1 for ratio plots. More...
 

Detailed Description

Flexible, experiment-agnostic plotting utilities for MaCh3.

Enumeration Type Documentation

◆ fileTypeEnum

Types of possible file that can be read.

Enumerator
kLLH 

Log Likelihood scan.

kPostFit 

Processed post fit errors.

kMCMC 

MCMC chain.

kSigmaVar 

Sigma variations.

kNFileTypes 

Number of types of file.

Definition at line 16 of file InputManager.h.

16  {
17  kLLH,
18  kPostFit,
19  kMCMC,
20  kSigmaVar,
21 
23 };
@ kMCMC
MCMC chain.
Definition: InputManager.h:19
@ kSigmaVar
Sigma variations.
Definition: InputManager.h:20
@ kNFileTypes
Number of types of file.
Definition: InputManager.h:22
@ kLLH
Log Likelihood scan.
Definition: InputManager.h:17
@ kPostFit
Processed post fit errors.
Definition: InputManager.h:18

Function Documentation

◆ SetSymmetricRatioRange()

void M3::Plotting::SetSymmetricRatioRange ( const std::vector< std::unique_ptr< TH1D >> &  RatioPlot)

Set a symmetric Y-axis range around 1 for ratio plots.

Definition at line 111 of file PlottingUtils.cpp.

112 {
113  double maxz = -999;
114  double minz = +999;
115 
116  for (int j = 0; j < static_cast<int>(RatioPlot.size()); j++) {
117  if (!RatioPlot[j]) continue;
118 
119  for (int i = 1; i < RatioPlot[0]->GetXaxis()->GetNbins(); i++) {
120  maxz = std::max(maxz, RatioPlot[j]->GetBinContent(i));
121  minz = std::min(minz, RatioPlot[j]->GetBinContent(i));
122  }
123  }
124 
125  maxz = maxz * 1.001;
126  minz = minz * 1.001;
127 
128  if (std::fabs(1 - maxz) > std::fabs(1 - minz))
129  RatioPlot[0]->GetYaxis()->SetRangeUser(1 - std::fabs(1 - maxz), 1 + std::fabs(1 - maxz));
130  else
131  RatioPlot[0]->GetYaxis()->SetRangeUser(1 - std::fabs(1 - minz), 1 + std::fabs(1 - minz));
132 }

◆ TGraphToTH1D()

TH1D M3::Plotting::TGraphToTH1D ( const TGraph &  graph,
const std::string &  newName,
const std::string &  newTitle 
)

This handy little function lets you interpret a TGraph as a TH1D.

It will go through your provided graph and make a histogram binning by taking the midpoints of all the graph points x values, then fill the histogram with the graphs y values. For the first and last points it will extend the binning out of the graph bounds using the width between the outermost and second outermost points. This can be useful if e.g. you want to draw cumulative stacks of LLH scans.

Parameters
graphThe graph you want to convert.
newNameThe new name you want to give to the histogram. If not specified, will just use the name of the graph.
newTitleThe new title you want to give to the histogram. If not specified, will just use the title of the graph.

Definition at line 10 of file PlottingUtils.cpp.

10  {
11  std::string name;
12  std::string title;
13 
14  if (newName == "")
15  name = graph.GetName();
16  else
17  name = newName;
18 
19  if (newTitle == "")
20  title = graph.GetTitle();
21  else
22  title = newTitle;
23 
24  int nPoints = graph.GetN();
25  if(nPoints < 2){
26  MACH3LOG_ERROR("Too few points in the graph.");
27  throw MaCh3Exception(__FILE__,__LINE__);
28  }
29  std::vector<double> pointsX(nPoints);
30  std::vector<double> pointsY(nPoints);
31 
32  // Get the points out
33  Double_t x, y;
34 
35  for (int pointId = 0; pointId < nPoints; pointId++)
36  {
37  graph.GetPoint(pointId, x, y);
38  pointsX[pointId] = x;
39  pointsY[pointId] = y;
40  }
41 
42  // get the bin edges
43  std::vector<double> binEdges(nPoints + 1);
44  binEdges[0] = pointsX[0] - (pointsX[1] - pointsX[0]) / 2.0;
45  binEdges[nPoints] = pointsX[nPoints - 1] + (pointsX[nPoints - 1] - pointsX[nPoints - 2]) / 2.0;
46 
47  for (int pointId = 1; pointId < nPoints; pointId++)
48  {
49  // take the midpoint of the two surrounding points
50  binEdges[pointId] = (pointsX[pointId] + pointsX[pointId - 1]) / 2.0;
51  }
52 
53  TH1D retHist = TH1D(name.c_str(), title.c_str(), nPoints, binEdges.data());
54 
55  for (int binId = 0; binId < nPoints; binId++)
56  {
57  retHist.SetBinContent(binId + 1, pointsY[binId]);
58  }
59 
60  return retHist;
61 }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
Custom exception class used throughout MaCh3.

◆ TGraphToVector() [1/2]

std::vector< std::vector< double > > M3::Plotting::TGraphToVector ( const TGraph &  graph)

This handy little function lets you interpret a TGraph as a vector containing the same data.

Parameters
graphThe graph you want to convert.
Returns
A vector of vectors containing the data from the initial graph. The first vector is the x axis, the 2nd the y axis

Definition at line 63 of file PlottingUtils.cpp.

63  {
64  int nPoints = graph.GetN();
65  std::vector<std::vector<double>> ret(2);
66  std::vector<double> pointsX(nPoints);
67  std::vector<double> pointsY(nPoints);
68 
69  // Get the points out
70  Double_t x, y;
71 
72  for (int pointId = 0; pointId < nPoints; pointId++)
73  {
74  graph.GetPoint(pointId, x, y);
75  pointsX[pointId] = x;
76  pointsY[pointId] = y;
77  }
78 
79  ret[0] = pointsX;
80  ret[1] = pointsY;
81 
82  return ret;
83 }

◆ TGraphToVector() [2/2]

std::vector< std::vector< double > > M3::Plotting::TGraphToVector ( const TGraph2D &  graph)

This handy little function lets you interpret a 2d TGraph as a vector containing the same data.

Parameters
graphThe graph you want to convert.
Returns
A vector of vectors containing the data from the initial graph. The first vector is the x axis, the 2nd the y axis, the 3rd is the z axis

Definition at line 86 of file PlottingUtils.cpp.

86  {
87  int nPoints = graph.GetN();
88  std::vector<std::vector<double>> ret(3);
89  std::vector<double> pointsX(nPoints);
90  std::vector<double> pointsY(nPoints);
91  std::vector<double> pointsZ(nPoints);
92 
93  // Get the points out
94  Double_t x, y, z;
95 
96  for (int pointId = 0; pointId < nPoints; pointId++)
97  {
98  graph.GetPoint(pointId, x, y, z);
99  pointsX[pointId] = x;
100  pointsY[pointId] = y;
101  pointsZ[pointId] = z;
102  }
103 
104  ret[0] = pointsX;
105  ret[1] = pointsY;
106  ret[2] = pointsZ;
107 
108  return ret;
109 }