CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/SimCalorimetry/EcalTrigPrimAlgos/src/EcalFenixLinearizer.cc

Go to the documentation of this file.
00001 #include <SimCalorimetry/EcalTrigPrimAlgos/interface/EcalFenixLinearizer.h>
00002 
00003 #include <CondFormats/EcalObjects/interface/EcalTPGLinearizationConst.h>
00004 #include <CondFormats/EcalObjects/interface/EcalTPGPedestals.h>
00005 #include <CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h>
00006 
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 EcalFenixLinearizer::EcalFenixLinearizer(bool famos)
00010   : famos_(famos), init_(false)
00011 {
00012 }
00013 
00014 EcalFenixLinearizer::~EcalFenixLinearizer(){
00015   if (init_) {
00016     for (int i=0;i<(int)vectorbadXStatus_.size();i++){
00017       delete vectorbadXStatus_[i];
00018     }
00019   }    
00020 }
00021 
00022 void EcalFenixLinearizer::setParameters(uint32_t raw, const EcalTPGPedestals * ecaltpPed, const EcalTPGLinearizationConst * ecaltpLin, const EcalTPGCrystalStatus * ecaltpBadX)
00023 {
00024   const EcalTPGLinearizationConstMap & linMap = ecaltpLin->getMap() ; 
00025   EcalTPGLinearizationConstMapIterator it=linMap.find(raw);
00026   if (it!=linMap.end()) {
00027     linConsts_=&(*it);
00028   }
00029   else edm::LogWarning("EcalTPG")<<" could not find EcalTPGLinearizationConstMap entry for "<<raw;
00030   
00031   const EcalTPGPedestalsMap & pedMap = ecaltpPed->getMap() ; 
00032   EcalTPGPedestalsMapIterator itped=pedMap.find(raw);
00033   if (itped!=pedMap.end())   peds_=&(*itped);
00034   else edm::LogWarning("EcalTPG")<<" could not find EcalTPGPedestalsMap entry for "<<raw;
00035 
00036   const EcalTPGCrystalStatusMap & badXMap = ecaltpBadX->getMap();
00037   EcalTPGCrystalStatusMapIterator itbadX=badXMap.find(raw); 
00038   
00039   if (itbadX!=badXMap.end()) {
00040     badXStatus_=&(*itbadX);
00041   }  
00042   else 
00043   {   
00044     edm::LogWarning("EcalTPG")<<" could not find EcalTPGCrystalStatusMap entry for "<<raw; 
00045     badXStatus_ = new EcalTPGCrystalStatusCode();
00046     vectorbadXStatus_.push_back(&(*badXStatus_));
00047     init_ = true;       
00048   }
00049 }
00050 
00051 int EcalFenixLinearizer::process()
00052 {
00053   int output=(uncorrectedSample_-base_); //Substract base
00054   //if(output<0) return 0;
00055   if(output<0) return famos_? 0. : shift_ << 12; // FENIX bug(!)
00056   output=(output*mult_)>>(shift_+2);        //Apply multiplicative factor
00057   if(output>0X3FFFF)output=0X3FFFF;         //Saturation if too high
00058   return output;
00059 }
00060 
00061 int EcalFenixLinearizer::setInput(const EcalMGPASample &RawSam)
00062 { 
00063   if(RawSam.raw()>0X3FFF)
00064     {
00065       LogDebug("EcalTPG")<<"ERROR IN INPUT SAMPLE OF FENIX LINEARIZER";
00066       return -1;
00067     }
00068   uncorrectedSample_=RawSam.adc(); //uncorrectedSample_ is coded in the 12 LSB
00069   gainID_=RawSam.gainId();       //uncorrectedSample_ is coded in the 2 next bits!
00070   //if (gainID_==0)    gainID_=3;
00071 
00072   if(gainID_ == 0)
00073   {
00074     base_ = 0;
00075     shift_ = 0;
00076     mult_ = 0xFF;
00077     if((linConsts_->mult_x12 == 0) && (linConsts_->mult_x6 == 0) && (linConsts_->mult_x1 == 0))
00078     {
00079       mult_ = 0; // Implemented in CCSSupervisor to
00080                  // reject overflow cases in rejected channels
00081     }
00082   }
00083   else if (gainID_==1) {
00084     base_ = peds_ -> mean_x12; 
00085     shift_ = linConsts_ -> shift_x12;
00086     
00087     // take into account the badX
00088     // badXStatus_ == 0 if the crystal works
00089     // badXStatus_ !=0 some problem with the crystal
00090     if (badXStatus_->getStatusCode()!=0){
00091       mult_ = 0;
00092     }
00093     else{ 
00094       mult_ = linConsts_ -> mult_x12;
00095     }
00096   }
00097   else if (gainID_==2) {
00098     base_ = peds_ -> mean_x6;
00099     shift_ = linConsts_ -> shift_x6;
00100     
00101     // take into account the badX
00102     // check if the badX has a status code=0 or 1 
00103     if (badXStatus_->getStatusCode()!=0){
00104       mult_ = 0;
00105     }
00106     else{
00107       mult_ = linConsts_ -> mult_x6;
00108     }  
00109   }
00110   else if (gainID_==3){
00111     base_ = peds_-> mean_x1; 
00112     shift_ = linConsts_ -> shift_x1;
00113     
00114     // take into account the badX 
00115     // check if the badX has a status code=0 or 1
00116     if (badXStatus_->getStatusCode()!=0){
00117       mult_ = 0;
00118     }
00119     else{
00120       mult_ = linConsts_ -> mult_x1;
00121     } 
00122   }
00123 
00124   if (famos_) base_=200; //FIXME by preparing a correct TPG.txt for Famos
00125  
00126   return 1;
00127 }
00128