Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-03-08 03:04:01

0001 #ifndef DataFormats_BTLDetId_BTLDetId_h
0002 #define DataFormats_BTLDetId_BTLDetId_h
0003 
0004 #include "DataFormats/ForwardDetId/interface/MTDDetId.h"
0005 #include <iostream>
0006 #include <ostream>
0007 #include <array>
0008 #include <bitset>
0009 
0010 /** 
0011   @class BTLDetId
0012   @brief Detector identifier class for the Barrel Timing Layer.
0013   The crystal count must start from 0, copy number must be scaled by 1 unit.
0014 
0015   // Geometry v2,v3 BTLDetID
0016   bit 15-10: module sequential number
0017   bit 9-8  : crystal type (1 - 3)
0018   bit 7-6  : readout unit sequential number within a type ( 1 - 2 )
0019   bit 5-0  : crystal sequential number within a module ( 0 - 15 )
0020 
0021   // Geometry v2 new DetID (all type 1 modules)
0022   bit 15: kBTLNewFormat (0 - old BTLDetID, 1 - new BTLDetID)
0023   bit 12-10: Readout unit number ( 1 - 6 )
0024   bit 9-6  : Detector Module ( 1 - 12 )
0025   bit  5   : Sensor Module inside DM ( 0 - 1 )
0026   bit 4-0  : Crystal number in a SM ( 1 - 16 )
0027 */
0028 
0029 class BTLDetId : public MTDDetId {
0030 public:
0031   // old BTLDetID
0032   static constexpr uint32_t kBTLoldModuleOffset = 10;
0033   static constexpr uint32_t kBTLoldModuleMask = 0x3F;
0034   static constexpr uint32_t kBTLoldModTypeOffset = 8;
0035   static constexpr uint32_t kBTLoldModTypeMask = 0x3;
0036   static constexpr uint32_t kBTLoldRUOffset = 6;
0037   static constexpr uint32_t kBTLoldRUMask = 0x3;
0038   static constexpr uint32_t kBTLoldCrystalOffset = 0;
0039   static constexpr uint32_t kBTLoldCrystalMask = 0x3F;
0040 
0041   // New BTLDetID
0042   static constexpr uint32_t kBTLRodOffset = 16;
0043   static constexpr uint32_t kBTLRodMask = 0x3F;
0044   static constexpr uint32_t kBTLRUOffset = 10;
0045   static constexpr uint32_t kBTLRUMask = 0x7;
0046   static constexpr uint32_t kBTLdetectorModOffset = 6;
0047   static constexpr uint32_t kBTLdetectorModMask = 0xF;
0048   static constexpr uint32_t kBTLsensorModOffset = 5;
0049   static constexpr uint32_t kBTLsensorModMask = 0x1;
0050   static constexpr uint32_t kBTLCrystalOffset = 0;
0051   static constexpr uint32_t kBTLCrystalMask = 0x1F;
0052 
0053   /// range constants, need two sets for the time being (one for tiles and one for bars)
0054   static constexpr uint32_t HALF_ROD = 36;
0055   static constexpr uint32_t kRUPerTypeV2 = 2;
0056   static constexpr uint32_t kRUPerRod = 6;
0057   static constexpr uint32_t kModulesPerRUV2 = 24;
0058   static constexpr uint32_t kDModulesPerRU = 12;
0059   static constexpr uint32_t kSModulesPerDM = 2;
0060   static constexpr uint32_t kDModulesInRUCol = 3;
0061   static constexpr uint32_t kDModulesInRURow = 4;
0062   static constexpr uint32_t kSModulesInDM = 2;
0063   static constexpr uint32_t kCrystalsPerModuleV2 = 16;
0064   static constexpr uint32_t kModulesPerTrkV2 = 3;
0065   static constexpr uint32_t kCrystalTypes = 3;
0066 
0067   // conversion
0068   static constexpr uint32_t kBTLoldFieldMask = 0x3FFFFF;
0069   static constexpr uint32_t kBTLNewFormat = 1 << 15;
0070 
0071   //
0072 
0073   // Number of crystals in BTL according to TDR design, valid also for barphiflat scenario:
0074   // 16 crystals x 24 modules x 2 readout units/type x 3 types x 36 rods/side x 2 sides
0075   //
0076   static constexpr uint32_t kCrystalsBTL =
0077       kCrystalsPerModuleV2 * kModulesPerRUV2 * kRUPerTypeV2 * kCrystalTypes * HALF_ROD * 2;
0078 
0079   enum class CrysLayout { tile = 1, bar = 2, barzflat = 3, barphiflat = 4, v2 = 5, v3 = 6, v4 = 7 };
0080 
0081   // ---------- Constructors, enumerated types ----------
0082 
0083   /** Construct a null id */
0084   BTLDetId() : MTDDetId(DetId::Forward, ForwardSubdetector::FastTime) {
0085     id_ |= (MTDType::BTL & kMTDsubdMask) << kMTDsubdOffset;
0086   }
0087 
0088   /** Construct from a raw value */
0089   BTLDetId(const uint32_t& raw_id) : MTDDetId(raw_id) { id_ = MTDDetId(raw_id).rawId(); }
0090 
0091   /** Construct from generic DetId */
0092   BTLDetId(const DetId& det_id) : MTDDetId(det_id.rawId()) { id_ = MTDDetId(det_id.rawId()).rawId(); }
0093 
0094   /** Construct from complete geometry information v2, v3 **/
0095   /** Geometry v1 is obsolete and not supported            **/
0096   BTLDetId(uint32_t zside, uint32_t rod, uint32_t runit, uint32_t module, uint32_t modtyp, uint32_t crystal, bool v2v3)
0097       : MTDDetId(DetId::Forward, ForwardSubdetector::FastTime) {
0098     id_ |= (MTDType::BTL & kMTDsubdMask) << kMTDsubdOffset | (zside & kZsideMask) << kZsideOffset |
0099            (rod & kRodRingMask) << kRodRingOffset | (module & kBTLoldModuleMask) << kBTLoldModuleOffset |
0100            (modtyp & kBTLoldModTypeMask) << kBTLoldModTypeOffset | (runit & kBTLoldRUMask) << kBTLoldRUOffset |
0101            ((crystal - 1) & kBTLoldCrystalMask) << kBTLoldCrystalOffset;
0102   }
0103 
0104   /** Construct from complete geometry information v4 **/
0105   BTLDetId(uint32_t zside, uint32_t rod, uint32_t runit, uint32_t dmodule, uint32_t smodule, uint32_t crystal)
0106       : MTDDetId(DetId::Forward, ForwardSubdetector::FastTime) {
0107     //RU, DM, SM & Xtal numbers start from 0
0108     id_ |= (MTDType::BTL & kMTDsubdMask) << kMTDsubdOffset | (zside & kZsideMask) << kZsideOffset |
0109            (rod & kRodRingMask) << kRodRingOffset | (runit & kBTLRUMask) << kBTLRUOffset |
0110            (dmodule & kBTLdetectorModMask) << kBTLdetectorModOffset |
0111            (smodule & kBTLsensorModMask) << kBTLsensorModOffset | (crystal & kBTLCrystalMask) << kBTLCrystalOffset;
0112     id_ |= kBTLNewFormat;
0113   }
0114 
0115   // ---------- Common methods ----------
0116 
0117   /** Returns BTL crystal number. */
0118   inline int crystal() const {
0119     if (id_ & kBTLNewFormat) {
0120       return ((id_ >> kBTLCrystalOffset) & kBTLCrystalMask);
0121     } else {
0122       return ((id_ >> kBTLoldCrystalOffset) & kBTLoldCrystalMask) + 1;
0123     }
0124   }
0125 
0126   /** Returns BTL crystal number in construction database. */
0127   inline int crystalConsDB() const {
0128     if (((id_ >> kBTLCrystalOffset) & kBTLCrystalMask) == kCrystalsPerModuleV2) {
0129       return -1;
0130     }
0131     if (smodule() == 0) {
0132       return kCrystalsPerModuleV2 - 1 - ((id_ >> kBTLCrystalOffset) & kBTLCrystalMask);
0133     } else {
0134       return ((id_ >> kBTLCrystalOffset) & kBTLCrystalMask);
0135     }
0136   }
0137 
0138   /** Returns BTL detector module number. */
0139   inline int dmodule() const {
0140     if (id_ & kBTLNewFormat) {
0141       return ((id_ >> kBTLdetectorModOffset) & kBTLdetectorModMask);
0142     } else {
0143       uint32_t oldModule = (id_ >> kBTLoldModuleOffset) & kBTLoldModuleMask;
0144       uint32_t detModule =
0145           int((oldModule - 1) % (kDModulesInRUCol)) * kDModulesInRURow +
0146           int((oldModule - 1) / (kDModulesInRUCol * kSModulesInDM));  // in old scenario module number starts from 1
0147       return detModule;
0148     }
0149   }
0150 
0151   /** Returns BTL sensor module number. */
0152   inline int smodule() const {
0153     if (id_ & kBTLNewFormat) {
0154       return ((id_ >> kBTLsensorModOffset) & kBTLsensorModMask);
0155     } else {
0156       uint32_t oldModule = (id_ >> kBTLoldModuleOffset) & kBTLoldModuleMask;
0157       uint32_t senModule =
0158           int((oldModule - 1) / kDModulesInRUCol) % kSModulesInDM;  // in old scenario module number starts from 1
0159       return senModule;
0160     }
0161   }
0162 
0163   /** Returns BTL module number [1-24] (OLD BTL NUMBERING). */
0164   inline int module() const {
0165     if (id_ & kBTLNewFormat) {
0166       return ((dmodule() % kDModulesInRURow) * (kSModulesInDM * kDModulesInRUCol) + int(dmodule() / kDModulesInRURow) +
0167               kDModulesInRUCol * smodule()) +
0168              1;
0169     } else {
0170       return (id_ >> kBTLoldModuleOffset) & kBTLoldModuleMask;
0171     }
0172   }
0173 
0174   /** Returns BTL crystal type number [1-3] (OLD BTL NUMBERING). */
0175   inline int modType() const {
0176     if (id_ & kBTLNewFormat) {
0177       return int(runit() / kRUPerTypeV2 + 1);
0178     } else {
0179       return (id_ >> kBTLoldModTypeOffset) & kBTLoldModTypeMask;
0180     }
0181   }
0182 
0183   /** Returns BTL global readout unit number. */
0184   inline int runit() const {
0185     if (id_ & kBTLNewFormat) {
0186       return ((id_ >> kBTLRUOffset) & kBTLRUMask);
0187     } else {
0188       return (modType() - 1) * kRUPerTypeV2 + int((id_ >> kBTLoldRUOffset) & kBTLoldRUMask);
0189     }
0190   }
0191 
0192   /** Returns BTL readout unit number per type [1-2], from Global RU number [1-6]. */
0193   inline int runitByType() const {
0194     if (id_ & kBTLNewFormat) {
0195       return ((runit() % kRUPerTypeV2) + 1);
0196     } else {
0197       return (((runit() - 1) % kRUPerTypeV2) + 1);
0198     }
0199   }
0200 
0201   /** return the row in GeomDet language **/
0202   inline int row(unsigned nrows = kCrystalsPerModuleV2) const {
0203     if (id_ & kBTLNewFormat) {
0204       return crystal() % nrows;
0205     } else {
0206       return (crystal() - 1) % nrows;
0207     }
0208   }
0209 
0210   /** return the column in GeomDetLanguage **/
0211   inline int column(unsigned nrows = kCrystalsPerModuleV2) const {
0212     if (id_ & kBTLNewFormat) {
0213       return crystal() / nrows;
0214     } else {
0215       return (crystal() - 1) / nrows;
0216     }
0217   }
0218 
0219   /** create a Geographical DetId for Tracking **/
0220   BTLDetId geographicalId(CrysLayout lay) const;
0221 };
0222 
0223 std::ostream& operator<<(std::ostream&, const BTLDetId&);
0224 
0225 #endif  // DataFormats_BTLDetId_BTLDetId_h