Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:43

0001 // -*- C++ -*-
0002 //
0003 // Package:     PhysicsTools/MVAComputer
0004 // Class  :     testMVAComputer.cppunit
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Christopher Jones
0010 //         Created:  Fri, 23 Jan 2015 18:54:27 GMT
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
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 ///registration of the test so that the runner can find it
0041 CPPUNIT_TEST_SUITE_REGISTRATION(testMVAComputer);
0042 
0043 using namespace PhysicsTools;
0044 
0045 void testMVAComputer::multTest() {
0046   {
0047     Calibration::MVAComputer calib;
0048     //this will be assigned to 'bit' 0
0049     calib.inputSet = {Calibration::Variable{AtomicId("x")}};
0050     //want to read out bit '1'
0051     calib.output = 1;
0052 
0053     //
0054     Calibration::ProcMultiply square;
0055     //we only want to read 1 input
0056     square.in = 1;
0057     //we will read bit '0' and multiply it by itself
0058     square.out = std::vector<Calibration::ProcMultiply::Config>{{0, 0}};
0059     //input to use comes from bit '0'
0060     square.inputVars.store = {0b1};
0061     //number of bits stored in the last char (?)
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     //this will be assigned to 'bit' 0 and 1
0086     calib.inputSet = {Calibration::Variable{AtomicId("x")}, Calibration::Variable{AtomicId("y")}};
0087     //want to read out bit '1'
0088     calib.output = 2;
0089 
0090     //
0091     Calibration::ProcMultiply square;
0092     //we only want to read 2 input
0093     square.in = 2;
0094     //we will read bit '0' and multiply it by bit '1'
0095     square.out = std::vector<Calibration::ProcMultiply::Config>{{0, 1}};
0096     //input comes from bits '0' and '1'
0097     square.inputVars.store = {0b11};
0098     //number of bits stored in the last char (?)
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     //this will be assigned to 'bit' 0
0117     calib.inputSet = {Calibration::Variable{AtomicId("x")}};
0118     //want to read out bit '1'
0119     calib.output = 1;
0120 
0121     //
0122     Calibration::ProcOptional optional;
0123     //default
0124     optional.neutralPos = {1.};
0125     //input to use comes from bit '0'
0126     optional.inputVars.store = {0b1};
0127     //number of bits stored in the last char (?)
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     //this will be assigned to 'bit' 0
0160     calib.inputSet = {Calibration::Variable{AtomicId("x")}};
0161     //want to read out bit '2'
0162     calib.output = 6;
0163 
0164     //
0165     Calibration::ProcForeach foreach;
0166     //we only want to read 1 input
0167     foreach
0168       .nProcs = 1;
0169 
0170     //input to use comes from bit '0'
0171     foreach
0172       .inputVars.store = {0b1};
0173     //number of bits stored in the last char (?)
0174     foreach
0175       .inputVars.bitsInLast = 1;
0176 
0177     calib.addProcessor(&foreach);
0178 
0179     //
0180     Calibration::ProcMultiply square;
0181     //we only want to read 1 input
0182     square.in = 1;
0183     //we will read bit '0' and multiply it by itself
0184     square.out = std::vector<Calibration::ProcMultiply::Config>{{0, 0}};
0185     //input comes from bits '2'
0186     square.inputVars.store = {0b100};
0187     //number of bits stored in the last char (?)
0188     square.inputVars.bitsInLast = 3;
0189 
0190     calib.addProcessor(&square);
0191 
0192     //Need to break apart the output int different elements
0193     Calibration::ProcSplitter splitter;
0194     splitter.nFirst = 2;
0195     //input comes from bits '3'
0196     splitter.inputVars.store = {0b1000};
0197     //number of bits stored in the last char (?)
0198     splitter.inputVars.bitsInLast = 4;
0199 
0200     calib.addProcessor(&splitter);
0201 
0202     //
0203     Calibration::ProcMultiply join;
0204     //we only want to read 2 inputs
0205     join.in = 2;
0206     //we will read bit '4' and '5'
0207     join.out = std::vector<Calibration::ProcMultiply::Config>{{0, 1}};
0208     //input comes from bits '4' and '5'
0209     join.inputVars.store = {0b110000};
0210     //number of bits stored in the last char (?)
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>