Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-14 02:23:00

0001 #include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h"
0002 #include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h"
0003 #include "CondFormats/EcalObjects/interface/EcalTPGSpike.h"
0004 #include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h"
0005 #include "CondFormats/EcalObjects/interface/EcalTPGTPMode.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include <SimCalorimetry/EcalTrigPrimAlgos/interface/EcalFenixTcpFormatEB.h>
0008 #include <iostream>
0009 using namespace std;
0010 
0011 EcalFenixTcpFormatEB::EcalFenixTcpFormatEB(bool tcpFormat, bool debug, bool famos, int binOfMax)
0012     : tcpFormat_(tcpFormat), debug_(debug), famos_(famos), binOfMax_(binOfMax) {
0013   status_ = 0;
0014   badTTStatus_ = &status_;
0015 }
0016 
0017 EcalFenixTcpFormatEB::~EcalFenixTcpFormatEB() {}
0018 
0019 void EcalFenixTcpFormatEB::process(std::vector<int> &Et_even_sum,
0020                                    std::vector<int> &Et_odd_sum,
0021                                    std::vector<int> &fgvb,
0022                                    std::vector<int> &sfgvb,
0023                                    int eTTotShift,
0024                                    std::vector<EcalTriggerPrimitiveSample> &out,
0025                                    std::vector<EcalTriggerPrimitiveSample> &out2) {
0026   // put TP-s in the output
0027   // on request also in TcpFormat
0028   // for famos version we have to write dummies except for the middle
0029 
0030   int myEt = 0;
0031   if (famos_) {
0032     for (unsigned int i = 0; i < out.size(); ++i) {
0033       if (i == binOfMax_ - 1) {
0034         myEt = Et_even_sum[i] >> eTTotShift;
0035         if (myEt > 0x3ff)
0036           myEt = 0x3ff;
0037 
0038         // badTTStatus_ ==0 if the TT works
0039         // badTTStatus_ !=0 if there are some problems
0040         int lut_out;
0041         if (*badTTStatus_ != 0) {
0042           lut_out = 0;
0043         } else
0044           lut_out = (lut_)[myEt];
0045 
0046         int ttFlag = (lut_out & 0x700) >> 8;
0047         myEt = lut_out & 0xff;
0048         out[i] = EcalTriggerPrimitiveSample(myEt, fgvb[0], sfgvb[0], ttFlag);
0049       } else
0050         out[i] = EcalTriggerPrimitiveSample();
0051     }
0052   } else {
0053     for (unsigned int i = 0; i < Et_even_sum.size(); ++i) {
0054       int myFgvb = fgvb[i];
0055       int mysFgvb = sfgvb[i];
0056       bool is_odd_larger = false;
0057 
0058       // Check if odd sum is larger than even sum, in case flag_EB_odd_even_tcp is used
0059       if (Et_odd_sum[i] > Et_even_sum[i]) {
0060         is_odd_larger = true;
0061       }
0062 
0063       switch (ecaltpgTPMode_->EBFenixTcpOutput) {
0064         case 0:  //output even sum
0065           myEt = Et_even_sum[i];
0066           break;
0067         case 1:  // output larger of odd and even
0068           if (Et_odd_sum[i] > Et_even_sum[i]) {
0069             myEt = Et_odd_sum[i];
0070           } else {
0071             myEt = Et_even_sum[i];
0072           }
0073           break;
0074         case 2:  // output even+odd
0075           myEt = Et_even_sum[i] + Et_odd_sum[i];
0076           break;
0077         default:
0078           // In case of unknown configuration switch to default
0079           myEt = Et_even_sum[i];
0080           break;
0081       }
0082 
0083       // check TPmode config to decide to output the FGVB or the odd>even flag
0084       int infobit1 = myFgvb;
0085       if (ecaltpgTPMode_->EBFenixTcpInfobit1)
0086         infobit1 = is_odd_larger;
0087 
0088       if (myEt > 0xfff)
0089         myEt = 0xfff;
0090       myEt >>= eTTotShift;
0091       if (myEt > 0x3ff)
0092         myEt = 0x3ff;
0093 
0094       // Spike killer
0095       if ((myEt > spikeZeroThresh_) && (mysFgvb == 0)) {
0096         myEt = 0;
0097       }
0098 
0099       int lut_out;
0100       if (*badTTStatus_ != 0) {
0101         lut_out = 0;
0102       } else
0103         lut_out = (lut_)[myEt];
0104 
0105       int ttFlag = (lut_out & 0x700) >> 8;
0106       if (tcpFormat_) {
0107         out2[i] = EcalTriggerPrimitiveSample(((ttFlag & 0x7) << 11) | ((infobit1 & 0x1) << 10) | (myEt & 0x3ff));
0108       }
0109       myEt = lut_out & 0xff;
0110       out[i] = EcalTriggerPrimitiveSample(myEt, infobit1, mysFgvb, ttFlag);
0111     }
0112   }
0113 }
0114 
0115 void EcalFenixTcpFormatEB::setParameters(uint32_t towid,
0116                                          const EcalTPGLutGroup *ecaltpgLutGroup,
0117                                          const EcalTPGLutIdMap *ecaltpgLut,
0118                                          const EcalTPGTowerStatus *ecaltpgbadTT,
0119                                          const EcalTPGSpike *ecaltpgSpike,
0120                                          const EcalTPGTPMode *ecaltpgTPMode) {
0121   // Get TP zeroing threshold - defaut to 1023 for old data (no record found or
0122   // EE)
0123   spikeZeroThresh_ = 1023;
0124   if (ecaltpgSpike != nullptr) {
0125     const EcalTPGSpike::EcalTPGSpikeMap &spikeMap = ecaltpgSpike->getMap();
0126     EcalTPGSpike::EcalTPGSpikeMapIterator sit = spikeMap.find(towid);
0127     if (sit != spikeMap.end()) {
0128       spikeZeroThresh_ = sit->second;
0129     }
0130   }
0131 
0132   const EcalTPGGroups::EcalTPGGroupsMap &groupmap = ecaltpgLutGroup->getMap();
0133   EcalTPGGroups::EcalTPGGroupsMapItr it = groupmap.find(towid);
0134   if (it != groupmap.end()) {
0135     uint32_t lutid = (*it).second;
0136     const EcalTPGLutIdMap::EcalTPGLutMap &lutmap = ecaltpgLut->getMap();
0137     EcalTPGLutIdMap::EcalTPGLutMapItr itl = lutmap.find(lutid);
0138     if (itl != lutmap.end()) {
0139       lut_ = (*itl).second.getLut();
0140     } else
0141       edm::LogWarning("EcalTPG") << " could not find EcalTPGLutMap for " << lutid;
0142 
0143   } else
0144     edm::LogWarning("EcalTPG") << " could not find EcalTPGFineGrainTowerEEMap for " << towid;
0145 
0146   const EcalTPGTowerStatusMap &badTTMap = ecaltpgbadTT->getMap();
0147   EcalTPGTowerStatusMapIterator itbadTT = badTTMap.find(towid);
0148   if (itbadTT != badTTMap.end()) {
0149     badTTStatus_ = &(*itbadTT).second;
0150   }
0151 
0152   ecaltpgTPMode_ = ecaltpgTPMode;
0153 }