Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:41

0001 /* Unit test for CaloCluster
0002    Stefano Argiro', Dec 2010
0003 
0004  */
0005 
0006 #include <cppunit/extensions/HelperMacros.h>
0007 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0008 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalSeverityLevelAlgo.h"
0009 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 
0012 class testEcalSeverityLevelAlgo : public CppUnit::TestFixture {
0013   CPPUNIT_TEST_SUITE(testEcalSeverityLevelAlgo);
0014   CPPUNIT_TEST(testSeverity);
0015   CPPUNIT_TEST_SUITE_END();
0016 
0017 public:
0018   void setUp();
0019   void tearDown() { delete algo_; }
0020 
0021   void testSeverity();
0022 
0023   EcalSeverityLevelAlgo* algo_;
0024 };
0025 
0026 ///registration of the test so that the runner can find it
0027 CPPUNIT_TEST_SUITE_REGISTRATION(testEcalSeverityLevelAlgo);
0028 
0029 using std::string;
0030 
0031 void testEcalSeverityLevelAlgo::setUp() {
0032   edm::ParameterSet ps;
0033 
0034   ps.addParameter<double>("timeThresh", 2.0);
0035 
0036   edm::ParameterSet flagmaskps;
0037   std::vector<std::string> kGoodv, kProblematicv, kRecoveredv, kTimev, kWeirdv, kBadv;
0038   kGoodv.push_back("kGood");
0039   kProblematicv.push_back("kPoorReco");
0040   kProblematicv.push_back("kPoorCalib");
0041   kProblematicv.push_back("kNoisy");
0042   kProblematicv.push_back("kSaturated");
0043   kRecoveredv.push_back("kLeadingEdgeRecovered");
0044   kRecoveredv.push_back("kTowerRecovered");
0045   kTimev.push_back("kOutOfTime");
0046   kWeirdv.push_back("kWeird");
0047   kWeirdv.push_back("kDiWeird");
0048   kBadv.push_back("kFaultyHardware");
0049   kBadv.push_back("kDead");
0050   kBadv.push_back("kKilled");
0051 
0052   flagmaskps.addParameter<std::vector<string> >("kGood", kGoodv);
0053   flagmaskps.addParameter<std::vector<string> >("kProblematic", kProblematicv);
0054   flagmaskps.addParameter<std::vector<string> >("kRecovered", kRecoveredv);
0055   flagmaskps.addParameter<std::vector<string> >("kTime", kTimev);
0056   flagmaskps.addParameter<std::vector<string> >("kWeird", kWeirdv);
0057   flagmaskps.addParameter<std::vector<string> >("kBad", kBadv);
0058 
0059   ps.addParameter<edm::ParameterSet>("flagMask", flagmaskps);
0060 
0061   edm::ParameterSet dbmaskps;
0062   std::vector<uint32_t> kGoods, kProblematics, kRecovereds, kTimes, kWeirds, kBads;
0063 
0064   kGoods.push_back(0);
0065   for (int i = 1; i <= 10; ++i)
0066     kProblematics.push_back(i);
0067   for (int i = 11; i <= 16; ++i)
0068     kBads.push_back(i);
0069 
0070   ps.addParameter<edm::ParameterSet>("dbstatusMask", dbmaskps);
0071 
0072   algo_ = new EcalSeverityLevelAlgo(ps);
0073 }
0074 void testEcalSeverityLevelAlgo::testSeverity() {
0075   EBDetId id(1, 1);
0076   EcalRecHit rh1(id, 0, 0);
0077   rh1.setFlag(EcalRecHit::kGood);
0078 
0079   CPPUNIT_ASSERT(algo_->severityLevel(rh1) == EcalSeverityLevel::kGood);
0080 
0081   EcalRecHit rh2(id, 0, 0);
0082   rh2.setFlag(EcalRecHit::kPoorReco);
0083   rh2.setFlag(EcalRecHit::kPoorCalib);
0084   rh2.setFlag(EcalRecHit::kNoisy);
0085   rh2.setFlag(EcalRecHit::kSaturated);
0086   CPPUNIT_ASSERT(algo_->severityLevel(rh2) == EcalSeverityLevel::kProblematic);
0087   CPPUNIT_ASSERT(algo_->severityLevel(rh2) != EcalSeverityLevel::kBad);
0088   CPPUNIT_ASSERT(algo_->severityLevel(rh2) != EcalSeverityLevel::kGood);
0089   CPPUNIT_ASSERT(algo_->severityLevel(rh2) != EcalSeverityLevel::kWeird);
0090 
0091   EcalRecHit rh3(id, 0, 0);
0092   rh3.setFlag(EcalRecHit::kLeadingEdgeRecovered);
0093   rh3.setFlag(EcalRecHit::kTowerRecovered);
0094 
0095   CPPUNIT_ASSERT(algo_->severityLevel(rh3) == EcalSeverityLevel::kRecovered);
0096 
0097   EcalRecHit rh4(id, 5.0, 0);
0098   rh4.setFlag(EcalRecHit::kOutOfTime);
0099   rh4.setFlag(EcalRecHit::kTowerRecovered);
0100 
0101   CPPUNIT_ASSERT(algo_->severityLevel(rh4) == EcalSeverityLevel::kTime);
0102 
0103   EcalRecHit rh5(id, 0, 0);
0104   rh5.setFlag(EcalRecHit::kWeird);
0105   rh5.setFlag(EcalRecHit::kDiWeird);
0106 
0107   CPPUNIT_ASSERT(algo_->severityLevel(rh5) == EcalSeverityLevel::kWeird);
0108 
0109   EcalRecHit rh6(id, 0, 0);
0110   rh6.setFlag(EcalRecHit::kFaultyHardware);
0111   rh6.setFlag(EcalRecHit::kDead);
0112   rh6.setFlag(EcalRecHit::kKilled);
0113 
0114   CPPUNIT_ASSERT(algo_->severityLevel(rh6) == EcalSeverityLevel::kBad);
0115 
0116   EcalRecHit rh7(id, 1.5, 0);
0117   rh7.setFlag(EcalRecHit::kOutOfTime);
0118 
0119   CPPUNIT_ASSERT(algo_->severityLevel(rh7) == EcalSeverityLevel::kGood);
0120 
0121   EcalRecHit rh8(id, 2.5, 0);
0122   rh8.setFlag(EcalRecHit::kOutOfTime);
0123 
0124   CPPUNIT_ASSERT(algo_->severityLevel(rh8) == EcalSeverityLevel::kTime);
0125 }