10TH1D
TGraphToTH1D(TGraph graph, std::string newName, 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]);
66 int nPoints = graph.GetN();
67 std::vector<std::vector<double>> ret(2);
68 std::vector<double> pointsX(nPoints);
69 std::vector<double> pointsY(nPoints);
74 for (
int pointId = 0; pointId < nPoints; pointId++)
76 graph.GetPoint(pointId, x, y);
90 int nPoints = graph.GetN();
91 std::vector<std::vector<double>> ret(3);
92 std::vector<double> pointsX(nPoints);
93 std::vector<double> pointsY(nPoints);
94 std::vector<double> pointsZ(nPoints);
99 for (
int pointId = 0; pointId < nPoints; pointId++)
101 graph.GetPoint(pointId, x, y, z);
102 pointsX[pointId] = x;
103 pointsY[pointId] = y;
104 pointsZ[pointId] = z;
Custom exception class for MaCh3 errors.
std::vector< std::vector< double > > TGraphToVector(TGraph graph)
This handy little function lets you interpret a TGraph as a vector containing the same data.
TH1D TGraphToTH1D(TGraph graph, std::string newName, std::string newTitle)
This handy little function lets you interpret a TGraph as a TH1D.