CMS 3D CMS Logo

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

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