From e768f9c9fd6d87b95a837571bd4e356bba8057d4 Mon Sep 17 00:00:00 2001
From: Alexandre Laurier <alexandre.laurier@cern.ch>
Date: Mon, 9 Nov 2020 21:50:09 +0100
Subject: [PATCH] Manually sweeping !37961 from 21.3 to master BugFix MM
 Overlay and sTGC

---
 .../python/MM_DigitizationConfig.py           |  8 +++++---
 .../python/sTGC_DigitizationConfig.py         |  8 ++++----
 .../share/sTGC_Digitization_VMM.config        |  2 +-
 .../sTGC_Digitization/src/sTgcDigitMaker.cxx  |  2 +-
 .../MuonOverlay/MM_Overlay/src/MM_Overlay.cxx | 20 ++++++++++++++++++-
 5 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/MuonSpectrometer/MuonDigitization/MM_Digitization/python/MM_DigitizationConfig.py b/MuonSpectrometer/MuonDigitization/MM_Digitization/python/MM_DigitizationConfig.py
index 3b114827329..eda1b277e67 100644
--- a/MuonSpectrometer/MuonDigitization/MM_Digitization/python/MM_DigitizationConfig.py
+++ b/MuonSpectrometer/MuonDigitization/MM_Digitization/python/MM_DigitizationConfig.py
@@ -7,12 +7,14 @@ from Digitization.DigitizationFlags import jobproperties
 from AthenaCommon import CfgMgr
 
 # The earliest bunch crossing time for which interactions will be sent
-# to the MdtDigitizationTool.
+# to the MMDigitizationTool.
+# MM readout window is 8BC. To be safe, do [-7,7]
 def MM_FirstXing():
-    return -250
+    return -200
 
 # The latest bunch crossing time for which interactions will be sent
-# to the MdtDigitizationTool.
+# to the MMDigitizationTool.
+# MM readout window is 8BC. To be safe, do [-7,7]
 def MM_LastXing():
     return 200
 
diff --git a/MuonSpectrometer/MuonDigitization/sTGC_Digitization/python/sTGC_DigitizationConfig.py b/MuonSpectrometer/MuonDigitization/sTGC_Digitization/python/sTGC_DigitizationConfig.py
index 1306e4060fa..a4d397afc97 100644
--- a/MuonSpectrometer/MuonDigitization/sTGC_Digitization/python/sTGC_DigitizationConfig.py
+++ b/MuonSpectrometer/MuonDigitization/sTGC_Digitization/python/sTGC_DigitizationConfig.py
@@ -7,14 +7,14 @@ from Digitization.DigitizationFlags import jobproperties
 from AthenaCommon import CfgMgr
 
 # The earliest bunch crossing time for which interactions will be sent 
-# to the sTGCDigitizationTool. 
+# to the sTGCDigitizationTool. BCID = -4
 def sTGC_FirstXing(): 
-    return -375 
+    return -100
  
 # The latest bunch crossing time for which interactions will be sent 
-# to the sTGCDigitizationTool. 
+# to the sTGCDigitizationTool. BCID = 3
 def sTGC_LastXing(): 
-    return 175 
+    return 100
 
 def sTgcDigitizationTool(name="sTgcDigitizationTool",**kwargs):
     if jobproperties.Digitization.doXingByXingPileUp():
diff --git a/MuonSpectrometer/MuonDigitization/sTGC_Digitization/share/sTGC_Digitization_VMM.config b/MuonSpectrometer/MuonDigitization/sTGC_Digitization/share/sTGC_Digitization_VMM.config
index f74723dcaa1..efbeb4abd0a 100644
--- a/MuonSpectrometer/MuonDigitization/sTGC_Digitization/share/sTGC_Digitization_VMM.config
+++ b/MuonSpectrometer/MuonDigitization/sTGC_Digitization/share/sTGC_Digitization_VMM.config
@@ -1,4 +1,4 @@
 neighborON			1
-mainThreshold			0.02
+mainThreshold			0.001
 neighborThreshold		0.0
 readoutTick			1
diff --git a/MuonSpectrometer/MuonDigitization/sTGC_Digitization/src/sTgcDigitMaker.cxx b/MuonSpectrometer/MuonDigitization/sTGC_Digitization/src/sTgcDigitMaker.cxx
index 596d29c1d5d..6d656adfddf 100644
--- a/MuonSpectrometer/MuonDigitization/sTGC_Digitization/src/sTgcDigitMaker.cxx
+++ b/MuonSpectrometer/MuonDigitization/sTGC_Digitization/src/sTgcDigitMaker.cxx
@@ -52,7 +52,7 @@ sTgcDigitMaker::sTgcDigitMaker(sTgcHitIdHelper* hitIdHelper, const MuonGM::MuonD
   m_GausMean                = 2.27;  //mm; VMM response from Oct/Nov 2013 test beam
   m_GausSigma               = 0.1885;//mm; VMM response from Oct/Nov 2013 test beam
   m_IntegralTimeOfElectr    = 20.00; // ns
-  m_CrossTalk               = 0.03; 
+  m_CrossTalk               = 0.00; // Turn off cross-talk. Old guesstimate was 0.03: Alexandre Laurier 2020-10-11 
   m_StripResolution         = 0.07; // Angular strip resolution parameter
   m_ChargeSpreadFactor      = 0.;
   m_channelTypes            = 3; // 1 -> strips, 2 -> strips+pad, 3 -> strips/wires/pads
diff --git a/MuonSpectrometer/MuonOverlay/MM_Overlay/src/MM_Overlay.cxx b/MuonSpectrometer/MuonOverlay/MM_Overlay/src/MM_Overlay.cxx
index 3fe5727010f..a8b239f698f 100644
--- a/MuonSpectrometer/MuonOverlay/MM_Overlay/src/MM_Overlay.cxx
+++ b/MuonSpectrometer/MuonOverlay/MM_Overlay/src/MM_Overlay.cxx
@@ -34,13 +34,31 @@ namespace Overlay
       throw std::runtime_error("mergeChannelData<MmDigit>() called by a wrong parent algorithm? Must be MM_Overlay.");
     }
 
+    // This is a needed temporary hack for which I dont fully understand the source. Alexandre Laurier 2020-10-06
+    // For some reason, sometimes the "main digit"'s size is empty.
+    // In these cases, dataContainer is larger than mcContainer which goes against the basic overlay assumption
+    // These happen in cases where we create very busy signal events.
+    // A MicroMega digit is a vector of strips, so an empty digit makes no sense.
+    bool skipOverlay = false;
+    if (signalDigit.stripResponseTime().size() == 0) {
+      signalDigit = bkgDigit;
+      skipOverlay = true;
+    }
+
     float sig_time = signalDigit.stripResponseTime()[0]; 
     float bkg_time = bkgDigit.stripResponseTime()[0]; 
+
+    if (skipOverlay) { // do nothing since 1 digit was empty. Keep the original
+      algorithm->msg(MSG::WARNING)
+        << "Skipping overlay of empty MM digit!"
+        << endmsg;
+    }
+
     // As of now, we need to decide how to overlay MM digits
     // NEEDS TO BE ADDRESSED
     // For this preliminary version of July 2019, use only the data from the 1st digit in vector. 
     /** signal masks the background */
-    if ( abs(sig_time - bkg_time) > parent->timeIntegrationWindow() && sig_time < bkg_time ) {
+    else if ( abs(sig_time - bkg_time) > parent->timeIntegrationWindow() && sig_time < bkg_time ) {
       // do nothing - keep baseDigit.
     }
     /** Background hit masks the signal hit */
-- 
GitLab