GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TCalGraph.cxx
Go to the documentation of this file.
1#include "TCalGraph.h"
2
3#include <iostream>
4#include "Globals.h"
5
10
11TCalGraph::TCalGraph(const TCalGraph& copy) : TGraphErrors(copy)
12{
13 // copy.Copy(*this);
14}
15
16void TCalGraph::Print(Option_t* opt) const
17{
18 std::cout << DRED;
19 TGraphErrors::Print(opt);
20 std::cout << RESET_COLOR;
21 for(const auto& iter : fCompareMap) {
22 std::cout << DBLUE << " Data " << RESET_COLOR << std::endl;
23 iter.second.first.Print();
24 std::cout << DGREEN << " Source " << RESET_COLOR << std::endl;
25 iter.second.second.Print();
26 std::cout << std::endl;
27 }
28}
29
30void TCalGraph::Clear(Option_t* opt)
31{
32 TGraphErrors::Clear(opt);
33 fCompareMap.clear();
34}
35
36void TCalGraph::AddPoint(const TCalPoint& cal_point)
37{
38 Int_t idx = GetN();
39 SetPoint(idx, cal_point.Centroid(), cal_point.Area());
40 SetPointError(idx, cal_point.CentroidErr(), cal_point.AreaErr());
41}
42
43Int_t TCalGraph::FindClosestPointX(const Double_t& x_val)
44{
45 Int_t closest_idx = 0;
46 Double_t closest_dist = 999999.;
47 Double_t* x_arr = GetX();
48 for(int i = 0; i < GetN(); ++i) {
49 if(std::abs(x_arr[i] - x_val) < closest_dist) {
50 closest_idx = i;
51 closest_dist = std::abs(x_arr[i] - x_val);
52 }
53 }
54 return closest_idx;
55}
56
57Double_t TCalGraph::FindDistToClosestPointX(const Double_t& x_val)
58{
59 Int_t idx = FindClosestPointX(x_val);
60 return std::fabs(GetX()[idx] - x_val);
61}
62
63Int_t TCalGraph::AddLists(const TCalList& cal_list, const TSourceList& src_list)
64{
65 // This is where we build the compared list
66 const auto& cal_map = cal_list.Map();
67 const auto& src_map = src_list.Map();
68
69 std::vector<std::pair<UInt_t, Double_t>> missing_cal_values_vec;
70 std::vector<std::pair<UInt_t, Double_t>> missing_src_values_vec;
71 TCalList missing_cal_values;
72 TCalList missing_src_values;
73
74 // Look in cal_list for src_list entries
75 for(const auto& cal : cal_map) {
76 const auto& iter = src_map.find(cal.first);
77 if(iter != src_map.end()) { // we found the matching data point
78 fCompareMap.insert(std::make_pair(cal.first, std::make_pair(cal.second, iter->second)));
79 } else {
80 missing_cal_values.AddPoint(cal.second);
81 missing_cal_values_vec.emplace_back(cal.first, cal.second.Centroid());
82 }
83 }
84
85 // Find if anything is missing from source list
86 for(const auto& src_it : src_map) {
87 const auto& cal_it = cal_map.find(src_it.first);
88 if(cal_it == cal_map.end()) { // we couldn't find the src data
89 missing_src_values.AddPoint(src_it.second);
90 missing_src_values_vec.emplace_back(src_it.first, src_it.second.Centroid());
91 }
92 }
93
94 if(!missing_cal_values_vec.empty()) {
95 std::cout << DRED << "Couldn't find matching cal points for: " << std::endl;
96 for(auto mit : missing_cal_values_vec) {
97 std::cout << mit.first << " Centroid = " << mit.second << std::endl;
98 }
99 }
100 if(!missing_src_values_vec.empty()) {
101 std::cout << DGREEN << "Couldn't find matching source points for: " << std::endl;
102 for(auto mit : missing_src_values_vec) {
103 std::cout << mit.first << " Centroid = " << mit.second << std::endl;
104 }
105 }
106 std::cout << RESET_COLOR;
107
108 CorrectMissingPoints(missing_cal_values, missing_src_values);
109
110 return static_cast<Int_t>(fCompareMap.size());
111}
112
114{
115 const auto& cal_map = cal_list.Map();
116 const auto& src_map = src_list.Map();
117 std::cout << "Attempting to match points within +/- 2 keV" << std::endl;
118 for(const auto& cal_it : cal_map) {
119 for(const auto& src_it : src_map) {
120 if(std::abs(static_cast<Int_t>(cal_it.first - src_it.first)) < 3.0) {
121 fCompareMap.insert(std::make_pair(src_it.first, std::make_pair(cal_it.second, src_it.second)));
122 std::cout << "Matched: " << cal_it.first << " and " << src_it.first << std::endl;
123 break;
124 }
125 }
126 }
127}
128
130{
131 // Clear all of the data points
132 while(RemovePoint(0) != -1) {
133 }
134}
#define DRED
Definition Globals.h:18
#define DGREEN
Definition Globals.h:17
#define DBLUE
Definition Globals.h:15
#define RESET_COLOR
Definition Globals.h:5
Int_t AddLists(const TCalList &cal_list, const TSourceList &src_list)
Definition TCalGraph.cxx:63
Int_t FindClosestPointX(const Double_t &x_val)
Definition TCalGraph.cxx:43
Double_t FindDistToClosestPointX(const Double_t &x_val)
Definition TCalGraph.cxx:57
void Print(Option_t *opt="") const override
Definition TCalGraph.cxx:16
void AddPoint(const TCalPoint &cal_point)
Definition TCalGraph.cxx:36
void ClearAllPoints(Option_t *opt="")
void CorrectMissingPoints(TCalList &cal_list, TCalList &src_list)
std::map< UInt_t, std::pair< TCalPoint, TCalPoint > > fCompareMap
Definition TCalGraph.h:64
void Clear(Option_t *opt="") override
Definition TCalGraph.cxx:30
void AddPoint(const TCalPoint &point)
Definition TCalList.cxx:30
const std::map< UInt_t, TCalPoint > & Map() const
Definition TCalList.h:34
Double_t CentroidErr() const
Definition TCalPoint.h:34
Double_t Area() const
Definition TCalPoint.h:33
Double_t Centroid() const
Definition TCalPoint.h:32
Double_t AreaErr() const
Definition TCalPoint.h:35