File indexing completed on 2024-04-06 12:04:04
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <Utilities/Testing/interface/CppUnit_testdriver.icpp>
0010 #include <cppunit/extensions/HelperMacros.h>
0011 #include <DataFormats/EcalDetId/interface/EBDetId.h>
0012 #include <DataFormats/EcalDetId/interface/EEDetId.h>
0013 #include <DataFormats/EcalDetId/interface/ESDetId.h>
0014 #include <DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h>
0015 #include <DataFormats/EcalDetId/interface/EcalPnDiodeDetId.h>
0016 #include "FWCore/Utilities/interface/Exception.h"
0017
0018 #include <vector>
0019 #include <algorithm>
0020 #include <iostream>
0021
0022 class testEcalDetId : public CppUnit::TestFixture {
0023 CPPUNIT_TEST_SUITE(testEcalDetId);
0024
0025 CPPUNIT_TEST(testEBDetId);
0026 CPPUNIT_TEST(testEEDetId);
0027 CPPUNIT_TEST(testESDetId);
0028 CPPUNIT_TEST(testEcalTrigTowerDetId);
0029
0030 CPPUNIT_TEST(testPnDiodeDetId);
0031 CPPUNIT_TEST(testDistancePhi);
0032
0033 CPPUNIT_TEST_SUITE_END();
0034
0035 public:
0036 void setUp() {}
0037 void tearDown() {}
0038 void testEBDetId();
0039 void testEEDetId();
0040 void testESDetId();
0041 void testEcalTrigTowerDetId();
0042
0043 void testPnDiodeDetId();
0044 void testDistancePhi();
0045 };
0046
0047
0048 CPPUNIT_TEST_SUITE_REGISTRATION(testEcalDetId);
0049
0050 void testEcalDetId::testEBDetId() {
0051 EBDetId smId;
0052
0053 std::vector<unsigned int> detIds(EBDetId::kSizeForDenseIndexing, 0);
0054
0055 CPPUNIT_ASSERT(!EBDetId::validDetId(0, 1));
0056 CPPUNIT_ASSERT(!EBDetId::validDetId(1, 0));
0057 CPPUNIT_ASSERT(!EBDetId::validDetId(1, -1));
0058 CPPUNIT_ASSERT(!EBDetId::validDetId(1, EBDetId::MAX_IPHI + 1));
0059 CPPUNIT_ASSERT(!EBDetId::validDetId(EBDetId::MAX_IETA + 1, 1));
0060 CPPUNIT_ASSERT(!EBDetId::validDetId(-EBDetId::MAX_IETA - 1, 1));
0061
0062 for (int ieta = EBDetId::MIN_IETA; ieta <= EBDetId::MAX_IETA; ieta++)
0063 for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; iphi++) {
0064
0065 try {
0066 {
0067 EBDetId aPositiveId(ieta, iphi);
0068 CPPUNIT_ASSERT(EBDetId::validDetId(ieta, iphi));
0069 CPPUNIT_ASSERT(aPositiveId.ieta() == ieta);
0070 CPPUNIT_ASSERT(aPositiveId.iphi() == iphi);
0071 CPPUNIT_ASSERT(aPositiveId.zside() == 1);
0072 CPPUNIT_ASSERT(aPositiveId.ietaAbs() == ieta);
0073 int i = 0;
0074 for (; i != 4; ++i)
0075 if (aPositiveId.ietaAbs() <= EBDetId::kModuleBoundaries[i])
0076 break;
0077 CPPUNIT_ASSERT(aPositiveId.im() == i + 1);
0078 CPPUNIT_ASSERT(
0079 !(EBDetId::isNextToEtaBoundary(aPositiveId) ^
0080 (ieta == 1 || std::binary_search(EBDetId::kModuleBoundaries, EBDetId::kModuleBoundaries + 4, ieta))));
0081
0082 smId = EBDetId(aPositiveId.ism(), aPositiveId.ic(), EBDetId::SMCRYSTALMODE);
0083 CPPUNIT_ASSERT(aPositiveId == smId);
0084 CPPUNIT_ASSERT(aPositiveId.ism() == smId.ism());
0085 CPPUNIT_ASSERT(aPositiveId.ic() == smId.ic());
0086 CPPUNIT_ASSERT(smId.ism() >= EBDetId::MIN_SM);
0087 CPPUNIT_ASSERT(smId.ism() <= EBDetId::MAX_SM);
0088 CPPUNIT_ASSERT(smId.ic() >= EBDetId::MIN_C);
0089 CPPUNIT_ASSERT(smId.ic() <= EBDetId::MAX_C);
0090 CPPUNIT_ASSERT(EBDetId::validHashIndex(aPositiveId.hashedIndex()));
0091 CPPUNIT_ASSERT(EBDetId::unhashIndex(aPositiveId.hashedIndex()) == aPositiveId);
0092 detIds.at(aPositiveId.hashedIndex()) = aPositiveId;
0093 }
0094
0095
0096 {
0097 EBDetId aNegativeId(-1 * ieta, iphi);
0098 CPPUNIT_ASSERT(EBDetId::validDetId(-ieta, iphi));
0099 CPPUNIT_ASSERT(aNegativeId.ieta() == -1 * ieta);
0100 CPPUNIT_ASSERT(aNegativeId.iphi() == iphi);
0101 CPPUNIT_ASSERT(aNegativeId.zside() == -1);
0102 CPPUNIT_ASSERT(aNegativeId.ietaAbs() == ieta);
0103
0104 smId = EBDetId(aNegativeId.ism(), aNegativeId.ic(), EBDetId::SMCRYSTALMODE);
0105 CPPUNIT_ASSERT(aNegativeId == smId);
0106 CPPUNIT_ASSERT(aNegativeId.ism() == smId.ism());
0107 CPPUNIT_ASSERT(aNegativeId.ic() == smId.ic());
0108 CPPUNIT_ASSERT(smId.ism() >= EBDetId::MIN_SM);
0109 CPPUNIT_ASSERT(smId.ism() <= EBDetId::MAX_SM);
0110 CPPUNIT_ASSERT(smId.ic() >= EBDetId::MIN_C);
0111 CPPUNIT_ASSERT(smId.ic() <= EBDetId::MAX_C);
0112 CPPUNIT_ASSERT(EBDetId::validHashIndex(aNegativeId.hashedIndex()));
0113 CPPUNIT_ASSERT(EBDetId::unhashIndex(aNegativeId.hashedIndex()) == aNegativeId);
0114 detIds.at(aNegativeId.hashedIndex()) = aNegativeId;
0115 }
0116 } catch (cms::Exception &e) {
0117 std::cout << e.what() << " failed for " << ieta << "," << iphi << std::endl;
0118 bool cmsExceptionCought = false;
0119 CPPUNIT_ASSERT(cmsExceptionCought);
0120 } catch (std::exception &e) {
0121 std::cout << e.what() << " failed for " << ieta << "," << iphi << std::endl;
0122 bool stdExceptionCought = false;
0123 CPPUNIT_ASSERT(stdExceptionCought);
0124 }
0125 }
0126
0127 for (int i = 0; i != EBDetId::kSizeForDenseIndexing; ++i) {
0128 CPPUNIT_ASSERT(detIds[i] != 0);
0129 CPPUNIT_ASSERT(EBDetId(detIds[i]).hashedIndex() == i);
0130 CPPUNIT_ASSERT(EBDetId::unhashIndex(i) == detIds[i]);
0131 }
0132 }
0133
0134 void testEcalDetId::testEEDetId() {
0135 std::vector<unsigned int> detIds(EEDetId::kSizeForDenseIndexing, 0);
0136
0137 for (int ix = EEDetId::IX_MIN; ix <= EEDetId::IX_MAX; ix++)
0138 for (int iy = EEDetId::IY_MIN; iy <= EEDetId::IY_MAX; iy++)
0139 try {
0140 bool fastV = EEDetId::fastValidDetId(ix, iy);
0141
0142 if (EEDetId::slowValidDetId(ix, iy)) {
0143 CPPUNIT_ASSERT(EEDetId::validDetId(ix, iy, 1));
0144 EEDetId aPositiveId(ix, iy, 1);
0145 CPPUNIT_ASSERT(aPositiveId.ix() == ix);
0146 CPPUNIT_ASSERT(aPositiveId.iy() == iy);
0147 CPPUNIT_ASSERT(aPositiveId.zside() == 1);
0148 CPPUNIT_ASSERT(EEDetId::validHashIndex(aPositiveId.hashedIndex()));
0149 CPPUNIT_ASSERT(EEDetId::unhashIndex(aPositiveId.hashedIndex()) == aPositiveId);
0150 detIds.at(aPositiveId.hashedIndex()) = aPositiveId;
0151 } else {
0152 CPPUNIT_ASSERT(!fastV);
0153 }
0154
0155 if (EEDetId::slowValidDetId(ix, iy)) {
0156 CPPUNIT_ASSERT(EEDetId::validDetId(ix, iy, -1));
0157 EEDetId aNegativeId(ix, iy, -1);
0158 CPPUNIT_ASSERT(aNegativeId.ix() == ix);
0159 CPPUNIT_ASSERT(aNegativeId.iy() == iy);
0160 CPPUNIT_ASSERT(aNegativeId.zside() == -1);
0161 CPPUNIT_ASSERT(EEDetId::validHashIndex(aNegativeId.hashedIndex()));
0162 CPPUNIT_ASSERT(EEDetId::unhashIndex(aNegativeId.hashedIndex()) == aNegativeId);
0163 detIds.at(aNegativeId.hashedIndex()) = aNegativeId;
0164 }
0165 } catch (cms::Exception &e) {
0166 bool cmsExceptionCought = false;
0167 CPPUNIT_ASSERT(cmsExceptionCought);
0168 } catch (std::exception &e) {
0169 bool stdExceptionCought = false;
0170 CPPUNIT_ASSERT(stdExceptionCought);
0171 }
0172
0173 int holes = 0;
0174 for (int i = 0; i != EEDetId::kSizeForDenseIndexing; ++i) {
0175
0176 if (detIds[i] == 0) {
0177 holes++;
0178 continue;
0179 }
0180 CPPUNIT_ASSERT(EEDetId(detIds[i]).hashedIndex() == i);
0181 CPPUNIT_ASSERT(EEDetId::unhashIndex(i) == detIds[i]);
0182 }
0183 CPPUNIT_ASSERT(holes == 0);
0184
0185
0186
0187 }
0188
0189 void testEcalDetId::testESDetId() {
0190 for (int istrip = ESDetId::ISTRIP_MIN; istrip <= ESDetId::ISTRIP_MAX; istrip++)
0191 for (int ix = ESDetId::IX_MIN; ix <= ESDetId::IX_MAX; ix++)
0192 for (int iy = ESDetId::IY_MIN; iy <= ESDetId::IY_MAX; iy++) {
0193 try {
0194
0195 {
0196 ESDetId aPositiveId(istrip, ix, iy, 1, 1);
0197 CPPUNIT_ASSERT(aPositiveId.strip() == istrip);
0198 CPPUNIT_ASSERT(aPositiveId.six() == ix);
0199 CPPUNIT_ASSERT(aPositiveId.siy() == iy);
0200 CPPUNIT_ASSERT(aPositiveId.plane() == 1);
0201 CPPUNIT_ASSERT(aPositiveId.zside() == 1);
0202 }
0203
0204 {
0205 ESDetId aPositiveId(istrip, ix, iy, 2, 1);
0206 CPPUNIT_ASSERT(aPositiveId.strip() == istrip);
0207 CPPUNIT_ASSERT(aPositiveId.six() == ix);
0208 CPPUNIT_ASSERT(aPositiveId.siy() == iy);
0209 CPPUNIT_ASSERT(aPositiveId.plane() == 2);
0210 CPPUNIT_ASSERT(aPositiveId.zside() == 1);
0211 }
0212
0213 {
0214 ESDetId aNegativeId(istrip, ix, iy, 1, -1);
0215 CPPUNIT_ASSERT(aNegativeId.strip() == istrip);
0216 CPPUNIT_ASSERT(aNegativeId.six() == ix);
0217 CPPUNIT_ASSERT(aNegativeId.siy() == iy);
0218 CPPUNIT_ASSERT(aNegativeId.plane() == 1);
0219 CPPUNIT_ASSERT(aNegativeId.zside() == -1);
0220 }
0221
0222 {
0223 ESDetId aNegativeId(istrip, ix, iy, 2, -1);
0224 CPPUNIT_ASSERT(aNegativeId.strip() == istrip);
0225 CPPUNIT_ASSERT(aNegativeId.six() == ix);
0226 CPPUNIT_ASSERT(aNegativeId.siy() == iy);
0227 CPPUNIT_ASSERT(aNegativeId.plane() == 2);
0228 CPPUNIT_ASSERT(aNegativeId.zside() == -1);
0229 }
0230 } catch (cms::Exception &e) {
0231 }
0232 }
0233 }
0234
0235 void testEcalDetId::testEcalTrigTowerDetId() {
0236 for (int ieta = EcalTrigTowerDetId::MIN_I; ieta <= EcalTrigTowerDetId::MAX_I; ieta++)
0237 for (int iphi = EcalTrigTowerDetId::MIN_I; iphi <= EcalTrigTowerDetId::MAX_I; iphi++) {
0238 try {
0239
0240 {
0241 EcalTrigTowerDetId aPositiveId(1, EcalBarrel, ieta, iphi);
0242 CPPUNIT_ASSERT(aPositiveId.subDet() == EcalBarrel);
0243 CPPUNIT_ASSERT(aPositiveId.ieta() == ieta);
0244 CPPUNIT_ASSERT(aPositiveId.iphi() == iphi);
0245 CPPUNIT_ASSERT(aPositiveId.zside() == 1);
0246 CPPUNIT_ASSERT(aPositiveId.ietaAbs() == ieta);
0247 }
0248
0249 {
0250 EcalTrigTowerDetId aNegativeId(-1, EcalBarrel, ieta, iphi);
0251 CPPUNIT_ASSERT(aNegativeId.subDet() == EcalBarrel);
0252 CPPUNIT_ASSERT(aNegativeId.ieta() == -1 * ieta);
0253 CPPUNIT_ASSERT(aNegativeId.iphi() == iphi);
0254 CPPUNIT_ASSERT(aNegativeId.zside() == -1);
0255 CPPUNIT_ASSERT(aNegativeId.ietaAbs() == ieta);
0256 }
0257 } catch (cms::Exception &e) {
0258 }
0259 try {
0260
0261 {
0262 EcalTrigTowerDetId aPositiveId(1, EcalEndcap, ieta, iphi);
0263 CPPUNIT_ASSERT(aPositiveId.ieta() == ieta);
0264 CPPUNIT_ASSERT(aPositiveId.subDet() == EcalEndcap);
0265 CPPUNIT_ASSERT(aPositiveId.iphi() == iphi);
0266 CPPUNIT_ASSERT(aPositiveId.zside() == 1);
0267 }
0268
0269 {
0270 EcalTrigTowerDetId aNegativeId(-1, EcalEndcap, ieta, iphi);
0271 CPPUNIT_ASSERT(aNegativeId.subDet() == EcalEndcap);
0272 CPPUNIT_ASSERT(aNegativeId.ieta() == -1 * ieta);
0273 CPPUNIT_ASSERT(aNegativeId.iphi() == iphi);
0274 CPPUNIT_ASSERT(aNegativeId.zside() == -1);
0275 }
0276 } catch (cms::Exception &e) {
0277 }
0278 }
0279 }
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301 void testEcalDetId::testPnDiodeDetId() {
0302 for (int iEcalSubDet = EcalBarrel; iEcalSubDet <= EcalEndcap; iEcalSubDet++)
0303 for (int iDCC = 1; iDCC <= 36; iDCC++)
0304 for (int iPn = 1; iPn <= 10; iPn++) {
0305 try {
0306
0307 {
0308 EcalPnDiodeDetId aId(iEcalSubDet, iDCC, iPn);
0309 CPPUNIT_ASSERT(aId.iEcalSubDetectorId() == iEcalSubDet);
0310 CPPUNIT_ASSERT(aId.iDCCId() == iDCC);
0311 CPPUNIT_ASSERT(aId.iPnId() == iPn);
0312 }
0313 } catch (cms::Exception &e) {
0314 }
0315 }
0316 }
0317
0318 void testEcalDetId::testDistancePhi() {
0319 EBDetId a1(1, 360);
0320 EBDetId b1(1, 1);
0321 CPPUNIT_ASSERT(EBDetId::distancePhi(a1, b1) == 1);
0322
0323 EBDetId a2(1, 1);
0324 EBDetId b2(1, 360);
0325 CPPUNIT_ASSERT(EBDetId::distancePhi(a2, b2) == 1);
0326
0327 EBDetId a3(1, 175);
0328 EBDetId b3(1, 185);
0329 CPPUNIT_ASSERT(EBDetId::distancePhi(a3, b3) == 10);
0330
0331 EBDetId a4(1, 350);
0332 EBDetId b4(1, 3);
0333 CPPUNIT_ASSERT(EBDetId::distancePhi(a4, b4) == 13);
0334 }