Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:23

0001 //-------------------------------------------------
0002 //
0003 //   Class: L1MuDTExtLut
0004 //
0005 //   Description: Look-up tables for extrapolation
0006 //
0007 //
0008 //   $Date: 2009/05/13 06:36:48 $
0009 //   $Revision: 1.6 $
0010 //
0011 //   Author :
0012 //   N. Neumeister            CERN EP
0013 //   J. Troconiz              UAM Madrid
0014 //
0015 //--------------------------------------------------
0016 
0017 //-----------------------
0018 // This Class's Header --
0019 //-----------------------
0020 
0021 #include "CondFormats/L1TObjects/interface/L1MuDTExtLut.h"
0022 
0023 //---------------
0024 // C++ Headers --
0025 //---------------
0026 
0027 #include <iostream>
0028 #include <ostream>
0029 #include <iomanip>
0030 #include <string>
0031 #include <cstdlib>
0032 
0033 //-------------------------------
0034 // Collaborating Class Headers --
0035 //-------------------------------
0036 
0037 #include "FWCore/Utilities/interface/FileInPath.h"
0038 #include "CondFormats/L1TObjects/interface/DTTFBitArray.h"
0039 #include "CondFormats/L1TObjects/interface/L1MuDTExtParam.h"
0040 #include "CondFormats/L1TObjects/interface/L1TriggerLutFile.h"
0041 
0042 using namespace std;
0043 
0044 // --------------------------------
0045 //       class L1MuDTExtLut
0046 //---------------------------------
0047 
0048 //----------------
0049 // Constructors --
0050 //----------------
0051 
0052 L1MuDTExtLut::L1MuDTExtLut() {
0053   ext_lut.reserve(MAX_EXT);
0054   setPrecision();
0055   //  if ( load() != 0 ) {
0056   //    cout << "Can not open files to load  extrapolation look-up tables for DTTrackFinder!" << endl;
0057   //  }
0058 
0059   //  if ( L1MuDTTFConfig::Debug(6) ) print();
0060 }
0061 
0062 //--------------
0063 // Destructor --
0064 //--------------
0065 
0066 L1MuDTExtLut::~L1MuDTExtLut() {
0067   typedef vector<LUT>::iterator LI;
0068   for (LI iter = ext_lut.begin(); iter != ext_lut.end(); iter++) {
0069     (*iter).low.clear();
0070     (*iter).high.clear();
0071   }
0072 
0073   ext_lut.clear();
0074 }
0075 
0076 //--------------
0077 // Operations --
0078 //--------------
0079 
0080 //
0081 // reset extrapolation look-up tables
0082 //
0083 void L1MuDTExtLut::reset() { ext_lut.clear(); }
0084 
0085 //
0086 // load extrapolation look-up tables
0087 //
0088 int L1MuDTExtLut::load() {
0089   // get directory name
0090   string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
0091   string ext_dir = "L1TriggerData/DTTrackFinder/Ext/";
0092   string ext_str = "";
0093 
0094   // precision : in the look-up tables the following precision is used :
0095   // phi ...12 bits (low, high), phib ...10 bits (address)
0096   // now convert phi and phib to the required precision
0097 
0098   int sh_phi = 12 - nbit_phi;
0099   int sh_phib = 10 - nbit_phib;
0100 
0101   // loop over all extrapolations
0102   for (int ext = 0; ext < MAX_EXT; ext++) {
0103     switch (ext) {
0104       case EX12:
0105         ext_str = "ext12";
0106         break;
0107       case EX13:
0108         ext_str = "ext13";
0109         break;
0110       case EX14:
0111         ext_str = "ext14";
0112         break;
0113       case EX21:
0114         ext_str = "ext21";
0115         break;
0116       case EX23:
0117         ext_str = "ext23";
0118         break;
0119       case EX24:
0120         ext_str = "ext24";
0121         break;
0122       case EX34:
0123         ext_str = "ext34";
0124         break;
0125       case EX15:
0126         ext_str = "ext15";
0127         break;
0128       case EX16:
0129         ext_str = "ext16";
0130         break;
0131       case EX25:
0132         ext_str = "ext25";
0133         break;
0134       case EX26:
0135         ext_str = "ext26";
0136         break;
0137       case EX56:
0138         ext_str = "ext56";
0139         break;
0140     }
0141 
0142     // assemble file name
0143     edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + ext_dir + ext_str + ".lut"));
0144     string ext_file = lut_f.fullPath();
0145 
0146     // open file
0147     L1TriggerLutFile file(ext_file);
0148     if (file.open() != 0)
0149       return -1;
0150     //    if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
0151     //                                         << file.getName() << endl;
0152 
0153     LUT tmplut;
0154 
0155     int number = -1;
0156     int adr_old = -512 >> sh_phib;
0157     int sum_low = 0;
0158     int sum_high = 0;
0159 
0160     // read values and shift to correct precision
0161     while (file.good()) {
0162       int adr = (file.readInteger()) >> sh_phib;  // address (phib)
0163       int low = (file.readInteger());             // low value (phi)
0164       int high = (file.readInteger());            // high value (phi)
0165 
0166       number++;
0167 
0168       if (adr != adr_old) {
0169         tmplut.low[adr_old] = sum_low >> sh_phi;
0170         tmplut.high[adr_old] = sum_high >> sh_phi;
0171 
0172         adr_old = adr;
0173         number = 0;
0174         sum_low = 0;
0175         sum_high = 0;
0176       }
0177 
0178       if (number == 0)
0179         sum_low = low;
0180       if (number == 0)
0181         sum_high = high;
0182 
0183       if (!file.good())
0184         file.close();
0185     }
0186 
0187     file.close();
0188     ext_lut.push_back(tmplut);
0189   }
0190   return 0;
0191 }
0192 
0193 //
0194 // print extrapolation look-up tables
0195 //
0196 void L1MuDTExtLut::print() const {
0197   cout << endl;
0198   cout << "L1 barrel Track Finder Extrapolation look-up tables :" << endl;
0199   cout << "=====================================================" << endl;
0200   cout << endl;
0201   cout << "Precision : " << endl;
0202   cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;
0203   cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
0204 
0205   // loop over all extrapolations
0206   for (int ext = 0; ext < MAX_EXT; ext++) {
0207     cout << endl;
0208     cout << "Extrapolation : " << static_cast<Extrapolation>(ext) << endl;
0209     cout << "====================" << endl;
0210     cout << endl;
0211 
0212     cout << "      address";
0213     for (int i = 0; i < nbit_phib; i++)
0214       cout << ' ';
0215     cout << "    low-value";
0216     for (int i = 0; i < nbit_phi; i++)
0217       cout << ' ';
0218     cout << "  high-value      " << endl;
0219     for (int i = 0; i < 2 * nbit_phi + nbit_phib; i++)
0220       cout << '-';
0221     cout << "---------------------------------" << endl;
0222 
0223     LUT::LUTmap::const_iterator iter = ext_lut[ext].low.begin();
0224     LUT::LUTmap::const_iterator iter1;
0225     while (iter != ext_lut[ext].low.end()) {
0226       int address = (*iter).first;
0227       int low = (*iter).second;
0228       iter1 = ext_lut[ext].high.find(address);
0229       int high = (*iter1).second;
0230 
0231       DTTFBitArray<10> b_address(static_cast<unsigned>(abs(address)));
0232       DTTFBitArray<12> b_low(static_cast<unsigned>(abs(low)));
0233       DTTFBitArray<12> b_high(static_cast<unsigned>(abs(high)));
0234 
0235       if (address < 0)
0236         b_address.twoComplement();
0237       if (low < 0)
0238         b_low.twoComplement();
0239       if (high < 0)
0240         b_high.twoComplement();
0241 
0242       cout.setf(ios::right, ios::adjustfield);
0243       cout << " " << setbase(10) << setw(5) << address << " (";
0244       for (int i = nbit_phib - 1; i >= 0; i--)
0245         cout << b_address[i];
0246       cout << ")   " << setw(5) << low << " (";
0247       for (int i = nbit_phi - 1; i >= 0; i--)
0248         cout << b_low[i];
0249       cout << ")   " << setw(5) << high << " (";
0250       for (int i = nbit_phi - 1; i >= 0; i--)
0251         cout << b_high[i];
0252       cout << ")  " << endl;
0253 
0254       iter++;
0255     }
0256   }
0257 
0258   cout << endl;
0259 }
0260 
0261 //
0262 // get low_value for a given address
0263 //
0264 int L1MuDTExtLut::getLow(int ext_ind, int address) const {
0265   LUT::LUTmap::const_iterator iter = ext_lut[ext_ind].low.find(address);
0266   if (iter != ext_lut[ext_ind].low.end()) {
0267     return (*iter).second;
0268   } else {
0269     cerr << "ExtLut::getLow : can not find address " << address << endl;
0270     return 99999;
0271   }
0272 }
0273 
0274 //
0275 // get high_value for a given address
0276 //
0277 int L1MuDTExtLut::getHigh(int ext_ind, int address) const {
0278   LUT::LUTmap::const_iterator iter = ext_lut[ext_ind].high.find(address);
0279   if (iter != ext_lut[ext_ind].high.end()) {
0280     return (*iter).second;
0281   } else {
0282     cerr << "ExtLut::getHigh : can not find address " << address << endl;
0283     return 99999;
0284   }
0285 }
0286 
0287 //
0288 // set precision for Look-up tables
0289 //
0290 void L1MuDTExtLut::setPrecision() {
0291   nbit_phi = 12;
0292   nbit_phib = 10;
0293 }