File indexing completed on 2024-04-06 12:02:39
0001 #ifndef SiStripNoises_h
0002 #define SiStripNoises_h
0003
0004 #include "CondFormats/Serialization/interface/Serializable.h"
0005
0006 #include <vector>
0007 #include <utility>
0008 #include <iostream>
0009
0010 #include <cassert>
0011 #include <cstring>
0012 #include <cstdint>
0013
0014 class TrackerTopology;
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 class SiStripNoises {
0026 public:
0027 struct ratioData {
0028 uint32_t detid;
0029 std::vector<float> values;
0030 };
0031
0032 struct DetRegistry {
0033 uint32_t detid;
0034 uint32_t ibegin;
0035 uint32_t iend;
0036
0037 COND_SERIALIZABLE;
0038 };
0039
0040 class StrictWeakOrdering {
0041 public:
0042 bool operator()(const DetRegistry& p, const uint32_t& i) const { return p.detid < i; }
0043 };
0044
0045 typedef std::vector<unsigned char> Container;
0046 typedef std::vector<unsigned char>::const_iterator ContainerIterator;
0047 typedef std::pair<ContainerIterator, ContainerIterator> Range;
0048 typedef std::vector<DetRegistry> Registry;
0049 typedef Registry::const_iterator RegistryIterator;
0050 typedef std::vector<uint16_t> InputVector;
0051
0052 SiStripNoises() {}
0053 ~SiStripNoises() {}
0054
0055 bool put(const uint32_t& detID, const InputVector& input);
0056 const Range getRange(const uint32_t detID) const;
0057 Range getRangeByPos(unsigned short pos) const;
0058 void getDetIds(std::vector<uint32_t>& DetIds_) const;
0059
0060 ContainerIterator getDataVectorBegin() const { return v_noises.begin(); }
0061 ContainerIterator getDataVectorEnd() const { return v_noises.end(); }
0062 RegistryIterator getRegistryVectorBegin() const { return indexes.begin(); }
0063 RegistryIterator getRegistryVectorEnd() const { return indexes.end(); }
0064
0065 static inline float getRawNoise(const uint16_t& strip, const Range& range) { return decode(strip, range); }
0066
0067 static inline float getNoiseFast(const uint16_t& strip, const Range& range) {
0068 return 0.1f * float(decode(strip, range));
0069 }
0070
0071 static void verify(uint16_t strip, const Range& range);
0072 static float getNoise(uint16_t strip, const Range& range) {
0073 #ifdef EDM_ML_DEBUG
0074 verify(strip, range);
0075 #endif
0076 return getNoiseFast(strip, range);
0077 }
0078
0079 void allNoises(std::vector<float>& noises, const Range& range) const;
0080 void setData(float noise_, InputVector& vped);
0081
0082 void printDebug(std::stringstream& ss, const TrackerTopology* trackerTopo) const;
0083 void printSummary(std::stringstream& ss, const TrackerTopology* trackerTopo) const;
0084
0085 std::vector<ratioData> operator/(const SiStripNoises& d);
0086
0087 private:
0088 static void encode(const InputVector& Vi, std::vector<unsigned char>& Vo_CHAR);
0089
0090 static inline uint16_t decode(uint16_t strip, const Range& range);
0091
0092
0093
0094 static inline uint16_t get9bits(const uint8_t*& ptr, int8_t skip);
0095
0096 Container v_noises;
0097 Registry indexes;
0098
0099
0100
0101
0102
0103
0104
0105 COND_SERIALIZABLE;
0106 };
0107
0108
0109
0110 inline uint16_t SiStripNoises::get9bits(const uint8_t*& ptr, int8_t skip) {
0111 uint8_t maskThis = (0xFF << skip);
0112 uint8_t maskThat = ((2 << skip) - 1);
0113 uint16_t ret = (((*ptr) & maskThis) >> skip);
0114 --ptr;
0115 return ret | (((*ptr) & maskThat) << (8 - skip));
0116 }
0117
0118 inline uint16_t SiStripNoises::decode(uint16_t strip, const Range& range) {
0119 const unsigned char* data = &*(range.second - 1);
0120 static const uint16_t BITS_PER_STRIP = 9;
0121
0122 uint32_t lowBit = strip * BITS_PER_STRIP;
0123 uint8_t firstByteBit = (lowBit & 7);
0124
0125 uint16_t vin = uint16_t(*(data - lowBit / 8)) | (uint16_t(*(data - lowBit / 8 - 1)) << 8);
0126 vin = vin >> firstByteBit;
0127 vin &= 0x1FF;
0128 return vin;
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156 }
0157
0158 #endif