Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-14 02:22:58

0001 #include <SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBFenixAmplitudeFilter.h>
0002 #include "CondFormats/EcalObjects/interface/EcalTPGWeightIdMap.h"
0003 #include "CondFormats/EcalObjects/interface/EcalTPGWeightGroup.h"
0004 #include "CondFormats/EcalObjects/interface/EcalTPGGroups.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include <iostream>
0007 
0008 EcalEBFenixAmplitudeFilter::EcalEBFenixAmplitudeFilter() : inputsAlreadyIn_(0), shift_(6) {}
0009 
0010 EcalEBFenixAmplitudeFilter::~EcalEBFenixAmplitudeFilter() {}
0011 
0012 int EcalEBFenixAmplitudeFilter::setInput(int input, int fgvb) {
0013   if (input > 0X3FFFF) {
0014     std::cout << "ERROR IN INPUT OF AMPLITUDE FILTER" << std::endl;
0015     return -1;
0016   }
0017   if (inputsAlreadyIn_ < 5) {
0018     //std::cout << " EcalEBFenixAmplitudeFilter::setInput inputsAlreadyIn_<5 input " << input << std::endl;
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       //std::cout << " EcalEBFenixAmplitudeFilter::setInput inputsAlreadyIn buffer " << buffer_[i] << std::endl;
0026       fgvbBuffer_[i] = fgvbBuffer_[i + 1];
0027     }
0028     buffer_[4] = input;
0029     fgvbBuffer_[4] = fgvb;
0030   }
0031   return 1;
0032 }
0033 
0034 void EcalEBFenixAmplitudeFilter::process(std::vector<int> &addout,
0035                                          std::vector<int> &output,
0036                                          std::vector<int> &fgvbIn,
0037                                          std::vector<int> &fgvbOut) {
0038   // test
0039 
0040   inputsAlreadyIn_ = 0;
0041   for (unsigned int i = 0; i < 5; i++) {
0042     buffer_[i] = 0;  //FIXME: 5
0043     fgvbBuffer_[i] = 0;
0044   }
0045 
0046   // test end
0047 
0048   //std::cout << "  EcalEBFenixAmplitudeFilter::process(std::vector<int> &addout size  " << addout.size() << std::endl;
0049   for (unsigned int i = 0; i < addout.size(); i++) {
0050     setInput(addout[i], fgvbIn[i]);
0051     for (unsigned int i = 0; i < 5; i++) {
0052       // std::cout << " buffer_ " << buffer_[i];
0053     }
0054     //std::cout << "  " << std::endl;
0055     process();
0056     output[i] = processedOutput_;
0057     fgvbOut[i] = processedFgvbOutput_;
0058   }
0059   // shift the result by 1!
0060   for (unsigned int i = 0; i < (output.size()); i++) {
0061     if (i != output.size() - 1) {
0062       output[i] = output[i + 1];
0063       fgvbOut[i] = fgvbOut[i + 1];
0064     } else {
0065       output[i] = 0;
0066       fgvbOut[i] = 0;
0067     }
0068   }
0069   return;
0070 }
0071 
0072 void EcalEBFenixAmplitudeFilter::process() {
0073   //UB FIXME: 5
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     //std::cout << " AmplitudeFilter buffer " << buffer_[i] << " weight " << weights_[i] << " output " << output << std::endl;
0083     if ((fgvbBuffer_[i] == 1 && i == 3) || fgvbInt == 1) {
0084       fgvbInt = 1;
0085     }
0086   }
0087   if (output < 0)
0088     output = 0;
0089   if (output > 0X3FFFF)
0090     output = 0X3FFFF;
0091   processedOutput_ = output;
0092   processedFgvbOutput_ = fgvbInt;
0093 }
0094 
0095 void EcalEBFenixAmplitudeFilter::setParameters(uint32_t raw,
0096                                                const EcalTPGWeightIdMap *ecaltpgWeightMap,
0097                                                const EcalTPGWeightGroup *ecaltpgWeightGroup) {
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     // we have to transform negative coded in 7 bits into negative coded in 32 bits
0108     // maybe this should go into the getValue method??
0109     //std::cout << "peak flag settings" << std::endl;
0110     for (int i = 0; i < 5; ++i) {
0111       weights_[i] = (params_[i] & 0x40) ? (int)(params_[i] | 0xffffffc0) : (int)(params_[i]);
0112 
0113       // Construct the peakFlag for sFGVB processing
0114       //peakFlag_[i] = ((params_[i] & 0x80) > 0x0) ? 1 : 0;
0115       //std::cout << " " << params_[i] << std::endl;
0116       //std::cout << " " << peakFlag_[i] << std::endl;
0117     }
0118     //std::cout << std::endl;
0119   } else
0120     edm::LogWarning("EcalTPG") << " could not find EcalTPGGroupsMap entry for " << raw;
0121 }