From a3afbc4ebd743e373dc39794ccb36349fcba0fb2 Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Fri, 8 Nov 2024 03:58:50 +0100
Subject: [PATCH] bugfix: kf::MaterialMap::Add() function

---
 algo/kf/core/geo/KfMaterialMap.cxx  | 8 ++++----
 algo/kf/core/geo/KfModuleIndexMap.h | 2 +-
 algo/kf/core/geo/KfSetup.h          | 2 --
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/algo/kf/core/geo/KfMaterialMap.cxx b/algo/kf/core/geo/KfMaterialMap.cxx
index 2307b2bcec..d247ba806d 100644
--- a/algo/kf/core/geo/KfMaterialMap.cxx
+++ b/algo/kf/core/geo/KfMaterialMap.cxx
@@ -59,20 +59,20 @@ void MaterialMap::Add(const MaterialMap& other, float zTarg)
   const auto stepSize{binSize / static_cast<float>(nRays)};             // Step between two neighboring rays [cm]
 
   // The coordinates of the first ray intersection with the other material layer [cm]
-  float xBinOther{-this->fXYmax * scaleFactor + stepSize * 0.5F};
-  float yBinOther{xBinOther};
+  float yBinOther{-this->fXYmax * scaleFactor + stepSize * 0.5F};
 
   // Loop over bins of the active (this)
   for (int iBinY{0}; iBinY < this->fNbins; ++iBinY) {
+    float xBinOther{-this->fXYmax * scaleFactor + stepSize * 0.5F};
     for (int iBinX{0}; iBinX < this->fNbins; ++iBinX) {
       // Collect material using ray shooting
       float avgThickness{0};  // Collected average thickness
       for (int iRayY{0}; iRayY < nRays; ++iRayY) {
         for (int iRayX{0}; iRayX < nRays; ++iRayX) {
-          avgThickness += other.GetThickness(xBinOther + iBinX * stepSize, yBinOther + iBinY * stepSize);
+          avgThickness += other.GetThicknessX0(xBinOther + iRayX * stepSize, yBinOther + iRayY * stepSize);
         }
       }
-      this->fTable[iBinX + this->fNbins * iBinY] += avgThickness / (nRays * nRays);
+      this->fTable[iBinX + this->fNbins * iBinY] += (avgThickness / (nRays * nRays));
       xBinOther += binSize;
     }
     yBinOther += binSize;
diff --git a/algo/kf/core/geo/KfModuleIndexMap.h b/algo/kf/core/geo/KfModuleIndexMap.h
index 66b1cdb489..2c54385cf7 100644
--- a/algo/kf/core/geo/KfModuleIndexMap.h
+++ b/algo/kf/core/geo/KfModuleIndexMap.h
@@ -147,7 +147,7 @@ namespace cbm::algo::kf
     }
 
     auto& iGlbDsbl = fvLocToGlb[fvDetLocOffset[iDetIntDsbl] + locIdDisable];
-    if (iGlbDsbl == -1) {
+    if (iGlbDsbl < 0) {
       return;  // Nothing to disable, component is already inactive
     }
 
diff --git a/algo/kf/core/geo/KfSetup.h b/algo/kf/core/geo/KfSetup.h
index 23823a4248..6789ab37ba 100644
--- a/algo/kf/core/geo/KfSetup.h
+++ b/algo/kf/core/geo/KfSetup.h
@@ -132,14 +132,12 @@ namespace cbm::algo::kf
   void Setup<T>::DisableLayer(EDetID iDet, int iLoc)
   {
     int iLayer{fModuleIndexMap.LocalToGlobal(iDet, iLoc)};
-    std::cout << "Disabling layer: iDet = " << static_cast<int>(iDet) << ", iLoc = " << iLoc << ", iLayer = " << iLayer << '\n';
     if (iLayer == -1) {
       return;
     }
 
     // Remove material layer and add it to the next one
     if (iLayer < static_cast<int>(fvMaterialLayers.size() - 1)) {
-      std::cout << " -- adding layer " << iLayer << " to layer " << iLayer + 1 << " with z = " << fvMaterialLayers[iLayer + 1].GetZref() << '\n';
       fvMaterialLayers[iLayer + 1].Add(fvMaterialLayers[iLayer], utils::simd::Cast<T, float>(fTarget.GetZ()));
     }
     fvMaterialLayers.erase(fvMaterialLayers.begin() + iLayer);
-- 
GitLab