ATLAS Offline Software
Loading...
Searching...
No Matches
ErrorMatrixCompressor Class Reference

#include <ErrorMatrixCompressor.h>

Collaboration diagram for ErrorMatrixCompressor:

Classes

class  Triplet

Public Member Functions

 ErrorMatrixCompressor (int)
 ~ErrorMatrixCompressor ()
bool compress (const std::vector< double > &, std::vector< unsigned int > &)
bool restore (const std::vector< unsigned int > &, std::vector< double > &)
void setBiases (const int b[6])
void setUpperLimits (const int l[2])

Protected Member Functions

bool CholeskyDecomposition (double a[5][5], double L[5][5])
bool compressFR (const std::vector< FloatRep > &, std::vector< unsigned short > &)
bool restoreFR (const std::vector< unsigned short > &, std::vector< FloatRep > &)

Protected Attributes

short int m_biases [6] {}
short int m_limits [2] {}
double m_scales [5] {}
int m_bitStrip {}

Private Attributes

DecoderFloat_IEEE754 m_decoder
unsigned int m_srcMasks [16] {}
std::vector< Tripletm_tripVec

Detailed Description

Definition at line 112 of file ErrorMatrixCompressor.h.

Constructor & Destructor Documentation

◆ ErrorMatrixCompressor()

ErrorMatrixCompressor::ErrorMatrixCompressor ( int b)

Definition at line 59 of file ErrorMatrixCompressor.cxx.

60{
61 short int biasArray[6] = {116,120,118,116,116,102};
62
63
64 double T[5]={0.2,0.5,100.0,100.0,20000.0};
65
67 for(int i=0;i<6;i++)
68 {
69 m_biases[i]=biasArray[i];
70 }
71 for(int i=0;i<5;i++)
72 {
73 m_scales[i]=T[i];
74 }
75 m_limits[0]=15;
76 m_limits[1]=31;
77 m_srcMasks[0]= 0x80000000;
78 m_srcMasks[1]= 0xC0000000;
79 m_srcMasks[2]= 0xE0000000;
80 m_srcMasks[3]= 0xF0000000;
81 m_srcMasks[4]= 0xF8000000;
82 m_srcMasks[5]= 0xFC000000;
83 m_srcMasks[6]= 0xFE000000;
84 m_srcMasks[7]= 0xFF000000;
85 m_srcMasks[8]= 0xFF800000;
86 m_srcMasks[9]= 0xFFC00000;
87 m_srcMasks[10]=0xFFE00000;
88 m_srcMasks[11]=0xFFF00000;
89 m_srcMasks[12]=0xFFF80000;
90 m_srcMasks[13]=0xFFFC0000;
91 m_srcMasks[14]=0xFFFE0000;
92 m_srcMasks[15]=0xFFFF0000;
93 m_tripVec.clear();
94 m_tripVec.push_back(Triplet(0,1,3));
95 m_tripVec.push_back(Triplet(2,4,6));
96 m_tripVec.push_back(Triplet(5,7,8));
97 m_tripVec.push_back(Triplet(9,10,11));
98 m_tripVec.push_back(Triplet(14,12,13));
99}
std::vector< Triplet > m_tripVec
unsigned long long T

◆ ~ErrorMatrixCompressor()

ErrorMatrixCompressor::~ErrorMatrixCompressor ( )
inline

Definition at line 128 of file ErrorMatrixCompressor.h.

128{m_tripVec.clear();}

Member Function Documentation

◆ CholeskyDecomposition()

bool ErrorMatrixCompressor::CholeskyDecomposition ( double a[5][5],
double L[5][5] )
protected

Definition at line 118 of file ErrorMatrixCompressor.cxx.

119{
120
121 int i{},j{},k{};
122 double sum{};
123 double p[5]{};
124
125 for(i=0;i<5;i++)
126 {
127 for(j=i;j<5;j++)
128 {
129 sum=a[i][j];
130 for(k=i-1;k>=0;k--)
131 sum-=a[i][k]*a[j][k];
132 if(i==j)
133 {
134 if(sum<=0.0)
135 {
136 return false;
137 }
138 p[i]=std::sqrt(sum);
139 L[i][i]=p[i];
140 }
141 else
142 {
143 a[j][i]=sum/p[i];
144 L[j][i]=a[j][i];
145 }
146 }
147 }
148 return true;
149}
static Double_t a
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)

◆ compress()

bool ErrorMatrixCompressor::compress ( const std::vector< double > & src,
std::vector< unsigned int > & dest )

Definition at line 151 of file ErrorMatrixCompressor.cxx.

