Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-31 23:51:07

0001 #ifndef DataFormats_CSCDigi_CSCCLCTDigi_h
0002 #define DataFormats_CSCDigi_CSCCLCTDigi_h
0003 
0004 /**\class CSCCLCTDigi
0005  *
0006  * Digi for CLCT trigger primitives.
0007  *
0008  *
0009  * \author N. Terentiev, CMU
0010  */
0011 
0012 #include <cstdint>
0013 #include <iosfwd>
0014 #include <vector>
0015 #include <limits>
0016 
0017 class CSCCLCTDigi {
0018 public:
0019   typedef std::vector<std::vector<uint16_t>> ComparatorContainer;
0020 
0021   enum class Version { Legacy = 0, Run3 };
0022   // for data vs emulator studies
0023   enum CLCTBXMask { kBXDataMask = 0x3 };
0024 
0025   /// Constructors
0026   CSCCLCTDigi(const uint16_t valid,
0027               const uint16_t quality,
0028               const uint16_t pattern,
0029               const uint16_t striptype,
0030               const uint16_t bend,
0031               const uint16_t strip,
0032               const uint16_t cfeb,
0033               const uint16_t bx,
0034               const uint16_t trknmb = 0,
0035               const uint16_t fullbx = 0,
0036               const int16_t compCode = -1,
0037               const Version version = Version::Legacy,
0038               const bool run3_quart_strip_bit = false,
0039               const bool run3_eighth_strip_bit = false,
0040               const uint16_t run3_pattern = 0,
0041               const uint16_t run3_slope = 0);
0042 
0043   /// default (calls clear())
0044   CSCCLCTDigi();
0045 
0046   /// clear this CLCT
0047   void clear();
0048 
0049   /// check CLCT validity (1 - valid CLCT)
0050   bool isValid() const { return valid_; }
0051 
0052   /// set valid
0053   void setValid(const uint16_t valid) { valid_ = valid; }
0054 
0055   /// return quality of a pattern (number of layers hit!)
0056   uint16_t getQuality() const { return quality_; }
0057 
0058   /// set quality
0059   void setQuality(const uint16_t quality) { quality_ = quality; }
0060 
0061   /// return pattern
0062   uint16_t getPattern() const { return pattern_; }
0063 
0064   /// set pattern
0065   void setPattern(const uint16_t pattern) { pattern_ = pattern; }
0066 
0067   /// return pattern
0068   uint16_t getRun3Pattern() const { return run3_pattern_; }
0069 
0070   /// set pattern
0071   void setRun3Pattern(const uint16_t pattern) { run3_pattern_ = pattern; }
0072 
0073   /// return the slope
0074   uint16_t getSlope() const { return run3_slope_; }
0075 
0076   /// set the slope
0077   void setSlope(const uint16_t slope) { run3_slope_ = slope; }
0078 
0079   /// slope in number of half-strips/layer
0080   /// negative means left-bending
0081   /// positive means right-bending
0082   float getFractionalSlope() const;
0083 
0084   /// return striptype
0085   uint16_t getStripType() const { return striptype_; }
0086 
0087   /// set stripType
0088   void setStripType(const uint16_t stripType) { striptype_ = stripType; }
0089 
0090   /// return bending
0091   /// 0: left-bending (negative delta-strip / delta layer)
0092   /// 1: right-bending (positive delta-strip / delta layer)
0093   uint16_t getBend() const { return bend_; }
0094 
0095   /// set bend
0096   void setBend(const uint16_t bend) { bend_ = bend; }
0097 
0098   /// return halfstrip that goes from 0 to 31 in a (D)CFEB
0099   uint16_t getStrip() const { return strip_; }
0100 
0101   /// set strip
0102   void setStrip(const uint16_t strip) { strip_ = strip; }
0103 
0104   /// set single quart strip bit
0105   void setQuartStripBit(const bool quartStripBit) { run3_quart_strip_bit_ = quartStripBit; }
0106 
0107   /// get single quart strip bit
0108   bool getQuartStripBit() const { return run3_quart_strip_bit_; }
0109 
0110   /// set single eighth strip bit
0111   void setEighthStripBit(const bool eighthStripBit) { run3_eighth_strip_bit_ = eighthStripBit; }
0112 
0113   /// get single eighth strip bit
0114   bool getEighthStripBit() const { return run3_eighth_strip_bit_; }
0115 
0116   /// return Key CFEB ID
0117   uint16_t getCFEB() const { return cfeb_; }
0118 
0119   /// set Key CFEB ID
0120   void setCFEB(const uint16_t cfeb) { cfeb_ = cfeb; }
0121 
0122   /// return BX
0123   uint16_t getBX() const { return bx_; }
0124 
0125   /// return 2-bit BX as in data
0126   uint16_t getBXData() const { return bx_ & kBXDataMask; }
0127 
0128   /// set bx
0129   void setBX(const uint16_t bx) { bx_ = bx; }
0130 
0131   /// return track number (1,2)
0132   uint16_t getTrknmb() const { return trknmb_; }
0133 
0134   /// Convert strip_ and cfeb_ to keyStrip. Each CFEB has up to 16 strips
0135   /// (32 halfstrips). There are 5 cfebs.  The "strip_" variable is one
0136   /// of 32 halfstrips on the keylayer of a single CFEB, so that
0137   /// Halfstrip = (cfeb*32 + strip).
0138   /// This function can also return the quartstrip or eighthstrip
0139   /// when the comparator code has been set
0140   uint16_t getKeyStrip(const uint16_t n = 2) const;
0141 
0142   /*
0143     Strips are numbered starting from 1 in CMSSW
0144     Half-strips, quarter-strips and eighth-strips are numbered starting from 0
0145     The table below shows the correct numbering
0146     ---------------------------------------------------------------------------------
0147     strip     |               1               |                 2                   |
0148     ---------------------------------------------------------------------------------
0149     1/2-strip |       0       |       1       |       2         |         3         |
0150     ---------------------------------------------------------------------------------
0151     1/4-strip |   0   |   1   |   2   |   3   |   4   |    5    |    6    |    7    |
0152     ---------------------------------------------------------------------------------
0153     1/8-strip | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
0154     ---------------------------------------------------------------------------------
0155 
0156     Note: the CSC geometry also has a strip offset of +/- 0.25 strips. When comparing the
0157     CLCT/LCT position with the true muon position, take the offset into account!
0158    */
0159   float getFractionalStrip(const uint16_t n = 2) const;
0160 
0161   /// Set track number (1,2) after sorting CLCTs.
0162   void setTrknmb(const uint16_t number) { trknmb_ = number; }
0163 
0164   /// return 12-bit full BX.
0165   uint16_t getFullBX() const { return fullbx_; }
0166 
0167   /// Set 12-bit full BX.
0168   void setFullBX(const uint16_t fullbx) { fullbx_ = fullbx; }
0169 
0170   // 12-bit comparator code
0171   int16_t getCompCode() const { return (isRun3() ? compCode_ : -1); }
0172 
0173   void setCompCode(const int16_t code) { compCode_ = code; }
0174 
0175   // comparator hits in this CLCT
0176   const ComparatorContainer& getHits() const { return hits_.empty() ? emptyContainer() : hits_; }
0177 
0178   void setHits(const ComparatorContainer& hits) { hits_ = hits; }
0179 
0180   /// True if the left-hand side has a larger "quality".  Full definition
0181   /// of "quality" depends on quality word itself, pattern type, and strip
0182   /// number.
0183   bool operator>(const CSCCLCTDigi&) const;
0184 
0185   /// True if the two LCTs have exactly the same members (except the number).
0186   bool operator==(const CSCCLCTDigi&) const;
0187 
0188   /// True if the preceding one is false.
0189   bool operator!=(const CSCCLCTDigi&) const;
0190 
0191   /// Print content of digi.
0192   void print() const;
0193 
0194   /// Distinguish Run-1/2 from Run-3
0195   bool isRun3() const { return version_ == Version::Run3; }
0196 
0197   void setRun3(bool isRun3);
0198 
0199 private:
0200   static const ComparatorContainer& emptyContainer();
0201   uint16_t valid_;
0202   uint16_t quality_;
0203   // Run-1/2 pattern number.
0204   // For Run-3 CLCTs, please use run3_pattern_. For some backward
0205   // compatibility the trigger emulator translates run3_pattern_
0206   // approximately into pattern_ with a lookup table
0207   uint16_t pattern_;
0208   uint16_t striptype_;  // not used since mid-2008
0209   // Common definition for left/right bending in Run-1, Run-2 and Run-3.
0210   // 0: right; 1: left
0211   uint16_t bend_;
0212   // actually the half-strip number
0213   uint16_t strip_;
0214   // There are up to 7 (D)CFEBs in a chamber
0215   uint16_t cfeb_;
0216   uint16_t bx_;
0217   uint16_t trknmb_;
0218   uint16_t fullbx_;
0219 
0220   // new members in Run-3:
0221 
0222   // 12-bit comparator code
0223   // set by default to -1 for Run-1 and Run-2 CLCTs
0224   int16_t compCode_;
0225   // 1/4-strip bit set by CCLUT (see DN-19-059)
0226   bool run3_quart_strip_bit_;
0227   // 1/8-strip bit set by CCLUT
0228   bool run3_eighth_strip_bit_;
0229   // In Run-3, the CLCT digi has 3-bit pattern ID, 0 through 4
0230   uint16_t run3_pattern_;
0231   // 4-bit bending value. There will be 16 bending values * 2 (left/right)
0232   uint16_t run3_slope_;
0233 
0234   // which hits are in this CLCT?
0235   ComparatorContainer hits_;
0236   Version version_;
0237 };
0238 
0239 std::ostream& operator<<(std::ostream& o, const CSCCLCTDigi& digi);
0240 
0241 #endif