CMS 3D CMS Logo

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