00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "CondFormats/L1TObjects/interface/L1MuDTPhiLut.h"
00022
00023
00024
00025
00026
00027 #include <iostream>
00028 #include <ostream>
00029 #include <iomanip>
00030 #include <string>
00031
00032
00033
00034
00035
00036 #include "FWCore/ParameterSet/interface/FileInPath.h"
00037
00038 #include "CondFormats/L1TObjects/interface/L1TriggerLutFile.h"
00039
00040 using namespace std;
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 L1MuDTPhiLut::L1MuDTPhiLut() {
00051
00052 phi_lut.reserve(2);
00053 setPrecision();
00054
00055
00056
00057
00058
00059
00060 }
00061
00062
00063
00064
00065
00066
00067 L1MuDTPhiLut::~L1MuDTPhiLut() {
00068
00069 vector<LUT>::iterator iter;
00070 for ( iter = phi_lut.begin(); iter != phi_lut.end(); iter++ ) {
00071 (*iter).clear();
00072 }
00073
00074 phi_lut.clear();
00075
00076 }
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 void L1MuDTPhiLut::reset() {
00087
00088 phi_lut.clear();
00089
00090 }
00091
00092
00093
00094
00095
00096 int L1MuDTPhiLut::load() {
00097
00098
00099 string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
00100 string phi_dir = "L1TriggerData/DTTrackFinder/Ass/";
00101 string phi_str = "";
00102
00103
00104
00105
00106 int sh_phi = 12 - nbit_phi;
00107 int sh_phib = 10 - nbit_phib;
00108
00109
00110 for ( int idx = 0; idx < 2; idx++ ) {
00111 switch ( idx ) {
00112 case 0 : { phi_str = "phi12"; break; }
00113 case 1 : { phi_str = "phi42"; break; }
00114 }
00115
00116
00117 edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + phi_dir + phi_str + ".lut"));
00118 string phi_file = lut_f.fullPath();
00119
00120
00121 L1TriggerLutFile file(phi_file);
00122 if ( file.open() != 0 ) return -1;
00123
00124
00125
00126 LUT tmplut;
00127
00128 int number = -1;
00129 int adr_old = -512 >> sh_phib;
00130 int sum_phi = 0;
00131
00132
00133 while ( file.good() ) {
00134
00135 int adr = (file.readInteger()) >> sh_phib;
00136 int phi = file.readInteger();
00137
00138 number++;
00139
00140 if ( adr != adr_old ) {
00141 tmplut.insert(make_pair( adr_old, ((sum_phi/number) >> sh_phi) ));
00142
00143 adr_old = adr;
00144 number = 0;
00145 sum_phi = 0;
00146 }
00147
00148 sum_phi += phi;
00149
00150 if ( !file.good() ) file.close();
00151
00152 }
00153
00154 file.close();
00155 phi_lut.push_back(tmplut);
00156 }
00157 return 0;
00158
00159 }
00160
00161
00162
00163
00164
00165 void L1MuDTPhiLut::print() const {
00166
00167 cout << endl;
00168 cout << "L1 barrel Track Finder Phi-Assignment look-up tables :" << endl;
00169 cout << "======================================================" << endl;
00170 cout << endl;
00171 cout << "Precision : " << endl;
00172 cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
00173 cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
00174
00175
00176 for ( int idx = 0; idx < 2; idx++ ) {
00177
00178 cout << endl;
00179 if ( idx == 0 ) cout << "Phi-Assignment Method : " << "PHI12" << endl;
00180 if ( idx == 1 ) cout << "Phi-Assignment Method : " << "PHI42" << endl;
00181 cout << "=============================" << endl;
00182 cout << endl;
00183
00184 cout << " address";
00185 for ( int i = 0; i < nbit_phib; i++ ) cout << ' ';
00186 cout << " value" << endl;
00187 for ( int i = 0; i < nbit_phi + nbit_phib; i++ ) cout << '-';
00188 cout << "----------------------" << endl;
00189
00190 LUT::const_iterator iter = phi_lut[idx].begin();
00191 while ( iter != phi_lut[idx].end() ) {
00192 int address = (*iter).first;
00193 int value = (*iter).second;
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 iter++;
00209 }
00210
00211 }
00212
00213 cout << endl;
00214
00215 }
00216
00217
00218
00219
00220
00221 int L1MuDTPhiLut::getDeltaPhi(int idx, int address) const {
00222
00223 LUT::const_iterator iter = phi_lut[idx].find(address);
00224 if ( iter != phi_lut[idx].end() ) {
00225 return (*iter).second;
00226 }
00227 else {
00228 cerr << "PhiLut::getDeltaPhi : can not find address " << address << endl;
00229 return 0;
00230 }
00231
00232 }
00233
00234
00235
00236
00237
00238 void L1MuDTPhiLut::setPrecision() {
00239
00240 nbit_phi = 12;
00241 nbit_phib = 10;
00242
00243 }
00244
00245
00246
00247
00248
00249 pair<unsigned short, unsigned short> L1MuDTPhiLut::getPrecision() const {
00250
00251 return pair<unsigned short, unsigned short>(nbit_phi,nbit_phib);
00252
00253 }