CMS 3D CMS Logo

SiStripThreshold.cc
Go to the documentation of this file.
4 #include <cassert>
5 #include <algorithm>
6 #include <math.h>
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 = std::lower_bound(indexes.begin(),indexes.end(),DetId,SiStripThreshold::StrictWeakOrdering());
12  if (p!=indexes.end() && p->detid==DetId){
13  edm::LogError("SiStripThreshold") << "[" << __PRETTY_FUNCTION__ << "] SiStripThreshold for DetID " << DetId << " is already stored. Skippig this put" << std::endl;
14  return false;
15  }
16 
17  SiStripThreshold::Container::iterator new_end=compact(vect);
18 
19  size_t sd= new_end-vect.begin();
20  DetRegistry detregistry;
21  detregistry.detid=DetId;
22  detregistry.ibegin=v_threshold.size();
23  detregistry.iend=v_threshold.size()+sd;
24  indexes.insert(p,detregistry);
25 
26  v_threshold.insert(v_threshold.end(),vect.begin(),new_end);
27 
28  return true;
29 }
30 
31 SiStripThreshold::Container::iterator SiStripThreshold::compact(Container& input) {
32  std::stable_sort(input.begin(),input.end());
33  return std::unique(input.begin(),input.end());
34 }
35 
37  // get SiStripThreshold Range of DetId
38 
39  RegistryIterator p = std::lower_bound(indexes.begin(),indexes.end(),DetId,SiStripThreshold::StrictWeakOrdering());
40  if (p==indexes.end()|| p->detid!=DetId)
41  return SiStripThreshold::Range(v_threshold.end(),v_threshold.end());
42  else
43  return SiStripThreshold::Range(v_threshold.begin()+p->ibegin,v_threshold.begin()+p->iend);
44 }
45 
46 
47 void SiStripThreshold::getDetIds(std::vector<uint32_t>& DetIds_) const {
48  // returns vector of DetIds in map
51  for (SiStripThreshold::RegistryIterator p=begin; p != end; ++p) {
52  DetIds_.push_back(p->detid);
53  }
54 }
55 
56 void SiStripThreshold::setData(const uint16_t& strip, const float& lTh,const float& hTh, Container& vthr){
57  Data a;
58  a.encode(strip,lTh,hTh);
59  vthr.push_back(a);
60 }
61 
62 void SiStripThreshold::setData(const uint16_t& strip, const float& lTh,const float& hTh, const float& cTh, Container& vthr){
63  Data a;
64  a.encode(strip,lTh,hTh,cTh);
65  vthr.push_back(a);
66 }
67 
68 SiStripThreshold::Data SiStripThreshold::getData(const uint16_t& strip, const Range& range) const {
70  ContainerIterator p = std::upper_bound(range.first,range.second,estrip,SiStripThreshold::dataStrictWeakOrdering());
71  if (p!=range.first){
72  return *(--p);
73  }
74  else{
75  throw cms::Exception("CorruptedData")
76  << "[SiStripThreshold::getData] asking for data for a strip " << strip << " lower then the first stored strip " << p->getFirstStrip();
77  }
78 }
79 
80 void SiStripThreshold::allThresholds(std::vector<float> &lowThs, std::vector<float> &highThs, const Range& range) const {
81  ContainerIterator it = range.first;
82  size_t strips = lowThs.size();
83  assert(strips == highThs.size());
84  while (it != range.second) {
85  size_t firstStrip = it->getFirstStrip();
86  //std::cout << "First strip is " << firstStrip << std::endl;
87  float high = it->getHth(), low = it->getLth();
88  //std::cout << "High is " << high << ", low is " << low << std::endl;
89  ++it; // increment the pointer
90  size_t lastStrip = (it == range.second ? strips : it->getFirstStrip());
91  //std::cout << "Last strip is " << lastStrip << std::endl;
92  if (lastStrip > strips) {
93  it = range.second; // I should stop here,
94  lastStrip = strips; // and fill only 'strips' strips
95  }
96  std::fill( & lowThs[firstStrip] , & lowThs[lastStrip] , low );
97  std::fill( & highThs[firstStrip], & highThs[lastStrip], high );
98  }
99 }
100 
101 void SiStripThreshold::printDebug(std::stringstream& ss) const{
103  ContainerIterator it,eit;
104  for(;rit!=erit;++rit){
105  it=getDataVectorBegin()+rit->ibegin;
106  eit=getDataVectorBegin()+rit->iend;
107  ss << "\ndetid: " << rit->detid << " \t ";
108  for(;it!=eit;++it){
109  ss << "\n \t ";
110  it->print(ss);
111  }
112  }
113 }
114 
115 void SiStripThreshold::printSummary(std::stringstream& ss) const{
117  ContainerIterator it,eit,itp;
118  float meanLth, meanHth, meanCth; //mean value
119  float rmsLth, rmsHth, rmsCth; //rms value
120  float maxLth, maxHth, maxCth; //max value
121  float minLth, minHth, minCth; //min value
122  uint16_t n;
123  uint16_t firstStrip,stripRange;
124  for(;rit!=erit;++rit){
125  it=getDataVectorBegin()+rit->ibegin;
126  eit=getDataVectorBegin()+rit->iend;
127  ss << "\ndetid: " << rit->detid << " \t ";
128 
129  meanLth=0; meanHth=0; meanCth=0; //mean value
130  rmsLth=0; rmsHth=0; rmsCth=0; //rms value
131  maxLth=0; maxHth=0; maxCth=0; //max value
132  minLth=10000; minHth=10000; minCth=10000; //min value
133  n=0;
134  firstStrip=0;
135  for(;it!=eit;++it){
136  itp=it+1;
137  firstStrip=it->getFirstStrip();
138  if(itp!=eit)
139  stripRange=(itp->getFirstStrip()-firstStrip);
140  else
141  stripRange=firstStrip>511?768-firstStrip:512-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
142 
143  addToStat(it->getLth() ,stripRange,meanLth,rmsLth,minLth,maxLth);
144  addToStat(it->getHth() ,stripRange,meanHth,rmsHth,minHth,maxHth);
145  addToStat(it->getClusth(),stripRange,meanCth,rmsCth,minCth,maxCth);
146  n+=stripRange;
147  }
148  meanLth/=n;
149  meanHth/=n;
150  meanCth/=n;
151  rmsLth= sqrt(rmsLth/n-meanLth*meanLth);
152  rmsHth= sqrt(rmsHth/n-meanHth*meanHth);
153  rmsCth= sqrt(rmsCth/n-meanCth*meanCth);
154  ss<< "\nn " << n << " \tmeanLth " << meanLth << " \t rmsLth " << rmsLth << " \t minLth " << minLth << " \t maxLth " << maxLth;
155  ss<< "\n\tmeanHth " << meanHth << " \t rmsHth " << rmsHth << " \t minHth " << minHth << " \t maxHth " << maxHth;
156  ss<< "\n\tmeanCth " << meanCth << " \t rmsCth " << rmsCth << " \t minCth " << minCth << " \t maxCth " << maxCth;
157  }
158 }
159 
160 void SiStripThreshold::addToStat(float value, uint16_t& range, float& sum, float& sum2, float& min, float& max) const{
161  sum+=value*range;
162  sum2+=value*value*range;
163  if(value<min)
164  min=value;
165  if(value>max)
166  max=value;
167 }
static const uint32_t FirstThStripShift_
bool put(const uint32_t &detID, const InputVector &vect)
Container::iterator compact(Container &input)
ContainerIterator getDataVectorBegin() const
void allThresholds(std::vector< float > &lowThs, std::vector< float > &highThs, const Range &range) const
static std::string const input
Definition: EdmProvDump.cc:44
std::vector< Data > Container
T sqrt(T t)
Definition: SSEVec.h:18
def unique(seq, keepstr=True)
Definition: tier0.py:24
SiStripThreshold::Data getData(const uint16_t &strip, const Range &range) const
#define end
Definition: vmac.h:37
Definition: value.py:1
T min(T a, T b)
Definition: MathUtil.h:58
RegistryIterator getRegistryVectorBegin() const
void encode(const uint16_t &strip, const float &lTh, const float &hTh)
Definition: DetId.h:18
void printDebug(std::stringstream &ss) const
Prints all the thresholds for all DetIds.
std::pair< ContainerIterator, ContainerIterator > Range
static const uint32_t HighThStripMask_
double sd
void getDetIds(std::vector< uint32_t > &DetIds_) const
void setData(const uint16_t &strip, const float &lTh, const float &hTh, Container &vthr)
void printSummary(std::stringstream &ss) const
Prints mean, rms, min and max threshold values for each DetId.
#define begin
Definition: vmac.h:30
static const uint32_t FirstThStripMask_
double a
Definition: hdecay.h:121
Registry::const_iterator RegistryIterator
void addToStat(float value, uint16_t &range, float &sum, float &sum2, float &min, float &max) const
const Range getRange(const uint32_t &detID) const
RegistryIterator getRegistryVectorEnd() const
Container::const_iterator ContainerIterator