CMS 3D CMS Logo

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