2828namespace o2 ::tpc
2929{
3030
31- struct CMVPerTF ; // forward declaration
32- struct CMVPerTFSparse ; // forward declaration
33- struct CMVPerTFHuffman ; // forward declaration
34- struct CMVPerTFCombined ; // forward declaration
31+ struct CMVPerTF ; // forward declaration
32+ struct CMVPerTFSparse ; // forward declaration
33+ struct CMVPerTFHuffman ; // forward declaration
34+ struct CMVPerTFCombined ; // forward declaration
35+ struct CMVPerTFQuantized ; // forward declaration
3536
3637// / Delta+zigzag+varint compressed CMV data for one TF across all CRUs
3738// / Produced by CMVPerTF::compressVarint(), restored with decompress()
@@ -108,7 +109,7 @@ struct CMVPerTFHuffman {
108109
109110// / Hybrid sparse+compressed-value encoding for one TF across all CRUs
110111// /
111- // / Non-zero positions are stored as sparse varint deltas (same as CMVPerTFSparse).
112+ // / Non-zero positions are stored as sparse varint deltas (same as CMVPerTFSparse)
112113// / The remaining non-zero values are encoded according to mValueMode:
113114// /
114115// / Mode 0 raw uint16_t — identical value encoding to CMVPerTFSparse
@@ -135,6 +136,31 @@ struct CMVPerTFCombined {
135136 ClassDefNV (CMVPerTFCombined, 1 )
136137};
137138
139+ // / Sparse positions + quantized-value symbols for one TF across all CRUs
140+ // /
141+ // / Non-zero positions are stored as sparse varint deltas.
142+ // / The corresponding values are encoded as quantized signed symbols:
143+ // / Mode 0 raw symbols — 4-byte LE uint32 per symbol
144+ // / Mode 1 varint symbols — varint(symbol)
145+ // / Mode 2 Huffman symbols — canonical Huffman over symbol stream
146+ // / Quantized symbols represent decimal-style values below the internally derived full-precision cutoff
147+ // / and exact raw signed I8F7 values above it.
148+ struct CMVPerTFQuantized {
149+ uint32_t firstOrbit{0 }; // /< First orbit of this TF
150+ uint16_t firstBC{0 }; // /< First bunch crossing of this TF
151+ uint8_t mValueMode {0 }; // /< 0 = raw symbols, 1 = varint symbols, 2 = Huffman symbols
152+
153+ std::vector<uint8_t > mData ; // /< Encoded payload
154+
155+ // / Restore nearest raw-I8F7 values into *cmv (must not be null)
156+ void decompress (CMVPerTF* cmv) const ;
157+
158+ // / Restore exact quantized float values into `values`, sized to CRU::MaxCRU * cmv::NTimeBinsPerTF
159+ void decompressToFloatBuffer (std::vector<float >& values) const ;
160+
161+ ClassDefNV (CMVPerTFQuantized, 1 )
162+ };
163+
138164// / CMV data for one TF across all CRUs
139165// / Raw 16-bit CMV values are stored in a flat C array indexed as [cru * NTimeBinsPerTF + timeBin]
140166// / CRU::MaxCRU and cmv::NTimeBinsPerTF are compile-time constants, so no dynamic allocation is needed
@@ -166,12 +192,24 @@ struct CMVPerTF {
166192 // / threshold=0 rounding is not applied
167193 void roundToIntegers (uint16_t threshold);
168194
195+ // / Quantise |v| with a Gaussian-CDF recovery profile:
196+ // / coarse decimal-style precision below and around mean, then a smooth return to the
197+ // / full native I8F7 precision as the magnitude increases with width sigma
198+ void trimGaussianPrecision (float mean, float sigma);
199+
169200 // / Compress this object into a CMVPerTFVarint using delta+zigzag+varint encoding
170201 CMVPerTFVarint compressVarint () const ;
171202
172203 // / Compress this object into a CMVPerTFSparse storing only non-zero timebins
173204 CMVPerTFSparse compressSparse () const ;
174205
206+ // / Dedicated sparse + quantized-value compression
207+ // / valueMode:
208+ // / 0 = raw symbol stream
209+ // / 1 = varint symbol stream
210+ // / 2 = Huffman symbol stream
211+ CMVPerTFQuantized compressQuantized (uint8_t valueMode = 0 , float quantizationMean = 1 .f, float quantizationSigma = 0 .f) const ;
212+
175213 // / Hybrid sparse+compressed-value compression
176214 // / Positions encoded as sparse varint deltas; values encoded according to valueMode:
177215 // / 0 = raw uint16_t (same as compressSparse, no additional gain)
@@ -189,9 +227,10 @@ struct CMVPerTF {
189227 static void writeToFile (const std::string& filename, const std::unique_ptr<TTree>& tree);
190228
191229 private:
192- static int32_t cmvToSigned (uint16_t raw); // /< Sign-magnitude uint16_t → signed integer
193- static uint32_t zigzagEncode (int32_t value); // /< Zigzag encode
194- static void encodeVarintInto (uint32_t value, std::vector<uint8_t >& out); // /< Varint encode
230+ static int32_t cmvToSigned (uint16_t raw); // /< Sign-magnitude uint16_t → signed integer
231+ static uint16_t quantizeBelowThreshold (uint16_t raw, float quantizationMean, float quantizationSigma); // /< Quantise sub-threshold values with a Gaussian-shaped recovery to full precision
232+ static uint32_t zigzagEncode (int32_t value); // /< Zigzag encode
233+ static void encodeVarintInto (uint32_t value, std::vector<uint8_t >& out); // /< Varint encode
195234
196235 public:
197236 ClassDefNV (CMVPerTF, 1 )
0 commit comments