10 TH1D
TGraphToTH1D(
const TGraph& graph,
const std::string& newName,
const std::string& newTitle) {
15 name = graph.GetName();
20 title = graph.GetTitle();
24 int nPoints = graph.GetN();
29 std::vector<double> pointsX(nPoints);
30 std::vector<double> pointsY(nPoints);
35 for (
int pointId = 0; pointId < nPoints; pointId++)
37 graph.GetPoint(pointId, x, y);
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;
47 for (
int pointId = 1; pointId < nPoints; pointId++)
50 binEdges[pointId] = (pointsX[pointId] + pointsX[pointId - 1]) / 2.0;
53 TH1D retHist = TH1D(name.c_str(), title.c_str(), nPoints, binEdges.data());
55 for (
int binId = 0; binId < nPoints; binId++)
57 retHist.SetBinContent(binId + 1, pointsY[binId]);
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);
72 for (
int pointId = 0; pointId < nPoints; pointId++)
74 graph.GetPoint(pointId, x, y);
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);
96 for (
int pointId = 0; pointId < nPoints; pointId++)
98 graph.GetPoint(pointId, x, y, z);
100 pointsY[pointId] = y;
101 pointsZ[pointId] = z;
116 for (
int j = 0; j < static_cast<int>(RatioPlot.size()); j++) {
117 if (!RatioPlot[j])
continue;
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));
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));
131 RatioPlot[0]->GetYaxis()->SetRangeUser(1 - std::fabs(1 - minz), 1 + std::fabs(1 - minz));
Custom exception class used throughout MaCh3.
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.
void SetSymmetricRatioRange(const std::vector< std::unique_ptr< TH1D >> &RatioPlot)
Set a symmetric Y-axis range around 1 for ratio plots.
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.
Main namespace for MaCh3 software.