Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <CondFormats/EcalObjects/interface/EcalTPGSlidingWindow.h>
0002 #include <CondFormats/EcalObjects/interface/EcalTPGStripStatus.h>
0003 #include <CondFormats/EcalObjects/interface/EcalTPGTPMode.h>
0004 #include <SimCalorimetry/EcalTrigPrimAlgos/interface/EcalFenixStripFormatEE.h>
0005 
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include <iostream>
0008 
0009 //-----------------------------------------------------------------------------------------
0010 EcalFenixStripFormatEE::EcalFenixStripFormatEE() : shift_(0) {}
0011 //------------------------------------------------------------------------------------------
0012 
0013 EcalFenixStripFormatEE::~EcalFenixStripFormatEE() {}
0014 
0015 //-----------------------------------------------------------------------------------------
0016 
0017 int EcalFenixStripFormatEE::setInput(int input_even, int inputEvenPeak, int input_odd, int inputOddPeak, int fgvb) {
0018   inputEvenPeak_ = inputEvenPeak;
0019   input_even_ = input_even;
0020   inputOddPeak_ = inputOddPeak;
0021   input_odd_ = input_odd;
0022   fgvb_ = fgvb;
0023   return 0;
0024 }
0025 //-----------------------------------------------------------------------------------------
0026 
0027 int EcalFenixStripFormatEE::process() {
0028   // Bad strip - zero everything
0029   if (stripStatus_ != 0)
0030     return 0;
0031 
0032   int even_output = 0;
0033   int odd_output = 0;
0034 
0035   // Applying sliding window on the strip output after the peak finder
0036   if (ecaltpgTPMode_->DisableEEEvenPeakFinder) {
0037     even_output = input_even_ >> shift_;
0038   } else {
0039     if (inputEvenPeak_ == 1)
0040       even_output = input_even_ >> shift_;
0041   }
0042 
0043   if (ecaltpgTPMode_->EnableEEOddPeakFinder) {
0044     if (inputOddPeak_ == 1)
0045       odd_output = input_odd_ >> shift_;
0046   } else {
0047     odd_output = input_odd_ >> shift_;
0048   }
0049 
0050   // Truncating the signals to  to 12 bit after peak finder sliding window
0051   if (odd_output > 0XFFF)
0052     odd_output = 0XFFF;
0053   if (even_output > 0XFFF)
0054     even_output = 0XFFF;
0055 
0056   // Prepare the amplitude output for the strip looking at the TPmode options
0057   int output = 0;
0058   bool is_odd_larger = false;
0059 
0060   if (ecaltpgTPMode_->EnableEEOddFilter && (odd_output > even_output))
0061     is_odd_larger =
0062         true;  // If running with odd filter enabled, check if odd output is larger regardless of strip formatter output mode
0063   switch (ecaltpgTPMode_->FenixEEStripOutput) {
0064     case 0:  // even filter out
0065       output = even_output;
0066       break;
0067     case 1:  // odd filter out
0068       if (ecaltpgTPMode_->EnableEEOddFilter)
0069         output = odd_output;
0070       else
0071         output = even_output;
0072       break;
0073     case 2:  // larger between odd and even
0074       if (ecaltpgTPMode_->EnableEEOddFilter && (odd_output > even_output)) {
0075         output = odd_output;
0076       } else
0077         output = even_output;
0078       break;
0079     case 3:  // even + odd
0080       if (ecaltpgTPMode_->EnableEEOddFilter)
0081         output = even_output + odd_output;
0082       else
0083         output = even_output;
0084       break;
0085   }
0086 
0087   // barrel saturates at 12 bits, endcap at 10!
0088   // Pascal: finally no,endcap has 12 bits as in EB (bug in FENIX!!!!)
0089   if (output > 0XFFF)
0090     output = 0XFFF;
0091 
0092   // Info bits
0093   // bit12 is sFGVB, bit13 is for odd>even flagging
0094   output |= ((fgvb_ & 0x1) << 12);
0095 
0096   if (ecaltpgTPMode_->EnableEEOddFilter && ecaltpgTPMode_->FenixEEStripInfobit2) {
0097     output |= ((is_odd_larger & 0x1) << 13);
0098   }
0099 
0100   return output;
0101 }
0102 //------------------------------------------------------------------------------------------
0103 
0104 void EcalFenixStripFormatEE::process(std::vector<int> &fgvbout,
0105                                      std::vector<int> &peakout_even,
0106                                      std::vector<int> &filtout_even,
0107                                      std::vector<int> &peakout_odd,
0108                                      std::vector<int> &filtout_odd,
0109                                      std::vector<int> &output) {
0110   if (peakout_even.size() != filtout_even.size() || fgvbout.size() != filtout_even.size() ||
0111       peakout_odd.size() != filtout_odd.size() || filtout_odd.size() != filtout_even.size()) {
0112     edm::LogWarning("EcalTPG") << " problem in EcalFenixStripFormatEE: peak_out and filt_out don't "
0113                                   "have the same size";
0114     std::cout << " Size peak_out" << peakout_even.size() << ", size filt_out:" << filtout_even.size() << std::flush
0115               << std::endl;
0116   }
0117 
0118   for (unsigned int i = 0; i < filtout_even.size(); i++) {
0119     setInput(filtout_even[i], peakout_even[i], filtout_odd[i], peakout_odd[i], fgvbout[i]);
0120     output[i] = process();
0121   }
0122   return;
0123 }
0124 //-----------------------------------------------------------------------------------------
0125 
0126 void EcalFenixStripFormatEE::setParameters(uint32_t id,
0127                                            const EcalTPGSlidingWindow *&slWin,
0128                                            const EcalTPGStripStatus *stripStatus,
0129                                            const EcalTPGTPMode *ecaltpgTPMode) {
0130   // TP mode contains options for the formatter (odd/even filters config)
0131   ecaltpgTPMode_ = ecaltpgTPMode;
0132   const EcalTPGSlidingWindowMap &slwinmap = slWin->getMap();
0133   EcalTPGSlidingWindowMapIterator it = slwinmap.find(id);
0134   if (it != slwinmap.end())
0135     shift_ = (*it).second;
0136   else
0137     edm::LogWarning("EcalTPG") << " could not find EcalTPGSlidingWindowMap entry for " << id;
0138 
0139   const EcalTPGStripStatusMap &statusMap = stripStatus->getMap();
0140   EcalTPGStripStatusMapIterator sit = statusMap.find(id);
0141   if (sit != statusMap.end()) {
0142     stripStatus_ = (*sit).second;
0143   } else {
0144     stripStatus_ = 0;  // Assume strip OK
0145   }
0146 }
0147 //-----------------------------------------------------------------------------------------