CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripApvGain.cc
Go to the documentation of this file.
5 
6 #include <algorithm>
7 
8 bool SiStripApvGain::put(const uint32_t& DetId, Range input) {
9  // put in SiStripApvGain of DetId
10  RegistryIterator p = std::lower_bound(v_detids.begin(),v_detids.end(),DetId);
11  if (p!=v_detids.end() && *p==DetId){
12  edm::LogError("SiStripApvGain") << "[" << __PRETTY_FUNCTION__ << "] SiStripApvGain for DetID " << DetId << " is already stored. Skippig this put" << std::endl;
13  return false;
14  }
15 
16  unsigned int sd= input.second-input.first;
17  unsigned int pd= p-v_detids.begin();
18 
19  unsigned int ibegin=v_gains.size();
20  unsigned int iend =v_gains.size()+sd;
21  v_detids.insert(p,DetId);
22  v_ibegin.insert(v_ibegin.begin()+pd,ibegin);
23  v_iend.insert(v_iend.begin()+pd,iend);
24 
25  v_gains.insert(v_gains.end(),input.first,input.second);
26  return true;
27 }
28 
30  // get SiStripApvGain Range of DetId
31  RegistryConstIterator p = std::lower_bound(v_detids.begin(),v_detids.end(),DetId);
32  if (p==v_detids.end() || *p!=DetId)
33  return SiStripApvGain::Range(v_gains.end(),v_gains.end());
34  else{
35  unsigned int pd= p-v_detids.begin();
36  unsigned int ibegin = *(v_ibegin.begin()+pd);
37  unsigned int iend = *(v_iend.begin()+pd);
38  return SiStripApvGain::Range(v_gains.begin()+ibegin,v_gains.begin()+iend);
39  }
40 }
41 
42 void SiStripApvGain::getDetIds(std::vector<uint32_t>& DetIds_) const {
43  // returns vector of DetIds in map
44  // DetIds_=v_detids;
45  DetIds_.insert(DetIds_.begin(),v_detids.begin(),v_detids.end());
46 }
47 
48 float SiStripApvGain::getStripGain(const uint16_t& strip, const Range& range) const {
49  uint16_t apv = (uint16_t) (strip/128);
50  if (apv>=range.second-range.first){
51  throw cms::Exception("CorruptedData")
52  << "[SiStripApvGain::getApvGain] looking for SiStripApvGain for a strip out of range: strip " << strip << " apv " << apv << std::endl;
53  }
54 
55  // return static_cast<float> (*(range.first+apv));
56 
57  return *(range.first+apv);
58 
59 }
60 
61 float SiStripApvGain::getApvGain(const uint16_t& apv, const Range& range) const {
62  if (apv>=range.second-range.first){
63  throw cms::Exception("CorruptedData")
64  << "[SiStripApvGain::getApvGain] looking for SiStripApvGain for an apv out of range: apv " << apv << std::endl;
65  }
66 
67  // return static_cast<float> (*(range.first+apv));
68 
69  return *(range.first+apv);
70 }
71 
72 void SiStripApvGain::printDebug(std::stringstream & ss) const
73 {
74  std::vector<unsigned int>::const_iterator detid = v_detids.begin();
75  ss << "Number of detids " << v_detids.size() << std::endl;
76 
77  for( ; detid != v_detids.end(); ++detid ) {
78  SiStripApvGain::Range range = getRange(*detid);
79  int apv=0;
80  for( int it=0; it < range.second - range.first; ++it ) {
81  ss << "detid " << *detid << " \t"
82  << " apv " << apv++ << " \t"
83  << getApvGain(it,range) << " \t"
84  << std::endl;
85  }
86  }
87 }
88 
89 void SiStripApvGain::printSummary(std::stringstream & ss) const
90 {
91  SiStripDetSummary summaryGain;
92 
93  std::vector<uint32_t>::const_iterator detid = v_detids.begin();
94  for( ; detid != v_detids.end(); ++detid ) {
95  Range range = getRange(*detid);
96  for( int it=0; it < range.second - range.first; ++it ) {
97  summaryGain.add(*detid, getApvGain(it, range));
98  }
99  }
100  ss << "Summary of gain values:" << std::endl;
101  summaryGain.print(ss, true);
102 }
Registry::const_iterator RegistryConstIterator
Registry::iterator RegistryIterator
void getDetIds(std::vector< uint32_t > &DetIds_) const
bool put(const uint32_t &detID, Range input)
float getStripGain(const uint16_t &strip, const Range &range) const
void printDebug(std::stringstream &ss) const
std::vector< float > v_gains
void printSummary(std::stringstream &ss) const
std::pair< ContainerIterator, ContainerIterator > Range
std::vector< unsigned int > v_iend
void print(std::stringstream &ss, const bool mean=true) const
Definition: DetId.h:20
std::vector< unsigned int > v_detids
double sd
const Range getRange(const uint32_t &detID) const
std::vector< unsigned int > v_ibegin
void add(const DetId &detid, const float &value)
Used to compute the mean value of the value variable divided by subdetector, layer and mono/stereo...
float getApvGain(const uint16_t &apv, const Range &range) const