From a89467cdeb4f0af6a3175026dc002bf8f5aad73c Mon Sep 17 00:00:00 2001
From: Maarten Van Veghel <mveghel@cern.ch>
Date: Mon, 19 Dec 2022 09:53:11 +0100
Subject: [PATCH 1/3] fix track-cell intersection scan

---
 .../CaloFuturePIDs/src/TrackToCaloEnergyAlgs.cpp  | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/CaloFuture/CaloFuturePIDs/src/TrackToCaloEnergyAlgs.cpp b/CaloFuture/CaloFuturePIDs/src/TrackToCaloEnergyAlgs.cpp
index 4322235726e..d51940b76b5 100644
--- a/CaloFuture/CaloFuturePIDs/src/TrackToCaloEnergyAlgs.cpp
+++ b/CaloFuture/CaloFuturePIDs/src/TrackToCaloEnergyAlgs.cpp
@@ -40,15 +40,23 @@ namespace LHCb::Calo {
     float getEnergy( LHCb::StateVector const& state, CaloDigits const& digits, DeCalorimeter const& calo,
                      float const deltaZ, int const nPlanes ) {
       float energy = 0.f;
+      // cellid bookkeeping
+      auto prev_cellid = LHCb::Detector::Calo::CellID();
       // scan at different planes in the calo
       auto       position = state.position();
       auto const slopes   = state.slopes();
       for ( int i = 0; i < nPlanes; ++i ) {
         const auto cell = calo.Cell_( position );
         if ( !cell || !cell->valid() ) continue;
-        const auto digit = digits( cell->cellID() );
+        // check if it is the same as last one
+        auto cellid = cell->cellID();
+        if ( prev_cellid == cellid ) continue;
+        // if not, add energy
+        const auto digit = digits( cellid );
         if ( digit ) energy += digit->energy();
+        // next position
         position += deltaZ * slopes;
+        prev_cellid = cellid;
       }
       return energy;
     }
@@ -116,14 +124,14 @@ namespace LHCb::Calo {
     // miscellaneous info
     LHCb::StateVector calo_state;
     auto const        calo_front = calo.plane( CaloPlane::Front );
-    float const       calo_zsize = calo.zSize();
+    float const       calo_dz    = calo.zSize() / ( m_nplanes > 1 ? m_nplanes - 1 : m_nplanes.value() );
 
     // loop over input tracks
     for ( auto const& trackincalo : tracksincalo.scalar() ) {
       auto track     = trackincalo.from();
       auto ref_state = track.state( state_loc.value() );
       if ( !propagateToCalo( calo_state, ref_state, calo_front ) ) continue;
-      float energy = getEnergy( calo_state, digits, calo, calo_zsize, m_nplanes );
+      float energy = getEnergy( calo_state, digits, calo, calo_dz, m_nplanes );
       // save result for this index in tracks
       output_table.add( track, energy );
       // statistics
@@ -153,6 +161,7 @@ namespace LHCb::Calo {
         : TrackToCaloEnergyAlg<TracksInHcal, TracksHcalEnergy>( name, pSvc ) {
       updateHandleLocation( *this, "Calorimeter", CaloFutureAlgUtils::DeCaloFutureLocation( "Hcal" ) );
       updateHandleLocation( *this, "Digits", CaloDigitLocation::Hcal );
+      setProperty( "nPlanes", 5 ).ignore();
     }
   };
 
-- 
GitLab


From 09a624199b82744487cf630894d68105daf67a61 Mon Sep 17 00:00:00 2001
From: Maarten Van Veghel <mveghel@cern.ch>
Date: Tue, 20 Dec 2022 14:38:19 +0100
Subject: [PATCH 2/3] index consistency fix

---
 CaloFuture/CaloFuturePIDs/src/AcceptanceCaloAlgs.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/CaloFuture/CaloFuturePIDs/src/AcceptanceCaloAlgs.cpp b/CaloFuture/CaloFuturePIDs/src/AcceptanceCaloAlgs.cpp
index b1495e26b1c..21a3cfbda5f 100644
--- a/CaloFuture/CaloFuturePIDs/src/AcceptanceCaloAlgs.cpp
+++ b/CaloFuture/CaloFuturePIDs/src/AcceptanceCaloAlgs.cpp
@@ -52,7 +52,7 @@ namespace LHCb::Calo {
     int acceptance( LHCb::StateVector& state, MyState const& ref_state, DeCalorimeter const& calo,
                     Gaudi::Plane3D const& plane, bool const fiducial ) {
       // linear extrapolation to calo
-      if ( !propagateToCalo<MyState>( state, ref_state, plane ) ) return 0;
+      if ( !propagateToCalo( state, ref_state, plane ) ) return 0;
       // check position
       const auto cell = calo.Cell_( state.position() );
       if ( !cell || !cell->valid() ) { return 0; }
@@ -65,7 +65,7 @@ namespace LHCb::Calo {
       // incomplete neibours: border of 2 zones ?
       return std::any_of( std::next( neighbours.begin() ), neighbours.end(),
                           [area = cell->cellID().area()]( const auto& n ) { return n.area() != area; } )
-                 ? LHCb::Detector::Calo::Index{cell->cellID()}
+                 ? cell->cellID().all()
                  : 0;
     }
 
-- 
GitLab


From 38a95dbb057d57d3a23fe1c0521842e12e6884ed Mon Sep 17 00:00:00 2001
From: Maarten Van Veghel <mveghel@cern.ch>
Date: Fri, 6 Jan 2023 15:18:53 +0100
Subject: [PATCH 3/3] updated pid table locs

---
 CaloFuture/CaloFuturePIDs/src/CaloChargedBremAlg.cpp | 6 +++---
 CaloFuture/CaloFuturePIDs/src/CaloChargedPIDsAlg.cpp | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/CaloFuture/CaloFuturePIDs/src/CaloChargedBremAlg.cpp b/CaloFuture/CaloFuturePIDs/src/CaloChargedBremAlg.cpp
index 59bac044e48..a614abfe8c8 100644
--- a/CaloFuture/CaloFuturePIDs/src/CaloChargedBremAlg.cpp
+++ b/CaloFuture/CaloFuturePIDs/src/CaloChargedBremAlg.cpp
@@ -50,9 +50,9 @@ namespace LHCb::Calo {
     // DLL parametrization locations
     Gaudi::Property<std::string> m_histo_location{this, "HistLocation", "",
                                                   "Histogram location for histoSvc/ParamFiles"};
-    Gaudi::Property<std::string> m_paramfiles_location{this, "ParamFilesLocation",
-                                                       "paramfile://data/CaloPID/DLLs_parametrization_histograms.root",
-                                                       "Location of ROOT file for charged calo PID DLL histograms"};
+    Gaudi::Property<std::string> m_paramfiles_location{
+        this, "ParamFilesLocation", "paramfile://data/CaloPID/DLLs_parametrization_histograms_122022.root",
+        "Location of ROOT file for charged calo PID DLL histograms"};
 
     ServiceHandle<IFileAccess> m_file{this, "FileAccessor", "ParamFileSvc", "Service used to retrieve file contents"};
     // DLL histograms
diff --git a/CaloFuture/CaloFuturePIDs/src/CaloChargedPIDsAlg.cpp b/CaloFuture/CaloFuturePIDs/src/CaloChargedPIDsAlg.cpp
index 432d1809a88..5ce8fac579b 100644
--- a/CaloFuture/CaloFuturePIDs/src/CaloChargedPIDsAlg.cpp
+++ b/CaloFuture/CaloFuturePIDs/src/CaloChargedPIDsAlg.cpp
@@ -44,9 +44,9 @@ namespace LHCb::Calo {
     // DLL parametrization locations
     Gaudi::Property<std::string> m_histo_location{this, "HistLocation", "",
                                                   "Histogram location for histoSvc/ParamFiles"};
-    Gaudi::Property<std::string> m_paramfiles_location{this, "ParamFilesLocation",
-                                                       "paramfile://data/CaloPID/DLLs_parametrization_histograms.root",
-                                                       "Location of ROOT file for charged calo PID DLL histograms"};
+    Gaudi::Property<std::string> m_paramfiles_location{
+        this, "ParamFilesLocation", "paramfile://data/CaloPID/DLLs_parametrization_histograms_122022.root",
+        "Location of ROOT file for charged calo PID DLL histograms"};
 
     ServiceHandle<IFileAccess> m_file{this, "FileAccessor", "ParamFileSvc", "Service used to retrieve file contents"};
     // DLL histograms
-- 
GitLab