Skip to content
Snippets Groups Projects
Commit 685e5c7c authored by Daniele Manuzzi's avatar Daniele Manuzzi
Browse files

rebase on master

parents 2925678e 87656f0e
Branches pre_commit
No related tags found
No related merge requests found
Pipeline #6286344 passed with stages
in 5 minutes and 51 seconds
......@@ -99,6 +99,7 @@ add_library(DetectorLib SHARED
Core/src/MagneticFieldExtension.cpp
Detector/LHCb/src/DeLHCb.cpp
Detector/LHCb/src/DeLHCbHandles.cpp
Detector/LHCb/src/InteractionRegion.cpp
Detector/LHCb/src/Tell40Links.cpp
Detector/Rich/src/DeRich.cpp
Detector/Rich/src/DeRichRadiator.cpp
......
......@@ -27,6 +27,7 @@ add_executable(test_DDS
src/test_DDS.cpp
src/test_DDS_limit_IOV.cpp
src/test_DDS_tell40links.cpp
src/test_DDS_interactionregion.cpp
)
target_link_libraries(test_DDS
Catch2::Catch2WithMain
......
/*****************************************************************************\
* (c) Copyright 2022 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 <Core/DetectorDataService.h>
#include <Core/Keys.h>
#include <DD4hep/Detector.h>
#include <Detector/LHCb/DeLHCb.h>
#include <Detector/Test/Fixture.h>
#include <cstdio>
#include <catch2/catch.hpp>
TEST_CASE( "InteractionRegion loading" ) {
namespace fs = std::filesystem;
using Catch::Matchers::Contains;
Detector::Test::Fixture f;
auto& description = f.description();
description.fromXML( "compact/trunk/LHCb.xml" );
REQUIRE( description.state() == dd4hep::Detector::READY );
auto det = description.detector( "/world" );
// the `!!` is needed because handles have `operator!` but not `operator bool`
REQUIRE( !!det );
LHCb::Detector::DetectorDataService dds( description, {"/world"} );
dds.initialize( nlohmann::json( {{"repository", "file:tests/ConditionsIOV"}} ) );
{
// get a condition slice where the condition exists
// - we should get the values from the condition
auto slice = dds.get_slice( 200 );
REQUIRE( slice );
LHCb::Detector::DeLHCb lhcb = slice->get( det, LHCb::Detector::Keys::deKey );
REQUIRE( !!lhcb );
auto ir = lhcb.interactionRegion();
REQUIRE( ir.has_value() );
CHECK( ir.value().avgPosition == ROOT::Math::XYZPoint{0.0, 0.0, 0.0} );
CHECK( ir.value().spread.At( 0, 0 ) == 0.0064 );
CHECK( ir.value().spread.At( 0, 1 ) == 0.0 );
CHECK( ir.value().spread.At( 0, 2 ) == 0.0 );
CHECK( ir.value().spread.At( 1, 1 ) == 0.0064 );
CHECK( ir.value().spread.At( 1, 2 ) == 0.0 );
CHECK( ir.value().spread.At( 2, 2 ) == 2809.0 );
CHECK( ir.value().tX() == 0.0 );
CHECK( ir.value().tY() == 0.0 );
}
{
// get a condition slice where the condition doesn't exist
// - we should get the fallback values
auto slice = dds.get_slice( 0 );
REQUIRE( slice );
LHCb::Detector::DeLHCb lhcb = slice->get( det, LHCb::Detector::Keys::deKey );
REQUIRE( !!lhcb );
auto ir = lhcb.interactionRegion();
REQUIRE( !ir.has_value() );
}
}
......@@ -13,11 +13,13 @@
#include <Core/ConditionsRepository.h>
#include <Core/DeIOV.h>
#include <Core/Keys.h>
#include <Detector/LHCb/InteractionRegion.h>
#include <Detector/LHCb/Tell40Links.h>
#include <fmt/core.h>
#include <memory>
#include <optional>
namespace LHCb::Detector {
......@@ -28,6 +30,7 @@ namespace LHCb::Detector {
void applyToAllChildren( const std::function<void( DeIOVElement<DeIOVObject> )>& ) const override;
std::vector<DeIOV> children;
Tell40Links m_tell40links;
std::optional<InteractionRegion> m_interactionRegion;
};
// Utility method to lookup DeIOV object from the condition slice
......@@ -40,6 +43,9 @@ namespace LHCb::Detector {
const Tell40Links& tell40links() const { return access()->m_tell40links; }
auto tell40links( Tell40Links::SourceId id ) const { return access()->m_tell40links[id]; }
/// Provide the position, spread, and tilt of the interaction region
std::optional<InteractionRegion> interactionRegion() const { return this->access()->m_interactionRegion; }
};
// Utility method to setup DeLHCb
......
/*****************************************************************************\
* (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. *
\*****************************************************************************/
#pragma once
#include <nlohmann/json_fwd.hpp>
#include <Math/Point3D.h>
#include <Math/SMatrix.h>
#include <Math/SMatrixDfwd.h>
namespace LHCb::Detector {
struct InteractionRegion {
InteractionRegion() = default;
InteractionRegion( const nlohmann::json& obj );
double tX() const { return ( spread( 2, 2 ) != 0.0 ) ? spread( 0, 2 ) / spread( 2, 2 ) : 0.0; }
double tY() const { return ( spread( 2, 2 ) != 0.0 ) ? spread( 1, 2 ) / spread( 2, 2 ) : 0.0; }
ROOT::Math::XYZPoint avgPosition;
ROOT::Math::SMatrixSym3D spread;
};
} // namespace LHCb::Detector
......@@ -23,6 +23,9 @@ LHCb::Detector::detail::DeLHCbObject::DeLHCbObject( const dd4hep::DetElement&
auto links = ctxt.condition( hash_key( de, "Tell40Links" ) ).get<nlohmann::json>();
if ( !links.is_null() ) { m_tell40links = links; }
auto cond = ctxt.condition( hash_key( de, "InteractionRegion" ) ).get<nlohmann::json>();
if ( !cond.is_null() ) { m_interactionRegion = cond; }
}
void LHCb::Detector::detail::DeLHCbObject::applyToAllChildren(
......@@ -101,5 +104,10 @@ void LHCb::Detector::setup_DeLHCb_callback( dd4hep::Detector& description ) {
"Tell40Links" );
depbuilder.add( hash_key( de, "Tell40Links" ) );
( *requests )
->addLocation( de, LHCb::Detector::item_key( "InteractionRegion" ),
"Conditions/LHCb/Online/InteractionRegion.yml", "InteractionRegion" );
depbuilder.add( hash_key( de, "InteractionRegion" ) );
( *requests )->addDependency( depbuilder.release() );
}
/*****************************************************************************\
* (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. *
\*****************************************************************************/
#include <Detector/LHCb/InteractionRegion.h>
#include <Core/Utils.h>
#include <DD4hep/DD4hepUnits.h>
#include <DD4hep/Handle.h>
#include <nlohmann/json.hpp>
template <std::size_t Size>
std::array<double, Size> arrayFromJson( const nlohmann::json& jsonArray, const double unit ) {
if ( jsonArray.size() != Size ) { throw std::runtime_error{"InteractionRegion condition array is wrong size"}; }
std::array<double, Size> values;
for ( std::size_t i{0}; i < Size; ++i ) {
if ( jsonArray[i].is_string() ) {
values[i] = dd4hep::_toDouble( jsonArray[i].get<std::string>() );
} else if ( jsonArray[i].is_number() ) {
values[i] = jsonArray[i].get<double>() * unit;
} else {
throw std::runtime_error{"InteractionRegion condition contains unexpected types"};
}
}
return values;
}
LHCb::Detector::InteractionRegion::InteractionRegion( const nlohmann::json& obj ) {
if ( !obj.contains( "position" ) || !obj.contains( "spread" ) ) {
throw std::runtime_error{"InteractionRegion condition is empty"};
}
auto& pos = obj.at( "position" );
constexpr std::size_t posSize{3};
std::array<double, posSize> posVals{arrayFromJson<posSize>( pos, dd4hep::mm )};
auto& spr = obj.at( "spread" );
constexpr std::size_t sprSize{6};
std::array<double, sprSize> sprVals{arrayFromJson<sprSize>( spr, dd4hep::mm2 )};
avgPosition.SetCoordinates( posVals.begin(), posVals.end() );
spread.SetElements( sprVals.begin(), sprVals.end(), true );
}
../trunk
\ No newline at end of file
......@@ -10,13 +10,14 @@
# or submit itself to any jurisdiction. #
###############################################################################
set -e
shopt -s extglob
filename=$(readlink -f $BASH_SOURCE)
dir=$(dirname $filename)
SCRIPT_LOC=$(cd $dir;pwd)
ret=0
for d in ${SCRIPT_LOC}/../compact/*; do
for d in ${SCRIPT_LOC}/../compact/!(run3); do
echo "=== Running ${SCRIPT_LOC}/verify_checksum.sh $d/LHCb.xml"
if ! ${SCRIPT_LOC}/verify_checksum.sh $d/LHCb.xml ; then
ret=1
......
# Special case of empty condition
---
InteractionRegion:
# Example of InteractionRegion condition
# ```
# InteractionRegion:
# position: <avg_position_x_y_z: [float x3]>
# spread: <spread_matrix_xx_xy_yy_xz_yz_zz: [float x6]>
# ```
---
InteractionRegion:
position: [ "0.0*mm", "0.0*mm", "0.0*mm" ]
spread: [ "0.0064*mm2", "0.0*mm2", "0.0064*mm2", "0.0*mm2", "0.0*mm2", "2809.0*mm2" ]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment