From 547b055b41b3a9670a9997ede2bd871743dd9571 Mon Sep 17 00:00:00 2001
From: Da Yu Tou <da.yu.tou@cern.ch>
Date: Tue, 4 Jun 2024 19:30:57 +0200
Subject: [PATCH] Update HLT1 vs HLT2 UT hits comparison

---
 ...onds_for_ut_v4r2_decoding_retinacluster.py | 19 ----
 .../compare_hlt1_hlt2_ut_hits_real_data.py    | 56 ++++++++++++
 ...mpare_hlt1_hlt2_ut_hits_with_mcchecking.py | 91 ++++++++++++++++---
 ..._hlt1_hlt2_ut_decoding_with_mcchecking.qmt |  2 +-
 ..._hlt2_ut_decoding_with_mcchecking_v4r2.qmt | 22 -----
 5 files changed, 135 insertions(+), 55 deletions(-)
 delete mode 100644 Hlt/Moore/tests/options/digi_input_and_conds_for_ut_v4r2_decoding_retinacluster.py
 create mode 100644 Hlt/RecoConf/options/compare_hlt1_hlt2_ut_hits_real_data.py
 delete mode 100644 Hlt/RecoConf/tests/qmtest/decoding.qms/compare_hlt1_hlt2_ut_decoding_with_mcchecking_v4r2.qmt

diff --git a/Hlt/Moore/tests/options/digi_input_and_conds_for_ut_v4r2_decoding_retinacluster.py b/Hlt/Moore/tests/options/digi_input_and_conds_for_ut_v4r2_decoding_retinacluster.py
deleted file mode 100644
index 9a579bb477b..00000000000
--- a/Hlt/Moore/tests/options/digi_input_and_conds_for_ut_v4r2_decoding_retinacluster.py
+++ /dev/null
@@ -1,19 +0,0 @@
-###############################################################################
-# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration           #
-#                                                                             #
-# This software is distributed under the terms of the GNU General Public      #
-# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
-#                                                                             #
-# In applying this licence, CERN does not waive the privileges and immunities #
-# granted to it by virtue of its status as an Intergovernmental Organization  #
-# or submit itself to any jurisdiction.                                       #
-###############################################################################
-from Moore import options
-from RecoConf.decoders import default_ft_decoding_version
-options.set_input_and_conds_from_testfiledb(
-    'upgrade-TELL40-UT-miniBias_retinacluster')
-default_ft_decoding_version.global_bind(value=6)
-
-# overwrite options for dd4hep
-options.geometry_version = "run3/trunk"
-options.conditions_version = "master"
diff --git a/Hlt/RecoConf/options/compare_hlt1_hlt2_ut_hits_real_data.py b/Hlt/RecoConf/options/compare_hlt1_hlt2_ut_hits_real_data.py
new file mode 100644
index 00000000000..c5c1224ce95
--- /dev/null
+++ b/Hlt/RecoConf/options/compare_hlt1_hlt2_ut_hits_real_data.py
@@ -0,0 +1,56 @@
+###############################################################################
+# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration           #
+#                                                                             #
+# This software is distributed under the terms of the GNU General Public      #
+# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   #
+#                                                                             #
+# In applying this licence, CERN does not waive the privileges and immunities #
+# granted to it by virtue of its status as an Intergovernmental Organization  #
+# or submit itself to any jurisdiction.                                       #
+###############################################################################
+from PyConf.Algorithms import GaudiAllenTransformAllenRecUTHits, CompareRecAllenUTHits
+from PyConf.application import configure_input, configure
+from PyConf.control_flow import CompositeNode, NodeLogic
+from Allen.config import setup_allen_non_event_data_service
+from AllenCore.generator import get_constants
+from AllenConf.ut_reconstruction import decode_ut
+from RecoConf.legacy_rec_hlt1_tracking import make_PrStorePrUTHits_hits
+from Moore import options
+
+# from Gaudi.Configuration import DEBUG
+# options.output_level = DEBUG
+
+config = configure_input(options)
+non_event_data_node = setup_allen_non_event_data_service(bank_types=["UT"])
+
+max_cluster_size = 128
+
+# Get Allen constants for UT hits dxdy
+constants = get_constants()
+
+allen_decoded_ut = decode_ut(
+    cluster_ut_hits=True,
+    position_method=0,  # AdcWeighting
+    max_cluster_size=max_cluster_size)
+
+rec_ut_hits = make_PrStorePrUTHits_hits(
+    isCluster=True, positionMethod="AdcWeighting", stripMax=max_cluster_size)
+
+transformed_ut_hits = GaudiAllenTransformAllenRecUTHits(
+    ut_hit_offsets=allen_decoded_ut["dev_ut_hit_offsets"],
+    ut_hits=allen_decoded_ut["dev_ut_hits"],
+    UTHitsLocation=rec_ut_hits,
+    allen_constants=constants)
+
+compare_allen_rec_hits = CompareRecAllenUTHits(
+    allen_ut_hits=transformed_ut_hits.allen_ut_hits,
+    rec_ut_hits=transformed_ut_hits.rec_ut_hits,
+    WeightingMethod="Adc",
+    MaxClusterSize=max_cluster_size)
+
+cf_node = CompositeNode(
+    'compare_ut_hits',
+    combine_logic=NodeLogic.NONLAZY_OR,
+    children=[non_event_data_node, compare_allen_rec_hits],
+    force_order=True)
+config.update(configure(options, cf_node))
diff --git a/Hlt/RecoConf/options/compare_hlt1_hlt2_ut_hits_with_mcchecking.py b/Hlt/RecoConf/options/compare_hlt1_hlt2_ut_hits_with_mcchecking.py
index 4b2c14830ea..acdd2c96c1b 100644
--- a/Hlt/RecoConf/options/compare_hlt1_hlt2_ut_hits_with_mcchecking.py
+++ b/Hlt/RecoConf/options/compare_hlt1_hlt2_ut_hits_with_mcchecking.py
@@ -8,31 +8,96 @@
 # granted to it by virtue of its status as an Intergovernmental Organization  #
 # or submit itself to any jurisdiction.                                       #
 ###############################################################################
