File indexing completed on 2024-04-06 12:02:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "CondFormats/L1TObjects/interface/L1MuDTPtaLut.h"
0022
0023
0024
0025
0026
0027 #include <iostream>
0028 #include <ostream>
0029 #include <iomanip>
0030 #include <string>
0031 #include <cstdlib>
0032
0033
0034
0035
0036
0037 #include "FWCore/Utilities/interface/FileInPath.h"
0038 #include "CondFormats/L1TObjects/interface/DTTFBitArray.h"
0039 #include "CondFormats/L1TObjects/interface/L1MuDTAssParam.h"
0040 #include "CondFormats/L1TObjects/interface/L1TriggerLutFile.h"
0041
0042 using namespace std;
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 L1MuDTPtaLut::L1MuDTPtaLut() : pta_lut(0), pta_threshold(MAX_PTASSMETH / 2) {
0053 pta_lut.reserve(MAX_PTASSMETH);
0054 pta_threshold.reserve(MAX_PTASSMETH / 2);
0055 setPrecision();
0056
0057
0058
0059
0060
0061
0062 }
0063
0064
0065
0066
0067
0068 L1MuDTPtaLut::~L1MuDTPtaLut() {
0069 vector<LUT>::iterator iter;
0070 for (iter = pta_lut.begin(); iter != pta_lut.end(); iter++) {
0071 (*iter).clear();
0072 }
0073
0074 pta_lut.clear();
0075 pta_threshold.clear();
0076 }
0077
0078
0079
0080
0081
0082
0083
0084
0085 void L1MuDTPtaLut::reset() {
0086 pta_lut.clear();
0087 pta_threshold.clear();
0088 }
0089
0090
0091
0092
0093 int L1MuDTPtaLut::load() {
0094
0095 string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
0096 string pta_dir = "L1TriggerData/DTTrackFinder/Ass/";
0097 string pta_str = "";
0098
0099
0100
0101
0102
0103 int sh_phi = 12 - nbit_phi;
0104
0105
0106 for (int pam = 0; pam < MAX_PTASSMETH; pam++) {
0107 switch (pam) {
0108 case PT12L: {
0109 pta_str = "pta12l";
0110 break;
0111 }
0112 case PT12H: {
0113 pta_str = "pta12h";
0114 break;
0115 }
0116 case PT13L: {
0117 pta_str = "pta13l";
0118 break;
0119 }
0120 case PT13H: {
0121 pta_str = "pta13h";
0122 break;
0123 }
0124 case PT14L: {
0125 pta_str = "pta14l";
0126 break;
0127 }
0128 case PT14H: {
0129 pta_str = "pta14h";
0130 break;
0131 }
0132 case PT23L: {
0133 pta_str = "pta23l";
0134 break;
0135 }
0136 case PT23H: {
0137 pta_str = "pta23h";
0138 break;
0139 }
0140 case PT24L: {
0141 pta_str = "pta24l";
0142 break;
0143 }
0144 case PT24H: {
0145 pta_str = "pta24h";
0146 break;
0147 }
0148 case PT34L: {
0149 pta_str = "pta34l";
0150 break;
0151 }
0152 case PT34H: {
0153 pta_str = "pta34h";
0154 break;
0155 }
0156 case PT12LO: {
0157 pta_str = "pta12l_ovl";
0158 break;
0159 }
0160 case PT12HO: {
0161 pta_str = "pta12h_ovl";
0162 break;
0163 }
0164 case PT13LO: {
0165 pta_str = "pta13l_ovl";
0166 break;
0167 }
0168 case PT13HO: {
0169 pta_str = "pta13h_ovl";
0170 break;
0171 }
0172 case PT14LO: {
0173 pta_str = "pta14l_ovl";
0174 break;
0175 }
0176 case PT14HO: {
0177 pta_str = "pta14h_ovl";
0178 break;
0179 }
0180 case PT23LO: {
0181 pta_str = "pta23l_ovl";
0182 break;
0183 }
0184 case PT23HO: {
0185 pta_str = "pta23h_ovl";
0186 break;
0187 }
0188 case PT24LO: {
0189 pta_str = "pta24l_ovl";
0190 break;
0191 }
0192 case PT24HO: {
0193 pta_str = "pta24h_ovl";
0194 break;
0195 }
0196 case PT34LO: {
0197 pta_str = "pta34l_ovl";
0198 break;
0199 }
0200 case PT34HO: {
0201 pta_str = "pta34h_ovl";
0202 break;
0203 }
0204 case PT15LO: {
0205 pta_str = "pta15l_ovl";
0206 break;
0207 }
0208 case PT15HO: {
0209 pta_str = "pta15h_ovl";
0210 break;
0211 }
0212 case PT25LO: {
0213 pta_str = "pta25l_ovl";
0214 break;
0215 }
0216 case PT25HO: {
0217 pta_str = "pta25h_ovl";
0218 break;
0219 }
0220 }
0221
0222
0223 edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + pta_dir + pta_str + ".lut"));
0224 string pta_file = lut_f.fullPath();
0225
0226
0227 L1TriggerLutFile file(pta_file);
0228 if (file.open() != 0)
0229 return -1;
0230
0231
0232
0233
0234 int shift = sh_phi;
0235 int adr_old = -2048 >> shift;
0236
0237 LUT tmplut;
0238
0239 int number = -1;
0240 int sum_pt = 0;
0241
0242 if (file.good()) {
0243 int threshold = file.readInteger();
0244 pta_threshold[pam / 2] = threshold;
0245 }
0246
0247
0248 while (file.good()) {
0249 int adr = (file.readInteger()) >> shift;
0250 int pt = file.readInteger();
0251
0252 number++;
0253
0254 if (adr != adr_old) {
0255 assert(number);
0256 tmplut.insert(make_pair(adr_old, (sum_pt / number)));
0257
0258 adr_old = adr;
0259 number = 0;
0260 sum_pt = 0;
0261 }
0262
0263 sum_pt += pt;
0264
0265 if (!file.good())
0266 file.close();
0267 }
0268
0269 file.close();
0270 pta_lut.push_back(tmplut);
0271 }
0272 return 0;
0273 }
0274
0275
0276
0277
0278 void L1MuDTPtaLut::print() const {
0279 cout << endl;
0280 cout << "L1 barrel Track Finder Pt-Assignment look-up tables :" << endl;
0281 cout << "=====================================================" << endl;
0282 cout << endl;
0283 cout << "Precision : " << endl;
0284 cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
0285
0286
0287 for (int pam = 0; pam < MAX_PTASSMETH; pam++) {
0288 cout << endl;
0289 cout << "Pt-Assignment Method : " << static_cast<PtAssMethod>(pam) << endl;
0290 cout << "============================" << endl;
0291 cout << endl;
0292
0293 cout << "\t Threshold : " << getPtLutThreshold(pam / 2) << endl << endl;
0294
0295 int maxbits = nbit_phi;
0296
0297 cout << " address";
0298 for (int i = 0; i < maxbits; i++)
0299 cout << ' ';
0300 cout << " value" << endl;
0301 for (int i = 0; i < maxbits; i++)
0302 cout << '-';
0303 cout << "-------------------------" << endl;
0304
0305 LUT::const_iterator iter = pta_lut[pam].begin();
0306 while (iter != pta_lut[pam].end()) {
0307 int address = (*iter).first;
0308 int value = (*iter).second;
0309
0310 DTTFBitArray<12> b_address(static_cast<unsigned>(abs(address)));
0311 DTTFBitArray<5> b_value(static_cast<unsigned>(abs(value)));
0312
0313 if (address < 0)
0314 b_address.twoComplement();
0315
0316 cout.setf(ios::right, ios::adjustfield);
0317 cout << " " << setbase(10) << setw(5) << address << " (";
0318 for (int i = maxbits - 1; i >= 0; i--)
0319 cout << b_address[i];
0320 cout << ") " << setw(3) << value << " (";
0321 b_value.print();
0322 cout << ")" << endl;
0323
0324 iter++;
0325 }
0326 }
0327
0328 cout << endl;
0329 }
0330
0331
0332
0333
0334 int L1MuDTPtaLut::getPt(int pta_ind, int address) const {
0335 LUT::const_iterator iter = pta_lut[pta_ind].find(address);
0336 if (iter != pta_lut[pta_ind].end()) {
0337 return (*iter).second;
0338 } else {
0339 cerr << "PtaLut::getPt : can not find address " << address << endl;
0340 return 0;
0341 }
0342 }
0343
0344
0345
0346
0347 int L1MuDTPtaLut::getPtLutThreshold(int pta_ind) const {
0348 if (pta_ind >= 0 && pta_ind < MAX_PTASSMETH / 2) {
0349 return pta_threshold[pta_ind];
0350 } else {
0351 cerr << "PtaLut::getPtLutThreshold : can not find threshold " << pta_ind << endl;
0352 return 0;
0353 }
0354 }
0355
0356
0357
0358
0359 void L1MuDTPtaLut::setPrecision() { nbit_phi = 12; }