diff --git a/include/SiPMAnalogSignal.h b/include/SiPMAnalogSignal.h index 5d1b7c3..eb5c7e9 100644 --- a/include/SiPMAnalogSignal.h +++ b/include/SiPMAnalogSignal.h @@ -24,6 +24,7 @@ #include #include #include +#include #include namespace sipm { diff --git a/include/SiPMDebugInfo.h b/include/SiPMDebugInfo.h index 6ce38c5..6506af0 100644 --- a/include/SiPMDebugInfo.h +++ b/include/SiPMDebugInfo.h @@ -15,6 +15,7 @@ #include #include #include +#include namespace sipm { struct SiPMDebugInfo { diff --git a/include/SiPMHit.h b/include/SiPMHit.h index ba9c743..020e07a 100644 --- a/include/SiPMHit.h +++ b/include/SiPMHit.h @@ -16,6 +16,7 @@ #include #include #include +#include namespace sipm { class SiPMHit { diff --git a/include/SiPMProperties.h b/include/SiPMProperties.h index fb74af6..fba2a8c 100644 --- a/include/SiPMProperties.h +++ b/include/SiPMProperties.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/src/SiPMRandom.cpp b/src/SiPMRandom.cpp index 1c81c7e..d680bf7 100644 --- a/src/SiPMRandom.cpp +++ b/src/SiPMRandom.cpp @@ -2,7 +2,6 @@ #include "SiPMTypes.h" #include - // Random seed #include static uint64_t rdtsc() { @@ -301,30 +300,30 @@ uint32_t SiPMRandom::randInteger(const uint32_t max) noexcept { } /** -* @param n Number of values to generate -*/ - std::vector SiPMRandom::Rand(const uint32_t n) { - std::vector f64(n); - uint64_t* u64; // Free at end of function - - if (n > 8) { - // simd8 allocates data - u64 = m_rng.simd8(n); - } else { - // We do allocation - u64 = (uint64_t*)aligned_alloc(64, n * sizeof(uint64_t)); - for (uint32_t i = 0; i < n; ++i) { - u64[i] = m_rng(); - } - } + * @param n Number of values to generate + */ +std::vector SiPMRandom::Rand(const uint32_t n) { + std::vector f64(n); + uint64_t* u64; // Free at end of function + if (n > 8) { + // simd8 allocates data + u64 = m_rng.simd8(n); + } else { + // We do allocation + u64 = (uint64_t*)aligned_alloc(64, n * sizeof(uint64_t)); for (uint32_t i = 0; i < n; ++i) { - f64[i] = static_cast(u64[i]) * 0x1p-64; + u64[i] = m_rng(); } + } - free(u64); + for (uint32_t i = 0; i < n; ++i) { + f64[i] = static_cast(u64[i]) * 0x1p-64; + } - return f64; + free(u64); + + return f64; } /** @@ -338,7 +337,7 @@ std::vector SiPMRandom::RandF(const uint32_t n) { // simd8 allocates data // need n/2 uint64_t to generate n uint32_t // odd case requires one more generation for tail - u32 = (uint32_t*)m_rng.simd8((n+1) / 2); + u32 = (uint32_t*)m_rng.simd8((n + 1) / 2); } else { // We do allocation u32 = (uint32_t*)aligned_alloc(64, n * sizeof(uint32_t)); @@ -353,7 +352,7 @@ std::vector SiPMRandom::RandF(const uint32_t n) { // See SiPMRandom.h for details f32[i] = static_cast(u32[i]) * 0x1p-32; } - f32[n-1] = Rand(); + f32[n - 1] = Rand(); free(u32); @@ -393,7 +392,7 @@ std::vector SiPMRandom::randGaussian(const double mu, const double sigma std::vector SiPMRandom::randGaussianF(const float mu, const float sigma, const uint32_t n) { std::vector out(n); const std::vector u = RandF(n); - constexpr float TWO_PI = 2 * M_PIf; + constexpr float TWO_PI = 2 * M_PI; for (uint32_t i = 0; i < n - 1; i += 2) { const float R = sqrtf(-2.0 * logf(u[i])); @@ -417,18 +416,18 @@ std::vector SiPMRandom::randInteger(const uint32_t max, const uint32_t std::vector out(n); uint32_t* u32; - if(n < 16){ + if (n < 16) { u32 = (uint32_t*)aligned_alloc(64, n * sizeof(uint32_t)); - for(uint32_t i = 0; i < n; ++i){ + for (uint32_t i = 0; i < n; ++i) { u32[i] = m_rng() >> 32; } } else { - u32 = (uint32_t*)m_rng.simd8((n+1)/2); + u32 = (uint32_t*)m_rng.simd8((n + 1) / 2); } // Sort of fixed point arithmetic // Avoids division and float numbers - for (uint32_t i = 0; i < n ; ++i) { + for (uint32_t i = 0; i < n; ++i) { const uint64_t m = uint64_t(u32[i]) * uint64_t(max); out[i] = m >> 32; }