File indexing completed on 2024-04-06 12:29:28
0001 #include "CondFormats/EcalObjects/interface/EcalTPGGroups.h"
0002 #include "CondFormats/EcalObjects/interface/EcalTPGWeightGroup.h"
0003 #include "CondFormats/EcalObjects/interface/EcalTPGWeightIdMap.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include <SimCalorimetry/EcalTrigPrimAlgos/interface/EcalFenixAmplitudeFilter.h>
0006 #include <iostream>
0007
0008 EcalFenixAmplitudeFilter::EcalFenixAmplitudeFilter(bool tpInfoPrintout)
0009 : inputsAlreadyIn_(0), stripid_{0}, shift_(6), tpInfoPrintout_(tpInfoPrintout) {}
0010
0011 EcalFenixAmplitudeFilter::~EcalFenixAmplitudeFilter() {}
0012
0013 int EcalFenixAmplitudeFilter::setInput(int input, int fgvb) {
0014 if (input > 0X3FFFF) {
0015 edm::LogError("EcalTPG") << "ERROR IN INPUT OF EVEN AMPLITUDE FILTER";
0016 return -1;
0017 }
0018 if (inputsAlreadyIn_ < 5) {
0019 buffer_[inputsAlreadyIn_] = input;
0020 fgvbBuffer_[inputsAlreadyIn_] = fgvb;
0021 inputsAlreadyIn_++;
0022 } else {
0023 for (int i = 0; i < 4; i++) {
0024 buffer_[i] = buffer_[i + 1];
0025 fgvbBuffer_[i] = fgvbBuffer_[i + 1];
0026 }
0027 buffer_[4] = input;
0028 fgvbBuffer_[4] = fgvb;
0029 }
0030 return 1;
0031 }
0032
0033 void EcalFenixAmplitudeFilter::process(std::vector<int> &addout,
0034 std::vector<int> &output,
0035 std::vector<int> &fgvbIn,
0036 std::vector<int> &fgvbOut) {
0037 inputsAlreadyIn_ = 0;
0038 for (unsigned int i = 0; i < 5; i++) {
0039 buffer_[i] = 0;
0040 fgvbBuffer_[i] = 0;
0041 }
0042
0043 for (unsigned int i = 0; i < addout.size(); i++) {
0044 setInput(addout[i], fgvbIn[i]);
0045 process();
0046 if (tpInfoPrintout_) {
0047 if (i >= 4) {
0048 edm::LogVerbatim("EcalTPG") << i << " " << stripid_ << " " << weights_[0] << " " << weights_[1] << " "
0049 << weights_[2] << " " << weights_[3] << " " << weights_[4] << " "
0050 << weights_[0] / 64.0 << " " << weights_[1] / 64.0 << " " << weights_[2] / 64.0
0051 << " " << weights_[3] / 64.0 << " " << weights_[4] / 64.0 << " [" << buffer_[0]
0052 << ", " << buffer_[1] << ", " << buffer_[2] << ", " << buffer_[3] << ", "
0053 << buffer_[4] << "]"
0054 << " --> output: " << processedOutput_ << " EVEN";
0055 }
0056 }
0057 output[i] = processedOutput_;
0058 fgvbOut[i] = processedFgvbOutput_;
0059 }
0060
0061 for (unsigned int i = 0; i < (output.size()); i++) {
0062 if (i != output.size() - 1) {
0063 output[i] = output[i + 1];
0064 fgvbOut[i] = fgvbOut[i + 1];
0065 } else {
0066 output[i] = 0;
0067 fgvbOut[i] = 0;
0068 }
0069 }
0070 return;
0071 }
0072
0073 void EcalFenixAmplitudeFilter::process() {
0074 processedOutput_ = 0;
0075 processedFgvbOutput_ = 0;
0076 if (inputsAlreadyIn_ < 5)
0077 return;
0078 int output = 0;
0079 int fgvbInt = 0;
0080 for (int i = 0; i < 5; i++) {
0081 output += (weights_[i] * buffer_[i]) >> shift_;
0082 if ((fgvbBuffer_[i] == 1 && i == 3) || fgvbInt == 1) {
0083 fgvbInt = 1;
0084 }
0085 }
0086 if (output < 0)
0087 output = 0;
0088 if (output > 0X3FFFF)
0089 output = 0X3FFFF;
0090 processedOutput_ = output;
0091 processedFgvbOutput_ = fgvbInt;
0092 }
0093
0094 void EcalFenixAmplitudeFilter::setParameters(uint32_t raw,
0095 const EcalTPGWeightIdMap *ecaltpgWeightMap,
0096 const EcalTPGWeightGroup *ecaltpgWeightGroup) {
0097 stripid_ = raw;
0098 uint32_t params_[5];
0099 const EcalTPGGroups::EcalTPGGroupsMap &groupmap = ecaltpgWeightGroup->getMap();
0100 EcalTPGGroups::EcalTPGGroupsMapItr it = groupmap.find(raw);
0101 if (it != groupmap.end()) {
0102 uint32_t weightid = (*it).second;
0103 const EcalTPGWeightIdMap::EcalTPGWeightMap &weightmap = ecaltpgWeightMap->getMap();
0104 EcalTPGWeightIdMap::EcalTPGWeightMapItr itw = weightmap.find(weightid);
0105 (*itw).second.getValues(params_[0], params_[1], params_[2], params_[3], params_[4]);
0106
0107 for (int i = 0; i < 5; ++i) {
0108 weights_[i] = (params_[i] & 0x40) ? (int)(params_[i] | 0xffffffc0) : (int)(params_[i]);
0109 }
0110 } else
0111 edm::LogWarning("EcalTPG") << " could not find EcalTPGGroupsMap entry for " << raw;
0112 }