CMS 3D CMS Logo

SectorProcessorLUT.cc
Go to the documentation of this file.
2 
3 #include <cassert>
4 #include <iostream>
5 #include <fstream>
6 
9 
10 
12  version_(0xFFFFFFFF)
13 {
14 
15 }
16 
18 
19 }
20 
21 void SectorProcessorLUT::read(unsigned pc_lut_version) {
22  if (version_ == pc_lut_version) return;
23 
24  std::string coord_lut_dir = "";
25  if (pc_lut_version == 0)
26  coord_lut_dir = "ph_lut_v1"; // All year 2016
27  else if (pc_lut_version == 1)
28  coord_lut_dir = "ph_lut_v2"; // Beginning of 2017
29  else
30  throw cms::Exception("SectorProcessorLUT")
31  << "Trying to use EMTF pc_lut_version = " << pc_lut_version << ", does not exist!";
32  // Will catch user trying to run with Global Tag settings on 2016 data, rather than fakeEmtfParams. - AWB 08.06.17
33 
34  std::string coord_lut_path = "L1Trigger/L1TMuon/data/emtf_luts/" + coord_lut_dir + "/";
35 
36  // std::cout << "coord_lut_path = " << coord_lut_path << std::endl;
37 
38  read_file(coord_lut_path+"ph_init_neighbor.txt", ph_init_neighbor_);
39  read_file(coord_lut_path+"ph_disp_neighbor.txt", ph_disp_neighbor_);
40  read_file(coord_lut_path+"th_init_neighbor.txt", th_init_neighbor_);
41  read_file(coord_lut_path+"th_disp_neighbor.txt", th_disp_neighbor_);
42  read_file(coord_lut_path+"th_lut_neighbor.txt", th_lut_neighbor_);
43  read_file(coord_lut_path+"th_corr_lut_neighbor.txt", th_corr_lut_neighbor_);
44 
45  if (ph_init_neighbor_.size() != 2*6*61) { // [endcap_2][sector_6][chamber_61]
46  throw cms::Exception("SectorProcessorLUT")
47  << "Expected ph_init_neighbor_ to get " << 2*6*61 << " values, "
48  << "got " << ph_init_neighbor_.size() << " values.";
49  }
50 
51  if (ph_disp_neighbor_.size() != 2*6*61) { // [endcap_2][sector_6][chamber_61]
52  throw cms::Exception("SectorProcessorLUT")
53  << "Expected ph_disp_neighbor_ to get " << 2*6*61 << " values, "
54  << "got " << ph_disp_neighbor_.size() << " values.";
55  }
56 
57  if (th_init_neighbor_.size() != 2*6*61) { // [endcap_2][sector_6][chamber_61]
58  throw cms::Exception("SectorProcessorLUT")
59  << "Expected th_init_neighbor_ to get " << 2*6*61 << " values, "
60  << "got " << th_init_neighbor_.size() << " values.";
61  }
62 
63  if (th_disp_neighbor_.size() != 2*6*61) { // [endcap_2][sector_6][chamber_61]
64  throw cms::Exception("SectorProcessorLUT")
65  << "Expected th_disp_neighbor_ to get " << 2*6*61 << " values, "
66  << "got " << th_disp_neighbor_.size() << " values.";
67  }
68 
69  if (th_lut_neighbor_.size() != 2*6*61*128) { // [endcap_2][sector_6][chamber_61][wire_128]
70  throw cms::Exception("SectorProcessorLUT")
71  << "Expected th_lut_neighbor_ to get " << 2*6*61*128 << " values, "
72  << "got " << th_lut_neighbor_.size() << " values.";
73  }
74 
75  if (th_corr_lut_neighbor_.size() != 2*6*7*128) { // [endcap_2][sector_6][chamber_61][strip_wire_128]
76  throw cms::Exception("SectorProcessorLUT")
77  << "Expected th_corr_lut_neighbor_ to get " << 2*6*7*128 << " values, "
78  << "got " << th_corr_lut_neighbor_.size() << " values.";
79  }
80 
81  // clct pattern convertion array from CMSSW
82  //{0.0, 0.0, -0.60, 0.60, -0.64, 0.64, -0.23, 0.23, -0.21, 0.21, 0.0}
83  // 0 0 -5 +5 -5 +5 -2 +2 -2 +2 0
84  ph_patt_corr_ = {
85  0, 0, 5, 5, 5, 5, 2, 2, 2, 2, 0
86  };
87  if (ph_patt_corr_.size() != 11) {
88  throw cms::Exception("SectorProcessorLUT")
89  << "Expected ph_patt_corr_ to get " << 11 << " values, "
90  << "got " << ph_patt_corr_.size() << " values.";
91  }
92 
94  0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0
95  };
96  if (ph_patt_corr_sign_.size() != 11) {
97  throw cms::Exception("SectorProcessorLUT")
98  << "Expected ph_patt_corr_sign_ to get " << 11 << " values, "
99  << "got " << ph_patt_corr_sign_.size() << " values.";
100  }
101 
102  ph_zone_offset_ = {
103  39,57,76,39,58,76,41,60,79,
104  95,114,132,95,114,133,98,116,135,
105  38,76,113,39,58,76,95,114,132,
106  38,76,113,39,58,76,95,114,132,
107  38,76,113,38,57,76,95,113,132,
108  21,21,23,1,21,1,21,1,20
109  };
110  if (ph_zone_offset_.size() != 6*9) {
111  throw cms::Exception("SectorProcessorLUT")
112  << "Expected ph_zone_offset_ to get " << 6*9 << " values, "
113  << "got " << ph_zone_offset_.size() << " values.";
114  }
115 
116  // start phi of each chamber in reduced precision, for zone hits,
117  // with negative offset to allow for possible chamber movement
118  ph_init_hard_ = {
119  39, 57, 76, 39, 58, 76, 41, 60, 79, 39, 57, 76, 21, 21, 23, 21,
120  95, 114, 132, 95, 114, 133, 98, 116, 135, 95, 114, 132, 0, 0, 0, 0,
121  38, 76, 113, 39, 58, 76, 95, 114, 132, 1, 21, 0, 0, 0, 0, 0,
122  38, 76, 113, 39, 58, 76, 95, 114, 132, 1, 21, 0, 0, 0, 0, 0,
123  38, 76, 113, 38, 57, 76, 95, 113, 132, 1, 20, 0, 0, 0, 0, 0
124  };
125  if (ph_init_hard_.size() != 5*16) {
126  throw cms::Exception("SectorProcessorLUT")
127  << "Expected ph_init_hard_ to get " << 5*16 << " values, "
128  << "got " << ph_init_hard_.size() << " values.";
129  }
130 
131  version_ = pc_lut_version;
132  return;
133 }
134 
135 uint32_t SectorProcessorLUT::get_ph_init(int fw_endcap, int fw_sector, int pc_lut_id) const {
136  size_t index = (fw_endcap * 6 + fw_sector) * 61 + pc_lut_id;
137  return ph_init_neighbor_.at(index);
138 }
139 
140 uint32_t SectorProcessorLUT::get_ph_disp(int fw_endcap, int fw_sector, int pc_lut_id) const {
141  size_t index = (fw_endcap * 6 + fw_sector) * 61 + pc_lut_id;
142  return ph_disp_neighbor_.at(index);
143 }
144 
145 uint32_t SectorProcessorLUT::get_th_init(int fw_endcap, int fw_sector, int pc_lut_id) const {
146  size_t index = (fw_endcap * 6 + fw_sector) * 61 + pc_lut_id;
147  return th_init_neighbor_.at(index);
148 }
149 
150 uint32_t SectorProcessorLUT::get_th_disp(int fw_endcap, int fw_sector, int pc_lut_id) const {
151  size_t index = (fw_endcap * 6 + fw_sector) * 61 + pc_lut_id;
152  return th_disp_neighbor_.at(index);
153 }
154 
155 uint32_t SectorProcessorLUT::get_th_lut(int fw_endcap, int fw_sector, int pc_lut_id, int pc_wire_id) const {
156  int pc_lut_id2 = pc_lut_id;
157 
158  // Make ME1/1a the same as ME1/1b
159  if ((9 <= pc_lut_id2 && pc_lut_id2 < 12) || (25 <= pc_lut_id2 && pc_lut_id2 < 28))
160  pc_lut_id2 -= 9;
161  // Make ME1/1a neighbor the same as ME1/1b
162  if (pc_lut_id2 == 15)
163  pc_lut_id2 -= 3;
164 
165  size_t index = ((fw_endcap * 6 + fw_sector) * 61 + pc_lut_id2) * 128 + pc_wire_id;
166  return th_lut_neighbor_.at(index);
167 }
168 
169 uint32_t SectorProcessorLUT::get_th_corr_lut(int fw_endcap, int fw_sector, int pc_lut_id, int pc_wire_strip_id) const {
170  int pc_lut_id2 = pc_lut_id;
171 
172  // Make ME1/1a the same as ME1/1b
173  if ((9 <= pc_lut_id2 && pc_lut_id2 < 12) || (25 <= pc_lut_id2 && pc_lut_id2 < 28))
174  pc_lut_id2 -= 9;
175  // Make ME1/1a neighbor the same as ME1/1b
176  if (pc_lut_id2 == 15)
177  pc_lut_id2 -= 3;
178 
179  if (pc_lut_id2 <= 3) {
180  pc_lut_id2 -= 0;
181  } else if (pc_lut_id2 == 12) {
182  pc_lut_id2 -= 9;
183  } else if (16 <= pc_lut_id2 && pc_lut_id2 < 19) {
184  pc_lut_id2 -= 12;
185  } else {
186  throw cms::Exception("SectorProcessorLUT")
187  << "get_th_corr_lut(): out of range pc_lut_id: " << pc_lut_id;
188  }
189 
190  size_t index = ((fw_endcap * 6 + fw_sector) * 7 + pc_lut_id2) * 128 + pc_wire_strip_id;
191  return th_corr_lut_neighbor_.at(index);
192 }
193 
195  return ph_patt_corr_.at(pattern);
196 }
197 
199  return ph_patt_corr_sign_.at(pattern);
200 }
201 
202 uint32_t SectorProcessorLUT::get_ph_zone_offset(int pc_station, int pc_chamber) const {
203  size_t index = pc_station * 9 + pc_chamber;
204  return ph_zone_offset_.at(index);
205 }
206 
207 uint32_t SectorProcessorLUT::get_ph_init_hard(int fw_station, int fw_cscid) const {
208  size_t index = fw_station * 16 + fw_cscid;
209  return ph_init_hard_.at(index);
210 }
211 
212 void SectorProcessorLUT::read_file(const std::string& filename, std::vector<uint32_t>& vec) {
213  vec.clear();
214 
215  std::ifstream infile;
216  infile.open(edm::FileInPath(filename).fullPath().c_str());
217 
218  int buf;
219  while (infile >> buf) {
220  buf = (buf == -999) ? 0 : buf;
221  vec.push_back(buf);
222  }
223  infile.close();
224 }
std::vector< uint32_t > ph_zone_offset_
std::vector< uint32_t > th_corr_lut_neighbor_
uint32_t get_ph_patt_corr_sign(int pattern) const
void read(unsigned pc_lut_version)
std::vector< uint32_t > th_disp_neighbor_
uint32_t get_th_init(int fw_endcap, int fw_sector, int pc_lut_id) const
std::vector< uint32_t > ph_patt_corr_
std::vector< uint32_t > ph_init_hard_
uint32_t get_th_disp(int fw_endcap, int fw_sector, int pc_lut_id) const
uint32_t get_ph_disp(int fw_endcap, int fw_sector, int pc_lut_id) const
std::vector< uint32_t > ph_patt_corr_sign_
std::vector< uint32_t > th_init_neighbor_
uint32_t get_ph_zone_offset(int pc_station, int pc_chamber) const
std::vector< uint32_t > ph_disp_neighbor_
uint32_t get_ph_patt_corr(int pattern) const
uint32_t get_th_lut(int fw_endcap, int fw_sector, int pc_lut_id, int pc_wire_id) const
std::vector< uint32_t > ph_init_neighbor_
uint32_t get_ph_init_hard(int fw_station, int fw_cscid) const
void read_file(const std::string &filename, std::vector< uint32_t > &vec)
uint32_t get_ph_init(int fw_endcap, int fw_sector, int pc_lut_id) const
uint32_t get_th_corr_lut(int fw_endcap, int fw_sector, int pc_lut_id, int pc_wire_strip_id) const
std::vector< uint32_t > th_lut_neighbor_