CMS 3D CMS Logo

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 
53  psi_lut.clear();
54  for (int k = 0; k < 3; k++)
55  phi_lut[k].clear();
56 }
57 
58 //--------------
59 // Operations --
60 //--------------
61 
62 //
63 // reset look-up tables
64 //
66 
67  psi_lut.clear();
68  for (int k = 0; k < 3; k++)
69  phi_lut[k].clear();
70 }
71 
72 //
73 // load look-up tables for traco
74 //
76 
77  // get file name in current directory
78  string ang_file = _testfile + ".anglut";
79  string pos_file = _testfile + ".poslut";
80 
81  // open file for PSI
82  DTTPGLutFile filePSI(ang_file);
83  if (filePSI.open() != 0)
84  return -1;
85 
86  // ignore comment lines
87  // filePSI.ignoreLines(14);
88 
89  // read file for PSI values ---> psi is 10 bits, 9+sign(10,11...16),
90  // resolution 9 bits,
91  for (int u = 0; u < 1024; u++) {
92  int word = filePSI.readHex(); // read a 16 bits word
93  // int psi = word & 0x01FF; //bits 0,1,...8
94  // int sgn = word & 0x0200; //bit 9
95  // if(sgn)
96  // psi = -psi;
97  psi_lut.push_back(word); // positive value
98  }
99  filePSI.close();
100 
101  // open file for PHI
102  DTTPGLutFile filePHI(pos_file);
103  if (filePHI.open() != 0)
104  return -1;
105 
106  // read file for PHI values ---> phi is 12 bits, 11+sign(12..16),
107  // resolution 12 bits
108  for (int y = 0; y < 3;
109  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 // print look-up tables for EMU
127 //
128 void DTTracoLUTs::print() const {
129 
130  cout << endl;
131  cout << "L1 barrel Traco look-up tables :" << endl;
132  cout << "====================================================" << endl;
133  cout << endl;
134 
135  // int i = 0;
136  // for debugging
137  for (int x = 0; x < 1024; x++)
138  cout << "K=" << x << " ---> " << hex << psi_lut[x] << dec << endl;
139  for (int m = 0; m < 512; m++)
140  cout << "X=" << m << " ---> " << hex << (phi_lut[0])[m] << " "
141  << (phi_lut[1])[m] << " " << (phi_lut[2])[m] << " " << dec << endl;
142 }
143 
144 //
145 // get phi radial value for a given position
146 //
147 unsigned short int DTTracoLUTs::getPhiRad(int pos, int flag) const {
148  unsigned short int phi = (phi_lut[flag])[pos] & 0xFFF; // 12 bits
149  // int sgn = (phi_lut[flag])[pos] & 0x800; //bit 12 for sign
150  // if(sgn)
151  // phi = - phi;
152 
153  return phi;
154 }
155 
156 //
157 // get psi value for a given angle
158 //
159 unsigned short int DTTracoLUTs::getPsi(int ang) const {
160 
161  unsigned short int ipsi = (psi_lut)[ang + 512]; // scritto in complemento a
162  // due
163  /*
164  //debug: try with formula
165  float fpsi = atan( ((float)(ang) * 4.2) /(18 * 1.3 * 30 ));
166  fpsi*=512;
167  if(fpsi<=0)fpsi-=1.0;
168  int ipsi = (int)fpsi;
169  // if outside range set to lower edge
170  if( ipsi>= 512 ||
171  ipsi< -512 ) ipsi=-512;
172  cout << "psi is="<<ipsi <<endl;
173  */
174  return ipsi;
175 }
176 
177 //
178 // get bending angle
179 //
180 unsigned short int DTTracoLUTs::getBendAng(int pos, int ang, int flag) const {
181  // bendAng = psi - phi : psi ha risoluzione 12, phi 9, quindi devo riportarli
182  // alla stessa risoluzione con : phi/8 (scarto i 3 bit meno significativi). Il
183  // risultato ha risoluzione 10 bits.
184  unsigned short int BendAng =
185  ((psi_lut)[ang + 512] - ((phi_lut[flag])[pos] / 8)) & 0x3FF; // 10 bits
186 
187  // cout << "Bending angle is:" << hex << BendAng << endl;
188  // cout << "Abs of bending angle is:" << hex << abs(BendAng) << endl;
189 
190  return BendAng;
191 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
unsigned short int getBendAng(int pos, int ang, int qualflag) const
return bending angle from pos and ang
Definition: DTTracoLUTs.cc:180
LUT phi_lut[3]
Definition: DTTracoLUTs.h:67
DTTracoLUTs(std::string filename)
constructor
Definition: DTTracoLUTs.cc:45
void reset()
reset look-up tables
Definition: DTTracoLUTs.cc:65
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
virtual ~DTTracoLUTs()
destructor
Definition: DTTracoLUTs.cc:51
int load()
load look-up tables
Definition: DTTracoLUTs.cc:75
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:147
int readHex()
read one hex from file
Definition: DTTPGLutFile.cc:87
std::string _testfile
Definition: DTTracoLUTs.h:69
void print() const
print look-up tables
Definition: DTTracoLUTs.cc:128
unsigned short int getPsi(int ang) const
get psi angle from traco k parameter
Definition: DTTracoLUTs.cc:159
int open()
open file
Definition: DTTPGLutFile.cc:61
void close()
close file
Definition: DTTPGLutFile.h:63