File indexing completed on 2024-04-06 11:58:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
0011 #include "CalibFormats/SiStripObjects/interface/SiStripDetInfo.h"
0012 #include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "FWCore/Utilities/interface/typelookup.h"
0015 #include <sstream>
0016
0017 void SiStripGain::multiply(const SiStripApvGain &apvgain,
0018 const double &factor,
0019 const std::pair<std::string, std::string> &recordLabelPair,
0020 const SiStripDetInfo &detInfo) {
0021
0022 if (apvgain_ == nullptr) {
0023 if ((factor != 1) && (factor != 0)) {
0024 fillNewGain(&apvgain, factor, detInfo);
0025 } else {
0026
0027
0028 apvgain_ = &apvgain;
0029 }
0030 } else {
0031
0032
0033 fillNewGain(apvgain_, 1., detInfo, &apvgain, factor);
0034 }
0035 recordLabelPair_.push_back(recordLabelPair);
0036 apvgainVector_.push_back(&apvgain);
0037 normVector_.push_back(factor);
0038 }
0039
0040 void SiStripGain::fillNewGain(const SiStripApvGain *apvgain,
0041 const double &factor,
0042 const SiStripDetInfo &detInfo,
0043 const SiStripApvGain *apvgain2,
0044 const double &factor2) {
0045 SiStripApvGain *newApvGain = new SiStripApvGain;
0046 const auto &DetInfos = detInfo.getAllData();
0047
0048
0049
0050 std::vector<uint32_t> detIds;
0051 apvgain->getDetIds(detIds);
0052 std::vector<uint32_t>::const_iterator it = detIds.begin();
0053 for (; it != detIds.end(); ++it) {
0054 auto detInfoIt = DetInfos.find(*it);
0055 if (detInfoIt != DetInfos.end()) {
0056 std::vector<float> theSiStripVector;
0057
0058
0059 SiStripApvGain::Range range = apvgain->getRange(*it);
0060
0061 SiStripApvGain::Range range2;
0062 if (apvgain2 != nullptr) {
0063 range2 = apvgain2->getRange(*it);
0064 }
0065
0066 for (int apv = 0; apv < detInfoIt->second.nApvs; ++apv) {
0067 float apvGainValue = apvgain->getApvGain(apv, range) / factor;
0068
0069 if ((apvgain2 != nullptr) && (factor2 != 0.)) {
0070 apvGainValue *= apvgain2->getApvGain(apv, range2) / factor2;
0071 }
0072
0073 theSiStripVector.push_back(apvGainValue);
0074 }
0075 SiStripApvGain::Range inputRange(theSiStripVector.begin(), theSiStripVector.end());
0076 if (!newApvGain->put(*it, inputRange)) {
0077 edm::LogError("SiStripGain") << "detid already exists" << std::endl;
0078 }
0079 }
0080 }
0081 apvgain_ = newApvGain;
0082
0083 apvgainAutoPtr_.reset(newApvGain);
0084 }
0085
0086 float SiStripGain::getStripGain(const uint16_t &strip, const SiStripApvGain::Range &range, const uint32_t index) const {
0087 if (!(apvgainVector_.empty())) {
0088 return (apvgainVector_[index]->getStripGain(strip, range));
0089 }
0090 edm::LogError("SiStripGain::getStripGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
0091 return 1.;
0092 }
0093
0094 float SiStripGain::getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range, const uint32_t index) const {
0095 if (!(apvgainVector_.empty())) {
0096 return (apvgainVector_[index]->getApvGain(apv, range)) / (normVector_[index]);
0097 }
0098 edm::LogError("SiStripGain::getApvGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
0099 return 1.;
0100 }
0101
0102 void SiStripGain::getDetIds(std::vector<uint32_t> &DetIds_) const {
0103
0104 return apvgain_->getDetIds(DetIds_);
0105 }
0106
0107 const SiStripApvGain::Range SiStripGain::getRange(const uint32_t &DetId, const uint32_t index) const {
0108 return apvgainVector_[index]->getRange(DetId);
0109 }
0110
0111 void SiStripGain::printDebug(std::stringstream &ss, const TrackerTopology * ) const {
0112 std::vector<unsigned int> detIds;
0113 getDetIds(detIds);
0114 std::vector<unsigned int>::const_iterator detid = detIds.begin();
0115 ss << "Number of detids " << detIds.size() << std::endl;
0116
0117 for (; detid != detIds.end(); ++detid) {
0118 SiStripApvGain::Range range = getRange(*detid);
0119 int apv = 0;
0120 for (int it = 0; it < range.second - range.first; ++it) {
0121 ss << "detid " << *detid << " \t"
0122 << " apv " << apv++ << " \t" << getApvGain(it, range) << " \t" << std::endl;
0123 }
0124 }
0125 }
0126
0127 void SiStripGain::printSummary(std::stringstream &ss, const TrackerTopology *trackerTopo) const {
0128 SiStripDetSummary summaryGain{trackerTopo};
0129
0130 std::vector<unsigned int> detIds;
0131 getDetIds(detIds);
0132 std::vector<uint32_t>::const_iterator detid = detIds.begin();
0133 for (; detid != detIds.end(); ++detid) {
0134 SiStripApvGain::Range range = getRange(*detid);
0135 for (int it = 0; it < range.second - range.first; ++it) {
0136 summaryGain.add(*detid, getApvGain(it, range));
0137 }
0138 }
0139 ss << "Summary of gain values:" << std::endl;
0140 summaryGain.print(ss, true);
0141 }