From 65dd33dd78abb0b7b6d777b61e1cad58db99e8cd Mon Sep 17 00:00:00 2001
From: Deion Elgin Fellers <dfellers@lxplus743.cern.ch>
Date: Thu, 1 Jun 2023 01:01:12 +0200
Subject: [PATCH] add calo_total_EM variables that only use fit integral when
 waveforms are overflown

---
 .../NtupleDumper/src/NtupleDumperAlg.cxx      | 34 +++++++++++++------
 .../NtupleDumper/src/NtupleDumperAlg.h        |  6 ++--
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.cxx b/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.cxx
index c0761ca3e..6e4c2aae5 100644
--- a/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.cxx
+++ b/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.cxx
@@ -185,10 +185,12 @@ StatusCode NtupleDumperAlg::initialize()
   addCalibratedBranches("Calo",4,0);
   addBranch("Calo_total_nMIP", &m_calo_total_nMIP);
   addBranch("Calo_total_E_dep", &m_calo_total_E_dep);
-  addBranch("Calo_total_E_EM", &m_calo_total_E_EM);
+  addBranch("Calo_total_fit_E_EM", &m_calo_total_fit_E_EM);
   addBranch("Calo_total_raw_E_EM", &m_calo_total_raw_E_EM);
-  addBranch("Calo_total_E_EM_fudged", &m_calo_total_E_EM_fudged);
+  addBranch("Calo_total_E_EM", &m_calo_total_E_EM);
+  addBranch("Calo_total_fit_E_EM_fudged", &m_calo_total_fit_E_EM_fudged);
   addBranch("Calo_total_raw_E_EM_fudged", &m_calo_total_raw_E_EM_fudged);
+  addBranch("Calo_total_E_EM_fudged", &m_calo_total_E_EM_fudged);
 
   addCalibratedBranches("Preshower",2,12);
   addBranch("Preshower_total_nMIP", &m_preshower_total_nMIP);
@@ -783,9 +785,15 @@ StatusCode NtupleDumperAlg::execute(const EventContext &ctx) const
 
     m_calo_total_nMIP += hit->Nmip();
     m_calo_total_E_dep += hit->E_dep();
-    m_calo_total_E_EM += hit->E_EM();
+    m_calo_total_fit_E_EM += hit->E_EM();
     m_calo_total_raw_E_EM += (hit->E_EM()*hit->fit_to_raw_ratio());
 
+    if (m_wave_status[ch]&4) {
+        m_calo_total_E_EM += hit->E_EM();
+    } else {
+        m_calo_total_E_EM += (hit->E_EM()*hit->fit_to_raw_ratio());
+    }
+
     ATH_MSG_DEBUG("Calibrated calo: ch is " << ch << ", edep is " << hit->E_dep() << ", E_EM is " << hit->E_EM() << ", Nmip is " << hit->Nmip() << ", fit_to_raw_ratio is " << hit->fit_to_raw_ratio());
 
     //// the following is an example of how to access the linked waveform data from the calibrated data
@@ -801,11 +809,13 @@ StatusCode NtupleDumperAlg::execute(const EventContext &ctx) const
   }
 
   // add a fudged energy variable that corrects the MC to agree with the testbeam results
-  m_calo_total_E_EM_fudged = m_calo_total_E_EM;
+  m_calo_total_fit_E_EM_fudged = m_calo_total_fit_E_EM;
   m_calo_total_raw_E_EM_fudged = m_calo_total_raw_E_EM;
+  m_calo_total_E_EM_fudged = m_calo_total_E_EM;
   if (isMC) {
-    m_calo_total_E_EM_fudged = m_calo_total_E_EM_fudged * m_caloMC_FudgeFactor;
+    m_calo_total_fit_E_EM_fudged = m_calo_total_fit_E_EM_fudged * m_caloMC_FudgeFactor;
     m_calo_total_raw_E_EM_fudged = m_calo_total_raw_E_EM_fudged * m_caloMC_FudgeFactor;
+    m_calo_total_E_EM_fudged = m_calo_total_E_EM_fudged * m_caloMC_FudgeFactor;
   }
 
   // load in calibrated preshower container
@@ -813,11 +823,11 @@ StatusCode NtupleDumperAlg::execute(const EventContext &ctx) const
   ATH_CHECK(preshowerCalibratedContainer.isValid());
   for (auto hit : *preshowerCalibratedContainer) {
     int ch=hit->channel();
-    m_calibrated_nMIP[ch] = hit->Nmip();
-    m_calibrated_E_dep[ch] = hit->E_dep();
+    m_calibrated_nMIP[ch] = hit->Nmip() * hit->fit_to_raw_ratio();
+    m_calibrated_E_dep[ch] = hit->E_dep() * hit->fit_to_raw_ratio();
 
-    m_preshower_total_nMIP += hit->Nmip();
-    m_preshower_total_E_dep += hit->E_dep();
+    m_preshower_total_nMIP += hit->Nmip() * hit->fit_to_raw_ratio();
+    m_preshower_total_E_dep += hit->E_dep() * hit->fit_to_raw_ratio();
 
     ATH_MSG_DEBUG("Calibrated preshower: ch is " << ch << ", edep is " << hit->E_dep() << ", E_EM is " << hit->E_EM() << ", Nmip is " << hit->Nmip() << ", fit_to_raw_ratio is " << hit->fit_to_raw_ratio());
   }
@@ -1288,10 +1298,12 @@ NtupleDumperAlg::clearTree() const
 
   m_calo_total_nMIP=0;
   m_calo_total_E_dep=0;
-  m_calo_total_E_EM=0;
+  m_calo_total_fit_E_EM=0;
   m_calo_total_raw_E_EM=0;
-  m_calo_total_E_EM_fudged=0;
+  m_calo_total_E_EM=0;
+  m_calo_total_fit_E_EM_fudged=0;
   m_calo_total_raw_E_EM_fudged=0;
+  m_calo_total_E_EM_fudged=0;
 
   m_preshower_total_nMIP=0;
   m_preshower_total_E_dep=0;
diff --git a/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.h b/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.h
index 339c0838b..67f3bacf8 100644
--- a/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.h
+++ b/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.h
@@ -174,11 +174,13 @@ private:
 
   mutable float m_calo_total_nMIP;
   mutable float m_calo_total_E_dep;
-  mutable float m_calo_total_E_EM;
+  mutable float m_calo_total_fit_E_EM;
   mutable float m_calo_total_raw_E_EM;
+  mutable float m_calo_total_E_EM;
 
-  mutable float m_calo_total_E_EM_fudged;
+  mutable float m_calo_total_fit_E_EM_fudged;
   mutable float m_calo_total_raw_E_EM_fudged;
+  mutable float m_calo_total_E_EM_fudged;
 
   mutable float m_preshower_total_nMIP;
   mutable float m_preshower_total_E_dep;
-- 
GitLab