CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
liblogintpack.h
Go to the documentation of this file.
1 #ifndef liblogintpack_h
2 #define liblogintpack_h
3 
4 #include <cmath>
5 
6 namespace logintpack
7 {
8  int8_t pack8logCeil(double x,double lmin, double lmax, uint8_t base=128)
9  {
10  if(base>128) base=128;
11  float l =log(fabs(x));
12  float centered = (l-lmin)/(lmax-lmin)*base;
13  int8_t r=ceil(centered);
14  if(centered >= base-1) r=base-1;
15  if(centered < 0) r=0;
16  if(x<0) r=-r;
17  return r;
18  }
19 
20  int8_t pack8log(double x,double lmin, double lmax, uint8_t base=128)
21  {
22  if(base>128) base=128;
23  float l =log(fabs(x));
24  float centered = (l-lmin)/(lmax-lmin)*base;
25  int8_t r=centered;
26  if(centered >= base-1) r=base-1;
27  if(centered < 0) r=0;
28  if(x<0) r=-r;
29  return r;
30  }
31 
34  int8_t pack8logClosed(double x,double lmin, double lmax, uint8_t base=128)
35  {
36  if(base>128) base=128;
37  float l =log(fabs(x));
38  float centered = (l-lmin)/(lmax-lmin)*(base-1);
39  int8_t r=round(centered);
40  if(centered >= base-1) r=base-1;
41  if(centered < 0) r=0;
42  if(x<0) r=-r;
43  return r;
44  }
45 
46 
47  double unpack8log(int8_t i,double lmin, double lmax, uint8_t base=128)
48  {
49  if(base>128) base=128;
50  float basef=base;
51  float l=lmin+abs(i)/basef*(lmax-lmin);
52  float val=exp(l);
53  if(i<0) return -val; else return val;
54  }
55 
57  double unpack8logClosed(int8_t i,double lmin, double lmax, uint8_t base=128)
58  {
59  if(base>128) base=128;
60  float basef=base-1;
61  float l=lmin+abs(i)/basef*(lmax-lmin);
62  if (abs(i) == base-1) l = lmax;
63  float val=exp(l);
64  if(i<0) return -val; else return val;
65  }
66 
67 }
68 #endif
tuple base
Main Program
Definition: newFWLiteAna.py:92
int i
Definition: DBlmapReader.cc:9
double unpack8log(int8_t i, double lmin, double lmax, uint8_t base=128)
Definition: liblogintpack.h:47
int8_t pack8log(double x, double lmin, double lmax, uint8_t base=128)
Definition: liblogintpack.h:20
int8_t pack8logCeil(double x, double lmin, double lmax, uint8_t base=128)
Definition: liblogintpack.h:8
int8_t pack8logClosed(double x, double lmin, double lmax, uint8_t base=128)
Definition: liblogintpack.h:34
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double unpack8logClosed(int8_t i, double lmin, double lmax, uint8_t base=128)
reverse of pack8logClosed
Definition: liblogintpack.h:57
Definition: DDAxes.h:10
tuple log
Definition: cmsBatch.py:347