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