Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:02

0001 //-------------------------------------------------
0002 //
0003 //   Class: DTTracoLUTs
0004 //
0005 //   Description: Look-up tables for phi radial angle and
0006 //   psi angle from angle and position in traco
0007 //
0008 //   Author :
0009 //   Sara Vanini - 10/III/03 - INFN Padova
0010 //   17/III/07 SV : delete SimpleConfigurable dependence
0011 //--------------------------------------------------
0012 // #include "Utilities/Configuration/interface/Architecture.h"
0013 
0014 //-----------------------
0015 // This Class's Header --
0016 //-----------------------
0017 
0018 #include "L1Trigger/DTTraco/interface/DTTracoLUTs.h"
0019 
0020 //---------------
0021 // C++ Headers --
0022 //---------------
0023 #include <algorithm>
0024 #include <cmath>
0025 #include <iomanip>
0026 #include <iostream>
0027 #include <string>
0028 
0029 //-------------------------------
0030 // Collaborating Class Headers --
0031 //-------------------------------
0032 
0033 #include "L1Trigger/DTUtilities/interface/DTTPGLutFile.h"
0034 
0035 using namespace std;
0036 
0037 // --------------------------------
0038 //       class DTTracoLUTs
0039 //---------------------------------
0040 
0041 //----------------
0042 // Constructors --
0043 //----------------
0044 
0045 DTTracoLUTs::DTTracoLUTs(string testfile) : _testfile(testfile) {}
0046 
0047 //--------------
0048 // Destructor --
0049 //--------------
0050 
0051 DTTracoLUTs::~DTTracoLUTs() {
0052   psi_lut.clear();
0053   for (int k = 0; k < 3; k++)
0054     phi_lut[k].clear();
0055 }
0056 
0057 //--------------
0058 // Operations --
0059 //--------------
0060 
0061 //
0062 // reset look-up tables
0063 //
0064 void DTTracoLUTs::reset() {
0065   psi_lut.clear();
0066   for (int k = 0; k < 3; k++)
0067     phi_lut[k].clear();
0068 }
0069 
0070 //
0071 // load look-up tables for traco
0072 //
0073 int DTTracoLUTs::load() {
0074   // get file name in current directory
0075   string ang_file = _testfile + ".anglut";
0076   string pos_file = _testfile + ".poslut";
0077 
0078   // open file for PSI
0079   DTTPGLutFile filePSI(ang_file);
0080   if (filePSI.open() != 0)
0081     return -1;
0082 
0083   // ignore comment lines
0084   // filePSI.ignoreLines(14);
0085 
0086   // read file for PSI values --->   psi is 10 bits, 9+sign(10,11...16),
0087   // resolution 9 bits,
0088   for (int u = 0; u < 1024; u++) {
0089     int word = filePSI.readHex();  // read a 16 bits word
0090     // int psi = word & 0x01FF;    //bits  0,1,...8
0091     // int sgn = word & 0x0200;    //bit 9
0092     // if(sgn)
0093     // psi = -psi;
0094     psi_lut.push_back(word);  // positive value
0095   }
0096   filePSI.close();
0097 
0098   // open file for PHI
0099   DTTPGLutFile filePHI(pos_file);
0100   if (filePHI.open() != 0)
0101     return -1;
0102 
0103   // read file for PHI values    --->  phi is 12 bits, 11+sign(12..16),
0104   // resolution 12 bits
0105   for (int y = 0; y < 3; y++) {  // 3 series of values: I-outer, II-innner, III-correlated
0106     for (int h = 0; h < 512; h++) {
0107       int phi = filePHI.readHex();
0108       // phi &= 0x0FFF;                //get 12 bits
0109       // int sgn = phi;
0110       // sgn >> 11;                    //bit 12 for sign
0111       // sgn &= 0x01;
0112       // if(sgn==1)                    //negative value
0113       // phi = -phi;
0114       phi_lut[y].push_back(phi);  // positive value
0115     }
0116   }
0117   filePHI.close();
0118   return 0;
0119 }
0120 
0121 //
0122 // print look-up tables for EMU
0123 //
0124 void DTTracoLUTs::print() const {
0125   cout << endl;
0126   cout << "L1 barrel Traco look-up tables :" << endl;
0127   cout << "====================================================" << endl;
0128   cout << endl;
0129 
0130   //  int i = 0;
0131   //  for debugging
0132   for (int x = 0; x < 1024; x++)
0133     cout << "K=" << x << " ---> " << hex << psi_lut[x] << dec << endl;
0134   for (int m = 0; m < 512; m++)
0135     cout << "X=" << m << " ---> " << hex << (phi_lut[0])[m] << "  " << (phi_lut[1])[m] << "  " << (phi_lut[2])[m]
0136          << "  " << dec << endl;
0137 }
0138 
0139 //
0140 // get phi radial value for a given position
0141 //
0142 unsigned short int DTTracoLUTs::getPhiRad(int pos, int flag) const {
0143   unsigned short int phi = (phi_lut[flag])[pos] & 0xFFF;  // 12 bits
0144   // int sgn = (phi_lut[flag])[pos]  &  0x800;     //bit 12 for sign
0145   // if(sgn)
0146   // phi = - phi;
0147 
0148   return phi;
0149 }
0150 
0151 //
0152 // get psi value for a given angle
0153 //
0154 unsigned short int DTTracoLUTs::getPsi(int ang) const {
0155   unsigned short int ipsi = (psi_lut)[ang + 512];  // scritto in complemento a
0156                                                    // due
0157   /*
0158     //debug: try with formula
0159     float fpsi = atan( ((float)(ang) * 4.2) /(18 * 1.3 * 30 ));
0160     fpsi*=512;
0161     if(fpsi<=0)fpsi-=1.0;
0162     int ipsi = (int)fpsi;
0163     // if outside range set to lower edge
0164     if( ipsi>= 512 ||
0165         ipsi< -512 ) ipsi=-512;
0166   cout << "psi is="<<ipsi <<endl;
0167   */
0168   return ipsi;
0169 }
0170 
0171 //
0172 // get bending angle
0173 //
0174 unsigned short int DTTracoLUTs::getBendAng(int pos, int ang, int flag) const {
0175   // bendAng = psi - phi  : psi ha risoluzione 12, phi 9, quindi devo riportarli
0176   // alla stessa risoluzione con : phi/8 (scarto i 3 bit meno significativi). Il
0177   // risultato ha risoluzione 10 bits.
0178   unsigned short int BendAng = ((psi_lut)[ang + 512] - ((phi_lut[flag])[pos] / 8)) & 0x3FF;  // 10 bits
0179 
0180   // cout << "Bending angle is:" << hex << BendAng << endl;
0181   // cout << "Abs of bending angle is:" << hex << abs(BendAng) << endl;
0182 
0183   return BendAng;
0184 }