21#include "gtest/gtest.h"
31 std::filesystem::path referenceSpectrumPath() {
32 return std::filesystem::path(OPALX_TEST_SOURCE_DIR) /
"data"
33 /
"cain_linear_compton_90deg_xi029_histogram.csv";
38 std::filesystem::path referenceJointSpectrumPath() {
39 return std::filesystem::path(OPALX_TEST_SOURCE_DIR) /
"data"
40 /
"cain_linear_compton_90deg_xi029_joint_histogram.csv";
44 std::filesystem::path referenceAngularSpectrumPath() {
45 return std::filesystem::path(OPALX_TEST_SOURCE_DIR) /
"data"
46 /
"cain_linear_compton_90deg_xi029_theta_histogram.csv";
50 std::filesystem::path referenceFiniteBeamSpectrumPath() {
51 return std::filesystem::path(OPALX_TEST_SOURCE_DIR) /
"data"
52 /
"cain_linear_compton_90deg_xi029_finite_beam_histogram.csv";
56 std::filesystem::path referenceFiniteBeamAngularSpectrumPath() {
57 return std::filesystem::path(OPALX_TEST_SOURCE_DIR) /
"data"
58 /
"cain_linear_compton_90deg_xi029_finite_beam_theta_histogram.csv";
62 std::filesystem::path referenceFiniteBeamJointSpectrumPath() {
63 return std::filesystem::path(OPALX_TEST_SOURCE_DIR) /
"data"
64 /
"cain_linear_compton_90deg_xi029_finite_beam_joint_histogram.csv";
69 std::filesystem::path referenceFiniteBeamEnergySpreadSpectrumPath() {
70 return std::filesystem::path(OPALX_TEST_SOURCE_DIR) /
"data"
71 /
"cain_linear_compton_90deg_xi029_finite_beam_energy_spread_histogram.csv";
75 std::filesystem::path referenceFiniteBeamEnergySpreadAngularSpectrumPath() {
76 return std::filesystem::path(OPALX_TEST_SOURCE_DIR) /
"data"
77 /
"cain_linear_compton_90deg_xi029_finite_beam_energy_spread_theta_histogram.csv";
82 std::filesystem::path referenceFiniteBeamEnergySpreadJointSpectrumPath() {
83 return std::filesystem::path(OPALX_TEST_SOURCE_DIR) /
"data"
84 /
"cain_linear_compton_90deg_xi029_finite_beam_energy_spread_joint_histogram.csv";
89 std::filesystem::path referenceFiniteBeamOverlapSpectrumPath() {
90 return std::filesystem::path(OPALX_TEST_SOURCE_DIR) /
"data"
91 /
"cain_linear_compton_90deg_xi029_finite_beam_overlap_histogram.csv";
95 std::filesystem::path referenceFiniteBeamOverlapAngularSpectrumPath() {
96 return std::filesystem::path(OPALX_TEST_SOURCE_DIR) /
"data"
97 /
"cain_linear_compton_90deg_xi029_finite_beam_overlap_theta_histogram.csv";
102 std::filesystem::path benchmarkExecutablePath() {
103 return std::filesystem::path(OPALX_LINEAR_COMPTON_BENCHMARK);
116 std::filesystem::path runFiniteBeamBenchmark(
117 const std::string& filename,
bool angular,
bool joint =
false,
118 const std::string& extraOptions =
"") {
119 const auto output = std::filesystem::temp_directory_path() / filename;
120 std::ostringstream command;
121 command << benchmarkExecutablePath().string() <<
' ' << output.string()
122 <<
" --finite-beam --beam-particles 100000 --seed 13579";
123 if (!extraOptions.empty()) {
124 command <<
' ' << extraOptions;
127 command <<
" --joint";
128 }
else if (angular) {
129 command <<
" --angular";
132 const int returnCode = std::system(command.str().c_str());
133 if (returnCode != 0) {
134 throw std::runtime_error(
135 "Failed to run finite-beam benchmark command: " + command.str());
141TEST(TestLinearComptonSpectrum, WeakFieldSpectrumMatchesCainReference) {
146 ASSERT_EQ(opalxSpectrum.centersGeV.size(), cainSpectrum.centersGeV.size());
152 EXPECT_NEAR(opalxMean, cainMean, cainMean * 3.0e-2);
154 const double l1Distance =
156 EXPECT_LT(l1Distance, 0.1);
159TEST(TestLinearComptonSpectrum, WeakFieldSampledSpectrumMatchesCainReference) {
167 ASSERT_EQ(opalxSpectrum.centersGeV.size(), cainSpectrum.centersGeV.size());
172 EXPECT_NEAR(opalxMean, cainMean, cainMean * 3.5e-2);
174 const double l1Distance =
176 EXPECT_LT(l1Distance, 0.14);
181TEST(TestLinearComptonSpectrum, WeakFieldAngularSpectrumMatchesCainReference) {
186 ASSERT_EQ(opalxSpectrum.centersRad.size(), cainSpectrum.centersRad.size());
192 EXPECT_NEAR(opalxMean, cainMean, cainMean * 5.0e-2);
194 const double l1Distance =
196 EXPECT_LT(l1Distance, 0.12);
199TEST(TestLinearComptonSpectrum, WeakFieldSampledAngularSpectrumMatchesCainReference) {
207 ASSERT_EQ(opalxSpectrum.centersRad.size(), cainSpectrum.centersRad.size());
212 EXPECT_NEAR(opalxMean, cainMean, cainMean * 5.0e-2);
214 const double l1Distance =
216 EXPECT_LT(l1Distance, 0.10);
221TEST(TestLinearComptonSpectrum, WeakFieldJointSpectrumMatchesCainReference) {
226 ASSERT_EQ(opalxSpectrum.energyCentersGeV.size(), cainSpectrum.energyCentersGeV.size());
227 ASSERT_EQ(opalxSpectrum.thetaCentersRad.size(), cainSpectrum.thetaCentersRad.size());
231 const double opalxMeanEnergy =
234 EXPECT_NEAR(opalxMeanEnergy, cainMeanEnergy, cainMeanEnergy * 3.0e-2);
238 EXPECT_NEAR(opalxMeanTheta, cainMeanTheta, cainMeanTheta * 5.0e-2);
240 const double l1Distance =
242 EXPECT_LT(l1Distance, 0.16);
245TEST(TestLinearComptonSpectrum, WeakFieldSampledJointSpectrumMatchesCainReference) {
253 ASSERT_EQ(opalxSpectrum.energyCentersGeV.size(), cainSpectrum.energyCentersGeV.size());
254 ASSERT_EQ(opalxSpectrum.thetaCentersRad.size(), cainSpectrum.thetaCentersRad.size());
257 const double opalxMeanEnergy =
260 EXPECT_NEAR(opalxMeanEnergy, cainMeanEnergy, cainMeanEnergy * 3.5e-2);
264 EXPECT_NEAR(opalxMeanTheta, cainMeanTheta, cainMeanTheta * 6.0e-2);
266 const double l1Distance =
268 EXPECT_LT(l1Distance, 0.09);
278TEST(TestLinearComptonSpectrum, FiniteBeamSpectrumMatchesCainReference) {
279 const auto output = runFiniteBeamBenchmark(
280 "opalx-linear-compton-90deg-xi029-finite-beam-histogram.csv",
false);
282 const auto cainSpectrum =
285 ASSERT_EQ(opalxSpectrum.centersGeV.size(), cainSpectrum.centersGeV.size());
291 EXPECT_NEAR(opalxMean, cainMean, cainMean * 2.0e-2);
293 const double l1Distance =
295 EXPECT_LT(l1Distance, 0.05);
298TEST(TestLinearComptonSpectrum, FiniteBeamAngularSpectrumMatchesCainReference) {
299 const auto output = runFiniteBeamBenchmark(
300 "opalx-linear-compton-90deg-xi029-finite-beam-theta-histogram.csv",
true);
302 const auto cainSpectrum =
305 ASSERT_EQ(opalxSpectrum.centersRad.size(), cainSpectrum.centersRad.size());
311 EXPECT_NEAR(opalxMean, cainMean, cainMean * 2.0e-2);
313 const double l1Distance =
315 EXPECT_LT(l1Distance, 0.03);
318TEST(TestLinearComptonSpectrum, FiniteBeamJointSpectrumMatchesCainReference) {
319 const auto output = runFiniteBeamBenchmark(
320 "opalx-linear-compton-90deg-xi029-finite-beam-joint-histogram.csv",
false,
true);
322 const auto cainSpectrum =
325 ASSERT_EQ(opalxSpectrum.energyCentersGeV.size(), cainSpectrum.energyCentersGeV.size());
326 ASSERT_EQ(opalxSpectrum.thetaCentersRad.size(), cainSpectrum.thetaCentersRad.size());
347TEST(TestLinearComptonSpectrum, FiniteBeamEnergySpreadSpectrumMatchesCainReference) {
348 const auto output = runFiniteBeamBenchmark(
349 "opalx-linear-compton-90deg-xi029-finite-beam-energy-spread-histogram.csv",
false,
350 false,
"--beam-relative-energy-spread 0.001");
352 const auto cainSpectrum =
355 ASSERT_EQ(opalxSpectrum.centersGeV.size(), cainSpectrum.centersGeV.size());
361 EXPECT_NEAR(opalxMean, cainMean, cainMean * 2.0e-2);
363 const double l1Distance =
365 EXPECT_LT(l1Distance, 0.05);
368TEST(TestLinearComptonSpectrum, FiniteBeamEnergySpreadAngularSpectrumMatchesCainReference) {
369 const auto output = runFiniteBeamBenchmark(
370 "opalx-linear-compton-90deg-xi029-finite-beam-energy-spread-theta-histogram.csv",
true,
371 false,
"--beam-relative-energy-spread 0.001");
374 referenceFiniteBeamEnergySpreadAngularSpectrumPath());
376 ASSERT_EQ(opalxSpectrum.centersRad.size(), cainSpectrum.centersRad.size());
382 EXPECT_NEAR(opalxMean, cainMean, cainMean * 2.0e-2);
384 const double l1Distance =
386 EXPECT_LT(l1Distance, 0.03);
389TEST(TestLinearComptonSpectrum, FiniteBeamEnergySpreadJointSpectrumMatchesCainReference) {
390 const auto output = runFiniteBeamBenchmark(
391 "opalx-linear-compton-90deg-xi029-finite-beam-energy-spread-joint-histogram.csv",
false,
392 true,
"--beam-relative-energy-spread 0.001");
395 referenceFiniteBeamEnergySpreadJointSpectrumPath());
397 ASSERT_EQ(opalxSpectrum.energyCentersGeV.size(), cainSpectrum.energyCentersGeV.size());
398 ASSERT_EQ(opalxSpectrum.thetaCentersRad.size(), cainSpectrum.thetaCentersRad.size());
413TEST(TestLinearComptonSpectrum, FiniteBeamOverlapSpectrumMatchesCainReference) {
414 const auto output = runFiniteBeamBenchmark(
415 "opalx-linear-compton-90deg-xi029-finite-beam-overlap-histogram.csv",
false,
false,
416 "--overlap-weighting --beam-sigma-longitudinal 0.000299792 --laser-rayleigh 12.5 "
417 "--laser-sigma-t 0.000299792");
419 const auto cainSpectrum =
422 ASSERT_EQ(opalxSpectrum.centersGeV.size(), cainSpectrum.centersGeV.size());
431TEST(TestLinearComptonSpectrum, FiniteBeamOverlapAngularSpectrumMatchesCainReference) {
432 const auto output = runFiniteBeamBenchmark(
433 "opalx-linear-compton-90deg-xi029-finite-beam-overlap-theta-histogram.csv",
true,
false,
434 "--overlap-weighting --beam-sigma-longitudinal 0.000299792 --laser-rayleigh 12.5 "
435 "--laser-sigma-t 0.000299792");
437 const auto cainSpectrum =
440 ASSERT_EQ(opalxSpectrum.centersRad.size(), cainSpectrum.centersRad.size());
TEST(TestLinearComptonSpectrum, WeakFieldSpectrumMatchesCainReference)
double histogramArea(const SpectrumHistogram &histogram)
SpectrumHistogram readSpectrumCSV(const std::filesystem::path &inputPath)
double angleHistogramL1Distance(const AngleHistogram &lhs, const AngleHistogram &rhs)
JointHistogram integrateLabJointSpectrum(const JointConfig &config)
AngleHistogram readAngleCSV(const std::filesystem::path &inputPath)
double angleHistogramMeanRad(const AngleHistogram &histogram)
double jointHistogramL1Distance(const JointHistogram &lhs, const JointHistogram &rhs)
double histogramL1Distance(const SpectrumHistogram &lhs, const SpectrumHistogram &rhs)
double jointHistogramArea(const JointHistogram &histogram)
double angleHistogramArea(const AngleHistogram &histogram)
SpectrumHistogram integrateLabSpectrum(const SpectrumConfig &config)
double jointHistogramMeanThetaRad(const JointHistogram &histogram)
double histogramMeanEnergyGeV(const SpectrumHistogram &histogram)
JointHistogram sampleLabJointSpectrum(const JointConfig &config, std::size_t sampleCount, std::uint64_t streamIndex=0)
SpectrumHistogram sampleLabSpectrum(const SpectrumConfig &config, std::size_t sampleCount, std::uint64_t streamIndex=0)
AngleHistogram integrateLabAngularSpectrum(const AngleConfig &config)
JointHistogram readJointCSV(const std::filesystem::path &inputPath)
AngleHistogram sampleLabAngularSpectrum(const AngleConfig &config, std::size_t sampleCount, std::uint64_t streamIndex=0)
double jointHistogramMeanEnergyGeV(const JointHistogram &histogram)
int seed
The current random seed.