Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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