File indexing completed on 2024-04-06 12:04:40
0001 #include <cppunit/extensions/HelperMacros.h>
0002 #include "DataFormats/Luminosity/interface/LumiDetails.h"
0003
0004 #include <string>
0005 #include <vector>
0006 #include <iostream>
0007
0008 class TestLumiDetails: public CppUnit::TestFixture
0009 {
0010 CPPUNIT_TEST_SUITE(TestLumiDetails);
0011 CPPUNIT_TEST(testConstructor);
0012 CPPUNIT_TEST(testFill);
0013 CPPUNIT_TEST_SUITE_END();
0014
0015 public:
0016 void setUp() {}
0017 void tearDown() {}
0018
0019 void testConstructor();
0020 void testFill();
0021 };
0022
0023
0024 CPPUNIT_TEST_SUITE_REGISTRATION(TestLumiDetails);
0025
0026 void
0027 TestLumiDetails::testConstructor() {
0028 std::cout << "\nTesting LumiDetails\n";
0029 LumiDetails lumiDetails;
0030
0031 CPPUNIT_ASSERT(!lumiDetails.isValid());
0032 lumiDetails.setLumiVersion(std::string("v1"));
0033 CPPUNIT_ASSERT(lumiDetails.lumiVersion() == std::string("v1"));
0034
0035 LumiDetails lumiDetails1(std::string("v2"));
0036 CPPUNIT_ASSERT(lumiDetails1.lumiVersion() == std::string("v2"));
0037
0038 std::vector<std::string> const& v1 = lumiDetails.algoNames();
0039 std::vector<std::string> const& v2 = lumiDetails.algoNames();
0040 CPPUNIT_ASSERT(v2[0] == std::string("OCC1"));
0041 CPPUNIT_ASSERT(v2[1] == std::string("OCC2"));
0042 CPPUNIT_ASSERT(v2[2] == std::string("ET"));
0043 CPPUNIT_ASSERT(v2[3] == std::string("PLT"));
0044 CPPUNIT_ASSERT(v1.size() == 4U);
0045 CPPUNIT_ASSERT(v2.size() == 4U);
0046 }
0047
0048 void
0049 TestLumiDetails::testFill() {
0050 LumiDetails lumiDetails;
0051 std::vector<float> val;
0052 val.push_back(1.0f);
0053 val.push_back(2.0f);
0054 val.push_back(3.0f);
0055
0056 std::vector<float> err;
0057 err.push_back(4.0f);
0058 err.push_back(5.0f);
0059 err.push_back(6.0f);
0060
0061 std::vector<short> qual;
0062 qual.push_back(7);
0063 qual.push_back(8);
0064 qual.push_back(9);
0065
0066 std::vector<float> beam1;
0067 beam1.push_back(10.0f);
0068 beam1.push_back(11.0f);
0069 beam1.push_back(12.0f);
0070
0071 std::vector<float> beam2;
0072 beam2.push_back(13.0f);
0073 beam2.push_back(14.0f);
0074 beam2.push_back(15.0f);
0075
0076 lumiDetails.fill(2, val, err, qual);
0077 lumiDetails.fillBeamIntensities(beam1, beam2);
0078
0079
0080 std::vector<float> val0;
0081 val0.push_back(1.0f);
0082
0083 std::vector<float> err0;
0084 err0.push_back(4.0f);
0085
0086 std::vector<short> qual0;
0087 qual0.push_back(7);
0088
0089 lumiDetails.fill(0, val0, err0, qual0);
0090
0091 std::vector<float> val1;
0092 std::vector<float> err1;
0093 std::vector<short> qual1;
0094 lumiDetails.fill(1, val1, err1, qual1);
0095
0096 std::vector<float> val3;
0097 val3.push_back(11.0f);
0098 val3.push_back(11.0f);
0099
0100 std::vector<float> err3;
0101 err3.push_back(21.0f);
0102 err3.push_back(21.0f);
0103
0104 std::vector<short> qual3;
0105 qual3.push_back(31);
0106 qual3.push_back(31);
0107
0108 lumiDetails.fill(3, val3, err3, qual3);
0109
0110 LumiDetails::ValueRange rangeVal = lumiDetails.lumiValuesForAlgo(2);
0111 std::cout << "values\n";
0112 int i = 1;
0113 for (std::vector<float>::const_iterator val = rangeVal.first;
0114 val != rangeVal.second; ++val, ++i) {
0115 std::cout << *val << " ";
0116 CPPUNIT_ASSERT(*val == i);
0117 }
0118 std::cout << "\n";
0119 CPPUNIT_ASSERT(lumiDetails.lumiValue(2,0) == 1.0f);
0120 CPPUNIT_ASSERT(lumiDetails.lumiValue(2,1) == 2.0f);
0121 CPPUNIT_ASSERT(lumiDetails.lumiValue(2,2) == 3.0f);
0122
0123 LumiDetails::ErrorRange rangeErr = lumiDetails.lumiErrorsForAlgo(2);
0124 std::cout << "errors\n";
0125 i = 4;
0126 for (std::vector<float>::const_iterator err = rangeErr.first;
0127 err != rangeErr.second; ++err, ++i) {
0128 std::cout << *err << " ";
0129 CPPUNIT_ASSERT(*err == i);
0130 }
0131 std::cout << "\n";
0132 CPPUNIT_ASSERT(lumiDetails.lumiError(2,0) == 4.0f);
0133 CPPUNIT_ASSERT(lumiDetails.lumiError(2,1) == 5.0f);
0134 CPPUNIT_ASSERT(lumiDetails.lumiError(2,2) == 6.0f);
0135
0136 LumiDetails::QualityRange rangeQual = lumiDetails.lumiQualitiesForAlgo(2);
0137 std::cout << "qualities\n";
0138 i = 7;
0139 for (std::vector<short>::const_iterator qual = rangeQual.first;
0140 qual != rangeQual.second; ++qual, ++i) {
0141 std::cout << *qual << " ";
0142 CPPUNIT_ASSERT(*qual == i);
0143 }
0144 std::cout << "\n";
0145 CPPUNIT_ASSERT(lumiDetails.lumiQuality(2,0) == 7);
0146 CPPUNIT_ASSERT(lumiDetails.lumiQuality(2,1) == 8);
0147 CPPUNIT_ASSERT(lumiDetails.lumiQuality(2,2) == 9);
0148
0149 std::vector<float> const& beam1Intensities = lumiDetails.lumiBeam1Intensities();
0150 std::cout << "beam1Intensities\n";
0151 i = 10;
0152 for (std::vector<float>::const_iterator beam1 = beam1Intensities.begin(),
0153 beam1End = beam1Intensities.end();
0154 beam1 != beam1End; ++beam1, ++i) {
0155 std::cout << *beam1 << "\n";
0156 CPPUNIT_ASSERT(*beam1 == i);
0157 }
0158 std::cout << "\n";
0159 CPPUNIT_ASSERT(lumiDetails.lumiBeam1Intensity(0) == 10.0f);
0160 CPPUNIT_ASSERT(lumiDetails.lumiBeam1Intensity(1) == 11.0f);
0161 CPPUNIT_ASSERT(lumiDetails.lumiBeam1Intensity(2) == 12.0f);
0162
0163 std::vector<float> const& beam2Intensities = lumiDetails.lumiBeam2Intensities();
0164 std::cout << "beam2Intensities\n";
0165 i = 13;
0166 for (std::vector<float>::const_iterator beam2 = beam2Intensities.begin(),
0167 beam2End = beam2Intensities.end();
0168 beam2 != beam2End; ++beam2, ++i) {
0169 std::cout << *beam2 << "\n";
0170 CPPUNIT_ASSERT(*beam2 == i);
0171 }
0172 std::cout << "\n";
0173 CPPUNIT_ASSERT(lumiDetails.lumiBeam2Intensity(0) == 13.0f);
0174 CPPUNIT_ASSERT(lumiDetails.lumiBeam2Intensity(1) == 14.0f);
0175 CPPUNIT_ASSERT(lumiDetails.lumiBeam2Intensity(2) == 15.0f);
0176
0177 CPPUNIT_ASSERT(lumiDetails.isProductEqual(lumiDetails));
0178
0179 LumiDetails lumiDetails2;
0180 CPPUNIT_ASSERT(!lumiDetails.isProductEqual(lumiDetails2));
0181
0182 std::cout << lumiDetails;
0183 }