Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:03:37

0001 #include "CondFormats/EcalObjects/interface/EcalTPGGroups.h"
0002 #include "CondFormats/EcalObjects/interface/EcalTPGOddWeightGroup.h"
0003 #include "CondFormats/EcalObjects/interface/EcalTPGOddWeightIdMap.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include <SimCalorimetry/EcalTrigPrimAlgos/interface/EcalFenixOddAmplitudeFilter.h>
0006 #include <iostream>
0007 #include <string>
0008 #include <fstream>
0009 
0010 EcalFenixOddAmplitudeFilter::EcalFenixOddAmplitudeFilter(bool tpInfoPrintout)
0011     : inputsAlreadyIn_(0), stripid_{0}, shift_(6), tpInfoPrintout_(tpInfoPrintout) {}
0012 
0013 EcalFenixOddAmplitudeFilter::~EcalFenixOddAmplitudeFilter() {}
0014 
0015 int EcalFenixOddAmplitudeFilter::setInput(int input) {
0016   if (input > 0X3FFFF) {
0017     edm::LogError("EcalTPG") << "ERROR IN INPUT OF ODD AMPLITUDE FILTER";
0018     return -1;
0019   }
0020   if (inputsAlreadyIn_ < 5) {
0021     buffer_[inputsAlreadyIn_] = input;
0022     inputsAlreadyIn_++;
0023   } else {
0024     for (int i = 0; i < 4; i++) {
0025       buffer_[i] = buffer_[i + 1];
0026     }
0027     buffer_[4] = input;
0028   }
0029   return 1;
0030 }
0031 
0032 void EcalFenixOddAmplitudeFilter::process(std::vector<int> &addout, std::vector<int> &output) {
0033   inputsAlreadyIn_ = 0;
0034   for (unsigned int i = 0; i < 5; i++) {
0035     buffer_[i] = 0;
0036   }
0037 
0038   for (unsigned int i = 0; i < addout.size(); i++) {
0039     setInput(addout[i]);
0040     process();
0041     if (tpInfoPrintout_) {
0042       if (i >= 4) {
0043         edm::LogVerbatim("EcalTPG") << i << " " << stripid_ << " " << weights_[0] << " " << weights_[1] << " "
0044                                     << weights_[2] << " " << weights_[3] << " " << weights_[4] << " "
0045                                     << weights_[0] / 64.0 << " " << weights_[1] / 64.0 << " " << weights_[2] / 64.0
0046                                     << " " << weights_[3] / 64.0 << " " << weights_[4] / 64.0 << " [" << buffer_[0]
0047                                     << ", " << buffer_[1] << ", " << buffer_[2] << ", " << buffer_[3] << ", "
0048                                     << buffer_[4] << "]"
0049                                     << " --> output: " << processedOutput_ << " ODD";
0050       }
0051     }
0052     output[i] = processedOutput_;
0053   }
0054   // shift the result by 1!
0055   for (unsigned int i = 0; i < (output.size()); i++) {
0056     if (i != output.size() - 1) {
0057       output[i] = output[i + 1];
0058     } else {
0059       output[i] = 0;
0060     }
0061   }
0062   return;
0063 }
0064 
0065 void EcalFenixOddAmplitudeFilter::process() {
0066   processedOutput_ = 0;
0067   if (inputsAlreadyIn_ < 5)  // 5 digis required to produce first ET value
0068     return;
0069   int output = 0;
0070 
0071   for (int i = 0; i < 5; i++) {
0072     output += (weights_[i] * buffer_[i]) >> shift_;
0073   }
0074 
0075   if (output < 0)
0076     output = 0;
0077   if (output > 0X3FFFF)
0078     output = 0X3FFFF;
0079   processedOutput_ = output;
0080 }
0081 
0082 void EcalFenixOddAmplitudeFilter::setParameters(uint32_t raw,
0083                                                 const EcalTPGOddWeightIdMap *ecaltpgOddWeightMap,
0084                                                 const EcalTPGOddWeightGroup *ecaltpgOddWeightGroup) {
0085   stripid_ = raw;
0086   uint32_t params_[5];
0087   const EcalTPGGroups::EcalTPGGroupsMap &groupmap = ecaltpgOddWeightGroup->getMap();
0088   EcalTPGGroups::EcalTPGGroupsMapItr it = groupmap.find(raw);
0089   if (it != groupmap.end()) {
0090     uint32_t weightid = (*it).second;
0091     const EcalTPGOddWeightIdMap::EcalTPGWeightMap &weightmap = ecaltpgOddWeightMap->getMap();
0092     EcalTPGOddWeightIdMap::EcalTPGWeightMapItr itw = weightmap.find(weightid);
0093     (*itw).second.getValues(params_[0], params_[1], params_[2], params_[3], params_[4]);
0094 
0095     for (int i = 0; i < 5; ++i) {
0096       weights_[i] = (params_[i] & 0x40) ? (int)(params_[i] | 0xffffffc0) : (int)(params_[i]);
0097     }
0098   } else
0099     edm::LogWarning("EcalTPG") << " could not find EcalTPGGroupsMap entry for " << raw;
0100 }