mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-23 11:57:58 +02:00
solved merge conflict
This commit is contained in:
@ -34,9 +34,25 @@ ClusterFile<ClusterType>::ClusterFile(const std::filesystem::path &fname,
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
template <typename ClusterType> ClusterFile<ClusterType>::~ClusterFile() {
|
||||
close();
|
||||
}
|
||||
=======
|
||||
void ClusterFile::set_roi(ROI roi){
|
||||
m_roi = roi;
|
||||
}
|
||||
|
||||
void ClusterFile::set_noise_map(const NDView<int32_t, 2> noise_map){
|
||||
m_noise_map = NDArray<int32_t, 2>(noise_map);
|
||||
}
|
||||
|
||||
void ClusterFile::set_gain_map(const NDView<double, 2> gain_map){
|
||||
m_gain_map = NDArray<double, 2>(gain_map);
|
||||
}
|
||||
|
||||
ClusterFile::~ClusterFile() { close(); }
|
||||
>>>>>>> developer
|
||||
|
||||
template <typename ClusterType> void ClusterFile<ClusterType>::close() {
|
||||
if (fp) {
|
||||
@ -56,16 +72,43 @@ void ClusterFile<ClusterType>::write_frame(
|
||||
!(clusters.cluster_size_y() == 3)) {
|
||||
throw std::runtime_error("Only 3x3 clusters are supported");
|
||||
}
|
||||
//First write the frame number - 4 bytes
|
||||
int32_t frame_number = clusters.frame_number();
|
||||
fwrite(&frame_number, sizeof(frame_number), 1, fp);
|
||||
if(fwrite(&frame_number, sizeof(frame_number), 1, fp)!=1){
|
||||
throw std::runtime_error(LOCATION + "Could not write frame number");
|
||||
}
|
||||
|
||||
//Then write the number of clusters - 4 bytes
|
||||
uint32_t n_clusters = clusters.size();
|
||||
fwrite(&n_clusters, sizeof(n_clusters), 1, fp);
|
||||
fwrite(clusters.data(), clusters.item_size(), clusters.size(), fp);
|
||||
if(fwrite(&n_clusters, sizeof(n_clusters), 1, fp)!=1){
|
||||
throw std::runtime_error(LOCATION + "Could not write number of clusters");
|
||||
}
|
||||
|
||||
//Now write the clusters in the frame
|
||||
if(fwrite(clusters.data(), clusters.item_size(), clusters.size(), fp)!=clusters.size()){
|
||||
throw std::runtime_error(LOCATION + "Could not write clusters");
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
template <typename ClusterType>
|
||||
ClusterVector<ClusterType>
|
||||
ClusterFile<ClusterType>::read_clusters(size_t n_clusters) {
|
||||
=======
|
||||
|
||||
ClusterVector<int32_t> ClusterFile::read_clusters(size_t n_clusters){
|
||||
if (m_mode != "r") {
|
||||
throw std::runtime_error("File not opened for reading");
|
||||
}
|
||||
if (m_noise_map || m_roi){
|
||||
return read_clusters_with_cut(n_clusters);
|
||||
}else{
|
||||
return read_clusters_without_cut(n_clusters);
|
||||
}
|
||||
}
|
||||
|
||||
ClusterVector<int32_t> ClusterFile::read_clusters_without_cut(size_t n_clusters) {
|
||||
>>>>>>> developer
|
||||
if (m_mode != "r") {
|
||||
throw std::runtime_error("File not opened for reading");
|
||||
}
|
||||
@ -96,6 +139,7 @@ ClusterFile<ClusterType>::read_clusters(size_t n_clusters) {
|
||||
if (nph_read < n_clusters) {
|
||||
// keep on reading frames and photons until reaching n_clusters
|
||||
while (fread(&iframe, sizeof(iframe), 1, fp)) {
|
||||
clusters.set_frame_number(iframe);
|
||||
// read number of clusters in frame
|
||||
if (fread(&nph, sizeof(nph), 1, fp)) {
|
||||
if (nph > (n_clusters - nph_read))
|
||||
@ -115,9 +159,12 @@ ClusterFile<ClusterType>::read_clusters(size_t n_clusters) {
|
||||
// Resize the vector to the number of clusters.
|
||||
// No new allocation, only change bounds.
|
||||
clusters.resize(nph_read);
|
||||
if(m_gain_map)
|
||||
clusters.apply_gain_map(m_gain_map->view());
|
||||
return clusters;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
template <typename ClusterType>
|
||||
ClusterVector<ClusterType>
|
||||
ClusterFile<ClusterType>::read_clusters(size_t n_clusters, ROI roi) {
|
||||
@ -200,6 +247,109 @@ ClusterFile<ClusterType>::read_clusters(size_t n_clusters, ROI roi) {
|
||||
|
||||
template <typename ClusterType>
|
||||
ClusterVector<ClusterType> ClusterFile<ClusterType>::read_frame() {
|
||||
=======
|
||||
|
||||
|
||||
ClusterVector<int32_t> ClusterFile::read_clusters_with_cut(size_t n_clusters) {
|
||||
ClusterVector<int32_t> clusters(3,3);
|
||||
clusters.reserve(n_clusters);
|
||||
|
||||
// if there are photons left from previous frame read them first
|
||||
if (m_num_left) {
|
||||
while(m_num_left && clusters.size() < n_clusters){
|
||||
Cluster3x3 c = read_one_cluster();
|
||||
if(is_selected(c)){
|
||||
clusters.push_back(c.x, c.y, reinterpret_cast<std::byte*>(c.data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// we did not have enough clusters left in the previous frame
|
||||
// keep on reading frames until reaching n_clusters
|
||||
if (clusters.size() < n_clusters) {
|
||||
// sanity check
|
||||
if (m_num_left) {
|
||||
throw std::runtime_error(LOCATION + "Entered second loop with clusters left\n");
|
||||
}
|
||||
|
||||
int32_t frame_number = 0; // frame number needs to be 4 bytes!
|
||||
while (fread(&frame_number, sizeof(frame_number), 1, fp)) {
|
||||
if (fread(&m_num_left, sizeof(m_num_left), 1, fp)) {
|
||||
clusters.set_frame_number(frame_number); //cluster vector will hold the last frame number
|
||||
while(m_num_left && clusters.size() < n_clusters){
|
||||
Cluster3x3 c = read_one_cluster();
|
||||
if(is_selected(c)){
|
||||
clusters.push_back(c.x, c.y, reinterpret_cast<std::byte*>(c.data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// we have enough clusters, break out of the outer while loop
|
||||
if (clusters.size() >= n_clusters)
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if(m_gain_map)
|
||||
clusters.apply_gain_map(m_gain_map->view());
|
||||
|
||||
return clusters;
|
||||
}
|
||||
|
||||
Cluster3x3 ClusterFile::read_one_cluster(){
|
||||
Cluster3x3 c;
|
||||
auto rc = fread(&c, sizeof(c), 1, fp);
|
||||
if (rc != 1) {
|
||||
throw std::runtime_error(LOCATION + "Could not read cluster");
|
||||
}
|
||||
--m_num_left;
|
||||
return c;
|
||||
}
|
||||
|
||||
ClusterVector<int32_t> ClusterFile::read_frame(){
|
||||
if (m_mode != "r") {
|
||||
throw std::runtime_error(LOCATION + "File not opened for reading");
|
||||
}
|
||||
if (m_noise_map || m_roi){
|
||||
return read_frame_with_cut();
|
||||
}else{
|
||||
return read_frame_without_cut();
|
||||
}
|
||||
}
|
||||
|
||||
ClusterVector<int32_t> ClusterFile::read_frame_without_cut() {
|
||||
if (m_mode != "r") {
|
||||
throw std::runtime_error("File not opened for reading");
|
||||
}
|
||||
if (m_num_left) {
|
||||
throw std::runtime_error(
|
||||
"There are still photons left in the last frame");
|
||||
}
|
||||
int32_t frame_number;
|
||||
if (fread(&frame_number, sizeof(frame_number), 1, fp) != 1) {
|
||||
throw std::runtime_error(LOCATION + "Could not read frame number");
|
||||
}
|
||||
|
||||
int32_t n_clusters; // Saved as 32bit integer in the cluster file
|
||||
if (fread(&n_clusters, sizeof(n_clusters), 1, fp) != 1) {
|
||||
throw std::runtime_error(LOCATION + "Could not read number of clusters");
|
||||
}
|
||||
|
||||
ClusterVector<int32_t> clusters(3, 3, n_clusters);
|
||||
clusters.set_frame_number(frame_number);
|
||||
|
||||
if (fread(clusters.data(), clusters.item_size(), n_clusters, fp) !=
|
||||
static_cast<size_t>(n_clusters)) {
|
||||
throw std::runtime_error(LOCATION + "Could not read clusters");
|
||||
}
|
||||
clusters.resize(n_clusters);
|
||||
if (m_gain_map)
|
||||
clusters.apply_gain_map(m_gain_map->view());
|
||||
return clusters;
|
||||
}
|
||||
|
||||
ClusterVector<int32_t> ClusterFile::read_frame_with_cut() {
|
||||
>>>>>>> developer
|
||||
if (m_mode != "r") {
|
||||
throw std::runtime_error("File not opened for reading");
|
||||
}
|
||||
@ -212,22 +362,31 @@ ClusterVector<ClusterType> ClusterFile<ClusterType>::read_frame() {
|
||||
throw std::runtime_error("Could not read frame number");
|
||||
}
|
||||
|
||||
int32_t n_clusters; // Saved as 32bit integer in the cluster file
|
||||
if (fread(&n_clusters, sizeof(n_clusters), 1, fp) != 1) {
|
||||
|
||||
if (fread(&m_num_left, sizeof(m_num_left), 1, fp) != 1) {
|
||||
throw std::runtime_error("Could not read number of clusters");
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
// std::vector<Cluster3x3> clusters(n_clusters);
|
||||
ClusterVector<ClusterType> clusters(n_clusters);
|
||||
=======
|
||||
|
||||
ClusterVector<int32_t> clusters(3, 3);
|
||||
clusters.reserve(m_num_left);
|
||||
>>>>>>> developer
|
||||
clusters.set_frame_number(frame_number);
|
||||
|
||||
if (fread(clusters.data(), clusters.item_size(), n_clusters, fp) !=
|
||||
static_cast<size_t>(n_clusters)) {
|
||||
throw std::runtime_error("Could not read clusters");
|
||||
while(m_num_left){
|
||||
Cluster3x3 c = read_one_cluster();
|
||||
if(is_selected(c)){
|
||||
clusters.push_back(c.x, c.y, reinterpret_cast<std::byte*>(c.data));
|
||||
}
|
||||
}
|
||||
clusters.resize(n_clusters);
|
||||
if (m_gain_map)
|
||||
clusters.apply_gain_map(m_gain_map->view());
|
||||
return clusters;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// std::vector<Cluster3x3> ClusterFile::read_cluster_with_cut(size_t n_clusters,
|
||||
// double *noise_map,
|
||||
// int nx, int ny) {
|
||||
@ -245,17 +404,23 @@ ClusterVector<ClusterType> ClusterFile<ClusterType>::read_frame() {
|
||||
// // uint32_t nn = *n_left;
|
||||
// uint32_t nn = m_num_left;
|
||||
// size_t nph_read = 0;
|
||||
=======
|
||||
|
||||
// int32_t t2max, tot1;
|
||||
// int32_t tot3;
|
||||
// // Cluster *ptr = buf;
|
||||
// Cluster3x3 *ptr = clusters.data();
|
||||
// int good = 1;
|
||||
// double noise;
|
||||
// // read photons left from previous frame
|
||||
// if (noise_map)
|
||||
// printf("Using noise map\n");
|
||||
>>>>>>> developer
|
||||
|
||||
bool ClusterFile::is_selected(Cluster3x3 &cl) {
|
||||
//Should fail fast
|
||||
if (m_roi) {
|
||||
if (!(m_roi->contains(cl.x, cl.y))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (m_noise_map){
|
||||
int32_t sum_1x1 = cl.data[4]; // central pixel
|
||||
int32_t sum_2x2 = cl.sum_2x2(); // highest sum of 2x2 subclusters
|
||||
int32_t sum_3x3 = cl.sum(); // sum of all pixels
|
||||
|
||||
<<<<<<< HEAD
|
||||
// if (nph) {
|
||||
// if (nph > n_clusters) {
|
||||
// // if we have more photons left in the frame then photons to
|
||||
@ -359,11 +524,22 @@ ClusterVector<ClusterType> ClusterFile<ClusterType>::read_frame() {
|
||||
// clusters.resize(nph_read);
|
||||
// return clusters;
|
||||
// }
|
||||
=======
|
||||
auto noise = (*m_noise_map)(cl.y, cl.x); //TODO! check if this is correct
|
||||
if (sum_1x1 <= noise || sum_2x2 <= 2 * noise || sum_3x3 <= 3 * noise) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//we passed all checks
|
||||
return true;
|
||||
}
|
||||
>>>>>>> developer
|
||||
|
||||
template <typename ClusterType>
|
||||
NDArray<double, 2> calculate_eta2(ClusterVector<ClusterType> &clusters) {
|
||||
// TOTO! make work with 2x2 clusters
|
||||
NDArray<double, 2> eta2({static_cast<int64_t>(clusters.size()), 2});
|
||||
<<<<<<< HEAD
|
||||
|
||||
for (size_t i = 0; i < clusters.size(); i++) {
|
||||
auto e = calculate_eta2<ClusterType>(clusters.at(i));
|
||||
@ -371,6 +547,25 @@ NDArray<double, 2> calculate_eta2(ClusterVector<ClusterType> &clusters) {
|
||||
eta2(i, 1) = e.y;
|
||||
}
|
||||
|
||||
=======
|
||||
|
||||
if (clusters.cluster_size_x() == 3 || clusters.cluster_size_y() == 3) {
|
||||
for (size_t i = 0; i < clusters.size(); i++) {
|
||||
auto e = calculate_eta2(clusters.at<Cluster3x3>(i));
|
||||
eta2(i, 0) = e.x;
|
||||
eta2(i, 1) = e.y;
|
||||
}
|
||||
}else if(clusters.cluster_size_x() == 2 || clusters.cluster_size_y() == 2){
|
||||
for (size_t i = 0; i < clusters.size(); i++) {
|
||||
auto e = calculate_eta2(clusters.at<Cluster2x2>(i));
|
||||
eta2(i, 0) = e.x;
|
||||
eta2(i, 1) = e.y;
|
||||
}
|
||||
}else{
|
||||
throw std::runtime_error("Only 3x3 and 2x2 clusters are supported");
|
||||
}
|
||||
|
||||
>>>>>>> developer
|
||||
return eta2;
|
||||
}
|
||||
|
||||
@ -476,6 +671,7 @@ template <typename T> Eta2 calculate_eta2(Cluster<T, 3, 3> &cl) {
|
||||
return eta;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
template <typename T> Eta2 calculate_eta2(Cluster<T, 2, 2> &cl) {
|
||||
Eta2 eta{};
|
||||
|
||||
@ -490,107 +686,19 @@ template <typename T> Eta2 calculate_eta2(Cluster<T, 2, 2> &cl) {
|
||||
int analyze_cluster(Cluster<int32_t, 3, 3> &cl, int32_t *t2, int32_t *t3,
|
||||
char *quad, double *eta2x, double *eta2y, double *eta3x,
|
||||
double *eta3y) {
|
||||
=======
|
||||
>>>>>>> developer
|
||||
|
||||
return analyze_data(cl.data, t2, t3, quad, eta2x, eta2y, eta3x, eta3y);
|
||||
Eta2 calculate_eta2(Cluster2x2 &cl) {
|
||||
Eta2 eta{};
|
||||
if ((cl.data[0] + cl.data[1]) != 0)
|
||||
eta.x = static_cast<double>(cl.data[1]) / (cl.data[0] + cl.data[1]);
|
||||
if ((cl.data[0] + cl.data[2]) != 0)
|
||||
eta.y = static_cast<double>(cl.data[2]) / (cl.data[0] + cl.data[2]);
|
||||
eta.sum = cl.data[0] + cl.data[1] + cl.data[2]+ cl.data[3];
|
||||
eta.c = cBottomLeft; //TODO! This is not correct, but need to put something
|
||||
return eta;
|
||||
}
|
||||
|
||||
int analyze_data(int32_t *data, int32_t *t2, int32_t *t3, char *quad,
|
||||
double *eta2x, double *eta2y, double *eta3x, double *eta3y) {
|
||||
|
||||
int ok = 1;
|
||||
|
||||
int32_t tot2[4];
|
||||
int32_t t2max = 0;
|
||||
char c = 0;
|
||||
int32_t val, tot3;
|
||||
|
||||
tot3 = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
tot2[i] = 0;
|
||||
|
||||
for (int ix = 0; ix < 3; ix++) {
|
||||
for (int iy = 0; iy < 3; iy++) {
|
||||
val = data[iy * 3 + ix];
|
||||
// printf ("%d ",data[iy * 3 + ix]);
|
||||
tot3 += val;
|
||||
if (ix <= 1 && iy <= 1)
|
||||
tot2[cBottomLeft] += val;
|
||||
if (ix >= 1 && iy <= 1)
|
||||
tot2[cBottomRight] += val;
|
||||
if (ix <= 1 && iy >= 1)
|
||||
tot2[cTopLeft] += val;
|
||||
if (ix >= 1 && iy >= 1)
|
||||
tot2[cTopRight] += val;
|
||||
}
|
||||
// printf ("\n");
|
||||
}
|
||||
// printf ("\n");
|
||||
|
||||
if (t2 || quad) {
|
||||
|
||||
t2max = tot2[0];
|
||||
c = cBottomLeft;
|
||||
for (int i = 1; i < 4; i++) {
|
||||
if (tot2[i] > t2max) {
|
||||
t2max = tot2[i];
|
||||
c = i;
|
||||
}
|
||||
}
|
||||
// printf("*** %d %d %d %d --
|
||||
// %d\n",tot2[0],tot2[1],tot2[2],tot2[3],t2max);
|
||||
if (quad)
|
||||
*quad = c;
|
||||
if (t2)
|
||||
*t2 = t2max;
|
||||
}
|
||||
|
||||
if (t3)
|
||||
*t3 = tot3;
|
||||
|
||||
if (eta2x || eta2y) {
|
||||
if (eta2x)
|
||||
*eta2x = 0;
|
||||
if (eta2y)
|
||||
*eta2y = 0;
|
||||
switch (c) {
|
||||
case cBottomLeft:
|
||||
if (eta2x && (data[3] + data[4]) != 0)
|
||||
*eta2x = static_cast<double>(data[4]) / (data[3] + data[4]);
|
||||
if (eta2y && (data[1] + data[4]) != 0)
|
||||
*eta2y = static_cast<double>(data[4]) / (data[1] + data[4]);
|
||||
break;
|
||||
case cBottomRight:
|
||||
if (eta2x && (data[2] + data[5]) != 0)
|
||||
*eta2x = static_cast<double>(data[5]) / (data[4] + data[5]);
|
||||
if (eta2y && (data[1] + data[4]) != 0)
|
||||
*eta2y = static_cast<double>(data[4]) / (data[1] + data[4]);
|
||||
break;
|
||||
case cTopLeft:
|
||||
if (eta2x && (data[7] + data[4]) != 0)
|
||||
*eta2x = static_cast<double>(data[4]) / (data[3] + data[4]);
|
||||
if (eta2y && (data[7] + data[4]) != 0)
|
||||
*eta2y = static_cast<double>(data[7]) / (data[7] + data[4]);
|
||||
break;
|
||||
case cTopRight:
|
||||
if (eta2x && t2max != 0)
|
||||
*eta2x = static_cast<double>(data[5]) / (data[5] + data[4]);
|
||||
if (eta2y && t2max != 0)
|
||||
*eta2y = static_cast<double>(data[7]) / (data[7] + data[4]);
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
||||
if (eta3x || eta3y) {
|
||||
if (eta3x && (data[3] + data[4] + data[5]) != 0)
|
||||
*eta3x = static_cast<double>(-data[3] + data[3 + 2]) /
|
||||
(data[3] + data[4] + data[5]);
|
||||
if (eta3y && (data[1] + data[4] + data[7]) != 0)
|
||||
*eta3y = static_cast<double>(-data[1] + data[2 * 3 + 1]) /
|
||||
(data[1] + data[4] + data[7]);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
} // namespace aare
|
80
src/ClusterFile.test.cpp
Normal file
80
src/ClusterFile.test.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include "aare/ClusterFile.hpp"
|
||||
#include "test_config.hpp"
|
||||
|
||||
|
||||
#include "aare/defs.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <filesystem>
|
||||
|
||||
|
||||
|
||||
|
||||
using aare::ClusterFile;
|
||||
|
||||
TEST_CASE("Read one frame from a a cluster file", "[.integration]") {
|
||||
//We know that the frame has 97 clusters
|
||||
auto fpath = test_data_path() / "clusters" / "single_frame_97_clustrers.clust";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
||||
ClusterFile f(fpath);
|
||||
auto clusters = f.read_frame();
|
||||
REQUIRE(clusters.size() == 97);
|
||||
REQUIRE(clusters.frame_number() == 135);
|
||||
}
|
||||
|
||||
TEST_CASE("Read one frame using ROI", "[.integration]") {
|
||||
//We know that the frame has 97 clusters
|
||||
auto fpath = test_data_path() / "clusters" / "single_frame_97_clustrers.clust";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
||||
ClusterFile f(fpath);
|
||||
aare::ROI roi;
|
||||
roi.xmin = 0;
|
||||
roi.xmax = 50;
|
||||
roi.ymin = 200;
|
||||
roi.ymax = 249;
|
||||
f.set_roi(roi);
|
||||
auto clusters = f.read_frame();
|
||||
REQUIRE(clusters.size() == 49);
|
||||
REQUIRE(clusters.frame_number() == 135);
|
||||
|
||||
//Check that all clusters are within the ROI
|
||||
for (size_t i = 0; i < clusters.size(); i++) {
|
||||
auto c = clusters.at<aare::Cluster3x3>(i);
|
||||
REQUIRE(c.x >= roi.xmin);
|
||||
REQUIRE(c.x <= roi.xmax);
|
||||
REQUIRE(c.y >= roi.ymin);
|
||||
REQUIRE(c.y <= roi.ymax);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Read clusters from single frame file", "[.integration]") {
|
||||
|
||||
auto fpath = test_data_path() / "clusters" / "single_frame_97_clustrers.clust";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
||||
SECTION("Read fewer clusters than available") {
|
||||
ClusterFile f(fpath);
|
||||
auto clusters = f.read_clusters(50);
|
||||
REQUIRE(clusters.size() == 50);
|
||||
REQUIRE(clusters.frame_number() == 135);
|
||||
}
|
||||
SECTION("Read more clusters than available") {
|
||||
ClusterFile f(fpath);
|
||||
// 100 is the maximum number of clusters read
|
||||
auto clusters = f.read_clusters(100);
|
||||
REQUIRE(clusters.size() == 97);
|
||||
REQUIRE(clusters.frame_number() == 135);
|
||||
}
|
||||
SECTION("Read all clusters") {
|
||||
ClusterFile f(fpath);
|
||||
auto clusters = f.read_clusters(97);
|
||||
REQUIRE(clusters.size() == 97);
|
||||
REQUIRE(clusters.frame_number() == 135);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -14,41 +14,41 @@ Interpolator::Interpolator(NDView<double, 3> etacube, NDView<double, 1> xbins,
|
||||
"The shape of the etacube does not match the shape of the bins");
|
||||
}
|
||||
|
||||
// Cumulative sum in the x direction, can maybe be combined with a copy?
|
||||
for (ssize_t k = 0; k < m_ietax.shape(2); k++) {
|
||||
// Cumulative sum in the x direction
|
||||
for (ssize_t i = 1; i < m_ietax.shape(0); i++) {
|
||||
for (ssize_t j = 0; j < m_ietax.shape(1); j++) {
|
||||
for (ssize_t i = 1; i < m_ietax.shape(0); i++) {
|
||||
for (ssize_t k = 0; k < m_ietax.shape(2); k++) {
|
||||
m_ietax(i, j, k) += m_ietax(i - 1, j, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize by the highest row, if norm less than 1 don't do anything
|
||||
for (ssize_t k = 0; k < m_ietax.shape(2); k++) {
|
||||
for (ssize_t i = 0; i < m_ietax.shape(0); i++) {
|
||||
for (ssize_t j = 0; j < m_ietax.shape(1); j++) {
|
||||
auto val = m_ietax(m_ietax.shape(0) - 1, j, k);
|
||||
double norm = val < 1 ? 1 : val;
|
||||
for (ssize_t i = 0; i < m_ietax.shape(0); i++) {
|
||||
for (ssize_t k = 0; k < m_ietax.shape(2); k++) {
|
||||
auto val = m_ietax(m_ietax.shape(0) - 1, j, k);
|
||||
double norm = val < 1 ? 1 : val;
|
||||
m_ietax(i, j, k) /= norm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cumulative sum in the y direction
|
||||
for (ssize_t k = 0; k < m_ietay.shape(2); k++) {
|
||||
for (ssize_t i = 0; i < m_ietay.shape(0); i++) {
|
||||
for (ssize_t j = 1; j < m_ietay.shape(1); j++) {
|
||||
for (ssize_t i = 0; i < m_ietay.shape(0); i++) {
|
||||
for (ssize_t j = 1; j < m_ietay.shape(1); j++) {
|
||||
for (ssize_t k = 0; k < m_ietay.shape(2); k++) {
|
||||
m_ietay(i, j, k) += m_ietay(i, j - 1, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize by the highest column, if norm less than 1 don't do anything
|
||||
for (ssize_t k = 0; k < m_ietay.shape(2); k++) {
|
||||
for (ssize_t i = 0; i < m_ietay.shape(0); i++) {
|
||||
auto val = m_ietay(i, m_ietay.shape(1) - 1, k);
|
||||
double norm = val < 1 ? 1 : val;
|
||||
for (ssize_t j = 0; j < m_ietay.shape(1); j++) {
|
||||
for (ssize_t i = 0; i < m_ietay.shape(0); i++) {
|
||||
for (ssize_t j = 0; j < m_ietay.shape(1); j++) {
|
||||
for (ssize_t k = 0; k < m_ietay.shape(2); k++) {
|
||||
auto val = m_ietay(i, m_ietay.shape(1) - 1, k);
|
||||
double norm = val < 1 ? 1 : val;
|
||||
m_ietay(i, j, k) /= norm;
|
||||
}
|
||||
}
|
||||
@ -110,8 +110,8 @@ Interpolator::interpolate(const ClusterVector<ClusterType> &clusters) {
|
||||
dY = -1.;
|
||||
break;
|
||||
}
|
||||
photon.x += m_ietax(ix, iy, 0) * 2 + dX;
|
||||
photon.y += m_ietay(ix, iy, 0) * 2 + dY;
|
||||
photon.x += m_ietax(ix, iy, ie) * 2 + dX;
|
||||
photon.y += m_ietay(ix, iy, ie) * 2 + dY;
|
||||
photons.push_back(photon);
|
||||
}
|
||||
} else if (clusters.cluster_size_x() == 2 ||
|
||||
@ -136,10 +136,10 @@ Interpolator::interpolate(const ClusterVector<ClusterType> &clusters) {
|
||||
auto ix = last_smaller(m_etabinsx, eta.x);
|
||||
auto iy = last_smaller(m_etabinsy, eta.y);
|
||||
|
||||
photon.x +=
|
||||
m_ietax(ix, iy, 0) * 2; // eta goes between 0 and 1 but we could
|
||||
// move the hit anywhere in the 2x2
|
||||
photon.y += m_ietay(ix, iy, 0) * 2;
|
||||
photon.x += m_ietax(ix, iy, ie) *
|
||||
2; // eta goes between 0 and 1 but we could move the hit
|
||||
// anywhere in the 2x2
|
||||
photon.y += m_ietay(ix, iy, ie) * 2;
|
||||
photons.push_back(photon);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <aare/algorithm.hpp>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("Find the closed index in a 1D array", "[algorithm]") {
|
||||
aare::NDArray<double, 1> arr({5});
|
||||
@ -17,7 +16,7 @@ TEST_CASE("Find the closed index in a 1D array", "[algorithm]") {
|
||||
REQUIRE(aare::nearest_index(arr, -1.0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Passing integers to nearest_index works"){
|
||||
TEST_CASE("Passing integers to nearest_index works", "[algorithm]") {
|
||||
aare::NDArray<int, 1> arr({5});
|
||||
for (size_t i = 0; i < arr.size(); i++) {
|
||||
arr[i] = i;
|
||||
@ -30,8 +29,7 @@ TEST_CASE("Passing integers to nearest_index works"){
|
||||
REQUIRE(aare::nearest_index(arr, -1) == 0);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("nearest_index works with std::vector"){
|
||||
TEST_CASE("nearest_index works with std::vector", "[algorithm]") {
|
||||
std::vector<double> vec = {0, 1, 2, 3, 4};
|
||||
REQUIRE(aare::nearest_index(vec, 2.123) == 2);
|
||||
REQUIRE(aare::nearest_index(vec, 2.66) == 3);
|
||||
@ -40,7 +38,7 @@ TEST_CASE("nearest_index works with std::vector"){
|
||||
REQUIRE(aare::nearest_index(vec, -10.0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("nearest index works with std::array"){
|
||||
TEST_CASE("nearest index works with std::array", "[algorithm]") {
|
||||
std::array<double, 5> arr = {0, 1, 2, 3, 4};
|
||||
REQUIRE(aare::nearest_index(arr, 2.123) == 2);
|
||||
REQUIRE(aare::nearest_index(arr, 2.501) == 3);
|
||||
@ -49,8 +47,7 @@ TEST_CASE("nearest index works with std::array"){
|
||||
REQUIRE(aare::nearest_index(arr, -10.0) == 0);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("last smaller"){
|
||||
TEST_CASE("last smaller", "[algorithm]") {
|
||||
aare::NDArray<double, 1> arr({5});
|
||||
for (size_t i = 0; i < arr.size(); i++) {
|
||||
arr[i] = i;
|
||||
@ -60,4 +57,13 @@ TEST_CASE("last smaller"){
|
||||
REQUIRE(aare::last_smaller(arr, 0.0) == 0);
|
||||
REQUIRE(aare::last_smaller(arr, 2.3) == 2);
|
||||
REQUIRE(aare::last_smaller(arr, 253.) == 4);
|
||||
}
|
||||
|
||||
TEST_CASE("returns last bin strictly smaller", "[algorithm]") {
|
||||
aare::NDArray<double, 1> arr({5});
|
||||
for (size_t i = 0; i < arr.size(); i++) {
|
||||
arr[i] = i;
|
||||
}
|
||||
// arr 0, 1, 2, 3, 4
|
||||
REQUIRE(aare::last_smaller(arr, 2.0) == 2);
|
||||
}
|
Reference in New Issue
Block a user