Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-07-12 02:58:07

0001 #ifndef DataFormats_ETLDetId_ETLDetId_h
0002 #define DataFormats_ETLDetId_ETLDetId_h
0003 
0004 #include "DataFormats/ForwardDetId/interface/MTDDetId.h"
0005 #include <ostream>
0006 
0007 /** 
0008     @class ETLDetId
0009     @brief Detector identifier class for the Endcap Timing Layer.
0010 
0011     bit 15-5 : module sequential number
0012     bit 4-3  : module type (unused so far)
0013 */
0014 
0015 class ETLDetId : public MTDDetId {
0016 private:
0017   // for conversion from old to new module bit field
0018   static constexpr uint32_t kETLoldToNewShift = 2;
0019   static constexpr uint32_t kETLoldFieldMask = 0x7FFF;
0020   static constexpr uint32_t kETLformatV2 = 1;
0021 
0022 public:
0023   static constexpr uint32_t kETLmoduleOffset = 5;
0024   static constexpr uint32_t kETLmoduleMask = 0x7FF;
0025   static constexpr uint32_t kETLmodTypeOffset = 3;
0026   static constexpr uint32_t kETLmodTypeMask = 0x3;
0027 
0028   static constexpr int kETLv1maxRing = 11;
0029   static constexpr int kETLv1maxModule = 176;
0030   static constexpr int kETLv1nDisc = 1;
0031 
0032   /// constants for the TDR ETL model
0033   static constexpr uint32_t kETLnDiscOffset = 3;
0034   static constexpr uint32_t kETLnDiscMask = 0x1;
0035   static constexpr uint32_t kETLdiscSideOffset = 2;
0036   static constexpr uint32_t kETLdiscSideMask = 0x1;
0037   static constexpr uint32_t kETLsectorMask = 0x3;
0038 
0039   static constexpr int kETLv4maxRing = 16;
0040   static constexpr int kETLv4maxSector = 4;
0041   static constexpr int kETLv4maxModule = 248;
0042   static constexpr int kETLv4nDisc = 2;
0043 
0044   static constexpr int kETLv5maxRing = 14;
0045   static constexpr int kETLv5maxSector = 2;
0046   static constexpr int kETLv5maxModule = 517;
0047   static constexpr int kETLv5nDisc = kETLv4nDisc;
0048 
0049   static constexpr uint32_t kSoff = 4;
0050 
0051   enum class EtlLayout { tp = 1, v4 = 2, v5 = 3 };
0052 
0053   // ---------- Constructors, enumerated types ----------
0054 
0055   /** Construct a null id */
0056   ETLDetId() : MTDDetId(DetId::Forward, ForwardSubdetector::FastTime) {
0057     id_ |= (MTDType::ETL & kMTDsubdMask) << kMTDsubdOffset;
0058     id_ |= kETLformatV2;
0059   }
0060 
0061   /** Construct from a raw value */
0062   ETLDetId(const uint32_t& raw_id) {
0063     uint32_t tmpId = raw_id;
0064     if ((tmpId & kETLformatV2) == 0) {
0065       tmpId = newForm(tmpId);
0066     }
0067     id_ = MTDDetId(tmpId).rawId();
0068   }
0069 
0070   /** Construct from generic DetId */
0071   ETLDetId(const DetId& det_id) {
0072     uint32_t tmpId = det_id.rawId();
0073     if ((tmpId & kETLformatV2) == 0) {
0074       tmpId = newForm(tmpId);
0075     }
0076     id_ = MTDDetId(tmpId).rawId();
0077   }
0078 
0079   /** Construct and fill only the det and sub-det fields. */
0080   ETLDetId(uint32_t zside, uint32_t ring, uint32_t module, uint32_t modtyp)
0081       : MTDDetId(DetId::Forward, ForwardSubdetector::FastTime) {
0082     id_ |= (MTDType::ETL & kMTDsubdMask) << kMTDsubdOffset | (zside & kZsideMask) << kZsideOffset |
0083            (ring & kRodRingMask) << kRodRingOffset | (module & kETLmoduleMask) << kETLmoduleOffset |
0084            (modtyp & kETLmodTypeMask) << kETLmodTypeOffset;
0085     id_ |= kETLformatV2;
0086   }
0087 
0088   /** ETL TDR Construct and fill only the det and sub-det fields. */
0089 
0090   inline uint32_t encodeSector(uint32_t& disc, uint32_t& discside, uint32_t& sector) const {
0091     return (sector + discside * kSoff + 2 * kSoff * disc);
0092   }
0093 
0094   ETLDetId(uint32_t zside, uint32_t disc, uint32_t discside, uint32_t sector, uint32_t module, uint32_t modtyp)
0095       : MTDDetId(DetId::Forward, ForwardSubdetector::FastTime) {
0096     id_ |= (MTDType::ETL & kMTDsubdMask) << kMTDsubdOffset | (zside & kZsideMask) << kZsideOffset |
0097            (encodeSector(disc, discside, sector) & kRodRingMask) << kRodRingOffset |
0098            (module & kETLmoduleMask) << kETLmoduleOffset | (modtyp & kETLmodTypeMask) << kETLmodTypeOffset;
0099     id_ |= kETLformatV2;
0100   }
0101 
0102   // ---------- Common methods ----------
0103 
0104   /** Returns ETL module number. */
0105   inline int module() const { return (id_ >> kETLmoduleOffset) & kETLmoduleMask; }
0106 
0107   /** Returns ETL module type number. */
0108   inline int modType() const { return (id_ >> kETLmodTypeOffset) & kETLmodTypeMask; }
0109 
0110   ETLDetId geographicalId() const { return id_; }
0111 
0112   // --------- Methods for the TDR ETL model only -----------
0113   // meaningless for TP model
0114 
0115   // starting from 1
0116   inline int sector() const { return ((((id_ >> kRodRingOffset) & kRodRingMask) - 1) & kETLsectorMask) + 1; }
0117 
0118   // 0 = front, 1 = back
0119   inline int discSide() const {
0120     return ((((id_ >> kRodRingOffset) & kRodRingMask) - 1) >> kETLdiscSideOffset) & kETLdiscSideMask;
0121   }
0122 
0123   // starting from 1
0124   inline int nDisc() const {
0125     return (((((id_ >> kRodRingOffset) & kRodRingMask) - 1) >> kETLnDiscOffset) & kETLnDiscMask) + 1;
0126   }
0127 
0128   uint32_t newForm(const uint32_t& rawid) {
0129     uint32_t fixedP = rawid & (0xFFFFFFFF - kETLoldFieldMask);          // unchanged part of id
0130     uint32_t shiftP = (rawid & kETLoldFieldMask) >> kETLoldToNewShift;  // shifted part
0131     return ((fixedP | shiftP) | kETLformatV2);
0132   }
0133 };
0134 
0135 std::ostream& operator<<(std::ostream&, const ETLDetId&);
0136 
0137 #endif  // DataFormats_ETLDetId_ETLDetId_h