Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:45

0001 ///
0002 /// \class l1t::CaloStage2TowerAlgorithmFirmwareImp1
0003 ///
0004 /// \author: Jim Brooke
0005 ///
0006 /// Description: first iteration of stage 2 jet algo
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "L1Trigger/L1TCalorimeter/interface/Stage2TowerDecompressAlgorithmFirmware.h"
0010 //#include "DataFormats/Math/interface/LorentzVector.h "
0011 
0012 #include "L1Trigger/L1TCalorimeter/interface/CaloParamsHelper.h"
0013 
0014 l1t::Stage2TowerDecompressAlgorithmFirmwareImp1::Stage2TowerDecompressAlgorithmFirmwareImp1(
0015     CaloParamsHelper const* params)
0016     : params_(params) {}
0017 
0018 l1t::Stage2TowerDecompressAlgorithmFirmwareImp1::~Stage2TowerDecompressAlgorithmFirmwareImp1() {}
0019 
0020 void l1t::Stage2TowerDecompressAlgorithmFirmwareImp1::processEvent(const std::vector<l1t::CaloTower>& inTowers,
0021                                                                    std::vector<l1t::CaloTower>& outTowers) {
0022   for (auto tow = inTowers.begin(); tow != inTowers.end(); ++tow) {
0023     if (!params_->doTowerEncoding()) {
0024       outTowers.push_back(*tow);
0025 
0026     }
0027 
0028     else {
0029       int sum = tow->hwPt();
0030       int ratio = tow->hwEtRatio();
0031       int qual = tow->hwQual();
0032 
0033       int denomCoeff = int((128. / (1. + pow(2, ratio))) + 0.5);
0034       int numCoeff = 128 - denomCoeff;
0035 
0036       // if ((qual & 0x1)==0) {
0037       //    switch (ratio) {
0038       //    case 000 :
0039       //      numCoeff = 64;
0040       //      denomCoeff = 64;
0041       //      break;
0042       //    case 001 :
0043       //      numCoeff = 43;
0044       //      denomCoeff = 85;
0045       //      break;
0046       //    case 010 :
0047       //      numCoeff = 26;
0048       //      denomCoeff = 102;
0049       //      break;
0050       //    case 011 :
0051       //      numCoeff = 14;
0052       //      denomCoeff = 114;
0053       //      break;
0054       //    case 100 :
0055       //      numCoeff = 8;
0056       //      denomCoeff = 120;
0057       //      break;
0058       //    case 101 :
0059       //      numCoeff = 4;
0060       //      denomCoeff = 124;
0061       //      break;
0062       //    case 110 :
0063       //      numCoeff = 2;
0064       //      denomCoeff = 126;
0065       //      break;
0066       //    case 111 :
0067       //      numCoeff = 1;
0068       //      denomCoeff = 127;
0069       //      break;
0070       //    }
0071       // }
0072       // else {
0073       //    numCoeff = 128;
0074       //    denomCoeff = 0;
0075       // }
0076 
0077       int em = 0;
0078       int had = 0;
0079 
0080       bool denomZeroFlag = ((qual & 0x1) > 0);
0081       bool eOverHFlag = ((qual & 0x2) > 0);
0082 
0083       if (denomZeroFlag && !eOverHFlag)
0084         had = sum;
0085 
0086       if (denomZeroFlag && eOverHFlag)
0087         em = sum;
0088 
0089       if (!denomZeroFlag && !eOverHFlag) {  // H > E, ratio = log(H/E)
0090         em = (denomCoeff * sum) >> 7;
0091         had = (numCoeff * sum) >> 7;
0092       }
0093 
0094       if (!denomZeroFlag && eOverHFlag) {  // E >= H , so ratio==log(E/H)
0095         em = (numCoeff * sum) >> 7;
0096         had = (denomCoeff * sum) >> 7;
0097       }
0098 
0099       em &= params_->towerMaskE();
0100       had &= params_->towerMaskH();
0101 
0102       l1t::CaloTower newTow;
0103       newTow.setHwEta(tow->hwEta());
0104       newTow.setHwPhi(tow->hwPhi());
0105       newTow.setHwEtEm(em);
0106       newTow.setHwEtHad(had);
0107 
0108       newTow.setHwPt(sum);
0109       newTow.setHwEtRatio(ratio);
0110       newTow.setHwQual(qual);
0111 
0112       outTowers.push_back(newTow);
0113     }
0114   }
0115 }