From 89ff1cdaa520837ad6facdc964eb28ae11f81f18 Mon Sep 17 00:00:00 2001 From: Laurent Dufour Date: Wed, 22 Jan 2025 16:59:55 +0100 Subject: [PATCH 1/4] Changes --- CMakeLists.txt | 1 + Detector/LHCb/include/Detector/LHCb/DeLHCb.h | 16 ++++- .../LHCb/VPGlobalCoordinateTransform.h | 33 +++++++++ Detector/LHCb/src/DeLHCb.cpp | 17 +++++ .../LHCb/src/VPGlobalCoordinateTransform.cpp | 70 +++++++++++++++++++ Detector/VP/include/Detector/VP/DeVP.h | 5 ++ 6 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 Detector/LHCb/include/Detector/LHCb/VPGlobalCoordinateTransform.h create mode 100644 Detector/LHCb/src/VPGlobalCoordinateTransform.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a858022620..b192dde8fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,6 +119,7 @@ add_library(DetectorLib SHARED Detector/LHCb/src/DeLHCb.cpp Detector/LHCb/src/DeLHCbHandles.cpp Detector/LHCb/src/InteractionRegion.cpp + Detector/LHCb/src/VPGlobalCoordinateTransform.cpp Detector/LHCb/src/SMOGInfo.cpp Detector/LHCb/src/Tell40Links.cpp Detector/LHCb/src/LHCInfo.cpp diff --git a/Detector/LHCb/include/Detector/LHCb/DeLHCb.h b/Detector/LHCb/include/Detector/LHCb/DeLHCb.h index 4e5102ab55..a463102479 100644 --- a/Detector/LHCb/include/Detector/LHCb/DeLHCb.h +++ b/Detector/LHCb/include/Detector/LHCb/DeLHCb.h @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -32,9 +33,10 @@ namespace LHCb::Detector { void applyToAllChildren( const std::function )>& ) const override; std::vector children; Tell40Links m_tell40links; - std::optional m_interactionRegion; - std::optional m_lhcinfo; - std::optional m_SMOG; + std::optional m_interactionRegion; + std::optional m_lhcinfo; + std::optional m_SMOG; + std::optional m_vpCoordinateTransform; }; // Utility method to lookup DeIOV object from the condition slice @@ -53,6 +55,14 @@ namespace LHCb::Detector { std::optional lhcInfo() const { return this->access()->m_lhcinfo; } // Provides the SMOG injection type, the injected gas and the injection stability const std::optional SMOG() const { return this->access()->m_SMOG; } + + // Offline calibration conditions + + // Transforms related to the VELO, which affect the vertex positions, + // and all positions downstream, after re-aligning + std::optional vpGlobalCoordinateTransformation() const { + return this->access()->m_vpCoordinateTransform; + } }; // Utility method to setup DeLHCb diff --git a/Detector/LHCb/include/Detector/LHCb/VPGlobalCoordinateTransform.h b/Detector/LHCb/include/Detector/LHCb/VPGlobalCoordinateTransform.h new file mode 100644 index 0000000000..a9f7b0cd4d --- /dev/null +++ b/Detector/LHCb/include/Detector/LHCb/VPGlobalCoordinateTransform.h @@ -0,0 +1,33 @@ +/*****************************************************************************\ +* (c) Copyright 2024 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. * +\*****************************************************************************/ +#pragma once + +#include + +#include +#include + +/** + * This condition is only present for the offline calibration. + */ +namespace LHCb::Detector { + struct VPGlobalCoordinateTransform { + + VPGlobalCoordinateTransform() = default; + VPGlobalCoordinateTransform( const nlohmann::json& obj ); + + ROOT::Math::Translation3D oldPosition; + ROOT::Math::Translation3D newPosition; + + ROOT::Math::RotationZYX oldRotation; + ROOT::Math::RotationZYX newRotation; + }; +} // namespace LHCb::Detector diff --git a/Detector/LHCb/src/DeLHCb.cpp b/Detector/LHCb/src/DeLHCb.cpp index c35eff9584..a4479c1a6c 100644 --- a/Detector/LHCb/src/DeLHCb.cpp +++ b/Detector/LHCb/src/DeLHCb.cpp @@ -49,6 +49,13 @@ LHCb::Detector::detail::DeLHCbObject::DeLHCbObject( const dd4hep::DetElement& if ( !SMOG.is_null() ) { m_SMOG = SMOG; } } } + { + auto cond = ctxt.condition( hash_key( de, "OfflineVPGlobalCoordinateTransform" ), false ); + if ( cond.isValid() ) { + auto coordinateTransformData = cond.get(); + if ( !coordinateTransformData.is_null() ) { m_vpCoordinateTransform = coordinateTransformData; } + } + } } void LHCb::Detector::detail::DeLHCbObject::applyToAllChildren( @@ -137,6 +144,16 @@ void LHCb::Detector::setup_DeLHCb_callback( dd4hep::Detector& description ) { depbuilder.add( hash_key( de, "InteractionRegion" ) ); } + // read possible offline coordinate transformations, if needed + if ( !schema || schema->has( "Conditions/LHCb/OfflineCalib/OfflineVPGlobalCoordinateTransform.yml", + "OfflineVPGlobalCoordinateTransform" ) ) { + ( *requests ) + ->addLocation( de, LHCb::Detector::item_key( "OfflineVPGlobalCoordinateTransform" ), + "Conditions/LHCb/OfflineCalib/OfflineVPGlobalCoordinateTransform.yml", + "OfflineVPGlobalCoordinateTransform" ); + depbuilder.add( hash_key( de, "OfflineVPGlobalCoordinateTransform" ) ); + } + if ( !schema || schema->has( "Conditions/LHCb/Online/LHC.yml", "LHC" ) ) { ( *requests )->addLocation( de, LHCb::Detector::item_key( "LHC" ), "Conditions/LHCb/Online/LHC.yml", "LHC" ); depbuilder.add( hash_key( de, "LHC" ) ); diff --git a/Detector/LHCb/src/VPGlobalCoordinateTransform.cpp b/Detector/LHCb/src/VPGlobalCoordinateTransform.cpp new file mode 100644 index 0000000000..360b451130 --- /dev/null +++ b/Detector/LHCb/src/VPGlobalCoordinateTransform.cpp @@ -0,0 +1,70 @@ +/*****************************************************************************\ +* (c) Copyright 2024 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. * +\*****************************************************************************/ +#include + +#include + +#include +#include + +#include + +template +std::array arrayFromJson( const nlohmann::json& jsonArray, const double unit ) { + if ( jsonArray.size() != Size ) { throw std::runtime_error{"Condition array is not of expected size"}; } + + std::array values; + + for ( std::size_t i{0}; i < Size; ++i ) { + if ( jsonArray[i].is_string() ) { + values[i] = dd4hep::_toDouble( jsonArray[i].get() ); + } else if ( jsonArray[i].is_number() ) { + values[i] = jsonArray[i].get() * unit; + } else { + throw std::runtime_error{"Condition contains unexpected types"}; + } + } + + return values; +} + +LHCb::Detector::VPGlobalCoordinateTransform::VPGlobalCoordinateTransform( const nlohmann::json& obj ) { + if ( !obj.contains( "oldPosition" ) || !obj.contains( "oldRotation" ) ) { + throw std::runtime_error{ + "Could not find old position & rotation information - are you running the latest version of the software?"}; + } + + if ( !obj.contains( "newPosition" ) || !obj.contains( "newRotation" ) ) { + throw std::runtime_error{"VPGlobalCoordinateTrransform condition is empty"}; + } + + constexpr std::size_t posSize{3}; + constexpr std::size_t rotationSize{3}; + + auto& newPos = obj.at( "newPosition" ); + std::array newPosVals{arrayFromJson( newPos, dd4hep::mm )}; + + auto& oldPos = obj.at( "oldPosition" ); + std::array oldPosVals{arrayFromJson( oldPos, dd4hep::mm )}; + + auto& newRotationData = obj.at( "newRotation" ); + std::array newRotationVals{arrayFromJson( newRotationData, dd4hep::radian )}; + + auto& oldRotationData = obj.at( "oldRotation" ); + std::array oldRotationVals{arrayFromJson( oldRotationData, dd4hep::radian )}; + + oldPosition.SetComponents( oldPosVals.begin(), oldPosVals.end() ); + newPosition.SetComponents( newPosVals.begin(), newPosVals.end() ); + + // The order in the yaml is RX RY RZ - mind the 'rbegin' and 'rend'! + oldRotation.SetComponents( oldRotationVals.rbegin(), oldRotationVals.rend() ); + newRotation.SetComponents( newRotationVals.rbegin(), newRotationVals.rend() ); +} diff --git a/Detector/VP/include/Detector/VP/DeVP.h b/Detector/VP/include/Detector/VP/DeVP.h index f8d7e33568..a81677db9a 100644 --- a/Detector/VP/include/Detector/VP/DeVP.h +++ b/Detector/VP/include/Detector/VP/DeVP.h @@ -12,6 +12,7 @@ #include "Core/DeIOV.h" #include "Core/Keys.h" +#include "Core/Units.h" #include "Detector/VP/DeVPSensor.h" #include @@ -158,6 +159,10 @@ namespace LHCb::Detector { return this->access()->sensitiveVolumeID( point ); } + auto getGlobalTransform() const { + return detail::toLHCbLengthUnits( this->access()->detectorAlignment().worldTransformation() ); + } + /// Return pointer to sensor for a given sensor number. const DeVPSensor sensor( VPChannelID id ) const { return sensor( id.sensor() ); } -- GitLab From 36ff4df35ddc53ff23edb0ab83e8bf4902a05425 Mon Sep 17 00:00:00 2001 From: Laurent Dufour Date: Wed, 22 Jan 2025 23:46:28 +0100 Subject: [PATCH 2/4] Updated transform --- .../Detector/LHCb/VPGlobalCoordinateTransform.h | 5 ++--- Detector/LHCb/src/VPGlobalCoordinateTransform.cpp | 13 +++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Detector/LHCb/include/Detector/LHCb/VPGlobalCoordinateTransform.h b/Detector/LHCb/include/Detector/LHCb/VPGlobalCoordinateTransform.h index a9f7b0cd4d..04672c7edc 100644 --- a/Detector/LHCb/include/Detector/LHCb/VPGlobalCoordinateTransform.h +++ b/Detector/LHCb/include/Detector/LHCb/VPGlobalCoordinateTransform.h @@ -25,9 +25,8 @@ namespace LHCb::Detector { VPGlobalCoordinateTransform( const nlohmann::json& obj ); ROOT::Math::Translation3D oldPosition; - ROOT::Math::Translation3D newPosition; - ROOT::Math::RotationZYX oldRotation; - ROOT::Math::RotationZYX newRotation; + + bool enabled; }; } // namespace LHCb::Detector diff --git a/Detector/LHCb/src/VPGlobalCoordinateTransform.cpp b/Detector/LHCb/src/VPGlobalCoordinateTransform.cpp index 360b451130..e2b118e6dc 100644 --- a/Detector/LHCb/src/VPGlobalCoordinateTransform.cpp +++ b/Detector/LHCb/src/VPGlobalCoordinateTransform.cpp @@ -49,22 +49,19 @@ LHCb::Detector::VPGlobalCoordinateTransform::VPGlobalCoordinateTransform( const constexpr std::size_t posSize{3}; constexpr std::size_t rotationSize{3}; - auto& newPos = obj.at( "newPosition" ); - std::array newPosVals{arrayFromJson( newPos, dd4hep::mm )}; - auto& oldPos = obj.at( "oldPosition" ); std::array oldPosVals{arrayFromJson( oldPos, dd4hep::mm )}; - auto& newRotationData = obj.at( "newRotation" ); - std::array newRotationVals{arrayFromJson( newRotationData, dd4hep::radian )}; - auto& oldRotationData = obj.at( "oldRotation" ); std::array oldRotationVals{arrayFromJson( oldRotationData, dd4hep::radian )}; oldPosition.SetComponents( oldPosVals.begin(), oldPosVals.end() ); - newPosition.SetComponents( newPosVals.begin(), newPosVals.end() ); // The order in the yaml is RX RY RZ - mind the 'rbegin' and 'rend'! oldRotation.SetComponents( oldRotationVals.rbegin(), oldRotationVals.rend() ); - newRotation.SetComponents( newRotationVals.rbegin(), newRotationVals.rend() ); + + const auto& read_enabled_flag = obj.at( "enabled" ); + + // support both 'true/false' and 1 / 0 + enabled = read_enabled_flag.is_boolean() ? read_enabled_flag.get() : bool( read_enabled_flag.get() ); } -- GitLab From 7bd4e91c3fb396be5740396c0a83b6b0f0b9f0a8 Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Wed, 22 Jan 2025 22:46:49 +0000 Subject: [PATCH 3/4] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Detector/-/jobs/49726811 --- .../LHCb/include/Detector/LHCb/VPGlobalCoordinateTransform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detector/LHCb/include/Detector/LHCb/VPGlobalCoordinateTransform.h b/Detector/LHCb/include/Detector/LHCb/VPGlobalCoordinateTransform.h index 04672c7edc..6aa58b32b4 100644 --- a/Detector/LHCb/include/Detector/LHCb/VPGlobalCoordinateTransform.h +++ b/Detector/LHCb/include/Detector/LHCb/VPGlobalCoordinateTransform.h @@ -25,7 +25,7 @@ namespace LHCb::Detector { VPGlobalCoordinateTransform( const nlohmann::json& obj ); ROOT::Math::Translation3D oldPosition; - ROOT::Math::RotationZYX oldRotation; + ROOT::Math::RotationZYX oldRotation; bool enabled; }; -- GitLab From 209437e52dedb9b3bff8f8c1c3a519e0825e06cf Mon Sep 17 00:00:00 2001 From: Thomas Latham Date: Mon, 3 Feb 2025 15:18:04 +0000 Subject: [PATCH 4/4] Drop not-used DeVP::getGlobalTransform --- Detector/VP/include/Detector/VP/DeVP.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Detector/VP/include/Detector/VP/DeVP.h b/Detector/VP/include/Detector/VP/DeVP.h index a81677db9a..daff5c923c 100644 --- a/Detector/VP/include/Detector/VP/DeVP.h +++ b/Detector/VP/include/Detector/VP/DeVP.h @@ -159,10 +159,6 @@ namespace LHCb::Detector { return this->access()->sensitiveVolumeID( point ); } - auto getGlobalTransform() const { - return detail::toLHCbLengthUnits( this->access()->detectorAlignment().worldTransformation() ); - } - /// Return pointer to sensor for a given sensor number. const DeVPSensor sensor( VPChannelID id ) const { return sensor( id.sensor() ); } -- GitLab