GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TCalibrationGraph.h
Go to the documentation of this file.
1#ifndef TCALIBRATIONGRAPH_H
2#define TCALIBRATIONGRAPH_H
3
4#include <vector>
5#include <string>
6#include <iostream>
7
8#include "TNamed.h"
9#include "TGraphErrors.h"
10#include "TList.h"
11#include "TLegend.h"
12#include "TQObject.h"
13
14#include "Globals.h"
15
17
18class TCalibrationGraph : public TGraphErrors {
19public:
20 TCalibrationGraph() = default;
21 TCalibrationGraph(TCalibrationGraphSet* parent, const int& size, const bool& isResidual = false) : TGraphErrors(size), fParent(parent), fIsResidual(isResidual) {}
22 TCalibrationGraph(TCalibrationGraphSet* parent, TGraphErrors* graph) : TGraphErrors(*graph), fParent(parent) {}
23 ~TCalibrationGraph() = default;
25 TCalibrationGraph(TCalibrationGraph&&) noexcept = default;
26 TCalibrationGraph& operator=(const TCalibrationGraph&) = default;
27 TCalibrationGraph& operator=(TCalibrationGraph&&) noexcept = default;
28
29 using TGraph::RemovePoint; // to use the function with integer index as argument
30 Int_t RemovePoint() override; // *MENU*
31
32 void IsResidual(bool val) { fIsResidual = val; }
33 bool IsResidual() const { return fIsResidual; }
34
35#if ROOT_VERSION_CODE < ROOT_VERSION(6, 26, 0)
36 void Scale(const double& scale);
37#endif
38
39private:
40 TCalibrationGraphSet* fParent{nullptr}; ///< pointer to the set this graph belongs to
41 bool fIsResidual{false}; ///< flag to indicate that this graph is for residuals
42
43 /// \cond CLASSIMP
44 ClassDefOverride(TCalibrationGraph, 1) // NOLINT(readability-else-after-return)
45 /// \endcond
46};
47
48class TCalibrationGraphSet : public TNamed, public TQObject {
49public:
50 explicit TCalibrationGraphSet(TGraphErrors* graph = nullptr, const std::string& label = "");
51 TCalibrationGraphSet(std::string xAxisLabel, std::string yAxisLabel);
56 {
57 /// Assignment operator that takes care of properly cloning all the pointers to objects.
58 fGraphs.resize(rhs.fGraphs.size());
59 for(size_t i = 0; i < fGraphs.size(); ++i) {
60 fGraphs[i] = rhs.fGraphs[i];
61 }
62 fResidualGraphs.resize(rhs.fResidualGraphs.size());
63 for(size_t i = 0; i < fResidualGraphs.size(); ++i) {
64 fResidualGraphs[i] = rhs.fResidualGraphs[i];
65 }
66 fLabel = rhs.fLabel;
67 fTotalGraph = static_cast<TGraphErrors*>(rhs.fTotalGraph->Clone());
68 fTotalResidualGraph = static_cast<TGraphErrors*>(rhs.fTotalResidualGraph->Clone());
69 fGraphIndex = rhs.fGraphIndex;
70 fPointIndex = rhs.fPointIndex;
71 fResidualSet = rhs.fResidualSet;
72 fName = rhs.fName;
73 return *this;
74 }
76
77 bool SetResidual(const bool& force = false);
78 int Add(TGraphErrors*, const std::string& label); ///< Add new graph to set, using the label when creating legends during plotting
79
80 void SetLineColor(int index, Color_t color)
81 {
82 /// Set the line color of the graph and residuals at index
83 fGraphs[index].SetLineColor(color);
84 fResidualGraphs[index].SetLineColor(color);
85 }
86 void SetMarkerColor(int index, Color_t color)
87 {
88 /// Set the marker color of the graph and residuals at index
89 if(fVerboseLevel > EVerbosity::kSubroutines) { std::cout << "setting marker color of graph " << index << " to " << color << std::endl; }
90 fGraphs[index].SetMarkerColor(color);
91 fResidualGraphs[index].SetMarkerColor(color);
92 }
93 void SetMarkerStyle(int index, Style_t style)
94 {
95 /// Set the marker style of the graph and residuals at index
96 fGraphs[index].SetMarkerStyle(style);
97 fResidualGraphs[index].SetMarkerStyle(style);
98 }
99 void SetColor(int index, Color_t color)
100 {
101 /// Set the line and marker color of the graph and residuals at index
102 SetLineColor(index, color);
103 SetMarkerColor(index, color);
104 }
105 void SetColorStyle(int index, int val)
106 {
107 /// Set the line and marker color and marker style of the graph and residuals at index
108 SetLineColor(index, static_cast<Color_t>(val));
109 SetMarkerColor(index, static_cast<Color_t>(val));
110 SetMarkerStyle(index, static_cast<Style_t>(val));
111 }
112
113 void SetAxisTitle(const char* title); ///< Set axis title for the graph (form "x-axis title;y-axis title")
114
115 int GetN() { return (fTotalGraph != nullptr ? fTotalGraph->GetN() : -1); } ///< Returns GetN(), i.e. number of points of the total graph.
116 double* GetX() { return (fTotalGraph != nullptr ? fTotalGraph->GetX() : nullptr); } ///< Returns an array of x-values of the total graph.
117 double* GetY() { return (fTotalGraph != nullptr ? fTotalGraph->GetY() : nullptr); } ///< Returns an array of y-values of the total graph.
118 double* GetEX() { return (fTotalGraph != nullptr ? fTotalGraph->GetEX() : nullptr); } ///< Returns an array of x-errors of the total graph.
119 double* GetEY() { return (fTotalGraph != nullptr ? fTotalGraph->GetEY() : nullptr); } ///< Returns an array of y-errors of the total graph.
120
121 double GetMinimumX() const { return fMinimumX; } ///< Return minimum x-value.
122 double GetMaximumX() const { return fMaximumX; } ///< Return maximum x-value.
123 double GetMinimumY() const { return fMinimumY; } ///< Return minimum y-value.
124 double GetMaximumY() const { return fMaximumY; } ///< Return maximum y-value.
125
126 void Fit(TF1* function, Option_t* opt = "") { fTotalGraph->Fit(function, opt); } ///< Fits the provided function to the total graph.
127 TF1* FitFunction() { return reinterpret_cast<TF1*>(fTotalGraph->GetListOfFunctions()->FindObject("fitfunction")); } ///< Gets the calibration from the total graph (might be nullptr!).
128 TGraphErrors* TotalGraph() { return fTotalGraph; }
129 TGraphErrors* TotalResidualGraph() { return fTotalResidualGraph; }
130 size_t NumberOfGraphs() { return fGraphs.size(); }
131 TCalibrationGraph* Graph(size_t index) { return &(fGraphs.at(index)); }
132 TCalibrationGraph* Residual(size_t index) { return &(fResidualGraphs.at(index)); }
133
134 void Draw(Option_t* opt = "") override { DrawCalibration(opt, nullptr); }
135 void DrawCalibration(Option_t* opt = "", TLegend* legend = nullptr);
136 void DrawResidual(Option_t* opt = "", TLegend* legend = nullptr);
137
138 void RemoveGraph(int64_t index)
139 {
140 fGraphs.erase(fGraphs.begin() + index);
142 }
143 Int_t RemovePoint(const Int_t& px, const Int_t& py); //*SIGNAL*
144 Int_t RemoveResidualPoint(const Int_t& px, const Int_t& py); //*SIGNAL*
145 Int_t RemovePoint(TGraphErrors* graph, const Int_t& px, const Int_t& py); //*SIGNAL*
146
147 void RemovePoint(const int& point); //*SIGNAL*
148
149 void XAxisLabel(const std::string& xAxisLabel) { fXAxisLabel = xAxisLabel; }
150 void YAxisLabel(const std::string& yAxisLabel) { fYAxisLabel = yAxisLabel; }
151
152 std::string XAxisLabel() { return fXAxisLabel; }
153 std::string YAxisLabel() { return fYAxisLabel; }
154
155 void Scale(bool useAllPrevious = true);
156
157 void Sort();
158
159 void Print(Option_t* opt = "") const override;
160
161 void ResetTotalGraph(); ///< reset the total graph and add the individual ones again (used e.g. after scaling of individual graphs is done)
162
163 static void VerboseLevel(EVerbosity val) { fVerboseLevel = val; }
165
166 void Clear(Option_t* option = "") override;
167
168private:
169 std::vector<TCalibrationGraph> fGraphs; ///< These are the graphs used for plotting the calibration points per source.
170 std::vector<TCalibrationGraph> fResidualGraphs; ///< These are the graphs used for plotting the residuals per source.
171 std::vector<std::string> fLabel; ///< The labels for the different graphs.
172 TGraphErrors* fTotalGraph{nullptr}; ///< The sum of the other graphs, used for fitting.
173 TGraphErrors* fTotalResidualGraph{nullptr}; ///< The sum of the residuals. Not really used apart from plotting (but overlayed with the individual graphs).
174 std::vector<size_t> fGraphIndex; ///< Index of the graph this point belongs to.
175 std::vector<size_t> fPointIndex; ///< Index of the point within the graph this point corresponds to.
176 bool fResidualSet{false}; ///< Flag to indicate if the residual has been set correctly.
177 double fMinimumX{0.}; ///< Minimum x-value
178 double fMaximumX{0.}; ///< Maximum x-value
179 double fMinimumY{0.}; ///< Minimum y-value
180 double fMaximumY{0.}; ///< Maximum y-value
181 std::string fXAxisLabel; ///< The label of the x-axis.
182 std::string fYAxisLabel; ///< The label of the y-axis.
183
184 static EVerbosity fVerboseLevel; ///< Changes verbosity
185
186 /// \cond CLASSIMP
187 ClassDefOverride(TCalibrationGraphSet, 3) // NOLINT(readability-else-after-return)
188 /// \endcond
189};
190#endif
EVerbosity
Definition Globals.h:143
TCalibrationGraphSet * fParent
pointer to the set this graph belongs to
TCalibrationGraph(TCalibrationGraphSet *parent, TGraphErrors *graph)
bool fIsResidual
flag to indicate that this graph is for residuals
TCalibrationGraph(const TCalibrationGraph &)=default
TCalibrationGraph(TCalibrationGraphSet *parent, const int &size, const bool &isResidual=false)
~TCalibrationGraph()=default
TCalibrationGraph(TCalibrationGraph &&) noexcept=default
TCalibrationGraph()=default
bool IsResidual() const
Int_t RemovePoint() override
void ResetTotalGraph()
reset the total graph and add the individual ones again (used e.g. after scaling of individual graphs...
void DrawResidual(Option_t *opt="", TLegend *legend=nullptr)
std::vector< size_t > fGraphIndex
Index of the graph this point belongs to.
int GetN()
Returns GetN(), i.e. number of points of the total graph.
void RemoveGraph(int64_t index)
std::vector< size_t > fPointIndex
Index of the point within the graph this point corresponds to.
void SetMarkerColor(int index, Color_t color)
bool SetResidual(const bool &force=false)
TCalibrationGraphSet(TGraphErrors *graph=nullptr, const std::string &label="")
void SetColor(int index, Color_t color)
TCalibrationGraphSet(TCalibrationGraphSet &&) noexcept=delete
std::string fYAxisLabel
The label of the y-axis.
static EVerbosity fVerboseLevel
Changes verbosity.
static void VerboseLevel(EVerbosity val)
std::vector< TCalibrationGraph > fResidualGraphs
These are the graphs used for plotting the residuals per source.
TGraphErrors * TotalResidualGraph()
TGraphErrors * fTotalGraph
The sum of the other graphs, used for fitting.
TCalibrationGraph * Graph(size_t index)
double GetMaximumY() const
Return maximum y-value.
void SetLineColor(int index, Color_t color)
double * GetY()
Returns an array of y-values of the total graph.
double fMaximumX
Maximum x-value.
double fMinimumY
Minimum y-value.
void SetColorStyle(int index, int val)
void Draw(Option_t *opt="") override
double * GetEX()
Returns an array of x-errors of the total graph.
void Print(Option_t *opt="") const override
void Fit(TF1 *function, Option_t *opt="")
Fits the provided function to the total graph.
void SetMarkerStyle(int index, Style_t style)
TCalibrationGraphSet & operator=(TCalibrationGraphSet &&) noexcept=delete
double GetMinimumY() const
Return minimum y-value.
double GetMinimumX() const
Return minimum x-value.
TGraphErrors * TotalGraph()
double fMaximumY
Maximum y-value.
std::string fXAxisLabel
The label of the x-axis.
void Scale(bool useAllPrevious=true)
double GetMaximumX() const
Return maximum x-value.
int Add(TGraphErrors *, const std::string &label)
Add new graph to set, using the label when creating legends during plotting.
void DrawCalibration(Option_t *opt="", TLegend *legend=nullptr)
TGraphErrors * fTotalResidualGraph
The sum of the residuals. Not really used apart from plotting (but overlayed with the individual grap...
bool fResidualSet
Flag to indicate if the residual has been set correctly.
void Clear(Option_t *option="") override
double fMinimumX
Minimum x-value.
TCalibrationGraph * Residual(size_t index)
Int_t RemovePoint(const Int_t &px, const Int_t &py)
void SetAxisTitle(const char *title)
Set axis title for the graph (form "x-axis title;y-axis title")
std::vector< TCalibrationGraph > fGraphs
These are the graphs used for plotting the calibration points per source.
double * GetEY()
Returns an array of y-errors of the total graph.
double * GetX()
Returns an array of x-values of the total graph.
TF1 * FitFunction()
Gets the calibration from the total graph (might be nullptr!).
void XAxisLabel(const std::string &xAxisLabel)
Int_t RemoveResidualPoint(const Int_t &px, const Int_t &py)
static EVerbosity VerboseLevel()
TCalibrationGraphSet(const TCalibrationGraphSet &)=delete
void YAxisLabel(const std::string &yAxisLabel)
std::vector< std::string > fLabel
The labels for the different graphs.