ATLAS Offline Software
Loading...
Searching...
No Matches
egamma1BDT_Test.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include "gtest/gtest.h"
9
10#include "../Egamma1BDT/parameters.h"
11
13
14#include <sstream>
15#include <fstream>
16#include <cmath>
17
18TEST (egamma1BDTTester, testvecs) {
19 std::string path =
20 "/eos/atlas/atlascerngroupdisk/data-art/large-input/trig-val/GlobalSimTest";
21
22 auto tv_fn = path + "/Egamma1BDT_testVecs.txt";
23
24 // lambda to read in test vectors
25
26 auto get_test_vectors =
27 [&tv_fn]()->std::optional<std::vector<std::vector<double>>> {
28 std::ifstream ifs(tv_fn);
29
30
31 if(!ifs) {
32 return std::optional<std::vector<std::vector<double>>>();
33 }
34
35 auto line = std::string();
36 std::string tok;
37
38 std::vector<std::vector<double>> inputs;
39
40 while (std::getline(ifs, line)) {
41 auto ss = std::stringstream(line);
42 std::vector<double> input;
43
44 while (std::getline(ss, tok, ',')) {
45 input.push_back(std::stod(tok));
46 }
47
48 constexpr int exp_size{18};
49 if (input.size() != exp_size) {
50 return std::optional<std::vector<std::vector<double>>>();
51 }
52
53 inputs.push_back(input);
54 }
55
56 return std::optional(inputs);
57
58 };
59
60 auto test_vectors_opt = get_test_vectors();
61
62 EXPECT_EQ(test_vectors_opt.has_value(), true);
63
64
65 auto test_vectors = *test_vectors_opt;
66
67 std::string fn_exp = path + "/Egamma1BDT_testExps_hls.txt";
68
69 // lambda to get test expectations
70 auto get_expectations =
71 [&fn_exp]() -> std::optional<std::vector<double>> {
72
73 std::ifstream ifs(fn_exp);
74 if(!ifs) {
75 return std::optional<std::vector<double>>();
76 }
77
78 auto line = std::string();
79 std::string tok;
80 std::vector<double> exps;
81
82 while (std::getline(ifs, line)) {
83 auto ss = std::stringstream(line);
84 while (std::getline(ss, tok)) {
85 exps.push_back(std::stod(tok));
86 }
87 }
88
89 return exps;
90
91 };
92
93
94 auto expectations_opt = get_expectations();
95
96 EXPECT_EQ(expectations_opt.has_value(), true);
97
98 auto expectations = *expectations_opt;
99
100 EXPECT_EQ(test_vectors.size(), expectations.size());
101
102 const auto tv_sz = test_vectors.size();
104 std::size_t i_vec{0};
105 for (std::size_t i_test = 0; i_test != tv_sz; ++i_test) {
106 const auto& tv = test_vectors[i_test];
107 const auto& exp = expectations[i_test];
108
109 auto tv_size = tv.size();
110 for(std::size_t j = 0; j != tv_size; ++j) {
111 x[j] = tv[j];
112 }
113
115
116 //main function for egamma BDT. object instantiated at start up
117 GlobalSim::bdt.decision_function(x, score);
118
119 EXPECT_EQ(score[0], exp);
120 ++i_vec;
121 }
122
123 EXPECT_EQ(i_vec, 32602u);
124}
static Double_t ss
#define x
Define macros for attributes used to control the static checker.
#define ATLAS_NO_CHECK_FILE_THREAD_SAFETY
TEST(egamma1BDTTester, testvecs)
score_t score_arr_t[n_classes]
Definition parameters.h:22
static const BDT::BDT< n_trees, n_classes, input_arr_t, score_t, threshold_t > bdt
Definition parameters.h:25
input_t input_arr_t[n_features]
Definition parameters.h:19