Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:28

0001 #ifndef DataFormats_Phase2TrackerDigi_Phase2TrackerDigi_H
0002 #define DataFormats_Phase2TrackerDigi_Phase2TrackerDigi_H
0003 
0004 #include <cstdint>
0005 #include <utility>
0006 #include <cassert>
0007 
0008 /**
0009  * Persistent digi for the Phase 2 tracker 
0010  */
0011 
0012 class Phase2TrackerDigi {
0013 public:
0014   typedef uint16_t PackedDigiType;
0015 
0016   Phase2TrackerDigi(unsigned int packed_channel) : theChannel(packed_channel) {}
0017 
0018   Phase2TrackerDigi(unsigned int row, unsigned int col) { theChannel = pixelToChannel(row, col); }
0019 
0020   Phase2TrackerDigi(unsigned int row, unsigned int col, bool ot_flag) {
0021     theChannel = pixelToChannel(row, col);
0022     if (ot_flag)
0023       theChannel |= (1 << 15);
0024   }
0025 
0026   Phase2TrackerDigi() : theChannel(0) {}
0027 
0028   // Access to digi information - pixel sensors
0029   unsigned int row() const { return channelToRow(theChannel); }
0030   unsigned int column() const { return channelToColumn(theChannel); }
0031   // Access to digi information - strip sensors
0032   unsigned int strip() const { return row(); }
0033   unsigned int edge() const { return column(); }  // CD: any better name for that?
0034   // Access to the (raw) channel number
0035   unsigned int channel() const { return 0x7FFF & theChannel; }
0036   // Access Overthreshold bit
0037   bool overThreshold() const { return (otBit(theChannel) ? true : false); }
0038 
0039   static std::pair<unsigned int, unsigned int> channelToPixel(unsigned int ch) {
0040     return std::pair<unsigned int, unsigned int>(channelToRow(ch), channelToColumn(ch));
0041   }
0042 
0043   static PackedDigiType pixelToChannel(unsigned int row, unsigned int col) {
0044     assert(row < 1016);
0045     assert(col < 32);
0046     return row | (col << 10);
0047   }
0048 
0049 private:
0050   PackedDigiType theChannel;
0051   static unsigned int channelToRow(unsigned int ch) { return ch & 0x03FF; }
0052   static unsigned int channelToColumn(unsigned int ch) { return ((ch >> 10) & 0x1F); }
0053   static unsigned int otBit(unsigned int ch) { return ((ch >> 15) & 0x1); }
0054 };
0055 
0056 // Comparison operators
0057 inline bool operator<(const Phase2TrackerDigi& one, const Phase2TrackerDigi& other) {
0058   return one.channel() < other.channel();
0059 }
0060 
0061 // distance operators
0062 inline int operator-(const Phase2TrackerDigi& one, const Phase2TrackerDigi& other) {
0063   return int(one.channel()) - int(other.channel());
0064 }
0065 
0066 #include <iostream>
0067 inline std::ostream& operator<<(std::ostream& o, const Phase2TrackerDigi& digi) { return o << " " << digi.channel(); }
0068 
0069 #endif  // DataFormats_Phase2TrackerDigi_Phase2TrackerDigi_H