Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-03 00:59:12

0001 #include "Geometry/HGCalCommonData/interface/HGCalProperty.h"
0002 #include "Geometry/HGCalCommonData/interface/HGCalTileIndex.h"
0003 
0004 int32_t HGCalTileIndex::tileIndex(int32_t layer, int32_t ring, int32_t phi) {
0005   int32_t id(0);
0006   id |= (((phi & HGCalProperty::kHGCalPhiMask) << HGCalProperty::kHGCalPhiOffset) |
0007          ((ring & HGCalProperty::kHGCalRingMask) << HGCalProperty::kHGCalRingOffset) |
0008          ((layer & HGCalProperty::kHGCalLayerMask) << HGCalProperty::kHGCalLayerOffset));
0009   return id;
0010 }
0011 
0012 int32_t HGCalTileIndex::tileLayer(int32_t id) {
0013   return ((id >> HGCalProperty::kHGCalLayerOffset) & HGCalProperty::kHGCalLayerMask);
0014 }
0015 
0016 int32_t HGCalTileIndex::tileRing(int32_t id) {
0017   return ((id >> HGCalProperty::kHGCalRingOffset) & HGCalProperty::kHGCalRingMask);
0018 }
0019 
0020 int32_t HGCalTileIndex::tilePhi(int32_t id) {
0021   return ((id >> HGCalProperty::kHGCalPhiOffset) & HGCalProperty::kHGCalPhiMask);
0022 }
0023 
0024 int32_t HGCalTileIndex::tileCassette(int32_t iphi, int32_t phiOffset, int32_t nphiCassette, int32_t cassettes) {
0025   int32_t cassette(0);
0026   if (nphiCassette > 1) {
0027     cassette = (iphi - phiOffset) / nphiCassette;
0028     if (cassette < 0)
0029       cassette += cassettes;
0030     else if (cassette >= cassettes)
0031       cassette = cassettes - 1;
0032   }
0033   return (cassette + 1);
0034 }
0035 
0036 int32_t HGCalTileIndex::tileProperty(int32_t type, int32_t sipm) {
0037   return (((type % HGCalProperty::kHGCalFactor) * HGCalProperty::kHGCalOffsetType) +
0038           ((sipm % HGCalProperty::kHGCalFactor) * HGCalProperty::kHGCalOffsetSiPM));
0039 }
0040 
0041 int32_t HGCalTileIndex::tileType(int32_t property) {
0042   return ((property / HGCalProperty::kHGCalOffsetType) % HGCalProperty::kHGCalFactor);
0043 }
0044 
0045 int32_t HGCalTileIndex::tileSiPM(int32_t property) {
0046   return ((property / HGCalProperty::kHGCalOffsetSiPM) % HGCalProperty::kHGCalFactor);
0047 }
0048 
0049 int32_t HGCalTileIndex::tilePack(int32_t ly, int32_t k1, int32_t k2) {
0050   return (
0051       ((ly % HGCalProperty::kHGCalTilePack) * HGCalProperty::kHGCalTilePack + (k1 % HGCalProperty::kHGCalTilePack)) *
0052           HGCalProperty::kHGCalTilePack +
0053       (k2 % HGCalProperty::kHGCalTilePack));
0054 }
0055 
0056 std::tuple<int32_t, int32_t, int32_t> HGCalTileIndex::tileUnpack(int32_t index) {
0057   int32_t ly =
0058       (index / (HGCalProperty::kHGCalTilePack * HGCalProperty::kHGCalTilePack)) % HGCalProperty::kHGCalTilePack;
0059   int32_t k1 = (index / HGCalProperty::kHGCalTilePack) % HGCalProperty::kHGCalTilePack;
0060   int32_t k2 = (index % HGCalProperty::kHGCalTilePack);
0061   return std::make_tuple(ly, k1, k2);
0062 }
0063 
0064 bool HGCalTileIndex::tileExist(const int32_t* hex, int32_t zside, int32_t iphi) {
0065   int32_t phi(iphi - 1);
0066   if (zside > 0) {
0067     phi += HGCalProperty::kHGCalTilePhisBy2;
0068     if (phi >= HGCalProperty::kHGCalTilePhis)
0069       phi -= HGCalProperty::kHGCalTilePhis;
0070   }
0071   int32_t jj = phi % HGCalProperty::kHGCalTilePhisBy3;
0072   int32_t iw = jj / HGCalProperty::kHGCalTilePhisBy12;
0073   int32_t ibit = HGCalProperty::kHGCalTilePhisBy12 - (jj % HGCalProperty::kHGCalTilePhisBy12) - 1;
0074   bool ok = (hex[iw] & (1 << ibit));
0075   return ok;
0076 }