CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTTracoLUTs.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: DTTracoLUTs
4 //
5 // Description: Look-up tables for phi radial angle and
6 // psi angle from angle and position in traco
7 //
8 // Author :
9 // Sara Vanini - 10/III/03 - INFN Padova
10 // 17/III/07 SV : delete SimpleConfigurable dependence
11 //--------------------------------------------------
12 // #include "Utilities/Configuration/interface/Architecture.h"
13 
14 //-----------------------
15 // This Class's Header --
16 //-----------------------
17 
19 
20 //---------------
21 // C++ Headers --
22 //---------------
23 #include <iostream>
24 #include <iomanip>
25 #include <string>
26 #include <cmath>
27 #include <algorithm>
28 
29 //-------------------------------
30 // Collaborating Class Headers --
31 //-------------------------------
32 
34 
35 using namespace std;
36 
37 // --------------------------------
38 // class DTTracoLUTs
39 //---------------------------------
40 
41 //----------------
42 // Constructors --
43 //----------------
44 
45 DTTracoLUTs::DTTracoLUTs(string testfile):
46  _testfile(testfile) {
47 }
48 
49 
50 //--------------
51 // Destructor --
52 //--------------
53 
55 
56  psi_lut.clear();
57  for(int k=0;k<3;k++)
58  phi_lut[k].clear();
59 }
60 
61 
62 //--------------
63 // Operations --
64 //--------------
65 
66 //
67 // reset look-up tables
68 //
70 
71  psi_lut.clear();
72  for(int k=0;k<3;k++)
73  phi_lut[k].clear();
74 }
75 
76 
77 //
78 // load look-up tables for traco
79 //
81 
82  // get file name in current directory
83  string ang_file = _testfile + ".anglut";
84  string pos_file = _testfile + ".poslut";
85 
86  // open file for PSI
87  DTTPGLutFile filePSI(ang_file);
88  if ( filePSI.open() != 0 ) return -1;
89 
90  // ignore comment lines
91  //filePSI.ignoreLines(14);
92 
93  // read file for PSI values ---> psi is 10 bits, 9+sign(10,11...16), resolution 9 bits,
94  for(int u=0;u<1024;u++){
95  int word = filePSI.readHex(); //read a 16 bits word
96  //int psi = word & 0x01FF; //bits 0,1,...8
97  //int sgn = word & 0x0200; //bit 9
98  //if(sgn)
99  //psi = -psi;
100  psi_lut.push_back(word); //positive value
101  }
102  filePSI.close();
103 
104  // open file for PHI
105  DTTPGLutFile filePHI(pos_file);
106  if ( filePHI.open() != 0 ) return -1;
107 
108  // read file for PHI values ---> phi is 12 bits, 11+sign(12..16), resolution 12 bits
109  for(int y=0;y<3;y++){ //3 series of values: I-outer, II-innner, III-correlated
110  for(int h=0;h<512;h++){
111  int phi = filePHI.readHex();
112  //phi &= 0x0FFF; //get 12 bits
113  //int sgn = phi;
114  //sgn >> 11; //bit 12 for sign
115  //sgn &= 0x01;
116  //if(sgn==1) //negative value
117  //phi = -phi;
118  phi_lut[y].push_back(phi); //positive value
119  }
120  }
121  filePHI.close();
122  return 0;
123 }
124 
125 
126 //
127 // print look-up tables for EMU
128 //
129 void DTTracoLUTs::print() const {
130 
131  cout << endl;
132  cout << "L1 barrel Traco look-up tables :" << endl;
133  cout << "====================================================" << endl;
134  cout << endl;
135 
136 // int i = 0;
137  // for debugging
138  for(int x=0;x<1024;x++)
139  cout << "K=" << x << " ---> " << hex << psi_lut[x] << dec << endl;
140  for(int m=0;m<512;m++)
141  cout << "X=" << m << " ---> " << hex << (phi_lut[0])[m] << " "
142  << (phi_lut[1])[m] << " "
143  << (phi_lut[2])[m] << " " << dec << endl;
144 
145 }
146 
147 //
148 // get phi radial value for a given position
149 //
150 unsigned short int DTTracoLUTs::getPhiRad(int pos,int flag) const {
151  unsigned short int phi = (phi_lut[flag])[pos] & 0xFFF; //12 bits
152  //int sgn = (phi_lut[flag])[pos] & 0x800; //bit 12 for sign
153  //if(sgn)
154  //phi = - phi;
155 
156  return phi;
157 }
158 
159 //
160 // get psi value for a given angle
161 //
162 unsigned short int DTTracoLUTs::getPsi(int ang) const {
163 
164  unsigned short int ipsi = (psi_lut)[ang+512]; //scritto in complemento a due
165 /*
166  //debug: try with formula
167  float fpsi = atan( ((float)(ang) * 4.2) /(18 * 1.3 * 30 ));
168  fpsi*=512;
169  if(fpsi<=0)fpsi-=1.0;
170  int ipsi = (int)fpsi;
171  // if outside range set to lower edge
172  if( ipsi>= 512 ||
173  ipsi< -512 ) ipsi=-512;
174 cout << "psi is="<<ipsi <<endl;
175 */
176  return ipsi;
177 }
178 
179 //
180 // get bending angle
181 //
182 unsigned short int DTTracoLUTs::getBendAng(int pos, int ang, int flag) const {
183  // bendAng = psi - phi : psi ha risoluzione 12, phi 9, quindi devo riportarli alla
184  // stessa risoluzione con : phi/8 (scarto i 3 bit meno significativi).
185  // Il risultato ha risoluzione 10 bits.
186  unsigned short int BendAng = ( (psi_lut)[ang+512] - ((phi_lut[flag])[pos]/8) ) & 0x3FF; //10 bits
187 
188  //cout << "Bending angle is:" << hex << BendAng << endl;
189  //cout << "Abs of bending angle is:" << hex << abs(BendAng) << endl;
190 
191 
192  return BendAng;
193 }
194 
195 
long int flag
Definition: mlp_lapack.h:47
unsigned short int getBendAng(int pos, int ang, int qualflag) const
return bending angle from pos and ang
Definition: DTTracoLUTs.cc:182
LUT phi_lut[3]
Definition: DTTracoLUTs.h:71
DTTracoLUTs(std::string filename)
constructor
Definition: DTTracoLUTs.cc:45
void reset()
reset look-up tables
Definition: DTTracoLUTs.cc:69
virtual ~DTTracoLUTs()
destructor
Definition: DTTracoLUTs.cc:54
int load()
load look-up tables
Definition: DTTracoLUTs.cc:80
int k[5][pyjets_maxn]
unsigned short int getPhiRad(int pos, int qualflag) const
get radial angle from traco position and flag: 0=outer, 1=inner, 2=correl.
Definition: DTTracoLUTs.cc:150
int readHex()
read one hex from file
Definition: DTTPGLutFile.cc:98
std::string _testfile
Definition: DTTracoLUTs.h:73
void print() const
print look-up tables
Definition: DTTracoLUTs.cc:129
unsigned short int getPsi(int ang) const
get psi angle from traco k parameter
Definition: DTTracoLUTs.cc:162
int open()
open file
Definition: DTTPGLutFile.cc:66
void close()
close file
Definition: DTTPGLutFile.h:66
tuple cout
Definition: gather_cfg.py:41
Definition: DDAxes.h:10
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
Definition: DDAxes.h:10