157 lines
5.0 KiB
C++
Executable File
157 lines
5.0 KiB
C++
Executable File
#include "simulation/position_binning.h"
|
|
#include "simulation/coordinates.h"
|
|
|
|
LowerAndUpperBoundBinning::LowerAndUpperBoundBinning(int num_bins,
|
|
double maximum)
|
|
: num_bins_(num_bins), stepsize_(maximum / num_bins) {}
|
|
|
|
int LowerAndUpperBoundBinning::bin(double position) const {
|
|
const int bin = position / stepsize_;
|
|
return std::max(0, std::min(bin, num_bins_ - 1));
|
|
}
|
|
|
|
double LowerAndUpperBoundBinning::stepsize() const {
|
|
return stepsize_;
|
|
}
|
|
|
|
int LowerAndUpperBoundBinning::numBins() const {
|
|
return num_bins_;
|
|
}
|
|
|
|
std::vector<double> LowerAndUpperBoundBinning::binBorders() const {
|
|
std::vector<double> bin_borders;
|
|
for (int i = 0; i <= num_bins_; ++i) {
|
|
bin_borders.push_back(i * stepsize_);
|
|
}
|
|
return bin_borders;
|
|
}
|
|
|
|
int LowerAndUpperBoundBinning::binIndexMin() const {
|
|
return 0;
|
|
}
|
|
int LowerAndUpperBoundBinning::binIndexMax() const {
|
|
return num_bins_ - 1;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
LowerBoundBinningWithOverflow::LowerBoundBinningWithOverflow(
|
|
int num_bins_excluding_overflow,
|
|
double maximum)
|
|
: num_bins_(num_bins_excluding_overflow + 1),
|
|
stepsize_(maximum / num_bins_excluding_overflow) {}
|
|
|
|
int LowerBoundBinningWithOverflow::bin(double position) const {
|
|
const int bin = position / stepsize_;
|
|
return std::max(0, std::min(bin, num_bins_ - 1));
|
|
}
|
|
|
|
double LowerBoundBinningWithOverflow::stepsize() const {
|
|
return stepsize_;
|
|
}
|
|
|
|
int LowerBoundBinningWithOverflow::numBinsWithOverflow() const {
|
|
return num_bins_;
|
|
}
|
|
int LowerBoundBinningWithOverflow::numBinsWithoutOverflow() const {
|
|
return num_bins_ - 1;
|
|
}
|
|
std::vector<double> LowerBoundBinningWithOverflow::binBorders() const {
|
|
std::vector<double> bin_borders;
|
|
for (int i = 0; i <= num_bins_ - 1; ++i) {
|
|
bin_borders.push_back(i * stepsize_);
|
|
}
|
|
return bin_borders;
|
|
}
|
|
|
|
int LowerBoundBinningWithOverflow::binIndexMin() const {
|
|
return 0;
|
|
}
|
|
int LowerBoundBinningWithOverflow::binIndexMax() const {
|
|
return num_bins_ - 1;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
BinningWithOverAndUnderflow::BinningWithOverAndUnderflow(
|
|
int num_bins_excluding_overunderflow,
|
|
double maximum)
|
|
: num_bins_(num_bins_excluding_overunderflow + 2),
|
|
stepsize_(maximum / num_bins_excluding_overunderflow){};
|
|
|
|
int BinningWithOverAndUnderflow::bin(double position) const {
|
|
const int bin =
|
|
position < 0 ? position / stepsize_ - 1 : position / stepsize_;
|
|
return std::max(-1, std::min(bin, num_bins_ - 2));
|
|
}
|
|
|
|
double BinningWithOverAndUnderflow::stepsize() const {
|
|
return stepsize_;
|
|
}
|
|
int BinningWithOverAndUnderflow::numBinsWithOverUnderflow() const {
|
|
return num_bins_;
|
|
}
|
|
int BinningWithOverAndUnderflow::numBinsWithoutOverUnderflow() const {
|
|
return num_bins_ - 2;
|
|
}
|
|
|
|
std::vector<double> BinningWithOverAndUnderflow::binBorders() const {
|
|
std::vector<double> bin_borders;
|
|
for (int i = 0; i <= num_bins_ - 2; ++i) {
|
|
bin_borders.push_back(i * stepsize_);
|
|
}
|
|
return bin_borders;
|
|
}
|
|
|
|
int BinningWithOverAndUnderflow::binIndexMin() const {
|
|
return -1;
|
|
}
|
|
int BinningWithOverAndUnderflow::binIndexMax() const {
|
|
return num_bins_ - 2;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
CylinderBinning::CylinderBinning(int num_bins_radial,
|
|
double radius,
|
|
int num_bins_longitudinal,
|
|
double height)
|
|
: radial_binning(num_bins_radial, radius),
|
|
longitudinal_binning(num_bins_longitudinal, height) {}
|
|
|
|
blitz::TinyVector<int, 2> CylinderBinning::bin(
|
|
const blitz::TinyVector<double, 3>& cylinder_position) const {
|
|
return blitz::TinyVector<int, 2>(
|
|
radial_binning.bin(cylinder_position(0)),
|
|
longitudinal_binning.bin(cylinder_position(2)));
|
|
}
|
|
|
|
blitz::TinyVector<int, 2> CylinderBinning::numBins() const {
|
|
return blitz::TinyVector<int, 2>(
|
|
radial_binning.numBinsWithoutOverflow(),
|
|
longitudinal_binning.numBinsWithoutOverUnderflow());
|
|
}
|
|
|
|
blitz::TinyVector<double, 2> CylinderBinning::stepsize() const {
|
|
return blitz::TinyVector<double, 2>(radial_binning.stepsize(),
|
|
longitudinal_binning.stepsize());
|
|
}
|
|
|
|
blitz::TinyVector<int, 2> CylinderBinning::numBinsIncludingOverUnderflow()
|
|
const {
|
|
return blitz::TinyVector<int, 2>(
|
|
radial_binning.numBinsWithOverflow(),
|
|
longitudinal_binning.numBinsWithOverUnderflow());
|
|
}
|
|
blitz::TinyVector<int, 2> CylinderBinning::binIndexMin() const {
|
|
return blitz::TinyVector<int, 2>(radial_binning.binIndexMin(),
|
|
longitudinal_binning.binIndexMin());
|
|
}
|
|
blitz::TinyVector<int, 2> CylinderBinning::binIndexMax() const {
|
|
return blitz::TinyVector<int, 2>(radial_binning.binIndexMax(),
|
|
longitudinal_binning.binIndexMax());
|
|
}
|