Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:17:03

0001 /**
0002  * @file trackbase/TrkrDefs.h
0003  * @author D. McGlinchey
0004  * @date June 2018
0005  * @brief Namespace with Trkr key types and utility functions
0006  */
0007 #ifndef TRACKBASE_TRKRDEFS_H
0008 #define TRACKBASE_TRKRDEFS_H
0009 
0010 #include <cstdint>
0011 #include <iostream>
0012 #include <map>
0013 #include <string>
0014 
0015 /**
0016  * @brief Define a namespace for Trkr typedefs
0017  */
0018 namespace TrkrDefs
0019 {
0020   [[maybe_unused]] static constexpr double EdepScaleFactor = 0.25;
0021   [[maybe_unused]] static constexpr double MvtxEnergyScaleup = 5.0e8;
0022   [[maybe_unused]] static constexpr double InttEnergyScaleup = 5.0e7;
0023 
0024   /// Key types
0025   using hitkey = uint32_t;      // 32 bit TrkrHit key type
0026   using hitsetkey = uint32_t;   // 32 bit TrkrHitSet key type
0027   using cluskey = uint64_t;     // 64 but TrkrCluster id type
0028   using clushitkey = uint32_t;  // 32 bit hit id type in TrkrCluster
0029   using subsurfkey = uint16_t;  // 16 bit sub surface key type
0030 
0031   /// Max values for keys (used as defaults or invalid values)
0032   [[maybe_unused]] static constexpr hitkey HITKEYMAX = UINT32_MAX;
0033   [[maybe_unused]] static constexpr hitsetkey HITSETKEYMAX = UINT32_MAX;
0034   [[maybe_unused]] static constexpr cluskey CLUSKEYMAX = UINT64_MAX;
0035   [[maybe_unused]] static constexpr clushitkey CLUSHITKEYMAX = UINT32_MAX;
0036   [[maybe_unused]] static constexpr subsurfkey SUBSURFKEYMAX = UINT16_MAX;
0037 
0038   /// Enumeration for tracker id to easily maintain consistency
0039   enum TrkrId
0040   {
0041     mvtxId = 0,
0042     inttId = 1,
0043     tpcId = 2,
0044     micromegasId = 3
0045   };
0046 
0047   //! Standard names for trackers
0048   static const std::map<TrkrId, std::string> TrkrNames =
0049   {
0050       {mvtxId, "MVTX"},
0051       {inttId, "INTT"},
0052       {tpcId, "TPC"},
0053       {micromegasId, "MICROMEGAS"}
0054   };
0055 
0056   /// Print the bits for each key type
0057   void printBits(const TrkrDefs::hitsetkey key, std::ostream& os = std::cout);
0058   void printBits(const TrkrDefs::cluskey key, std::ostream& os = std::cout);
0059   // void print_bits(const TrkrDefs::hitkey key, std::ostream& os = std::cout);
0060 
0061   /// Get the tracker ID from either key type
0062   uint8_t getTrkrId(const TrkrDefs::hitsetkey key);
0063   uint8_t getTrkrId(const TrkrDefs::cluskey key);
0064 
0065   /// Get the layer number from either key type
0066   uint8_t getLayer(const TrkrDefs::hitsetkey key);
0067   uint8_t getLayer(const TrkrDefs::cluskey key);
0068 
0069   /// Get the lower 32 bits for cluster keys only
0070   uint32_t getClusIndex(const TrkrDefs::cluskey key);
0071 
0072   /// generate the common upper 16 bits for hitsetkey
0073   TrkrDefs::hitsetkey genHitSetKey(const TrkrDefs::TrkrId trkrId, const uint8_t lyr);
0074 
0075   /// generate cluster key from hitset key and cluster index
0076   TrkrDefs::cluskey genClusKey(const TrkrDefs::hitsetkey hskey, const uint32_t clusid);
0077 
0078   /// Get the upper 32 bits from cluster keys
0079   uint32_t getHitSetKeyFromClusKey(const TrkrDefs::cluskey key);
0080 
0081   /// Get a valid low / hi range for hitsetkey given tracker id & layer
0082   TrkrDefs::hitsetkey getHitSetKeyLo(const TrkrDefs::TrkrId trkrId);
0083   TrkrDefs::hitsetkey getHitSetKeyHi(const TrkrDefs::TrkrId trkrId);
0084   TrkrDefs::hitsetkey getHitSetKeyLo(const TrkrDefs::TrkrId trkrId, const uint8_t lyr);
0085   TrkrDefs::hitsetkey getHitSetKeyHi(const TrkrDefs::TrkrId trkrId, const uint8_t lyr);
0086 
0087   /// Get a valid low / hi range for cluskey given tracker id & layer
0088   TrkrDefs::cluskey getClusKeyLo(const TrkrDefs::TrkrId trkrId);
0089   TrkrDefs::cluskey getClusKeyHi(const TrkrDefs::TrkrId trkrId);
0090   TrkrDefs::cluskey getClusKeyLo(const TrkrDefs::TrkrId trkrId, const uint8_t lyr);
0091   TrkrDefs::cluskey getClusKeyHi(const TrkrDefs::TrkrId trkrId, const uint8_t lyr);
0092 
0093   [[maybe_unused]] static constexpr unsigned int kBitShiftPhiElement = 8;  // sector
0094   [[maybe_unused]] static constexpr unsigned int kBitShiftZElement = 0;    // side
0095 
0096   uint8_t getPhiElement(TrkrDefs::hitsetkey key);  // sector
0097   uint8_t getZElement(TrkrDefs::hitsetkey key);    // side
0098   uint8_t getPhiElement(TrkrDefs::cluskey key);    // sector
0099   uint8_t getZElement(TrkrDefs::cluskey key);      // side
0100 
0101 }  // namespace TrkrDefs
0102 
0103 #endif  // TRACKBASE_TRKRDEFS_H