CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CondFormats/L1TObjects/src/L1MuDTPhiLut.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: L1MuDTPhiLut
00004 //
00005 //   Description: Look-up tables for phi assignment 
00006 //
00007 //
00008 //   $Date: 2012/08/05 12:48:33 $
00009 //   $Revision: 1.8 $
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/L1MuDTPhiLut.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/L1TriggerLutFile.h"
00040 
00041 using namespace std;
00042 
00043 // --------------------------------
00044 //       class L1MuDTPhiLut
00045 //---------------------------------
00046 
00047 //----------------
00048 // Constructors --
00049 //----------------
00050 
00051 L1MuDTPhiLut::L1MuDTPhiLut() {
00052 
00053   phi_lut.reserve(2);
00054   setPrecision();
00055   //  if ( load() != 0 ) {
00056   //    cout << "Can not open files to load phi-assignment look-up tables for DTTrackFinder!" << endl;
00057   //  }
00058 
00059   //  if ( L1MuDTTFConfig::Debug(6) ) print();
00060 
00061 }
00062 
00063 
00064 //--------------
00065 // Destructor --
00066 //--------------
00067 
00068 L1MuDTPhiLut::~L1MuDTPhiLut() {
00069 
00070   vector<LUT>::iterator iter;
00071   for ( iter = phi_lut.begin(); iter != phi_lut.end(); iter++ ) {
00072     (*iter).clear();
00073   }
00074 
00075   phi_lut.clear();
00076 
00077 }
00078 
00079 
00080 //--------------
00081 // Operations --
00082 //--------------
00083 
00084 //
00085 // reset phi-assignment look-up tables
00086 //
00087 void L1MuDTPhiLut::reset() {
00088 
00089   phi_lut.clear();
00090 
00091 }
00092 
00093 
00094 //
00095 // load phi-assignment look-up tables
00096 //
00097 int L1MuDTPhiLut::load() {
00098 
00099   // get directory name
00100   string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
00101   string phi_dir = "L1TriggerData/DTTrackFinder/Ass/";
00102   string phi_str = "";
00103 
00104   // precision : in the look-up tables the following precision is used :
00105   // address (phib) ...10 bits, phi ... 12 bits
00106 
00107   int sh_phi  = 12 - nbit_phi;
00108   int sh_phib = 10 - nbit_phib;
00109 
00110   // loop over all phi-assignment methods
00111   for ( int idx = 0; idx < 2; idx++ ) {
00112     switch ( idx ) {
00113       case 0 : { phi_str = "phi12"; break; }
00114       case 1 : { phi_str = "phi42"; break; }
00115     }
00116 
00117     // assemble file name
00118     edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + phi_dir + phi_str + ".lut"));
00119     string phi_file = lut_f.fullPath();
00120 
00121     // open file
00122     L1TriggerLutFile file(phi_file);
00123     if ( file.open() != 0 ) return -1;
00124     //    if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : " 
00125     //                                         << file.getName() << endl; 
00126 
00127     LUT tmplut;
00128 
00129     int number = -1;
00130     int adr_old = -512 >> sh_phib;
00131     int sum_phi = 0;
00132 
00133     // read values
00134     while ( file.good() ) {
00135     
00136       int adr = (file.readInteger()) >> sh_phib;
00137       int phi =  file.readInteger();
00138       
00139       number++;
00140 
00141       if ( adr != adr_old ) {
00142         assert(number);
00143         tmplut.insert(make_pair( adr_old, ((sum_phi/number) >> sh_phi) ));
00144 
00145         adr_old = adr;
00146         number = 0;
00147         sum_phi  = 0;
00148       }
00149       
00150       sum_phi += phi;
00151 
00152       if ( !file.good() ) file.close();
00153 
00154     }
00155 
00156     file.close();
00157     phi_lut.push_back(tmplut);
00158   } 
00159   return 0;
00160 
00161 }
00162 
00163 
00164 //
00165 // print phi-assignment look-up tables
00166 //
00167 void L1MuDTPhiLut::print() const {
00168 
00169   cout << endl;
00170   cout << "L1 barrel Track Finder Phi-Assignment look-up tables :" << endl;
00171   cout << "======================================================" << endl;
00172   cout << endl;
00173   cout << "Precision : " << endl;
00174   cout << '\t' << setw(2) << nbit_phi  << " bits are used for phi "  << endl;
00175   cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
00176 
00177   // loop over all phi-assignment methods
00178   for ( int idx = 0; idx < 2; idx++ ) { 
00179 
00180     cout << endl;
00181     if ( idx == 0 ) cout << "Phi-Assignment Method : " << "PHI12" << endl;
00182     if ( idx == 1 ) cout << "Phi-Assignment Method : " << "PHI42" << endl;    
00183     cout << "=============================" << endl;
00184     cout << endl;
00185 
00186     cout << "      address";
00187     for ( int i = 0; i < nbit_phib; i++ ) cout << ' ';
00188     cout << "    value" << endl;
00189     for ( int i = 0; i < nbit_phi + nbit_phib; i++ ) cout << '-';
00190     cout << "----------------------" << endl;
00191 
00192     LUT::const_iterator iter = phi_lut[idx].begin();
00193     while ( iter != phi_lut[idx].end() ) {
00194       int address = (*iter).first;
00195       int value   = (*iter).second;
00196 
00197       DTTFBitArray<10> b_address(static_cast<unsigned>(abs(address)));
00198       DTTFBitArray<12> b_value(static_cast<unsigned>(abs(value)));
00199 
00200       if ( address < 0 ) b_address.twoComplement();
00201       if ( value < 0 ) b_value.twoComplement();
00202 
00203       cout.setf(ios::right,ios::adjustfield);
00204       cout << " " << setbase(10) << setw(5) << address << " (";
00205       for ( int i = nbit_phib-1; i >= 0; i-- ) cout << b_address[i];
00206       cout << ")   " << setw(5) << value  << " (";
00207       for ( int i = nbit_phi-1; i >= 0; i-- ) cout << b_value[i];
00208       cout << ")  " << endl;
00209 
00210       iter++;
00211     }
00212     
00213   }
00214 
00215   cout << endl;   
00216   
00217 }
00218 
00219 
00220 //
00221 // get delta-phi value for a given address
00222 //
00223 int L1MuDTPhiLut::getDeltaPhi(int idx, int address) const {
00224 
00225   LUT::const_iterator iter = phi_lut[idx].find(address);
00226   if ( iter != phi_lut[idx].end() ) {
00227     return (*iter).second;
00228   }
00229   else {
00230     cerr << "PhiLut::getDeltaPhi : can not find address " << address << endl;
00231     return 0;
00232   }
00233 
00234 }
00235 
00236 
00237 //
00238 // set precision for look-up tables
00239 //
00240 void L1MuDTPhiLut::setPrecision() {
00241 
00242   nbit_phi  = 12;
00243   nbit_phib = 10;
00244 
00245 }
00246 
00247 
00248 //
00249 // get precision for look-up tables
00250 //
00251 pair<unsigned short, unsigned short> L1MuDTPhiLut::getPrecision() const {
00252 
00253   return pair<unsigned short, unsigned short>(nbit_phi,nbit_phib);
00254 
00255 }