From 08142744680625bb28545a10c9dc99435f881878 Mon Sep 17 00:00:00 2001
From: Stanislav Polacek <stanislav.polacek@cern.ch>
Date: Tue, 8 Dec 2020 18:14:32 +0000
Subject: [PATCH] TileTimeBCOffset - improved algorithm for finding events with
 time offset in channels of faulty DMUs

---
 .../TileRecUtils/TileTimeBCOffsetFilter.h       |  4 ++++
 .../python/TileRawChannelCorrectionConfig.py    |  6 ++++--
 .../TileRecUtils/src/TileTimeBCOffsetFilter.cxx | 17 +++++++++++++----
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/TileCalorimeter/TileRecUtils/TileRecUtils/TileTimeBCOffsetFilter.h b/TileCalorimeter/TileRecUtils/TileRecUtils/TileTimeBCOffsetFilter.h
index 2b0c8342aca..c1aa0d64e36 100644
--- a/TileCalorimeter/TileRecUtils/TileRecUtils/TileTimeBCOffsetFilter.h
+++ b/TileCalorimeter/TileRecUtils/TileRecUtils/TileTimeBCOffsetFilter.h
@@ -95,7 +95,11 @@ class TileTimeBCOffsetFilter: public extends<AthAlgTool, ITileRawChannelTool> {
     float m_ene_threshold_3chan;
     float m_ene_threshold_1chan;
     float m_time_threshold_diff;
+    float m_time_threshold_ref_ch;
+    float m_ene_threshold_ref_ch;
+    
     bool m_checkDCS;
 
 };
 #endif
+
diff --git a/TileCalorimeter/TileRecUtils/python/TileRawChannelCorrectionConfig.py b/TileCalorimeter/TileRecUtils/python/TileRawChannelCorrectionConfig.py
index 55cfd98db1d..61329b4100e 100644
--- a/TileCalorimeter/TileRecUtils/python/TileRawChannelCorrectionConfig.py
+++ b/TileCalorimeter/TileRecUtils/python/TileRawChannelCorrectionConfig.py
@@ -101,9 +101,11 @@ def TileTimeBCOffsetFilterCfg(flags, **kwargs):
 
     acc = ComponentAccumulator()
     kwargs.setdefault('CheckDCS', flags.Tile.useDCS)
-    kwargs.setdefault('EneThreshold3', 3000)
-    kwargs.setdefault('EneThreshold1', 4000)
+    kwargs.setdefault('EneThreshold3', 1000)
+    kwargs.setdefault('EneThreshold1', 3000)
     kwargs.setdefault('TimeThreshold', 15)
+    kwargs.setdefault('RefEneThreshold', 500)
+    kwargs.setdefault('RefTimeThreshold', 10)
 
     from TileRecUtils.TileDQstatusConfig import TileDQstatusAlgCfg
     acc.merge( TileDQstatusAlgCfg(flags) )
diff --git a/TileCalorimeter/TileRecUtils/src/TileTimeBCOffsetFilter.cxx b/TileCalorimeter/TileRecUtils/src/TileTimeBCOffsetFilter.cxx
index 46f5d56972c..65e9c84b3b1 100644
--- a/TileCalorimeter/TileRecUtils/src/TileTimeBCOffsetFilter.cxx
+++ b/TileCalorimeter/TileRecUtils/src/TileTimeBCOffsetFilter.cxx
@@ -26,6 +26,7 @@
 #include "TileEvent/TileRawChannelContainer.h"
 #include "TileIdentifier/TileRawChannelUnit.h"
 #include "TileCalibBlobObjs/TileCalibUtils.h"
+#include "TileRecUtils/TileRawChannelBuilder.h"
 
 // Atlas includes
 #include "AthenaKernel/errorcheck.h"
@@ -41,9 +42,11 @@ TileTimeBCOffsetFilter::TileTimeBCOffsetFilter(const std::string& type,
     , m_tileHWID(nullptr)
     , m_cabling(nullptr)
 {
-  declareProperty("EneThreshold3", m_ene_threshold_3chan = 3000);
-  declareProperty("EneThreshold1", m_ene_threshold_1chan = 4000);
+  declareProperty("EneThreshold3", m_ene_threshold_3chan = 1000);
+  declareProperty("EneThreshold1", m_ene_threshold_1chan = 3000);
   declareProperty("TimeThreshold", m_time_threshold_diff = 15);
+  declareProperty("RefEneThreshold", m_ene_threshold_ref_ch = 500);
+  declareProperty("RefTimeThreshold", m_time_threshold_ref_ch = 10);
 
   declareProperty("CheckDCS", m_checkDCS = false);
 }
@@ -58,6 +61,10 @@ StatusCode TileTimeBCOffsetFilter::initialize() {
                       << m_ene_threshold_1chan << endmsg;
       msg(MSG::DEBUG) << "TimeThreshold = " 
                       << m_time_threshold_diff << endmsg;
+      msg(MSG::DEBUG) << "RefEneThreshold = "
+                      << m_ene_threshold_ref_ch << endmsg;
+      msg(MSG::DEBUG) << "RefTimeThreshold = "
+                      << m_time_threshold_ref_ch << endmsg;
       msg(MSG::DEBUG) << "CheckDCS = " 
                       << ((m_checkDCS)?"true":"false") << endmsg;
   }
@@ -234,6 +241,7 @@ TileTimeBCOffsetFilter::process (TileMutableRawChannelContainer& rchCont) const
       for(int i=0; i <= nchan_dmu; ++i) {
         ene_above = ene_above || ((ch_number[i] >= 0) && (ch_amp[i] > ene_threshold));
       }
+      ene_above = ene_above && (ch_amp[0] > m_ene_threshold_ref_ch);  // reference energy above threshold
       if (ene_above) { // at least 1 channel above the threshold
         ATH_MSG_VERBOSE( "Energy above threshold");
         /* first check whether the times of 1-3 channels on the DMU are within
@@ -255,7 +263,8 @@ TileTimeBCOffsetFilter::process (TileMutableRawChannelContainer& rchCont) const
         if (time_dmu_same) {
           time_dmu_aver /= n_dmu_aver;
           ATH_MSG_VERBOSE( "Average time "<< time_dmu_aver);
-          if (fabs(ch_time[0]-time_dmu_aver) > m_time_threshold_diff) {
+          if ((fabs(ch_time[0]-time_dmu_aver) > m_time_threshold_diff)    // reference time far from average DMU time
+                      && (fabs(ch_time[0]) < m_time_threshold_ref_ch)) {  // reference time ~0 ns
             for(int i=1; i <= nchan_dmu; ++i) {
               if (ch_number[i] >= 0) ch_mask[i] = true;
             }
@@ -373,4 +382,4 @@ int TileTimeBCOffsetFilter::find_partner(int ros, int ch) const {
     return lbcells[ch];
   else         // EB
     return ebcells[ch];
-}
+}
\ No newline at end of file
-- 
GitLab