From 20ece35ab8a64fbea9ffc12dc96e0b99e80c0f92 Mon Sep 17 00:00:00 2001
From: Alison Elliot <alison.elliot@cern.ch>
Date: Mon, 27 Sep 2021 10:14:47 +0200
Subject: [PATCH] fixing scale error in efex taus, and updating the counts

---
 .../L1CaloFEXSim/L1CaloFEXSim/eFEXFormTOBs.h  |  3 ++-
 .../L1CaloFEX/L1CaloFEXSim/src/eFEXFPGA.cxx   | 22 +++++--------------
 .../L1CaloFEXSim/src/eFEXFormTOBs.cxx         | 19 +++++++++++-----
 .../share/ref_v1Dev_decodeBS_build.ref        | 14 ++++++------
 4 files changed, 28 insertions(+), 30 deletions(-)

diff --git a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/L1CaloFEXSim/eFEXFormTOBs.h b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/L1CaloFEXSim/eFEXFormTOBs.h
index f72cf814bf73..102f121f55aa 100644
--- a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/L1CaloFEXSim/eFEXFormTOBs.h
+++ b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/L1CaloFEXSim/eFEXFormTOBs.h
@@ -38,7 +38,8 @@ namespace LVL1 {
 
     /** Internal data */
   private:
-
+    const unsigned int m_eFexStep = 25;
+    const unsigned int m_eFexTobStep = 100;
   };
 
 } // end of namespace
