CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/L1Trigger/RegionalCaloTrigger/src/L1RCTLookupTables.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 using std::cout;
00003 using std::endl;
00004 
00005 #include <fstream>
00006 #include <string>
00007 
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTLookupTables.h"
00012 
00013 #include "CondFormats/L1TObjects/interface/L1RCTParameters.h"
00014 #include "CondFormats/L1TObjects/interface/L1RCTChannelMask.h"
00015 #include "CondFormats/L1TObjects/interface/L1RCTNoisyChannelMask.h"
00016 #include "CondFormats/L1TObjects/interface/L1CaloEcalScale.h"
00017 #include "CondFormats/L1TObjects/interface/L1CaloHcalScale.h"
00018 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
00019 
00020 unsigned int L1RCTLookupTables::lookup(unsigned short ecalInput,
00021                                        unsigned short hcalInput,
00022                                        unsigned short fgbit,
00023                                        unsigned short crtNo,
00024                                        unsigned short crdNo,
00025                                        unsigned short twrNo) const
00026 {
00027   if(rctParameters_ == 0)
00028     throw cms::Exception("L1RCTParameters Invalid")
00029       << "L1RCTParameters should be set every event" << rctParameters_;
00030   if(channelMask_ == 0)
00031     throw cms::Exception("L1RCTChannelMask Invalid")
00032       << "L1RCTChannelMask should be set every event" << channelMask_;
00033   if(noisyChannelMask_ == 0)
00034     throw cms::Exception("L1RCTNoisyChannelMask Invalid")
00035       << "L1RCTNoisyChannelMask should be set every event" << noisyChannelMask_;
00036   if(ecalInput > 0xFF) 
00037     throw cms::Exception("Invalid Data") 
00038       << "ECAL compressedET should be less than 0xFF, is " << ecalInput;
00039   if(hcalInput > 0xFF) 
00040     throw cms::Exception("Invalid Data") 
00041       << "HCAL compressedET should be less than 0xFF, is " << hcalInput;
00042   if(fgbit > 1) 
00043     throw cms::Exception("Invalid Data") 
00044       << "ECAL finegrain should be a single bit, is " << fgbit;
00045   short iEta = (short) rctParameters_->calcIEta(crtNo, crdNo, twrNo);
00046   unsigned short iAbsEta = (unsigned short) abs(iEta);
00047   short sign = iEta/iAbsEta;
00048   unsigned short iPhi = rctParameters_->calcIPhi(crtNo, crdNo, twrNo);
00049   unsigned short phiSide = (iPhi/4)%2;
00050   if(iAbsEta < 1 || iAbsEta > 28) 
00051     throw cms::Exception("Invalid Data") 
00052       << "1 <= |IEta| <= 28, is " << iAbsEta;
00053 
00054 
00055   //Pre Input bits
00056   unsigned short ecalAfterMask=0;
00057   unsigned short hcalAfterMask=0;
00058 
00059 
00060   // using channel mask to mask off ecal channels
00061   //Mike: Introducing the hot channel mask 
00062   //If the Et is above the threshold then mask it as well
00063 
00064 
00065   
00066   float ecalBeforeMask = convertEcal(ecalInput, iAbsEta, sign);
00067 
00068 
00069   bool resetECAL = (channelMask_->ecalMask[crtNo][phiSide][iAbsEta-1]) || //channel mask
00070     (noisyChannelMask_->ecalMask[crtNo][phiSide][iAbsEta-1] &&
00071      ecalBeforeMask<noisyChannelMask_->ecalThreshold)||//hot mask
00072       (rctParameters_->eGammaECalScaleFactors()[iAbsEta-1] == 0.&&
00073        rctParameters_->jetMETECalScaleFactors()[iAbsEta-1] == 0.);       
00074     
00075 
00076 
00077   if (resetECAL)    {
00078       ecalAfterMask=0;
00079     }
00080   else    {
00081       ecalAfterMask=ecalInput;
00082     }
00083 
00084   float ecal =  convertEcal(ecalAfterMask, iAbsEta, sign);
00085 
00086 
00087   // masking off hcal for channels in channel mask
00088   float hcalBeforeMask = convertHcal(hcalInput, iAbsEta, sign);
00089 
00090   bool resetHCAL = channelMask_->hcalMask[crtNo][phiSide][iAbsEta-1]||
00091     (noisyChannelMask_->hcalMask[crtNo][phiSide][iAbsEta-1] &&
00092      hcalBeforeMask<noisyChannelMask_->hcalThreshold)||//hot mask
00093       (rctParameters_->eGammaHCalScaleFactors()[iAbsEta-1] == 0.&&
00094        rctParameters_->jetMETHCalScaleFactors()[iAbsEta-1] == 0.);
00095 
00096   if (resetHCAL)    {
00097       hcalAfterMask=0;
00098     }
00099   else    {
00100       hcalAfterMask=hcalInput;
00101     }
00102 
00103   float hcal = convertHcal(hcalAfterMask, iAbsEta, sign);
00104 
00105   unsigned long etIn7Bits;
00106   unsigned long etIn9Bits;
00107 
00108   if((ecalAfterMask == 0 && hcalAfterMask > 0) &&
00109      ((rctParameters_->noiseVetoHB() && iAbsEta > 0 && iAbsEta < 18)
00110       || (rctParameters_->noiseVetoHEplus() && iAbsEta>17 && crtNo>8)
00111       || (rctParameters_->noiseVetoHEminus() && iAbsEta>17 && crtNo<9)))
00112     {
00113       etIn7Bits = 0;
00114       etIn9Bits = 0;
00115     }
00116   else
00117     {
00118       etIn7Bits = eGammaETCode(ecal, hcal, iAbsEta);
00119       etIn9Bits = jetMETETCode(ecal, hcal, iAbsEta);
00120     }
00121   // Saturated input towers cause tower ET pegging at the highest value
00122   if((ecalAfterMask == 0xFF && 
00123       rctParameters_->eGammaECalScaleFactors()[iAbsEta-1] != 0. ) 
00124      || (hcalAfterMask == 0xFF &&
00125          rctParameters_->eGammaHCalScaleFactors()[iAbsEta-1] != 0. )
00126      )
00127     {
00128       etIn7Bits = 0x7F; // egamma path
00129     }
00130   if((ecalAfterMask == 0xFF &&
00131       rctParameters_->jetMETECalScaleFactors()[iAbsEta-1] != 0. )
00132      || (hcalAfterMask == 0xFF &&
00133          rctParameters_->jetMETHCalScaleFactors()[iAbsEta-1] != 0. ))
00134     {
00135       etIn9Bits = 0x1FF; // sums path
00136     }
00137 
00138   unsigned long shiftEtIn9Bits = etIn9Bits<<8;
00139   unsigned long shiftHE_FGBit = hOeFGVetoBit(ecal, hcal, fgbit)<<7;
00140   unsigned long shiftActivityBit = 0;
00141   if ( rctParameters_->jetMETECalScaleFactors()[iAbsEta-1] == 0.
00142        && rctParameters_->jetMETHCalScaleFactors()[iAbsEta-1] == 0. )
00143     {
00144       // do nothing, it's already zero
00145     }
00146   else if (rctParameters_->jetMETECalScaleFactors()[iAbsEta-1] == 0. )
00147     {
00148       shiftActivityBit = activityBit(0., hcal)<<17;
00149     }
00150   else if (rctParameters_->jetMETHCalScaleFactors()[iAbsEta-1] == 0. )
00151     {
00152       shiftActivityBit = activityBit(ecal, 0.)<<17;
00153     }
00154   else
00155     {
00156       shiftActivityBit = activityBit(ecal, hcal)<<17;
00157     }
00158   unsigned long output=etIn7Bits+shiftHE_FGBit+shiftEtIn9Bits+shiftActivityBit;
00159   return output;
00160 }
00161 
00162 unsigned int L1RCTLookupTables::lookup(unsigned short hfInput,
00163                                        unsigned short crtNo,
00164                                        unsigned short crdNo,
00165                                        unsigned short twrNo
00166                                        ) const
00167 {
00168   if(rctParameters_ == 0)
00169     throw cms::Exception("L1RCTParameters Invalid")
00170       << "L1RCTParameters should be set every event" << rctParameters_;
00171   if(channelMask_ == 0)
00172     throw cms::Exception("L1RCTChannelMask Invalid")
00173       << "L1RCTChannelMask should be set every event" << channelMask_;
00174   if(hfInput > 0xFF) 
00175     throw cms::Exception("Invalid Data") 
00176       << "HF compressedET should be less than 0xFF, is " << hfInput;
00177   short iEta = rctParameters_->calcIEta(crtNo, crdNo, twrNo);
00178   unsigned short iAbsEta = abs(iEta);
00179   short sign = (iEta/iAbsEta);
00180   unsigned short phiSide = twrNo/4;
00181   if(iAbsEta < 29 || iAbsEta > 32) 
00182     throw cms::Exception("Invalid Data") 
00183       << "29 <= |iEta| <= 32, is " << iAbsEta;
00184 
00185   float et = convertHcal(hfInput, iAbsEta, sign);;
00186 
00187 
00188 
00189   if (channelMask_->hfMask[crtNo][phiSide][iAbsEta-29]||
00190       (noisyChannelMask_->hfMask[crtNo][phiSide][iAbsEta-29]&&
00191        et<noisyChannelMask_->hfThreshold))
00192     {
00193       et = 0;
00194     }
00195 
00196   unsigned int result = convertToInteger(et, rctParameters_->jetMETLSB(), 8);
00197   return result;
00198 }
00199 
00200 bool L1RCTLookupTables::hOeFGVetoBit(float ecal, float hcal, bool fgbit) const
00201 {
00202   if(rctParameters_ == 0)
00203     throw cms::Exception("L1RCTParameters Invalid")
00204       << "L1RCTParameters should be set every event" << rctParameters_;
00205   bool veto = false;
00206   if(ecal > rctParameters_->eMinForFGCut() && 
00207      ecal < rctParameters_->eMaxForFGCut())
00208     {
00209       if(fgbit) veto = true;
00210     }
00211   if(ecal > rctParameters_->eMinForHoECut() && 
00212      ecal < rctParameters_->eMaxForHoECut())
00213     {
00214       if((hcal / ecal) > rctParameters_->hOeCut()) veto = true;
00215     }
00216   //  else
00217   if (ecal < rctParameters_->eMinForHoECut())
00218     {
00219       if(hcal > rctParameters_->hMinForHoECut()) veto = true;  // Changed from eMinForHoECut() - JLL 2008-Feb-13
00220     }
00221   return veto;
00222 }
00223 
00224 bool L1RCTLookupTables::activityBit(float ecal, float hcal) const
00225 {
00226   if(rctParameters_ == 0)
00227     throw cms::Exception("L1RCTParameters Invalid")
00228       << "L1RCTParameters should be set every event" << rctParameters_;
00229   return ((ecal > rctParameters_->eActivityCut()) || 
00230           (hcal > rctParameters_->hActivityCut()));
00231 }
00232 
00233 // uses etScale
00234 unsigned int L1RCTLookupTables::emRank(unsigned short energy) const 
00235 {
00236   if(etScale_)
00237     {
00238       return etScale_->rank(energy);
00239     }
00240   else
00241     //    edm::LogInfo("L1RegionalCaloTrigger") 
00242     //      << "CaloEtScale was not used - energy instead of rank" << std::endl;
00243   return energy;
00244 }
00245 
00246 // converts compressed ecal energy to linear (real) scale
00247 float L1RCTLookupTables::convertEcal(unsigned short ecal, unsigned short iAbsEta, short sign) const
00248 {
00249   if(ecalScale_)
00250     {
00251       //std::cout << "[luts] energy " << ecal << " sign " << sign 
00252       //<< " iAbsEta " << iAbsEta << " iPhi "   << iPhi << std::endl;
00253       float dummy = 0;
00254       dummy = float (ecalScale_->et( ecal, iAbsEta, sign ));
00255       /*
00256       if (ecal > 0)
00257         {
00258           std::cout << "[luts] ecal converted from " << ecal << " to " 
00259                     << dummy << " with iAbsEta " << iAbsEta << std::endl;
00260         }
00261       */
00262       return dummy;
00263     }
00264   //else if(rctParameters_ == 0)
00265   //  {
00266   //    throw cms::Exception("L1RCTParameters Invalid")
00267   //    << "L1RCTParameters should be set every event" << rctParameters_;
00268   //  }
00269   else
00270     {
00271       return ((float) ecal) * rctParameters_->eGammaLSB();
00272     }
00273 }
00274 
00275 // converts compressed hcal energy to linear (real) scale
00276 float L1RCTLookupTables::convertHcal(unsigned short hcal, unsigned short iAbsEta, short sign) const
00277 {
00278   if (hcalScale_ != 0)
00279     {
00280       return (hcalScale_->et( hcal, iAbsEta, sign ));
00281     }
00282   else
00283     {
00284       //      edm::LogInfo("L1RegionalCaloTrigger") 
00285       //        << "CaloTPGTranscoder was not used" << std::endl;
00286       return ((float) hcal) * rctParameters_->jetMETLSB();
00287     }
00288 }
00289 
00290 // integerize given an LSB and set maximum value of 2^precision-1
00291 unsigned long L1RCTLookupTables::convertToInteger(float et, 
00292                                                   float lsb, 
00293                                                   int precision) const
00294 {
00295   unsigned long etBits = (unsigned long)(et/lsb);
00296   unsigned long maxValue = (1 << precision) - 1;
00297   if(etBits > maxValue)
00298     return maxValue;
00299   else
00300     return etBits;
00301 }
00302 
00303 unsigned int L1RCTLookupTables::eGammaETCode(float ecal, float hcal, int iAbsEta) const
00304 {
00305   if(rctParameters_ == 0)
00306     throw cms::Exception("L1RCTParameters Invalid")
00307       << "L1RCTParameters should be set every event" << rctParameters_;
00308   float etLinear = rctParameters_->EGammaTPGSum(ecal,hcal,iAbsEta);
00309   return convertToInteger(etLinear, rctParameters_->eGammaLSB(), 7);
00310 }
00311 
00312 unsigned int L1RCTLookupTables::jetMETETCode(float ecal, float hcal, int iAbsEta) const
00313 {
00314   if(rctParameters_ == 0)
00315     throw cms::Exception("L1RCTParameters Invalid")
00316       << "L1RCTParameters should be set every event" << rctParameters_;
00317   float etLinear = rctParameters_->JetMETTPGSum(ecal,hcal,iAbsEta);
00318   return convertToInteger(etLinear, rctParameters_->jetMETLSB(), 9);
00319 }