Repository navigation
Expand file tree
/
Copy pathProjTransferResultContainers.h
More file actions
247 lines (200 loc) · 8.63 KB
/
Copy pathProjTransferResultContainers.h
File metadata and controls
247 lines (200 loc) · 8.63 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
235
236
237
238
239
240
241
242
243
244
245
246
247
#ifndef SROTHMAN_EEC_PROJ_TRANSFER_CONTAINERS_H
#define SROTHMAN_EEC_PROJ_TRANSFER_CONTAINERS_H
#include "usings.h"
#include <vector>
#include <numeric>
#include <boost/multi_array.hpp>
#include "ProjResultContainers.h"
namespace EEC{
template <typename T>
class ProjTransferVectorContainer;
class ProjTransferArrayContainer{
public:
using data_t = multi_array<double, 2>;
using TYPE = unsigned;
constexpr static bool SHOULD_BIN = true;
constexpr static bool IS_ARRAY = true;
ProjTransferArrayContainer() :
nR_reco(0), nR_gen(0),
data() {
printf("WARNING: CALLING DEFAULT CONSTRUCTOR FOR ProjTransferArrayContainer\n");
}
ProjTransferArrayContainer(const size_t nR_reco,
const size_t nR_gen) :
nR_reco(nR_reco), nR_gen(nR_gen){
data.resize(boost::extents[nR_reco][nR_gen]);
std::fill(data.data(), data.data() + data.num_elements(), 0.0);
}
ProjTransferArrayContainer(ProjTransferArrayContainer&& other) :
nR_reco(other.nR_reco), nR_gen(other.nR_gen){
data.resize(boost::extents[nR_reco][nR_gen]);
data = other.get_data();
}
ProjTransferArrayContainer(const ProjTransferArrayContainer& other) :
nR_reco(other.nR_reco), nR_gen(other.nR_gen){
data.resize(boost::extents[nR_reco][nR_gen]);
data = other.get_data();
}
ProjTransferArrayContainer(const ProjTransferVectorContainer<unsigned>& other);
void fill(unsigned iR_reco, unsigned iR_gen, double wt_reco, [[maybe_unused]] double wt_gen) noexcept{
data[iR_reco][iR_gen] += wt_reco;
}
const data_t& get_data() const noexcept{
return data;
}
double total_weight_reco() const noexcept {
return std::accumulate(data.data(), data.data()+data.num_elements(), 0.0);
}
double total_weight_gen() const noexcept {
return std::accumulate(data.data(), data.data()+data.num_elements(), 0.0);
}
ProjTransferArrayContainer& operator+=(const ProjTransferArrayContainer& other) noexcept{
std::transform(data.data(), data.data()+data.num_elements(),
other.data.data(), data.data(),
std::plus<double>());
return *this;
}
ProjTransferArrayContainer& operator+=(const ProjTransferVectorContainer<unsigned> other) noexcept;
template <class OtherContainer>
ProjTransferArrayContainer operator+(const OtherContainer& other) const noexcept{
ProjTransferArrayContainer result(*this);
result += other;
return result;
}
ProjTransferArrayContainer operator-=(const ProjTransferArrayContainer& other) noexcept{
std::transform(data.data(), data.data()+data.num_elements(),
other.data.data(), data.data(),
std::minus<double>());
return *this;
}
ProjTransferArrayContainer operator-=(const ProjTransferVectorContainer<unsigned>& other) noexcept;
template <class OtherContainer>
ProjTransferArrayContainer operator-(const OtherContainer& other) const noexcept{
ProjTransferArrayContainer result(*this);
result -= other;
return result;
}
bool operator==(const ProjTransferArrayContainer& other) const noexcept{
return std::equal(data.data(), data.data()+data.num_elements(),
other.data.data(),
[](double a, double b){
return std::abs(a - b) < 1e-6;
});
}
bool operator==(const ProjTransferVectorContainer<unsigned>& other) const noexcept {
return *this== ProjTransferArrayContainer(other);
}
ProjArrayContainer get_sum_over_gen() const noexcept{
ProjArrayContainer sum(nR_reco);
for (size_t iR_reco = 0; iR_reco < nR_reco; ++iR_reco){
for (size_t iR_gen = 0; iR_gen < nR_gen; ++iR_gen){
sum.fill(iR_reco, data[iR_reco][iR_gen]);
}
}
return sum;
}
ProjArrayContainer get_sum_over_reco() const noexcept{
printf("WARNING: calling ProjArrayContainer::get_sum_over_reco()\n");
ProjArrayContainer sum(nR_gen);
for (size_t iR_reco = 0; iR_reco < nR_reco; ++iR_reco){
for (size_t iR_gen = 0; iR_gen < nR_gen; ++iR_gen){
sum.fill(iR_gen, data[iR_reco][iR_gen]);
}
}
return sum;
}
const size_t nR_reco, nR_gen;
private:
data_t data;
};
template <typename T>
class ProjTransferVectorContainer{
public:
struct entry{
T iR_reco, iR_gen;
double wt_reco, wt_gen;
entry(T iR_reco, T iR_gen, double wt_reco, double wt_gen) noexcept :
iR_reco(iR_reco), iR_gen(iR_gen), wt_reco(wt_reco), wt_gen(wt_gen) {}
};
using data_t = std::vector<entry>;
using TYPE = T;
constexpr static bool SHOULD_BIN = std::is_same<T, unsigned>::value;
constexpr static bool IS_ARRAY = false;
ProjTransferVectorContainer(const size_t nR_reco,
const size_t nR_gen) :
nR_reco(nR_reco), nR_gen(nR_gen){
data.reserve(100);
}
ProjTransferVectorContainer() :
nR_reco(0), nR_gen(0),
data() {
printf("WARNING: CALLING DEFAULT CONSTRUCTOR FOR ProjTransferVectorContainer\n");
}
ProjTransferVectorContainer(ProjTransferVectorContainer&& other) :
nR_reco(other.nR_reco), nR_gen(other.nR_gen),
data(std::move(other.data)) {}
ProjTransferVectorContainer(const ProjTransferVectorContainer& other) :
nR_reco(other.nR_reco), nR_gen(other.nR_gen),
data(other.data) {}
void fill(T iR_reco, T iR_gen, double wt_reco, double wt_gen) noexcept{
data.emplace_back(iR_reco, iR_gen, wt_reco, wt_gen);
}
ProjTransferVectorContainer<T>& operator+=(const ProjTransferVectorContainer<T>& other) noexcept {
data.insert(data.end(),
other.data.begin(),
other.data.end());
return *this;
}
template <class OtherContainer>
ProjTransferVectorContainer<T> operator+(const OtherContainer& other) const noexcept {
ProjTransferVectorContainer<T> result(*this);
result += other;
return result;
}
template <class OtherContainer>
ProjTransferArrayContainer operator-(const OtherContainer& other) const noexcept {
ProjTransferArrayContainer result(*this);
result -= other;
return result;
}
bool operator==(const ProjTransferVectorContainer& other) const noexcept{
return ProjTransferArrayContainer(*this) == ProjTransferArrayContainer(other);
}
bool operator==(const ProjTransferArrayContainer& other) const noexcept{
return ProjTransferArrayContainer(*this) == other;
}
const data_t& get_data() const noexcept{
return data;
}
double total_weight_reco() const noexcept {
return std::accumulate(data.begin(), data.end(), 0.0,
[](double sum, const entry& e) {
return sum + e.wt_reco;
});
}
double total_weight_gen() const noexcept {
return std::accumulate(data.begin(), data.end(), 0.0,
[](double sum, const entry& e) {
return sum + e.wt_gen;
});
}
ProjArrayContainer get_sum_over_gen() const noexcept{
ProjArrayContainer sum(nR_reco);
for (const auto& entry : data){
sum.fill(entry.iR_reco, entry.wt_reco);
}
return sum;
}
ProjArrayContainer get_sum_over_reco() const noexcept{
ProjArrayContainer sum(nR_gen);
for (const auto& entry : data){
sum.fill(entry.iR_gen, entry.wt_gen);
}
return sum;
}
const size_t nR_reco, nR_gen;
private:
data_t data;
};
};
#endif