15 Int_t px = gPad->GetEventX();
16 Int_t py = gPad->GetEventY();
22#if ROOT_VERSION_CODE < ROOT_VERSION(6, 26, 0)
23void TCalibrationGraph::Scale(
const double& scale)
26 Double_t* ey = GetEY();
28 for(
int i = 0; i < GetN(); ++i) {
38 : fTotalGraph(new TGraphErrors), fTotalResidualGraph(new TGraphErrors)
41 if(graph !=
nullptr) {
48 : fTotalGraph(new TGraphErrors), fTotalResidualGraph(new TGraphErrors), fXAxisLabel(std::move(xAxisLabel)), fYAxisLabel(std::move(yAxisLabel))
62 std::cout << __PRETTY_FUNCTION__ <<
", fTotalGraph " <<
fTotalGraph << std::endl;
65 if(graph->GetN() == 0) {
66 std::cout << __PRETTY_FUNCTION__ <<
": graph \"" << graph->GetName() <<
"\", label \"" << label <<
"\" is empty, not adding it" << std::endl;
70 graph->GetListOfFunctions()->Clear();
79 double* rhsX = graph->GetX();
80 double* rhsY = graph->GetY();
81 double* rhsEX = graph->GetEX();
82 double* rhsEY = graph->GetEY();
86 std::vector<std::tuple<double, double, double, double, size_t, size_t>> data(
fTotalGraph->GetN() + graph->GetN());
91 for(
int i = 0; i < graph->GetN(); ++i) {
92 data[
fTotalGraph->GetN() + i] = std::make_tuple(rhsX[i], rhsY[i], rhsEX[i], rhsEY[i],
fGraphs.size(), i);
95 std::sort(data.begin(), data.end());
105 for(
size_t i = 0; i < data.size(); ++i) {
106 fTotalGraph->SetPoint(
static_cast<Int_t
>(i), std::get<0>(data[i]), std::get<1>(data[i]));
107 fTotalGraph->SetPointError(
static_cast<Int_t
>(i), std::get<2>(data[i]), std::get<3>(data[i]));
120 fGraphs.emplace_back(
this, graph);
124 fGraphs.back().SetLineColor(
static_cast<Color_t
>(
fGraphs.size()));
125 fGraphs.back().SetMarkerColor(
static_cast<Color_t
>(
fGraphs.size()));
126 fGraphs.back().SetMarkerStyle(
static_cast<Style_t
>(
fGraphs.size()));
132 std::cout <<
"done" << std::endl;
135 return static_cast<int>(
fGraphs.size() - 1);
142 if(calibration !=
nullptr && (!
fResidualSet || force)) {
150 fTotalResidualGraph->SetPointError(i, TMath::Sqrt(TMath::Power(ey[i], 2) + TMath::Power(ex[i] * calibration->Derivative(x[i]), 2)), ey[i]);
152 for(
size_t g = 0; g <
fGraphs.size(); ++g) {
158 for(
int i = 0; i <
fGraphs[g].GetN(); ++i) {
160 fResidualGraphs[g].SetPointError(i, TMath::Sqrt(TMath::Power(ey[i], 2) + TMath::Power(ex[i] * calibration->Derivative(x[i]), 2)), ey[i]);
164 auto* mother = gPad->GetMother();
166 while(mother->GetPad(pad) !=
nullptr) {
167 mother->GetPad(pad)->Modified();
168 mother->GetPad(pad)->Update();
174 if(
fVerboseLevel >
EVerbosity::kSubroutines) { std::cout << __PRETTY_FUNCTION__ <<
": didn't find calibration (" << calibration <<
"), or the residual was already set (" << (
fResidualSet ?
"true" :
"false") <<
") and we don't force it (" << (force ?
"true" :
"false") <<
")" << std::endl; }
184 std::cerr <<
"Trying to set axis title to \"" << title <<
"\" failed because no total graph is present for this title to be applied to!" << std::endl;
192 TString options = opt;
194 if(options.Contains(
"same")) {
195 options.Remove(options.Index(
"same"), 4);
196 opt = options.Data();
203 fTotalGraph->GetHistogram()->GetXaxis()->CenterTitle();
205 fTotalGraph->GetHistogram()->GetYaxis()->CenterTitle();
209 for(
size_t i = 0; i <
fGraphs.size(); ++i) {
212 if(legend !=
nullptr) {
220 TString options = opt;
225 if(
hist !=
nullptr) {
226 hist->GetXaxis()->SetLabelSize(0.06);
228 std::cout <<
"Failed to get histogram for graph:" << std::endl;
235 if(legend !=
nullptr) {
246 std::cout << __PRETTY_FUNCTION__ <<
": point " << px <<
", " << py <<
"; gPad " << gPad->GetName() <<
": " << gPad->AbsPixeltoX(px) <<
", " << gPad->AbsPixeltoY(py) << std::endl;
257 Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(x[i]));
258 Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(y[i]));
260 if(dpx * dpx + dpy * dpy < 100) {
262 std::cout << i <<
": dpx = " << dpx <<
" = " << px <<
" - " << gPad->XtoAbsPixel(gPad->XtoPad(x[i])) <<
", dpy = " << dpy <<
" = " << py <<
" - " << gPad->YtoAbsPixel(gPad->YtoPad(y[i])) <<
" this is the point we're looking for" << std::endl;
268 std::cout << i <<
": dpx = " << dpx <<
" = " << px <<
" - " << gPad->XtoAbsPixel(gPad->XtoPad(x[i])) <<
", dpy = " << dpy <<
" = " << py <<
" - " << gPad->YtoAbsPixel(gPad->YtoPad(y[i])) <<
" not the point we're looking for" << std::endl;
272 std::cout <<
"Failed to find point close to " << px <<
", " << py << std::endl;
274 std::cout << __PRETTY_FUNCTION__ << std::endl;
288 std::cout << ipoint <<
" removed residual point" << std::endl;
294 std::cout <<
"point " << ipoint <<
" out of range?" << std::endl;
306 auto* mother = gPad->GetMother();
308 while(mother->GetPad(pad) !=
nullptr) {
309 mother->GetPad(pad)->Modified();
310 mother->GetPad(pad)->Update();
316 std::array<Longptr_t, 2> args = {px, py};
318 Emit(
"RemovePoint(Int_t, Int_t)", args.data());
333 Int_t dpx = px - gPad->XtoAbsPixel(gPad->XtoPad(x[i]));
334 Int_t dpy = py - gPad->YtoAbsPixel(gPad->YtoPad(y[i]));
336 if(dpx * dpx + dpy * dpy < 100) {
344 std::cout << __PRETTY_FUNCTION__ << std::endl;
350 std::cout << __PRETTY_FUNCTION__ << std::endl;
360 std::cout <<
"point " << ipoint <<
" out of range?" << std::endl;
372 auto* mother = gPad->GetMother();
375 while(mother->GetPad(pad) !=
nullptr) {
376 mother->GetPad(pad)->Modified();
381 std::array<Longptr_t, 2> args = {px, py};
383 Emit(
"RemoveResidualPoint(Int_t, Int_t)", args.data());
393 std::cout << __PRETTY_FUNCTION__ << std::endl;
396 for(
size_t g = 1; g <
fGraphs.size(); ++g) {
398 if(graph.GetN() == 0) {
399 std::cout <<
"No entries in " << g <<
". graph" << std::endl;
402 double* x = graph.GetX();
403 double* y = graph.GetY();
406 for(g2 = 0; (useAllPrevious ? g2 < g : g2 < 1); ++g2) {
407 double minRef =
fGraphs[g2].GetX()[0];
410 std::cout <<
"Checking overlap between " << g2 <<
". graph (" <<
fGraphs[g2].GetN() <<
": " << minRef <<
" - " << maxRef <<
") and " << g <<
". graph (" << graph.GetN() << std::flush <<
": " << x[0] <<
" - " << x[graph.GetN() - 1] <<
")" << std::endl;
412 if(maxRef < x[0] || x[graph.GetN() - 1] < minRef) {
414 std::cout <<
"No overlap between " << g2 <<
". graph (" <<
fGraphs[g2].GetN() <<
": " << minRef <<
" - " << maxRef <<
") and " << g <<
". graph (" << graph.GetN() <<
": " << x[0] <<
" - " << x[graph.GetN() - 1] <<
")" << std::endl;
420 for(
int p = 0; p < graph.GetN(); ++p) {
421 if(minRef < x[p] && x[p] < maxRef) {
422 sum +=
fGraphs[g2].Eval(x[p]) / y[p];
433 std::cout <<
"No overlap(s) between 0. to " << g2 - 1 <<
". graph and " << g <<
". graph (" << graph.GetN() <<
": " << x[0] <<
" - " << x[graph.GetN() - 1] <<
"), not scaling this one!" << std::endl;
444 std::cerr <<
"No graphs added yet, makes no sense to reset total graph?" << std::endl;
450 newSize += graph.GetN();
454 std::vector<std::tuple<double, double, double, double, size_t, size_t>> data(newSize);
456 for(
size_t i = 0; i <
fGraphs.size(); ++i) {
460 double* eX =
fGraphs[i].GetEX();
461 double* eY =
fGraphs[i].GetEY();
462 for(
int p = 0; p <
fGraphs[i].GetN(); ++p, ++counter) {
464 data[counter] = std::make_tuple(x[p], y[p], eX[p], eY[p], i, p);
468 std::sort(data.begin(), data.end());
478 for(
size_t i = 0; i < data.size(); ++i) {
479 fTotalGraph->SetPoint(i, std::get<0>(data[i]), std::get<1>(data[i]));
480 fTotalGraph->SetPointError(i, std::get<2>(data[i]), std::get<3>(data[i]));
496 std::cout << __PRETTY_FUNCTION__ <<
", fTotalGraph " <<
fTotalGraph << std::endl;
499 std::cout <<
"TCalibrationGraphSet " <<
this <<
" - " << GetName() <<
": " <<
fGraphs.size() <<
" calibration graphs, " <<
fResidualGraphs.size() <<
" residual graphs, " <<
fLabel.size() <<
" labels, ";
501 std::cout <<
fTotalGraph->GetN() <<
" calibration points, and ";
503 std::cout <<
" no calibration points, and ";
508 std::cout <<
" no residual points" << std::endl;
510 TString options = opt;
511 bool errors = options.Contains(
"e", TString::ECaseCompare::kIgnoreCase);
513 double* x = g.GetX();
514 double* y = g.GetY();
515 double* ex = g.GetEX();
516 double* ey = g.GetEY();
517 for(
int p = 0; p < g.GetN(); ++p) {
519 std::cout << p <<
" - " << x[p] <<
"(" << ex[p] <<
"), " << y[p] <<
"(" << ey[p] <<
"); ";
521 std::cout << p <<
" - " << x[p] <<
", " << y[p] <<
"; ";
524 std::cout << std::endl;
526 std::cout <<
fGraphIndex.size() <<
" graph indices: ";
527 for(
const auto& i :
fGraphIndex) { std::cout << i <<
" "; }
528 std::cout << std::endl;
529 std::cout <<
fPointIndex.size() <<
" point indices: ";
530 for(
const auto& i :
fPointIndex) { std::cout << i <<
" "; }
531 std::cout << std::endl;
532 std::cout <<
"---- total graph ----" << std::endl;
536 std::cout << p <<
" - " << x[p] <<
", " << y[p] <<
"; ";
538 std::cout << std::endl;
539 std::cout <<
"---------------------" << std::endl;
554 TNamed::Clear(option);
TCalibrationGraphSet * fParent
pointer to the set this graph belongs to
bool fIsResidual
flag to indicate that this graph is for residuals
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.
std::vector< size_t > fPointIndex
Index of the point within the graph this point corresponds to.
bool SetResidual(const bool &force=false)
TCalibrationGraphSet(TGraphErrors *graph=nullptr, const std::string &label="")
std::string fYAxisLabel
The label of the y-axis.
static EVerbosity fVerboseLevel
Changes verbosity.
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.
double fMaximumX
Maximum x-value.
double fMinimumY
Minimum y-value.
void Print(Option_t *opt="") const override
double fMaximumY
Maximum y-value.
std::string fXAxisLabel
The label of the x-axis.
void Scale(bool useAllPrevious=true)
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.
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.
TF1 * FitFunction()
Gets the calibration from the total graph (might be nullptr!).
Int_t RemoveResidualPoint(const Int_t &px, const Int_t &py)
static EVerbosity VerboseLevel()
std::vector< std::string > fLabel
The labels for the different graphs.