Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:22

0001 #include <SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2AmplitudeReconstructor.h>
0002 #include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGAmplWeightIdMap.h"
0003 #include "CondFormats/EcalObjects/interface/EcalTPGWeightGroup.h"
0004 #include "DataFormats/EcalDigi/interface/EcalConstants.h"
0005 #include "CondFormats/EcalObjects/interface/EcalTPGGroups.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 
0008 #include <iostream>
0009 
0010 EcalEBPhase2AmplitudeReconstructor::EcalEBPhase2AmplitudeReconstructor(bool debug)
0011     : debug_(debug), inputsAlreadyIn_(0), shift_(13) {}
0012 
0013 EcalEBPhase2AmplitudeReconstructor::~EcalEBPhase2AmplitudeReconstructor() {}
0014 
0015 int EcalEBPhase2AmplitudeReconstructor::setInput(int input) {
0016   if (input > 0X3FFF) {
0017     edm::LogError("EcalEBPhase2AmplitudeReconstructor") << "ERROR IN INPUT OF AMPLITUDE FILTER" << std::endl;
0018     return -1;
0019   }
0020 
0021   if (inputsAlreadyIn_ < maxSamplesUsed_) {
0022     if (debug_)
0023       LogDebug("") << " EcalEBPhase2AmplitudeReconstructor::setInput inputsAlreadyIn_<5 input " << input << std::endl;
0024 
0025     buffer_[inputsAlreadyIn_] = input;
0026     inputsAlreadyIn_++;
0027   } else {
0028     for (int i = 0; i < (maxSamplesUsed_ - 1); i++) {
0029       buffer_[i] = buffer_[i + 1];
0030       if (debug_)
0031         LogDebug("") << " EcalEBPhase2AmplitudeReconstructor::setInput inputsAlreadyIn buffer " << buffer_[i]
0032                      << std::endl;
0033     }
0034     buffer_[maxSamplesUsed_ - 1] = input;
0035   }
0036   return 1;
0037 }
0038 
0039 void EcalEBPhase2AmplitudeReconstructor::process(std::vector<int> &linout, std::vector<int> &output) {
0040   inputsAlreadyIn_ = 0;
0041   for (unsigned int i = 0; i < maxSamplesUsed_; i++) {
0042     buffer_[i] = 0;
0043   }
0044 
0045   for (unsigned int i = 0; i < linout.size(); i++) {
0046     setInput(linout[i]);
0047     if (debug_) {
0048       for (unsigned int j = 0; j < maxSamplesUsed_; j++) {
0049         LogDebug("") << " buffer_ " << buffer_[j];
0050       }
0051       LogDebug("") << "  " << std::endl;
0052     }
0053 
0054     if (i == (maxSamplesUsed_ - 1)) {
0055       process();
0056       output[0] = processedOutput_;
0057     } else if (i == (ecalPh2::sampleSize - 1)) {
0058       process();
0059       output[1] = processedOutput_;
0060     }
0061   }
0062   return;
0063 }
0064 
0065 void EcalEBPhase2AmplitudeReconstructor::process() {
0066   processedOutput_ = 0;
0067   if (inputsAlreadyIn_ < maxSamplesUsed_)
0068     return;
0069   int64_t tmpIntOutput = 0;
0070   for (int i = 0; i < maxSamplesUsed_; i++) {
0071     tmpIntOutput += (weights_[i] * buffer_[i]);
0072     if (debug_)
0073       LogDebug("") << " AmplitudeFilter buffer " << buffer_[i] << " weight " << weights_[i] << std::endl;
0074   }
0075   if (tmpIntOutput < 0)
0076     tmpIntOutput = 0;
0077   tmpIntOutput = tmpIntOutput >> shift_;
0078   if (debug_)
0079     LogDebug("") << " AmplitudeFilter tmpIntOutput " << tmpIntOutput << " shift_ " << shift_ << std::endl;
0080   if (tmpIntOutput > 0X1FFF)
0081     tmpIntOutput = 0X1FFF;
0082   uint output = tmpIntOutput;  // should be 13 bit uint at this point
0083   processedOutput_ = output;
0084   if (debug_)
0085     LogDebug("") << " AmplitudeFilter  processedOutput_ " << processedOutput_ << std::endl;
0086 }
0087 
0088 void EcalEBPhase2AmplitudeReconstructor::setParameters(uint32_t raw,
0089                                                        const EcalEBPhase2TPGAmplWeightIdMap *ecaltpgWeightMap,
0090                                                        const EcalTPGWeightGroup *ecaltpgWeightGroup) {
0091   uint32_t params_[maxSamplesUsed_];
0092   const EcalTPGGroups::EcalTPGGroupsMap &groupmap = ecaltpgWeightGroup->getMap();
0093   if (debug_)
0094     LogDebug("") << " EcalEBPhase2AmplitudeReconstructor::setParameters groupmap size " << groupmap.size()
0095                  << "  channel ID " << raw << std::endl;
0096   EcalTPGGroups::EcalTPGGroupsMapItr it = groupmap.find(raw);
0097   if (it != groupmap.end()) {
0098     uint32_t weightid = (*it).second;
0099 
0100     const EcalEBPhase2TPGAmplWeightIdMap::EcalEBPhase2TPGAmplWeightMap &weightmap = ecaltpgWeightMap->getMap();
0101     EcalEBPhase2TPGAmplWeightIdMap::EcalEBPhase2TPGAmplWeightMapItr itw = weightmap.find(weightid);
0102 
0103     (*itw).second.getValues(params_[0],
0104                             params_[1],
0105                             params_[2],
0106                             params_[3],
0107                             params_[4],
0108                             params_[5],
0109                             params_[6],
0110                             params_[7],
0111                             params_[8],
0112                             params_[9],
0113                             params_[10],
0114                             params_[11]);
0115 
0116     if (debug_)
0117       LogDebug("") << " EcalEBPhase2AmplitudeReconstructor::setParameters weights after the map  " << params_[0] << " "
0118                    << params_[1] << " " << params_[2] << " " << params_[3] << " " << params_[4] << " " << params_[5]
0119                    << " " << params_[6] << " " << params_[7] << " " << params_[8] << " " << params_[9] << " "
0120                    << params_[10] << " " << params_[11] << std::endl;
0121 
0122     // we have to transform negative coded in 13 bits into negative coded in 32 bits
0123     // maybe this should go into the getValue method??
0124 
0125     for (int i = 0; i < maxSamplesUsed_; ++i) {
0126       weights_[i] = (params_[i] & 0x1000) ? (int)(params_[i] | 0xfffff000) : (int)(params_[i]);
0127     }
0128 
0129     if (debug_) {
0130       for (int i = 0; i < maxSamplesUsed_; ++i) {
0131         LogDebug("") << " EcalEBPhase2AmplitudeReconstructor::setParameters weights after the cooking " << weights_[i]
0132                      << std::endl;
0133       }
0134       LogDebug("") << std::endl;
0135     }
0136 
0137   } else
0138     edm::LogWarning("EcalTPG")
0139         << " EcalEBPhase2AmplitudeReconstructor::setParameters could not find EcalTPGGroupsMap entry for " << raw;
0140 }