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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
|
#ifndef CondFormats_PhysicsToolsObjects_Histogram3D_icc
#define CondFormats_PhysicsToolsObjects_Histogram3D_icc
#include <cmath>
#include <cstddef>
#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>
#include "FWCore/Utilities/interface/Exception.h"
#include "CondFormats/PhysicsToolsObjects/interface/Histogram3D.h"
namespace PhysicsTools {
namespace Calibration {
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::Histogram3D()
: strideX(0),
strideY(0),
limitsX(AxisX_t(), AxisX_t()),
limitsY(AxisY_t(), AxisY_t()),
limitsZ(AxisZ_t(), AxisZ_t()),
total(Value_t()) {
totalValid.store(false, std::memory_order_release);
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::Histogram3D(const Histogram3D &orig)
: strideX(orig.strideX),
strideY(orig.strideY),
binULimitsX(orig.binULimitsX),
binULimitsY(orig.binULimitsY),
binULimitsZ(orig.binULimitsZ),
binValues(orig.binValues),
limitsX(orig.limitsX),
limitsY(orig.limitsY),
limitsZ(orig.limitsZ),
total(orig.total),
rowTotal(orig.rowTotal),
columnTotal(orig.columnTotal) {
totalValid.store(orig.totalValid.load(std::memory_order_acquire), std::memory_order_release);
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
template <typename OValue_t, typename OAxisX_t, typename OAxisY_t, typename OAxisZ_t>
Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::Histogram3D(
const Histogram3D<OValue_t, OAxisX_t, OAxisY_t, OAxisZ_t> &orig)
: strideX(orig.strideX),
strideY(orig.strideY),
binULimitsX(orig.binULimitsX.begin(), orig.binULimitsX.end()),
binULimitsY(orig.binULimitsY.begin(), orig.binULimitsY.end()),
binULimitsZ(orig.binULimitsZ.begin(), orig.binULimitsZ.end()),
binValues(orig.binValues.begin(), orig.binValues.end()),
limitsX(orig.limitsX),
limitsY(orig.limitsY),
limitsZ(orig.limitsZ),
total(orig.total),
rowTotal(orig.rowTotal.begin(), orig.rowTotal.end()),
columnTotal(orig.columnTotal.begin(), orig.columnTotal.end()) {
totalValid.store(orig.totalValid.load(std::memory_order_acquire), std::memory_order_release);
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::Histogram3D(const std::vector<AxisX_t> &binULimitsX,
const std::vector<AxisY_t> &binULimitsY,
const std::vector<AxisZ_t> &binULimitsZ)
: strideX(binULimitsX.size() + 1),
strideY(binULimitsY.size() + 1),
binULimitsX(binULimitsX),
binULimitsY(binULimitsY),
binULimitsZ(binULimitsZ),
binValues((binULimitsZ.size() + 1) * strideX * strideY),
limitsX(AxisX_t(), AxisX_t()),
limitsY(AxisY_t(), AxisY_t()),
limitsZ(AxisZ_t(), AxisZ_t()),
total(Value_t()),
sliceTotal(binULimitsZ.size() + 1),
rowTotal(binULimitsY.size() + 1),
columnTotal(binULimitsX.size() + 1) {
totalValid.store(true, std::memory_order_release);
if (binULimitsX.size() < 2)
throw cms::Exception("TooFewBinsError") << "Trying to generate degenerate 3D histogram: "
"Fewer than one bin in X requested."
<< std::endl;
limitsX.min = binULimitsX.front();
limitsX.max = binULimitsX.back();
if (binULimitsY.size() < 2)
throw cms::Exception("TooFewBinsError") << "Trying to generate degenerate 3D histogram: "
"Fewer than one bin in Y requested."
<< std::endl;
limitsY.min = binULimitsY.front();
limitsY.max = binULimitsY.back();
if (binULimitsZ.size() < 2)
throw cms::Exception("TooFewBinsError") << "Trying to generate degenerate 3D histogram: "
"Fewer than one bin in 3 requested."
<< std::endl;
limitsZ.min = binULimitsZ.front();
limitsZ.max = binULimitsZ.back();
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
template <typename OAxisX_t, typename OAxisY_t, typename OAxisZ_t>
Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::Histogram3D(const std::vector<OAxisX_t> &binULimitsX,
const std::vector<OAxisY_t> &binULimitsY,
const std::vector<OAxisZ_t> &binULimitsZ)
: strideX(binULimitsX.size() + 1),
strideY(binULimitsY.size() + 1),
binULimitsX(binULimitsX.begin(), binULimitsX.end()),
binULimitsY(binULimitsY.begin(), binULimitsY.end()),
binULimitsZ(binULimitsZ.begin(), binULimitsZ.end()),
binValues((binULimitsZ.size() + 1) * strideX * strideY),
limitsX(AxisX_t(), AxisX_t()),
limitsY(AxisY_t(), AxisY_t()),
limitsZ(AxisZ_t(), AxisZ_t()),
total(Value_t()),
sliceTotal(binULimitsY.size() + 1),
rowTotal(binULimitsY.size() + 1),
columnTotal(binULimitsX.size() + 1) {
totalValid.store(true, std::memory_order_release);
if (binULimitsX.size() < 2)
throw cms::Exception("TooFewBinsError") << "Trying to generate degenerate 3D histogram: "
"Fewer than one bin in X requested."
<< std::endl;
limitsX.min = binULimitsX.front();
limitsX.max = binULimitsX.back();
if (binULimitsY.size() < 2)
throw cms::Exception("TooFewBinsError") << "Trying to generate degenerate 3D histogram: "
"Fewer than one bin in Y requested."
<< std::endl;
limitsY.min = binULimitsY.front();
limitsY.max = binULimitsY.back();
if (binULimitsZ.size() < 2)
throw cms::Exception("TooFewBinsError") << "Trying to generate degenerate 3D histogram: "
"Fewer than one bin in Z requested."
<< std::endl;
limitsZ.min = binULimitsZ.front();
limitsZ.max = binULimitsZ.back();
}
//TO BE CONVERTED FROM HISTO2D TO HISTO3D
/*
template<typename Value_t, typename AxisX_t, typename AxisY_t>
template<typename OAxisX_t, typename OAxisY_t>
Histogram3D<Value_t, AxisX_t, AxisY_t>::Histogram3D(
const std::vector<OAxisX_t> &binULimitsX,
unsigned int nBinsY,
const PhysicsTools::Calibration::Range<OAxisY_t> &rangeY) :
stride(binULimitsX.size() + 1),
binULimitsX(binULimitsX.begin(), binULimitsX.end()),
binValues((nBinsY + 2) * stride),
limitsX(AxisX_t(), AxisX_t()), limitsY(rangeY),
total(Value_t()), totalValid(true),
rowTotal(nBinsY + 2), columnTotal(binULimitsX.size() + 1)
{
if (binULimitsX.size() < 2)
throw cms::Exception("TooFewBinsError")
<< "Trying to generate degenerate 2D histogram: "
"Fewer than one bin in X requested." << std::endl;
limitsX.min = binULimitsX.front();
limitsX.max = binULimitsX.back();
if (!nBinsY)
throw cms::Exception("TooFewBinsError")
<< "Trying to generate degenerate 2D histogram: "
"Fewer than one bin in Y requested." << std::endl;
}
template<typename Value_t, typename AxisX_t, typename AxisY_t>
template<typename OAxisX_t, typename OAxisY_t>
Histogram3D<Value_t, AxisX_t, AxisY_t>::Histogram3D(
unsigned int nBinsX,
const PhysicsTools::Calibration::Range<OAxisX_t> &rangeX,
const std::vector<OAxisY_t> &binULimitsY) :
stride(nBinsX + 2),
binULimitsY(binULimitsY.begin(), binULimitsY.end()),
binValues((binULimitsY.size() + 1) * stride),
limitsX(rangeX), limitsY(AxisY_t(), AxisY_t()),
total(Value_t()), totalValid(true),
rowTotal(binULimitsY.size() + 1), columnTotal(nBinsX + 2)
{
if (!nBinsX)
throw cms::Exception("TooFewBinsError")
<< "Trying to generate degenerate 2D histogram: "
"Fewer than one bin in X requested." << std::endl;
if (binULimitsY.size() < 2)
throw cms::Exception("TooFewBinsError")
<< "Trying to generate degenerate 2D histogram: "
"Fewer than one bin in Y requested." << std::endl;
limitsY.min = binULimitsY.front();
limitsY.max = binULimitsY.back();
}
template<typename Value_t, typename AxisX_t, typename AxisY_t>
template<typename OAxisX_t, typename OAxisY_t>
Histogram3D<Value_t, AxisX_t, AxisY_t>::Histogram3D(
unsigned int nBinsX,
const PhysicsTools::Calibration::Range<OAxisX_t> &rangeX,
unsigned int nBinsY,
const PhysicsTools::Calibration::Range<OAxisY_t> &rangeY) :
stride(nBinsX + 2), binValues((nBinsY + 2) * stride),
limitsX(rangeX), limitsY(rangeY), total(Value_t()), totalValid(true),
rowTotal(nBinsY + 2), columnTotal(nBinsX + 2)
{
if (!nBinsX)
throw cms::Exception("TooFewBinsError")
<< "Trying to generate degenerate 2D histogram: "
"Fewer than one bin in X requested." << std::endl;
if (!nBinsY)
throw cms::Exception("TooFewBinsError")
<< "Trying to generate degenerate 2D histogram: "
"Fewer than one bin in Y requested." << std::endl;
}
*/
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::Histogram3D(unsigned int nBinsX,
AxisX_t minX,
AxisX_t maxX,
unsigned int nBinsY,
AxisY_t minY,
AxisY_t maxY,
unsigned int nBinsZ,
AxisZ_t minZ,
AxisZ_t maxZ)
: strideX(nBinsX + 2),
strideY(nBinsY + 2),
binValues((nBinsZ + 2) * strideX * strideY),
limitsX(minX, maxX),
limitsY(minY, maxY),
limitsZ(minZ, maxZ),
total(Value_t()),
sliceTotal(nBinsZ + 2),
rowTotal(nBinsY + 2),
columnTotal(nBinsX + 2) {
totalValid.store(true, std::memory_order_release);
if (!nBinsX)
throw cms::Exception("TooFewBinsError") << "Trying to generate degenerate 3D histogram: "
"Fewer than one bin in X requested."
<< std::endl;
if (!nBinsY)
throw cms::Exception("TooFewBinsError") << "Trying to generate degenerate 3D histogram: "
"Fewer than one bin in Y requested."
<< std::endl;
if (!nBinsZ)
throw cms::Exception("TooFewBinsError") << "Trying to generate degenerate 3D histogram: "
"Fewer than one bin in Z requested."
<< std::endl;
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::~Histogram3D() {}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t> &Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::operator=(
const Histogram3D &orig) {
strideX = orig.strideX;
strideY = orig.strideY;
binULimitsX = orig.binULimitsX;
binULimitsY = orig.binULimitsY;
binULimitsZ = orig.binULimitsZ;
binValues = orig.binValues;
limitsX = orig.limitsX;
limitsY = orig.limitsY;
limitsZ = orig.limitsZ;
total = orig.total;
totalValid.store(orig.totalValid.load(std::memory_order_acquire), std::memory_order_release);
rowTotal = orig.rowTotal;
columnTotal = orig.columnTotal;
sliceTotal = orig.sliceTotal;
return *this;
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
template <typename OValue_t, typename OAxisX_t, typename OAxisY_t, typename OAxisZ_t>
Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t> &Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::operator=(
const Histogram3D<OValue_t, OAxisX_t, OAxisY_t, OAxisZ_t> &orig) {
strideX = orig.strideX;
strideY = orig.strideY;
binULimitsX = std::vector<AxisX_t>(orig.binULimitsX.begin(), orig.binULimitsX.end());
binULimitsY = std::vector<AxisY_t>(orig.binULimitsY.begin(), orig.binULimitsY.end());
binULimitsZ = std::vector<AxisZ_t>(orig.binULimitsZ.begin(), orig.binULimitsZ.end());
binValues = std::vector<Value_t>(orig.binValues.begin(), orig.binValues.end());
limitsX = orig.limitsX;
limitsY = orig.limitsY;
limitsZ = orig.limitsZ;
total = orig.total;
totalValid.store(orig.totalValid.load(std::memory_order_acquire), std::memory_order_release);
rowTotal = std::vector<Value_t>(orig.rowTotal.begin(), orig.rowTotal.end());
columnTotal = std::vector<Value_t>(orig.columnTotal.begin(), orig.columnTotal.end());
sliceTotal = std::vector<Value_t>(orig.sliceTotal.begin(), orig.sliceTotal.end());
return *this;
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
void Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::reset() {
std::fill(binValues.begin(), binValues.end(), Value_t());
total = Value_t();
totalValid.store(true, std::memory_order_release);
sliceTotal.clear();
rowTotal.clear();
columnTotal.clear();
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
void Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::setBinContent(int bin, Value_t value) {
if (bin < 0 || (unsigned int)bin >= binValues.size())
throw cms::Exception("RangeError") << "Histogram3D bin " << bin
<< " out of range "
"[0, "
<< (binValues.size() - 1) << "]." << std::endl;
binValues[bin] = value;
totalValid.store(false, std::memory_order_release);
rowTotal.clear();
columnTotal.clear();
sliceTotal.clear();
}
/*
//TO BE CONVERTED FROM HISTO2D TO HISTO3D
template<typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
Value_t Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::normalizedXValue(
AxisX_t x, AxisY_t y) const
{
int binX = findBinX(x);
int binY = findBinY(y);
return binContent(bin2D(binX, binY)) / normalizationX(binY);
}
template<typename Value_t, typename AxisX_t, typename AxisY_t>
Value_t Histogram3D<Value_t, AxisX_t, AxisY_t>::normalizedYValue(
AxisX_t x, AxisY_t y) const
{
int binX = findBinX(x);
int binY = findBinY(y);
return binContent(bin2D(binX, binY)) / normalizationY(binX);
}
template<typename Value_t, typename AxisX_t, typename AxisY_t>
Value_t Histogram3D<Value_t, AxisX_t, AxisY_t>::normalizedXError(
AxisX_t x, AxisY_t y) const
{
int binX = findBinX(x);
int binY = findBinY(y);
return std::sqrt(binContent(bin2D(binX, binY))) / normalizationX(binY);
}
template<typename Value_t, typename AxisX_t, typename AxisY_t>
Value_t Histogram3D<Value_t, AxisX_t, AxisY_t>::normalizedYError(
AxisX_t x, AxisY_t y) const
{
int binX = findBinX(x);
int binY = findBinY(y);
return std::sqrt(binContent(bin2D(binX, binY))) / normalizationY(binX);
}
*/
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
void Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::fill(AxisX_t x, AxisY_t y, AxisZ_t z, Value_t weight) {
int bin = findBin(x, y, z);
binValues[bin] += weight;
totalValid.store(false, std::memory_order_release);
rowTotal.clear();
columnTotal.clear();
sliceTotal.clear();
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
void Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::setValues(const std::vector<Value_t> &values) {
if (values.size() != binValues.size())
throw cms::Exception("InvalidVectorSizeError") << "Invalid vector size while setting "
"3D histogram values"
<< std::endl;
binValues = values;
totalValid.store(false, std::memory_order_release);
rowTotal.clear();
columnTotal.clear();
sliceTotal.clear();
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
template <typename OValue_t>
void Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::setValues(const std::vector<OValue_t> &values) {
if (values.size() != binValues.size())
throw cms::Exception("InvalidVectorSizeError") << "Invalid vector size while setting "
"3D histogram values"
<< std::endl;
std::copy(values.begin(), values.end(), binValues.begin());
totalValid.store(false, std::memory_order_release);
rowTotal.clear();
columnTotal.clear();
sliceTotal.clear();
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
typename Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::RangeX
Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::binRangeX(int binX) const {
if (binX < 1 || (unsigned int)binX > strideX - 2)
throw cms::Exception("RangeError") << "Histogram3D X bin " << binX << " out of range "
<< "[1, " << (strideX - 2) << "]." << std::endl;
if (hasEquidistantBinsX()) {
AxisX_t min = (AxisX_t)(binX - 1) / (strideX - 2);
AxisX_t max = (AxisX_t)binX / (strideX - 2);
min *= limitsX.width();
min += limitsX.min;
max *= limitsX.width();
max += limitsX.min;
return RangeX(min, max);
} else
return RangeX(binULimitsX[binX - 1], binULimitsX[binX]);
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
typename Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::RangeY
Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::binRangeY(int binY) const {
if (binY < 1 || (unsigned int)binY > strideY - 2)
throw cms::Exception("RangeError") << "Histogram3D Y bin " << binY << " out of range "
<< "[1, " << (strideY - 2) << "]." << std::endl;
if (hasEquidistantBinsY()) {
AxisY_t min = (AxisY_t)(binY - 1) / (strideY - 2);
AxisY_t max = (AxisY_t)binY / (strideY - 2);
min *= limitsY.width();
min += limitsY.min;
max *= limitsY.width();
max += limitsY.min;
return RangeY(min, max);
} else
return RangeY(binULimitsY[binY - 1], binULimitsY[binY]);
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
typename Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::RangeZ
Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::binRangeZ(int binZ) const {
unsigned int size = binValues.size() / (strideX * strideY);
if (binZ < 1 || (unsigned int)binZ > size - 2)
throw cms::Exception("RangeError") << "Histogram3D Z bin " << binZ << " out of range "
<< "[1, " << (size - 2) << "]." << std::endl;
if (hasEquidistantBinsZ()) {
AxisZ_t min = (AxisY_t)(binZ - 1) / (size - 2);
AxisZ_t max = (AxisY_t)binZ / (size - 2);
min *= limitsZ.width();
min += limitsZ.min;
max *= limitsZ.width();
max += limitsZ.min;
return RangeZ(min, max);
} else
return RangeZ(binULimitsZ[binZ - 1], binULimitsZ[binZ]);
}
//TO BE CONVERTED FROM HISTO2D TO HISTO3D
/*
template<typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
std::pair<typename Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::RangeX,
typename Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::RangeY,
typename Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::RangeZ>
Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::binRange(int bin) const
{
std::size_t size = binValues.size();
if (bin < 1 || (unsigned int)bin > size - 2)
throw cms::Exception("RangeError")
<< "Histogram3D bin " << bin << " out of range "
<< "[1, " << (size - 2) << "]." << std::endl;
return std::make_pair(binRangeX(bin % stride),
binRangeY(bin / stride));
}
*/
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
int Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::findBinX(AxisX_t x) const {
if (hasEquidistantBinsX()) {
x -= limitsX.min;
x *= strideX - 2;
x /= limitsX.width();
unsigned int iStrideX = strideX;
return clamp(0, (int)(std::floor(x)) + 1, (int)iStrideX - 1);
} else
return std::upper_bound(binULimitsX.begin(), binULimitsX.end(), x) - binULimitsX.begin();
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
int Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::findBinY(AxisY_t y) const {
if (hasEquidistantBinsY()) {
y -= limitsY.min;
y *= strideY - 2;
y /= limitsY.width();
unsigned int iStrideY = strideY;
return clamp(0, (int)(std::floor(y)) + 1, (int)iStrideY - 1);
} else
return std::upper_bound(binULimitsY.begin(), binULimitsY.end(), y) - binULimitsY.begin();
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
int Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::findBinZ(AxisZ_t z) const {
unsigned int size = binValues.size() / (strideX * strideY);
if (hasEquidistantBinsZ()) {
z -= limitsZ.min;
z *= size - 2;
z /= limitsZ.width();
return clamp(0, (int)(std::floor(z)) + 1, (int)size - 1);
} else
return std::upper_bound(binULimitsZ.begin(), binULimitsZ.end(), z) - binULimitsZ.begin();
}
template <typename Value_t, typename AxisX_t, typename AxisY_t, typename AxisZ_t>
Value_t Histogram3D<Value_t, AxisX_t, AxisY_t, AxisZ_t>::normalization() const {
if (!totalValid.load(std::memory_order_acquire)) {
total = std::accumulate(binValues.begin() + 1, binValues.end() - 1, Value_t());
totalValid.store(true, std::memory_order_release);
}
return total;
}
/*
//TO BE CONVERTED FROM HISTO2D TO HISTO3D
template<typename Value_t, typename AxisX_t, typename AxisY_t>
Value_t Histogram3D<Value_t, AxisX_t, AxisY_t>::normalizationX(int binY) const
{
if (rowTotal.empty()) {
rowTotal.resize(binValues.size() / stride);
typename std::vector<Value_t>::iterator sum = rowTotal.begin();
for(typename std::vector<Value_t>::const_iterator iter =
binValues.begin();
iter != binValues.end(); iter += stride)
*sum++ = std::accumulate(iter + 1, iter + (stride - 1),
Value_t());
}
if (binY < 0 || (unsigned int)binY >= binValues.size() / stride)
throw cms::Exception("RangeError")
<< "Histogram3D bin " << binY << " in Y out of range "
"[0, " << (binValues.size() / stride - 1) << "]." << std::endl;
return rowTotal[binY];
}
template<typename Value_t, typename AxisX_t, typename AxisY_t>
Value_t Histogram3D<Value_t, AxisX_t, AxisY_t>::normalizationY(int binX) const
{
if (columnTotal.empty()) {
columnTotal.resize(stride);
typename std::vector<Value_t>::iterator sum =
columnTotal.begin();
for(typename std::vector<Value_t>::const_iterator col =
binValues.begin();
col != binValues.begin() + stride; ++col) {
Value_t value = Value_t();
for(typename std::vector<Value_t>::const_iterator pos =
col + stride;
pos < (binValues.end() - stride); pos += stride)
value += *pos;
*sum++ = value;
}
}
if (binX < 0 || (unsigned int)binX >= stride)
throw cms::Exception("RangeError")
<< "Histogram3D bin " << binX << " in X out of range "
"[0, " << (stride - 1) << "]." << std::endl;
return columnTotal[binX];
}
*/
} // namespace Calibration
} // namespace PhysicsTools
#endif // CondFormats_PhysicsToolsObjects_Histogram3D_icc
|