Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:40

0001 #include "CondFormats/SiStripObjects/interface/SiStripApvGain.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h"
0005 
0006 #include <algorithm>
0007 
0008 bool SiStripApvGain::put(const uint32_t& DetId, Range input) {
0009   // put in SiStripApvGain of DetId
0010   RegistryIterator p = std::lower_bound(v_detids.begin(), v_detids.end(), DetId);
0011   if (p != v_detids.end() && *p == DetId) {
0012     edm::LogError("SiStripApvGain") << "[" << __PRETTY_FUNCTION__ << "] SiStripApvGain for DetID " << DetId
0013                                     << " is already stored. Skipping this put" << std::endl;
0014     return false;
0015   }
0016 
0017   unsigned int sd = input.second - input.first;
0018   unsigned int pd = p - v_detids.begin();
0019 
0020   unsigned int ibegin = v_gains.size();
0021   unsigned int iend = v_gains.size() + sd;
0022   v_detids.insert(p, DetId);
0023   v_ibegin.insert(v_ibegin.begin() + pd, ibegin);
0024   v_iend.insert(v_iend.begin() + pd, iend);
0025 
0026   v_gains.insert(v_gains.end(), input.first, input.second);
0027   return true;
0028 }
0029 
0030 const SiStripApvGain::Range SiStripApvGain::getRange(const uint32_t DetId) const {
0031   // get SiStripApvGain Range of DetId
0032   RegistryConstIterator p = std::lower_bound(v_detids.begin(), v_detids.end(), DetId);
0033   if (p == v_detids.end() || *p != DetId)
0034     return SiStripApvGain::Range(v_gains.end(), v_gains.end());
0035   else {
0036     unsigned int pd = p - v_detids.begin();
0037     unsigned int ibegin = *(v_ibegin.begin() + pd);
0038     unsigned int iend = *(v_iend.begin() + pd);
0039     __builtin_prefetch((&v_gains.front()) + ibegin);
0040     return SiStripApvGain::Range(v_gains.begin() + ibegin, v_gains.begin() + iend);
0041   }
0042 }
0043 
0044 SiStripApvGain::Range SiStripApvGain::getRangeByPos(unsigned short pos) const {
0045   if (pos > v_detids.size())
0046     return Range(v_gains.end(), v_gains.end());
0047   unsigned int ibegin = *(v_ibegin.begin() + pos);
0048   unsigned int iend = *(v_iend.begin() + pos);
0049   __builtin_prefetch((&v_gains.front()) + ibegin);
0050   return SiStripApvGain::Range(v_gains.begin() + ibegin, v_gains.begin() + iend);
0051 }
0052 
0053 void SiStripApvGain::getDetIds(std::vector<uint32_t>& DetIds_) const {
0054   // returns vector of DetIds in map
0055   //  DetIds_=v_detids;
0056   DetIds_.insert(DetIds_.begin(), v_detids.begin(), v_detids.end());
0057 }
0058 
0059 #ifdef EDM_ML_DEBUG
0060 float SiStripApvGain::getStripGain(const uint16_t& strip, const Range& range) {
0061   uint16_t apv = (uint16_t)(strip / 128);
0062   if (apv >= range.second - range.first) {
0063     throw cms::Exception("CorruptedData")
0064         << "[SiStripApvGain::getApvGain] looking for SiStripApvGain for a strip out of range: strip " << strip
0065         << " apv " << apv << std::endl;
0066   }
0067 
0068   //  return static_cast<float> (*(range.first+apv));
0069 
0070   return *(range.first + apv);
0071 }
0072 
0073 float SiStripApvGain::getApvGain(const uint16_t& apv, const Range& range) {
0074   if (apv >= range.second - range.first) {
0075     throw cms::Exception("CorruptedData")
0076         << "[SiStripApvGain::getApvGain] looking for SiStripApvGain for an apv out of range: apv " << apv << std::endl;
0077   }
0078 
0079   //  return static_cast<float> (*(range.first+apv));
0080 
0081   return *(range.first + apv);
0082 }
0083 #endif
0084 
0085 void SiStripApvGain::printDebug(std::stringstream& ss, const TrackerTopology* /*trackerTopo*/) const {
0086   std::vector<unsigned int>::const_iterator detid = v_detids.begin();
0087   ss << "Number of detids " << v_detids.size() << std::endl;
0088 
0089   for (; detid != v_detids.end(); ++detid) {
0090     SiStripApvGain::Range range = getRange(*detid);
0091     int apv = 0;
0092     for (int it = 0; it < range.second - range.first; ++it) {
0093       ss << "detid " << *detid << " \t"
0094          << " apv " << apv++ << " \t" << getApvGain(it, range) << " \t" << std::endl;
0095     }
0096   }
0097 }
0098 
0099 void SiStripApvGain::printSummary(std::stringstream& ss, const TrackerTopology* trackerTopo) const {
0100   SiStripDetSummary summaryGain{trackerTopo};
0101 
0102   std::vector<uint32_t>::const_iterator detid = v_detids.begin();
0103   for (; detid != v_detids.end(); ++detid) {
0104     Range range = getRange(*detid);
0105     for (int it = 0; it < range.second - range.first; ++it) {
0106       summaryGain.add(*detid, getApvGain(it, range));
0107     }
0108   }
0109   ss << "Summary of gain values:" << std::endl;
0110   summaryGain.print(ss, true);
0111 }