Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBPhase2TimeReconstructor.h>
0002 #include "CondFormats/EcalObjects/interface/EcalEBPhase2TPGTimeWeightIdMap.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 #include <iostream>
0008 
0009 EcalEBPhase2TimeReconstructor::EcalEBPhase2TimeReconstructor(bool debug)
0010     : debug_(debug), inputsAlreadyIn_(0), shift_(maxSamplesUsed_) {}
0011 
0012 EcalEBPhase2TimeReconstructor::~EcalEBPhase2TimeReconstructor() {}
0013 
0014 int EcalEBPhase2TimeReconstructor::setInput(int input) {
0015   if (input > 0X7FFF) {
0016     edm::LogError("EcalEBPhase2TimeReconstructor::setInput") << "ERROR IN INPUT OF TIME FILTER" << std::endl;
0017     return -1;
0018   }
0019   if (inputsAlreadyIn_ < maxSamplesUsed_) {
0020     if (debug_)
0021       LogDebug("") << " EcalEBPhase2TimeReconstructor::setInput inputsAlreadyIn_<5 input " << input << std::endl;
0022 
0023     buffer_[inputsAlreadyIn_] = input;
0024     inputsAlreadyIn_++;
0025   } else {
0026     for (int i = 0; i < (maxSamplesUsed_ - 1); i++) {
0027       buffer_[i] = buffer_[i + 1];
0028       if (debug_)
0029         LogDebug("") << " EcalEBPhase2TimeReconstructor::setInput inputsAlreadyIn buffer " << buffer_[i] << std::endl;
0030     }
0031     buffer_[maxSamplesUsed_ - 1] = input;
0032     inputsAlreadyIn_++;
0033   }
0034   return 1;
0035 }
0036 
0037 void EcalEBPhase2TimeReconstructor::process(std::vector<int> &addout,
0038                                             std::vector<int> &ampRecoOutput,
0039                                             std::vector<int64_t> &output) {
0040   inputsAlreadyIn_ = 0;
0041   for (unsigned int i = 0; i < maxSamplesUsed_; i++) {
0042     buffer_[i] = 0;
0043   }
0044 
0045   //Taking in the results of the amplitude reconstruction
0046   //Bit shifting them for use as index of invAmpAr_ lookup table
0047   // move input amplitude (13 bits) to 9 bits to use as array index
0048 
0049   ampIn_[0] = ampRecoOutput[0] >> 4;
0050   ampIn_[1] = ampRecoOutput[1] >> 4;
0051 
0052   for (unsigned int i = 0; i < addout.size(); i++) {
0053     setInput(addout[i]);
0054 
0055     if (debug_) {
0056       LogDebug("") << "  EcalEBPhase2TimeReconstructor::process(std::vector<int> buffer_ " << std::endl;
0057 
0058       for (unsigned int j = 0; j < maxSamplesUsed_; j++) {
0059         LogDebug("") << " buffer_ " << buffer_[j];
0060       }
0061       LogDebug("") << "  " << std::endl;
0062     }
0063 
0064     if (i == (maxSamplesUsed_ - 1)) {
0065       if (debug_)
0066         LogDebug("") << "  EcalEBPhase2TimeReconstructor::process(std::vector<int>)    i = 11 " << std::endl;
0067       process();
0068       if (debug_)
0069         LogDebug("") << "  EcalEBPhase2TimeReconstructor::process(std::vector<int>)    after process() "
0070                      << processedOutput_ << std::endl;
0071       output[0] = processedOutput_;
0072       if (debug_)
0073         LogDebug("") << "  EcalEBPhase2TimeReconstructor::process(std::vector<int>)    after setting the output "
0074                      << output[0] << std::endl;
0075     } else if (i == (ecalPh2::sampleSize - 1)) {
0076       if (debug_)
0077         LogDebug("") << "  EcalEBPhase2TimeReconstructor::process(std::vector<int>)    i = 15 " << std::endl;
0078       process();
0079       output[1] = processedOutput_;
0080     }
0081   }
0082 
0083   return;
0084 }
0085 
0086 void EcalEBPhase2TimeReconstructor::process() {
0087   //UB FIXME: 5
0088   processedOutput_ = 0;
0089   if (inputsAlreadyIn_ < 12)
0090     return;
0091   int64_t output = 0;
0092   for (int i = 0; i < 12; i++) {
0093     output += (weights_[i] * buffer_[i]);
0094     if (debug_)
0095       LogDebug("") << " TimeFilter buffer " << buffer_[i] << " weight " << weights_[i] << " output " << output
0096                    << std::endl;
0097   }
0098   output = output >> shift_;
0099   if (debug_)
0100     LogDebug("") << " TimeFilter local  output " << output << std::endl;
0101   //Dividing output by the result of the amplitude reconstruction via an approximation using the invAmpAr lookup table
0102   int ampInd = 0;
0103   if (debug_)
0104     LogDebug("") << " inputsAlreadyIn_ " << inputsAlreadyIn_ << std::endl;
0105   if (inputsAlreadyIn_ > 12) {
0106     ampInd = 1;
0107   }
0108 
0109   if (debug_)
0110     LogDebug("") << " Begininning Final TimeFilter Calculation" << std::endl;
0111 
0112   int64_t tmpOutput = output * invAmpAr_[ampIn_[ampInd]];
0113   if (debug_)
0114     LogDebug("") << " output*tmpInvAmpAr " << tmpOutput << std::endl;
0115 
0116   output = tmpOutput >> 20;
0117   if (debug_)
0118     LogDebug("") << " output after bit shift " << output << std::endl;
0119 
0120   if (output < -1024)
0121     output = -1023;
0122   else if (output > 1024)
0123     output = 1023;
0124   if (debug_)
0125     LogDebug("") << " output after if/else " << output << std::endl;
0126   processedOutput_ = output;
0127 
0128   if (debug_)
0129     LogDebug("") << " TimeFilter final output " << processedOutput_ << std::endl;
0130 }
0131 
0132 void EcalEBPhase2TimeReconstructor::setParameters(uint32_t raw,
0133                                                   const EcalEBPhase2TPGTimeWeightIdMap *ecaltpgWeightMap,
0134                                                   const EcalTPGWeightGroup *ecaltpgWeightGroup) {
0135   uint32_t params_[12];
0136   const EcalTPGGroups::EcalTPGGroupsMap &groupmap = ecaltpgWeightGroup->getMap();
0137   if (debug_)
0138     LogDebug("") << " EcalEBPhase2TimeReconstructor::setParameters groupmap size " << groupmap.size() << std::endl;
0139   EcalTPGGroups::EcalTPGGroupsMapItr it = groupmap.find(raw);
0140   if (it != groupmap.end()) {
0141     uint32_t weightid = (*it).second;
0142     const EcalEBPhase2TPGTimeWeightIdMap::EcalEBPhase2TPGTimeWeightMap &weightmap = ecaltpgWeightMap->getMap();
0143     EcalEBPhase2TPGTimeWeightIdMap::EcalEBPhase2TPGTimeWeightMapItr itw = weightmap.find(weightid);
0144 
0145     (*itw).second.getValues(params_[0],
0146                             params_[1],
0147                             params_[2],
0148                             params_[3],
0149                             params_[4],
0150                             params_[5],
0151                             params_[6],
0152                             params_[7],
0153                             params_[8],
0154                             params_[9],
0155                             params_[10],
0156                             params_[11]);
0157 
0158     if (debug_)
0159       LogDebug("") << " EcalEBPhase2TimeReconstructor::setParameters time weights after the map  " << params_[0] << " "
0160                    << params_[1] << " " << params_[2] << " " << params_[3] << " " << params_[4] << " " << params_[5]
0161                    << " " << params_[6] << " " << params_[7] << " " << params_[8] << " " << params_[9] << " "
0162                    << params_[10] << " " << params_[11] << std::endl;
0163 
0164     // we have to transform negative coded in 16 bits into negative coded in 32 bits
0165     // maybe this should go into the getValue method??
0166 
0167     for (int i = 0; i < 12; ++i) {
0168       weights_[i] = (params_[i] & 0x8000) ? (int)(params_[i] | 0xffff8000) : (int)(params_[i]);
0169     }
0170 
0171   } else
0172     edm::LogWarning("EcalTPG")
0173         << " EcalEBPhase2TimeReconstructor::setParameters could not find EcalTPGGroupsMap entry for " << raw;
0174 }