File indexing completed on 2024-04-06 12:29:22
0001 #include <SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2Linearizer.h>
0002
0003
0004
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006
0007 EcalEBPhase2Linearizer::EcalEBPhase2Linearizer(bool debug)
0008 : debug_(debug), init_(false), peds_(nullptr), badXStatus_(nullptr) {}
0009
0010 EcalEBPhase2Linearizer::~EcalEBPhase2Linearizer() {
0011 if (init_) {
0012 for (int i = 0; i < (int)vectorbadXStatus_.size(); i++) {
0013 delete vectorbadXStatus_[i];
0014 }
0015 }
0016 }
0017
0018 void EcalEBPhase2Linearizer::setParameters(EBDetId detId,
0019 const EcalLiteDTUPedestalsMap *ecaltpPed,
0020 const EcalEBPhase2TPGLinearizationConstMap *ecaltpLin,
0021 const EcalTPGCrystalStatus *ecaltpBadX)
0022
0023 {
0024 EcalLiteDTUPedestalsMap::const_iterator itped = ecaltpPed->getMap().find(detId);
0025 if (itped != ecaltpPed->end())
0026 peds_ = &(*itped);
0027 else
0028 edm::LogError("EcalEBPhase2Linearizer") << " could not find EcalLiteDTUPedestal entry for " << detId << std::endl;
0029
0030 const EcalEBPhase2TPGLinearizationConstMap &linMap = ecaltpLin->getMap();
0031 EcalEBPhase2TPGLinearizationConstMapIterator it = linMap.find(detId.rawId());
0032 if (it != linMap.end()) {
0033 linConsts_ = &(*it);
0034 } else
0035 edm::LogError("EcalEBPhase2Linearizer")
0036 << " could not find EcalEBPhase2TPGLinearizationConstMap entry for " << detId.rawId() << std::endl;
0037
0038 const EcalTPGCrystalStatusMap &badXMap = ecaltpBadX->getMap();
0039 EcalTPGCrystalStatusMapIterator itbadX = badXMap.find(detId.rawId());
0040 if (itbadX != badXMap.end()) {
0041 badXStatus_ = &(*itbadX);
0042 } else {
0043 edm::LogWarning("EcalTPG") << " could not find EcalTPGCrystalStatusMap entry for " << detId.rawId();
0044 badXStatus_ = new EcalTPGCrystalStatusCode();
0045 vectorbadXStatus_.push_back(&(*badXStatus_));
0046 init_ = true;
0047 }
0048 }
0049
0050 int EcalEBPhase2Linearizer::doOutput() {
0051 int tmpIntOut;
0052 if (uncorrectedSample_) {
0053 tmpIntOut = (uncorrectedSample_ - base_ + I2CSub_);
0054 } else {
0055 tmpIntOut = 0;
0056 }
0057 if (tmpIntOut < 0) {
0058 tmpIntOut = 0;
0059 }
0060 uint output = tmpIntOut;
0061 output = (output * mult_) >> shift_;
0062
0063
0064
0065 return output;
0066 }
0067
0068 int EcalEBPhase2Linearizer::setInput(const EcalLiteDTUSample &RawSam)
0069
0070 {
0071 uncorrectedSample_ = RawSam.adc();
0072 gainID_ = RawSam.gainId();
0073
0074 base_ = peds_->mean(gainID_);
0075
0076 if (gainID_ == 0) {
0077 mult_ = linConsts_->mult_x10;
0078 shift_ = linConsts_->shift_x10;
0079 I2CSub_ = linConsts_->i2cSub_x10;
0080 } else {
0081 mult_ = linConsts_->mult_x1;
0082 shift_ = linConsts_->shift_x1;
0083 I2CSub_ = linConsts_->i2cSub_x1;
0084 }
0085
0086 return 1;
0087 }
0088
0089 void EcalEBPhase2Linearizer::process(const EBDigiCollectionPh2::Digi &df, std::vector<int> &output_percry) {
0090
0091
0092
0093
0094
0095
0096
0097
0098 for (int i = 0; i < df.size(); i++) {
0099 EcalLiteDTUSample thisSample = df[i];
0100 setInput(thisSample);
0101 output_percry[i] = doOutput();
0102 }
0103
0104 if (debug_) {
0105 LogDebug("EcalEBPhase2Linearizer") << " mult "
0106 << " ";
0107 for (int i = 0; i < df.size(); i++) {
0108 EcalLiteDTUSample thisSample = df[i];
0109 setInput(thisSample);
0110 LogDebug("") << mult_ << " ";
0111 }
0112 LogDebug("") << " " << std::endl;
0113
0114 LogDebug("") << " gainID "
0115 << " ";
0116 for (int i = 0; i < df.size(); i++) {
0117 EcalLiteDTUSample thisSample = df[i];
0118 setInput(thisSample);
0119 LogDebug("") << gainID_ << " ";
0120 }
0121 LogDebug("") << " " << std::endl;
0122
0123 LogDebug("") << " Ped "
0124 << " ";
0125 for (int i = 0; i < df.size(); i++) {
0126 EcalLiteDTUSample thisSample = df[i];
0127 setInput(thisSample);
0128 LogDebug("") << base_ << " ";
0129 }
0130 LogDebug("") << " " << std::endl;
0131
0132 LogDebug("") << " i2c "
0133 << " ";
0134 for (int i = 0; i < df.size(); i++) {
0135 EcalLiteDTUSample thisSample = df[i];
0136 setInput(thisSample);
0137 LogDebug("") << I2CSub_ << " ";
0138 }
0139 LogDebug("") << " " << std::endl;
0140
0141 LogDebug("") << " shift "
0142 << " ";
0143 for (int i = 0; i < df.size(); i++) {
0144 EcalLiteDTUSample thisSample = df[i];
0145 setInput(thisSample);
0146 LogDebug("") << shift_ << " ";
0147 }
0148 LogDebug("") << " " << std::endl;
0149
0150 LogDebug("") << " lin out "
0151 << " ";
0152 for (int i = 0; i < df.size(); i++) {
0153 LogDebug("") << output_percry[i] << " ";
0154 }
0155
0156 LogDebug("") << " " << std::endl;
0157
0158 LogDebug("") << " EcalEBPhase2Linearizer::process(const .. Final output " << std::endl;
0159 LogDebug("") << " output_percry "
0160 << " ";
0161 for (int i = 0; i < df.size(); i++) {
0162 LogDebug("") << output_percry[i] << " ";
0163 }
0164 LogDebug("") << " " << std::endl;
0165 }
0166 return;
0167 }