Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:01

0001 #include <cppunit/extensions/HelperMacros.h>
0002 #include "DataFormats/Luminosity/interface/LumiInfo.h"
0003 
0004 #include <string>
0005 #include <vector>
0006 #include <iostream>
0007 #include <cmath>
0008 
0009 class TestLumiInfo : public CppUnit::TestFixture {
0010   static const float tol;
0011 
0012   CPPUNIT_TEST_SUITE(TestLumiInfo);
0013   CPPUNIT_TEST(testConstructor);
0014   CPPUNIT_TEST(testFill);
0015   CPPUNIT_TEST_SUITE_END();
0016 
0017 public:
0018   void setUp() {}
0019   void tearDown() {}
0020 
0021   void testConstructor();
0022   void testFill();
0023 };
0024 
0025 const float TestLumiInfo::tol = 1e-5;
0026 
0027 ///registration of the test so that the runner can find it
0028 CPPUNIT_TEST_SUITE_REGISTRATION(TestLumiInfo);
0029 
0030 void TestLumiInfo::testConstructor() {
0031   std::cout << "\nTesting LumiInfo\n";
0032   LumiInfo lumiInfo;
0033 
0034   lumiInfo.setDeadFraction(0.4);
0035   CPPUNIT_ASSERT(std::abs(lumiInfo.getDeadFraction() - 0.4) < tol);
0036   CPPUNIT_ASSERT(std::abs(lumiInfo.getLiveFraction() - 0.6) < tol);
0037 }
0038 
0039 void TestLumiInfo::testFill() {
0040   LumiInfo lumiInfo;
0041   lumiInfo.setDeadFraction(0.5);
0042   std::vector<float> lumBX;
0043   lumBX.push_back(1.0f);
0044   lumBX.push_back(2.0f);
0045   lumBX.push_back(3.0f);
0046 
0047   lumiInfo.setInstLumiAllBX(lumBX);
0048   lumiInfo.setTotalInstLumi(8.0f);
0049 
0050   CPPUNIT_ASSERT(std::abs(lumiInfo.getInstLumiBX(0) - 1.0f) < tol);
0051   CPPUNIT_ASSERT(std::abs(lumiInfo.getInstLumiBX(1) - 2.0f) < tol);
0052   CPPUNIT_ASSERT(std::abs(lumiInfo.getInstLumiBX(2) - 3.0f) < tol);
0053 
0054   CPPUNIT_ASSERT(std::abs(lumiInfo.getTotalInstLumi() - 8.0f) < tol);
0055   CPPUNIT_ASSERT(std::abs(lumiInfo.instLuminosityBXSum() - 6.0f) < tol);
0056   CPPUNIT_ASSERT(std::abs(lumiInfo.integLuminosity() - 8.0f * lumiInfo.lumiSectionLength()) < tol);
0057   CPPUNIT_ASSERT(std::abs(lumiInfo.recordedLuminosity() - 4.0f * lumiInfo.lumiSectionLength()) < tol);
0058 
0059   lumiInfo.setTotalInstToBXSum();
0060   CPPUNIT_ASSERT(std::abs(lumiInfo.getTotalInstLumi() - 6.0f) < tol);
0061 
0062   CPPUNIT_ASSERT(lumiInfo.isProductEqual(lumiInfo));
0063 
0064   LumiInfo lumiInfo2;
0065   CPPUNIT_ASSERT(!lumiInfo.isProductEqual(lumiInfo2));
0066 
0067   std::cout << lumiInfo;
0068 }