CMS 3D CMS Logo

SiStripNoises.cc
Go to the documentation of this file.
3 #include <iostream>
4 #include <algorithm>
5 #include <cmath>
6 #include <iomanip>
8 
10  v_noises.clear();
11  indexes.clear();
12  v_noises.insert(v_noises.end(), input.v_noises.begin(), input.v_noises.end());
13  indexes.insert(indexes.end(), input.indexes.begin(), input.indexes.end());
14 }
15 
16 bool SiStripNoises::put(const uint32_t& DetId, const InputVector& input) {
17  std::vector<unsigned char> Vo_CHAR;
18  encode(input, Vo_CHAR);
19 
20  Registry::iterator p = std::lower_bound(indexes.begin(), indexes.end(), DetId, SiStripNoises::StrictWeakOrdering());
21  if (p != indexes.end() && p->detid == DetId)
22  return false;
23 
24  size_t sd = Vo_CHAR.end() - Vo_CHAR.begin();
25  DetRegistry detregistry;
26  detregistry.detid = DetId;
27  detregistry.ibegin = v_noises.size();
28  detregistry.iend = v_noises.size() + sd;
29  indexes.insert(p, detregistry);
30  v_noises.insert(v_noises.end(), Vo_CHAR.begin(), Vo_CHAR.end());
31  return true;
32 }
33 
34 const SiStripNoises::Range SiStripNoises::getRange(const uint32_t DetId) const {
35  // get SiStripNoises Range of DetId
36 
38  if (p == indexes.end() || p->detid != DetId)
39  return SiStripNoises::Range(v_noises.end(), v_noises.end());
40  else {
41  __builtin_prefetch((&v_noises.front()) + p->ibegin);
42  __builtin_prefetch((&v_noises.front()) + p->ibegin + 96);
43  __builtin_prefetch((&v_noises.front()) + p->iend - 96);
44  return SiStripNoises::Range(v_noises.begin() + p->ibegin, v_noises.begin() + p->iend);
45  }
46 }
47 
49  if (pos > indexes.size())
50  return Range(v_noises.end(), v_noises.end());
51  auto p = indexes.begin() + pos;
52  __builtin_prefetch((&v_noises.front()) + p->ibegin);
53  __builtin_prefetch((&v_noises.front()) + p->ibegin + 96);
54  __builtin_prefetch((&v_noises.front()) + p->iend - 96);
55  return Range(v_noises.begin() + p->ibegin, v_noises.begin() + p->iend);
56 }
57 
58 void SiStripNoises::getDetIds(std::vector<uint32_t>& DetIds_) const {
59  // returns vector of DetIds in map
62  DetIds_.reserve(indexes.size());
63  for (SiStripNoises::RegistryIterator p = begin; p != end; ++p) {
64  DetIds_.push_back(p->detid);
65  }
66 }
67 
68 void SiStripNoises::verify(uint16_t strip, const Range& range) {
69  if (9 * strip >= (range.second - range.first) * 8)
70  throw cms::Exception("CorruptedData")
71  << "[SiStripNoises::getNoise] looking for SiStripNoises for a strip out of range: strip " << strip;
72 }
73 
75  v.push_back((static_cast<int16_t>(noise_ * 10.0 + 0.5) & 0x01FF));
76 }
77 
78 void SiStripNoises::encode(const InputVector& Vi, std::vector<unsigned char>& Vo) {
79  static const uint16_t BITS_PER_STRIP = 9;
80  const size_t VoSize = (size_t)((Vi.size() * BITS_PER_STRIP) / 8 + .999);
81  Vo.resize(VoSize);
82  for (size_t i = 0; i < VoSize; ++i)
83  Vo[i] &= 0x00u;
84 
85  for (unsigned int stripIndex = 0; stripIndex < Vi.size(); ++stripIndex) {
86  unsigned char* data = &Vo[VoSize - 1];
87  uint32_t lowBit = stripIndex * BITS_PER_STRIP;
88  uint8_t firstByteBit = (lowBit & 0x7);
89  uint8_t firstByteNBits = 8 - firstByteBit;
90  uint8_t firstByteMask = 0xffu << firstByteBit;
91  uint8_t secondByteNbits = (BITS_PER_STRIP - firstByteNBits);
92  uint8_t secondByteMask = ~(0xffu << secondByteNbits);
93 
94  *(data - lowBit / 8) = (*(data - lowBit / 8) & ~(firstByteMask)) | ((Vi[stripIndex] & 0xffu) << firstByteBit);
95  *(data - lowBit / 8 - 1) =
96  (*(data - lowBit / 8 - 1) & ~(secondByteMask)) | ((Vi[stripIndex] >> firstByteNBits) & secondByteMask);
97 
98  /*
99  if(stripIndex < 25 ){
100  std::cout << "***************ENCODE*********************"<<std::endl
101  << "\tdata-lowBit/8 :"<<print_as_binary((*(data-lowBit/8) & ~(firstByteMask)))
102  << "-"<<print_as_binary(((Vi[stripIndex] & 0xffu) <<firstByteBit))
103  << "\tdata-lowBit/8-1 :"<<print_as_binary((*(data-lowBit/8-1) & ~(secondByteMask)))
104  << "-"<<print_as_binary((((Vi[stripIndex]>> firstByteNBits) & secondByteMask)))
105  << std::endl;
106  std::cout << "strip "<<stripIndex<<"\tvi: " << Vi[stripIndex] <<"\t"
107  << print_short_as_binary(Vi[stripIndex])
108  << "\tvo1:"<< print_char_as_binary(*(data-lowBit/8))
109  << "\tvo2:"<< print_char_as_binary(*(data-lowBit/8-1))
110  << "\tlowBit:"<< lowBit
111  << "\tfirstByteMask :"<<print_as_binary(firstByteMask)
112  << "\tsecondByteMask:"<<print_as_binary(secondByteMask)
113  << "\tfirstByteBit:"<<print_as_binary(firstByteBit)
114  << std::endl;
115  }
116  */
117  }
118 }
119 
120 //============ Methods for bulk-decoding all noises for a module ================
121 
122 void SiStripNoises::allNoises(std::vector<float>& noises, const Range& range) const {
123  size_t mysize = ((range.second - range.first) << 3) / 9;
124  size_t size = noises.size();
125  if (mysize < size)
126  throw cms::Exception("CorruptedData") << "[SiStripNoises::allNoises] Requested noise for " << noises.size()
127  << " strips, I have it only for " << mysize << " strips\n";
128  size_t size8 = size & (~0x7), carry = size & 0x7; // we have an optimized way of unpacking 8 strips
129  const uint8_t* ptr = (&*range.second) - 1;
130  std::vector<float>::iterator out = noises.begin(), end8 = noises.begin() + size8;
131  // we do it this baroque way instead of just loopin on all the strips because it's faster
132  // as the value of 'skip' is a constant, so the compiler can compute the masks directly
133  while (out < end8) {
134  *out = static_cast<float>(get9bits(ptr, 0) / 10.0f);
135  ++out;
136  *out = static_cast<float>(get9bits(ptr, 1) / 10.0f);
137  ++out;
138  *out = static_cast<float>(get9bits(ptr, 2) / 10.0f);
139  ++out;
140  *out = static_cast<float>(get9bits(ptr, 3) / 10.0f);
141  ++out;
142  *out = static_cast<float>(get9bits(ptr, 4) / 10.0f);
143  ++out;
144  *out = static_cast<float>(get9bits(ptr, 5) / 10.0f);
145  ++out;
146  *out = static_cast<float>(get9bits(ptr, 6) / 10.0f);
147  ++out;
148  *out = static_cast<float>(get9bits(ptr, 7) / 10.0f);
149  ++out;
150  --ptr; // every 8 strips we have to skip one more bit
151  }
152  for (size_t rem = 0; rem < carry; ++rem) {
153  *out = static_cast<float>(get9bits(ptr, rem) / 10.0f);
154  ++out;
155  }
156 }
157 
158 /*
159 const std::string SiStripNoises::print_as_binary(const uint8_t ch) const
160 {
161  std::string str;
162  int i = CHAR_BIT;
163  while (i > 0)
164  {
165  -- i;
166  str.push_back((ch&(1 << i) ? '1' : '0'));
167  }
168  return str;
169 }
170 
171 std::string SiStripNoises::print_char_as_binary(const unsigned char ch) const
172 {
173  std::string str;
174  int i = CHAR_BIT;
175  while (i > 0)
176  {
177  -- i;
178  str.push_back((ch&(1 << i) ? '1' : '0'));
179  }
180  return str;
181 }
182 
183 std::string SiStripNoises::print_short_as_binary(const short ch) const
184 {
185  std::string str;
186  int i = CHAR_BIT*2;
187  while (i > 0)
188  {
189  -- i;
190  str.push_back((ch&(1 << i) ? '1' : '0'));
191  }
192  return str;
193 }
194 */
195 
196 void SiStripNoises::printDebug(std::stringstream& ss, const TrackerTopology* /*trackerTopo*/) const {
198  uint16_t Nstrips;
199  std::vector<float> vstripnoise;
200 
201  ss << "detid" << std::setw(15) << "strip" << std::setw(10) << "noise" << std::endl;
202 
203  int detId = 0;
204  int oldDetId = 0;
205  for (; rit != erit; ++rit) {
206  Nstrips = (rit->iend - rit->ibegin) * 8 / 9; //number of strips = number of chars * char size / strip noise size
207  vstripnoise.resize(Nstrips);
208  allNoises(vstripnoise, make_pair(getDataVectorBegin() + rit->ibegin, getDataVectorBegin() + rit->iend));
209 
210  detId = rit->detid;
211  if (detId != oldDetId) {
212  oldDetId = detId;
213  ss << detId;
214  } else
215  ss << " ";
216  for (size_t i = 0; i < Nstrips; ++i) {
217  if (i != 0)
218  ss << " ";
219  ss << std::setw(15) << i << std::setw(10) << vstripnoise[i] << std::endl;
220  }
221  }
222 }
223 
224 void SiStripNoises::printSummary(std::stringstream& ss, const TrackerTopology* trackerTopo) const {
225  SiStripDetSummary summary{trackerTopo};
226 
227  std::stringstream tempss;
228 
230  uint16_t Nstrips;
231  std::vector<float> vstripnoise;
232  double mean, rms, min, max;
233  for (; rit != erit; ++rit) {
234  Nstrips = (rit->iend - rit->ibegin) * 8 / 9; //number of strips = number of chars * char size / strip noise size
235  vstripnoise.resize(Nstrips);
236  allNoises(vstripnoise, make_pair(getDataVectorBegin() + rit->ibegin, getDataVectorBegin() + rit->iend));
237  tempss << "\ndetid: " << rit->detid << " \t ";
238  mean = 0;
239  rms = 0;
240  min = 10000;
241  max = 0;
242 
243  DetId detId(rit->detid);
244 
245  for (size_t i = 0; i < Nstrips; ++i) {
246  mean += vstripnoise[i];
247  rms += vstripnoise[i] * vstripnoise[i];
248  if (vstripnoise[i] < min)
249  min = vstripnoise[i];
250  if (vstripnoise[i] > max)
251  max = vstripnoise[i];
252 
253  summary.add(detId, vstripnoise[i]);
254  }
255  mean /= Nstrips;
256  rms = sqrt(rms / Nstrips - mean * mean);
257 
258  tempss << "Nstrips " << Nstrips << " \t; mean " << mean << " \t; rms " << rms << " \t; min " << min << " \t; max "
259  << max << "\t ";
260  }
261  ss << std::endl << "Summary:" << std::endl;
262  summary.print(ss);
263  ss << std::endl;
264  ss << tempss.str();
265 }
266 
267 std::vector<SiStripNoises::ratioData> SiStripNoises::operator/(const SiStripNoises& d) {
268  std::vector<ratioData> result;
269  ratioData aData;
270 
273 
274  //Divide result by d
275  for (; iter != iterE; ++iter) {
276  float value;
277  //get noise from d
278  aData.detid = iter->detid;
279  aData.values.clear();
280  Range d_range = d.getRange(iter->detid);
281  Range range = Range(v_noises.begin() + iter->ibegin, v_noises.begin() + iter->iend);
282 
283  //if denominator is missing, put the ratio value to 0xFFFF (=inf)
284  size_t strip = 0, stripE = (range.second - range.first) * 8 / 9;
285  for (; strip < stripE; ++strip) {
286  if (d_range.first == d_range.second) {
287  value = 0xFFFF;
288  } else {
289  value = getNoise(strip, range) / d.getNoise(strip, d_range);
290  }
291  aData.values.push_back(value);
292  }
293  result.push_back(aData);
294  }
295 
296  iter = d.getRegistryVectorBegin();
297  iterE = d.getRegistryVectorEnd();
298 
299  //Divide result by d
300  for (; iter != iterE; ++iter) {
301  float value;
302  //get noise from d
303  Range range = this->getRange(iter->detid);
304  Range d_range = Range(d.v_noises.begin() + iter->ibegin, d.v_noises.begin() + iter->iend);
305  if (range.first == range.second) {
306  aData.detid = iter->detid;
307  aData.values.clear();
308  size_t strip = 0, stripE = (d_range.second - d_range.first) * 8 / 9;
309  for (; strip < stripE; ++strip) {
310  value = 0.;
311  aData.values.push_back(value);
312  }
313  result.push_back(aData);
314  }
315  }
316 
317  return result;
318 }
SiStripNoises::getDataVectorBegin
ContainerIterator getDataVectorBegin() const
Definition: SiStripNoises.h:61
SiStripNoises::printSummary
void printSummary(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Definition: SiStripNoises.cc:224
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
sistrip::extrainfo::noise_
static const char noise_[]
Definition: ConstantsForDqm.h:47
mps_fire.i
i
Definition: mps_fire.py:428
SiStripDetSummary.h
input
static const std::string input
Definition: EdmProvDump.cc:48
SiStripPI::mean
Definition: SiStripPayloadInspectorHelper.h:169
SiStripNoises::DetRegistry::detid
uint32_t detid
Definition: SiStripNoises.h:33
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
SiStripNoises
Definition: SiStripNoises.h:25
SiStripNoises::put
bool put(const uint32_t &detID, const InputVector &input)
Definition: SiStripNoises.cc:16
SiStripNoises::ratioData::values
std::vector< float > values
Definition: SiStripNoises.h:29
min
T min(T a, T b)
Definition: MathUtil.h:58
TrackerTopology
Definition: TrackerTopology.h:16
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
pos
Definition: PixelAliasList.h:18
SiStripNoises::getRegistryVectorEnd
RegistryIterator getRegistryVectorEnd() const
Definition: SiStripNoises.h:64
SiStripNoises.h
SiStripNoises::StrictWeakOrdering
Definition: SiStripNoises.h:40
findQualityFiles.v
v
Definition: findQualityFiles.py:179
SiStripNoises::getRange
const Range getRange(const uint32_t detID) const
Definition: SiStripNoises.cc:34
SiStripNoises::getDetIds
void getDetIds(std::vector< uint32_t > &DetIds_) const
Definition: SiStripNoises.cc:58
SiStripPI::rms
Definition: SiStripPayloadInspectorHelper.h:169
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
DetId
Definition: DetId.h:17
SiStripNoises::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
mps_fire.end
end
Definition: mps_fire.py:242
SiStripNoises::setData
void setData(float noise_, InputVector &vped)
Definition: SiStripNoises.cc:74
SiStripNoises::ratioData::detid
uint32_t detid
Definition: SiStripNoises.h:28
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
SiStripNoises::SiStripNoises
SiStripNoises()
Definition: SiStripNoises.h:53
SiStripNoises::DetRegistry
Definition: SiStripNoises.h:32
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
SiStripNoises::getRangeByPos
Range getRangeByPos(unsigned short pos) const
Definition: SiStripNoises.cc:48
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
SiStripNoises::get9bits
static uint16_t get9bits(const uint8_t *&ptr, int8_t skip)
Definition: SiStripNoises.h:111
SiStripNoises::DetRegistry::ibegin
uint32_t ibegin
Definition: SiStripNoises.h:34
SiStripNoises::indexes
Registry indexes
Definition: SiStripNoises.h:98
value
Definition: value.py:1
SiStripNoises::verify
static void verify(uint16_t strip, const Range &range)
Definition: SiStripNoises.cc:68
SiStripNoises::printDebug
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Definition: SiStripNoises.cc:196
SiStripNoises::v_noises
Container v_noises
Definition: SiStripNoises.h:97
SiStripNoises::ratioData
Definition: SiStripNoises.h:27
SiStripNoises::getRegistryVectorBegin
RegistryIterator getRegistryVectorBegin() const
Definition: SiStripNoises.h:63
SiStripNoises::allNoises
void allNoises(std::vector< float > &noises, const Range &range) const
Definition: SiStripNoises.cc:122
relativeConstraints.value
value
Definition: relativeConstraints.py:53
Exception
Definition: hltDiff.cc:246
SiStripNoises::encode
static void encode(const InputVector &Vi, std::vector< unsigned char > &Vo_CHAR)
Definition: SiStripNoises.cc:78
Exception.h
SiStripDetSummary
Definition: SiStripDetSummary.h:28
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
SiStripNoises::RegistryIterator
Registry::const_iterator RegistryIterator
Definition: SiStripNoises.h:49
sd
double sd
Definition: CascadeWrapper.h:113
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ztail.d
d
Definition: ztail.py:151
mps_fire.result
result
Definition: mps_fire.py:311
SiStripNoises::InputVector
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:50
SiStripNoises::getNoise
static float getNoise(uint16_t strip, const Range &range)
Definition: SiStripNoises.h:73
SiStripNoises::operator/
std::vector< ratioData > operator/(const SiStripNoises &d)
Definition: SiStripNoises.cc:267
HLTEgPhaseIITestSequence_cff.noises
noises
Definition: HLTEgPhaseIITestSequence_cff.py:1348
SiStripNoises::DetRegistry::iend
uint32_t iend
Definition: SiStripNoises.h:35
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443