CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ComparatorCodeLUT.cc
Go to the documentation of this file.
3 
6 }
7 
9 
10 void ComparatorCodeLUT::run(CSCCLCTDigi& digi, unsigned numCFEBs) const {
11  // print out the old CLCT for debugging
12  if (infoV_ > 2) {
13  std::ostringstream strm;
14  strm << "\n";
15  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
16  strm << "+ Before CCCLUT algorithm: +\n";
17  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
18  strm << " Old CLCT digi " << digi << "\n";
19  strm << " 1/4 strip bit " << digi.getQuartStripBit() << " 1/8 strip bit " << digi.getEighthStripBit() << "\n";
20  strm << " 1/4 strip number " << digi.getKeyStrip(4) << " 1/8 strip number " << digi.getKeyStrip(8) << "\n";
21  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
22  LogDebug("ComparatorCodeLUT") << strm.str();
23  }
24 
25  // set Run-3 flag
26  digi.setRun3(true);
27 
28  // Get the comparator hits
29  auto compHits = digi.getHits();
30 
31  // Wrap the comparator code in a format for calculation
32  pattern compHitsCC;
33 
34  for (int i = 0; i < CSCConstants::NUM_LAYERS; i++) {
35  int iCC = 0;
36  for (int j = 0; j < CSCConstants::CLCT_PATTERN_WIDTH; j++) {
37  // only fill when the pattern is active
38  if (clct_pattern_[digi.getPattern()][i][j]) {
39  if (compHits[i][j] != CSCConstants::INVALID_HALF_STRIP) {
40  compHitsCC[i][iCC] = 1;
41  } else {
42  compHitsCC[i][iCC] = 0;
43  }
44  iCC++;
45  }
46  }
47  }
48 
49  // calculate the comparator code
50  const int comparatorCode(calculateComparatorCode(compHitsCC));
51 
52  // store the comparator code
53  digi.setCompCode(comparatorCode);
54 
55  // calculate the slope and position offset
56  const int pattern(digi.getPattern());
57 
58  // set the Run-3 pattern
59  digi.setRun3Pattern(pattern);
60 
61  // look-up the unsigned values
62  const unsigned positionCC(lookupTableCCLUT_->cclutPosition(pattern, comparatorCode));
63  const unsigned slopeCC(lookupTableCCLUT_->cclutSlope(pattern, comparatorCode));
64  const unsigned run2PatternCC(convertSlopeToRun2Pattern(slopeCC));
65 
66  // if the slope is negative, set bending to 0
67  const bool slopeCCSign((slopeCC >> 4) & 0x1);
68  const unsigned slopeCCValue(slopeCC & 0xf);
69  digi.setBend(slopeCCSign);
70 
71  // calculate the new position
72  uint16_t halfstrip = digi.getKeyStrip();
73  std::tuple<int16_t, bool, bool> stripoffset;
74  assignPositionCC(positionCC, stripoffset);
75  const int halfstripoffset = std::get<0>(stripoffset);
76  halfstrip += halfstripoffset;
77 
78  // store the new CFEB, 1/2, 1/4 and 1/8 strip positions
81  digi.setQuartStripBit(std::get<1>(stripoffset));
82  digi.setEighthStripBit(std::get<2>(stripoffset));
83 
84  // store the bending angle value in the pattern data member
85  digi.setSlope(slopeCCValue);
86 
87  // set the quasi Run-2 pattern - to accommodate integration with EMTF/OMTF
88  digi.setPattern(run2PatternCC);
89 
90  // now print out the new CLCT for debugging
91  if (infoV_ > 2) {
92  std::ostringstream strm;
93  strm << "\n";
94  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
95  strm << "+ CCCLUT algorithm results: +\n";
96  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
97  strm << " New CLCT digi " << digi << "\n";
98  strm << " 1/4 strip bit " << digi.getQuartStripBit() << " 1/8 strip bit " << digi.getEighthStripBit() << "\n";
99  strm << " 1/4 strip number " << digi.getKeyStrip(4) << " 1/8 strip number " << digi.getKeyStrip(8) << "\n";
100  strm << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
101  LogDebug("ComparatorCodeLUT") << strm.str();
102  }
103 }
104 
105 int ComparatorCodeLUT::calculateComparatorCode(const pattern& halfStripPattern) const {
106  int id = 0;
107 
108  for (unsigned int column = 0; column < CSCConstants::NUM_LAYERS; column++) {
109  int rowPat = 0; //physical arrangement of the three bits
110  int rowCode = 0; //code used to identify the arrangement
111 
112  //use Firmware definition for comparator code definition
113  for (int row = 2; row >= 0; row--) {
114  rowPat = rowPat << 1; //bitshift the last number to the left
115  rowPat += halfStripPattern[column][row];
116  }
117  switch (rowPat) {
118  case 0: //000
119  rowCode = 0;
120  break;
121  case 1: //00X
122  rowCode = 1;
123  break;
124  case 2: //0X0
125  rowCode = 2;
126  break;
127  case 4: //00X
128  rowCode = 3;
129  break;
130  default:
131  // default return value is -1
132  return -1;
133  }
134  //each column has two bits of information, largest layer is most significant bit
135  id += (rowCode << 2 * column);
136  }
137  return id;
138 }
139 
140 unsigned ComparatorCodeLUT::convertSlopeToRun2Pattern(const unsigned slope) const {
141  const unsigned slopeList[32] = {10, 10, 10, 8, 8, 8, 6, 6, 6, 4, 4, 4, 2, 2, 2, 2,
142  10, 10, 10, 9, 9, 9, 7, 7, 7, 5, 5, 5, 3, 3, 3, 3};
143  return slopeList[slope];
144 }
145 
146 void ComparatorCodeLUT::assignPositionCC(const unsigned offset, std::tuple<int16_t, bool, bool>& returnValue) const {
147  /*
148  | Value | Half-Strip Offset | Delta Half-Strip | Quarter-Strip Bit | Eighth-Strip Bit |
149  |-------|--------------------|-------------------|--------------------|------------------|
150  | 0 | -7/4 | -2 | 0 | 1 |
151  | 1 | -3/2 | -2 | 1 | 0 |
152  | 2 | -5/4 | -2 | 1 | 1 |
153  | 3 | -1 | -1 | 0 | 0 |
154  | 4 | -3/4 | -1 | 0 | 1 |
155  | 5 | -1/2 | -1 | 1 | 0 |
156  | 6 | -1/4 | -1 | 1 | 1 |
157  | 7 | 0 | 0 | 0 | 0 |
158  | 8 | 1/4 | 0 | 0 | 1 |
159  | 9 | 1/2 | 0 | 1 | 0 |
160  | 10 | 3/4 | 0 | 1 | 1 |
161  | 11 | 1 | 1 | 0 | 0 |
162  | 12 | 5/4 | 1 | 0 | 1 |
163  | 13 | 3/2 | 1 | 1 | 0 |
164  | 14 | 7/4 | 1 | 1 | 1 |
165  | 15 | 2 | 2 | 0 | 0 |
166  */
167  std::vector<std::tuple<int16_t, bool, bool>> my_tuple = {
168  {-2, false, true},
169  {-2, true, false},
170  {-2, true, true},
171  {-1, false, false},
172  {-1, false, true},
173  {-1, true, false},
174  {-1, true, true},
175  {0, false, false},
176  {0, false, true},
177  {0, true, false},
178  {0, true, true},
179  {1, false, false},
180  {1, false, true},
181  {1, true, false},
182  {1, true, true},
183  {2, false, false},
184  };
185  returnValue = my_tuple[offset];
186 }
void setQuartStripBit(const bool quartStripBit)
set single quart strip bit
Definition: CSCCLCTDigi.h:105
uint16_t *__restrict__ id
unsigned cclutPosition(unsigned pattern, unsigned code) const
std::array< std::array< int, 3 >, CSCConstants::NUM_LAYERS > pattern
void setBend(const uint16_t bend)
set bend
Definition: CSCCLCTDigi.h:96
static const double slope[3]
void setStrip(const uint16_t strip)
set strip
Definition: CSCCLCTDigi.h:102
void setPattern(const uint16_t pattern)
set pattern
Definition: CSCCLCTDigi.h:65
CSCPatternBank::LCTPatterns clct_pattern_
void run(CSCCLCTDigi &digi, unsigned numCFEBs) const
uint16_t getKeyStrip(const uint16_t n=2) const
Definition: CSCCLCTDigi.cc:107
static const LCTPatterns clct_pattern_run3_
void setCompCode(const int16_t code)
Definition: CSCCLCTDigi.h:173
void setRun3(bool isRun3)
Definition: CSCCLCTDigi.cc:133
void setSlope(const uint16_t slope)
set the slope
Definition: CSCCLCTDigi.h:77
void setRun3Pattern(const uint16_t pattern)
set pattern
Definition: CSCCLCTDigi.h:71
ComparatorCodeLUT(const edm::ParameterSet &conf)
int calculateComparatorCode(const pattern &halfStripPattern) const
const ComparatorContainer & getHits() const
Definition: CSCCLCTDigi.h:176
uint16_t getPattern() const
return pattern
Definition: CSCCLCTDigi.h:62
unsigned cclutSlope(unsigned pattern, unsigned code) const
void setCFEB(const uint16_t cfeb)
set Key CFEB ID
Definition: CSCCLCTDigi.h:120
void setEighthStripBit(const bool eighthStripBit)
set single eighth strip bit
Definition: CSCCLCTDigi.h:111
unsigned convertSlopeToRun2Pattern(const unsigned slope) const
void setESLookupTables(const CSCL1TPLookupTableCCLUT *conf)
bool getQuartStripBit() const
get single quart strip bit
Definition: CSCCLCTDigi.h:108
#define LogDebug(id)
void assignPositionCC(const unsigned offset, std::tuple< int16_t, bool, bool > &returnValue) const
const CSCL1TPLookupTableCCLUT * lookupTableCCLUT_