CMS 3D CMS Logo

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