CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: L1MuDTPtaLut
00004 //
00005 //   Description: Look-up tables for pt 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/L1MuDTPtaLut.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/L1MuDTAssParam.h"
00040 #include "CondFormats/L1TObjects/interface/L1TriggerLutFile.h"
00041 
00042 using namespace std;
00043 
00044 // --------------------------------
00045 //       class L1MuDTPtaLut
00046 //---------------------------------
00047 
00048 //----------------
00049 // Constructors --
00050 //----------------
00051 
00052 L1MuDTPtaLut::L1MuDTPtaLut() : 
00053                   pta_lut(0), 
00054                   pta_threshold(MAX_PTASSMETH/2) {
00055 
00056   pta_lut.reserve(MAX_PTASSMETH);
00057   pta_threshold.reserve(MAX_PTASSMETH/2);
00058   setPrecision();
00059   
00060   //  if ( load() != 0 ) {
00061   //    cout << "Can not open files to load pt-assignment look-up tables for DTTrackFinder!" << endl;
00062   //  }
00063 
00064   //  if ( L1MuDTTFConfig::Debug(6) ) print();
00065   
00066 }
00067 
00068 
00069 //--------------
00070 // Destructor --
00071 //--------------
00072 
00073 L1MuDTPtaLut::~L1MuDTPtaLut() {
00074 
00075   vector<LUT>::iterator iter;
00076   for ( iter = pta_lut.begin(); iter != pta_lut.end(); iter++ ) {
00077     (*iter).clear();
00078   }
00079 
00080   pta_lut.clear();
00081   pta_threshold.clear();
00082 
00083 }
00084 
00085 
00086 //--------------
00087 // Operations --
00088 //--------------
00089 
00090 //
00091 // reset pt-assignment look-up tables
00092 //
00093 void L1MuDTPtaLut::reset() {
00094 
00095   pta_lut.clear();
00096   pta_threshold.clear();
00097 
00098 }
00099 
00100 
00101 //
00102 // load pt-assignment look-up tables
00103 //
00104 int L1MuDTPtaLut::load() {
00105 
00106   // get directory name
00107   string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
00108   string pta_dir = "L1TriggerData/DTTrackFinder/Ass/";
00109   string pta_str = "";
00110 
00111   // precision : in the look-up tables the following precision is used :
00112   // phi ...12 bits (address) and  pt ...5 bits
00113   // now convert phi and phib to the required precision
00114 
00115   int sh_phi  = 12 - nbit_phi;
00116 
00117   // loop over all pt-assignment methods
00118   for ( int pam = 0; pam < MAX_PTASSMETH; pam++ ) { 
00119     switch ( pam ) {
00120       case PT12L  : { pta_str = "pta12l"; break; }
00121       case PT12H  : { pta_str = "pta12h"; break; }
00122       case PT13L  : { pta_str = "pta13l"; break; }
00123       case PT13H  : { pta_str = "pta13h"; break; }
00124       case PT14L  : { pta_str = "pta14l"; break; }
00125       case PT14H  : { pta_str = "pta14h"; break; }
00126       case PT23L  : { pta_str = "pta23l"; break; }
00127       case PT23H  : { pta_str = "pta23h"; break; }
00128       case PT24L  : { pta_str = "pta24l"; break; }
00129       case PT24H  : { pta_str = "pta24h"; break; }
00130       case PT34L  : { pta_str = "pta34l"; break; }
00131       case PT34H  : { pta_str = "pta34h"; break; }
00132       case PT12LO : { pta_str = "pta12l_ovl"; break; }
00133       case PT12HO : { pta_str = "pta12h_ovl"; break; }
00134       case PT13LO : { pta_str = "pta13l_ovl"; break; }
00135       case PT13HO : { pta_str = "pta13h_ovl"; break; }
00136       case PT14LO : { pta_str = "pta14l_ovl"; break; }
00137       case PT14HO : { pta_str = "pta14h_ovl"; break; }
00138       case PT23LO : { pta_str = "pta23l_ovl"; break; }
00139       case PT23HO : { pta_str = "pta23h_ovl"; break; }
00140       case PT24LO : { pta_str = "pta24l_ovl"; break; }
00141       case PT24HO : { pta_str = "pta24h_ovl"; break; }
00142       case PT34LO : { pta_str = "pta34l_ovl"; break; }
00143       case PT34HO : { pta_str = "pta34h_ovl"; break; }
00144       case PT15LO : { pta_str = "pta15l_ovl"; break; }
00145       case PT15HO : { pta_str = "pta15h_ovl"; break; }
00146       case PT25LO : { pta_str = "pta25l_ovl"; break; }
00147       case PT25HO : { pta_str = "pta25h_ovl"; break; }      
00148     }
00149 
00150     // assemble file name
00151     edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + pta_dir + pta_str + ".lut"));
00152     string pta_file = lut_f.fullPath();
00153 
00154     // open file
00155     L1TriggerLutFile file(pta_file);
00156     if ( file.open() != 0 ) return -1;
00157     //    if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : " 
00158     //                                         << file.getName() << endl; 
00159 
00160     // get the right shift factor
00161     int shift = sh_phi;
00162     int adr_old = -2048 >> shift;
00163 
00164     LUT tmplut;
00165 
00166     int number = -1;
00167     int sum_pt = 0;
00168 
00169     if ( file.good() ) {
00170       int threshold = file.readInteger();
00171       pta_threshold[pam/2] = threshold;
00172     }
00173     
00174     // read values and shift to correct precision
00175     while ( file.good() ) {
00176         
00177       int adr = (file.readInteger()) >> shift;
00178       int pt  = file.readInteger();
00179 
00180       number++;
00181       
00182       if ( adr != adr_old ) {
00183         assert(number);
00184         tmplut.insert(make_pair( adr_old, (sum_pt/number) ));
00185 
00186         adr_old = adr;
00187         number = 0;
00188         sum_pt = 0;
00189       }
00190       
00191       sum_pt += pt;
00192       
00193       if ( !file.good() ) file.close();
00194       
00195     }
00196 
00197     file.close();
00198     pta_lut.push_back(tmplut);
00199   }
00200   return 0;
00201 
00202 }
00203 
00204 
00205 //
00206 // print pt-assignment look-up tables
00207 //
00208 void L1MuDTPtaLut::print() const {
00209 
00210   cout << endl;
00211   cout << "L1 barrel Track Finder Pt-Assignment look-up tables :" << endl;
00212   cout << "=====================================================" << endl;
00213   cout << endl;
00214   cout << "Precision : " << endl;
00215   cout << '\t' << setw(2) << nbit_phi  << " bits are used for phi "  << endl;
00216 
00217   // loop over all pt-assignment methods
00218   for ( int pam = 0; pam < MAX_PTASSMETH; pam++ ) {
00219  
00220     cout << endl;
00221     cout << "Pt-Assignment Method : " << static_cast<PtAssMethod>(pam) << endl;
00222     cout << "============================" << endl;
00223     cout << endl;
00224 
00225     cout << "\t Threshold : " << getPtLutThreshold(pam/2) << endl << endl;
00226 
00227     int maxbits = nbit_phi;
00228   
00229     cout << "      address";
00230     for ( int i = 0; i < maxbits; i++ ) cout << ' ';
00231     cout << "  value" << endl;
00232     for ( int i = 0; i < maxbits; i++ ) cout << '-';    
00233     cout << "-------------------------" << endl;
00234 
00235     LUT::const_iterator iter = pta_lut[pam].begin();
00236     while ( iter != pta_lut[pam].end() ) {
00237       int address = (*iter).first;
00238       int value   = (*iter).second;
00239 
00240       DTTFBitArray<12> b_address(static_cast<unsigned>(abs(address)));
00241       DTTFBitArray<5> b_value(static_cast<unsigned>(abs(value)));
00242 
00243       if ( address < 0 ) b_address.twoComplement();
00244 
00245       cout.setf(ios::right,ios::adjustfield);
00246       cout << " " << setbase(10) << setw(5) << address << " (";
00247       for ( int i = maxbits-1; i >= 0; i-- ) cout << b_address[i];  
00248       cout << ")   " << setw(3) << value << " (";
00249       b_value.print();
00250       cout << ")" << endl;
00251 
00252       iter++;
00253     }
00254     
00255   }
00256 
00257   cout << endl;   
00258   
00259 }
00260 
00261 
00262 //
00263 // get pt value for a given address
00264 //
00265 int L1MuDTPtaLut::getPt(int pta_ind, int address) const {
00266 
00267   LUT::const_iterator iter = pta_lut[pta_ind].find(address);
00268   if ( iter != pta_lut[pta_ind].end() ) {
00269     return (*iter).second;
00270   }
00271   else {
00272     cerr << "PtaLut::getPt : can not find address " << address << endl;
00273     return 0;
00274   }
00275 
00276 }
00277 
00278 
00279 //
00280 // get pt-assignment LUT threshold
00281 //
00282 int L1MuDTPtaLut::getPtLutThreshold(int pta_ind) const {
00283 
00284   if ( pta_ind >= 0 && pta_ind < MAX_PTASSMETH/2 ) {
00285     return pta_threshold[pta_ind];
00286   }
00287   else {
00288     cerr << "PtaLut::getPtLutThreshold : can not find threshold " << pta_ind << endl;
00289     return 0;
00290   }
00291 
00292 }
00293 
00294 
00295 //
00296 // set precision for look-up tables
00297 //
00298 void L1MuDTPtaLut::setPrecision() {
00299 
00300   nbit_phi  = 12;  
00301 
00302 }