diff --git a/include/aare/defs.hpp b/include/aare/defs.hpp index 5fc4257..0236b45 100644 --- a/include/aare/defs.hpp +++ b/include/aare/defs.hpp @@ -188,6 +188,37 @@ struct ROI { } }; +/// @brief Chip specifications for Matterhorn1 +struct Matterhorn10 { + constexpr static size_t nRows = 256; + constexpr static size_t nCols = 256; +}; + +/// @brief Chip specifications for Matterhorn2 +struct Matterhorn02 { + constexpr static size_t nRows = 48; + constexpr static size_t nCols = 48; + constexpr static size_t nHalfCols = 24; +}; + +/// @brief Chip specifications for Moench04 +struct Moench04 { + constexpr static size_t nRows = 400; + constexpr static size_t nCols = 400; + constexpr static std::array + adcNumbers = + { + 9, 8, 11, 10, 13, 12, 15, 14, 1, 0, 3, + 2, 5, 4, 7, 6, 23, 22, 21, 20, 19, 18, + 17, 16, 31, 30, 29, 28, 27, 26, 25, 24}; // TODO : should we + // only have chip + // specifications or + // also wiring in + // chiptestboard? + constexpr static size_t nPixelsPerSuperColumn = 5000; + constexpr static size_t superColumnWidth = 25; +}; + enum ReadoutMode : uint8_t { ANALOG_ONLY = 0, DIGITAL_ONLY = 1, diff --git a/python/aare/transform.py b/python/aare/transform.py index b94840f..10d9e39 100644 --- a/python/aare/transform.py +++ b/python/aare/transform.py @@ -2,6 +2,7 @@ import numpy as np from . import _aare from aare import ReadoutMode +from aare._aare import Matterhorn10 class AdcSar04Transform64to16: def __call__(self, data): @@ -92,12 +93,8 @@ class Matterhorn10Transform: :type data: np.ndarray :raises ValueError: if not compatible """ + expected_size = (Matterhorn10.nRows*Matterhorn10.nCols*self.num_counters*self.dynamic_range)//8 # read_frame returns data in uint8_t - # TODO maybe better to have definition in matterhorn10 struct - rows = 256 - cols = 256 - expected_size = (rows*cols*self.num_counters*self.dynamic_range)//8 # read_frame returns data in uint8_t - if(data.size != expected_size): raise ValueError(f"Data size {data.size} does not match expected size {expected_size} for Matterhorn10 with dynamic range {self.dynamic_range} and num_counters {self.num_counters}.") diff --git a/python/src/bind_Defs.hpp b/python/src/bind_Defs.hpp new file mode 100644 index 0000000..e048f1c --- /dev/null +++ b/python/src/bind_Defs.hpp @@ -0,0 +1,25 @@ +#include +#include + +#include "aare/defs.hpp" + +namespace py = pybind11; +using namespace aare; + +void define_defs_bindings(py::module &m) { + auto matterhorn10 = py::class_(m, "Matterhorn10"); + matterhorn10.attr("nRows") = Matterhorn10::nRows; + matterhorn10.attr("nCols") = Matterhorn10::nCols; + + auto matterhorn02 = py::class_(m, "Matterhorn02"); + matterhorn02.attr("nRows") = Matterhorn02::nRows; + matterhorn02.attr("nCols") = Matterhorn02::nCols; + matterhorn02.attr("nHalfCols") = Matterhorn02::nHalfCols; + + auto moench04 = py::class_(m, "Moench04"); + moench04.attr("nRows") = Moench04::nRows; + moench04.attr("nCols") = Moench04::nCols; + moench04.attr("nPixelsPerSuperColumn") = Moench04::nPixelsPerSuperColumn; + moench04.attr("superColumnWidth") = Moench04::superColumnWidth; + moench04.attr("adcNumbers") = Moench04::adcNumbers; +} diff --git a/python/src/module.cpp b/python/src/module.cpp index 4986f1f..6defb40 100644 --- a/python/src/module.cpp +++ b/python/src/module.cpp @@ -9,12 +9,13 @@ #include "bind_ClusterFinder.hpp" #include "bind_ClusterFinderMT.hpp" #include "bind_ClusterVector.hpp" +#include "bind_Defs.hpp" #include "bind_Eta.hpp" #include "bind_Interpolator.hpp" +#include "bind_PixelMap.hpp" #include "bind_calibration.hpp" // TODO! migrate the other names -#include "bind_PixelMap.hpp" #include "ctb_raw_file.hpp" #include "file.hpp" #include "fit.hpp" @@ -140,6 +141,8 @@ PYBIND11_MODULE(_aare, m) { register_calculate_3x3eta(m); register_calculate_3x3eta(m); + define_defs_bindings(m); + using Sum_index_pair_d = Sum_index_pair; PYBIND11_NUMPY_DTYPE(Sum_index_pair_d, sum, index); using Sum_index_pair_f = Sum_index_pair; diff --git a/src/PixelMap.cpp b/src/PixelMap.cpp index 5a1e6e1..efae362 100644 --- a/src/PixelMap.cpp +++ b/src/PixelMap.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 #include "aare/PixelMap.hpp" +#include "aare/defs.hpp" #include @@ -32,23 +33,20 @@ NDArray GenerateMoench03PixelMap() { } NDArray GenerateMoench04AnalogPixelMap() { - std::array const adc_nr = { - 9, 8, 11, 10, 13, 12, 15, 14, 1, 0, 3, 2, 5, 4, 7, 6, - 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24}; - int const sc_width = 25; - int const nadc = 32; - int const pixels_per_sc = 5000; - NDArray order_map({400, 400}); + std::array const adc_nr = Moench04::adcNumbers; + int const nadc = adc_nr.size(); + NDArray order_map({Moench04::nRows, Moench04::nCols}); int pixel = 0; - for (int i = 0; i != pixels_per_sc; ++i) { - for (int i_adc = 0; i_adc != nadc; ++i_adc) { - int const col = (adc_nr[i_adc] % 16) * 25 + (i % sc_width); + for (size_t i = 0; i != Moench04::nPixelsPerSuperColumn; ++i) { + for (size_t i_adc = 0; i_adc != nadc; ++i_adc) { + int const col = + (adc_nr[i_adc] % 16) * 25 + (i % Moench04::superColumnWidth); int row = 0; if (i_adc < 16) - row = 199 - (i / sc_width); + row = 199 - (i / Moench04::superColumnWidth); else - row = 200 + (i / sc_width); + row = 200 + (i / Moench04::superColumnWidth); order_map(row, col) = pixel; pixel++; @@ -134,13 +132,14 @@ NDArray GenerateEigerFlipRowsPixelMap() { NDArray GenerateMH02SingleCounterPixelMap() { // This is the pixel map for a single counter Matterhorn02, i.e. 48x48 // pixels. Data is read from two transceivers in blocks of 4 pixels. - NDArray order_map({48, 48}); + NDArray order_map({Matterhorn02::nRows, Matterhorn02::nCols}); size_t offset = 0; size_t nSamples = 4; - for (int row = 0; row < 48; row++) { - for (int col = 0; col < 24; col++) { - for (int iTrans = 0; iTrans < 2; iTrans++) { - order_map(row, iTrans * 24 + col) = offset + nSamples * iTrans; + for (size_t row = 0; row < Matterhorn02::nRows; row++) { + for (size_t col = 0; col < Matterhorn02::nHalfCols; col++) { + for (size_t iTrans = 0; iTrans < 2; iTrans++) { + order_map(row, iTrans * Matterhorn02::nHalfCols + col) = + offset + nSamples * iTrans; } offset += 1; if ((col + 1) % nSamples == 0) { @@ -153,12 +152,14 @@ NDArray GenerateMH02SingleCounterPixelMap() { NDArray GenerateMH02FourCounterPixelMap() { auto single_counter_map = GenerateMH02SingleCounterPixelMap(); - NDArray order_map({4, 48, 48}); - for (int counter = 0; counter < 4; counter++) { - for (int row = 0; row < 48; row++) { - for (int col = 0; col < 48; col++) { + NDArray order_map( + {4, Matterhorn02::nRows, Matterhorn02::nCols}); + for (size_t counter = 0; counter < 4; counter++) { + for (size_t row = 0; row < Matterhorn02::nRows; row++) { + for (size_t col = 0; col < Matterhorn02::nCols; col++) { order_map(counter, row, col) = - single_counter_map(row, col) + counter * 48 * 48; + single_counter_map(row, col) + + counter * Matterhorn02::nRows * Matterhorn02::nCols; } } } @@ -167,8 +168,8 @@ NDArray GenerateMH02FourCounterPixelMap() { NDArray GenerateMatterhorn10PixelMap(const size_t dynamic_range, const size_t n_counters) { - constexpr size_t n_cols = 256; - constexpr size_t n_rows = 256; + constexpr size_t n_cols = Matterhorn10::nCols; + constexpr size_t n_rows = Matterhorn10::nRows; NDArray pixel_map( {static_cast(n_rows * n_counters), n_cols});