CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/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   output=(output*mult_)>>(shift_+2);        //Apply multiplicative factor
00056   if(output>0X3FFFF)output=0X3FFFF;         //Saturation if too high
00057   return output;
00058 }
00059 
00060 int EcalFenixLinearizer::setInput(const EcalMGPASample &RawSam)
00061 { 
00062   if(RawSam.raw()>0X3FFF)
00063     {
00064       LogDebug("EcalTPG")<<"ERROR IN INPUT SAMPLE OF FENIX LINEARIZER";
00065       return -1;
00066     }
00067   uncorrectedSample_=RawSam.adc(); //uncorrectedSample_ is coded in the 12 LSB
00068   gainID_=RawSam.gainId();       //uncorrectedSample_ is coded in the 2 next bits!
00069   if (gainID_==0)    gainID_=3;
00070 
00071   if (gainID_==1) {
00072     base_ = peds_ -> mean_x12; 
00073     shift_ = linConsts_ -> shift_x12;
00074     
00075     // take into account the badX
00076     // badXStatus_ == 0 if the crystal works
00077     // badXStatus_ !=0 some problem with the crystal
00078     if (badXStatus_->getStatusCode()!=0){
00079       mult_ = 0;
00080     }
00081     else{ 
00082       mult_ = linConsts_ -> mult_x12;
00083     }
00084   }
00085   else if (gainID_==2) {
00086     base_ = peds_ -> mean_x6;
00087     shift_ = linConsts_ -> shift_x6;
00088     
00089     // take into account the badX
00090     // check if the badX has a status code=0 or 1 
00091     if (badXStatus_->getStatusCode()!=0){
00092       mult_ = 0;
00093     }
00094     else{
00095       mult_ = linConsts_ -> mult_x6;
00096     }  
00097   }
00098   else if (gainID_==3){
00099     base_ = peds_-> mean_x1; 
00100     shift_ = linConsts_ -> shift_x1;
00101     
00102     // take into account the badX 
00103     // check if the badX has a status code=0 or 1
00104     if (badXStatus_->getStatusCode()!=0){
00105       mult_ = 0;
00106     }
00107     else{
00108       mult_ = linConsts_ -> mult_x1;
00109     } 
00110   }
00111 
00112   if (famos_) base_=200; //FIXME by preparing a correct TPG.txt for Famos
00113  
00114   return 1;
00115 }
00116