Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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