-from PyConf.Algorithms import CompareRecAllenUTHitsMCCheck
+from PyConf.Algorithms import GaudiAllenTransformAllenRecUTHits, MCCheckRecAllenUTHits, CompareRecAllenUTHits
 from PyConf.application import configure_input, configure
 from PyConf.control_flow import CompositeNode, NodeLogic
 from Allen.config import setup_allen_non_event_data_service
+from AllenCore.generator import get_constants
 from AllenConf.ut_reconstruction import decode_ut
 from RecoConf.data_from_file import mc_unpackers
 from RecoConf.legacy_rec_hlt1_tracking import make_PrStorePrUTHits_hits
 from Moore import options
 
+# from Gaudi.Configuration import DEBUG
+# options.output_level = DEBUG
+
 config = configure_input(options)
 non_event_data_node = setup_allen_non_event_data_service(bank_types=["UT"])
-allen_decoded_ut = decode_ut()
 
-with make_PrStorePrUTHits_hits.bind(isCluster=False):
-    rec_ut_hits = make_PrStorePrUTHits_hits()
+# 0 = AdcWeighting, 1 = GeoWeighting for Allen
+settings = [("Adc", "AdcWeighting", 0, 4), ("Adc", "AdcWeighting", 0, 128),
+            ("Geo", "GeoWeighting", 1, 4), ("Geo", "GeoWeighting", 1, 128)]
+
+test_hits_nodes = list()
+# Get Allen constants for UT hits dxdy
+constants = get_constants()
+for weighting_method, rec_weighting, allen_weighting, max_cluster_size in settings:
+    allen_decoded_ut = decode_ut(
+        cluster_ut_hits=True,
+        position_method=allen_weighting,
+        max_cluster_size=max_cluster_size)
 
