File indexing completed on 2024-04-06 12:04:53
0001 #ifndef _DataFormats_PatCandidates_CovarianceParameterization_h_
0002 #define _DataFormats_PatCandidates_CovarianceParameterization_h_
0003 #include <TFile.h>
0004 #include <TH3D.h>
0005 #include <iostream>
0006 #include <unordered_map>
0007 #include <array>
0008 #include <TKey.h>
0009 class CompressionElement {
0010 public:
0011 enum Method { float16 = 0, reduceMantissa = 1, logPack = 2, tanLogPack = 3, zero = 4, one = 5 };
0012 enum Target { realValue = 0, ratioToRef = 1, differenceToRef = 2 };
0013 CompressionElement() : method(zero), target(realValue) {}
0014 CompressionElement(Method m, Target t, int bitsUsed, std::vector<float> p)
0015 : method(m), target(t), bits(bitsUsed), params(p) {}
0016 Method method;
0017 Target target;
0018 int bits;
0019 std::vector<float> params;
0020 uint16_t pack(float value, float ref = 0.) const;
0021 float unpack(uint16_t packed, float ref = 0.) const;
0022 };
0023
0024 class CovarianceParameterization {
0025 public:
0026 static int index(int i, int j) {
0027 if (i >= j)
0028 return j + i * (i + 1) / 2;
0029 else
0030 return i + j * (j + 1) / 2;
0031 }
0032 struct CompressionSchema {
0033 CompressionSchema() {}
0034 std::array<CompressionElement, 15> elements;
0035 CompressionElement &operator()(int i, int j) { return elements[index(i, j)]; }
0036 const CompressionElement &operator()(int i, int j) const { return elements[index(i, j)]; }
0037 };
0038 CovarianceParameterization() : loadedVersion_(-1) {}
0039 bool isValid() const { return loadedVersion_ != -1; }
0040 int loadedVersion() const { return loadedVersion_; }
0041 void load(int version);
0042 float meanValue(
0043 int i, int j, int sign, float pt, float eta, int nHits, int pixelHits, float cii = 1., float cjj = 1.) const;
0044 float pack(float value,
0045 int schema,
0046 int i,
0047 int j,
0048 float pt,
0049 float eta,
0050 int nHits,
0051 int pixelHits,
0052 float cii = 1.,
0053 float cjj = 1.) const;
0054 float unpack(uint16_t packed,
0055 int schema,
0056 int i,
0057 int j,
0058 float pt,
0059 float eta,
0060 int nHits,
0061 int pixelHits,
0062 float cii = 1.,
0063 float cjj = 1.) const;
0064
0065 private:
0066 void readFile(TFile &);
0067 void addTheHistogram(
0068 std::vector<TH3D *> *HistoVector, std::string StringToAddInTheName, int i, int j, TFile &fileToRead);
0069 int loadedVersion_;
0070 TFile *fileToRead_;
0071 std::unordered_map<uint16_t, CompressionSchema> schemas;
0072 std::vector<TH3D *> cov_elements_pixelHit;
0073 std::vector<TH3D *> cov_elements_noPixelHit;
0074 };
0075
0076 #endif