CMS 3D CMS Logo

SiStripThreshold.cc
Go to the documentation of this file.
4 #include <cassert>
5 #include <algorithm>
6 #include <cmath>
7 
8 bool SiStripThreshold::put(const uint32_t& DetId, const InputVector& _vect) {
9  InputVector vect = _vect;
10  // put in SiStripThreshold::v_threshold of DetId
11  Registry::iterator p =
13  if (p != indexes.end() && p->detid == DetId) {
14  edm::LogError("SiStripThreshold") << "[" << __PRETTY_FUNCTION__ << "] SiStripThreshold for DetID " << DetId
15  << " is already stored. Skipping this put" << std::endl;
16  return false;
17  }
18 
19  SiStripThreshold::Container::iterator new_end = compact(vect);
20 
21  size_t sd = new_end - vect.begin();
22  DetRegistry detregistry;
23  detregistry.detid = DetId;
24  detregistry.ibegin = v_threshold.size();
25  detregistry.iend = v_threshold.size() + sd;
26  indexes.insert(p, detregistry);
27 
28  v_threshold.insert(v_threshold.end(), vect.begin(), new_end);
29 
30  return true;
31 }
32 
33 SiStripThreshold::Container::iterator SiStripThreshold::compact(Container& input) {
34  std::stable_sort(input.begin(), input.end());
35  return std::unique(input.begin(), input.end());
36 }
37 
39  // get SiStripThreshold Range of DetId
40 
42  if (p == indexes.end() || p->detid != DetId)
43  return SiStripThreshold::Range(v_threshold.end(), v_threshold.end());
44  else
45  return SiStripThreshold::Range(v_threshold.begin() + p->ibegin, v_threshold.begin() + p->iend);
46 }
47 
48 void SiStripThreshold::getDetIds(std::vector<uint32_t>& DetIds_) const {
49  // returns vector of DetIds in map
52  for (SiStripThreshold::RegistryIterator p = begin; p != end; ++p) {
53  DetIds_.push_back(p->detid);
54  }
55 }
56 
57 void SiStripThreshold::setData(const uint16_t& strip, const float& lTh, const float& hTh, Container& vthr) {
58  Data a;
59  a.encode(strip, lTh, hTh);
60  vthr.push_back(a);
61 }
62 
64  const uint16_t& strip, const float& lTh, const float& hTh, const float& cTh, Container& vthr) {
65  Data a;
66  a.encode(strip, lTh, hTh, cTh);
67  vthr.push_back(a);
68 }
69 
71  uint16_t estrip =
74  if (p != range.first) {
75  return *(--p);
76  } else {
77  throw cms::Exception("CorruptedData") << "[SiStripThreshold::getData] asking for data for a strip " << strip
78  << " lower then the first stored strip " << p->getFirstStrip();
79  }
80 }
81 
82 void SiStripThreshold::allThresholds(std::vector<float>& lowThs,
83  std::vector<float>& highThs,
84  const Range& range) const {
85  ContainerIterator it = range.first;
86  size_t strips = lowThs.size();
87  assert(strips == highThs.size());
88  while (it != range.second) {
89  size_t firstStrip = it->getFirstStrip();
90  //std::cout << "First strip is " << firstStrip << std::endl;
91  float high = it->getHth(), low = it->getLth();
92  //std::cout << "High is " << high << ", low is " << low << std::endl;
93  ++it; // increment the pointer
94  size_t lastStrip = (it == range.second ? strips : it->getFirstStrip());
95  //std::cout << "Last strip is " << lastStrip << std::endl;
96  if (lastStrip > strips) {
97  it = range.second; // I should stop here,
98  lastStrip = strips; // and fill only 'strips' strips
99  }
100  std::fill(&lowThs[firstStrip], &lowThs[lastStrip], low);
101  std::fill(&highThs[firstStrip], &highThs[lastStrip], high);
102  }
103 }
104 
105 void SiStripThreshold::printDebug(std::stringstream& ss, const TrackerTopology* /*trackerTopo*/) const {
107  ContainerIterator it, eit;
108  for (; rit != erit; ++rit) {
109  it = getDataVectorBegin() + rit->ibegin;
110  eit = getDataVectorBegin() + rit->iend;
111  ss << "\ndetid: " << rit->detid << " \t ";
112  for (; it != eit; ++it) {
113  ss << "\n \t ";
114  it->print(ss);
115  }
116  }
117 }
118 
119 void SiStripThreshold::printSummary(std::stringstream& ss, const TrackerTopology* /*trackerTopo*/) const {
121  ContainerIterator it, eit, itp;
122  float meanLth, meanHth, meanCth; //mean value
123  float rmsLth, rmsHth, rmsCth; //rms value
124  float maxLth, maxHth, maxCth; //max value
125  float minLth, minHth, minCth; //min value
126  uint16_t n;
127  uint16_t firstStrip, stripRange;
128  for (; rit != erit; ++rit) {
129  it = getDataVectorBegin() + rit->ibegin;
130  eit = getDataVectorBegin() + rit->iend;
131  ss << "\ndetid: " << rit->detid << " \t ";
132 
133  meanLth = 0;
134  meanHth = 0;
135  meanCth = 0; //mean value
136  rmsLth = 0;
137  rmsHth = 0;
138  rmsCth = 0; //rms value
139  maxLth = 0;
140  maxHth = 0;
141  maxCth = 0; //max value
142  minLth = 10000;
143  minHth = 10000;
144  minCth = 10000; //min value
145  n = 0;
146  firstStrip = 0;
147  for (; it != eit; ++it) {
148  itp = it + 1;
149  firstStrip = it->getFirstStrip();
150  if (itp != eit)
151  stripRange = (itp->getFirstStrip() - firstStrip);
152  else
153  stripRange =
154  firstStrip > 511
155  ? 768 - firstStrip
156  : 512 -
157  firstStrip; //*FIXME, I dont' know ithis class the strip number of a detector, so I assume wrongly that if the last firstStrip<511 the detector has only 512 strips. Clearly wrong. to be fixed
158 
159  addToStat(it->getLth(), stripRange, meanLth, rmsLth, minLth, maxLth);
160  addToStat(it->getHth(), stripRange, meanHth, rmsHth, minHth, maxHth);
161  addToStat(it->getClusth(), stripRange, meanCth, rmsCth, minCth, maxCth);
162  n += stripRange;
163  }
164  meanLth /= n;
165  meanHth /= n;
166  meanCth /= n;
167  rmsLth = sqrt(rmsLth / n - meanLth * meanLth);
168  rmsHth = sqrt(rmsHth / n - meanHth * meanHth);
169  rmsCth = sqrt(rmsCth / n - meanCth * meanCth);
170  ss << "\nn " << n << " \tmeanLth " << meanLth << " \t rmsLth " << rmsLth << " \t minLth " << minLth << " \t maxLth "
171  << maxLth;
172  ss << "\n\tmeanHth " << meanHth << " \t rmsHth " << rmsHth << " \t minHth " << minHth << " \t maxHth " << maxHth;
173  ss << "\n\tmeanCth " << meanCth << " \t rmsCth " << rmsCth << " \t minCth " << minCth << " \t maxCth " << maxCth;
174  }
175 }
176 
177 void SiStripThreshold::addToStat(float value, uint16_t& range, float& sum, float& sum2, float& min, float& max) const {
178  sum += value * range;
179  sum2 += value * value * range;
180  if (value < min)
181  min = value;
182  if (value > max)
183  max = value;
184 }
static const uint32_t FirstThStripShift_
bool put(const uint32_t &detID, const InputVector &vect)
Container::iterator compact(Container &input)
void allThresholds(std::vector< float > &lowThs, std::vector< float > &highThs, const Range &range) const
SiStripThreshold::Data getData(const uint16_t &strip, const Range &range) const
void printSummary(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Prints mean, rms, min and max threshold values for each DetId.
Log< level::Error, false > LogError
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:50
std::vector< Data > Container
T sqrt(T t)
Definition: SSEVec.h:19
def unique(seq, keepstr=True)
Definition: tier0.py:24
void addToStat(float value, uint16_t &range, float &sum, float &sum2, float &min, float &max) const
Definition: value.py:1
Definition: DetId.h:17
std::pair< ContainerIterator, ContainerIterator > Range
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Prints all the thresholds for all DetIds.
static const uint32_t HighThStripMask_
void setData(const uint16_t &strip, const float &lTh, const float &hTh, Container &vthr)
const Range getRange(const uint32_t &detID) const
static const uint32_t FirstThStripMask_
double a
Definition: hdecay.h:121
RegistryIterator getRegistryVectorEnd() const
Registry::const_iterator RegistryIterator
ContainerIterator getDataVectorBegin() const
strips
#turn off noise in all subdetectors simHcalUnsuppressedDigis.doNoise = False mix.digitizers.hcal.doNoise = False simEcalUnsuppressedDigis.doNoise = False mix.digitizers.ecal.doNoise = False simEcalUnsuppressedDigis.doESNoise = False simSiPixelDigis.AddNoise = False mix.digitizers.pixel.AddNoise = False simSiStripDigis.Noise = False mix.digitizers.strip.AddNoise = False
Definition: DigiDM_cff.py:32
void getDetIds(std::vector< uint32_t > &DetIds_) const
RegistryIterator getRegistryVectorBegin() const
Container::const_iterator ContainerIterator