-    test_hits = CompareRecAllenUTHitsMCCheck(
+    rec_ut_hits = make_PrStorePrUTHits_hits(
+        isCluster=True,
+        positionMethod=rec_weighting,
+        stripMax=max_cluster_size)
+
+    transformed_ut_hits = GaudiAllenTransformAllenRecUTHits(
         ut_hit_offsets=allen_decoded_ut["dev_ut_hit_offsets"],
         ut_hits=allen_decoded_ut["dev_ut_hits"],
+        UTHitsLocation=rec_ut_hits,
+        allen_constants=constants)
+
+    mc_check_hits = MCCheckRecAllenUTHits(
+        allen_ut_hits=transformed_ut_hits.allen_ut_hits,
+        rec_ut_hits=transformed_ut_hits.rec_ut_hits,
+        allen_constants=constants,
+        rec_ut_dxdys=transformed_ut_hits.rec_ut_dxdys,
         UnpackedUTHits=mc_unpackers()['MCUTHits'],
-        UTHitsLocation=rec_ut_hits)
-
-    cf_node = CompositeNode(
-        'compare_ut_hits_with_mcchecking',
-        combine_logic=NodeLogic.NONLAZY_OR,
-        children=[non_event_data_node, test_hits],
-        force_order=True)
-    config.update(configure(options, cf_node))
+        WeightingMethod=weighting_method,
+        MaxClusterSize=max_cluster_size)
+
+    compare_allen_rec_hits = CompareRecAllenUTHits(
+        allen_ut_hits=transformed_ut_hits.allen_ut_hits,
+        rec_ut_hits=transformed_ut_hits.rec_ut_hits,
+        WeightingMethod=weighting_method,
+        MaxClusterSize=max_cluster_size)
+
+    test_hits_nodes.append(mc_check_hits)
+    test_hits_nodes.append(compare_allen_rec_hits)
+
+# No clustering checker
+
+allen_decoded_ut = decode_ut(cluster_ut_hits=False)
+rec_ut_hits = make_PrStorePrUTHits_hits(isCluster=False)
+
+transformed_ut_hits = GaudiAllenTransformAllenRecUTHits(
+    ut_hit_offsets=allen_decoded_ut["dev_ut_hit_offsets"],
+    ut_hits=allen_decoded_ut["dev_ut_hits"],
+    UTHitsLocation=rec_ut_hits,
+    allen_constants=constants)
+
+mc_check_hits = MCCheckRecAllenUTHits(
+    allen_ut_hits=transformed_ut_hits.allen_ut_hits,
+    rec_ut_hits=transformed_ut_hits.rec_ut_hits,
+    rec_ut_dxdys=transformed_ut_hits.rec_ut_dxdys,
+    allen_constants=constants,
+    UnpackedUTHits=mc_unpackers()['MCUTHits'],
+    WeightingMethod="No",
+    MaxClusterSize="1")
+
+compare_allen_rec_hits = CompareRecAllenUTHits(
+    allen_ut_hits=transformed_ut_hits.allen_ut_hits,
+    rec_ut_hits=transformed_ut_hits.rec_ut_hits,
+    WeightingMethod="No",
+    MaxClusterSize="1")
+
+test_hits_nodes.append(mc_check_hits)
+test_hits_nodes.append(compare_allen_rec_hits)
+
+cf_node = CompositeNode(
+    'compare_ut_hits_with_mcchecking',
+    combine_logic=NodeLogic.NONLAZY_OR,
+    children=[non_event_data_node] + test_hits_nodes,
+    force_order=True)
+config.update(configure(options, cf_node))
diff --git a/Hlt/RecoConf/tests/qmtest/decoding.qms/compare_hlt1_hlt2_ut_decoding_with_mcchecking.qmt b/Hlt/RecoConf/tests/qmtest/decoding.qms/compare_hlt1_hlt2_ut_decoding_with_mcchecking.qmt
index 84fc8ebe2cf..e53e0063f7f 100644
--- a/Hlt/RecoConf/tests/qmtest/decoding.qms/compare_hlt1_hlt2_ut_decoding_with_mcchecking.qmt
+++ b/Hlt/RecoConf/tests/qmtest/decoding.qms/compare_hlt1_hlt2_ut_decoding_with_mcchecking.qmt
@@ -12,7 +12,7 @@
 <extension class="GaudiTest.GaudiExeTest" kind="test">
   <argument name="program"><text>gaudirun.py</text></argument>
   <argument name="args"><set>
-    <text>$MOOREROOT/tests/options/digi_input_and_conds_Sim10aU1.py</text>
+    <text>$MOOREROOT/tests/options/default_input_and_conds_hlt1.py</text>
     <text>$RECOCONFROOT/options/compare_hlt1_hlt2_ut_hits_with_mcchecking.py</text>
   </set></argument>
   <argument name="validator"><text>
diff --git a/Hlt/RecoConf/tests/qmtest/decoding.qms/compare_hlt1_hlt2_ut_decoding_with_mcchecking_v4r2.qmt b/Hlt/RecoConf/tests/qmtest/decoding.qms/compare_hlt1_hlt2_ut_decoding_with_mcchecking_v4r2.qmt
deleted file mode 100644
index b49b33df401..00000000000
--- a/Hlt/RecoConf/tests/qmtest/decoding.qms/compare_hlt1_hlt2_ut_decoding_with_mcchecking_v4r2.qmt
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" ?><!DOCTYPE extension  PUBLIC '-//QM/2.3/Extension//EN'  'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'>
-<!--
-    (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration
-
-    This software is distributed under the terms of the GNU General Public
-    Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".
-
-    In applying this licence, CERN does not waive the privileges and immunities
-    granted to it by virtue of its status as an Intergovernmental Organization
-    or submit itself to any jurisdiction.
--->
-<extension class="GaudiTest.GaudiExeTest" kind="test">
-  <argument name="program"><text>gaudirun.py</text></argument>
-  <argument name="args"><set>
-    <text>$MOOREROOT/tests/options/digi_input_and_conds_for_ut_v4r2_decoding_retinacluster.py</text>
-    <text>$RECOCONFROOT/options/compare_hlt1_hlt2_ut_hits_with_mcchecking.py</text>
-  </set></argument>
-  <argument name="use_temp_dir"><enumeral>true</enumeral></argument>
-  <argument name="validator"><text>
-countErrorLines({"FATAL": 0, "ERROR": 0, "WARNING": 0})
-  </text></argument>
-</extension>
-- 
GitLab