CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:26:38 2009 for CMSSW by  doxygen 1.5.4