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