From e220b68e94ac7608253a4c5c0cd116b66d71d111 Mon Sep 17 00:00:00 2001
From: "P.-A. Loizeau" <p.-a.loizeau@gsi.de>
Date: Tue, 13 Feb 2024 13:52:24 +0100
Subject: [PATCH] [CI][GEOM] Disable sampling part of overlap check macro

- Make overlap threshold optional input parameter (default = 0.0001 as before)
- Make sampling controllable by flag (disabled by default)
- Make number of samples in sampling mode controllable by input par (default = 0 leading to ROOT default of 1M)

Two problems from ROOT side lead to it being unrelyable for now
- Threshold is not working in this method
- Changing the number of samples lead to really small overlaps apearing and disappearing

See https://github.com/root-project/root/issues/14675 for reference
---
 macro/geometry/check_overlaps.C | 42 ++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git a/macro/geometry/check_overlaps.C b/macro/geometry/check_overlaps.C
index 92a1d32a6b..5ff4476d32 100644
--- a/macro/geometry/check_overlaps.C
+++ b/macro/geometry/check_overlaps.C
@@ -287,7 +287,8 @@ bool expected_cbm_sampling(TGeoOverlap* ov)
   return false;
 }
 
-void check_overlaps(TString dataset = "test", TString alignment_matrices = "")
+void check_overlaps(TString dataset = "test", TString alignment_matrices = "", Double_t dThr = 0.0001,
+                    bool bTestsampling = false, uint32_t uSamplesNb = 0)
 {
   // 2014-07-04 - DE  - test CBM setups for collisions in nightly tests
   // 2014-07-04 - DE  - currently there are 2 overlaps between the PIPE and STS layer 8
@@ -339,7 +340,7 @@ void check_overlaps(TString dataset = "test", TString alignment_matrices = "")
     }
   }
 
-  gGeoManager->CheckOverlaps(0.0001);
+  gGeoManager->CheckOverlaps(dThr);
   TIter next(gGeoManager->GetListOfOverlaps());
   TGeoOverlap* ov;
   while ((ov = (TGeoOverlap*) next())) {
@@ -359,28 +360,35 @@ void check_overlaps(TString dataset = "test", TString alignment_matrices = "")
   std::cout << std::endl;
 
   /*
-   * Commented the sampling part of the check as its threshold is broken
+   * Disabled by defaults the sampling part of the check as its threshold is broken
    * For explanation see
    * - https://git.cbm.gsi.de/computing/cbmroot/-/merge_requests/1639
    * - https://github.com/root-project/root/issues/14675
-  //                       Threshold | N Samples
-  gGeoManager->CheckOverlaps(0.0001, "s2000000");
-  TIter next1(gGeoManager->GetListOfOverlaps());
-  while ((ov = (TGeoOverlap*) next1())) {
-
-    if ((dataset.Contains("mcbm") && expected_mcbm_sampling(ov)) || expected_cbm_sampling(ov)) {
-      /// Detected and logged in special function above
-      continue;
+   * - https://redmine.cbm.gsi.de/issues/3198
+   */
+  if (bTestsampling) {
+    //                       Threshold | N Samples
+    if (0 < uNbSamples) {
+      gGeoManager->CheckOverlaps(dThr, Form("s%u", uNbSamples));
     }
     else {
-      std::cout << "Unexpected Overlap (sampled):" << std::endl;
-      ov->PrintInfo();
-      std::cout << std::endl;
-      unexpectedOverlaps++;
+      gGeoManager->CheckOverlaps(dThr, "s");
     }
+    TIter next1(gGeoManager->GetListOfOverlaps());
+    while ((ov = (TGeoOverlap*) next1())) {
+      if ((dataset.Contains("mcbm") && expected_mcbm_sampling(ov)) || expected_cbm_sampling(ov)) {
+        /// Detected and logged in special function above
+        continue;
+      }
+      else {
+        std::cout << "Unexpected Overlap (sampled):" << std::endl;
+        ov->PrintInfo();
+        std::cout << std::endl;
+        unexpectedOverlaps++;
+      }
+    }
+    std::cout << std::endl;
   }
-  std::cout << std::endl;
-  */
 
   if (unexpectedOverlaps != 0) {
     std::cout << " Test failed" << std::endl;
-- 
GitLab