Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /* Unit test for CaloCluster
0002    Stefano Argiro', Dec 2010
0003 
0004  */
0005 
0006 #include <cppunit/extensions/HelperMacros.h>
0007 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0008 #include "DataFormats/Math/interface/Point3D.h"
0009 #include "DataFormats/CaloRecHit/interface/CaloID.h"
0010 #include "DataFormats/Common/interface/OrphanHandle.h"
0011 #include "DataFormats/Provenance/interface/ProductID.h"
0012 #include <iostream>
0013 
0014 class testSuperCluster : public CppUnit::TestFixture {
0015   CPPUNIT_TEST_SUITE(testSuperCluster);
0016   CPPUNIT_TEST(PreshowerPlanesTest);
0017   CPPUNIT_TEST(CopyCtorTest);
0018   CPPUNIT_TEST_SUITE_END();
0019 
0020 public:
0021   void setUp() {}
0022   void tearDown() {}
0023 
0024   void PreshowerPlanesTest();
0025   void CopyCtorTest();
0026 };
0027 
0028 ///registration of the test so that the runner can find it
0029 CPPUNIT_TEST_SUITE_REGISTRATION(testSuperCluster);
0030 
0031 void testSuperCluster::PreshowerPlanesTest() {
0032   using namespace reco;
0033   using namespace math;
0034 
0035   SuperCluster c1(0., XYZPoint());
0036 
0037   c1.setPreshowerPlanesStatus(0);
0038   c1.setFlags(CaloCluster::cleanOnly);
0039   c1.setPreshowerPlanesStatus(0);
0040 
0041   CPPUNIT_ASSERT(c1.flags() == CaloCluster::cleanOnly);
0042   CPPUNIT_ASSERT(c1.isInClean() == true);
0043   CPPUNIT_ASSERT(c1.isInUnclean() == false);
0044 
0045   CPPUNIT_ASSERT(c1.getPreshowerPlanesStatus() == 0);
0046 
0047   c1.setFlags(CaloCluster::uncleanOnly);
0048   c1.setPreshowerPlanesStatus(1);
0049   CPPUNIT_ASSERT(c1.getPreshowerPlanesStatus() == 1);
0050   CPPUNIT_ASSERT(c1.flags() == CaloCluster::uncleanOnly);
0051   CPPUNIT_ASSERT(c1.isInClean() == false);
0052   CPPUNIT_ASSERT(c1.isInUnclean() == true);
0053 
0054   c1.setPreshowerPlanesStatus(2);
0055   c1.setFlags(CaloCluster::common);
0056 
0057   CPPUNIT_ASSERT(c1.getPreshowerPlanesStatus() == 2);
0058   CPPUNIT_ASSERT(c1.flags() == CaloCluster::common);
0059   CPPUNIT_ASSERT(c1.isInClean() == true);
0060   CPPUNIT_ASSERT(c1.isInUnclean() == true);
0061 
0062   c1.setPreshowerPlanesStatus(3);
0063   c1.setFlags(CaloCluster::uncleanOnly);
0064 
0065   CPPUNIT_ASSERT(c1.getPreshowerPlanesStatus() == 3);
0066   CPPUNIT_ASSERT(c1.flags() == CaloCluster::uncleanOnly);
0067   CPPUNIT_ASSERT(c1.isInClean() == false);
0068   CPPUNIT_ASSERT(c1.isInUnclean() == true);
0069 }
0070 
0071 void testSuperCluster::CopyCtorTest() {
0072   using namespace reco;
0073   using namespace edm;
0074 
0075   CaloID id;
0076   CaloCluster c1(1.0, math::XYZPoint(0, 0, 0), id);
0077   CaloCluster c2(2.0, math::XYZPoint(0, 0, 0), id);
0078   CaloCluster c3(3.0, math::XYZPoint(0, 0, 0), id);
0079 
0080   CaloClusterCollection clusters;
0081   clusters.push_back(c1);
0082   clusters.push_back(c2);
0083   clusters.push_back(c3);
0084 
0085   ProductID const pid(1, 1);
0086 
0087   OrphanHandle<CaloClusterCollection> handle(&clusters, pid);
0088 
0089   CaloClusterPtr pc1(handle, 0), pc2(handle, 1), pc3(handle, 2);
0090 
0091   SuperCluster sc(5.0, math::XYZPoint(0, 0, 0));
0092   sc.setSeed(pc1);
0093   sc.addCluster(pc2);
0094   sc.addCluster(pc3);
0095 
0096   SuperCluster sccopy = sc;
0097 
0098   CPPUNIT_ASSERT(sc.energy() == sccopy.energy());
0099 
0100   CPPUNIT_ASSERT(sc.seed()->energy() == sccopy.seed()->energy());
0101 
0102   CaloClusterPtrVector::const_iterator bcitcopy = sccopy.clustersBegin();
0103 
0104   for (CaloClusterPtrVector::const_iterator bcit = sc.clustersBegin(); bcit != sc.clustersEnd(); ++bcit) {
0105     CPPUNIT_ASSERT((*bcit)->energy() == (*bcitcopy)->energy());
0106 
0107     bcitcopy++;
0108   }
0109 }