152{
153 int i{},j{};
154 double C0[5][5]{},C[5][5]{};
155
156
157 dest.clear();
158
159 int idx=0;
160 for (i=0;i<5;i++)
161 for(j=0;j<=i;j++)
162 {
163 C[i][j]=src[idx];
164 C[j][i]=C0[i][j]=C0[j][i]=C[i][j];
165 idx++;
166 }
167 double L[5][5]{};
168
169 for(i=0;i<5;i++)
170 for(j=0;j<=i;j++)
171 {
172 C[i][j]*=(m_scales[i]*m_scales[j]);
173 C[j][i]=C[i][j];
174 }
175 if(!CholeskyDecomposition(C,L)) return false;
176 //
177 float S[5][5]{};
178 for(i=0;i<5;i++)
179 for(j=0;j<=i;j++) S[i][j]=L[i][j];
180
181 std::vector<FloatRep> vecFR;
182 vecFR.clear();
183
184 for(i=0;i<5;i++)
185 {
186 for(j=0;j<=i;j++)
187 {
188 m_decoder.setF(S[i][j]);
189 char sign=(S[i][j]<0)?1:0;
190 std::uint32_t mant=m_decoder.getMantissa();
191 unsigned short int ex=m_decoder.getExponent();
192 vecFR.push_back(FloatRep(sign,ex,mant));
193 }
194 }
195 std::vector<unsigned short> vShorts;
196 vShorts.clear();
197 if(!compressFR(vecFR,vShorts)) return false;
198
199 //re-packing as ints
200
201 int nBits=0;
202 std::uint32_t buffer = 0x00000000u;
203
204 for(std::vector<unsigned short>::iterator it = vShorts.begin(); it != vShorts.end();++it) {
205 // printf("short = 0x%X\n",(*it));
206 if(nBits==2) {
207 dest.push_back(buffer);
208 nBits=0;
209 buffer = 0x00000000;
210 }
211 if(nBits==0) {
212 buffer = (*it);
213 buffer = buffer << 16;
214 nBits++;
215 }
216 else {
217 buffer = buffer | (*it);
218 nBits++;
219 }
220 }
221 dest.push_back(buffer);
222 return true;
223}
int sign(int a)
bool compressFR(const std::vector< FloatRep > &, std::vector< unsigned short > &)
DecoderFloat_IEEE754 m_decoder
bool CholeskyDecomposition(double a[5][5], double L[5][5])
struct color C

◆ compressFR()

bool ErrorMatrixCompressor::compressFR ( const std::vector< FloatRep > & src,
std::vector< unsigned short > & dest )
protected

Definition at line 283 of file ErrorMatrixCompressor.cxx.

