Repository navigation
Expand file tree
/
Copy pathRes4Result.h
More file actions
234 lines (200 loc) · 7.36 KB
/
Copy pathRes4Result.h
File metadata and controls
234 lines (200 loc) · 7.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#ifndef SROTHMAN_EECS_RES4_RESULT_H
#define SROTHMAN_EECS_RES4_RESULT_H
#include "usings.h"
#include "Res4Axes.h"
#include "ResResultContainers.h"
#include "SRothman/SimonTools/src/histutil.h"
#include <vector>
#include <numeric>
#include <boost/multi_array.hpp>
namespace EEC{
template <class Container>
class Res4Result{
public:
Res4Result() :
dipole(),
tee(),
triangle(),
pt_denom_set(false),
pt_denom(-1) {}
constexpr static bool SHOULD_BIN = Container::SHOULD_BIN;
constexpr static bool IS_ARRAY = Container::IS_ARRAY;
using T = typename Container::TYPE;
Res4Result(
const size_t nR,
const size_t nr_dipole,
const size_t nc_dipole,
const size_t nr_tee,
const size_t nc_tee,
const size_t nr_triangle,
const size_t nc_triangle) :
dipole(nR, nr_dipole, nc_dipole),
tee(nR, nr_tee, nc_tee),
triangle(nR, nr_triangle, nc_triangle),
pt_denom_set(false),
pt_denom(-1) {}
Res4Result(const Res4Axes& axes) :
Res4Result(simon::AXextent(axes.R),
simon::AXextent(axes.r_dipole),
simon::AXextent(axes.c_dipole),
simon::AXextent(axes.r_tee),
simon::AXextent(axes.c_tee),
simon::AXextent(axes.r_triangle),
simon::AXextent(axes.c_triangle)) {}
template <typename CALCULATOR>
Res4Result(const CALCULATOR& calculator) :
Res4Result(calculator.get_axes()) {}
template <typename OtherContainer>
Res4Result(const OtherContainer& dipole,
const OtherContainer& tee,
const OtherContainer& triangle) :
dipole(dipole),
tee(tee),
triangle(triangle),
pt_denom_set(false),
pt_denom(-1) {}
template <typename OtherContainer>
Res4Result(OtherContainer&& dipole,
OtherContainer&& tee,
OtherContainer&& triangle) :
dipole(std::move(dipole)),
tee(std::move(tee)),
triangle(std::move(triangle)),
pt_denom_set(false),
pt_denom(-1) {}
template <typename OtherContainer>
Res4Result(const Res4Result<OtherContainer>& other) :
dipole(other.get_dipole()),
tee(other.get_tee()),
triangle(other.get_triangle()){
if (other.is_pt_denom_set()){
pt_denom = other.get_pt_denom();
pt_denom_set = true;
} else {
pt_denom_set = false;
pt_denom = -1;
}
}
template <typename OtherContainer>
Res4Result(Res4Result<OtherContainer>&& other) :
dipole(std::move(other.get_dipole())),
tee(std::move(other.get_tee())),
triangle(std::move(other.get_triangle())){
if (other.is_pt_denom_set()){
pt_denom = other.get_pt_denom();
pt_denom_set = true;
} else {
pt_denom_set = false;
pt_denom = -1;
}
}
void fill_dipole(
T iR, T ir,
T ic, double wt) noexcept{
dipole.fill(iR, ir, ic, wt);
};
void fill_tee(
T iR, T ir,
T ic, double wt) noexcept{
tee.fill(iR, ir, ic, wt);
}
void fill_triangle(
T iR, T ir,
T ic, double wt) noexcept{
triangle.fill(iR, ir, ic, wt);
}
void set_pt_denom(double pt_denom_) {
if (pt_denom_set){
throw std::runtime_error("pt_denom already set");
} else {
pt_denom = pt_denom_;
pt_denom_set = true;
}
}
double get_pt_denom() const {
if (!pt_denom_set){
throw std::runtime_error("pt_denom not set");
} else {
return pt_denom;
}
}
bool is_pt_denom_set() const noexcept{
return pt_denom_set;
}
const Container& get_dipole() const noexcept{
return dipole;
}
const Container& get_tee() const noexcept{
return tee;
}
const Container& get_triangle() const noexcept{
return triangle;
}
double total_dipole_weight() const noexcept{
return dipole.total_weight();
}
double total_tee_weight() const noexcept{
return tee.total_weight();
}
double total_triangle_weight() const noexcept{
return triangle.total_weight();
}
template <class OtherContainer>
bool operator==(const Res4Result<OtherContainer>& other) const noexcept{
return dipole == other.get_dipole() &&
tee == other.get_tee() &&
triangle == other.get_triangle();
}
template <class OtherContainer>
bool operator!=(const Res4Result<OtherContainer>& other) const noexcept{
return !(*this == other);
}
template <class OtherContainer>
Res4Result<Container>& operator+=(const Res4Result<OtherContainer>& other) noexcept{
dipole += other.get_dipole();
tee += other.get_tee();
triangle += other.get_triangle();
return *this;
}
template <class OtherContainer>
Res4Result<Container> operator+(const Res4Result<OtherContainer>& other) const noexcept{
Res4Result<Container> result(*this);
result += other;
return result;
}
template <class OtherContainer>
Res4Result<Container>& operator-=(const Res4Result<OtherContainer>& other) noexcept{
if constexpr(std::is_same_v<Container, ResMultiArrayContainer>){
dipole -= other.get_dipole();
tee -= other.get_tee();
triangle -= other.get_triangle();
} else {
//we only want a valid operator
//for ResMultiArrayContainer
//this is probably the wrong way
//to do this,
//but it should fail to compile
//if you try to use this operator
//with a ResVectorContainer
static_assert(std::is_same_v<Container, ResMultiArrayContainer>);
}
return *this;
}
template <class OtherContainer>
Res4Result<ResMultiArrayContainer> operator-(const Res4Result<OtherContainer>& other) const noexcept{
Res4Result<ResMultiArrayContainer> result(*this);
result -= other;
return result;
}
private:
Container dipole;
Container tee;
Container triangle;
bool pt_denom_set;
double pt_denom;
};
using Res4Result_MultiArray = Res4Result<ResMultiArrayContainer>;
using Res4Result_Vector = Res4Result<ResVectorContainer<unsigned>>;
using Res4Result_Unbinned = Res4Result<ResVectorContainer<double>>;
};
#endif