CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/SimCalorimetry/EcalTrigPrimAlgos/src/EcalFenixTcpFormat.cc

Go to the documentation of this file.
00001 #include <SimCalorimetry/EcalTrigPrimAlgos/interface/EcalFenixTcpFormat.h>
00002 #include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h"
00003 #include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h"
00004 #include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h"
00005 #include "CondFormats/EcalObjects/interface/EcalTPGSpike.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include <iostream>
00008 
00009 using  namespace std;
00010 
00011 EcalFenixTcpFormat::EcalFenixTcpFormat(bool tcpFormat, bool debug, bool famos,int binOfMax)
00012   : tcpFormat_(tcpFormat),debug_(debug),famos_(famos),binOfMax_(binOfMax)
00013 {
00014   status_=0;
00015   badTTStatus_=&status_;
00016 }
00017  
00018 EcalFenixTcpFormat::~EcalFenixTcpFormat() {
00019 }
00020 
00021  
00022 void EcalFenixTcpFormat::process(std::vector<int> &Et, std::vector<int> &fgvb,
00023                                  std::vector<int> &sfgvb,int eTTotShift,
00024                                  std::vector<EcalTriggerPrimitiveSample> & out,
00025                                  std::vector<EcalTriggerPrimitiveSample> & out2, bool isInInnerRings){
00026   // put TP-s in the output
00027   // on request also in TcpFormat    
00028   // for famos version we have to write dummies except for the middle
00029   
00030   int myEt;
00031   if (famos_) {
00032     for (unsigned int i=0; i<out.size();++i) {
00033       if (i==binOfMax_-1) {
00034         myEt=Et[0]>>eTTotShift;
00035         if (myEt>0x3ff) myEt=0x3ff ;
00036         if (isInInnerRings) myEt = myEt /2 ;
00037         
00038         // badTTStatus_ ==0 if the TT works
00039         // badTTStatus_ !=0 if there are some problems
00040         int lut_out;
00041         if (*badTTStatus_!=0){
00042           lut_out = 0;
00043         }
00044         else
00045           lut_out = (lut_)[myEt] ;
00046         
00047         int ttFlag = (lut_out & 0x700) >> 8 ;
00048         myEt = lut_out & 0xff ;
00049         out[i]=EcalTriggerPrimitiveSample( myEt,fgvb[0],sfgvb[0],ttFlag); 
00050       }
00051       else out[i]=EcalTriggerPrimitiveSample( );
00052     }
00053   }
00054   else {
00055     for (unsigned int i=0; i<Et.size();++i) {
00056       int myFgvb=fgvb[i];
00057       int mysFgvb=sfgvb[i];
00058       //myEt=Et[i]>>eTTotShift;
00059       //if (myEt>0x3ff) myEt=0x3ff ;
00060       //if (isInInnerRings) myEt = myEt /2 ;  
00061 
00062       // bug fix 091009:
00063       myEt=Et[i]; 
00064       if (myEt>0xfff) 
00065         myEt=0xfff ;
00066       if (isInInnerRings) 
00067         myEt = myEt /2 ;  
00068       myEt >>= eTTotShift ;
00069       if (myEt>0x3ff) myEt=0x3ff ;
00070 
00071       // Spike killing
00072       if((myEt > spikeZeroThresh_) && (mysFgvb == 0))
00073       {
00074         myEt = 0;
00075       }
00076 
00077         int lut_out;
00078         if (*badTTStatus_!=0){
00079           lut_out = 0;
00080         }
00081         else
00082           lut_out = (lut_)[myEt] ;
00083       
00084       int ttFlag = (lut_out & 0x700) >> 8 ;
00085       if (tcpFormat_)  {
00086         out2[i]=EcalTriggerPrimitiveSample( ((ttFlag&0x7)<<11) | ((myFgvb & 0x1)<<10) |  (myEt & 0x3ff));
00087       }
00088       myEt = lut_out & 0xff ;
00089       out[i]=EcalTriggerPrimitiveSample( myEt,myFgvb,mysFgvb,ttFlag); 
00090     }
00091   }
00092 }
00093 
00094 void EcalFenixTcpFormat::setParameters(uint32_t towid,const EcalTPGLutGroup *ecaltpgLutGroup, const EcalTPGLutIdMap *ecaltpgLut, const EcalTPGTowerStatus *ecaltpgbadTT,const EcalTPGSpike * ecaltpgSpike)
00095 {
00096   // Get TP zeroing threshold - defaut to 1023 for old data (no record found or EE)
00097   spikeZeroThresh_ = 1023;
00098   if(ecaltpgSpike != 0)
00099   {
00100     const EcalTPGSpike::EcalTPGSpikeMap &spikeMap = ecaltpgSpike->getMap();
00101     EcalTPGSpike:: EcalTPGSpikeMapIterator sit = spikeMap.find(towid);
00102     if(sit != spikeMap.end())
00103     {
00104       spikeZeroThresh_ = sit->second;
00105     }
00106   }
00107 
00108   const EcalTPGGroups::EcalTPGGroupsMap & groupmap = ecaltpgLutGroup -> getMap();
00109   EcalTPGGroups::EcalTPGGroupsMapItr it=groupmap.find(towid);
00110   if (it!=groupmap.end()) {
00111     uint32_t lutid=(*it).second;
00112     const EcalTPGLutIdMap::EcalTPGLutMap &lutmap = ecaltpgLut-> getMap();
00113     EcalTPGLutIdMap::EcalTPGLutMapItr itl=lutmap.find(lutid);
00114     if (itl!=lutmap.end()) {
00115       lut_=(*itl).second.getLut();
00116     }  else edm::LogWarning("EcalTPG")<<" could not find EcalTPGLutMap for "<<lutid;
00117 
00118   }
00119   else edm::LogWarning("EcalTPG")<<" could not find EcalTPGFineGrainTowerEEMap for "<<towid;
00120   
00121   const EcalTPGTowerStatusMap & badTTMap = ecaltpgbadTT -> getMap();
00122   EcalTPGTowerStatusMapIterator itbadTT = badTTMap.find(towid);
00123   if (itbadTT!=badTTMap.end()) {
00124     badTTStatus_=&(*itbadTT).second;
00125   }
00126 }
00127