//-------------------------------------------------
//
//   Class: L1MuGMTLFDeltaEtaLUT
//
//   this class was automatically generated by L1MuGMTLUT::MakeSubClass()
//
//
//   Author :
//   H. Sakulin            HEPHY Vienna
//
//   Migrated to CMSSW:
//   I. Mikulec
//
//--------------------------------------------------

//-----------------------
// This Class's Header --
//-----------------------
#include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTLFDeltaEtaLUT.h"

//------------------------------------
// Collaborating Class Declarations --
//------------------------------------
#include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTConfig.h"
#include "CondFormats/L1TObjects/interface/L1MuGMTScales.h"
#include "CondFormats/L1TObjects/interface/L1MuTriggerScales.h"
#include "CondFormats/L1TObjects/interface/L1MuPacking.h"

void L1MuGMTLFDeltaEtaLUT::InitParameters() {}

unsigned L1MuGMTLFDeltaEtaLUT::TheLookupFunction(int idx, unsigned eta_dtcsc, unsigned eta_rpc) const {
  const L1MuGMTScales* theGMTScales = L1MuGMTConfig::getGMTScales();
  const L1MuTriggerScales* theTriggerScales = L1MuGMTConfig::getTriggerScales();

  // idx is DTRPC CSCRPC

  float etaValue_dtcsc = theTriggerScales->getRegionalEtaScale(idx * 2)->getCenter(eta_dtcsc);
  float etaValue_rpc = theTriggerScales->getRegionalEtaScale(idx * 2 + 1)->getCenter(eta_rpc);

  float delta_eta = etaValue_dtcsc - etaValue_rpc;

  unsigned delta_eta_4bit = 0;

  // check out of range
  if (delta_eta < theGMTScales->getDeltaEtaScale(idx)->getScaleMin() ||
      delta_eta > theGMTScales->getDeltaEtaScale(idx)->getScaleMax()) {
    L1MuSignedPacking<4> pack;
    delta_eta_4bit = pack.packedFromIdx(-8);
  } else {
    delta_eta_4bit = theGMTScales->getDeltaEtaScale(idx)->getPacked(delta_eta);
  }

  //      cout << "delta-eta LUT : idx= " << idx
  //  	 << ", etaValue_dtcsc = " << etaValue_dtcsc
  //  	 << ", etaValue_rpc = " << etaValue_rpc
  //  	 << ", delta_eta = " << delta_eta
  //  	 << ", packed = " << delta_eta_4bit
  //  	 << endl;

  return delta_eta_4bit;
}
