Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:40

0001 #include <cppunit/extensions/HelperMacros.h>
0002 #include "DataFormats/Luminosity/interface/BeamCurrentInfo.h"
0003 
0004 #include <string>
0005 #include <vector>
0006 #include <iostream>
0007 #include <cmath>
0008 
0009 class TestBeamCurrentInfo : public CppUnit::TestFixture {
0010   static const float tol;
0011 
0012   CPPUNIT_TEST_SUITE(TestBeamCurrentInfo);
0013   CPPUNIT_TEST(testFill);
0014   CPPUNIT_TEST_SUITE_END();
0015 
0016 public:
0017   void setUp() {}
0018   void tearDown() {}
0019 
0020   void testFill();
0021 };
0022 
0023 // tolerance (relative)
0024 const float TestBeamCurrentInfo::tol = 1e-3;
0025 
0026 ///registration of the test so that the runner can find it
0027 CPPUNIT_TEST_SUITE_REGISTRATION(TestBeamCurrentInfo);
0028 
0029 void TestBeamCurrentInfo::testFill() {
0030   BeamCurrentInfo beamCurrentInfo;
0031 
0032   // Use somewhat realistic data so that we don't end up out-of-range.
0033 
0034   std::vector<float> beam1;
0035   beam1.push_back(0.042e10f);
0036   beam1.push_back(14.481e10f);
0037   beam1.push_back(0.422e10f);
0038 
0039   std::vector<float> beam2;
0040   beam2.push_back(0.081e10f);
0041   beam2.push_back(14.662e10f);
0042   beam2.push_back(0.135e10f);
0043 
0044   beamCurrentInfo.fill(beam1, beam2);
0045 
0046   std::cout << beamCurrentInfo;
0047 
0048   CPPUNIT_ASSERT(std::abs(beamCurrentInfo.getBeam1IntensityBX(0) - beam1[0]) <
0049                  beamCurrentInfo.getBeam1IntensityBX(0) * tol);
0050   CPPUNIT_ASSERT(std::abs(beamCurrentInfo.getBeam1IntensityBX(1) - beam1[1]) <
0051                  beamCurrentInfo.getBeam1IntensityBX(1) * tol);
0052   CPPUNIT_ASSERT(std::abs(beamCurrentInfo.getBeam1IntensityBX(2) - beam1[2]) <
0053                  beamCurrentInfo.getBeam1IntensityBX(2) * tol);
0054 
0055   CPPUNIT_ASSERT(std::abs(beamCurrentInfo.getBeam2IntensityBX(0) - beam2[0]) <
0056                  beamCurrentInfo.getBeam2IntensityBX(0) * tol);
0057   CPPUNIT_ASSERT(std::abs(beamCurrentInfo.getBeam2IntensityBX(1) - beam2[1]) <
0058                  beamCurrentInfo.getBeam2IntensityBX(1) * tol);
0059   CPPUNIT_ASSERT(std::abs(beamCurrentInfo.getBeam2IntensityBX(2) - beam2[2]) <
0060                  beamCurrentInfo.getBeam2IntensityBX(2) * tol);
0061 
0062   CPPUNIT_ASSERT(beamCurrentInfo.isProductEqual(beamCurrentInfo));
0063 
0064   BeamCurrentInfo beamCurrentInfo2;
0065   CPPUNIT_ASSERT(!beamCurrentInfo.isProductEqual(beamCurrentInfo2));
0066 }