File indexing completed on 2024-04-06 12:04:47
0001
0002
0003
0004
0005
0006
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
0037 CPPUNIT_TEST_SUITE_REGISTRATION(testCSCDetId);
0038
0039 void testCSCDetId::testOne() {
0040
0041
0042
0043
0044
0045
0046
0047
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
0062
0063
0064 CPPUNIT_ASSERT(detid.endcap() == endcap);
0065
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
0072
0073
0074 CPPUNIT_ASSERT(detid.iChamberType() == CSCDetId::iChamberType(station, ring));
0075
0076
0077 int myId = detid.rawId();
0078 CSCDetId anotherId(myId);
0079 CPPUNIT_ASSERT(detid == anotherId);
0080 }
0081 }
0082 }
0083
0084 void testCSCDetId::testFail() {
0085
0086
0087 std::cout << "\nConstruct CSCDetId using an invalid input index\n";
0088 CSCDetId detid1(3, 1, 1, 1, 7);
0089 testValid(detid1);
0090
0091
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);
0107
0108
0109
0110
0111
0112
0113
0114
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 }