From 70c6eef41512de526f1c3fc7e600c89515f23d16 Mon Sep 17 00:00:00 2001 From: Jean-Francois Marchand Date: Thu, 17 Jul 2025 10:13:25 +0200 Subject: [PATCH 1/6] Adding gamma to energy --- .../CaloFutureReco/src/CaloECorrection.cpp | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp b/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp index ae4657e9797..aa655245e77 100644 --- a/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp +++ b/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp @@ -47,14 +47,14 @@ namespace { } } // namespace -class PileupMap { +class EcalMap { std::array m_constants; public: - PileupMap( const std::string& json_string ) { + EcalMap( const std::string& json_string ) { m_constants.fill( std::numeric_limits::quiet_NaN() ); - nlohmann::json pileup_mapJSON = nlohmann::json::parse( json_string ); - for ( auto const& [key, value] : pileup_mapJSON.items() ) { + nlohmann::json ecal_mapJSON = nlohmann::json::parse( json_string ); + for ( auto const& [key, value] : ecal_mapJSON.items() ) { using Gaudi::Parsers::parse; LHCb::Detector::Calo::CellID id{}; parse( id, key ).orThrow( "Unknown cell ID in the pile-up correction file" ); @@ -66,7 +66,7 @@ public: float at( LHCb::Detector::Calo::CellID id ) const { int cellID = id.index(); if ( std::isnan( m_constants[cellID] ) ) { - throw std::runtime_error{ "Requested pileup correction for cellID that was not specified in the file" }; + throw std::runtime_error{ "Requested correction for cellID that was not specified in the file" }; } return m_constants[cellID]; } @@ -104,6 +104,7 @@ namespace LHCb::Calo { // and be used transparently via the functional framework DetDesc::ConditionAccessor m_calo{ this, "DeCalo", DeCalorimeterLocation::Ecal }; DetDesc::ConditionAccessor m_offsets{ this, "CaloMaps", "EcalMaps" }; + DetDesc::ConditionAccessor m_gammas{ this, "CaloGammasMaps", "EcalGammasMaps" }; ToolHandle m_caloElectron{ this, "ElectronTool", "CaloFutureElectron" }; struct ECorrInputParams { @@ -177,7 +178,7 @@ namespace LHCb::Calo { mutable std::array m_countersAlpha = make_counters( this, " " ); ServiceHandle m_filesvc{ this, "FileAccess", "ParamFileSvc" }; - std::optional m_pileupMap; + std::optional m_pileupMap; void read_pileup_map() { auto s = m_filesvc->read( m_pileupMapName.value() ); if ( !s ) throw std::runtime_error( "No PileUpCorrections found at " + m_pileupMapName.value() ); @@ -188,6 +189,17 @@ namespace LHCb::Calo { [this]( auto& ) { if ( m_pileupMap ) read_pileup_map(); } }; + std::optional m_gammasMap; + void read_gammas_map() { + auto s = m_filesvc->read( m_gammasMapName.value() ); + if ( !s ) throw std::runtime_error( "No gammas found at " + m_gammasMapName.value() ); + m_gammasMap.emplace( *s ); + } + + Gaudi::Property m_gammasMapName{ this, "PileupMapFileName", "paramfile://data/EcalGammas.json", + [this]( auto& ) { + if ( m_gammasMap ) read_gammas_map(); + } }; }; DECLARE_COMPONENT_WITH_ID( ECorrection, "CaloFutureECorrection" ) @@ -205,17 +217,37 @@ namespace LHCb::Calo { return map; } - float computeOffset( DeCalorimeter const& calo, PileupMap const& pileupMap, Detector::Calo::CellID id, int nPV ) { + float computeOffset( DeCalorimeter const& calo, EcalMap const& pileupMap, Detector::Calo::CellID id, int nPV ) { if ( id.calo() != calo.index() ) { throw std::invalid_argument( "Wrong Calorimeter for this instance" ); } float pileupParam = pileupMap.at( id ); return pileupParam * nPV; } + + Detector::Calo::Map createGammasMap( const DeCalorimeter& caloDet ) { + Detector::Calo::Map map; + // fill the maps from the CaloFuture DetElem + for ( const auto& c : caloDet.cellParams() ) { + const auto id = c.cellID(); + if ( !caloDet.valid( id ) || id.isPin() ) continue; + map[id] = c.Gamma(); + } + return map; + } + + float computeGamma( DeCalorimeter const& calo, EcalMap const& gammasMap, Detector::Calo::CellID id ) { + if ( id.calo() != calo.index() ) { throw std::invalid_argument( "Wrong Calorimeter for this instance" ); } + float gammasParam = gammasMap.at( id ); + return gammasParam; + } + } // namespace StatusCode ECorrection::initialize() { return extends::initialize().andThen( [&] { this->addSharedConditionDerivation( { m_calo.key() }, m_offsets.key(), &createMap ); read_pileup_map(); + this->addSharedConditionDerivation( { m_calo.key() }, m_gammas.key(), &createGammasMap ); + read_gammas_map(); } ); } @@ -469,7 +501,8 @@ namespace LHCb::Calo { // Apply Ecal leakage corrections float alpha = aG * aE * aB * aX * aY; - float eCor = eEcal * alpha * gT + dT + offset; + float gamma = computeGamma( calo, *m_gammasMap, cellID ); + float eCor = eEcal * alpha * gT + dT + offset + gamma; /* DG,20190421: derivative calculation simplified by removal of SPD and PRS * -- GitLab From 3361ef024d2083c5bc13e4ad6273fed48bbf2878 Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Thu, 17 Jul 2025 08:14:16 +0000 Subject: [PATCH 2/6] pre-commit fixes patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/58897519 --- CaloFuture/CaloFutureReco/src/CaloECorrection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp b/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp index aa655245e77..598b1887fe0 100644 --- a/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp +++ b/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp @@ -189,8 +189,8 @@ namespace LHCb::Calo { [this]( auto& ) { if ( m_pileupMap ) read_pileup_map(); } }; - std::optional m_gammasMap; - void read_gammas_map() { + std::optional m_gammasMap; + void read_gammas_map() { auto s = m_filesvc->read( m_gammasMapName.value() ); if ( !s ) throw std::runtime_error( "No gammas found at " + m_gammasMapName.value() ); m_gammasMap.emplace( *s ); -- GitLab From a383a26b338e70730f642066df220fb42e3381b8 Mon Sep 17 00:00:00 2001 From: Jean-Francois Marchand Date: Thu, 17 Jul 2025 13:44:42 +0200 Subject: [PATCH 3/6] Add ApplyGammaToEnergy condition --- CaloFuture/CaloFutureReco/src/CaloECorrection.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp b/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp index 598b1887fe0..3f027c4d9c8 100644 --- a/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp +++ b/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp @@ -200,6 +200,9 @@ namespace LHCb::Calo { [this]( auto& ) { if ( m_gammasMap ) read_gammas_map(); } }; + + Gaudi::Property m_applyGammaToEnergy{ this, "ApplyGammaToEnergy", false }; + }; DECLARE_COMPONENT_WITH_ID( ECorrection, "CaloFutureECorrection" ) @@ -501,7 +504,7 @@ namespace LHCb::Calo { // Apply Ecal leakage corrections float alpha = aG * aE * aB * aX * aY; - float gamma = computeGamma( calo, *m_gammasMap, cellID ); + float gamma = m_applyGammaToEnergy ? computeGamma( calo, *m_gammasMap, cellID ) : 0; float eCor = eEcal * alpha * gT + dT + offset + gamma; /* DG,20190421: derivative calculation simplified by removal of SPD and PRS -- GitLab From 71618ce4c60584e78e74845e1594188371cb28bc Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Thu, 17 Jul 2025 11:45:29 +0000 Subject: [PATCH 4/6] pre-commit fixes patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/58908914 --- CaloFuture/CaloFutureReco/src/CaloECorrection.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp b/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp index 3f027c4d9c8..0193d07f243 100644 --- a/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp +++ b/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp @@ -201,8 +201,7 @@ namespace LHCb::Calo { if ( m_gammasMap ) read_gammas_map(); } }; - Gaudi::Property m_applyGammaToEnergy{ this, "ApplyGammaToEnergy", false }; - + Gaudi::Property m_applyGammaToEnergy{ this, "ApplyGammaToEnergy", false }; }; DECLARE_COMPONENT_WITH_ID( ECorrection, "CaloFutureECorrection" ) -- GitLab From 16b4fa2a595ebce973f83d6d224d24956103cabd Mon Sep 17 00:00:00 2001 From: Jean-Francois Marchand Date: Wed, 23 Jul 2025 11:40:42 +0200 Subject: [PATCH 5/6] Move gammas to conditions --- .../CaloFutureReco/src/CaloECorrection.cpp | 49 +++---------------- 1 file changed, 8 insertions(+), 41 deletions(-) diff --git a/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp b/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp index 0193d07f243..0e0b582f286 100644 --- a/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp +++ b/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp @@ -47,14 +47,14 @@ namespace { } } // namespace -class EcalMap { +class PileupMap { std::array m_constants; public: - EcalMap( const std::string& json_string ) { + PileupMap( const std::string& json_string ) { m_constants.fill( std::numeric_limits::quiet_NaN() ); - nlohmann::json ecal_mapJSON = nlohmann::json::parse( json_string ); - for ( auto const& [key, value] : ecal_mapJSON.items() ) { + nlohmann::json pileup_mapJSON = nlohmann::json::parse( json_string ); + for ( auto const& [key, value] : pileup_mapJSON.items() ) { using Gaudi::Parsers::parse; LHCb::Detector::Calo::CellID id{}; parse( id, key ).orThrow( "Unknown cell ID in the pile-up correction file" ); @@ -66,7 +66,7 @@ public: float at( LHCb::Detector::Calo::CellID id ) const { int cellID = id.index(); if ( std::isnan( m_constants[cellID] ) ) { - throw std::runtime_error{ "Requested correction for cellID that was not specified in the file" }; + throw std::runtime_error{ "Requested pileup correction for cellID that was not specified in the file" }; } return m_constants[cellID]; } @@ -104,7 +104,6 @@ namespace LHCb::Calo { // and be used transparently via the functional framework DetDesc::ConditionAccessor m_calo{ this, "DeCalo", DeCalorimeterLocation::Ecal }; DetDesc::ConditionAccessor m_offsets{ this, "CaloMaps", "EcalMaps" }; - DetDesc::ConditionAccessor m_gammas{ this, "CaloGammasMaps", "EcalGammasMaps" }; ToolHandle m_caloElectron{ this, "ElectronTool", "CaloFutureElectron" }; struct ECorrInputParams { @@ -178,7 +177,7 @@ namespace LHCb::Calo { mutable std::array m_countersAlpha = make_counters( this, " " ); ServiceHandle m_filesvc{ this, "FileAccess", "ParamFileSvc" }; - std::optional m_pileupMap; + std::optional m_pileupMap; void read_pileup_map() { auto s = m_filesvc->read( m_pileupMapName.value() ); if ( !s ) throw std::runtime_error( "No PileUpCorrections found at " + m_pileupMapName.value() ); @@ -189,19 +188,7 @@ namespace LHCb::Calo { [this]( auto& ) { if ( m_pileupMap ) read_pileup_map(); } }; - std::optional m_gammasMap; - void read_gammas_map() { - auto s = m_filesvc->read( m_gammasMapName.value() ); - if ( !s ) throw std::runtime_error( "No gammas found at " + m_gammasMapName.value() ); - m_gammasMap.emplace( *s ); - } - Gaudi::Property m_gammasMapName{ this, "PileupMapFileName", "paramfile://data/EcalGammas.json", - [this]( auto& ) { - if ( m_gammasMap ) read_gammas_map(); - } }; - - Gaudi::Property m_applyGammaToEnergy{ this, "ApplyGammaToEnergy", false }; }; DECLARE_COMPONENT_WITH_ID( ECorrection, "CaloFutureECorrection" ) @@ -219,37 +206,17 @@ namespace LHCb::Calo { return map; } - float computeOffset( DeCalorimeter const& calo, EcalMap const& pileupMap, Detector::Calo::CellID id, int nPV ) { + float computeOffset( DeCalorimeter const& calo, PileupMap const& pileupMap, Detector::Calo::CellID id, int nPV ) { if ( id.calo() != calo.index() ) { throw std::invalid_argument( "Wrong Calorimeter for this instance" ); } float pileupParam = pileupMap.at( id ); return pileupParam * nPV; } - - Detector::Calo::Map createGammasMap( const DeCalorimeter& caloDet ) { - Detector::Calo::Map map; - // fill the maps from the CaloFuture DetElem - for ( const auto& c : caloDet.cellParams() ) { - const auto id = c.cellID(); - if ( !caloDet.valid( id ) || id.isPin() ) continue; - map[id] = c.Gamma(); - } - return map; - } - - float computeGamma( DeCalorimeter const& calo, EcalMap const& gammasMap, Detector::Calo::CellID id ) { - if ( id.calo() != calo.index() ) { throw std::invalid_argument( "Wrong Calorimeter for this instance" ); } - float gammasParam = gammasMap.at( id ); - return gammasParam; - } - } // namespace StatusCode ECorrection::initialize() { return extends::initialize().andThen( [&] { this->addSharedConditionDerivation( { m_calo.key() }, m_offsets.key(), &createMap ); read_pileup_map(); - this->addSharedConditionDerivation( { m_calo.key() }, m_gammas.key(), &createGammasMap ); - read_gammas_map(); } ); } @@ -503,7 +470,7 @@ namespace LHCb::Calo { // Apply Ecal leakage corrections float alpha = aG * aE * aB * aX * aY; - float gamma = m_applyGammaToEnergy ? computeGamma( calo, *m_gammasMap, cellID ) : 0; + float gamma = calo.getGamma(cellID); float eCor = eEcal * alpha * gT + dT + offset + gamma; /* DG,20190421: derivative calculation simplified by removal of SPD and PRS -- GitLab From 8730b88a0901e53605ec944aa7819570454320a1 Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Wed, 23 Jul 2025 09:41:22 +0000 Subject: [PATCH 6/6] pre-commit fixes patch generated by https://gitlab.cern.ch/lhcb/Rec/-/jobs/59173511 --- CaloFuture/CaloFutureReco/src/CaloECorrection.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp b/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp index 0e0b582f286..04985dd5598 100644 --- a/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp +++ b/CaloFuture/CaloFutureReco/src/CaloECorrection.cpp @@ -188,7 +188,6 @@ namespace LHCb::Calo { [this]( auto& ) { if ( m_pileupMap ) read_pileup_map(); } }; - }; DECLARE_COMPONENT_WITH_ID( ECorrection, "CaloFutureECorrection" ) @@ -470,7 +469,7 @@ namespace LHCb::Calo { // Apply Ecal leakage corrections float alpha = aG * aE * aB * aX * aY; - float gamma = calo.getGamma(cellID); + float gamma = calo.getGamma( cellID ); float eCor = eEcal * alpha * gT + dT + offset + gamma; /* DG,20190421: derivative calculation simplified by removal of SPD and PRS -- GitLab