284{
285 unsigned short buf=0x0000;
286 dest.clear();
287 int nMantLength=23-m_bitStrip;
288 if(nMantLength<8)
289 {
290 std::cout<<"Requested mantissa reduction is too large: 23->"<<nMantLength<<std::endl;
291 return false;
292 }
293 std::vector<FloatRep>::const_iterator fIt;
294
295 // 1. Check limits
296 fIt=src.begin();
297 int i,j;
298 for (i=0;i<5;i++)
299 for (j=0;j<=i;j++)
300 {
301 unsigned short int ex=(*fIt).exponent();
302 std::uint32_t mant=(*fIt).mantissa();
303 int bias,limit;
304 if(i==j)
305 {
306 bias=m_biases[i];
307 limit=m_limits[0];
308 }
309 else
310 {
311 bias=m_biases[5];
312 limit=m_limits[1];
313 }
314 if((ex!=0)&&(mant!=0))
315 {
316 if((ex<bias)||(ex-bias>limit))
317 {
318 return false;
319 }
320 }
321 ++fIt;
322 }
323 // 2. Pack exponents: diag e + non-diag s1 + non-diag e1 + non-diag s2 + non-diag e2
324
325 i=0;
326 for(std::vector<Triplet>::iterator trIt=m_tripVec.begin();trIt!=m_tripVec.end();++trIt)
327 {
328 int i1,i2[2];
329 i1=(*trIt).m_d;
330 i2[0]=(*trIt).m_nd1;i2[1]=(*trIt).m_nd2;
331 //printf("%d %d %d\n",i1,i2[0],i2[1]);
332 buf=0x0000;
333 unsigned short e;
334
335 e=src[i1].exponent()-m_biases[i];
336 buf = buf | ((e<<12) & 0xF000);
337 if((src[i2[0]].exponent()==0)&&(src[i2[0]].mantissa()==0))
338 {
339 e=src[i2[0]].exponent();
340 buf = buf | 0x0800;//-0
341 }
342 else
343 {
344 if(src[i2[0]].sign())
345 buf = buf | 0x0800;
346 e=src[i2[0]].exponent()-m_biases[5];
347 }
348 buf = buf | ((e<<6) & 0x07C0);
349 if((src[i2[1]].exponent()==0)&&(src[i2[1]].mantissa()==0))
350 {
351 buf = buf | 0x0020;//-0
352 e=src[i2[1]].exponent();
353 }
354 else
355 {
356 e=src[i2[1]].exponent()-m_biases[5];
357 if(src[i2[1]].sign())
358 buf = buf | 0x0020;
359 }
360 buf = buf | (e & 0x001F);
361 // printf("Exponent 0x%X\n",buf);
362 dest.push_back(buf);
363 i++;
364 }
365 // 3. Pack reduced mantissas
366 fIt=src.begin();
367 unsigned int nPacked=0;
368 int nFreeBits=0,nBitsToStore=0,nBufferLength=0;
369 std::uint32_t srcBuffer=0x00000000u;
370 // printf("L=%d\n",nMantLength);
371 while (nPacked<=src.size()+1)
372 {
373 if(nFreeBits==0)
374 {
375 if(nBufferLength!=0)
376 {
377 dest.push_back(buf);
378 // printf("Storing 0x%X\n",buf);
379 }
380 buf=0x0000;
381 nFreeBits=16;
382 nBufferLength++;
383 }
384 if(nBitsToStore==0)
385 {
386 if(nPacked!=0)
387 ++fIt;
388 if(fIt==src.end()) break;
389 nPacked++;
390 srcBuffer=((*fIt).mantissa()<<9);
391 // printf("Packing 0x%X = %ud\n",(*fIt).mantissa(),(*fIt).mantissa());
392 nBitsToStore=nMantLength;
393 }
394 int Np=(nBitsToStore>nFreeBits)?nFreeBits:nBitsToStore;
395 std::uint32_t mask=m_srcMasks[Np-1];
396 std::uint32_t slice = srcBuffer & mask;
397 slice = (slice >> (32-nFreeBits)) & 0x0000FFFF;
398 std::uint32_t tmp = slice;
399 // printf("Np=%d Tmp=0x%X\n",Np,tmp);
400 buf = buf | tmp;
401 srcBuffer = srcBuffer << Np;
402 // printf("dest=0x%X src=0x%X\n",buf,srcBuffer);
403 nFreeBits-=Np;
404 nBitsToStore-=Np;
405 }
406 dest.push_back(buf);
407 return true;
408}

◆ restore()

bool ErrorMatrixCompressor::restore ( const std::vector< unsigned int > & src,
std::vector< double > & dest )

Definition at line 225 of file ErrorMatrixCompressor.cxx.

226{
227 int i{},j{};
228 double C[5][5]{};
229
230 dest.clear();
231
232 std::vector<FloatRep> vecFR;
233 vecFR.clear();
234
235 std::vector<unsigned short> vShorts;
236
237 vShorts.clear();
238
239 for (unsigned int ii : src) {
240 unsigned short s1,s2;
241
242 s1 = (unsigned short)((0xFFFF0000 & ii) >> 16);
243 s2 = (unsigned short)(0x0000FFFF & ii);
244 vShorts.push_back(s1);
245 //if(!((s2==0) && ((it+1)==src.end()))) //do not store last zero
246 vShorts.push_back(s2);
247 }
248
249 if(!restoreFR(vShorts,vecFR)) return false;
250
251 std::vector<FloatRep>::iterator fIt(vecFR.begin());
252 float S[5][5]{};
253 for(i=0;i<5;i++)
254 for(j=0;j<=i;j++)
255 {
256 if(fIt==vecFR.end()) break;
257 S[i][j]=(*fIt).restore();
258 ++fIt;
259 }
260
261 double L[5][5]{};
262 for(i=0;i<5;i++)
263 for(j=0;j<=i;j++) L[i][j]=S[i][j];
264 for(i=0;i<5;i++)
265 for(j=i;j<5;j++)
266 {
267 C[i][j]=0.0;
268 for(int k=0;k<5;k++)
269 C[i][j]+=L[i][k]*L[j][k];
270 C[j][i]=C[i][j];
271 }
272 for(i=0;i<5;i++)
273 for(j=0;j<=i;j++)
274 {
275 C[i][j]/=(m_scales[i]*m_scales[j]);
276 C[j][i]=C[i][j];
277 }
278 for(i=0;i<5;i++) for(j=0;j<=i;j++) dest.push_back(C[i][j]);
279 return true;
280}
bool restoreFR(const std::vector< unsigned short > &, std::vector< FloatRep > &)

◆ restoreFR()

