CMS 3D CMS Logo

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