CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/CondFormats/L1TObjects/src/L1MuDTExtLut.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: L1MuDTExtLut
00004 //
00005 //   Description: Look-up tables for extrapolation
00006 //
00007 //
00008 //   $Date: 2010/05/12 23:03:43 $
00009 //   $Revision: 1.7 $
00010 //
00011 //   Author :
00012 //   N. Neumeister            CERN EP
00013 //   J. Troconiz              UAM Madrid
00014 //
00015 //--------------------------------------------------
00016 
00017 //-----------------------
00018 // This Class's Header --
00019 //-----------------------
00020 
00021 #include "CondFormats/L1TObjects/interface/L1MuDTExtLut.h"
00022 
00023 //---------------
00024 // C++ Headers --
00025 //---------------
00026 
00027 #include <iostream>
00028 #include <ostream>
00029 #include <iomanip>
00030 #include <string>
00031 #include <cstdlib>
00032 
00033 //-------------------------------
00034 // Collaborating Class Headers --
00035 //-------------------------------
00036 
00037 #include "FWCore/ParameterSet/interface/FileInPath.h"
00038 #include "CondFormats/L1TObjects/interface/DTTFBitArray.h"
00039 #include "CondFormats/L1TObjects/interface/L1MuDTExtParam.h"
00040 #include "CondFormats/L1TObjects/interface/L1TriggerLutFile.h"
00041 
00042 using namespace std;
00043 
00044 // --------------------------------
00045 //       class L1MuDTExtLut
00046 //---------------------------------
00047 
00048 //----------------
00049 // Constructors --
00050 //----------------
00051 
00052 L1MuDTExtLut::L1MuDTExtLut() {
00053 
00054   ext_lut.reserve(MAX_EXT);
00055   setPrecision();
00056   //  if ( load() != 0 ) {
00057   //    cout << "Can not open files to load  extrapolation look-up tables for DTTrackFinder!" << endl;
00058   //  }
00059 
00060   //  if ( L1MuDTTFConfig::Debug(6) ) print();
00061 
00062 }
00063 
00064 
00065 //--------------
00066 // Destructor --
00067 //--------------
00068 
00069 L1MuDTExtLut::~L1MuDTExtLut() {
00070 
00071   typedef vector<LUT>::iterator LI;
00072   for ( LI iter = ext_lut.begin(); iter != ext_lut.end(); iter++ ) {
00073     (*iter).low.clear();
00074     (*iter).high.clear();
00075   }
00076 
00077   ext_lut.clear();
00078 
00079 }
00080 
00081 
00082 //--------------
00083 // Operations --
00084 //--------------
00085 
00086 //
00087 // reset extrapolation look-up tables
00088 //
00089 void L1MuDTExtLut::reset() {
00090 
00091   ext_lut.clear();
00092 
00093 }
00094 
00095 
00096 //
00097 // load extrapolation look-up tables
00098 //
00099 int L1MuDTExtLut::load() {
00100 
00101   // get directory name
00102   string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
00103   string ext_dir = "L1TriggerData/DTTrackFinder/Ext/";
00104   string ext_str = "";
00105 
00106   // precision : in the look-up tables the following precision is used :
00107   // phi ...12 bits (low, high), phib ...10 bits (address)
00108   // now convert phi and phib to the required precision
00109 
00110   int sh_phi  = 12 - nbit_phi;
00111   int sh_phib = 10 - nbit_phib;
00112 
00113   // loop over all extrapolations
00114   for ( int ext = 0; ext < MAX_EXT; ext++ ) { 
00115     switch (ext) {
00116       case EX12 : ext_str = "ext12"; break;
00117       case EX13 : ext_str = "ext13"; break;
00118       case EX14 : ext_str = "ext14"; break;
00119       case EX21 : ext_str = "ext21"; break;
00120       case EX23 : ext_str = "ext23"; break;
00121       case EX24 : ext_str = "ext24"; break;
00122       case EX34 : ext_str = "ext34"; break;
00123       case EX15 : ext_str = "ext15"; break;
00124       case EX16 : ext_str = "ext16"; break;
00125       case EX25 : ext_str = "ext25"; break;
00126       case EX26 : ext_str = "ext26"; break;
00127       case EX56 : ext_str = "ext56"; break;
00128     }
00129 
00130     // assemble file name
00131     edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + ext_dir + ext_str + ".lut"));
00132     string ext_file = lut_f.fullPath();
00133 
00134     // open file
00135     L1TriggerLutFile file(ext_file);
00136     if ( file.open() != 0 ) return -1;
00137     //    if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : " 
00138     //                                         << file.getName() << endl; 
00139 
00140     LUT tmplut;
00141 
00142     int number = -1;
00143     int adr_old = -512 >> sh_phib;
00144     int sum_low = 0;
00145     int sum_high = 0;
00146 
00147     // read values and shift to correct precision
00148     while ( file.good() ) {
00149  
00150       int adr  = ( file.readInteger() ) >> sh_phib;     // address (phib)
00151       int low  = ( file.readInteger() );                // low value (phi)
00152       int high = ( file.readInteger() );                // high value (phi)
00153 
00154       number++;
00155       
00156       if ( adr != adr_old ) {
00157       
00158         tmplut.low[adr_old]  = sum_low  >> sh_phi;
00159         tmplut.high[adr_old] = sum_high >> sh_phi;
00160 
00161         adr_old = adr;
00162         number = 0;
00163         sum_low  = 0;
00164         sum_high = 0;
00165 
00166       }
00167 
00168       if (number == 0) sum_low  = low;
00169       if (number == 0) sum_high = high;
00170 
00171       if ( !file.good() ) file.close();
00172     }
00173 
00174     file.close();
00175     ext_lut.push_back(tmplut);
00176   }
00177   return 0;
00178 
00179 }
00180 
00181 
00182 //
00183 // print extrapolation look-up tables
00184 //
00185 void L1MuDTExtLut::print() const {
00186 
00187   cout << endl;
00188   cout << "L1 barrel Track Finder Extrapolation look-up tables :" << endl;
00189   cout << "=====================================================" << endl;
00190   cout << endl;
00191   cout << "Precision : " << endl;
00192   cout << '\t' << setw(2) << nbit_phi  << " bits are used for phi "  << endl;
00193   cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
00194 
00195   // loop over all extrapolations
00196   for ( int ext = 0; ext < MAX_EXT; ext++ ) {
00197 
00198     cout << endl;
00199     cout << "Extrapolation : " << static_cast<Extrapolation>(ext) << endl;
00200     cout << "====================" << endl;
00201     cout << endl;
00202 
00203     cout << "      address";
00204     for ( int i = 0; i < nbit_phib; i++ ) cout << ' ';
00205     cout << "    low-value";
00206     for ( int i = 0; i < nbit_phi; i++ ) cout << ' ';
00207     cout << "  high-value      " << endl;
00208     for ( int i = 0; i < 2*nbit_phi + nbit_phib; i++ ) cout << '-';
00209     cout << "---------------------------------" << endl;
00210 
00211     LUT::LUTmap::const_iterator iter = ext_lut[ext].low.begin();
00212     LUT::LUTmap::const_iterator iter1;
00213     while ( iter != ext_lut[ext].low.end() ) {
00214       int address = (*iter).first;
00215       int low     = (*iter).second;
00216       iter1 = ext_lut[ext].high.find(address);
00217       int high    = (*iter1).second;
00218 
00219       DTTFBitArray<10> b_address(static_cast<unsigned>(abs(address)));
00220       DTTFBitArray<12> b_low(static_cast<unsigned>(abs(low)));
00221       DTTFBitArray<12> b_high(static_cast<unsigned>(abs(high)));
00222 
00223       if ( address < 0 ) b_address.twoComplement();
00224       if ( low < 0 ) b_low.twoComplement();
00225       if ( high < 0 ) b_high.twoComplement();
00226 
00227       cout.setf(ios::right,ios::adjustfield);
00228       cout << " " << setbase(10) << setw(5) << address << " (";
00229       for ( int i = nbit_phib-1; i >= 0; i-- ) cout << b_address[i];
00230       cout << ")   " << setw(5) << low  << " (";
00231       for ( int i = nbit_phi-1; i >= 0; i-- ) cout << b_low[i];
00232       cout << ")   " << setw(5) << high << " (";
00233       for ( int i = nbit_phi-1; i >= 0; i-- ) cout << b_high[i];
00234       cout << ")  " << endl;
00235 
00236       iter++;
00237     }
00238 
00239   }
00240 
00241   cout << endl;
00242 
00243 }
00244 
00245 
00246 //
00247 // get low_value for a given address
00248 //
00249 int L1MuDTExtLut::getLow(int ext_ind, int address) const {
00250 
00251   LUT::LUTmap::const_iterator iter = ext_lut[ext_ind].low.find(address);
00252   if ( iter != ext_lut[ext_ind].low.end() ) {
00253     return (*iter).second;
00254   }
00255   else {
00256     cerr << "ExtLut::getLow : can not find address " << address << endl;
00257     return 99999;
00258   }
00259 }
00260 
00261 
00262 //
00263 // get high_value for a given address
00264 //
00265 int L1MuDTExtLut::getHigh(int ext_ind, int address) const {
00266 
00267   LUT::LUTmap::const_iterator iter = ext_lut[ext_ind].high.find(address);
00268   if ( iter != ext_lut[ext_ind].high.end() ) {
00269     return (*iter).second;
00270   }
00271   else {
00272     cerr << "ExtLut::getHigh : can not find address " << address << endl;
00273     return 99999;
00274   }
00275 }
00276 
00277 
00278 //
00279 // set precision for Look-up tables
00280 //
00281 void L1MuDTExtLut::setPrecision() {
00282 
00283   nbit_phi  = 12;
00284   nbit_phib = 10;
00285 
00286 }