ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DSTCompressor.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DSTCompressor.h
1 #ifndef G4EVAL_DSTCOMPRESSOR_H
2 #define G4EVAL_DSTCOMPRESSOR_H
3 
4 #include "compressor_generator.h"
5 #include "RtypesCore.h"
6 
7 
8 class DSTCompressor {
9 public:
10  // whether to print the debug info
11  const bool debug = false;
12  // exit prematurely after this much residuals
13  const int earlybreak = 1000 * 1000 * 1000;
14 
15  const float dist_phi = 0.05;
16  const float dist_z = 3;
17  int phiBits;
18  int zBits;
19 
20 
21 
22  using bit5 = std::bitset<5>;
23  using bit8 = std::bitset<8>;
24  using bit10 = std::bitset<10>;
25  using bstream = std::vector<u_char>;
26  using Dict = std::vector<float>;
27 
28  const int wordwidth = 8; // a char has 8 bits
29  // phi mean, phi sigma, z mean, z sigma
30  using Pars = std::array<double, 4>;
31 
34 
35  DSTCompressor(float phiMean = -3e-5,
36  float phiSigma = 0.015,
37  float zMean = -0.00063,
38  float zSigma = 0.07036,
39  int nBitPhi = 8,
40  int nBitZ = 8)
41  : phiBits(nBitPhi),
42  zBits(nBitZ)
43 {
44  int numPoints = 1000000;
45  phiDict = compress_gaussian_dist(phiMean, phiSigma, numPoints, phiBits);
46  zDict = compress_gaussian_dist(zMean, zSigma, numPoints, zBits);
47 }
48 
51 Dict compress_gaussian_dist(double mean, double stddev,
52  int numPoints, int numBits) {
53  std::vector<ushort> order;
54  std::vector<float> dict;
55  std::vector<unsigned long> cnt;
56  std::default_random_engine generator;
57  std::normal_distribution<double> distribution(mean, stddev);
58  float maxAbsError = approx(&order, &dict, &cnt, numPoints, generator,
59  distribution, (size_t)pow(2, numBits));
60  std::cout << "Compressing with " << numBits << " bits" << std::endl;
61  std::cout << "Number of clusters = " << dict.size() << std::endl;
62  std::cout << "Maximum absolute error = " << maxAbsError << std::endl;
63  return dict;
64 }
65 
66  unsigned short compressPhi(float inPhi) {
67  return residesIn(inPhi, &phiDict);
68  };
69 
70  unsigned short compressZ(float inZ) {
71  return residesIn(inZ, &zDict);
72  };
73 
74  float decompressPhi(unsigned short key) {
75  return phiDict.at(key);
76  }
77 
78  float decompressZ(unsigned short key) {
79  return zDict.at(key);
80  }
81 
82 };
83 
84 #endif // G4EVAL_DSTCOMPRESSOR_H