CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/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: 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/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         tmplut.insert(make_pair( adr_old, ((sum_phi/number) >> sh_phi) ));
00143 
00144         adr_old = adr;
00145         number = 0;
00146         sum_phi  = 0;
00147       }
00148       
00149       sum_phi += phi;
00150 
00151       if ( !file.good() ) file.close();
00152 
00153     }
00154 
00155     file.close();
00156     phi_lut.push_back(tmplut);
00157   } 
00158   return 0;
00159 
00160 }
00161 
00162 
00163 //
00164 // print phi-assignment look-up tables
00165 //
00166 void L1MuDTPhiLut::print() const {
00167 
00168   cout << endl;
00169   cout << "L1 barrel Track Finder Phi-Assignment look-up tables :" << endl;
00170   cout << "======================================================" << endl;
00171   cout << endl;
00172   cout << "Precision : " << endl;
00173   cout << '\t' << setw(2) << nbit_phi  << " bits are used for phi "  << endl;
00174   cout << '\t' << setw(2) << nbit_phib << " bits are used for phib " << endl;
00175 
00176   // loop over all phi-assignment methods
00177   for ( int idx = 0; idx < 2; idx++ ) { 
00178 
00179     cout << endl;
00180     if ( idx == 0 ) cout << "Phi-Assignment Method : " << "PHI12" << endl;
00181     if ( idx == 1 ) cout << "Phi-Assignment Method : " << "PHI42" << endl;    
00182     cout << "=============================" << endl;
00183     cout << endl;
00184 
00185     cout << "      address";
00186     for ( int i = 0; i < nbit_phib; i++ ) cout << ' ';
00187     cout << "    value" << endl;
00188     for ( int i = 0; i < nbit_phi + nbit_phib; i++ ) cout << '-';
00189     cout << "----------------------" << endl;
00190 
00191     LUT::const_iterator iter = phi_lut[idx].begin();
00192     while ( iter != phi_lut[idx].end() ) {
00193       int address = (*iter).first;
00194       int value   = (*iter).second;
00195 
00196       DTTFBitArray<10> b_address(static_cast<unsigned>(abs(address)));
00197       DTTFBitArray<12> b_value(static_cast<unsigned>(abs(value)));
00198 
00199       if ( address < 0 ) b_address.twoComplement();
00200       if ( value < 0 ) b_value.twoComplement();
00201 
00202       cout.setf(ios::right,ios::adjustfield);
00203       cout << " " << setbase(10) << setw(5) << address << " (";
00204       for ( int i = nbit_phib-1; i >= 0; i-- ) cout << b_address[i];
00205       cout << ")   " << setw(5) << value  << " (";
00206       for ( int i = nbit_phi-1; i >= 0; i-- ) cout << b_value[i];
00207       cout << ")  " << endl;
00208 
00209       iter++;
00210     }
00211     
00212   }
00213 
00214   cout << endl;   
00215   
00216 }
00217 
00218 
00219 //
00220 // get delta-phi value for a given address
00221 //
00222 int L1MuDTPhiLut::getDeltaPhi(int idx, int address) const {
00223 
00224   LUT::const_iterator iter = phi_lut[idx].find(address);
00225   if ( iter != phi_lut[idx].end() ) {
00226     return (*iter).second;
00227   }
00228   else {
00229     cerr << "PhiLut::getDeltaPhi : can not find address " << address << endl;
00230     return 0;
00231   }
00232 
00233 }
00234 
00235 
00236 //
00237 // set precision for look-up tables
00238 //
00239 void L1MuDTPhiLut::setPrecision() {
00240 
00241   nbit_phi  = 12;
00242   nbit_phib = 10;
00243 
00244 }
00245 
00246 
00247 //
00248 // get precision for look-up tables
00249 //
00250 pair<unsigned short, unsigned short> L1MuDTPhiLut::getPrecision() const {
00251 
00252   return pair<unsigned short, unsigned short>(nbit_phi,nbit_phib);
00253 
00254 }