diff --git a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXFPGA.cxx b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXFPGA.cxx
index 192414cfef5d..2da55681ebba 100644
--- a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXFPGA.cxx
+++ b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXFPGA.cxx
@@ -99,9 +99,6 @@ StatusCode eFEXFPGA::execute(eFEXOutputCollection* inputOutputCollection){
 
   auto & thr_eEM = l1Menu->thrExtraInfo().eEM();
 
-  const unsigned int eFexstep = 25;
-  const unsigned int eFexTobstep = 100;
-
   for(int ieta = 1; ieta < 5; ieta++) {
     for(int iphi = 1; iphi < 9; iphi++) {
       int tobtable[3][3]={
@@ -122,13 +119,10 @@ StatusCode eFEXFPGA::execute(eFEXOutputCollection* inputOutputCollection){
       unsigned int ptMinToTopoCounts = 0;
       ptMinToTopoCounts = thr_eEM.ptMinToTopoCounts(); 
 
-      //returns a unsigned integer et value corresponding to the... eFEX EM cluster? in 1 MeV scale
+      //returns a unsigned integer et value corresponding to the... eFEX EM cluster in 25 MeV internal calculation scale
       unsigned int eEMTobEt = 0;
       eEMTobEt = m_eFEXegAlgoTool->getET();
-      
-      unsigned int eEMTobEtCounts = 0;
-      eEMTobEtCounts = eEMTobEt*eFexstep/eFexTobstep; //rescale from 25 MeV eFEX steps to 100 MeV for the TOB
-      
+            
       // thresholds from Trigger menu
       auto iso_loose  = thr_eEM.isolation(TrigConf::Selection::WP::LOOSE, ieta);
       auto iso_medium = thr_eEM.isolation(TrigConf::Selection::WP::MEDIUM, ieta);
@@ -178,8 +172,8 @@ StatusCode eFEXFPGA::execute(eFEXOutputCollection* inputOutputCollection){
       int phi_ind = iphi - 1;
 
       //form the egamma tob word
-      uint32_t tobword = m_eFEXFormTOBsTool->formEmTOBWord(m_id,eta_ind,phi_ind,RhadWP,WstotWP,RetaWP,seed,eEMTobEtCounts,ptMinToTopoCounts);
-      if ( (tobword != 0) && (eEMTobEtCounts != 0) ) m_emTobwords.push_back(tobword);
+      uint32_t tobword = m_eFEXFormTOBsTool->formEmTOBWord(m_id,eta_ind,phi_ind,RhadWP,WstotWP,RetaWP,seed,eEMTobEt,ptMinToTopoCounts);
+      if ( (tobword != 0) && (eEMTobEt != 0) ) m_emTobwords.push_back(tobword);
 
       std::unique_ptr<eFEXegTOB> tmp_tob = m_eFEXegAlgoTool->geteFEXegTOB();
       
@@ -219,8 +213,6 @@ StatusCode eFEXFPGA::execute(eFEXOutputCollection* inputOutputCollection){
   }
 
 
-  //ATH_CHECK(store())
-
   // --------------- TAU -------------
   for(int ieta = 1; ieta < 5; ieta++)
   {
@@ -237,16 +229,14 @@ StatusCode eFEXFPGA::execute(eFEXOutputCollection* inputOutputCollection){
 
       if (!m_eFEXtauAlgoTool->isCentralTowerSeed()){ continue; }
 
-      // Get Et of eFEX tau object in MeV
+      // Get Et of eFEX tau object in internal units (25 MeV)
       unsigned int eTauTobEt = 0;
       eTauTobEt = m_eFEXtauAlgoTool->getEt();
-      unsigned int eTauTobEtCounts = 0;
-      eTauTobEtCounts = eTauTobEt / eFexTobstep; // steps of 100 MeV for the TOB
 
       int eta_ind = ieta; // No need to offset eta index with new 0-5 convention
       int phi_ind = iphi - 1;
       
-      uint32_t tobword = m_eFEXFormTOBsTool->formTauTOBWord(m_id, eta_ind, phi_ind, eTauTobEtCounts);
+      uint32_t tobword = m_eFEXFormTOBsTool->formTauTOBWord(m_id, eta_ind, phi_ind, eTauTobEt);
       if ( tobword != 0 ) m_tauTobwords.push_back(tobword);
 
       // for plotting
diff --git a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXFormTOBs.cxx b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXFormTOBs.cxx
index b62d539d8166..91d6a6c3dc17 100644
--- a/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXFormTOBs.cxx
+++ b/Trigger/TrigT1/L1CaloFEX/L1CaloFEXSim/src/eFEXFormTOBs.cxx
@@ -35,17 +35,21 @@ uint32_t eFEXFormTOBs::formTauTOBWord(int & fpga, int & eta, int & phi, unsigned
 {
   uint32_t tobWord = 0;
 
+  //rescale from 25 MeV eFEX steps to 100 MeV for the TOB
+  unsigned int etTob = 0;
+  etTob = et*m_eFexStep/m_eFexTobStep; 
+
   // Truncate at 12 bits, set to max value of 4095, 0xfff, or 111111111111
-  if (et > 0xfff) et = 0xfff;
+  if (etTob > 0xfff) etTob = 0xfff;
 
   // Create bare minimum tob word with et, eta, phi, and fpga index, bitshifted to the appropriate locations
-  tobWord = tobWord + (fpga << 30) + (eta << 27) + (phi << 24) + et;
+  tobWord = tobWord + (fpga << 30) + (eta << 27) + (phi << 24) + etTob;
 
   ATH_MSG_DEBUG("Tau tobword: " << std::bitset<32>(tobWord) );
 
   // Some arbitrary cut so that we're not flooded with tobs, to be taken from the Trigger menu in the future!
   unsigned int minEtThreshold = 30;
-  if (et < minEtThreshold) return 0;
+  if (etTob < minEtThreshold) return 0;
   else return tobWord;
 }
 
@@ -53,17 +57,20 @@ uint32_t eFEXFormTOBs::formEmTOBWord(int & fpga, int & eta, int & phi, unsigned
 {
   uint32_t tobWord = 0;
 
+  unsigned int etTob = 0;
+  etTob = et*m_eFexStep/m_eFexTobStep; //rescale from 25 MeV eFEX steps to 100 MeV for the TOB
+
   // Truncate at 12 bits, set to max value of 4095, 0xfff, or 111111111111
-  if (et > 0xfff) et = 0xfff;
+  if (etTob > 0xfff) etTob = 0xfff;
 
   // Create bare minimum tob word with et, eta, phi, and fpga index, bitshifted to the appropriate locations
-  tobWord = tobWord + (fpga << 30) + (eta << 27) + (phi << 24) + (rhad << 22) + (wstot << 20) + (reta << 18) + (seed << 16) + et;
+  tobWord = tobWord + (fpga << 30) + (eta << 27) + (phi << 24) + (rhad << 22) + (wstot << 20) + (reta << 18) + (seed << 16) + etTob;
 
   ATH_MSG_DEBUG("EM tobword: " << std::bitset<32>(tobWord) );
 
   // Some arbitrary cut so that we're not flooded with tobs, to be taken from the Trigger menu in the future!
   unsigned int minEtThreshold = ptMinTopo;
-  if (et < minEtThreshold) return 0;
+  if (etTob < minEtThreshold) return 0;
   else return tobWord;
 }
 
diff --git a/Trigger/TrigValidation/TrigP1Test/share/ref_v1Dev_decodeBS_build.ref b/Trigger/TrigValidation/TrigP1Test/share/ref_v1Dev_decodeBS_build.ref
index 3a210656b56d..822feb89d49f 100644
--- a/Trigger/TrigValidation/TrigP1Test/share/ref_v1Dev_decodeBS_build.ref
+++ b/Trigger/TrigValidation/TrigP1Test/share/ref_v1Dev_decodeBS_build.ref
@@ -3904,23 +3904,23 @@ HLT_noalg_L1eEM8M:
 HLT_noalg_L1eTAU100:
   eventCount: 0
 HLT_noalg_L1eTAU12:
-  eventCount: 0
+  eventCount: 1
 HLT_noalg_L1eTAU12L:
-  eventCount: 0
+  eventCount: 1
 HLT_noalg_L1eTAU12M:
-  eventCount: 0
+  eventCount: 1
 HLT_noalg_L1eTAU20:
-  eventCount: 0
+  eventCount: 1
 HLT_noalg_L1eTAU25:
-  eventCount: 0
+  eventCount: 1
 HLT_noalg_L1eTAU30H:
-  eventCount: 0
+  eventCount: 1
 HLT_noalg_L1eTAU40:
   eventCount: 0
 HLT_noalg_L1eTAU60:
   eventCount: 0
 HLT_noalg_L1eTAU8:
-  eventCount: 0
+  eventCount: 1
 HLT_noalg_L1gTE50:
   eventCount: 0
 HLT_noalg_L1gXE30:
-- 
GitLab