CMS 3D CMS Logo

CSCL1TPLookupTableEP.cc
Go to the documentation of this file.
1 // system include files
9 
16 
17 // user include files
18 #include <fstream>
19 #include <string>
20 #include <vector>
21 #include <unordered_map>
22 
24 public:
26  ~CSCL1TPLookupTableEP() override {}
27 
28  std::unique_ptr<CSCL1TPLookupTableCCLUT> produceCCLUT(const CSCL1TPLookupTableCCLUTRcd&);
29  std::unique_ptr<CSCL1TPLookupTableME11ILT> produceME11ILT(const CSCL1TPLookupTableME11ILTRcd&);
30  std::unique_ptr<CSCL1TPLookupTableME21ILT> produceME21ILT(const CSCL1TPLookupTableME21ILTRcd&);
31 
32 protected:
34  const edm::IOVSyncValue&,
35  edm::ValidityInterval&) override;
36 
37 private:
38  std::vector<unsigned> load(std::string fileName) const;
40 };
41 
46  findingRecord<CSCL1TPLookupTableCCLUTRcd>();
47  findingRecord<CSCL1TPLookupTableME11ILTRcd>();
48  findingRecord<CSCL1TPLookupTableME21ILTRcd>();
49 }
50 
52  const edm::IOVSyncValue& iosv,
53  edm::ValidityInterval& oValidity) {
55  oValidity = infinity;
56 }
57 
58 std::unique_ptr<CSCL1TPLookupTableCCLUT> CSCL1TPLookupTableEP::produceCCLUT(const CSCL1TPLookupTableCCLUTRcd&) {
59  // make the LUT object
60  std::unique_ptr<CSCL1TPLookupTableCCLUT> lut = std::make_unique<CSCL1TPLookupTableCCLUT>();
61 
62  // get the text files
63  std::vector<std::string> positionLUTFiles_ = pset_.getParameter<std::vector<std::string>>("positionLUTFiles");
64  std::vector<std::string> slopeLUTFiles_ = pset_.getParameter<std::vector<std::string>>("slopeLUTFiles");
65 
66  std::unordered_map<unsigned, std::vector<unsigned>> cclutPosition;
67  std::unordered_map<unsigned, std::vector<unsigned>> cclutSlope;
68 
69  // read the text files and extract the data
70  for (int i = 0; i < 5; ++i) {
71  cclutPosition[i] = load(positionLUTFiles_[i]);
72  cclutSlope[i] = load(slopeLUTFiles_[i]);
73  }
74 
75  // set the data in the LUT object
76  lut->set_cclutPosition(std::move(cclutPosition));
77  lut->set_cclutSlope(std::move(cclutSlope));
78 
79  return lut;
80 }
81 
82 std::unique_ptr<CSCL1TPLookupTableME11ILT> CSCL1TPLookupTableEP::produceME11ILT(const CSCL1TPLookupTableME11ILTRcd&) {
83  // make the LUT object
84  std::unique_ptr<CSCL1TPLookupTableME11ILT> lut = std::make_unique<CSCL1TPLookupTableME11ILT>();
85 
86  // get the text files
87  std::vector<std::string> padToEsME11aFiles_ = pset_.getParameter<std::vector<std::string>>("padToEsME11aFiles");
88  std::vector<std::string> padToEsME11bFiles_ = pset_.getParameter<std::vector<std::string>>("padToEsME11bFiles");
89 
90  std::vector<std::string> rollToMaxWgME11Files_ = pset_.getParameter<std::vector<std::string>>("rollToMaxWgME11Files");
91  std::vector<std::string> rollToMinWgME11Files_ = pset_.getParameter<std::vector<std::string>>("rollToMinWgME11Files");
92 
93  std::vector<std::string> gemCscSlopeCosiFiles_ = pset_.getParameter<std::vector<std::string>>("gemCscSlopeCosiFiles");
94  std::vector<std::string> gemCscSlopeCosiCorrectionFiles_ =
95  pset_.getParameter<std::vector<std::string>>("gemCscSlopeCosiCorrectionFiles");
96  std::vector<std::string> gemCscSlopeCorrectionFiles_ =
97  pset_.getParameter<std::vector<std::string>>("gemCscSlopeCorrectionFiles");
98 
99  std::vector<std::string> esDiffToSlopeME11aFiles_ =
100  pset_.getParameter<std::vector<std::string>>("esDiffToSlopeME11aFiles");
101  std::vector<std::string> esDiffToSlopeME11bFiles_ =
102  pset_.getParameter<std::vector<std::string>>("esDiffToSlopeME11bFiles");
103 
104  // read the text files and extract the data
105  auto GEM_pad_CSC_es_ME11a_even_ = load(padToEsME11aFiles_[0]);
106  auto GEM_pad_CSC_es_ME11a_odd_ = load(padToEsME11aFiles_[1]);
107  auto GEM_pad_CSC_es_ME11b_even_ = load(padToEsME11bFiles_[0]);
108  auto GEM_pad_CSC_es_ME11b_odd_ = load(padToEsME11bFiles_[1]);
109 
110  auto GEM_roll_CSC_min_wg_ME11_even_ = load(rollToMinWgME11Files_[0]);
111  auto GEM_roll_CSC_min_wg_ME11_odd_ = load(rollToMinWgME11Files_[1]);
112  auto GEM_roll_CSC_max_wg_ME11_even_ = load(rollToMaxWgME11Files_[0]);
113  auto GEM_roll_CSC_max_wg_ME11_odd_ = load(rollToMaxWgME11Files_[1]);
114 
115  auto CSC_slope_cosi_2to1_L1_ME11a_even_ = load(gemCscSlopeCosiFiles_[0]);
116  auto CSC_slope_cosi_2to1_L1_ME11a_odd_ = load(gemCscSlopeCosiFiles_[1]);
117  auto CSC_slope_cosi_3to1_L1_ME11a_even_ = load(gemCscSlopeCosiFiles_[2]);
118  auto CSC_slope_cosi_3to1_L1_ME11a_odd_ = load(gemCscSlopeCosiFiles_[3]);
119 
120  auto CSC_slope_cosi_2to1_L1_ME11b_even_ = load(gemCscSlopeCosiFiles_[4]);
121  auto CSC_slope_cosi_2to1_L1_ME11b_odd_ = load(gemCscSlopeCosiFiles_[5]);
122  auto CSC_slope_cosi_3to1_L1_ME11b_even_ = load(gemCscSlopeCosiFiles_[6]);
123  auto CSC_slope_cosi_3to1_L1_ME11b_odd_ = load(gemCscSlopeCosiFiles_[7]);
124 
125  auto CSC_slope_cosi_corr_L1_ME11a_even_ = load(gemCscSlopeCosiCorrectionFiles_[0]);
126  auto CSC_slope_cosi_corr_L1_ME11b_even_ = load(gemCscSlopeCosiCorrectionFiles_[1]);
127  auto CSC_slope_cosi_corr_L1_ME11a_odd_ = load(gemCscSlopeCosiCorrectionFiles_[3]);
128  auto CSC_slope_cosi_corr_L1_ME11b_odd_ = load(gemCscSlopeCosiCorrectionFiles_[4]);
129 
130  auto CSC_slope_corr_L1_ME11a_even_ = load(gemCscSlopeCorrectionFiles_[0]);
131  auto CSC_slope_corr_L1_ME11b_even_ = load(gemCscSlopeCorrectionFiles_[1]);
132  auto CSC_slope_corr_L1_ME11a_odd_ = load(gemCscSlopeCorrectionFiles_[3]);
133  auto CSC_slope_corr_L1_ME11b_odd_ = load(gemCscSlopeCorrectionFiles_[4]);
134  auto CSC_slope_corr_L2_ME11a_even_ = load(gemCscSlopeCorrectionFiles_[6]);
135  auto CSC_slope_corr_L2_ME11b_even_ = load(gemCscSlopeCorrectionFiles_[7]);
136  auto CSC_slope_corr_L2_ME11a_odd_ = load(gemCscSlopeCorrectionFiles_[9]);
137  auto CSC_slope_corr_L2_ME11b_odd_ = load(gemCscSlopeCorrectionFiles_[10]);
138 
139  auto es_diff_slope_L1_ME11a_even_ = load(esDiffToSlopeME11aFiles_[0]);
140  auto es_diff_slope_L1_ME11a_odd_ = load(esDiffToSlopeME11aFiles_[1]);
141  auto es_diff_slope_L2_ME11a_even_ = load(esDiffToSlopeME11aFiles_[2]);
142  auto es_diff_slope_L2_ME11a_odd_ = load(esDiffToSlopeME11aFiles_[3]);
143 
144  auto es_diff_slope_L1_ME11b_even_ = load(esDiffToSlopeME11bFiles_[0]);
145  auto es_diff_slope_L1_ME11b_odd_ = load(esDiffToSlopeME11bFiles_[1]);
146  auto es_diff_slope_L2_ME11b_even_ = load(esDiffToSlopeME11bFiles_[2]);
147  auto es_diff_slope_L2_ME11b_odd_ = load(esDiffToSlopeME11bFiles_[3]);
148 
149  // set the data in the LUT object
150  lut->set_GEM_pad_CSC_es_ME11b_even(std::move(GEM_pad_CSC_es_ME11b_even_));
151  lut->set_GEM_pad_CSC_es_ME11a_even(std::move(GEM_pad_CSC_es_ME11a_even_));
152  lut->set_GEM_pad_CSC_es_ME11b_odd(std::move(GEM_pad_CSC_es_ME11b_odd_));
153  lut->set_GEM_pad_CSC_es_ME11a_odd(std::move(GEM_pad_CSC_es_ME11a_odd_));
154 
155  lut->set_GEM_roll_CSC_min_wg_ME11_even(std::move(GEM_roll_CSC_min_wg_ME11_even_));
156  lut->set_GEM_roll_CSC_min_wg_ME11_odd(std::move(GEM_roll_CSC_min_wg_ME11_odd_));
157  lut->set_GEM_roll_CSC_max_wg_ME11_even(std::move(GEM_roll_CSC_max_wg_ME11_even_));
158  lut->set_GEM_roll_CSC_max_wg_ME11_odd(std::move(GEM_roll_CSC_max_wg_ME11_odd_));
159 
160  // GEM-CSC trigger: slope correction
161  lut->set_CSC_slope_cosi_2to1_L1_ME11a_even(std::move(CSC_slope_cosi_2to1_L1_ME11a_even_));
162  lut->set_CSC_slope_cosi_2to1_L1_ME11a_odd(std::move(CSC_slope_cosi_2to1_L1_ME11a_odd_));
163  lut->set_CSC_slope_cosi_3to1_L1_ME11a_even(std::move(CSC_slope_cosi_3to1_L1_ME11a_even_));
164  lut->set_CSC_slope_cosi_3to1_L1_ME11a_odd(std::move(CSC_slope_cosi_3to1_L1_ME11a_odd_));
165 
166  lut->set_CSC_slope_cosi_2to1_L1_ME11b_even(std::move(CSC_slope_cosi_2to1_L1_ME11b_even_));
167  lut->set_CSC_slope_cosi_2to1_L1_ME11b_odd(std::move(CSC_slope_cosi_2to1_L1_ME11b_odd_));
168  lut->set_CSC_slope_cosi_3to1_L1_ME11b_even(std::move(CSC_slope_cosi_3to1_L1_ME11b_even_));
169  lut->set_CSC_slope_cosi_3to1_L1_ME11b_odd(std::move(CSC_slope_cosi_3to1_L1_ME11b_odd_));
170 
171  lut->set_CSC_slope_corr_L1_ME11a_even(std::move(CSC_slope_corr_L1_ME11a_even_));
172  lut->set_CSC_slope_corr_L1_ME11a_odd(std::move(CSC_slope_corr_L1_ME11a_odd_));
173  lut->set_CSC_slope_corr_L1_ME11b_even(std::move(CSC_slope_corr_L1_ME11b_even_));
174  lut->set_CSC_slope_corr_L1_ME11b_odd(std::move(CSC_slope_corr_L1_ME11b_odd_));
175  lut->set_CSC_slope_corr_L2_ME11a_even(std::move(CSC_slope_corr_L2_ME11a_even_));
176  lut->set_CSC_slope_corr_L2_ME11a_odd(std::move(CSC_slope_corr_L2_ME11a_odd_));
177  lut->set_CSC_slope_corr_L2_ME11b_even(std::move(CSC_slope_corr_L2_ME11b_even_));
178  lut->set_CSC_slope_corr_L2_ME11b_odd(std::move(CSC_slope_corr_L2_ME11b_odd_));
179 
180  // GEM-CSC trigger: 1/8-strip difference to slope
181  lut->set_es_diff_slope_L1_ME11a_even(std::move(es_diff_slope_L1_ME11a_even_));
182  lut->set_es_diff_slope_L1_ME11a_odd(std::move(es_diff_slope_L1_ME11a_odd_));
183  lut->set_es_diff_slope_L2_ME11a_even(std::move(es_diff_slope_L2_ME11a_even_));
184  lut->set_es_diff_slope_L2_ME11a_odd(std::move(es_diff_slope_L2_ME11a_odd_));
185 
186  lut->set_es_diff_slope_L1_ME11b_even(std::move(es_diff_slope_L1_ME11b_even_));
187  lut->set_es_diff_slope_L1_ME11b_odd(std::move(es_diff_slope_L1_ME11b_odd_));
188  lut->set_es_diff_slope_L2_ME11b_even(std::move(es_diff_slope_L2_ME11b_even_));
189  lut->set_es_diff_slope_L2_ME11b_odd(std::move(es_diff_slope_L2_ME11b_odd_));
190 
191  return lut;
192 }
193 
194 std::unique_ptr<CSCL1TPLookupTableME21ILT> CSCL1TPLookupTableEP::produceME21ILT(const CSCL1TPLookupTableME21ILTRcd&) {
195  // make the LUT object
196  std::unique_ptr<CSCL1TPLookupTableME21ILT> lut = std::make_unique<CSCL1TPLookupTableME21ILT>();
197 
198  // get the text files
199  std::vector<std::string> padToEsME21Files_ = pset_.getParameter<std::vector<std::string>>("padToEsME21Files");
200 
201  std::vector<std::string> rollToMaxWgME21Files_ = pset_.getParameter<std::vector<std::string>>("rollToMaxWgME21Files");
202  std::vector<std::string> rollToMinWgME21Files_ = pset_.getParameter<std::vector<std::string>>("rollToMinWgME21Files");
203 
204  std::vector<std::string> gemCscSlopeCosiFiles_ = pset_.getParameter<std::vector<std::string>>("gemCscSlopeCosiFiles");
205  std::vector<std::string> gemCscSlopeCosiCorrectionFiles_ =
206  pset_.getParameter<std::vector<std::string>>("gemCscSlopeCosiCorrectionFiles");
207  std::vector<std::string> gemCscSlopeCorrectionFiles_ =
208  pset_.getParameter<std::vector<std::string>>("gemCscSlopeCorrectionFiles");
209 
210  std::vector<std::string> esDiffToSlopeME21Files_ =
211  pset_.getParameter<std::vector<std::string>>("esDiffToSlopeME21Files");
212 
213  // read the text files and extract the data
214  auto GEM_pad_CSC_es_ME21_even_ = load(padToEsME21Files_[0]);
215  auto GEM_pad_CSC_es_ME21_odd_ = load(padToEsME21Files_[1]);
216 
217  auto GEM_roll_L1_CSC_min_wg_ME21_even_ = load(rollToMinWgME21Files_[0]);
218  auto GEM_roll_L1_CSC_min_wg_ME21_odd_ = load(rollToMinWgME21Files_[1]);
219  auto GEM_roll_L2_CSC_min_wg_ME21_even_ = load(rollToMinWgME21Files_[2]);
220  auto GEM_roll_L2_CSC_min_wg_ME21_odd_ = load(rollToMinWgME21Files_[3]);
221 
222  auto GEM_roll_L1_CSC_max_wg_ME21_even_ = load(rollToMaxWgME21Files_[0]);
223  auto GEM_roll_L1_CSC_max_wg_ME21_odd_ = load(rollToMaxWgME21Files_[1]);
224  auto GEM_roll_L2_CSC_max_wg_ME21_even_ = load(rollToMaxWgME21Files_[2]);
225  auto GEM_roll_L2_CSC_max_wg_ME21_odd_ = load(rollToMaxWgME21Files_[3]);
226 
227  auto es_diff_slope_L1_ME21_even_ = load(esDiffToSlopeME21Files_[0]);
228  auto es_diff_slope_L1_ME21_odd_ = load(esDiffToSlopeME21Files_[1]);
229  auto es_diff_slope_L2_ME21_even_ = load(esDiffToSlopeME21Files_[2]);
230  auto es_diff_slope_L2_ME21_odd_ = load(esDiffToSlopeME21Files_[3]);
231 
232  auto CSC_slope_cosi_2to1_L1_ME21_even_ = load(gemCscSlopeCosiFiles_[8]);
233  auto CSC_slope_cosi_2to1_L1_ME21_odd_ = load(gemCscSlopeCosiFiles_[9]);
234  auto CSC_slope_cosi_3to1_L1_ME21_even_ = load(gemCscSlopeCosiFiles_[10]);
235  auto CSC_slope_cosi_3to1_L1_ME21_odd_ = load(gemCscSlopeCosiFiles_[11]);
236 
237  auto CSC_slope_cosi_corr_L1_ME21_even_ = load(gemCscSlopeCosiCorrectionFiles_[2]);
238  auto CSC_slope_cosi_corr_L1_ME21_odd_ = load(gemCscSlopeCosiCorrectionFiles_[5]);
239 
240  auto CSC_slope_corr_L1_ME21_even_ = load(gemCscSlopeCorrectionFiles_[2]);
241  auto CSC_slope_corr_L1_ME21_odd_ = load(gemCscSlopeCorrectionFiles_[5]);
242  auto CSC_slope_corr_L2_ME21_even_ = load(gemCscSlopeCorrectionFiles_[8]);
243  auto CSC_slope_corr_L2_ME21_odd_ = load(gemCscSlopeCorrectionFiles_[11]);
244 
245  // set the data in the LUT object
246  lut->set_GEM_pad_CSC_es_ME21_even(std::move(GEM_pad_CSC_es_ME21_even_));
247  lut->set_GEM_pad_CSC_es_ME21_odd(std::move(GEM_pad_CSC_es_ME21_odd_));
248 
249  lut->set_GEM_roll_L1_CSC_min_wg_ME21_even(std::move(GEM_roll_L1_CSC_min_wg_ME21_even_));
250  lut->set_GEM_roll_L1_CSC_max_wg_ME21_even(std::move(GEM_roll_L1_CSC_max_wg_ME21_even_));
251  lut->set_GEM_roll_L1_CSC_min_wg_ME21_odd(std::move(GEM_roll_L1_CSC_min_wg_ME21_odd_));
252  lut->set_GEM_roll_L1_CSC_max_wg_ME21_odd(std::move(GEM_roll_L1_CSC_max_wg_ME21_odd_));
253 
254  lut->set_GEM_roll_L2_CSC_min_wg_ME21_even(std::move(GEM_roll_L2_CSC_min_wg_ME21_even_));
255  lut->set_GEM_roll_L2_CSC_max_wg_ME21_even(std::move(GEM_roll_L2_CSC_max_wg_ME21_even_));
256  lut->set_GEM_roll_L2_CSC_min_wg_ME21_odd(std::move(GEM_roll_L2_CSC_min_wg_ME21_odd_));
257  lut->set_GEM_roll_L2_CSC_max_wg_ME21_odd(std::move(GEM_roll_L2_CSC_max_wg_ME21_odd_));
258 
259  lut->set_es_diff_slope_L1_ME21_even(std::move(es_diff_slope_L1_ME21_even_));
260  lut->set_es_diff_slope_L1_ME21_odd(std::move(es_diff_slope_L1_ME21_odd_));
261  lut->set_es_diff_slope_L2_ME21_even(std::move(es_diff_slope_L2_ME21_even_));
262  lut->set_es_diff_slope_L2_ME21_odd(std::move(es_diff_slope_L2_ME21_odd_));
263 
264  lut->set_CSC_slope_cosi_2to1_L1_ME21_even(std::move(CSC_slope_cosi_2to1_L1_ME21_even_));
265  lut->set_CSC_slope_cosi_2to1_L1_ME21_odd(std::move(CSC_slope_cosi_2to1_L1_ME21_odd_));
266  lut->set_CSC_slope_cosi_3to1_L1_ME21_even(std::move(CSC_slope_cosi_3to1_L1_ME21_even_));
267  lut->set_CSC_slope_cosi_3to1_L1_ME21_odd(std::move(CSC_slope_cosi_3to1_L1_ME21_odd_));
268 
269  lut->set_CSC_slope_corr_L1_ME21_even(std::move(CSC_slope_corr_L1_ME21_even_));
270  lut->set_CSC_slope_corr_L1_ME21_odd(std::move(CSC_slope_corr_L1_ME21_odd_));
271  lut->set_CSC_slope_corr_L2_ME21_even(std::move(CSC_slope_corr_L2_ME21_even_));
272  lut->set_CSC_slope_corr_L2_ME21_odd(std::move(CSC_slope_corr_L2_ME21_odd_));
273 
274  return lut;
275 }
276 
277 std::vector<unsigned> CSCL1TPLookupTableEP::load(std::string fileName) const {
278  std::vector<unsigned> returnV;
279  std::ifstream fstream;
280  fstream.open(edm::FileInPath(fileName.c_str()).fullPath());
281  // empty file, return empty lut
282  if (!fstream.good()) {
283  fstream.close();
284  return returnV;
285  }
286 
288 
289  while (std::getline(fstream, line)) {
290  //ignore comments
291  line.erase(std::find(line.begin(), line.end(), '#'), line.end());
292  std::istringstream lineStream(line);
293  std::pair<unsigned, unsigned> entry;
294  while (lineStream >> entry.first >> entry.second) {
295  returnV.push_back(entry.second);
296  }
297  }
298  return returnV;
299 }
300 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const edm::ParameterSet pset_
std::unique_ptr< CSCL1TPLookupTableCCLUT > produceCCLUT(const CSCL1TPLookupTableCCLUTRcd &)
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
std::unique_ptr< CSCL1TPLookupTableME21ILT > produceME21ILT(const CSCL1TPLookupTableME21ILTRcd &)
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
const double infinity
CSCL1TPLookupTableEP(const edm::ParameterSet &)
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
std::vector< unsigned > load(std::string fileName) const
std::unique_ptr< CSCL1TPLookupTableME11ILT > produceME11ILT(const CSCL1TPLookupTableME11ILTRcd &)
def move(src, dest)
Definition: eostools.py:511