File indexing completed on 2025-01-04 00:29:27
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/L1MuDTPhiLut.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/L1TriggerLutFile.h"
0040
0041 using namespace std;
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 L1MuDTPhiLut::L1MuDTPhiLut() {
0052 phi_lut.reserve(2);
0053 setPrecision();
0054
0055
0056
0057
0058
0059 }
0060
0061
0062
0063
0064
0065 L1MuDTPhiLut::~L1MuDTPhiLut() {
0066 vector<LUT>::iterator iter;
0067 for (iter = phi_lut.begin(); iter != phi_lut.end(); iter++) {
0068 (*iter).clear();
0069 }
0070
0071 phi_lut.clear();
0072 }
0073
0074
0075
0076
0077
0078
0079
0080
0081 void L1MuDTPhiLut::reset() { phi_lut.clear(); }
0082
0083
0084
0085
0086 int L1MuDTPhiLut::load() {
0087
0088 string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
0089 string phi_dir = "L1TriggerData/DTTrackFinder/Ass/";
0090 string phi_str = "";
0091
0092
0093
0094
0095 int sh_phi = 12 - nbit_phi;
0096 int sh_phib = 10 - nbit_phib;
0097
0098
0099 for (int idx = 0; idx < 2; idx++) {
0100 switch (idx) {
0101 case 0: {
0102 phi_str = "phi12";
0103 break;
0104 }
0105 case 1: {
0106 phi_str = "phi42";
0107 break;
0108 }
0109 }
0110
0111
0112 edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + phi_dir + phi_str + ".lut"));
0113 const string& phi_file = lut_f.fullPath();
0114
0115
0116 L1TriggerLutFile file(phi_file);
0117 if (file.open() != 0)
0118 return -1;
0119
0120
0121
0122 LUT tmplut;
0123
0124 int number = -1;
0125 int adr_old = -512 >> sh_phib;
0126 int sum_phi = 0;
0127
0128
0129 while (file.good()) {
0130 int adr = (file.readInteger()) >> sh_phib;
0131 int phi = file.readInteger();
0132
0133 number++;
0134
0135 if (adr != adr_old) {
0136 assert(number);
0137 tmplut.insert(make_pair(adr_old, ((sum_phi / number) >> sh_phi)));
0138
0139 adr_old = adr;
0140 number = 0;
0141 sum_phi = 0;
0142 }
0143
0144 sum_phi += phi;
0145
0146 if (!file.good())
0147 file.close();
0148 }
0149
0150 file.close();
0151 phi_lut.push_back(tmplut);
0152 }
0153 return 0;
0154 }
0155
0156
0157
0158
0159 void L1MuDTPhiLut::print() const {
0160 cout << endl;
0161 cout << "L1 barrel Track Finder Phi-Assignment look-up tables :" << endl;
0162 cout << "======================================================" << endl;
0163 cout << endl;
0164 cout << "Precision : " << endl;
0165 cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
0166 cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
0167
0168
0169 for (int idx = 0; idx < 2; idx++) {
0170 cout << endl;
0171 if (idx == 0)
0172 cout << "Phi-Assignment Method : "
0173 << "PHI12" << endl;
0174 if (idx == 1)
0175 cout << "Phi-Assignment Method : "
0176 << "PHI42" << endl;
0177 cout << "=============================" << endl;
0178 cout << endl;
0179
0180 cout << " address";
0181 for (int i = 0; i < nbit_phib; i++)
0182 cout << ' ';
0183 cout << " value" << endl;
0184 for (int i = 0; i < nbit_phi + nbit_phib; i++)
0185 cout << '-';
0186 cout << "----------------------" << endl;
0187
0188 LUT::const_iterator iter = phi_lut[idx].begin();
0189 while (iter != phi_lut[idx].end()) {
0190 int address = (*iter).first;
0191 int value = (*iter).second;
0192
0193 DTTFBitArray<10> b_address(static_cast<unsigned>(abs(address)));
0194 DTTFBitArray<12> b_value(static_cast<unsigned>(abs(value)));
0195
0196 if (address < 0)
0197 b_address.twoComplement();
0198 if (value < 0)
0199 b_value.twoComplement();
0200
0201 cout.setf(ios::right, ios::adjustfield);
0202 cout << " " << setbase(10) << setw(5) << address << " (";
0203 for (int i = nbit_phib - 1; i >= 0; i--)
0204 cout << b_address[i];
0205 cout << ") " << setw(5) << value << " (";
0206 for (int i = nbit_phi - 1; i >= 0; i--)
0207 cout << b_value[i];
0208 cout << ") " << endl;
0209
0210 iter++;
0211 }
0212 }
0213
0214 cout << endl;
0215 }
0216
0217
0218
0219
0220 int L1MuDTPhiLut::getDeltaPhi(int idx, int address) const {
0221 LUT::const_iterator iter = phi_lut[idx].find(address);
0222 if (iter != phi_lut[idx].end()) {
0223 return (*iter).second;
0224 } else {
0225 cerr << "PhiLut::getDeltaPhi : can not find address " << address << endl;
0226 return 0;
0227 }
0228 }
0229
0230
0231
0232
0233 void L1MuDTPhiLut::setPrecision() {
0234 nbit_phi = 12;
0235 nbit_phib = 10;
0236 }
0237
0238
0239
0240
0241 pair<unsigned short, unsigned short> L1MuDTPhiLut::getPrecision() const {
0242 return pair<unsigned short, unsigned short>(nbit_phi, nbit_phib);
0243 }