Warning, file /eic-opticks/qudarap/tests/QScintGenerateTest.cc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #include <algorithm>
0002 #include <cmath>
0003 #include <cstdio>
0004 #include <cstdlib>
0005
0006 #include "NP.hh"
0007 #include "scuda.h"
0008 #include "sphoton.h"
0009 #include "squad.h"
0010 #include "srngcpu.h"
0011 #include "sscint.h"
0012 using RNG = srngcpu;
0013
0014 #include "stexture.h"
0015 MockTextureManager* MockTextureManager::INSTANCE = nullptr;
0016
0017 #include "qscint.h"
0018
0019 namespace
0020 {
0021 void require(bool condition, const char* expression, int line)
0022 {
0023 if (condition)
0024 return;
0025 std::fprintf(stderr, "%s:%d requirement failed: %s\n", __FILE__, line, expression);
0026 std::exit(EXIT_FAILURE);
0027 }
0028
0029 #define REQUIRE(expression) require((expression), #expression, __LINE__)
0030
0031 qscint makeScintillationSampler()
0032 {
0033 NP* spectrum = NP::Make<float>(3, 4, 4);
0034 std::fill_n(spectrum->values<float>(), spectrum->num_values(), 420.f);
0035
0036 qscint scintillation = {};
0037 scintillation.scint_tex = MockTextureManager::Add(spectrum);
0038 scintillation.hd_factor = 0;
0039 return scintillation;
0040 }
0041
0042 void test_stationary_genstep_has_finite_time(const qscint& scintillation, RNG& rng)
0043 {
0044 sscint genstep = {};
0045 genstep.pos = make_float3(1.f, 2.f, 3.f);
0046 genstep.time = 10.f;
0047 genstep.charge = -1.f;
0048 genstep.step_length = 0.f;
0049 genstep.meanVelocity = 0.f;
0050 genstep.ScintillationTime = 4.f;
0051
0052 sphoton photon = {};
0053 scintillation.generate(photon, rng, reinterpret_cast<const quad6&>(genstep), 0, 0);
0054
0055 REQUIRE(std::isfinite(photon.time));
0056 REQUIRE(photon.time > genstep.time);
0057 }
0058 }
0059
0060 int main()
0061 {
0062 qscint scintillation = makeScintillationSampler();
0063 RNG rng;
0064 rng.set_fake(0.5);
0065
0066 test_stationary_genstep_has_finite_time(scintillation, rng);
0067 std::puts("QScintGenerateTest: PASS");
0068 return 0;
0069 }