Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:39

0001 /**
0002    \file
0003    test unit for CSCIndexers (both CSCIndexerStartup and CSCIndexerPostls1)
0004 
0005    What's tested:
0006     - full round-trip index conversion test for the full ranges of all the
0007    indices
0008     - for the ganged case check the equivalence of ME1a input to ME1a WRT the
0009    calculation of various indices
0010     - full comparison of various indices calculation against the old code
0011 
0012    The old indexers with some code adaptations are saved in
0013    CalibMuon/CSCCalibration/test/old_indexers/
0014 
0015    \author Vadim Khotilovich
0016    \date 2 Dec 2012
0017 */
0018 
0019 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0020 #include <cppunit/extensions/HelperMacros.h>
0021 
0022 #include "CalibMuon/CSCCalibration/interface/CSCIndexerPostls1.h"
0023 #include "CalibMuon/CSCCalibration/interface/CSCIndexerStartup.h"
0024 #include "CalibMuon/CSCCalibration/test/old_indexers/CSCIndexerOldPostls1.h"
0025 #include "CalibMuon/CSCCalibration/test/old_indexers/CSCIndexerOldStartup.h"
0026 #include "FWCore/Utilities/interface/Exception.h"
0027 
0028 #include <iostream>
0029 
0030 using namespace std;
0031 
0032 typedef CSCIndexerBase::IndexType IndexType;
0033 typedef CSCIndexerBase::LongIndexType LongIndexType;
0034 
0035 // an "external polymolrphism" sort of adapter pattern for making unrelated
0036 // indexer classes polymorphic
0037 class IndexerAdapterBase {
0038 public:
0039   virtual ~IndexerAdapterBase() {}
0040   virtual int ringsInStation(int s) = 0;
0041   virtual int chambersInRingOfStation(int s, int r) = 0;
0042   virtual int stripChannelsPerLayer(int s, int r) = 0;
0043   virtual int chipsPerLayer(int s, int r) = 0;
0044   virtual int sectorsPerLayer(int s, int r) = 0;
0045   virtual int chamberIndex(CSCDetId &id) = 0;
0046   virtual IndexType layerIndex(CSCDetId &id) = 0;
0047   virtual LongIndexType stripChannelIndex(CSCDetId &id, int strip) = 0;
0048   virtual IndexType chipIndex(CSCDetId &id, int chip) = 0;
0049   virtual IndexType gasGainIndex(int hvseg, int chit, CSCDetId &id) = 0;
0050 };
0051 
0052 template <class INDEXER>
0053 class IndexerAdapter : public IndexerAdapterBase {
0054   INDEXER indexer;
0055 
0056 public:
0057   int ringsInStation(int s) { return indexer.ringsInStation(s); }
0058   int chambersInRingOfStation(int s, int r) { return indexer.chambersInRingOfStation(s, r); }
0059   int stripChannelsPerLayer(int s, int r) { return indexer.stripChannelsPerLayer(s, r); }
0060   int chipsPerLayer(int s, int r) { return indexer.chipsPerLayer(s, r); }
0061   int sectorsPerLayer(int s, int r) { return indexer.sectorsPerLayer(s, r); }
0062   int chamberIndex(CSCDetId &id) { return indexer.chamberIndex(id); }
0063   IndexType layerIndex(CSCDetId &id) { return indexer.layerIndex(id); }
0064   LongIndexType stripChannelIndex(CSCDetId &id, int strip) { return indexer.stripChannelIndex(id, strip); }
0065   IndexType chipIndex(CSCDetId &id, int chip) { return indexer.chipIndex(id, chip); }
0066   IndexType gasGainIndex(int hvseg, int chip, CSCDetId &id) { return indexer.gasGainIndex(hvseg, chip, id); }
0067 };
0068 
0069 class testCSCIndexer : public CppUnit::TestFixture {
0070   CPPUNIT_TEST_SUITE(testCSCIndexer);
0071 
0072   CPPUNIT_TEST(testStartupChamber);
0073   CPPUNIT_TEST(testStartupLayer);
0074   CPPUNIT_TEST(testStartupStripChannel);
0075   CPPUNIT_TEST(testStartupChip);
0076   CPPUNIT_TEST(testStartupGasGain);
0077 
0078   CPPUNIT_TEST(testPostls1Chamber);
0079   CPPUNIT_TEST(testPostls1Layer);
0080   CPPUNIT_TEST(testPostls1StripChannel);
0081   CPPUNIT_TEST(testPostls1Chip);
0082   CPPUNIT_TEST(testPostls1GasGain);
0083 
0084   CPPUNIT_TEST(testStartupChamberME1a);
0085   CPPUNIT_TEST(testStartupLayerME1a);
0086   CPPUNIT_TEST(testStartupStripChannelME1a);
0087   CPPUNIT_TEST(testStartupChipME1a);
0088   CPPUNIT_TEST(testStartupGasGainME1a);
0089 
0090   CPPUNIT_TEST(testStartupAgainstOldCode);
0091   CPPUNIT_TEST(testPostls1AgainstOldCode);
0092 
0093   // CPPUNIT_TEST(testFail);
0094 
0095   CPPUNIT_TEST_SUITE_END();
0096 
0097   CSCIndexerBase *indexer_;
0098   CSCIndexerStartup *indexer_startup_;
0099   CSCIndexerPostls1 *indexer_postls1_;
0100 
0101   IndexerAdapterBase *indexer_old_;
0102   IndexerAdapter<CSCIndexerOldStartup> *indexer_old_startup_;
0103   IndexerAdapter<CSCIndexerOldPostls1> *indexer_old_postls1_;
0104 
0105   void modeStartup() {
0106     indexer_ = indexer_startup_;
0107     indexer_old_ = indexer_old_startup_;
0108   }
0109   void modePostls1() {
0110     indexer_ = indexer_postls1_;
0111     indexer_old_ = indexer_old_postls1_;
0112   }
0113 
0114 public:
0115   void setUp();
0116   void tearDown();
0117 
0118   void testChamber();
0119   void testLayer();
0120   void testStripChannel();
0121   void testChip();
0122   void testGasGain();
0123   // void testFail();
0124 
0125   void testStartupChamber() {
0126     modeStartup();
0127     testChamber();
0128   }
0129   void testStartupLayer() {
0130     modeStartup();
0131     testLayer();
0132   }
0133   void testStartupStripChannel() {
0134     modeStartup();
0135     testStripChannel();
0136   }
0137   void testStartupChip() {
0138     modeStartup();
0139     testChip();
0140   }
0141   void testStartupGasGain() {
0142     modeStartup();
0143     testGasGain();
0144   }
0145 
0146   void testPostls1Chamber() {
0147     modePostls1();
0148     testChamber();
0149   }
0150   void testPostls1Layer() {
0151     modePostls1();
0152     testLayer();
0153   }
0154   void testPostls1StripChannel() {
0155     modePostls1();
0156     testStripChannel();
0157   }
0158   void testPostls1Chip() {
0159     modePostls1();
0160     testChip();
0161   }
0162   void testPostls1GasGain() {
0163     modePostls1();
0164     testGasGain();
0165   }
0166 
0167   void testStartupChamberME1a();
0168   void testStartupLayerME1a();
0169   void testStartupStripChannelME1a();
0170   void testStartupChipME1a();
0171   void testStartupGasGainME1a();
0172 
0173   void testStartupAgainstOldCode() {
0174     modeStartup();
0175     testAgainstOldCode();
0176   }
0177   void testPostls1AgainstOldCode() {
0178     modePostls1();
0179     testAgainstOldCode();
0180   }
0181 
0182   void testAgainstOldCode();
0183 };
0184 
0185 /// registration of the test so that the runner can find it
0186 CPPUNIT_TEST_SUITE_REGISTRATION(testCSCIndexer);
0187 
0188 void testCSCIndexer::setUp() {
0189   indexer_ = nullptr;
0190   indexer_startup_ = new CSCIndexerStartup();
0191   indexer_postls1_ = new CSCIndexerPostls1();
0192 
0193   indexer_old_ = nullptr;
0194   indexer_old_startup_ = new IndexerAdapter<CSCIndexerOldStartup>();
0195   indexer_old_postls1_ = new IndexerAdapter<CSCIndexerOldPostls1>();
0196 }
0197 
0198 void testCSCIndexer::tearDown() {
0199   delete indexer_startup_;
0200   delete indexer_postls1_;
0201   delete indexer_old_startup_;
0202   delete indexer_old_postls1_;
0203 }
0204 
0205 void testCSCIndexer::testChamber() {
0206   // std::cout << "\ntestCSCIndexer: testChamber starting... " << std::endl;
0207 
0208   for (LongIndexType i = 1; i <= indexer_->maxChamberIndex(); ++i) {
0209     CSCDetId id = indexer_->detIdFromChamberIndex(i);
0210     int ie = id.endcap();
0211     int is = id.station();
0212     int ir = id.ring();
0213     int ic = id.chamber();
0214     IndexType ii = indexer_->chamberIndex(id);
0215 
0216     if (i != ii)
0217       cout << " BAD CHAMBER INDEX: " << i << " != " << ii << " \t   (" << ie << " " << is << " " << ir << " " << ic
0218            << ")" << endl;
0219     CPPUNIT_ASSERT(i == ii);  // loop-back index test
0220     CPPUNIT_ASSERT(ie >= 1 && ie <= 2);
0221     CPPUNIT_ASSERT(is >= 1 && is <= 4);
0222     CPPUNIT_ASSERT(ir >= 1 && ir <= indexer_->offlineRingsInStation(is));
0223     CPPUNIT_ASSERT(ic >= 1 && ic <= indexer_->chambersInRingOfStation(is, ir));
0224   }
0225 }
0226 
0227 void testCSCIndexer::testLayer() {
0228   // std::cout << "\ntestCSCIndexer: testLayer starting... " << std::endl;
0229 
0230   for (LongIndexType i = 1; i <= indexer_->maxLayerIndex(); ++i) {
0231     CSCDetId id = indexer_->detIdFromLayerIndex(i);
0232     int ie = id.endcap();
0233     int is = id.station();
0234     int ir = id.ring();
0235     int ic = id.chamber();
0236     int il = id.layer();
0237     IndexType ii = indexer_->layerIndex(id);
0238 
0239     if (i != ii)
0240       cout << " BAD LAYER INDEX: " << i << " != " << ii << " \t   (" << ie << " " << is << " " << ir << " " << ic << " "
0241            << il << ")" << endl;
0242     CPPUNIT_ASSERT(i == ii);  // loop-back index test
0243     CPPUNIT_ASSERT(ie >= 1 && ie <= 2);
0244     CPPUNIT_ASSERT(is >= 1 && is <= 4);
0245     CPPUNIT_ASSERT(ir >= 1 && ir <= indexer_->offlineRingsInStation(is));
0246     CPPUNIT_ASSERT(ic >= 1 && ic <= indexer_->chambersInRingOfStation(is, ir));
0247     CPPUNIT_ASSERT(il >= 1 && il <= 6);
0248   }
0249 }
0250 
0251 void testCSCIndexer::testStripChannel() {
0252   // std::cout << "\ntestCSCIndexer: testStripChannel starting... " <<
0253   // std::endl;
0254 
0255   for (LongIndexType i = 1; i <= indexer_->maxStripChannelIndex(); ++i) {
0256     std::pair<CSCDetId, CSCIndexerBase::IndexType> t = indexer_->detIdFromStripChannelIndex(i);
0257     CSCDetId id = t.first;
0258     int ie = id.endcap();
0259     int is = id.station();
0260     int ir = id.ring();
0261     int ic = id.chamber();
0262     int il = id.layer();
0263     int st = t.second;
0264     LongIndexType ii = indexer_->stripChannelIndex(id, st);
0265 
0266     if (i != ii)
0267       cout << " BAD STRIPCHANNEL INDEX: " << i << " != " << ii << " \t   (" << ie << " " << is << " " << ir << " " << ic
0268            << " " << il << ") " << st << endl;
0269     CPPUNIT_ASSERT(i == ii);  // loop-back index test
0270     CPPUNIT_ASSERT(ie >= 1 && ie <= 2);
0271     CPPUNIT_ASSERT(is >= 1 && is <= 4);
0272     CPPUNIT_ASSERT(ir >= 1 && ir <= indexer_->offlineRingsInStation(is));
0273     CPPUNIT_ASSERT(ic >= 1 && ic <= indexer_->chambersInRingOfStation(is, ir));
0274     CPPUNIT_ASSERT(il >= 1 && il <= 6);
0275     CPPUNIT_ASSERT(st >= 1 && st <= indexer_->stripChannelsPerLayer(is, ir));
0276   }
0277 }
0278 
0279 void testCSCIndexer::testChip() {
0280   // std::cout << "\ntestCSCIndexer: testChip starting... " << std::endl;
0281 
0282   for (IndexType i = 1; i <= indexer_->maxChipIndex(); ++i) {
0283     std::pair<CSCDetId, IndexType> t = indexer_->detIdFromChipIndex(i);
0284     CSCDetId id = t.first;
0285     int ie = id.endcap();
0286     int is = id.station();
0287     int ir = id.ring();
0288     int ic = id.chamber();
0289     int il = id.layer();
0290     int ch = t.second;
0291     IndexType ii = indexer_->chipIndex(id, ch);
0292 
0293     if (i != ii)
0294       cout << " BAD CHIP INDEX: " << i << " != " << ii << " \t   (" << ie << " " << is << " " << ir << " " << ic << " "
0295            << il << ") " << ch << endl;
0296     CPPUNIT_ASSERT(i == ii);  // loop-back index test
0297     CPPUNIT_ASSERT(ie >= 1 && ie <= 2);
0298     CPPUNIT_ASSERT(is >= 1 && is <= 4);
0299     CPPUNIT_ASSERT(ir >= 1 && ir <= indexer_->offlineRingsInStation(is));
0300     CPPUNIT_ASSERT(ic >= 1 && ic <= indexer_->chambersInRingOfStation(is, ir));
0301     CPPUNIT_ASSERT(il >= 1 && il <= 6);
0302     CPPUNIT_ASSERT(ch >= 1 && ch <= indexer_->chipsPerLayer(is, ir));
0303   }
0304 }
0305 
0306 void testCSCIndexer::testGasGain() {
0307   // std::cout << "\ntestCSCIndexer: testGasGain starting... " << std::endl;
0308 
0309   for (IndexType i = 1; i <= indexer_->maxGasGainIndex(); ++i) {
0310     CSCIndexerBase::GasGainIndexType t = indexer_->detIdFromGasGainIndex(i);
0311     CSCDetId id = std::get<0>(t);
0312     int ie = id.endcap();
0313     int is = id.station();
0314     int ir = id.ring();
0315     int ic = id.chamber();
0316     int il = id.layer();
0317     int hv = std::get<1>(t);
0318     int ch = std::get<2>(t);
0319     IndexType ii = indexer_->gasGainIndex(hv, ch, id);
0320 
0321     if (i != ii)
0322       cout << " BAD GASGAIN INDEX: " << i << " != " << ii << " \t   (" << ie << " " << is << " " << ir << " " << ic
0323            << " " << il << ") " << hv << " " << ch << endl;
0324     CPPUNIT_ASSERT(i == ii);  // loop-back index test
0325     CPPUNIT_ASSERT(ie >= 1 && ie <= 2);
0326     CPPUNIT_ASSERT(is >= 1 && is <= 4);
0327     CPPUNIT_ASSERT(ir >= 1 && ir <= indexer_->offlineRingsInStation(is));
0328     CPPUNIT_ASSERT(ic >= 1 && ic <= indexer_->chambersInRingOfStation(is, ir));
0329     CPPUNIT_ASSERT(il >= 1 && il <= 6);
0330     CPPUNIT_ASSERT(hv >= 1 && hv <= indexer_->hvSegmentsPerLayer(is, ir));
0331     CPPUNIT_ASSERT(ch >= 1 && ch <= indexer_->chipsPerLayer(is, ir));
0332   }
0333 }
0334 
0335 void testCSCIndexer::testStartupChamberME1a() {
0336   modeStartup();
0337   const CSCDetId id_me1a(1, 1, 4, 1);
0338   const CSCDetId id_me1b(1, 1, 1, 1);
0339   CPPUNIT_ASSERT(indexer_->chamberIndex(id_me1a) == indexer_->chamberIndex(id_me1b));
0340 }
0341 
0342 void testCSCIndexer::testStartupLayerME1a() {
0343   modeStartup();
0344   const CSCDetId id_me1a(1, 1, 4, 1, 2);
0345   const CSCDetId id_me1b(1, 1, 1, 1, 2);
0346   CPPUNIT_ASSERT(indexer_->layerIndex(id_me1a) == indexer_->layerIndex(id_me1b));
0347 }
0348 
0349 void testCSCIndexer::testStartupStripChannelME1a() {
0350   modeStartup();
0351   const CSCDetId id_me1a(1, 1, 4, 1, 2);
0352   const CSCDetId id_me1b(1, 1, 1, 1, 2);
0353   const IndexType istrip = 66;
0354   CPPUNIT_ASSERT(indexer_->stripChannelIndex(id_me1a, istrip) == indexer_->stripChannelIndex(id_me1b, istrip));
0355 }
0356 
0357 void testCSCIndexer::testStartupChipME1a() {
0358   modeStartup();
0359   const CSCDetId id_me1a(1, 1, 4, 1, 2);
0360   const CSCDetId id_me1b(1, 1, 1, 1, 2);
0361   const IndexType ichip = 5;
0362   CPPUNIT_ASSERT(indexer_->chipIndex(id_me1a, ichip) == indexer_->chipIndex(id_me1b, ichip));
0363 }
0364 
0365 void testCSCIndexer::testStartupGasGainME1a() {
0366   modeStartup();
0367   const CSCDetId id_me1a(1, 1, 4, 1, 2);
0368   const CSCDetId id_me1b(1, 1, 1, 1, 2);
0369   const IndexType istrip = 66;
0370   const IndexType iwire = 4;
0371   CPPUNIT_ASSERT(indexer_->gasGainIndex(id_me1a, istrip, iwire) == indexer_->gasGainIndex(id_me1b, istrip, iwire));
0372 }
0373 
0374 void testCSCIndexer::testAgainstOldCode() {
0375   for (int e = 1; e <= 2; ++e)
0376     for (int s = 1; s <= 4; ++s) {
0377       int rmax = indexer_->ringsInStation(s);
0378       CPPUNIT_ASSERT(rmax == indexer_old_->ringsInStation(s));
0379 
0380       if (s == 1 && indexer_->name() == "CSCIndexerPostls1")
0381         rmax = 4;
0382 
0383       for (int r = 1; r <= rmax; ++r) {
0384         int cmax = indexer_->chambersInRingOfStation(s, r);
0385         CPPUNIT_ASSERT(cmax == indexer_old_->chambersInRingOfStation(s, r));
0386 
0387         CPPUNIT_ASSERT(indexer_->stripChannelsPerLayer(s, r) == indexer_old_->stripChannelsPerLayer(s, r));
0388         int stripmax = indexer_->stripChannelsPerOnlineLayer(s, r);
0389 
0390         CPPUNIT_ASSERT(indexer_->chipsPerLayer(s, r) == indexer_old_->chipsPerLayer(s, r));
0391         int chipmax = indexer_->chipsPerOnlineLayer(s, r);
0392 
0393         CPPUNIT_ASSERT(indexer_->sectorsPerLayer(s, r) == indexer_old_->sectorsPerLayer(s, r));
0394         int hvsegmax = indexer_->sectorsPerOnlineLayer(s, r);
0395 
0396         for (int c = 1; c <= cmax; ++c) {
0397           CSCDetId cid(e, s, r, c);
0398           CPPUNIT_ASSERT(indexer_->chamberIndex(cid) == indexer_old_->chamberIndex(cid));
0399 
0400           for (int l = 1; l <= 6; ++l) {
0401             CSCDetId id(e, s, r, c, l);
0402             CPPUNIT_ASSERT(indexer_->layerIndex(id) == indexer_old_->layerIndex(id));
0403 
0404             for (int strip = 1; strip <= stripmax; ++strip) {
0405               CPPUNIT_ASSERT(indexer_->stripChannelIndex(id, strip) == indexer_old_->stripChannelIndex(id, strip));
0406             }
0407 
0408             for (int chip = 1; chip <= chipmax; ++chip) {
0409               CPPUNIT_ASSERT(indexer_->chipIndex(id, chip) == indexer_old_->chipIndex(id, chip));
0410 
0411               for (int hvseg = 1; hvseg <= hvsegmax; ++hvseg) {
0412                 CPPUNIT_ASSERT(indexer_->gasGainIndex(hvseg, chip, id) == indexer_old_->gasGainIndex(hvseg, chip, id));
0413               }
0414             }
0415           }
0416         }
0417       }
0418     }
0419 }
0420 
0421 /*
0422 void testCSCIndexer::testFail(){
0423 
0424   // std::cout << "\ntestCSCIndexer: testFail starting... " << std::endl;
0425 
0426   // construct using an invalid input index
0427   try {
0428     // Invalid layer
0429     CSCDetId detid(3,1,1,1,7);
0430     CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0431     detid.rawId(); // avoid compiler warning
0432   } catch (cms::Exception& e) {
0433     //    std::cout << "\ntestCSCDetId: testFail exception caught " <<
0434 std::endl;
0435     // OK
0436   } catch (...) {
0437     CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0438   }
0439 
0440 }
0441 */