Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /**
0002    \file
0003    test file for CSCDetId
0004 
0005    \author Stefano ARGIRO
0006    \date 27 Jul 2005
0007 */
0008 
0009 #include <cppunit/extensions/HelperMacros.h>
0010 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
0011 #include <FWCore/Utilities/interface/Exception.h>
0012 
0013 #include <iostream>
0014 using namespace std;
0015 
0016 class testCSCDetId : public CppUnit::TestFixture {
0017   CPPUNIT_TEST_SUITE(testCSCDetId);
0018 
0019   CPPUNIT_TEST(testOne);
0020   CPPUNIT_TEST(testFail);
0021   CPPUNIT_TEST(testStatic);
0022 
0023   CPPUNIT_TEST_SUITE_END();
0024 
0025 public:
0026   void setUp() {}
0027   void tearDown() {}
0028   void testOne();
0029   void testFail();
0030   void testStatic();
0031 
0032 private:
0033   void testValid(CSCDetId&);
0034 };
0035 
0036 ///registration of the test so that the runner can find it
0037 CPPUNIT_TEST_SUITE_REGISTRATION(testCSCDetId);
0038 
0039 void testCSCDetId::testOne() {
0040   /*
0041     std::cout << "\ntestCSCDetId: testOne starting... " << std::endl;
0042   
0043     std::cout << "min endcap = " << CSCDetId::minEndcapId() << std::endl;
0044     std::cout << "max endcap = " << CSCDetId::maxEndcapId() << std::endl;
0045   
0046     std::cout << "min station = " << CSCDetId::minStationId() << std::endl;
0047     std::cout << "max station = " << CSCDetId::maxStationId() << std::endl;
0048   */
0049 
0050   unsigned short rings[] = {4, 2, 2, 2};
0051   unsigned short chambers[] = {36, 36, 36, 36, 18, 36, 18, 36, 18, 36};
0052 
0053   for (int endcap = CSCDetId::minEndcapId(); endcap <= CSCDetId::maxEndcapId(); ++endcap)
0054     for (int station = CSCDetId::minStationId(); station <= CSCDetId::maxStationId(); ++station)
0055       for (int ring = CSCDetId::minRingId(); ring <= rings[station - 1]; ++ring) {
0056         unsigned short itype = CSCDetId::iChamberType(station, ring);
0057         unsigned short nchambers = chambers[itype - 1];
0058         for (int chamber = CSCDetId::minChamberId(); chamber <= nchambers; ++chamber)
0059           for (int layer = CSCDetId::minLayerId(); layer <= CSCDetId::maxLayerId(); ++layer) {
0060             CSCDetId detid(endcap, station, ring, chamber, layer);
0061             //                std::cout << "detid = " << detid.rawId() << "  " << hex << detid.rawId() <<
0062             //                "  " << oct << detid.rawId() << dec << std::endl;
0063             //              std::cout << "\ndetid.endcap()= " << detid.endcap() << " endcap = " << endcap << std::endl;
0064             CPPUNIT_ASSERT(detid.endcap() == endcap);
0065             //              std::cout << "\ndetid.station()= " << detid.station() << " station = " << station << std::endl;
0066             CPPUNIT_ASSERT(detid.station() == station);
0067             CPPUNIT_ASSERT(detid.ring() == ring);
0068             CPPUNIT_ASSERT(detid.chamber() == chamber);
0069             CPPUNIT_ASSERT(detid.layer() == layer);
0070 
0071             // check chamber type number
0072             //            std::cout << "E" << endcap << " S" << station << " R" << ring << " C" << chamber <<
0073             //        " L" << layer << "   chamber type=" << detid.iChamberType() << std::endl;
0074             CPPUNIT_ASSERT(detid.iChamberType() == CSCDetId::iChamberType(station, ring));
0075 
0076             // test constructor from id
0077             int myId = detid.rawId();
0078             CSCDetId anotherId(myId);
0079             CPPUNIT_ASSERT(detid == anotherId);
0080           }
0081       }
0082 }
0083 
0084 void testCSCDetId::testFail() {
0085   // construct using an invalid input index
0086   // Invalid layer
0087   std::cout << "\nConstruct CSCDetId using an invalid input index\n";
0088   CSCDetId detid1(3, 1, 1, 1, 7);
0089   testValid(detid1);
0090 
0091   // contruct using an invalid input id
0092   std::cout << "\nConstruct CSCDetId using an invalid input id\n";
0093   CSCDetId detid2(3211);
0094   testValid(detid2);
0095 }
0096 
0097 void testCSCDetId::testStatic() {
0098   int ie = 2;
0099   int is = 3;
0100   int ir = 2;
0101   int ic = 10;
0102   int il = 3;
0103 
0104   int id1 = CSCDetId::rawIdMaker(2, 3, 2, 10, 3);
0105   int id2 = CSCDetId::rawIdMaker(ie, is, ir, ic, il);
0106   int id3 = CSCDetId::rawIdMaker(ie, is, ir, ic, 0);  // all layers i.e. chamber id
0107 
0108   //  std::cout << "\nE" << ie << " S" << is << " R" << ir << " C" << ic
0109   //       << " L" << il << " has rawId = " << id2 << " (dec) = "
0110   //       << hex << id2 << " (hex) " << oct << id2 << " (oct)" << dec << std::endl;
0111   //
0112   //  std::cout << "\nE" << ie << " S" << is << " R" << ir << " C" << ic
0113   //       << " L0" << " has rawId = " << id3 << " = "
0114   //       << hex << id3 << " (hex) " << oct << id3 << " (oct)" << dec << std::endl;
0115 
0116   CPPUNIT_ASSERT(id1 == id2);
0117   CPPUNIT_ASSERT(CSCDetId::endcap(id2) == ie);
0118   CPPUNIT_ASSERT(CSCDetId::station(id2) == is);
0119   CPPUNIT_ASSERT(CSCDetId::ring(id2) == ir);
0120   CPPUNIT_ASSERT(CSCDetId::chamber(id2) == ic);
0121   CPPUNIT_ASSERT(CSCDetId::layer(id2) == il);
0122   CPPUNIT_ASSERT(CSCDetId::chamber(id3) == ic);
0123 }
0124 
0125 void testCSCDetId::testValid(CSCDetId& detId) {
0126   if (detId.det() != DetId::Muon || detId.subdetId() != MuonSubdetId::CSC) {
0127     std::cout << "Invalid CSCDetId:"
0128               << " det: " << detId.det() << " subdet: " << detId.subdetId() << " is not a valid CSC id\n";
0129   }
0130   int iendcap = detId.endcap();
0131   int istation = detId.station();
0132   int iring = detId.ring();
0133   int ichamber = detId.chamber();
0134   int ilayer = detId.layer();
0135   if (iendcap < detId.minEndcapId() || iendcap > detId.maxEndcapId() || istation < detId.minStationId() ||
0136       istation > detId.maxStationId() || iring < detId.minRingId() || iring > detId.maxRingId() ||
0137       ichamber < detId.minChamberId() || ichamber > detId.maxChamberId() || ilayer < detId.minLayerId() ||
0138       ilayer > detId.maxLayerId()) {
0139     std::cout << "Invalid CSCDetId:"
0140               << " Invalid parameters: "
0141               << " E:" << iendcap << "(" << detId.minEndcapId() << ":" << detId.maxEndcapId() << ")"
0142               << " S:" << istation << "(" << detId.minStationId() << ":" << detId.maxStationId() << ")"
0143               << " R:" << iring << "(" << detId.minRingId() << ":" << detId.maxRingId() << ")"
0144               << " C:" << ichamber << "(" << detId.minChamberId() << ":" << detId.maxChamberId() << ")"
0145               << " L:" << ilayer << "(" << detId.minLayerId() << ":" << detId.maxLayerId() << ")"
0146               << "\n";
0147   }
0148 }