bool ErrorMatrixCompressor::restoreFR ( const std::vector< unsigned short > & src,
std::vector< FloatRep > & dest )
protected

Definition at line 410 of file ErrorMatrixCompressor.cxx.

411{
412 int i,nRestored,nFreeBits,nBitsToStore;
413 unsigned short buf=0x0000;
414 std::uint32_t destBuffer=0x00000000;
415 std::vector<unsigned short>::const_iterator uIt(src.begin());
416 dest.clear();
417
418 for(i=0;i<15;i++)
419 {
420 dest.push_back(FloatRep(0,0,0));
421 }
422
423 i=0;
424 for(;uIt!=src.end();++uIt)
425 {
426 int i0=m_tripVec[i].m_d;
427 int i1=m_tripVec[i].m_nd1;
428 int i2=m_tripVec[i].m_nd2;
429 buf=(*uIt);
430 char s=((buf & 0x0800)==0)?0:1;
431 dest[i1].sign(s);
432 s=((buf & 0x0020)==0)?0:1;
433 dest[i2].sign(s);
434 unsigned short e = ((buf & 0xF000) >> 12);
435 dest[i0].exponent(e+m_biases[i]);
436 e = ((buf & 0x07C0) >> 6);
437 dest[i1].exponent(e+m_biases[5]);
438 e = (buf & 0x001F);
439 dest[i2].exponent(e+m_biases[5]);
440 i++;
441 if(i==5) break;
442 }
443 if(i<5) return false;
444 nRestored=0;
445 nBitsToStore=0;
446 nFreeBits=0;
447 int nMantLength=23-m_bitStrip;
448 while(nRestored<=15)
449 {
450 if(nFreeBits==0)
451 {
452 if(nRestored!=0)
453 {
454 //printf("Dest 0x%X ",destBuffer);
455 destBuffer = destBuffer << m_bitStrip;
456 //printf("<< 0x%X = %lu\n",destBuffer,destBuffer);
457 dest[nRestored-1].mantissa(destBuffer);
458 }
459 ++nRestored;
460 destBuffer=0x00000000;
461 nFreeBits=nMantLength;
462 }
463 if(nBitsToStore==0)
464 {
465 if(uIt==src.end()) break;
466 ++uIt;
467 if(uIt==src.end())
468 {
469 //printf("Breaking ... nR=%d\n",nRestored);
470 break;
471 }
472 nBitsToStore=16;buf=(*uIt);//printf("Source 0x%X\n",buf);
473 }
474 int Np=(nFreeBits>nBitsToStore) ? nBitsToStore : nFreeBits;
475 std::uint32_t tmp = buf;
476 tmp = tmp >> (16-Np);
477 nBitsToStore-=Np;
478 destBuffer = destBuffer | tmp;
479 nFreeBits-=Np;
480 }
481 return true;
482}

◆ setBiases()

void ErrorMatrixCompressor::setBiases ( const int b[6])

Definition at line 101 of file ErrorMatrixCompressor.cxx.

102{
103 for(int i=0;i<6;i++)
104 {
105 m_biases[i]=b[i];
106 }
107}

◆ setUpperLimits()

void ErrorMatrixCompressor::setUpperLimits ( const int l[2])

Definition at line 109 of file ErrorMatrixCompressor.cxx.

110{
111 for(int i=0;i<2;i++)
112 {
113 m_limits[i]=l[i];
114 }
115}
l
Printing final latex table to .tex output file.

Member Data Documentation

◆ m_biases

short int ErrorMatrixCompressor::m_biases[6] {}
protected

Definition at line 141 of file ErrorMatrixCompressor.h.

141{};

◆ m_bitStrip

int ErrorMatrixCompressor::m_bitStrip {}
protected

Definition at line 145 of file ErrorMatrixCompressor.h.

145{};

◆ m_decoder

DecoderFloat_IEEE754 ErrorMatrixCompressor::m_decoder
private

Definition at line 148 of file ErrorMatrixCompressor.h.

◆ m_limits

short int ErrorMatrixCompressor::m_limits[2] {}
protected

Definition at line 142 of file ErrorMatrixCompressor.h.

142{};

◆ m_scales

double ErrorMatrixCompressor::m_scales[5] {}
protected

Definition at line 143 of file ErrorMatrixCompressor.h.

143{};

◆ m_srcMasks

unsigned int ErrorMatrixCompressor::m_srcMasks[16] {}
private

Definition at line 149 of file ErrorMatrixCompressor.h.

149{};

◆ m_tripVec

std::vector<Triplet> ErrorMatrixCompressor::m_tripVec
private

Definition at line 150 of file ErrorMatrixCompressor.h.


The documentation for this class was generated from the following files: