Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-21 23:28:37

0001 #include "SimDataFormats/CaloTest/interface/HGCalTestNumbering.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include <iostream>
0004 
0005 uint32_t HGCalTestNumbering::packSquareIndex(int zp, int lay, int sec, int subsec, int cell) {
0006   if (!HGCalTestNumbering::isValidSquare(zp, lay, sec, subsec, lay)) {
0007     zp = lay = sec = subsec = cell = 0;
0008   }
0009 
0010   uint32_t rawid = 0;
0011   rawid |= ((cell & kHGCalCellSMask) << kHGCalCellSOffset);
0012   rawid |= ((sec & kHGCalSectorSMask) << kHGCalSectorSOffset);
0013   if (subsec < 0)
0014     subsec = 0;
0015   rawid |= ((subsec & kHGCalSubSectorSMask) << kHGCalSubSectorSOffset);
0016   rawid |= ((lay & kHGCalLayerSMask) << kHGCalLayerSOffset);
0017   if (zp > 0)
0018     rawid |= ((zp & kHGCalZsideSMask) << kHGCalZsideSOffset);
0019   return rawid;
0020 }
0021 
0022 uint32_t HGCalTestNumbering::packHexagonIndex(int subdet, int zp, int lay, int wafer, int celltyp, int cell) {
0023   if (!HGCalTestNumbering::isValidHexagon(subdet, zp, lay, wafer, celltyp, cell)) {
0024     subdet = zp = lay = wafer = celltyp = cell = 0;
0025   }
0026 
0027   uint32_t rawid = 0;
0028   rawid |= ((cell & kHGCalCellHMask) << kHGCalCellHOffset);
0029   rawid |= ((celltyp & kHGCalCellTypHMask) << kHGCalCellTypHOffset);
0030   rawid |= ((wafer & kHGCalWaferHMask) << kHGCalWaferHOffset);
0031   rawid |= ((lay & kHGCalLayerHMask) << kHGCalLayerHOffset);
0032   if (zp > 0)
0033     rawid |= ((zp & kHGCalZsideHMask) << kHGCalZsideHOffset);
0034   rawid |= ((subdet & kHGCalSubdetHMask) << kHGCalSubdetHOffset);
0035   return rawid;
0036 }
0037 
0038 void HGCalTestNumbering::unpackSquareIndex(const uint32_t& idx, int& zp, int& lay, int& sec, int& subsec, int& cell) {
0039   cell = (idx >> kHGCalCellSOffset) & kHGCalCellSMask;
0040   subsec = ((idx >> kHGCalSubSectorSOffset) & kHGCalSubSectorSMask ? 1 : -1);
0041   sec = (idx >> kHGCalSectorSOffset) & kHGCalSectorSMask;
0042   lay = (idx >> kHGCalLayerSOffset) & kHGCalLayerSMask;
0043   zp = ((idx >> kHGCalZsideSOffset) & kHGCalZsideSMask ? 1 : -1);
0044 }
0045 
0046 void HGCalTestNumbering::unpackHexagonIndex(
0047     const uint32_t& idx, int& subdet, int& zp, int& lay, int& wafer, int& celltyp, int& cell) {
0048   cell = (idx >> kHGCalCellHOffset) & kHGCalCellHMask;
0049   celltyp = (idx >> kHGCalCellTypHOffset) & kHGCalCellTypHMask;
0050   wafer = (idx >> kHGCalWaferHOffset) & kHGCalWaferHMask;
0051   lay = (idx >> kHGCalLayerHOffset) & kHGCalLayerHMask;
0052   zp = ((idx >> kHGCalZsideHOffset) & kHGCalZsideHMask ? 1 : -1);
0053   subdet = (idx >> kHGCalSubdetHOffset) & kHGCalSubdetHMask;
0054 }
0055 
0056 bool HGCalTestNumbering::isValidSquare(int zp, int lay, int sec, int subsec, int cell) {
0057   if (cell > kHGCalCellSMask || sec > kHGCalSectorSMask || subsec > kHGCalSubSectorSMask || lay > kHGCalLayerSMask) {
0058 #ifdef EDM_ML_DEBUG
0059     std::cout << "[HGCalTestNumbering] request for new id for layer=" << lay << " zp=" << zp << " sector=" << sec
0060               << " subsec=" << subsec << " cell=" << cell << " has one or more fields out of bounds and will be reset"
0061               << std::endl;
0062 #endif
0063     return false;
0064   }
0065   return true;
0066 }
0067 
0068 bool HGCalTestNumbering::isValidHexagon(int subdet, int zp, int lay, int wafer, int celltyp, int cell) {
0069   if (cell > kHGCalCellHMask || celltyp > kHGCalCellTypHMask || wafer > kHGCalWaferHMask || lay > kHGCalLayerSMask ||
0070       subdet > kHGCalSubdetHMask) {
0071     edm::LogWarning("HGCSim") << "[HGCalTestNumbering] request for new id for layer=" << lay << " zp=" << zp
0072                               << " wafer=" << wafer << " celltyp=" << celltyp << " cell=" << cell
0073                               << " for subdet=" << subdet
0074                               << " has one or more fields out of bounds and will be reset *****";
0075     return false;
0076   }
0077   return true;
0078 }