Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBFenixTcpFormat.h>
0002 #include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h"
0003 #include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h"
0004 #include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h"
0005 #include "CondFormats/EcalObjects/interface/EcalTPGSpike.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include <iostream>
0008 
0009 using namespace std;
0010 
0011 EcalEBFenixTcpFormat::EcalEBFenixTcpFormat(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 EcalEBFenixTcpFormat::~EcalEBFenixTcpFormat() {}
0018 
0019 void EcalEBFenixTcpFormat::process(std::vector<int> &Etin, std::vector<int> &Etout) {
0020   // put TP-s in the output
0021   // on request also in TcpFormat
0022   // for famos version we have to write dummies except for the middle
0023   // std::cout << "   EcalEBFenixTcpFormat::process(... Etout size " << Etout.size() << "  Et size " << Etin.size() << std::endl;
0024 
0025   int myEt;
0026   int eTTotShift = 2;
0027 
0028   //  std::cout << " FenixTcpFormatter Etin size() " << Etin.size() << std::endl;
0029   for (unsigned int i = 0; i < Etin.size(); ++i) {
0030     // bug fix 091009:
0031     myEt = Etin[i];
0032     //std::cout << " Et " << myEt << std::endl;
0033     if (myEt > 0xfff)
0034       myEt = 0xfff;
0035 
0036     myEt >>= eTTotShift;
0037     //std::cout << " after myEt>>= eTTotShift " << myEt << std::endl;
0038     if (myEt > 0x3ff)
0039       myEt = 0x3ff;
0040 
0041     //myEt = lut_out & 0xff ;
0042     // the lut is foreseen for 8 bits. Useless to use it here
0043 
0044     // stay with 10 bits
0045     Etout[i] = myEt;
0046   }
0047 }
0048 
0049 void EcalEBFenixTcpFormat::process(std::vector<int> &Et,
0050                                    std::vector<int> &fgvb,
0051                                    std::vector<int> &sfgvb,
0052                                    int eTTotShift,
0053                                    std::vector<EcalEBTriggerPrimitiveSample> &out,
0054                                    std::vector<EcalEBTriggerPrimitiveSample> &out2,
0055                                    bool isInInnerRings) {
0056   // put TP-s in the output
0057   // on request also in TcpFormat
0058   // for famos version we have to write dummies except for the middle
0059   //std::cout << "   EcalEBFenixTcpFormat::process(... out size " << out.size() << "  Et size " << Et.size() << " Et[0] " << Et[0] << std::endl;
0060 
0061   int myEt;
0062   if (famos_) {
0063     for (unsigned int i = 0; i < out.size(); ++i) {
0064       if (i == binOfMax_ - 1) {
0065         myEt = Et[0] >> eTTotShift;
0066         if (myEt > 0x3ff)
0067           myEt = 0x3ff;
0068         if (isInInnerRings)
0069           myEt = myEt / 2;
0070 
0071         // badTTStatus_ ==0 if the TT works
0072         // badTTStatus_ !=0 if there are some problems
0073         int lut_out;
0074         if (*badTTStatus_ != 0) {
0075           lut_out = 0;
0076         } else
0077           lut_out = (lut_)[myEt];
0078 
0079         // int ttFlag = (lut_out & 0x700) >> 8 ;
0080         myEt = lut_out & 0xff;
0081         //  out[i]=EcalEBTriggerPrimitiveSample( myEt,fgvb[0],sfgvb[0],ttFlag);
0082         out[i] = EcalEBTriggerPrimitiveSample(myEt);
0083       } else
0084         out[i] = EcalEBTriggerPrimitiveSample();
0085     }
0086   } else {
0087     //std::cout << " FenixTcpFormatter et.size() " << Et.size() << std::endl;
0088     for (unsigned int i = 0; i < Et.size(); ++i) {
0089       //int myFgvb=fgvb[i];
0090       int mysFgvb = sfgvb[i];
0091       //myEt=Et[i]>>eTTotShift;
0092       //if (myEt>0x3ff) myEt=0x3ff ;
0093       //if (isInInnerRings) myEt = myEt /2 ;
0094 
0095       // bug fix 091009:
0096       myEt = Et[i];
0097       //std::cout << " Et " << myEt << std::endl;
0098       if (myEt > 0xfff)
0099         myEt = 0xfff;
0100       if (isInInnerRings)
0101         myEt = myEt / 2;
0102       myEt >>= eTTotShift;
0103       //std::cout << " after myEt>>= eTTotShift " << myEt << std::endl;
0104       if (myEt > 0x3ff)
0105         myEt = 0x3ff;
0106 
0107       // Spike killing
0108       if ((myEt > spikeZeroThresh_) && (mysFgvb == 0)) {
0109         myEt = 0;
0110       }
0111 
0112       int lut_out;
0113       if (*badTTStatus_ != 0) {
0114         lut_out = 0;
0115       } else
0116         lut_out = (lut_)[myEt];
0117 
0118       //int ttFlag = (lut_out & 0x700) >> 8 ;
0119       if (tcpFormat_) {
0120         out2[i] = EcalEBTriggerPrimitiveSample(myEt & 0x3ff);
0121         //std::cout << " FenixTcpFormatter final et " << (myEt & 0x3ff) << std::endl;
0122       }
0123 
0124       myEt = lut_out & 0xff;
0125       //std::cout << " FenixTcpFormatter final lut_out " << lut_out << " 0xff " << 0xff << " et " << myEt << std::endl;
0126       out[i] = EcalEBTriggerPrimitiveSample(myEt);
0127     }
0128   }
0129 }
0130 
0131 void EcalEBFenixTcpFormat::setParameters(uint32_t towid,
0132                                          const EcalTPGLutGroup *ecaltpgLutGroup,
0133                                          const EcalTPGLutIdMap *ecaltpgLut,
0134                                          const EcalTPGTowerStatus *ecaltpgbadTT,
0135                                          const EcalTPGSpike *ecaltpgSpike) {
0136   // Get TP zeroing threshold - defaut to 1023 for old data (no record found or EE)
0137   spikeZeroThresh_ = 1023;
0138   if (ecaltpgSpike != nullptr) {
0139     const EcalTPGSpike::EcalTPGSpikeMap &spikeMap = ecaltpgSpike->getMap();
0140     EcalTPGSpike::EcalTPGSpikeMapIterator sit = spikeMap.find(towid);
0141     if (sit != spikeMap.end()) {
0142       spikeZeroThresh_ = sit->second;
0143     }
0144   }
0145 
0146   const EcalTPGGroups::EcalTPGGroupsMap &groupmap = ecaltpgLutGroup->getMap();
0147   EcalTPGGroups::EcalTPGGroupsMapItr it = groupmap.find(towid);
0148   if (it != groupmap.end()) {
0149     uint32_t lutid = (*it).second;
0150     const EcalTPGLutIdMap::EcalTPGLutMap &lutmap = ecaltpgLut->getMap();
0151     EcalTPGLutIdMap::EcalTPGLutMapItr itl = lutmap.find(lutid);
0152     if (itl != lutmap.end()) {
0153       lut_ = (*itl).second.getLut();
0154       //std::cout << " FenixTcpFormatter lut_ " << std::dec<<lut_ << std::endl;
0155     } else
0156       edm::LogWarning("EcalTPG") << " could not find EcalTPGLutMap for " << lutid;
0157 
0158   } else
0159     edm::LogWarning("EcalTPG") << " could not find EcalTPGFineGrainTowerEEMap for " << towid;
0160 
0161   const EcalTPGTowerStatusMap &badTTMap = ecaltpgbadTT->getMap();
0162   EcalTPGTowerStatusMapIterator itbadTT = badTTMap.find(towid);
0163   if (itbadTT != badTTMap.end()) {
0164     badTTStatus_ = &(*itbadTT).second;
0165   }
0166 }