Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <SimCalorimetry/EcalEBTrigPrimAlgos/interface/EcalEBFenixLinearizer.h>
0002 
0003 #include <CondFormats/EcalObjects/interface/EcalTPGLinearizationConst.h>
0004 #include <CondFormats/EcalObjects/interface/EcalTPGPedestals.h>
0005 #include <CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h>
0006 
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 
0009 EcalEBFenixLinearizer::EcalEBFenixLinearizer(bool famos)
0010     : famos_(famos), init_(false), linConsts_(nullptr), peds_(nullptr), badXStatus_(nullptr) {}
0011 
0012 EcalEBFenixLinearizer::~EcalEBFenixLinearizer() {
0013   if (init_) {
0014     for (int i = 0; i < (int)vectorbadXStatus_.size(); i++) {
0015       delete vectorbadXStatus_[i];
0016     }
0017   }
0018 }
0019 
0020 void EcalEBFenixLinearizer::setParameters(uint32_t raw,
0021                                           const EcalTPGPedestals *ecaltpPed,
0022                                           const EcalTPGLinearizationConst *ecaltpLin,
0023                                           const EcalTPGCrystalStatus *ecaltpBadX) {
0024   const EcalTPGLinearizationConstMap &linMap = ecaltpLin->getMap();
0025   EcalTPGLinearizationConstMapIterator it = linMap.find(raw);
0026 
0027   if (it != linMap.end()) {
0028     linConsts_ = &(*it);
0029   } else
0030     std::cout << " could not find EcalTPGLinearizationConstMap entry for " << raw << std::endl;
0031 
0032   EcalTPGPedestalsMapIterator itped = ecaltpPed->find(raw);
0033   if (itped != ecaltpPed->end())
0034     peds_ = &(*itped);
0035   else
0036     std::cout << " could not find EcalTPGPedestalsMap entry for " << raw << std::endl;
0037 
0038   const EcalTPGCrystalStatusMap &badXMap = ecaltpBadX->getMap();
0039   EcalTPGCrystalStatusMapIterator itbadX = badXMap.find(raw);
0040 
0041   if (itbadX != badXMap.end()) {
0042     badXStatus_ = &(*itbadX);
0043   } else {
0044     edm::LogWarning("EcalTPG") << " could not find EcalTPGCrystalStatusMap entry for " << raw;
0045     badXStatus_ = new EcalTPGCrystalStatusCode();
0046     vectorbadXStatus_.push_back(&(*badXStatus_));
0047     init_ = true;
0048   }
0049 }
0050 
0051 int EcalEBFenixLinearizer::process() {
0052   int output = (uncorrectedSample_ - base_);  //Substract base
0053   //std::cout << " EcalEBFenixLinearizer::process() output non bit shifted " << output << std::endl;
0054   if (famos_ || output < 0)
0055     return 0;
0056 
0057   if (output < 0)
0058     return shift_ << 12;                      // FENIX bug(!)
0059   output = (output * mult_) >> (shift_ + 2);  //Apply multiplicative factor
0060   //std::cout << " EcalEBFenixLinearizer::process() output 2nd step " << output << std::endl;
0061   if (output > 0X3FFFF)
0062     output = 0X3FFFF;  //Saturation if too high
0063   //std::cout << " EcalEBFenixLinearizer::process() output 3rd step " << output << std::endl;
0064   return output;
0065 }
0066 
0067 int EcalEBFenixLinearizer::setInput(const EcalMGPASample &RawSam) {
0068   //std::cout << "  EcalEBFenixLinearizer::setInput RawSam.raw() " << RawSam.raw() << std::endl;
0069   if (RawSam.raw() > 0X3FFF) {
0070     LogDebug("EcalTPG") << "ERROR IN INPUT SAMPLE OF FENIX LINEARIZER";
0071     return -1;
0072   }
0073 
0074   uncorrectedSample_ = RawSam.adc();  //uncorrectedSample_ is coded in the 12 LSB
0075   gainID_ = RawSam.gainId();          //uncorrectedSample_ is coded in the 2 next bits!
0076 
0077   if (gainID_ == 0) {
0078     base_ = 0;
0079     shift_ = 0;
0080     mult_ = 0xFF;
0081     if ((linConsts_->mult_x12 == 0) && (linConsts_->mult_x6 == 0) && (linConsts_->mult_x1 == 0)) {
0082       mult_ = 0;  // Implemented in CCSSupervisor to
0083                   // reject overflow cases in rejected channels
0084     }
0085   } else if (gainID_ == 1) {
0086     base_ = peds_->mean_x12;
0087     shift_ = linConsts_->shift_x12;
0088 
0089     // take into account the badX
0090     // badXStatus_ == 0 if the crystal works
0091     // badXStatus_ !=0 some problem with the crystal
0092     if (badXStatus_->getStatusCode() != 0) {
0093       mult_ = 0;
0094     } else {
0095       mult_ = linConsts_->mult_x12;
0096     }
0097   } else if (gainID_ == 2) {
0098     base_ = peds_->mean_x6;
0099     shift_ = linConsts_->shift_x6;
0100 
0101     // take into account the badX
0102     // check if the badX has a status code=0 or 1
0103     if (badXStatus_->getStatusCode() != 0) {
0104       mult_ = 0;
0105     } else {
0106       mult_ = linConsts_->mult_x6;
0107     }
0108   } else if (gainID_ == 3) {
0109     base_ = peds_->mean_x1;
0110     shift_ = linConsts_->shift_x1;
0111 
0112     // take into account the badX
0113     // check if the badX has a status code=0 or 1
0114     if (badXStatus_->getStatusCode() != 0) {
0115       mult_ = 0;
0116     } else {
0117       mult_ = linConsts_->mult_x1;
0118     }
0119   }
0120 
0121   //std::cout << "  EcalEBFenixLinearizer::setInput   uncorrectedSample_ " << RawSam.adc() << " gainID " << gainID_ << " baseline " << base_ << std::endl;
0122 
0123   if (famos_)
0124     base_ = 200;  //FIXME by preparing a correct TPG.txt for Famos
0125 
0126   return 1;
0127 }