Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:20:31

0001 /**
0002  * @file intt/InttDefs.cc
0003  * @author D. McGlinchey
0004  * @date June 2018
0005  * @brief Implementation file for InttDefs.h
0006  */
0007 #include "InttDefs.h"
0008 
0009 namespace
0010 {
0011 
0012   // hitsetkey layout:
0013   //  Intt specific lower 16 bits
0014   //   24 - 31  tracker id  // 8 bits
0015   //   16 - 23  layer       // 8 bits
0016   //   14 - 15  ladder z id   // 2 bits
0017   //   10 - 13       ladder phi id  // 4 bits
0018   //   0 - 9     time bucket  // 10 bits
0019   static constexpr unsigned int kBitShiftTimeBucketIdOffset = 0;
0020   static constexpr unsigned int kBitShiftTimeBucketIdWidth = 10;
0021   static constexpr unsigned int kBitShiftLadderPhiIdOffset = 10;
0022   static constexpr unsigned int kBitShiftLadderPhiIdWidth = 4;
0023   static constexpr unsigned int kBitShiftLadderZIdOffset = 14;
0024   static constexpr unsigned int kBitShiftLadderZIdWidth = 2;
0025   static constexpr int crossingOffset = 512;
0026 
0027   // bit shift for hitkey
0028   static const unsigned int kBitShiftCol __attribute__((unused)) = 16;
0029   static const unsigned int kBitShiftRow __attribute__((unused)) = 0;
0030 }
0031 
0032 uint8_t
0033 InttDefs::getLadderZId(TrkrDefs::hitsetkey key)
0034 {
0035   TrkrDefs::hitsetkey tmp = (key >> kBitShiftLadderZIdOffset);
0036   // clear the bits not associated with the ladderZId
0037   uint8_t tmp1 = tmp;
0038   tmp1 = (tmp1 << (8 - kBitShiftLadderZIdWidth));
0039   tmp1 = (tmp1 >> (8 - kBitShiftLadderZIdWidth));
0040   return tmp1;
0041 }
0042 
0043 uint8_t
0044 InttDefs::getLadderZId(TrkrDefs::cluskey key)
0045 {
0046   const TrkrDefs::hitsetkey tmp = TrkrDefs::getHitSetKeyFromClusKey(key);
0047   return getLadderZId(tmp);
0048 }
0049 
0050 uint8_t
0051 InttDefs::getLadderPhiId(TrkrDefs::hitsetkey key)
0052 {
0053   TrkrDefs::hitsetkey tmp = (key >> kBitShiftLadderPhiIdOffset);
0054   // clear the bits not associated with the ladderPhiId
0055   uint8_t tmp1 = tmp;
0056   tmp1 = (tmp1 << (8 - kBitShiftLadderPhiIdWidth));
0057   tmp1 = (tmp1 >> (8 - kBitShiftLadderPhiIdWidth));
0058   return tmp1;
0059 }
0060 
0061 uint8_t
0062 InttDefs::getLadderPhiId(TrkrDefs::cluskey key)
0063 {
0064   const TrkrDefs::hitsetkey tmp = TrkrDefs::getHitSetKeyFromClusKey(key);
0065   return getLadderPhiId(tmp);
0066 }
0067 
0068 int InttDefs::getTimeBucketId(TrkrDefs::hitsetkey key)
0069 {
0070   TrkrDefs::hitsetkey tmp = (key >> kBitShiftTimeBucketIdOffset);
0071   // clear the bits not associated with the TimeBucketId
0072   uint16_t tmp1 = tmp;
0073   tmp1 = (tmp1 << (16 - kBitShiftTimeBucketIdWidth));
0074   tmp1 = (tmp1 >> (16 - kBitShiftTimeBucketIdWidth));
0075 
0076   int tmp2 = (int) tmp1 - crossingOffset;  // get back to signed crossing
0077 
0078   return tmp2;
0079 }
0080 
0081 int InttDefs::getTimeBucketId(TrkrDefs::cluskey key)
0082 {
0083   const TrkrDefs::hitsetkey tmp = TrkrDefs::getHitSetKeyFromClusKey(key);
0084   return getTimeBucketId(tmp);
0085 }
0086 
0087 uint16_t
0088 InttDefs::getCol(TrkrDefs::hitkey key)
0089 {
0090   TrkrDefs::hitkey tmp = (key >> kBitShiftCol);
0091   return tmp;
0092 }
0093 
0094 uint16_t
0095 InttDefs::getRow(TrkrDefs::hitkey key)
0096 {
0097   TrkrDefs::hitkey tmp = (key >> kBitShiftRow);
0098   return tmp;
0099 }
0100 
0101 TrkrDefs::hitkey
0102 InttDefs::genHitKey(const uint16_t col, const uint16_t row)
0103 {
0104   TrkrDefs::hitkey key = (col << kBitShiftCol);
0105   TrkrDefs::hitkey tmp = (row << kBitShiftRow);
0106   key |= tmp;
0107   return key;
0108 }
0109 
0110 TrkrDefs::hitsetkey
0111 InttDefs::genHitSetKey(const uint8_t lyr, const uint8_t ladder_z_index, uint8_t ladder_phi_index, const int crossing_in)
0112 {
0113   TrkrDefs::hitsetkey key = TrkrDefs::genHitSetKey(TrkrDefs::TrkrId::inttId, lyr);
0114 
0115   // offset crossing to make it positive, fit inside 10 bits
0116   int crossing = crossing_in + crossingOffset;
0117   if (crossing < 0)
0118   {
0119     crossing = 0;
0120   }
0121   if (crossing > 1023)
0122   {
0123     crossing = 1023;
0124   }
0125   unsigned int ucrossing = (unsigned int) crossing;
0126 
0127   TrkrDefs::hitsetkey tmp = ladder_z_index;
0128   key |= (tmp << kBitShiftLadderZIdOffset);
0129   tmp = ladder_phi_index;
0130   key |= (tmp << kBitShiftLadderPhiIdOffset);
0131   tmp = ucrossing;
0132   key |= (tmp << kBitShiftTimeBucketIdOffset);
0133 
0134   return key;
0135 }
0136 
0137 TrkrDefs::cluskey
0138 InttDefs::genClusKey(const uint8_t lyr, const uint8_t ladder_z_index, const uint8_t ladder_phi_index, const int crossing, const uint32_t clusid)
0139 {
0140   TrkrDefs::cluskey key = genHitSetKey(lyr, ladder_z_index, ladder_phi_index, crossing);
0141   return TrkrDefs::genClusKey(key, clusid);
0142 }
0143 
0144 TrkrDefs::hitsetkey
0145 InttDefs::resetCrossing(const TrkrDefs::hitsetkey hitsetkey)
0146 {
0147   // Note: this method uses the fact that the crossing is in the first 10 bits
0148   TrkrDefs::hitsetkey tmp = hitsetkey;
0149   // zero the crossing bits by shifting them out of the word, then shift back
0150   tmp = (tmp >> kBitShiftTimeBucketIdWidth);
0151   tmp = (tmp << kBitShiftTimeBucketIdWidth);
0152   unsigned int zero_crossing = crossingOffset;
0153   tmp |= (zero_crossing << kBitShiftTimeBucketIdOffset);
0154 
0155   return tmp;
0156 }