CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/L1Trigger/DTTraco/src/DTTracoLUTs.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: DTTracoLUTs
00004 //
00005 //   Description: Look-up tables for phi radial angle and
00006 //   psi angle from angle and position in traco
00007 //
00008 //   Author :
00009 //   Sara Vanini - 10/III/03 - INFN Padova
00010 //   17/III/07 SV : delete SimpleConfigurable dependence
00011 //--------------------------------------------------
00012 // #include "Utilities/Configuration/interface/Architecture.h"
00013 
00014 //-----------------------
00015 // This Class's Header --
00016 //-----------------------
00017 
00018 #include "L1Trigger/DTTraco/interface/DTTracoLUTs.h"
00019 
00020 //---------------
00021 // C++ Headers --
00022 //---------------
00023 #include <iostream>
00024 #include <iomanip>
00025 #include <string>
00026 #include <cmath>
00027 #include <algorithm>
00028 
00029 //-------------------------------
00030 // Collaborating Class Headers --
00031 //-------------------------------
00032 
00033 #include "L1Trigger/DTUtilities/interface/DTTPGLutFile.h"
00034 
00035 using namespace std;
00036 
00037 // --------------------------------
00038 //       class DTTracoLUTs
00039 //---------------------------------
00040 
00041 //----------------
00042 // Constructors --
00043 //----------------
00044 
00045 DTTracoLUTs::DTTracoLUTs(string testfile):
00046                         _testfile(testfile) {
00047 }
00048 
00049 
00050 //--------------
00051 // Destructor --
00052 //--------------
00053 
00054 DTTracoLUTs::~DTTracoLUTs() {
00055 
00056   psi_lut.clear();
00057   for(int k=0;k<3;k++)
00058     phi_lut[k].clear();
00059 }
00060 
00061 
00062 //--------------
00063 // Operations --
00064 //--------------
00065 
00066 //
00067 // reset look-up tables
00068 //
00069 void DTTracoLUTs::reset() {
00070 
00071   psi_lut.clear();
00072   for(int k=0;k<3;k++)
00073     phi_lut[k].clear();
00074 }
00075 
00076 
00077 //
00078 // load look-up tables for traco
00079 //
00080 int DTTracoLUTs::load() {
00081 
00082   // get file name in current directory
00083   string ang_file = _testfile + ".anglut";
00084   string pos_file = _testfile + ".poslut";
00085  
00086   // open file for PSI 
00087   DTTPGLutFile filePSI(ang_file);
00088   if ( filePSI.open() != 0 ) return -1;
00089 
00090   // ignore comment lines 
00091   //filePSI.ignoreLines(14);
00092 
00093   // read file for PSI values --->   psi is 10 bits, 9+sign(10,11...16), resolution 9 bits, 
00094   for(int u=0;u<1024;u++){
00095       int word  = filePSI.readHex();  //read a 16 bits word
00096       //int psi = word & 0x01FF;    //bits  0,1,...8
00097       //int sgn = word & 0x0200;    //bit 9
00098       //if(sgn)
00099         //psi = -psi;
00100       psi_lut.push_back(word);      //positive value
00101   }
00102   filePSI.close();
00103  
00104   // open file for PHI 
00105   DTTPGLutFile filePHI(pos_file);
00106   if ( filePHI.open() != 0 ) return -1;
00107 
00108   // read file for PHI values    --->  phi is 12 bits, 11+sign(12..16), resolution 12 bits
00109   for(int y=0;y<3;y++){     //3 series of values: I-outer, II-innner, III-correlated
00110     for(int h=0;h<512;h++){
00111         int phi  = filePHI.readHex();
00112         //phi &= 0x0FFF;                //get 12 bits
00113         //int sgn = phi;
00114         //sgn >> 11;                    //bit 12 for sign
00115         //sgn &= 0x01;
00116         //if(sgn==1)                    //negative value
00117           //phi = -phi;
00118         phi_lut[y].push_back(phi);  //positive value
00119     }
00120   } 
00121   filePHI.close();
00122   return 0;
00123 }
00124 
00125 
00126 //
00127 // print look-up tables for EMU
00128 //
00129 void DTTracoLUTs::print() const {
00130 
00131   cout << endl;
00132   cout << "L1 barrel Traco look-up tables :" << endl;
00133   cout << "====================================================" << endl;
00134   cout << endl;
00135 
00136 //  int i = 0;
00137   //  for debugging
00138   for(int x=0;x<1024;x++)
00139     cout << "K=" << x << " ---> " << hex << psi_lut[x] << dec << endl;
00140   for(int m=0;m<512;m++)
00141     cout << "X=" << m << " ---> " << hex << (phi_lut[0])[m] << "  " 
00142                                   << (phi_lut[1])[m] << "  " 
00143                                   << (phi_lut[2])[m] << "  " << dec << endl; 
00144 
00145 }
00146 
00147 //
00148 // get phi radial value for a given position 
00149 //
00150 unsigned short int DTTracoLUTs::getPhiRad(int pos,int flag) const {
00151   unsigned short int phi = (phi_lut[flag])[pos]  &  0xFFF;     //12 bits
00152   //int sgn = (phi_lut[flag])[pos]  &  0x800;     //bit 12 for sign
00153   //if(sgn)
00154     //phi = - phi;
00155 
00156   return phi;
00157 }
00158 
00159 //
00160 // get psi value for a given angle 
00161 //
00162 unsigned short int DTTracoLUTs::getPsi(int ang) const {
00163 
00164   unsigned short int ipsi = (psi_lut)[ang+512]; //scritto in complemento a due 
00165 /*
00166   //debug: try with formula
00167   float fpsi = atan( ((float)(ang) * 4.2) /(18 * 1.3 * 30 ));
00168   fpsi*=512;
00169   if(fpsi<=0)fpsi-=1.0;
00170   int ipsi = (int)fpsi;
00171   // if outside range set to lower edge
00172   if( ipsi>= 512 ||
00173       ipsi< -512 ) ipsi=-512;
00174 cout << "psi is="<<ipsi <<endl;
00175 */
00176    return ipsi;
00177 }
00178 
00179 //
00180 // get bending angle 
00181 //
00182 unsigned short int DTTracoLUTs::getBendAng(int pos, int ang, int flag) const {
00183   // bendAng = psi - phi  : psi ha risoluzione 12, phi 9, quindi devo riportarli alla
00184   // stessa risoluzione con : phi/8 (scarto i 3 bit meno significativi). 
00185   // Il risultato ha risoluzione 10 bits. 
00186   unsigned short int BendAng = ( (psi_lut)[ang+512] - ((phi_lut[flag])[pos]/8) ) & 0x3FF;    //10 bits
00187    
00188   //cout << "Bending angle is:" << hex << BendAng << endl; 
00189   //cout << "Abs of bending angle is:" << hex << abs(BendAng) << endl; 
00190 
00191 
00192   return BendAng;
00193 }
00194 
00195