File indexing completed on 2024-04-06 12:23:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <cppunit/extensions/HelperMacros.h>
0017
0018 #include "CondFormats/PhysicsToolsObjects/interface/MVAComputer.h"
0019
0020 #include "PhysicsTools/MVAComputer/interface/MVAComputer.h"
0021
0022 class testMVAComputer : public CppUnit::TestFixture {
0023 CPPUNIT_TEST_SUITE(testMVAComputer);
0024
0025 CPPUNIT_TEST(multTest);
0026 CPPUNIT_TEST(optionalTest);
0027 CPPUNIT_TEST(foreachTest);
0028
0029 CPPUNIT_TEST_SUITE_END();
0030
0031 public:
0032 void setUp() {}
0033 void tearDown() {}
0034
0035 void multTest();
0036 void optionalTest();
0037 void foreachTest();
0038 };
0039
0040
0041 CPPUNIT_TEST_SUITE_REGISTRATION(testMVAComputer);
0042
0043 using namespace PhysicsTools;
0044
0045 void testMVAComputer::multTest() {
0046 {
0047 Calibration::MVAComputer calib;
0048
0049 calib.inputSet = {Calibration::Variable{AtomicId("x")}};
0050
0051 calib.output = 1;
0052
0053
0054 Calibration::ProcMultiply square;
0055
0056 square.in = 1;
0057
0058 square.out = std::vector<Calibration::ProcMultiply::Config>{{0, 0}};
0059
0060 square.inputVars.store = {0b1};
0061
0062 square.inputVars.bitsInLast = 1;
0063
0064 calib.addProcessor(&square);
0065
0066 MVAComputer mva(&calib, false);
0067
0068 {
0069 std::vector<Variable::Value> input;
0070 input.emplace_back("x", 2);
0071
0072 CPPUNIT_ASSERT(4 == mva.eval(input));
0073 }
0074
0075 {
0076 std::vector<Variable::Value> input;
0077 input.emplace_back("x", 3);
0078
0079 CPPUNIT_ASSERT(9 == mva.eval(input));
0080 }
0081 }
0082
0083 {
0084 Calibration::MVAComputer calib;
0085
0086 calib.inputSet = {Calibration::Variable{AtomicId("x")}, Calibration::Variable{AtomicId("y")}};
0087
0088 calib.output = 2;
0089
0090
0091 Calibration::ProcMultiply square;
0092
0093 square.in = 2;
0094
0095 square.out = std::vector<Calibration::ProcMultiply::Config>{{0, 1}};
0096
0097 square.inputVars.store = {0b11};
0098
0099 square.inputVars.bitsInLast = 2;
0100
0101 calib.addProcessor(&square);
0102
0103 MVAComputer mva(&calib, false);
0104
0105 std::vector<Variable::Value> input;
0106 input.emplace_back("x", 2);
0107 input.emplace_back("y", 3);
0108
0109 CPPUNIT_ASSERT(6 == mva.eval(input));
0110 }
0111 }
0112
0113 void testMVAComputer::optionalTest() {
0114 {
0115 Calibration::MVAComputer calib;
0116
0117 calib.inputSet = {Calibration::Variable{AtomicId("x")}};
0118
0119 calib.output = 1;
0120
0121
0122 Calibration::ProcOptional optional;
0123
0124 optional.neutralPos = {1.};
0125
0126 optional.inputVars.store = {0b1};
0127
0128 optional.inputVars.bitsInLast = 1;
0129
0130 calib.addProcessor(&optional);
0131
0132 MVAComputer mva(&calib, false);
0133
0134 {
0135 std::vector<Variable::Value> input;
0136 input.emplace_back("x", 2);
0137
0138 CPPUNIT_ASSERT(2 == mva.eval(input));
0139 }
0140
0141 {
0142 std::vector<Variable::Value> input;
0143
0144 CPPUNIT_ASSERT(1 == mva.eval(input));
0145 }
0146
0147 {
0148 std::vector<Variable::Value> input;
0149 input.emplace_back("y", 2);
0150
0151 CPPUNIT_ASSERT(1 == mva.eval(input));
0152 }
0153 }
0154 }
0155
0156 void testMVAComputer::foreachTest() {
0157 {
0158 Calibration::MVAComputer calib;
0159
0160 calib.inputSet = {Calibration::Variable{AtomicId("x")}};
0161
0162 calib.output = 6;
0163
0164
0165 Calibration::ProcForeach foreach;
0166
0167 foreach
0168 .nProcs = 1;
0169
0170
0171 foreach
0172 .inputVars.store = {0b1};
0173
0174 foreach
0175 .inputVars.bitsInLast = 1;
0176
0177 calib.addProcessor(&foreach);
0178
0179
0180 Calibration::ProcMultiply square;
0181
0182 square.in = 1;
0183
0184 square.out = std::vector<Calibration::ProcMultiply::Config>{{0, 0}};
0185
0186 square.inputVars.store = {0b100};
0187
0188 square.inputVars.bitsInLast = 3;
0189
0190 calib.addProcessor(&square);
0191
0192
0193 Calibration::ProcSplitter splitter;
0194 splitter.nFirst = 2;
0195
0196 splitter.inputVars.store = {0b1000};
0197
0198 splitter.inputVars.bitsInLast = 4;
0199
0200 calib.addProcessor(&splitter);
0201
0202
0203 Calibration::ProcMultiply join;
0204
0205 join.in = 2;
0206
0207 join.out = std::vector<Calibration::ProcMultiply::Config>{{0, 1}};
0208
0209 join.inputVars.store = {0b110000};
0210
0211 join.inputVars.bitsInLast = 7;
0212 calib.addProcessor(&join);
0213
0214 MVAComputer mva(&calib, false);
0215
0216 {
0217 std::vector<Variable::Value> input;
0218 input.emplace_back("x", 2);
0219 input.emplace_back("x", 2);
0220
0221 CPPUNIT_ASSERT(4 * 4 == mva.eval(input));
0222 }
0223
0224 {
0225 std::vector<Variable::Value> input;
0226 input.emplace_back("x", 3);
0227 input.emplace_back("x", 3);
0228
0229 CPPUNIT_ASSERT(9 * 9 == mva.eval(input));
0230 }
0231 }
0232 }
0233
0234 #include <Utilities/Testing/interface/CppUnit_testdriver.icpp>