From 0cc51f7ceb2d01469e101a00d1b567712026aef3 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Tue, 21 Sep 2021 13:04:07 +0200 Subject: [PATCH 01/37] First commit, copying FTChannelID from LHCb and starting the interface. Does not compile yet --- Detector/FT/include/Detector/FT/DeFT.h | 87 +++++-- Detector/FT/include/Detector/FT/DeFTLayer.h | 10 +- Detector/FT/include/Detector/FT/DeFTMat.h | 1 + Detector/FT/include/Detector/FT/DeFTModule.h | 7 +- Detector/FT/include/Detector/FT/DeFTQuarter.h | 33 ++- Detector/FT/include/Detector/FT/DeFTStation.h | 12 +- Detector/FT/include/Detector/FT/FTChannelID.h | 234 ++++++++++++++++++ Detector/FT/src/DeFT.cpp | 54 +++- 8 files changed, 411 insertions(+), 27 deletions(-) create mode 100644 Detector/FT/include/Detector/FT/FTChannelID.h diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index aa0af29a..8518420b 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -1,19 +1,23 @@ /*****************************************************************************\ -* (c) Copyright 2000-2019 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. * + * (c) Copyright 2000-2019 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 "Detector/FT/DeFTStation.h" +#include "Detector/FT/FTChannelID.h" +namespace DeFTLocation { + // FT location defined in the XmlDDDB + inline const std::string Default = "/dd/Structure/LHCb/AfterMagnetRegion/T/FT"; +} // namespace DeFTDetectorLocation namespace LHCb::Detector { - namespace detail { /** @@ -23,15 +27,64 @@ namespace LHCb::Detector { * \version 1.0 */ struct DeFTObject : DeIOVObject { - int version{dd4hep::_toInt( "FT:version" )}; // FT Geometry Version - int nModulesT1{dd4hep::_toInt( "FT:nModulesT1" )}; // Number of modules in T1 - int nModulesT2{dd4hep::_toInt( "FT:nModulesT2" )}; // Number of modules in T2 - int nModulesT3{dd4hep::_toInt( "FT:nModulesT3" )}; // Number of modules in T3 - int nLayers{dd4hep::_toInt( "FT:nLayers" )}; // Number of layers per station - int nQuarters{dd4hep::_toInt( "FT:nQuarters" )}; // Number of quarters per layer - int nChannelsInModule{dd4hep::_toInt( "FT:nChannelsInModule" )}; // Number of channels per SiPM - std::array stations; + int m_version {dd4hep::_toInt( "FT:version" )}; // FT Geometry Version + int m_nModulesT1{dd4hep::_toInt( "FT:nModulesT1" )}; // Number of modules in T1 + int m_nModulesT2{dd4hep::_toInt( "FT:nModulesT2" )}; // Number of modules in T2 + int m_nModulesT3{dd4hep::_toInt( "FT:nModulesT3" )}; // Number of modules in T3 + int m_nLayers {dd4hep::_toInt( "FT:nLayers" )}; // Number of layers per station + int m_nQuarters {dd4hep::_toInt( "FT:nQuarters" )}; // Number of quarters per layer + int m_nChannelsInModule{dd4hep::_toInt( "FT:nChannelsInModule" )}; // Number of channels per SiPM + int m_nTotChannels; + int m_nTotQuarters; + + std::array m_stations; + + int version() const {return m_version;}; + DeFTObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); + + /** Find the FT Station corresponding to the channel id + * @return Pointer to the relevant station + */ + [[nodiscard]] const DeFTStation findStation( const LHCb::FTChannelID& aChannel ) const { + return DeFTStation(&(m_stations[to_unsigned( aChannel.station() ) - 1u])); + } + + /** Find the FT Layer corresponding to the channel id + * @return Pointer to the relevant layer + */ + [[nodiscard]] const DeFTLayer findLayer( const LHCb::FTChannelID& aChannel ) const { + const DeFTStation s = findStation( aChannel ); + return s->findLayer( aChannel ); + } + + /** Find the FT Quarter corresponding to the channel id + * @return Pointer to the relevant quarter + */ + [[nodiscard]] const DeFTQuarter findQuarter( const LHCb::FTChannelID& aChannel ) const { + const DeFTLayer l = findLayer( aChannel ); + return l->findQuarter( aChannel ); + } + + /** Find the FT Module corresponding to the channel id + * @return Pointer to the relevant module + */ + [[nodiscard]] const DeFTModule findModule( const LHCb::FTChannelID& aChannel ) const { + const DeFTQuarter q = findQuarter( aChannel ); + return q->findModule( aChannel ); + } + + /** Find the FT Mat corresponding to the channel id + * @return Pointer to the relevant module + */ + [[nodiscard]] const DeFTMat findMat( const LHCb::FTChannelID& aChannel ) const { + const DeFTModule m = findModule( aChannel ); + return m->findMat( aChannel ); + } + + LHCb::FTChannelID getRandomChannelFromSeed( const float seed ) const; + LHCb::FTChannelID getRandomChannelFromPseudo( const int pseudoChannel, const float seed ) const; + }; } // End namespace detail diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 56459c5d..684998dc 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -12,6 +12,7 @@ #include "Core/DeIOV.h" #include "Detector/FT/DeFTQuarter.h" +#include "Detector/FT/FTChannelID.h" #include @@ -27,8 +28,15 @@ namespace LHCb::Detector { */ struct DeFTLayerObject : DeIOVObject { /// Reference to the static information of the quarters - std::array quarters; + std::array m_quarters;//FIXME hardcoded DeFTLayerObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); + /** Const method to return the quarter for a given channel id + * @param aChannel an FT channel id + * @return pointer to detector element + */ + [[nodiscard]] const DeFTQuarter* findQuarter( const LHCb::FTChannelID& aChannel ) const { + return m_quarters[to_unsigned( aChannel.quarter() )]; + } }; } // End namespace detail diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index 28f93d2c..70231e5f 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -12,6 +12,7 @@ #include "Core/DeIOV.h" #include "Detector/FT/FTConstants.h" +#include "Detector/FT/FTChannelID.h" #include #include diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 3f0c416c..30986b65 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -12,6 +12,7 @@ #include "Core/DeIOV.h" #include "Detector/FT/DeFTMat.h" +#include "Detector/FT/FTChannelID.h" #include @@ -27,8 +28,12 @@ namespace LHCb::Detector { */ struct DeFTModuleObject : DeIOVObject { /// Reference to the static information of mats - std::array mats; + std::array m_mats;//FIXME hardcoded DeFTModuleObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); + [[nodiscard]] const DeFTMat findMat( const LHCb::FTChannelID& id ) const { + return m_mats[to_unsigned( id.mat() )]; + } + }; } // End namespace detail diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index cc14408d..b47efe57 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -12,6 +12,7 @@ #include "Core/DeIOV.h" #include "Detector/FT/DeFTModule.h" +#include "Detector/FT/FTChannelID.h" namespace LHCb::Detector { @@ -25,8 +26,38 @@ namespace LHCb::Detector { */ struct DeFTQuarterObject : DeIOVObject { /// Reference to the static information of modules - std::array modules; + std::array m_modules;//FIXME hardcoded DeFTQuarterObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); + + /** Const method to return the module for a given channel id + * @param aChannel an FT channel id + * @return pointer to detector element + */ + [[nodiscard]] const DeFTModule* findModule( const LHCb::FTChannelID aChannel ) const { + auto m = to_unsigned( aChannel.module() ); + return m_modules[m]; + } + + /** Const method to return the module for a given XYZ point + * @param aPoint the given point + * @return const pointer to detector element + */ + // [[nodiscard]] const DeFTModule* findModule( const Gaudi::XYZPoint& aPoint ) const; + + /** Flat vector of all FT modules + * @return vector of modules + */ + [[nodiscard]] const auto& modules() const { return m_modules; } + + /** @return quarterID */ + // [[nodiscard]] ID quarterID() const { return m_quarterID; } + + /** @return flag true if this quarter is bottom half */ + // [[nodiscard]] bool isBottom() const { return m_quarterID == ID{0} || m_quarterID == ID{1}; } + + /** @return flag true if this quarter is top half */ + // [[nodiscard]] bool isTop() const { return m_quarterID == ID{2} || m_quarterID == ID{3}; } + }; } // End namespace detail diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index c1ca656b..42bdc8ab 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -12,11 +12,12 @@ #include "Core/DeIOV.h" #include "Detector/FT/DeFTLayer.h" +#include "Detector/FT/FTChannelID.h" namespace LHCb::Detector { namespace detail { - + /** * Generic FT iov dependent detector element of a FT station * \author Markus Frank @@ -25,8 +26,15 @@ namespace LHCb::Detector { */ struct DeFTStationObject : DeIOVObject { /// Reference to the static information of the layers - std::array layers; + std::array m_layers;//FIXME hardcoded DeFTStationObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); + /** Const method to return the layer for a given channel id + * @param aChannel an FT channel id + * @return pointer to detector element + */ + [[nodiscard]] const DeFTLayer* findLayer( const LHCb::FTChannelID& aChannel ) const { + return m_layers[to_unsigned( aChannel.layer() )]; + } }; } // End namespace detail diff --git a/Detector/FT/include/Detector/FT/FTChannelID.h b/Detector/FT/include/Detector/FT/FTChannelID.h new file mode 100644 index 00000000..a74ebf5a --- /dev/null +++ b/Detector/FT/include/Detector/FT/FTChannelID.h @@ -0,0 +1,234 @@ +/*****************************************************************************\ +* (c) Copyright 2000-2019 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 + +namespace LHCb { + + /** @class FTChannelID FTChannelID.h + * + * Channel ID for the Fibre Tracker (LHCb Upgrade) + * + * @author FT software team + * + */ + + class FTChannelID final { + + /// Bitmasks for bitfield channelID + enum struct Mask : unsigned { + channel = 0x7f, + sipm = 0x180, + mat = 0x600, + module = 0x3800, + quarter = 0xc000, + layer = 0x30000, + station = 0xc0000, + uniqueLayer = layer | station, + uniqueQuarter = quarter | uniqueLayer, + uniqueModule = module | uniqueQuarter, + uniqueMat = mat | uniqueModule, + uniqueSiPM = sipm | uniqueMat, + die = 0x40, + sipmInModule = mat | sipm, + channelInModule = channel | sipmInModule + }; + + template + [[nodiscard]] static constexpr unsigned int extract( unsigned int i ) { + constexpr auto b = + __builtin_ctz( static_cast( m ) ); // FIXME: C++20 replace __builtin_ctz with std::countr_zero + return ( i & static_cast( m ) ) >> b; + } + + template + [[nodiscard]] static constexpr unsigned int shift( unsigned int i ) { + constexpr auto b = + __builtin_ctz( static_cast( m ) ); // FIXME: C++20 replace __builtin_ctz with std::countr_zero + auto v = ( i << static_cast( b ) ); + assert( extract( v ) == i ); + return v; + } + + template + [[nodiscard]] static constexpr unsigned int shift( T i ) { + return shift( to_unsigned( i ) ); + } + + public: + enum struct StationID : unsigned int {}; + [[nodiscard]] friend constexpr unsigned int to_unsigned( StationID id ) { return static_cast( id ); } + + enum struct LayerID : unsigned int {}; + [[nodiscard]] friend constexpr unsigned int to_unsigned( LayerID id ) { return static_cast( id ); } + [[nodiscard]] friend constexpr bool is_X( LayerID id ) { return id == LayerID{0} || id == LayerID{3}; } + + enum struct QuarterID : unsigned int {}; + [[nodiscard]] friend constexpr unsigned int to_unsigned( QuarterID id ) { return static_cast( id ); } + [[nodiscard]] friend constexpr bool is_bottom( QuarterID id ) { return id == QuarterID{0} || id == QuarterID{1}; } + [[nodiscard]] friend constexpr bool is_top( QuarterID id ) { return id == QuarterID{2} || id == QuarterID{3}; } + + enum struct ModuleID : unsigned int {}; + [[nodiscard]] friend constexpr unsigned int to_unsigned( ModuleID id ) { return static_cast( id ); } + + enum struct MatID : unsigned int {}; + [[nodiscard]] friend constexpr unsigned int to_unsigned( MatID id ) { return static_cast( id ); } + + /// Default Constructor + constexpr FTChannelID() = default; + + /// Partial constructor using the unique sipm and the channel + constexpr FTChannelID( unsigned int uniqueSiPM, unsigned int channel ) + : m_channelID{( shift( uniqueSiPM ) ) + ( shift( channel ) )} {}; + + /// Constructor from int + constexpr explicit FTChannelID( unsigned int id ) : m_channelID{id} {} + + /// Explicit constructor from the geometrical location + constexpr FTChannelID( StationID station, LayerID layer, QuarterID quarter, ModuleID module, MatID mat, + unsigned int sipm, unsigned int channel ) + : FTChannelID{shift( station ) | shift( layer ) | shift( quarter ) | + shift( module ) | shift( mat ) | shift( sipm ) | + shift( channel )} {} + + /// Explicit constructor from the geometrical location + constexpr FTChannelID( StationID station, LayerID layer, QuarterID quarter, ModuleID module, + unsigned int channelInModule ) + : FTChannelID{shift( station ) | shift( layer ) | shift( quarter ) | + shift( module ) | shift( channelInModule )} {} + + /// Operator overload, to cast channel ID to unsigned int. Used by linkers where the key (channel id) is an int + constexpr operator unsigned int() const { return m_channelID; } + + /// Comparison equality + constexpr friend bool operator==( FTChannelID lhs, FTChannelID rhs ) { return lhs.channelID() == rhs.channelID(); } + + /// Comparison < + constexpr friend bool operator<( FTChannelID lhs, FTChannelID rhs ) { return lhs.channelID() < rhs.channelID(); } + + /// Comparison > + constexpr friend bool operator>( FTChannelID lhs, FTChannelID rhs ) { return rhs < lhs; } + + /// Useful for decoding: maximum number of SiPMs + static unsigned int maxNumberOfSiPMs(); + + // FTChannelID with channelID set to kInvalid bits + static constexpr FTChannelID kInvalidChannel() { + return {StationID{0u}, LayerID{0u}, QuarterID{0u}, ModuleID{7u}, MatID{0u}, 0, 0}; + }; + + // FTChannelID with channelID set to kInvalid bits + static constexpr unsigned int kInvalidChannelID() { return kInvalidChannel().channelID(); }; + + /// Increment the channelID + constexpr FTChannelID& advance() { + ++m_channelID; + return *this; + } + + /// Return the SiPM number within the module (0-15) + [[nodiscard]] constexpr unsigned int sipmInModule() const { return extract( m_channelID ); } + + /// Return the die number (0 or 1) + [[nodiscard]] constexpr unsigned int die() const { return extract( m_channelID ); } + + /// Return true if channelID is in x-layer + [[nodiscard]] constexpr bool isX() const { return is_X( layer() ); } + + /// Return true if channelID is in bottom part of detector + [[nodiscard]] constexpr bool isBottom() const { return is_bottom( quarter() ); } + + /// Return true if channelID is in top part of detector + [[nodiscard]] constexpr bool isTop() const { return is_top( quarter() ); } + + /// Retrieve const FT Channel ID + [[nodiscard]] constexpr unsigned int channelID() const { return m_channelID; } + + /// Retrieve Channel in the 128 channel SiPM + [[nodiscard]] constexpr unsigned int channel() const { return extract( m_channelID ); } + + /// Retrieve ID of the SiPM in the mat + [[nodiscard]] constexpr unsigned int sipm() const { return extract( m_channelID ); } + + /// Retrieve ID of the mat in the module + [[nodiscard]] constexpr MatID mat() const { return MatID{extract( m_channelID )}; } + + /// Retrieve Module id (0 - 5 or 0 - 6) + [[nodiscard]] constexpr ModuleID module() const { return ModuleID{extract( m_channelID )}; } + + /// Retrieve Quarter ID (0 - 3) + [[nodiscard]] constexpr QuarterID quarter() const { return QuarterID{extract( m_channelID )}; } + + /// Retrieve Layer id + [[nodiscard]] constexpr LayerID layer() const { return LayerID{extract( m_channelID )}; } + + /// Retrieve Station id + [[nodiscard]] constexpr StationID station() const { return StationID{extract( m_channelID )}; } + + /// Retrieve unique layer + [[nodiscard]] constexpr unsigned int uniqueLayer() const { return extract( m_channelID ); } + + /// Retrieve unique quarter + [[nodiscard]] constexpr unsigned int uniqueQuarter() const { return extract( m_channelID ); } + + /// Retrieve unique module + [[nodiscard]] constexpr unsigned int uniqueModule() const { return extract( m_channelID ); } + + /// Retrieve unique mat + [[nodiscard]] constexpr unsigned int uniqueMat() const { return extract( m_channelID ); } + + /// Retrieve unique SiPM + [[nodiscard]] constexpr unsigned int uniqueSiPM() const { return extract( m_channelID ); } + + /// Retrieve moduleID for monitoring + [[nodiscard]] constexpr unsigned int moniModuleID() const { + return 6 * ( 4 * ( 4 * ( to_unsigned( station() ) - 1 ) + to_unsigned( layer() ) ) + to_unsigned( quarter() ) ) + + to_unsigned( module() ); + } + + /// Retrieve moduleID unique per station for monitoring + [[nodiscard]] constexpr unsigned int moniModuleIDstation() const { + return to_unsigned( module() ) + 4 * to_unsigned( quarter() ) + 16 * to_unsigned( layer() ); + } + + /// Retrieve quarterID for monitoring + [[nodiscard]] constexpr unsigned int moniQuarterID() const { + return 4 * to_unsigned( layer() ) + to_unsigned( quarter() ) + 16 * ( to_unsigned( station() ) - 1 ); + } + + /// Retrieve SiPMID for monitoring + [[nodiscard]] constexpr unsigned int moniSiPMID() const { + return sipm() + 4 * to_unsigned( mat() ) + 20 * to_unsigned( module() ); + } + + /// Retrieve channelID for monitoring + [[nodiscard]] constexpr unsigned int moniChannelID() const { + return to_unsigned( mat() ) + 4 * sipm() + 16 * channel(); + } + + friend std::ostream& operator<<( std::ostream& s, const FTChannelID& obj ) { + return s << "{ FTChannelID : " + << " channel =" << obj.channel() << " sipm =" << obj.sipm() << " mat =" << to_unsigned( obj.mat() ) + << " module=" << to_unsigned( obj.module() ) << " quarter=" << to_unsigned( obj.quarter() ) + << " layer=" << to_unsigned( obj.layer() ) << " station=" << to_unsigned( obj.station() ) << " }"; + } + + private: + unsigned int m_channelID{0}; ///< FT Channel ID + + }; // class FTChannelID + +} // namespace LHCb + +// ----------------------------------------------------------------------------- +// end of class +// ----------------------------------------------------------------------------- diff --git a/Detector/FT/src/DeFT.cpp b/Detector/FT/src/DeFT.cpp index 31ecf941..c3e8429f 100644 --- a/Detector/FT/src/DeFT.cpp +++ b/Detector/FT/src/DeFT.cpp @@ -11,22 +11,24 @@ // Framework include files #include "Detector/FT/DeFT.h" +#include "Detector/FT/FTChannelID.h" + #include "DD4hep/Printout.h" LHCb::Detector::detail::DeFTObject::DeFTObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) - , stations{{{de.child( "T1" ), ctxt}, {de.child( "T2" ), ctxt}, {de.child( "T3" ), ctxt}}} {} + , m_stations{{{de.child( "T1" ), ctxt}, {de.child( "T2" ), ctxt}, {de.child( "T3" ), ctxt}}} {} LHCb::Detector::detail::DeFTStationObject::DeFTStationObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) - , layers{{{de.child( "X1" ), ctxt}, {de.child( "U" ), ctxt}, {de.child( "V" ), ctxt}, {de.child( "X2" ), ctxt}}} {} + , m_layers{{{de.child( "X1" ), ctxt}, {de.child( "U" ), ctxt}, {de.child( "V" ), ctxt}, {de.child( "X2" ), ctxt}}} {} LHCb::Detector::detail::DeFTLayerObject::DeFTLayerObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) - , quarters{ + , m_quarters{ {{de.child( "Q0" ), ctxt}, {de.child( "Q1" ), ctxt}, {de.child( "Q2" ), ctxt}, {de.child( "Q3" ), ctxt}}} {} LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetElement& de, @@ -34,7 +36,7 @@ LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetE : DeIOVObject( de, ctxt ) , // XXX no always 6 modules ? - modules{{{de.child( "M0" ), ctxt}, + m_modules{{{de.child( "M0" ), ctxt}, {de.child( "M1" ), ctxt}, {de.child( "M2" ), ctxt}, {de.child( "M3" ), ctxt}, @@ -44,7 +46,49 @@ LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetE LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) - , mats{{{de.child( "Mat0" ), ctxt}, + , m_mats{{{de.child( "Mat0" ), ctxt}, {de.child( "Mat1" ), ctxt}, {de.child( "Mat2" ), ctxt}, {de.child( "Mat3" ), ctxt}}} {} + + +/// Get a random FTChannelID (useful for the thermal noise, which is ~flat) +LHCb::FTChannelID LHCb::Detector::detail::DeFT::getRandomChannelFromSeed( const float seed ) const { + if ( seed < 0.f || seed > 1.f ) return LHCb::FTChannelID::kChannelID; + unsigned int flatChannel = int( seed * m_nTotChannels ); + unsigned int channelInModule = flatChannel & ( m_nChannelsInModule - 1u ); + flatChannel /= m_nChannelsInModule; + unsigned int quarter = flatChannel & ( m_nQuarters - 1u ); + flatChannel /= m_nQuarters; + unsigned int layer = flatChannel & ( m_nLayers - 1u ); + flatChannel /= m_nLayers; + unsigned int station = 1; + unsigned int module = flatChannel; + if ( flatChannel >= m_nModulesT1 + m_nModulesT2 ) { + station = 3; + module = flatChannel - m_nModulesT1 - m_nModulesT2; + } else if ( flatChannel >= m_nModulesT1 ) { + station = 2; + module = flatChannel - m_nModulesT1; + } + return LHCb::FTChannelID( LHCb::FTChannelID::StationID{station}, LHCb::FTChannelID::LayerID{layer}, + LHCb::FTChannelID::QuarterID{quarter}, LHCb::FTChannelID::ModuleID{module}, + channelInModule ); +} + +/// Get a random FTChannelID from a pseudoChannel (useful for the AP noise) +LHCb::FTChannelID LHCb::Detector::detail::DeFT::getRandomChannelFromPseudo( const int pseudoChannel, const float seed ) const { + if ( seed < 0.f || seed > 1.f ) return LHCb::FTChannelID::kInvalid; + unsigned int flatQuarter = int( seed * m_nTotQuarters ); + auto quarter = LHCb::FTChannelID::QuarterID{flatQuarter & ( m_nQuarters - 1u )}; + flatQuarter /= m_nQuarters; + auto layer = LHCb::FTChannelID::LayerID{flatQuarter & ( m_nLayers - 1u )}; + flatQuarter /= m_nLayers; + auto station = LHCb::FTChannelID::StationID{( flatQuarter & m_nStations ) + 1u}; + + auto module = LHCb::FTChannelID::ModuleID{pseudoChannel / m_nChannelsInModule}; + const DeFTModule* moduleDet = findModule( LHCb::FTChannelID( station, layer, quarter, module, 0u ) ); + return moduleDet ? moduleDet->channelFromPseudo( pseudoChannel & ( m_nChannelsInModule - 1u ) ) + : LHCb::FTChannelID( 0u ); +} + -- GitLab From f0eea7cb0a209c8ec922454bdfbcbcebbb687924 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Tue, 21 Sep 2021 15:21:53 +0200 Subject: [PATCH 02/37] First compiling version with proper templating. Missing key methods and having had to hardcode a boolean in quarter and module construction (reversed). --- Detector/FT/include/Detector/FT/DeFT.h | 135 ++++++++++++------ Detector/FT/include/Detector/FT/DeFTLayer.h | 36 ++--- Detector/FT/include/Detector/FT/DeFTMat.h | 9 +- Detector/FT/include/Detector/FT/DeFTModule.h | 24 +++- Detector/FT/include/Detector/FT/DeFTQuarter.h | 66 ++++----- Detector/FT/include/Detector/FT/DeFTStation.h | 36 ++--- Detector/FT/src/DeFT.cpp | 56 ++------ 7 files changed, 191 insertions(+), 171 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 8518420b..b814244a 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -19,7 +19,6 @@ namespace DeFTLocation { namespace LHCb::Detector { namespace detail { - /** * FT detector element data * \author Markus Frank @@ -38,56 +37,104 @@ namespace LHCb::Detector { int m_nTotQuarters; std::array m_stations; - - int version() const {return m_version;}; - DeFTObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); + }; + + } // End namespace detail - /** Find the FT Station corresponding to the channel id - * @return Pointer to the relevant station - */ - [[nodiscard]] const DeFTStation findStation( const LHCb::FTChannelID& aChannel ) const { - return DeFTStation(&(m_stations[to_unsigned( aChannel.station() ) - 1u])); - } - - /** Find the FT Layer corresponding to the channel id - * @return Pointer to the relevant layer - */ - [[nodiscard]] const DeFTLayer findLayer( const LHCb::FTChannelID& aChannel ) const { - const DeFTStation s = findStation( aChannel ); - return s->findLayer( aChannel ); - } - - /** Find the FT Quarter corresponding to the channel id - * @return Pointer to the relevant quarter - */ - [[nodiscard]] const DeFTQuarter findQuarter( const LHCb::FTChannelID& aChannel ) const { - const DeFTLayer l = findLayer( aChannel ); - return l->findQuarter( aChannel ); - } + /** + * FT interface + * + * \author Louis Henry + * \date 2021-09-21 + * \version 1.0 + */ + template + struct DeFTElement : DeIOVElement { + int version() const {return this->access()->m_version;}; + + /** Find the FT Station corresponding to the channel id + * @return Pointer to the relevant station + */ + [[nodiscard]] const DeFTStation& findStation( const LHCb::FTChannelID& aChannel ) const { + return this->access()->m_stations[to_unsigned( aChannel.station() ) - 1u]; + } + + /** Find the FT Layer corresponding to the channel id + * @return Pointer to the relevant layer + */ + [[nodiscard]] const DeFTLayer& findLayer( const LHCb::FTChannelID& aChannel ) const { + const auto& s = findStation( aChannel ); + return s.findLayer( aChannel ); + } + + /** Find the FT Quarter corresponding to the channel id + * @return Pointer to the relevant quarter + */ + [[nodiscard]] const DeFTQuarter& findQuarter( const LHCb::FTChannelID& aChannel ) const { + const auto& l = findLayer( aChannel ); + return l.findQuarter( aChannel ); + } - /** Find the FT Module corresponding to the channel id - * @return Pointer to the relevant module - */ - [[nodiscard]] const DeFTModule findModule( const LHCb::FTChannelID& aChannel ) const { - const DeFTQuarter q = findQuarter( aChannel ); - return q->findModule( aChannel ); - } + /** Find the FT Module corresponding to the channel id + * @return Pointer to the relevant module + */ + [[nodiscard]] const DeFTModule& findModule( const LHCb::FTChannelID& aChannel ) const { + const auto& q = findQuarter( aChannel ); + return q.findModule( aChannel ); + } - /** Find the FT Mat corresponding to the channel id - * @return Pointer to the relevant module - */ - [[nodiscard]] const DeFTMat findMat( const LHCb::FTChannelID& aChannel ) const { - const DeFTModule m = findModule( aChannel ); - return m->findMat( aChannel ); + /** Find the FT Mat corresponding to the channel id + * @return Pointer to the relevant module + */ + [[nodiscard]] const DeFTMat& findMat( const LHCb::FTChannelID& aChannel ) const { + const auto& m = findModule( aChannel ); + return m.findMat( aChannel ); + } + + /// Get a random FTChannelID (useful for the thermal noise, which is ~flat) + LHCb::FTChannelID getRandomChannelFromSeed( const float seed ) const { + if ( seed < 0.f || seed > 1.f ) return LHCb::FTChannelID::kInvalidChannel(); + const auto& obj = this->access(); + unsigned int flatChannel = int( seed * obj.m_nTotChannels ); + unsigned int channelInModule = flatChannel & ( obj.m_nChannelsInModule - 1u ); + flatChannel /= obj.m_nChannelsInModule; + unsigned int quarter = flatChannel & ( obj.m_nQuarters - 1u ); + flatChannel /= obj.m_nQuarters; + unsigned int layer = flatChannel & ( obj.m_nLayers - 1u ); + flatChannel /= obj.m_nLayers; + unsigned int station = 1; + unsigned int module = flatChannel; + if ( flatChannel >= obj.m_nModulesT1 + obj.m_nModulesT2 ) { + station = 3; + module = flatChannel - obj.m_nModulesT1 - obj.m_nModulesT2; + } else if ( flatChannel >= obj.m_nModulesT1 ) { + station = 2; + module = flatChannel - obj.m_nModulesT1; } + return LHCb::FTChannelID( LHCb::FTChannelID::StationID{station}, LHCb::FTChannelID::LayerID{layer}, + LHCb::FTChannelID::QuarterID{quarter}, LHCb::FTChannelID::ModuleID{module}, + channelInModule ); + } - LHCb::FTChannelID getRandomChannelFromSeed( const float seed ) const; - LHCb::FTChannelID getRandomChannelFromPseudo( const int pseudoChannel, const float seed ) const; + /// Get a random FTChannelID from a pseudoChannel (useful for the AP noise) + LHCb::FTChannelID getRandomChannelFromPseudo( const int pseudoChannel, const float seed ) const { + if ( seed < 0.f || seed > 1.f ) return LHCb::FTChannelID::kInvalidChannel(); + const auto& obj = this->access(); + unsigned int flatQuarter = int( seed * obj.m_nTotQuarters ); + auto quarter = LHCb::FTChannelID::QuarterID{flatQuarter & ( obj.m_nQuarters - 1u )}; + flatQuarter /= obj.m_nQuarters; + auto layer = LHCb::FTChannelID::LayerID{flatQuarter & ( obj.m_nLayers - 1u )}; + flatQuarter /= obj.m_nLayers; + auto station = LHCb::FTChannelID::StationID{( flatQuarter & obj.m_stations.size() ) + 1u}; - }; - } // End namespace detail + auto module = LHCb::FTChannelID::ModuleID{pseudoChannel / obj.m_nChannelsInModule}; + const DeFTModule* moduleDet = findModule( LHCb::FTChannelID( station, layer, quarter, module, 0u ) ); + return moduleDet ? moduleDet->channelFromPseudo( pseudoChannel & ( obj.m_nChannelsInModule - 1u ) ) : LHCb::FTChannelID::kInvalidChannel(); + } - using DeFT = DeIOVElement; + }; + + using DeFT = DeFTElement; } // End namespace LHCb::Detector diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 684998dc..21171694 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -1,12 +1,12 @@ /*****************************************************************************\ -* (c) Copyright 2000-2019 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. * + * (c) Copyright 2000-2019 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 @@ -30,16 +30,20 @@ namespace LHCb::Detector { /// Reference to the static information of the quarters std::array m_quarters;//FIXME hardcoded DeFTLayerObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); - /** Const method to return the quarter for a given channel id - * @param aChannel an FT channel id - * @return pointer to detector element - */ - [[nodiscard]] const DeFTQuarter* findQuarter( const LHCb::FTChannelID& aChannel ) const { - return m_quarters[to_unsigned( aChannel.quarter() )]; - } }; } // End namespace detail - using DeFTLayer = DeIOVElement; + template + struct DeFTLayerElement : DeIOVElement { + /** Const method to return the layer for a given channel id + * @param aChannel an FT channel id + * @return pointer to detector element + */ + [[nodiscard]] const DeFTQuarter& findQuarter( const LHCb::FTChannelID& aChannel ) const { + return this->access()->m_quarters[to_unsigned( aChannel.quarter() )]; + } + }; + + using DeFTLayer = DeFTLayerElement; } // End namespace LHCb::Detector diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index 70231e5f..1db9c48c 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -37,7 +37,10 @@ namespace LHCb::Detector { using DeIOVObject::DeIOVObject; }; } // End namespace detail - - using DeFTMat = DeIOVElement; - + template + struct DeFTMatElement : DeIOVElement { + }; + + using DeFTMat = DeFTMatElement; + } // End namespace LHCb::Detector diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 30986b65..3bdd8f2c 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -28,15 +28,27 @@ namespace LHCb::Detector { */ struct DeFTModuleObject : DeIOVObject { /// Reference to the static information of mats + bool m_reversed; std::array m_mats;//FIXME hardcoded - DeFTModuleObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); - [[nodiscard]] const DeFTMat findMat( const LHCb::FTChannelID& id ) const { - return m_mats[to_unsigned( id.mat() )]; - } + DeFTModuleObject( const dd4hep::DetElement& de, bool rev, dd4hep::cond::ConditionUpdateContext& ctxt ); }; } // End namespace detail - - using DeFTModule = DeIOVElement; + template + struct DeFTModuleElement : DeIOVElement { + [[nodiscard]] const DeFTMat& findMat( const LHCb::FTChannelID& id ) const { + return this->access()->m_mats[to_unsigned( id.mat() )]; + } + [[nodiscard]] LHCb::FTChannelID channelFromPseudo( const int pseudoChannel ) const { + // const auto& obj = this->access(); + // int channelInModule = pseudoChannel & ( obj.m_nChannelsInModule - 1u ); + // if ( obj.m_reversed ) { channelInModule = obj.m_nChannelsInModule - 1 - channelInModule; } + // return LHCb::FTChannelID( elementID() + channelInModule ); + return LHCb::FTChannelID::kInvalidChannel(); + } + + }; + + using DeFTModule = DeFTModuleElement; } // End namespace LHCb::Detector diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index b47efe57..08081ede 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -1,12 +1,12 @@ /*****************************************************************************\ -* (c) Copyright 2000-2019 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. * + * (c) Copyright 2000-2019 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 @@ -27,40 +27,26 @@ namespace LHCb::Detector { struct DeFTQuarterObject : DeIOVObject { /// Reference to the static information of modules std::array m_modules;//FIXME hardcoded - DeFTQuarterObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); - - /** Const method to return the module for a given channel id - * @param aChannel an FT channel id - * @return pointer to detector element - */ - [[nodiscard]] const DeFTModule* findModule( const LHCb::FTChannelID aChannel ) const { - auto m = to_unsigned( aChannel.module() ); - return m_modules[m]; - } - - /** Const method to return the module for a given XYZ point - * @param aPoint the given point - * @return const pointer to detector element - */ - // [[nodiscard]] const DeFTModule* findModule( const Gaudi::XYZPoint& aPoint ) const; - - /** Flat vector of all FT modules - * @return vector of modules - */ - [[nodiscard]] const auto& modules() const { return m_modules; } - - /** @return quarterID */ - // [[nodiscard]] ID quarterID() const { return m_quarterID; } - - /** @return flag true if this quarter is bottom half */ - // [[nodiscard]] bool isBottom() const { return m_quarterID == ID{0} || m_quarterID == ID{1}; } - - /** @return flag true if this quarter is top half */ - // [[nodiscard]] bool isTop() const { return m_quarterID == ID{2} || m_quarterID == ID{3}; } - + DeFTQuarterObject( const dd4hep::DetElement& de, bool rev, dd4hep::cond::ConditionUpdateContext& ctxt ); }; } // End namespace detail - using DeFTQuarter = DeIOVElement; + template + struct DeFTQuarterElement : DeIOVElement { + /** Const method to return the layer for a given channel id + * @param aChannel an FT channel id + * @return pointer to detector element + */ + [[nodiscard]] const DeFTModule& findModule( const LHCb::FTChannelID aChannel ) const { + auto m = to_unsigned( aChannel.module() ); + return this->access()->m_modules[m]; + } + /** Flat vector of all FT modules + * @return vector of modules + */ + [[nodiscard]] const auto& modules() const { return this->access()->m_modules; } + }; + + using DeFTQuarter = DeFTQuarterElement; } // End namespace LHCb::Detector diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index 42bdc8ab..21b43eb3 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -1,12 +1,12 @@ /*****************************************************************************\ -* (c) Copyright 2000-2019 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. * + * (c) Copyright 2000-2019 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 @@ -28,16 +28,20 @@ namespace LHCb::Detector { /// Reference to the static information of the layers std::array m_layers;//FIXME hardcoded DeFTStationObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); - /** Const method to return the layer for a given channel id - * @param aChannel an FT channel id - * @return pointer to detector element - */ - [[nodiscard]] const DeFTLayer* findLayer( const LHCb::FTChannelID& aChannel ) const { - return m_layers[to_unsigned( aChannel.layer() )]; - } }; } // End namespace detail - using DeFTStation = DeIOVElement; + template + struct DeFTStationElement : DeIOVElement { + /** Const method to return the layer for a given channel id + * @param aChannel an FT channel id + * @return pointer to detector element + */ + [[nodiscard]] const DeFTLayer& findLayer( const LHCb::FTChannelID& aChannel ) const { + return this->access()->m_layers[to_unsigned( aChannel.layer() )]; + } + }; + + using DeFTStation = DeFTStationElement; } // End namespace LHCb::Detector diff --git a/Detector/FT/src/DeFT.cpp b/Detector/FT/src/DeFT.cpp index c3e8429f..9ebea199 100644 --- a/Detector/FT/src/DeFT.cpp +++ b/Detector/FT/src/DeFT.cpp @@ -29,66 +29,30 @@ LHCb::Detector::detail::DeFTLayerObject::DeFTLayerObject( const dd4hep::DetEleme dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) , m_quarters{ - {{de.child( "Q0" ), ctxt}, {de.child( "Q1" ), ctxt}, {de.child( "Q2" ), ctxt}, {de.child( "Q3" ), ctxt}}} {} + {{de.child( "Q0" ), true, ctxt}, {de.child( "Q1" ), true, ctxt}, {de.child( "Q2" ), false, ctxt}, {de.child( "Q3" ), false, ctxt}}} {} LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetElement& de, + bool rev, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) , // XXX no always 6 modules ? - m_modules{{{de.child( "M0" ), ctxt}, - {de.child( "M1" ), ctxt}, - {de.child( "M2" ), ctxt}, - {de.child( "M3" ), ctxt}, - {de.child( "M4" ), ctxt}, - {de.child( "M5" ), ctxt}}} {} + m_modules{{{de.child( "M0" ), rev, ctxt}, + {de.child( "M1" ), rev, ctxt}, + {de.child( "M2" ), rev, ctxt}, + {de.child( "M3" ), rev, ctxt}, + {de.child( "M4" ), rev, ctxt}, + {de.child( "M5" ), rev, ctxt}}} {} LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetElement& de, + bool rev, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) + , m_reversed{rev} , m_mats{{{de.child( "Mat0" ), ctxt}, {de.child( "Mat1" ), ctxt}, {de.child( "Mat2" ), ctxt}, {de.child( "Mat3" ), ctxt}}} {} -/// Get a random FTChannelID (useful for the thermal noise, which is ~flat) -LHCb::FTChannelID LHCb::Detector::detail::DeFT::getRandomChannelFromSeed( const float seed ) const { - if ( seed < 0.f || seed > 1.f ) return LHCb::FTChannelID::kChannelID; - unsigned int flatChannel = int( seed * m_nTotChannels ); - unsigned int channelInModule = flatChannel & ( m_nChannelsInModule - 1u ); - flatChannel /= m_nChannelsInModule; - unsigned int quarter = flatChannel & ( m_nQuarters - 1u ); - flatChannel /= m_nQuarters; - unsigned int layer = flatChannel & ( m_nLayers - 1u ); - flatChannel /= m_nLayers; - unsigned int station = 1; - unsigned int module = flatChannel; - if ( flatChannel >= m_nModulesT1 + m_nModulesT2 ) { - station = 3; - module = flatChannel - m_nModulesT1 - m_nModulesT2; - } else if ( flatChannel >= m_nModulesT1 ) { - station = 2; - module = flatChannel - m_nModulesT1; - } - return LHCb::FTChannelID( LHCb::FTChannelID::StationID{station}, LHCb::FTChannelID::LayerID{layer}, - LHCb::FTChannelID::QuarterID{quarter}, LHCb::FTChannelID::ModuleID{module}, - channelInModule ); -} - -/// Get a random FTChannelID from a pseudoChannel (useful for the AP noise) -LHCb::FTChannelID LHCb::Detector::detail::DeFT::getRandomChannelFromPseudo( const int pseudoChannel, const float seed ) const { - if ( seed < 0.f || seed > 1.f ) return LHCb::FTChannelID::kInvalid; - unsigned int flatQuarter = int( seed * m_nTotQuarters ); - auto quarter = LHCb::FTChannelID::QuarterID{flatQuarter & ( m_nQuarters - 1u )}; - flatQuarter /= m_nQuarters; - auto layer = LHCb::FTChannelID::LayerID{flatQuarter & ( m_nLayers - 1u )}; - flatQuarter /= m_nLayers; - auto station = LHCb::FTChannelID::StationID{( flatQuarter & m_nStations ) + 1u}; - - auto module = LHCb::FTChannelID::ModuleID{pseudoChannel / m_nChannelsInModule}; - const DeFTModule* moduleDet = findModule( LHCb::FTChannelID( station, layer, quarter, module, 0u ) ); - return moduleDet ? moduleDet->channelFromPseudo( pseudoChannel & ( m_nChannelsInModule - 1u ) ) - : LHCb::FTChannelID( 0u ); -} -- GitLab From 762a9ba0f59f9f730b1c823febcbd5c2168901cb Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Tue, 21 Sep 2021 15:53:52 +0200 Subject: [PATCH 03/37] Adding FIXMEs and changing the namespace of the FTChannelID. Cleaning up some includes --- Detector/FT/include/Detector/FT/DeFT.h | 35 ++++++++++--------- Detector/FT/include/Detector/FT/DeFTLayer.h | 3 +- Detector/FT/include/Detector/FT/DeFTModule.h | 7 ++-- Detector/FT/include/Detector/FT/DeFTQuarter.h | 3 +- Detector/FT/include/Detector/FT/DeFTStation.h | 3 +- Detector/FT/include/Detector/FT/FTChannelID.h | 2 +- Detector/FT/src/DeFT.cpp | 4 +-- 7 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index b814244a..12d26ca8 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -56,14 +56,14 @@ namespace LHCb::Detector { /** Find the FT Station corresponding to the channel id * @return Pointer to the relevant station */ - [[nodiscard]] const DeFTStation& findStation( const LHCb::FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTStation& findStation( const FTChannelID& aChannel ) const { return this->access()->m_stations[to_unsigned( aChannel.station() ) - 1u]; } /** Find the FT Layer corresponding to the channel id * @return Pointer to the relevant layer */ - [[nodiscard]] const DeFTLayer& findLayer( const LHCb::FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTLayer& findLayer( const FTChannelID& aChannel ) const { const auto& s = findStation( aChannel ); return s.findLayer( aChannel ); } @@ -71,7 +71,7 @@ namespace LHCb::Detector { /** Find the FT Quarter corresponding to the channel id * @return Pointer to the relevant quarter */ - [[nodiscard]] const DeFTQuarter& findQuarter( const LHCb::FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTQuarter& findQuarter( const FTChannelID& aChannel ) const { const auto& l = findLayer( aChannel ); return l.findQuarter( aChannel ); } @@ -79,7 +79,7 @@ namespace LHCb::Detector { /** Find the FT Module corresponding to the channel id * @return Pointer to the relevant module */ - [[nodiscard]] const DeFTModule& findModule( const LHCb::FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTModule& findModule( const FTChannelID& aChannel ) const { const auto& q = findQuarter( aChannel ); return q.findModule( aChannel ); } @@ -87,14 +87,14 @@ namespace LHCb::Detector { /** Find the FT Mat corresponding to the channel id * @return Pointer to the relevant module */ - [[nodiscard]] const DeFTMat& findMat( const LHCb::FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTMat& findMat( const FTChannelID& aChannel ) const { const auto& m = findModule( aChannel ); return m.findMat( aChannel ); } /// Get a random FTChannelID (useful for the thermal noise, which is ~flat) - LHCb::FTChannelID getRandomChannelFromSeed( const float seed ) const { - if ( seed < 0.f || seed > 1.f ) return LHCb::FTChannelID::kInvalidChannel(); + FTChannelID getRandomChannelFromSeed( const float seed ) const { + if ( seed < 0.f || seed > 1.f ) return FTChannelID::kInvalidChannel(); const auto& obj = this->access(); unsigned int flatChannel = int( seed * obj.m_nTotChannels ); unsigned int channelInModule = flatChannel & ( obj.m_nChannelsInModule - 1u ); @@ -112,25 +112,26 @@ namespace LHCb::Detector { station = 2; module = flatChannel - obj.m_nModulesT1; } - return LHCb::FTChannelID( LHCb::FTChannelID::StationID{station}, LHCb::FTChannelID::LayerID{layer}, - LHCb::FTChannelID::QuarterID{quarter}, LHCb::FTChannelID::ModuleID{module}, + return FTChannelID( FTChannelID::StationID{station}, FTChannelID::LayerID{layer}, + FTChannelID::QuarterID{quarter}, FTChannelID::ModuleID{module}, channelInModule ); } /// Get a random FTChannelID from a pseudoChannel (useful for the AP noise) - LHCb::FTChannelID getRandomChannelFromPseudo( const int pseudoChannel, const float seed ) const { - if ( seed < 0.f || seed > 1.f ) return LHCb::FTChannelID::kInvalidChannel(); + FTChannelID getRandomChannelFromPseudo( const int pseudoChannel, const float seed ) const { + //FIXME: moduleDet->channelFromPseudo returns invalidChannel all the time + if ( seed < 0.f || seed > 1.f ) return FTChannelID::kInvalidChannel(); const auto& obj = this->access(); unsigned int flatQuarter = int( seed * obj.m_nTotQuarters ); - auto quarter = LHCb::FTChannelID::QuarterID{flatQuarter & ( obj.m_nQuarters - 1u )}; + auto quarter = FTChannelID::QuarterID{flatQuarter & ( obj.m_nQuarters - 1u )}; flatQuarter /= obj.m_nQuarters; - auto layer = LHCb::FTChannelID::LayerID{flatQuarter & ( obj.m_nLayers - 1u )}; + auto layer = FTChannelID::LayerID{flatQuarter & ( obj.m_nLayers - 1u )}; flatQuarter /= obj.m_nLayers; - auto station = LHCb::FTChannelID::StationID{( flatQuarter & obj.m_stations.size() ) + 1u}; + auto station = FTChannelID::StationID{( flatQuarter & obj.m_stations.size() ) + 1u}; - auto module = LHCb::FTChannelID::ModuleID{pseudoChannel / obj.m_nChannelsInModule}; - const DeFTModule* moduleDet = findModule( LHCb::FTChannelID( station, layer, quarter, module, 0u ) ); - return moduleDet ? moduleDet->channelFromPseudo( pseudoChannel & ( obj.m_nChannelsInModule - 1u ) ) : LHCb::FTChannelID::kInvalidChannel(); + auto module = FTChannelID::ModuleID{pseudoChannel / obj.m_nChannelsInModule}; + const DeFTModule* moduleDet = findModule( FTChannelID( station, layer, quarter, module, 0u ) ); + return moduleDet ? moduleDet->channelFromPseudo( pseudoChannel & ( obj.m_nChannelsInModule - 1u ) ) : FTChannelID::kInvalidChannel(); } }; diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 21171694..993838ce 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -12,7 +12,6 @@ #include "Core/DeIOV.h" #include "Detector/FT/DeFTQuarter.h" -#include "Detector/FT/FTChannelID.h" #include @@ -39,7 +38,7 @@ namespace LHCb::Detector { * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTQuarter& findQuarter( const LHCb::FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTQuarter& findQuarter( const FTChannelID& aChannel ) const { return this->access()->m_quarters[to_unsigned( aChannel.quarter() )]; } }; diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 3bdd8f2c..e208bbb0 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -12,7 +12,6 @@ #include "Core/DeIOV.h" #include "Detector/FT/DeFTMat.h" -#include "Detector/FT/FTChannelID.h" #include @@ -36,15 +35,15 @@ namespace LHCb::Detector { } // End namespace detail template struct DeFTModuleElement : DeIOVElement { - [[nodiscard]] const DeFTMat& findMat( const LHCb::FTChannelID& id ) const { + [[nodiscard]] const DeFTMat& findMat( const FTChannelID& id ) const { return this->access()->m_mats[to_unsigned( id.mat() )]; } - [[nodiscard]] LHCb::FTChannelID channelFromPseudo( const int pseudoChannel ) const { + [[nodiscard]] FTChannelID channelFromPseudo( const int pseudoChannel ) const { // const auto& obj = this->access(); // int channelInModule = pseudoChannel & ( obj.m_nChannelsInModule - 1u ); // if ( obj.m_reversed ) { channelInModule = obj.m_nChannelsInModule - 1 - channelInModule; } // return LHCb::FTChannelID( elementID() + channelInModule ); - return LHCb::FTChannelID::kInvalidChannel(); + return FTChannelID::kInvalidChannel(); } }; diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index 08081ede..155233ea 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -12,7 +12,6 @@ #include "Core/DeIOV.h" #include "Detector/FT/DeFTModule.h" -#include "Detector/FT/FTChannelID.h" namespace LHCb::Detector { @@ -37,7 +36,7 @@ namespace LHCb::Detector { * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTModule& findModule( const LHCb::FTChannelID aChannel ) const { + [[nodiscard]] const DeFTModule& findModule( const FTChannelID aChannel ) const { auto m = to_unsigned( aChannel.module() ); return this->access()->m_modules[m]; } diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index 21b43eb3..bc972fa7 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -12,7 +12,6 @@ #include "Core/DeIOV.h" #include "Detector/FT/DeFTLayer.h" -#include "Detector/FT/FTChannelID.h" namespace LHCb::Detector { @@ -37,7 +36,7 @@ namespace LHCb::Detector { * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTLayer& findLayer( const LHCb::FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTLayer& findLayer( const FTChannelID& aChannel ) const { return this->access()->m_layers[to_unsigned( aChannel.layer() )]; } }; diff --git a/Detector/FT/include/Detector/FT/FTChannelID.h b/Detector/FT/include/Detector/FT/FTChannelID.h index a74ebf5a..4b1062f9 100644 --- a/Detector/FT/include/Detector/FT/FTChannelID.h +++ b/Detector/FT/include/Detector/FT/FTChannelID.h @@ -12,7 +12,7 @@ #include #include -namespace LHCb { +namespace LHCb::Detector { /** @class FTChannelID FTChannelID.h * diff --git a/Detector/FT/src/DeFT.cpp b/Detector/FT/src/DeFT.cpp index 9ebea199..c4bb604a 100644 --- a/Detector/FT/src/DeFT.cpp +++ b/Detector/FT/src/DeFT.cpp @@ -29,14 +29,14 @@ LHCb::Detector::detail::DeFTLayerObject::DeFTLayerObject( const dd4hep::DetEleme dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) , m_quarters{ - {{de.child( "Q0" ), true, ctxt}, {de.child( "Q1" ), true, ctxt}, {de.child( "Q2" ), false, ctxt}, {de.child( "Q3" ), false, ctxt}}} {} + {{de.child( "Q0" ), true, ctxt}, {de.child( "Q1" ), true, ctxt}, {de.child( "Q2" ), false, ctxt}, {de.child( "Q3" ), false, ctxt}}} {}//FIXME Hardcoded LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetElement& de, bool rev, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) , - // XXX no always 6 modules ? + // FIXME no always 6 modules ? m_modules{{{de.child( "M0" ), rev, ctxt}, {de.child( "M1" ), rev, ctxt}, {de.child( "M2" ), rev, ctxt}, -- GitLab From 4154516ca6d1123862d5c70a4ed9d2dcc7bb1581 Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Tue, 21 Sep 2021 13:54:33 +0000 Subject: [PATCH 04/37] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Detector/-/jobs/16411992 --- Detector/FT/include/Detector/FT/DeFT.h | 55 +++++++++---------- Detector/FT/include/Detector/FT/DeFTLayer.h | 6 +- Detector/FT/include/Detector/FT/DeFTMat.h | 9 ++- Detector/FT/include/Detector/FT/DeFTModule.h | 10 ++-- Detector/FT/include/Detector/FT/DeFTQuarter.h | 4 +- Detector/FT/include/Detector/FT/DeFTStation.h | 10 ++-- Detector/FT/include/Detector/FT/FTChannelID.h | 2 +- Detector/FT/src/DeFT.cpp | 40 +++++++------- 8 files changed, 65 insertions(+), 71 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 12d26ca8..67682932 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -15,7 +15,7 @@ namespace DeFTLocation { // FT location defined in the XmlDDDB inline const std::string Default = "/dd/Structure/LHCb/AfterMagnetRegion/T/FT"; -} // namespace DeFTDetectorLocation +} // namespace DeFTLocation namespace LHCb::Detector { namespace detail { @@ -26,12 +26,12 @@ namespace LHCb::Detector { * \version 1.0 */ struct DeFTObject : DeIOVObject { - int m_version {dd4hep::_toInt( "FT:version" )}; // FT Geometry Version + int m_version{dd4hep::_toInt( "FT:version" )}; // FT Geometry Version int m_nModulesT1{dd4hep::_toInt( "FT:nModulesT1" )}; // Number of modules in T1 int m_nModulesT2{dd4hep::_toInt( "FT:nModulesT2" )}; // Number of modules in T2 int m_nModulesT3{dd4hep::_toInt( "FT:nModulesT3" )}; // Number of modules in T3 - int m_nLayers {dd4hep::_toInt( "FT:nLayers" )}; // Number of layers per station - int m_nQuarters {dd4hep::_toInt( "FT:nQuarters" )}; // Number of quarters per layer + int m_nLayers{dd4hep::_toInt( "FT:nLayers" )}; // Number of layers per station + int m_nQuarters{dd4hep::_toInt( "FT:nQuarters" )}; // Number of quarters per layer int m_nChannelsInModule{dd4hep::_toInt( "FT:nChannelsInModule" )}; // Number of channels per SiPM int m_nTotChannels; int m_nTotQuarters; @@ -39,27 +39,27 @@ namespace LHCb::Detector { std::array m_stations; DeFTObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); }; - + } // End namespace detail - /** - * FT interface - * - * \author Louis Henry - * \date 2021-09-21 - * \version 1.0 - */ + /** + * FT interface + * + * \author Louis Henry + * \date 2021-09-21 + * \version 1.0 + */ template - struct DeFTElement : DeIOVElement { - int version() const {return this->access()->m_version;}; - + struct DeFTElement : DeIOVElement { + int version() const { return this->access()->m_version; }; + /** Find the FT Station corresponding to the channel id * @return Pointer to the relevant station */ [[nodiscard]] const DeFTStation& findStation( const FTChannelID& aChannel ) const { return this->access()->m_stations[to_unsigned( aChannel.station() ) - 1u]; } - + /** Find the FT Layer corresponding to the channel id * @return Pointer to the relevant layer */ @@ -67,7 +67,7 @@ namespace LHCb::Detector { const auto& s = findStation( aChannel ); return s.findLayer( aChannel ); } - + /** Find the FT Quarter corresponding to the channel id * @return Pointer to the relevant quarter */ @@ -75,7 +75,7 @@ namespace LHCb::Detector { const auto& l = findLayer( aChannel ); return l.findQuarter( aChannel ); } - + /** Find the FT Module corresponding to the channel id * @return Pointer to the relevant module */ @@ -83,7 +83,7 @@ namespace LHCb::Detector { const auto& q = findQuarter( aChannel ); return q.findModule( aChannel ); } - + /** Find the FT Mat corresponding to the channel id * @return Pointer to the relevant module */ @@ -95,7 +95,7 @@ namespace LHCb::Detector { /// Get a random FTChannelID (useful for the thermal noise, which is ~flat) FTChannelID getRandomChannelFromSeed( const float seed ) const { if ( seed < 0.f || seed > 1.f ) return FTChannelID::kInvalidChannel(); - const auto& obj = this->access(); + const auto& obj = this->access(); unsigned int flatChannel = int( seed * obj.m_nTotChannels ); unsigned int channelInModule = flatChannel & ( obj.m_nChannelsInModule - 1u ); flatChannel /= obj.m_nChannelsInModule; @@ -112,16 +112,15 @@ namespace LHCb::Detector { station = 2; module = flatChannel - obj.m_nModulesT1; } - return FTChannelID( FTChannelID::StationID{station}, FTChannelID::LayerID{layer}, - FTChannelID::QuarterID{quarter}, FTChannelID::ModuleID{module}, - channelInModule ); + return FTChannelID( FTChannelID::StationID{station}, FTChannelID::LayerID{layer}, FTChannelID::QuarterID{quarter}, + FTChannelID::ModuleID{module}, channelInModule ); } /// Get a random FTChannelID from a pseudoChannel (useful for the AP noise) FTChannelID getRandomChannelFromPseudo( const int pseudoChannel, const float seed ) const { - //FIXME: moduleDet->channelFromPseudo returns invalidChannel all the time + // FIXME: moduleDet->channelFromPseudo returns invalidChannel all the time if ( seed < 0.f || seed > 1.f ) return FTChannelID::kInvalidChannel(); - const auto& obj = this->access(); + const auto& obj = this->access(); unsigned int flatQuarter = int( seed * obj.m_nTotQuarters ); auto quarter = FTChannelID::QuarterID{flatQuarter & ( obj.m_nQuarters - 1u )}; flatQuarter /= obj.m_nQuarters; @@ -131,11 +130,11 @@ namespace LHCb::Detector { auto module = FTChannelID::ModuleID{pseudoChannel / obj.m_nChannelsInModule}; const DeFTModule* moduleDet = findModule( FTChannelID( station, layer, quarter, module, 0u ) ); - return moduleDet ? moduleDet->channelFromPseudo( pseudoChannel & ( obj.m_nChannelsInModule - 1u ) ) : FTChannelID::kInvalidChannel(); + return moduleDet ? moduleDet->channelFromPseudo( pseudoChannel & ( obj.m_nChannelsInModule - 1u ) ) + : FTChannelID::kInvalidChannel(); } - }; - + using DeFT = DeFTElement; } // End namespace LHCb::Detector diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 993838ce..66d1758a 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -27,20 +27,20 @@ namespace LHCb::Detector { */ struct DeFTLayerObject : DeIOVObject { /// Reference to the static information of the quarters - std::array m_quarters;//FIXME hardcoded + std::array m_quarters; // FIXME hardcoded DeFTLayerObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); }; } // End namespace detail template - struct DeFTLayerElement : DeIOVElement { + struct DeFTLayerElement : DeIOVElement { /** Const method to return the layer for a given channel id * @param aChannel an FT channel id * @return pointer to detector element */ [[nodiscard]] const DeFTQuarter& findQuarter( const FTChannelID& aChannel ) const { return this->access()->m_quarters[to_unsigned( aChannel.quarter() )]; - } + } }; using DeFTLayer = DeFTLayerElement; diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index 1db9c48c..f2a0a0e0 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -11,8 +11,8 @@ #pragma once #include "Core/DeIOV.h" -#include "Detector/FT/FTConstants.h" #include "Detector/FT/FTChannelID.h" +#include "Detector/FT/FTConstants.h" #include #include @@ -38,9 +38,8 @@ namespace LHCb::Detector { }; } // End namespace detail template - struct DeFTMatElement : DeIOVElement { - }; - + struct DeFTMatElement : DeIOVElement {}; + using DeFTMat = DeFTMatElement; - + } // End namespace LHCb::Detector diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index e208bbb0..6fb1af91 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -27,14 +27,13 @@ namespace LHCb::Detector { */ struct DeFTModuleObject : DeIOVObject { /// Reference to the static information of mats - bool m_reversed; - std::array m_mats;//FIXME hardcoded + bool m_reversed; + std::array m_mats; // FIXME hardcoded DeFTModuleObject( const dd4hep::DetElement& de, bool rev, dd4hep::cond::ConditionUpdateContext& ctxt ); - }; } // End namespace detail template - struct DeFTModuleElement : DeIOVElement { + struct DeFTModuleElement : DeIOVElement { [[nodiscard]] const DeFTMat& findMat( const FTChannelID& id ) const { return this->access()->m_mats[to_unsigned( id.mat() )]; } @@ -45,9 +44,8 @@ namespace LHCb::Detector { // return LHCb::FTChannelID( elementID() + channelInModule ); return FTChannelID::kInvalidChannel(); } - }; - + using DeFTModule = DeFTModuleElement; } // End namespace LHCb::Detector diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index 155233ea..b1fdb39c 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -25,13 +25,13 @@ namespace LHCb::Detector { */ struct DeFTQuarterObject : DeIOVObject { /// Reference to the static information of modules - std::array m_modules;//FIXME hardcoded + std::array m_modules; // FIXME hardcoded DeFTQuarterObject( const dd4hep::DetElement& de, bool rev, dd4hep::cond::ConditionUpdateContext& ctxt ); }; } // End namespace detail template - struct DeFTQuarterElement : DeIOVElement { + struct DeFTQuarterElement : DeIOVElement { /** Const method to return the layer for a given channel id * @param aChannel an FT channel id * @return pointer to detector element diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index bc972fa7..a57cbfd6 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -16,7 +16,7 @@ namespace LHCb::Detector { namespace detail { - + /** * Generic FT iov dependent detector element of a FT station * \author Markus Frank @@ -25,22 +25,22 @@ namespace LHCb::Detector { */ struct DeFTStationObject : DeIOVObject { /// Reference to the static information of the layers - std::array m_layers;//FIXME hardcoded + std::array m_layers; // FIXME hardcoded DeFTStationObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); }; } // End namespace detail template - struct DeFTStationElement : DeIOVElement { + struct DeFTStationElement : DeIOVElement { /** Const method to return the layer for a given channel id * @param aChannel an FT channel id * @return pointer to detector element */ [[nodiscard]] const DeFTLayer& findLayer( const FTChannelID& aChannel ) const { return this->access()->m_layers[to_unsigned( aChannel.layer() )]; - } + } }; - + using DeFTStation = DeFTStationElement; } // End namespace LHCb::Detector diff --git a/Detector/FT/include/Detector/FT/FTChannelID.h b/Detector/FT/include/Detector/FT/FTChannelID.h index 4b1062f9..d7c60fa8 100644 --- a/Detector/FT/include/Detector/FT/FTChannelID.h +++ b/Detector/FT/include/Detector/FT/FTChannelID.h @@ -227,7 +227,7 @@ namespace LHCb::Detector { }; // class FTChannelID -} // namespace LHCb +} // namespace LHCb::Detector // ----------------------------------------------------------------------------- // end of class diff --git a/Detector/FT/src/DeFT.cpp b/Detector/FT/src/DeFT.cpp index c4bb604a..aa6dcb49 100644 --- a/Detector/FT/src/DeFT.cpp +++ b/Detector/FT/src/DeFT.cpp @@ -23,36 +23,34 @@ LHCb::Detector::detail::DeFTObject::DeFTObject( const dd4hep::DetElement& LHCb::Detector::detail::DeFTStationObject::DeFTStationObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) - , m_layers{{{de.child( "X1" ), ctxt}, {de.child( "U" ), ctxt}, {de.child( "V" ), ctxt}, {de.child( "X2" ), ctxt}}} {} + , m_layers{{{de.child( "X1" ), ctxt}, {de.child( "U" ), ctxt}, {de.child( "V" ), ctxt}, {de.child( "X2" ), ctxt}}} { +} LHCb::Detector::detail::DeFTLayerObject::DeFTLayerObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) - , m_quarters{ - {{de.child( "Q0" ), true, ctxt}, {de.child( "Q1" ), true, ctxt}, {de.child( "Q2" ), false, ctxt}, {de.child( "Q3" ), false, ctxt}}} {}//FIXME Hardcoded + , m_quarters{{{de.child( "Q0" ), true, ctxt}, + {de.child( "Q1" ), true, ctxt}, + {de.child( "Q2" ), false, ctxt}, + {de.child( "Q3" ), false, ctxt}}} {} // FIXME Hardcoded -LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetElement& de, - bool rev, +LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetElement& de, bool rev, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) , - // FIXME no always 6 modules ? - m_modules{{{de.child( "M0" ), rev, ctxt}, - {de.child( "M1" ), rev, ctxt}, - {de.child( "M2" ), rev, ctxt}, - {de.child( "M3" ), rev, ctxt}, - {de.child( "M4" ), rev, ctxt}, - {de.child( "M5" ), rev, ctxt}}} {} - -LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetElement& de, - bool rev, + // FIXME no always 6 modules ? + m_modules{{{de.child( "M0" ), rev, ctxt}, + {de.child( "M1" ), rev, ctxt}, + {de.child( "M2" ), rev, ctxt}, + {de.child( "M3" ), rev, ctxt}, + {de.child( "M4" ), rev, ctxt}, + {de.child( "M5" ), rev, ctxt}}} {} + +LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetElement& de, bool rev, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) , m_reversed{rev} , m_mats{{{de.child( "Mat0" ), ctxt}, - {de.child( "Mat1" ), ctxt}, - {de.child( "Mat2" ), ctxt}, - {de.child( "Mat3" ), ctxt}}} {} - - - + {de.child( "Mat1" ), ctxt}, + {de.child( "Mat2" ), ctxt}, + {de.child( "Mat3" ), ctxt}}} {} -- GitLab From 61fa8c06fb0e911a158cd6d5abd147fb410dbcac Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Fri, 24 Sep 2021 14:55:42 +0200 Subject: [PATCH 05/37] Removed hardcoded constants, added bare minimum methods. --- Detector/FT/include/Detector/FT/DeFTLayer.h | 5 +- Detector/FT/include/Detector/FT/DeFTModule.h | 27 +++++--- Detector/FT/include/Detector/FT/DeFTQuarter.h | 5 +- Detector/FT/include/Detector/FT/DeFTStation.h | 5 +- Detector/FT/include/Detector/FT/FTChannelID.h | 3 + Detector/FT/include/Detector/FT/FTConstants.h | 5 ++ Detector/FT/src/DeFT.cpp | 62 ++++++++++++------- 7 files changed, 75 insertions(+), 37 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 66d1758a..022ae321 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -27,8 +27,9 @@ namespace LHCb::Detector { */ struct DeFTLayerObject : DeIOVObject { /// Reference to the static information of the quarters - std::array m_quarters; // FIXME hardcoded - DeFTLayerObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); + unsigned int m_id; + std::array m_quarters; + DeFTLayerObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iLayer, unsigned int stationID ); }; } // End namespace detail diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 6fb1af91..e2aac9ab 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -27,22 +27,33 @@ namespace LHCb::Detector { */ struct DeFTModuleObject : DeIOVObject { /// Reference to the static information of mats + unsigned int m_id; + int m_nChannelsInModule{dd4hep::_toInt( "FT:nChannelsInModule" )}; + std::array m_mats; bool m_reversed; - std::array m_mats; // FIXME hardcoded - DeFTModuleObject( const dd4hep::DetElement& de, bool rev, dd4hep::cond::ConditionUpdateContext& ctxt ); + FTChannelID m_elementid; + DeFTModuleObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iModule, unsigned int quarterID ); + /// Convert local position to global position + ROOT::Math::XYZPoint localToGlobal( const ROOT::Math::XYZPoint& point ) const { + return ROOT::Math::XYZPoint( this->detectorAlignment.localToWorld( ROOT::Math::XYZVector( point ) ) ); + } }; } // End namespace detail template - struct DeFTModuleElement : DeIOVElement { + struct DeFTModuleElement : DeIOVElement { + [[nodiscard]] const DeFTMat& findMat( const FTChannelID& id ) const { return this->access()->m_mats[to_unsigned( id.mat() )]; } + [[nodiscard]] const FTChannelID& elementID( ) const { + return this->access()->m_elementid; + } + [[nodiscard]] FTChannelID channelFromPseudo( const int pseudoChannel ) const { - // const auto& obj = this->access(); - // int channelInModule = pseudoChannel & ( obj.m_nChannelsInModule - 1u ); - // if ( obj.m_reversed ) { channelInModule = obj.m_nChannelsInModule - 1 - channelInModule; } - // return LHCb::FTChannelID( elementID() + channelInModule ); - return FTChannelID::kInvalidChannel(); + const auto& obj = this->access(); + int channelInModule = pseudoChannel & ( obj.m_nChannelsInModule - 1u ); + if ( obj.m_reversed ) { channelInModule = obj.m_nChannelsInModule - 1 - channelInModule; } + return FTChannelID( this->elementID() + channelInModule ); } }; diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index b1fdb39c..59905fff 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -25,8 +25,9 @@ namespace LHCb::Detector { */ struct DeFTQuarterObject : DeIOVObject { /// Reference to the static information of modules - std::array m_modules; // FIXME hardcoded - DeFTQuarterObject( const dd4hep::DetElement& de, bool rev, dd4hep::cond::ConditionUpdateContext& ctxt ); + unsigned int m_id; + std::array m_modules; + DeFTQuarterObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iQuarter, unsigned int layerID ); }; } // End namespace detail diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index a57cbfd6..38f2cdea 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -25,8 +25,9 @@ namespace LHCb::Detector { */ struct DeFTStationObject : DeIOVObject { /// Reference to the static information of the layers - std::array m_layers; // FIXME hardcoded - DeFTStationObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); + unsigned int m_id; + std::array m_layers; + DeFTStationObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iStation ); }; } // End namespace detail diff --git a/Detector/FT/include/Detector/FT/FTChannelID.h b/Detector/FT/include/Detector/FT/FTChannelID.h index d7c60fa8..611f1b74 100644 --- a/Detector/FT/include/Detector/FT/FTChannelID.h +++ b/Detector/FT/include/Detector/FT/FTChannelID.h @@ -93,6 +93,9 @@ namespace LHCb::Detector { /// Constructor from int constexpr explicit FTChannelID( unsigned int id ) : m_channelID{id} {} + // /// Constructor from int + // constexpr explicit FTChannelID( const FTChannelID& id ) : m_channelID{id.channelID()} {} + /// Explicit constructor from the geometrical location constexpr FTChannelID( StationID station, LayerID layer, QuarterID quarter, ModuleID module, MatID mat, unsigned int sipm, unsigned int channel ) diff --git a/Detector/FT/include/Detector/FT/FTConstants.h b/Detector/FT/include/Detector/FT/FTConstants.h index 04aa0798..16726768 100644 --- a/Detector/FT/include/Detector/FT/FTConstants.h +++ b/Detector/FT/include/Detector/FT/FTConstants.h @@ -20,6 +20,11 @@ namespace LHCb::Detector { MODULE = 1 << 4, MAT = 1 << 5 }; + constexpr unsigned int nStations = 3; + constexpr unsigned int nLayers = 4; + constexpr unsigned int nQuarters = 4; + constexpr unsigned int nModules = 6; + constexpr unsigned int nMats = 4; } } // End namespace LHCb::Detector diff --git a/Detector/FT/src/DeFT.cpp b/Detector/FT/src/DeFT.cpp index aa6dcb49..47fc1de4 100644 --- a/Detector/FT/src/DeFT.cpp +++ b/Detector/FT/src/DeFT.cpp @@ -18,39 +18,55 @@ LHCb::Detector::detail::DeFTObject::DeFTObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) - , m_stations{{{de.child( "T1" ), ctxt}, {de.child( "T2" ), ctxt}, {de.child( "T3" ), ctxt}}} {} + , m_stations{{{de.child( "T1" ), ctxt, 1}, + {de.child( "T2" ), ctxt, 2}, + {de.child( "T3" ), ctxt, 3}}} {} LHCb::Detector::detail::DeFTStationObject::DeFTStationObject( const dd4hep::DetElement& de, - dd4hep::cond::ConditionUpdateContext& ctxt ) + dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iStation ) : DeIOVObject( de, ctxt ) - , m_layers{{{de.child( "X1" ), ctxt}, {de.child( "U" ), ctxt}, {de.child( "V" ), ctxt}, {de.child( "X2" ), ctxt}}} { -} + , m_id{iStation} + , m_layers{{{de.child( "X1" ), ctxt, 0, m_id}, + {de.child( "U" ), ctxt, 1, m_id}, + {de.child( "V" ), ctxt, 2, m_id}, + {de.child( "X2" ), ctxt, 3, m_id}}} {} LHCb::Detector::detail::DeFTLayerObject::DeFTLayerObject( const dd4hep::DetElement& de, - dd4hep::cond::ConditionUpdateContext& ctxt ) + dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iLayer, unsigned int stationID ) : DeIOVObject( de, ctxt ) - , m_quarters{{{de.child( "Q0" ), true, ctxt}, - {de.child( "Q1" ), true, ctxt}, - {de.child( "Q2" ), false, ctxt}, - {de.child( "Q3" ), false, ctxt}}} {} // FIXME Hardcoded + , m_id{(stationID*FT::nLayers+iLayer)} + , m_quarters{{{de.child( "Q0" ), ctxt, 0, m_id}, + {de.child( "Q1" ), ctxt, 1, m_id}, + {de.child( "Q2" ), ctxt, 2, m_id}, + {de.child( "Q3" ), ctxt, 3, m_id}}} {} -LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetElement& de, bool rev, - dd4hep::cond::ConditionUpdateContext& ctxt ) +LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetElement& de, + dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iQuarter, unsigned int layerID ) : DeIOVObject( de, ctxt ) - , - // FIXME no always 6 modules ? - m_modules{{{de.child( "M0" ), rev, ctxt}, - {de.child( "M1" ), rev, ctxt}, - {de.child( "M2" ), rev, ctxt}, - {de.child( "M3" ), rev, ctxt}, - {de.child( "M4" ), rev, ctxt}, - {de.child( "M5" ), rev, ctxt}}} {} + , m_id{layerID*FT::nQuarters+iQuarter} +// FIXME no always 6 modules ? + , m_modules{{{de.child( "M0" ), ctxt, 0, m_id}, + {de.child( "M1" ), ctxt, 1, m_id}, + {de.child( "M2" ), ctxt, 2, m_id}, + {de.child( "M3" ), ctxt, 3, m_id}, + {de.child( "M4" ), ctxt, 4, m_id}, + {de.child( "M5" ), ctxt, 5, m_id}}} {} -LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetElement& de, bool rev, - dd4hep::cond::ConditionUpdateContext& ctxt ) +LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iModule, unsigned int quarterID ) : DeIOVObject( de, ctxt ) - , m_reversed{rev} + , m_id{quarterID*FT::nModules+iModule} , m_mats{{{de.child( "Mat0" ), ctxt}, {de.child( "Mat1" ), ctxt}, {de.child( "Mat2" ), ctxt}, - {de.child( "Mat3" ), ctxt}}} {} + {de.child( "Mat3" ), ctxt}}} { + //Is reversed? + const auto firstPoint = this->localToGlobal( {-1, 0, 0} ); + const auto lastPoint = this->localToGlobal( { 1, 0, 0} ); + m_reversed = std::abs( firstPoint.x() ) > std::abs( lastPoint.x() ); + //Build the FTChannelID + auto localModuleID = FTChannelID::ModuleID {static_cast(m_id%FT::nModules)}; + auto localQuarterID = FTChannelID::QuarterID{static_cast(m_id%(FT::nModules*FT::nQuarters))}; + auto localLayerID = FTChannelID::LayerID {static_cast(m_id%(FT::nModules*FT::nQuarters*FT::nLayers))}; + auto localStationID = FTChannelID::StationID{static_cast(m_id/(FT::nModules*FT::nQuarters*FT::nLayers))}; + m_elementid = FTChannelID(localStationID,localLayerID,localQuarterID,localModuleID,0); +} -- GitLab From ce0f2e615416200ef780a0eeb37df8a75747ad2d Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Fri, 24 Sep 2021 12:56:31 +0000 Subject: [PATCH 06/37] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Detector/-/jobs/16485073 --- Detector/FT/include/Detector/FT/DeFTLayer.h | 5 +- Detector/FT/include/Detector/FT/DeFTModule.h | 25 +++---- Detector/FT/include/Detector/FT/DeFTQuarter.h | 5 +- Detector/FT/include/Detector/FT/DeFTStation.h | 5 +- Detector/FT/include/Detector/FT/FTChannelID.h | 2 +- Detector/FT/include/Detector/FT/FTConstants.h | 2 +- Detector/FT/src/DeFT.cpp | 74 ++++++++++--------- 7 files changed, 62 insertions(+), 56 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 022ae321..1e6c77c5 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -27,9 +27,10 @@ namespace LHCb::Detector { */ struct DeFTLayerObject : DeIOVObject { /// Reference to the static information of the quarters - unsigned int m_id; + unsigned int m_id; std::array m_quarters; - DeFTLayerObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iLayer, unsigned int stationID ); + DeFTLayerObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iLayer, + unsigned int stationID ); }; } // End namespace detail diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index e2aac9ab..62b39749 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -27,12 +27,13 @@ namespace LHCb::Detector { */ struct DeFTModuleObject : DeIOVObject { /// Reference to the static information of mats - unsigned int m_id; - int m_nChannelsInModule{dd4hep::_toInt( "FT:nChannelsInModule" )}; - std::array m_mats; - bool m_reversed; - FTChannelID m_elementid; - DeFTModuleObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iModule, unsigned int quarterID ); + unsigned int m_id; + int m_nChannelsInModule{dd4hep::_toInt( "FT:nChannelsInModule" )}; + std::array m_mats; + bool m_reversed; + FTChannelID m_elementid; + DeFTModuleObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iModule, + unsigned int quarterID ); /// Convert local position to global position ROOT::Math::XYZPoint localToGlobal( const ROOT::Math::XYZPoint& point ) const { return ROOT::Math::XYZPoint( this->detectorAlignment.localToWorld( ROOT::Math::XYZVector( point ) ) ); @@ -40,18 +41,16 @@ namespace LHCb::Detector { }; } // End namespace detail template - struct DeFTModuleElement : DeIOVElement { + struct DeFTModuleElement : DeIOVElement { [[nodiscard]] const DeFTMat& findMat( const FTChannelID& id ) const { return this->access()->m_mats[to_unsigned( id.mat() )]; } - [[nodiscard]] const FTChannelID& elementID( ) const { - return this->access()->m_elementid; - } - + [[nodiscard]] const FTChannelID& elementID() const { return this->access()->m_elementid; } + [[nodiscard]] FTChannelID channelFromPseudo( const int pseudoChannel ) const { - const auto& obj = this->access(); - int channelInModule = pseudoChannel & ( obj.m_nChannelsInModule - 1u ); + const auto& obj = this->access(); + int channelInModule = pseudoChannel & ( obj.m_nChannelsInModule - 1u ); if ( obj.m_reversed ) { channelInModule = obj.m_nChannelsInModule - 1 - channelInModule; } return FTChannelID( this->elementID() + channelInModule ); } diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index 59905fff..de8f9328 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -25,9 +25,10 @@ namespace LHCb::Detector { */ struct DeFTQuarterObject : DeIOVObject { /// Reference to the static information of modules - unsigned int m_id; + unsigned int m_id; std::array m_modules; - DeFTQuarterObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iQuarter, unsigned int layerID ); + DeFTQuarterObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, + unsigned int iQuarter, unsigned int layerID ); }; } // End namespace detail diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index 38f2cdea..0ab30c2b 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -25,9 +25,10 @@ namespace LHCb::Detector { */ struct DeFTStationObject : DeIOVObject { /// Reference to the static information of the layers - unsigned int m_id; + unsigned int m_id; std::array m_layers; - DeFTStationObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iStation ); + DeFTStationObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, + unsigned int iStation ); }; } // End namespace detail diff --git a/Detector/FT/include/Detector/FT/FTChannelID.h b/Detector/FT/include/Detector/FT/FTChannelID.h index 611f1b74..bbc76ca9 100644 --- a/Detector/FT/include/Detector/FT/FTChannelID.h +++ b/Detector/FT/include/Detector/FT/FTChannelID.h @@ -95,7 +95,7 @@ namespace LHCb::Detector { // /// Constructor from int // constexpr explicit FTChannelID( const FTChannelID& id ) : m_channelID{id.channelID()} {} - + /// Explicit constructor from the geometrical location constexpr FTChannelID( StationID station, LayerID layer, QuarterID quarter, ModuleID module, MatID mat, unsigned int sipm, unsigned int channel ) diff --git a/Detector/FT/include/Detector/FT/FTConstants.h b/Detector/FT/include/Detector/FT/FTConstants.h index 16726768..f00a4c24 100644 --- a/Detector/FT/include/Detector/FT/FTConstants.h +++ b/Detector/FT/include/Detector/FT/FTConstants.h @@ -25,6 +25,6 @@ namespace LHCb::Detector { constexpr unsigned int nQuarters = 4; constexpr unsigned int nModules = 6; constexpr unsigned int nMats = 4; - } + } // namespace FT } // End namespace LHCb::Detector diff --git a/Detector/FT/src/DeFT.cpp b/Detector/FT/src/DeFT.cpp index 47fc1de4..f2647ee0 100644 --- a/Detector/FT/src/DeFT.cpp +++ b/Detector/FT/src/DeFT.cpp @@ -18,55 +18,59 @@ LHCb::Detector::detail::DeFTObject::DeFTObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) - , m_stations{{{de.child( "T1" ), ctxt, 1}, - {de.child( "T2" ), ctxt, 2}, - {de.child( "T3" ), ctxt, 3}}} {} + , m_stations{{{de.child( "T1" ), ctxt, 1}, {de.child( "T2" ), ctxt, 2}, {de.child( "T3" ), ctxt, 3}}} {} LHCb::Detector::detail::DeFTStationObject::DeFTStationObject( const dd4hep::DetElement& de, - dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iStation ) + dd4hep::cond::ConditionUpdateContext& ctxt, + unsigned int iStation ) : DeIOVObject( de, ctxt ) , m_id{iStation} - , m_layers{{{de.child( "X1" ), ctxt, 0, m_id}, - {de.child( "U" ), ctxt, 1, m_id}, - {de.child( "V" ), ctxt, 2, m_id}, - {de.child( "X2" ), ctxt, 3, m_id}}} {} + , m_layers{{{de.child( "X1" ), ctxt, 0, m_id}, + {de.child( "U" ), ctxt, 1, m_id}, + {de.child( "V" ), ctxt, 2, m_id}, + {de.child( "X2" ), ctxt, 3, m_id}}} {} LHCb::Detector::detail::DeFTLayerObject::DeFTLayerObject( const dd4hep::DetElement& de, - dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iLayer, unsigned int stationID ) + dd4hep::cond::ConditionUpdateContext& ctxt, + unsigned int iLayer, unsigned int stationID ) : DeIOVObject( de, ctxt ) - , m_id{(stationID*FT::nLayers+iLayer)} - , m_quarters{{{de.child( "Q0" ), ctxt, 0, m_id}, - {de.child( "Q1" ), ctxt, 1, m_id}, - {de.child( "Q2" ), ctxt, 2, m_id}, - {de.child( "Q3" ), ctxt, 3, m_id}}} {} + , m_id{( stationID * FT::nLayers + iLayer )} + , m_quarters{{{de.child( "Q0" ), ctxt, 0, m_id}, + {de.child( "Q1" ), ctxt, 1, m_id}, + {de.child( "Q2" ), ctxt, 2, m_id}, + {de.child( "Q3" ), ctxt, 3, m_id}}} {} -LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetElement& de, - dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iQuarter, unsigned int layerID ) +LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetElement& de, + dd4hep::cond::ConditionUpdateContext& ctxt, + unsigned int iQuarter, unsigned int layerID ) : DeIOVObject( de, ctxt ) - , m_id{layerID*FT::nQuarters+iQuarter} -// FIXME no always 6 modules ? - , m_modules{{{de.child( "M0" ), ctxt, 0, m_id}, - {de.child( "M1" ), ctxt, 1, m_id}, - {de.child( "M2" ), ctxt, 2, m_id}, - {de.child( "M3" ), ctxt, 3, m_id}, - {de.child( "M4" ), ctxt, 4, m_id}, - {de.child( "M5" ), ctxt, 5, m_id}}} {} + , m_id{layerID * FT::nQuarters + iQuarter} // FIXME no always 6 modules ? + , m_modules{{{de.child( "M0" ), ctxt, 0, m_id}, + {de.child( "M1" ), ctxt, 1, m_id}, + {de.child( "M2" ), ctxt, 2, m_id}, + {de.child( "M3" ), ctxt, 3, m_id}, + {de.child( "M4" ), ctxt, 4, m_id}, + {de.child( "M5" ), ctxt, 5, m_id}}} {} -LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iModule, unsigned int quarterID ) +LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetElement& de, + dd4hep::cond::ConditionUpdateContext& ctxt, + unsigned int iModule, unsigned int quarterID ) : DeIOVObject( de, ctxt ) - , m_id{quarterID*FT::nModules+iModule} + , m_id{quarterID * FT::nModules + iModule} , m_mats{{{de.child( "Mat0" ), ctxt}, {de.child( "Mat1" ), ctxt}, {de.child( "Mat2" ), ctxt}, {de.child( "Mat3" ), ctxt}}} { - //Is reversed? + // Is reversed? const auto firstPoint = this->localToGlobal( {-1, 0, 0} ); - const auto lastPoint = this->localToGlobal( { 1, 0, 0} ); - m_reversed = std::abs( firstPoint.x() ) > std::abs( lastPoint.x() ); - //Build the FTChannelID - auto localModuleID = FTChannelID::ModuleID {static_cast(m_id%FT::nModules)}; - auto localQuarterID = FTChannelID::QuarterID{static_cast(m_id%(FT::nModules*FT::nQuarters))}; - auto localLayerID = FTChannelID::LayerID {static_cast(m_id%(FT::nModules*FT::nQuarters*FT::nLayers))}; - auto localStationID = FTChannelID::StationID{static_cast(m_id/(FT::nModules*FT::nQuarters*FT::nLayers))}; - m_elementid = FTChannelID(localStationID,localLayerID,localQuarterID,localModuleID,0); + const auto lastPoint = this->localToGlobal( {1, 0, 0} ); + m_reversed = std::abs( firstPoint.x() ) > std::abs( lastPoint.x() ); + // Build the FTChannelID + auto localModuleID = FTChannelID::ModuleID{static_cast( m_id % FT::nModules )}; + auto localQuarterID = FTChannelID::QuarterID{static_cast( m_id % ( FT::nModules * FT::nQuarters ) )}; + auto localLayerID = + FTChannelID::LayerID{static_cast( m_id % ( FT::nModules * FT::nQuarters * FT::nLayers ) )}; + auto localStationID = + FTChannelID::StationID{static_cast( m_id / ( FT::nModules * FT::nQuarters * FT::nLayers ) )}; + m_elementid = FTChannelID( localStationID, localLayerID, localQuarterID, localModuleID, 0 ); } -- GitLab From 6dfd19d0196826889b3c584959064ae91c844a26 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Wed, 29 Sep 2021 17:10:09 +0200 Subject: [PATCH 07/37] Adding findX methods --- Detector/FT/include/Detector/FT/DeFT.h | 33 +++++++++++++++++++ Detector/FT/include/Detector/FT/DeFTLayer.h | 19 +++++++++++ Detector/FT/include/Detector/FT/DeFTModule.h | 10 ++++++ Detector/FT/include/Detector/FT/DeFTQuarter.h | 13 +++++++- Detector/FT/include/Detector/FT/DeFTStation.h | 12 +++++++ 5 files changed, 86 insertions(+), 1 deletion(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 67682932..50a7331b 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -53,6 +53,39 @@ namespace LHCb::Detector { struct DeFTElement : DeIOVElement { int version() const { return this->access()->m_version; }; + /** Find the FT Station corresponding to the point + * @return Pointer to the relevant station + */ + [[nodiscard]] const DeFTStation* findStation( const ROOT::Math::XYZPoint& aPoint ) const { + auto iS = std::find_if( std::begin( this->access()->m_stations ), std::end( this->access()->m_stations ), + [&aPoint]( const DeFTStation* s ) { return s ? s->isInside( aPoint ) : false; } ); + return iS != this->access()->m_stations.end() ? *iS : nullptr; + } + + /// Find the layer for a given XYZ point + const DeFTLayer* findLayer( const ROOT::Math::XYZPoint& aPoint ) const { + const DeFTStation* s = findStation( aPoint ); + return s ? s->findLayer( aPoint ) : nullptr; + } + + /// Find the quarter for a given XYZ point + const DeFTQuarter* findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { + const DeFTLayer* l = findLayer( aPoint ); + return l ? l->findQuarter( aPoint ) : nullptr; + } + + /// Find the module for a given XYZ point + const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { + const DeFTLayer* l = findLayer( aPoint ); // is faster than via DeFTQuarter + return l ? l->findModule( aPoint ) : nullptr; + } + + /// Find the mat for a given XYZ point + const DeFTMat* findMat( const ROOT::Math::XYZPoint& aPoint ) const { + const DeFTModule* m = findModule( aPoint ); + return m ? m->findMat( aPoint ) : nullptr; + } + /** Find the FT Station corresponding to the channel id * @return Pointer to the relevant station */ diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 1e6c77c5..af0c82f6 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -36,6 +36,25 @@ namespace LHCb::Detector { template struct DeFTLayerElement : DeIOVElement { + + unsigned int layerID() const{return this->access()->m_id;} + + /** Find the FT Quarter corresponding to the point + * @return Pointer to the relevant quarter + */ + [[nodiscard]] const DeFTQuarter* findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { + auto iQ = std::find_if( this->access()->m_quarters.begin(), this->access()->m_quarters.end(), + [&aPoint]( const DeFTQuarter* q ) { return q ? q->isInside( aPoint ) : false; } ); + return iQ != this->access()->m_quarters.end() ? *iQ : nullptr; + } + + /// Find the module for a given XYZ point + const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { + auto iM = std::find_if( this->access()->m_modules.begin(), this->access()->m_modules.end(), + [&aPoint]( const DeFTModule* m ) { return m ? m->isInside( aPoint ) : false; } ); + return iM != this->access()->m_modules.end() ? *iM : nullptr; + } + /** Const method to return the layer for a given channel id * @param aChannel an FT channel id * @return pointer to detector element diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 62b39749..b1ee7ef6 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -43,6 +43,16 @@ namespace LHCb::Detector { template struct DeFTModuleElement : DeIOVElement { + unsigned int moduleID() const{return this->access()->m_id;} + + /// Find the layer for a given XYZ point + const DeFTMat* findMat( const ROOT::Math::XYZPoint& aPoint ) const { + /// Find the layer and return a pointer to the layer from XYZ point + auto iter = std::find_if( this->access()->m_mats.begin(), this->access()->m_mats.end(), + [&aPoint]( const DeFTMat* m ) { return m ? m->isInside( aPoint ) : false; } ); + return iter != this->access()->m_mats.end() ? iter : nullptr; + } + [[nodiscard]] const DeFTMat& findMat( const FTChannelID& id ) const { return this->access()->m_mats[to_unsigned( id.mat() )]; } diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index de8f9328..38e53604 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -34,7 +34,18 @@ namespace LHCb::Detector { template struct DeFTQuarterElement : DeIOVElement { - /** Const method to return the layer for a given channel id + + unsigned int quarterID() const{return this->access()->m_id;} + + /** Find the FT Module corresponding to the point + * @return Pointer to the relevant module + */ + [[nodiscard]] const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { + auto iM = std::find_if( this->access()->m_modules.begin(), this->access()->m_modules.end(), + [&aPoint]( const DeFTModule* m ) { return m && m->isInside( aPoint ); } ); + return iM != this->access()->m_modules.end() ? *iM : nullptr; + } + /** Const method to return the module for a given channel id * @param aChannel an FT channel id * @return pointer to detector element */ diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index 0ab30c2b..958eeb85 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -34,6 +34,18 @@ namespace LHCb::Detector { template struct DeFTStationElement : DeIOVElement { + + unsigned int stationID() const{return this->access()->m_id;} + + /** Find the FT Layer corresponding to the point + * @return Pointer to the relevant layer + */ + [[nodiscard]] const DeFTLayer* findLayer( const ROOT::Math::XYZPoint& aPoint ) const { + auto iter = std::find_if( this->access()->m_layers.begin(), this->access()->m_layers.end(), + [&aPoint]( const DeFTLayer* l ) { return l ? l->isInside( aPoint ) : false; } ); + return iter != this->access()->m_layers.end() ? *iter : nullptr; + } + /** Const method to return the layer for a given channel id * @param aChannel an FT channel id * @return pointer to detector element -- GitLab From 44becfb068ac4b0190946cfc5486913f4c08e654 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Wed, 29 Sep 2021 22:50:57 +0200 Subject: [PATCH 08/37] Solved most compilation issues, still have some problems with TGeoNode --- Detector/FT/include/Detector/FT/DeFT.h | 30 +++++++++---------- Detector/FT/include/Detector/FT/DeFTLayer.h | 15 +++++----- Detector/FT/include/Detector/FT/DeFTMat.h | 6 +++- Detector/FT/include/Detector/FT/DeFTModule.h | 6 ++-- Detector/FT/include/Detector/FT/DeFTQuarter.h | 6 ++-- Detector/FT/include/Detector/FT/DeFTStation.h | 6 ++-- Detector/FT/src/DeFT.cpp | 14 ++++++--- 7 files changed, 46 insertions(+), 37 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 50a7331b..2dec242d 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -56,34 +56,34 @@ namespace LHCb::Detector { /** Find the FT Station corresponding to the point * @return Pointer to the relevant station */ - [[nodiscard]] const DeFTStation* findStation( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTStation& findStation( const ROOT::Math::XYZPoint& aPoint ) const { auto iS = std::find_if( std::begin( this->access()->m_stations ), std::end( this->access()->m_stations ), - [&aPoint]( const DeFTStation* s ) { return s ? s->isInside( aPoint ) : false; } ); - return iS != this->access()->m_stations.end() ? *iS : nullptr; + [&aPoint]( const DeFTStation& s ) { return s.isInside( aPoint ); } ); + return iS != this->access()->m_stations.end() ? *iS : "{}"; } /// Find the layer for a given XYZ point - const DeFTLayer* findLayer( const ROOT::Math::XYZPoint& aPoint ) const { - const DeFTStation* s = findStation( aPoint ); - return s ? s->findLayer( aPoint ) : nullptr; + [[nodiscard]] const DeFTLayer& findLayer( const ROOT::Math::XYZPoint& aPoint ) const { + auto s = findStation( aPoint ); + return s ? s.findLayer( aPoint ) : "{}"; } /// Find the quarter for a given XYZ point - const DeFTQuarter* findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { - const DeFTLayer* l = findLayer( aPoint ); - return l ? l->findQuarter( aPoint ) : nullptr; + [[nodiscard]] const DeFTQuarter& findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { + auto l = findLayer( aPoint ); + return l ? l.findQuarter( aPoint ) : "{}"; } /// Find the module for a given XYZ point - const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { - const DeFTLayer* l = findLayer( aPoint ); // is faster than via DeFTQuarter - return l ? l->findModule( aPoint ) : nullptr; + [[nodiscard]] const DeFTModule& findModule( const ROOT::Math::XYZPoint& aPoint ) const { + auto l = findLayer( aPoint ); // is faster than via DeFTQuarter + return l ? l.findModule( aPoint ) : "{}"; } /// Find the mat for a given XYZ point - const DeFTMat* findMat( const ROOT::Math::XYZPoint& aPoint ) const { - const DeFTModule* m = findModule( aPoint ); - return m ? m->findMat( aPoint ) : nullptr; + [[nodiscard]] const DeFTMat& findMat( const ROOT::Math::XYZPoint& aPoint ) const { + auto m = findModule( aPoint ); + return m ? m.findMat( aPoint ) : "{}"; } /** Find the FT Station corresponding to the channel id diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index af0c82f6..f8b06bdc 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -42,19 +42,18 @@ namespace LHCb::Detector { /** Find the FT Quarter corresponding to the point * @return Pointer to the relevant quarter */ - [[nodiscard]] const DeFTQuarter* findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTQuarter& findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { auto iQ = std::find_if( this->access()->m_quarters.begin(), this->access()->m_quarters.end(), - [&aPoint]( const DeFTQuarter* q ) { return q ? q->isInside( aPoint ) : false; } ); - return iQ != this->access()->m_quarters.end() ? *iQ : nullptr; + [&aPoint]( const DeFTQuarter* q ) { return q->isInside( aPoint ); } ); + return iQ != this->access()->m_quarters.end() ? *iQ : "{}"; } /// Find the module for a given XYZ point - const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { - auto iM = std::find_if( this->access()->m_modules.begin(), this->access()->m_modules.end(), - [&aPoint]( const DeFTModule* m ) { return m ? m->isInside( aPoint ) : false; } ); - return iM != this->access()->m_modules.end() ? *iM : nullptr; + [[nodiscard]] const DeFTModule& findModule( const ROOT::Math::XYZPoint& aPoint ) const { + auto iQ = findQuarter(aPoint); + return iQ ? iQ->findModule(aPoint) : "{}"; } - + /** Const method to return the layer for a given channel id * @param aChannel an FT channel id * @return pointer to detector element diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index f2a0a0e0..0b959006 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -34,11 +34,15 @@ namespace LHCb::Detector { int nChannelsInSiPM{}; int nSiPMsInMat{}; int nDiesInSiPM{}; + unsigned int matID; + DeFTMatObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iMat); using DeIOVObject::DeIOVObject; }; } // End namespace detail template - struct DeFTMatElement : DeIOVElement {}; + struct DeFTMatElement : DeIOVElement { + unsigned int matID(){return this->access()->matID;} + }; using DeFTMat = DeFTMatElement; diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index b1ee7ef6..390e9e08 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -46,11 +46,11 @@ namespace LHCb::Detector { unsigned int moduleID() const{return this->access()->m_id;} /// Find the layer for a given XYZ point - const DeFTMat* findMat( const ROOT::Math::XYZPoint& aPoint ) const { + const DeFTMat& findMat( const ROOT::Math::XYZPoint& aPoint ) const { /// Find the layer and return a pointer to the layer from XYZ point auto iter = std::find_if( this->access()->m_mats.begin(), this->access()->m_mats.end(), - [&aPoint]( const DeFTMat* m ) { return m ? m->isInside( aPoint ) : false; } ); - return iter != this->access()->m_mats.end() ? iter : nullptr; + [&aPoint]( const DeFTMat& m ) { return m.isInside( aPoint ); } ); + return iter != this->access()->m_mats.end() ? iter : "{}"; } [[nodiscard]] const DeFTMat& findMat( const FTChannelID& id ) const { diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index 38e53604..9b23e28d 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -40,10 +40,10 @@ namespace LHCb::Detector { /** Find the FT Module corresponding to the point * @return Pointer to the relevant module */ - [[nodiscard]] const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTModule& findModule( const ROOT::Math::XYZPoint& aPoint ) const { auto iM = std::find_if( this->access()->m_modules.begin(), this->access()->m_modules.end(), - [&aPoint]( const DeFTModule* m ) { return m && m->isInside( aPoint ); } ); - return iM != this->access()->m_modules.end() ? *iM : nullptr; + [&aPoint]( const DeFTModule* m ) { return m->isInside( aPoint ); } ); + return iM != this->access()->m_modules.end() ? *iM : "{}"; } /** Const method to return the module for a given channel id * @param aChannel an FT channel id diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index 958eeb85..2763adce 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -40,10 +40,10 @@ namespace LHCb::Detector { /** Find the FT Layer corresponding to the point * @return Pointer to the relevant layer */ - [[nodiscard]] const DeFTLayer* findLayer( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTLayer& findLayer( const ROOT::Math::XYZPoint& aPoint ) const { auto iter = std::find_if( this->access()->m_layers.begin(), this->access()->m_layers.end(), - [&aPoint]( const DeFTLayer* l ) { return l ? l->isInside( aPoint ) : false; } ); - return iter != this->access()->m_layers.end() ? *iter : nullptr; + [&aPoint]( const DeFTLayer* l ) { return l->isInside( aPoint );} ); + return iter != this->access()->m_layers.end() ? *iter : "{}"; } /** Const method to return the layer for a given channel id diff --git a/Detector/FT/src/DeFT.cpp b/Detector/FT/src/DeFT.cpp index f2647ee0..39bef9d5 100644 --- a/Detector/FT/src/DeFT.cpp +++ b/Detector/FT/src/DeFT.cpp @@ -57,10 +57,10 @@ LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetEle unsigned int iModule, unsigned int quarterID ) : DeIOVObject( de, ctxt ) , m_id{quarterID * FT::nModules + iModule} - , m_mats{{{de.child( "Mat0" ), ctxt}, - {de.child( "Mat1" ), ctxt}, - {de.child( "Mat2" ), ctxt}, - {de.child( "Mat3" ), ctxt}}} { + , m_mats{{{de.child( "Mat0" ), ctxt, 0}, + {de.child( "Mat1" ), ctxt, 1}, + {de.child( "Mat2" ), ctxt, 2}, + {de.child( "Mat3" ), ctxt, 3}}} { // Is reversed? const auto firstPoint = this->localToGlobal( {-1, 0, 0} ); const auto lastPoint = this->localToGlobal( {1, 0, 0} ); @@ -74,3 +74,9 @@ LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetEle FTChannelID::StationID{static_cast( m_id / ( FT::nModules * FT::nQuarters * FT::nLayers ) )}; m_elementid = FTChannelID( localStationID, localLayerID, localQuarterID, localModuleID, 0 ); } + +LHCb::Detector::detail::DeFTMatObject::DeFTMatObject( const dd4hep::DetElement& de, + dd4hep::cond::ConditionUpdateContext& ctxt, + unsigned int iMat ) + : DeIOVObject( de, ctxt ) + , matID{iMat} {} -- GitLab From 0333d2c82406938e3e6e1bfabf3ba0f252b1fe81 Mon Sep 17 00:00:00 2001 From: Gerhard Raven Date: Wed, 29 Sep 2021 22:53:41 +0200 Subject: [PATCH 09/37] Apply 1 suggestion(s) to 1 file(s) --- Detector/FT/include/Detector/FT/FTChannelID.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detector/FT/include/Detector/FT/FTChannelID.h b/Detector/FT/include/Detector/FT/FTChannelID.h index bbc76ca9..875702ec 100644 --- a/Detector/FT/include/Detector/FT/FTChannelID.h +++ b/Detector/FT/include/Detector/FT/FTChannelID.h @@ -88,7 +88,7 @@ namespace LHCb::Detector { /// Partial constructor using the unique sipm and the channel constexpr FTChannelID( unsigned int uniqueSiPM, unsigned int channel ) - : m_channelID{( shift( uniqueSiPM ) ) + ( shift( channel ) )} {}; + : m_channelID{ shift( uniqueSiPM ) | shift( channel ) } {}; /// Constructor from int constexpr explicit FTChannelID( unsigned int id ) : m_channelID{id} {} -- GitLab From 39fa652b9163c5a49354838fd0380f896e15e2a8 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Wed, 29 Sep 2021 22:59:54 +0200 Subject: [PATCH 10/37] Added back some checks --- Detector/FT/include/Detector/FT/DeFTLayer.h | 2 +- Detector/FT/include/Detector/FT/DeFTModule.h | 2 +- Detector/FT/include/Detector/FT/DeFTQuarter.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index f8b06bdc..bcbf3ad9 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -44,7 +44,7 @@ namespace LHCb::Detector { */ [[nodiscard]] const DeFTQuarter& findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { auto iQ = std::find_if( this->access()->m_quarters.begin(), this->access()->m_quarters.end(), - [&aPoint]( const DeFTQuarter* q ) { return q->isInside( aPoint ); } ); + [&aPoint]( const DeFTQuarter* q ) { return q && q->isInside( aPoint ); } ); return iQ != this->access()->m_quarters.end() ? *iQ : "{}"; } diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 390e9e08..eae7738f 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -49,7 +49,7 @@ namespace LHCb::Detector { const DeFTMat& findMat( const ROOT::Math::XYZPoint& aPoint ) const { /// Find the layer and return a pointer to the layer from XYZ point auto iter = std::find_if( this->access()->m_mats.begin(), this->access()->m_mats.end(), - [&aPoint]( const DeFTMat& m ) { return m.isInside( aPoint ); } ); + [&aPoint]( const DeFTMat* m ) { return m && m->isInside( aPoint ); } ); return iter != this->access()->m_mats.end() ? iter : "{}"; } diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index 9b23e28d..8db26a66 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -42,7 +42,7 @@ namespace LHCb::Detector { */ [[nodiscard]] const DeFTModule& findModule( const ROOT::Math::XYZPoint& aPoint ) const { auto iM = std::find_if( this->access()->m_modules.begin(), this->access()->m_modules.end(), - [&aPoint]( const DeFTModule* m ) { return m->isInside( aPoint ); } ); + [&aPoint]( const DeFTModule* m ) { return m && m->isInside( aPoint ); } ); return iM != this->access()->m_modules.end() ? *iM : "{}"; } /** Const method to return the module for a given channel id -- GitLab From ff6b7e47267abe20096b6320726b0299ba9784eb Mon Sep 17 00:00:00 2001 From: Gerhard Raven Date: Wed, 29 Sep 2021 23:02:28 +0200 Subject: [PATCH 11/37] Apply 1 suggestion(s) to 1 file(s) --- Detector/FT/include/Detector/FT/FTChannelID.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detector/FT/include/Detector/FT/FTChannelID.h b/Detector/FT/include/Detector/FT/FTChannelID.h index 875702ec..4cd1feba 100644 --- a/Detector/FT/include/Detector/FT/FTChannelID.h +++ b/Detector/FT/include/Detector/FT/FTChannelID.h @@ -84,7 +84,7 @@ namespace LHCb::Detector { [[nodiscard]] friend constexpr unsigned int to_unsigned( MatID id ) { return static_cast( id ); } /// Default Constructor - constexpr FTChannelID() = default; + constexpr FTChannelID(): FTChannelID{ kInvalidChannel() } {}; /// Partial constructor using the unique sipm and the channel constexpr FTChannelID( unsigned int uniqueSiPM, unsigned int channel ) -- GitLab From d49eee803bd59e813e7d28f3b88277de4d1aee5b Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Wed, 29 Sep 2021 23:15:29 +0200 Subject: [PATCH 12/37] Moved findChannel(point) to returning a pointer --- Detector/FT/include/Detector/FT/DeFT.h | 20 +++++++++---------- Detector/FT/include/Detector/FT/DeFTLayer.h | 8 ++++---- Detector/FT/include/Detector/FT/DeFTModule.h | 4 ++-- Detector/FT/include/Detector/FT/DeFTQuarter.h | 4 ++-- Detector/FT/include/Detector/FT/DeFTStation.h | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 2dec242d..86b2d888 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -56,34 +56,34 @@ namespace LHCb::Detector { /** Find the FT Station corresponding to the point * @return Pointer to the relevant station */ - [[nodiscard]] const DeFTStation& findStation( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTStation* findStation( const ROOT::Math::XYZPoint& aPoint ) const { auto iS = std::find_if( std::begin( this->access()->m_stations ), std::end( this->access()->m_stations ), [&aPoint]( const DeFTStation& s ) { return s.isInside( aPoint ); } ); - return iS != this->access()->m_stations.end() ? *iS : "{}"; + return iS != this->access()->m_stations.end() ? iS : nullptr; } /// Find the layer for a given XYZ point - [[nodiscard]] const DeFTLayer& findLayer( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTLayer* findLayer( const ROOT::Math::XYZPoint& aPoint ) const { auto s = findStation( aPoint ); - return s ? s.findLayer( aPoint ) : "{}"; + return s ? s->findLayer( aPoint ) : nullptr; } /// Find the quarter for a given XYZ point - [[nodiscard]] const DeFTQuarter& findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTQuarter* findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { auto l = findLayer( aPoint ); - return l ? l.findQuarter( aPoint ) : "{}"; + return l ? l->findQuarter( aPoint ) : nullptr; } /// Find the module for a given XYZ point - [[nodiscard]] const DeFTModule& findModule( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { auto l = findLayer( aPoint ); // is faster than via DeFTQuarter - return l ? l.findModule( aPoint ) : "{}"; + return l ? l->findModule( aPoint ) : nullptr; } /// Find the mat for a given XYZ point - [[nodiscard]] const DeFTMat& findMat( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTMat* findMat( const ROOT::Math::XYZPoint& aPoint ) const { auto m = findModule( aPoint ); - return m ? m.findMat( aPoint ) : "{}"; + return m ? m->findMat( aPoint ) : nullptr; } /** Find the FT Station corresponding to the channel id diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index bcbf3ad9..0c326630 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -42,16 +42,16 @@ namespace LHCb::Detector { /** Find the FT Quarter corresponding to the point * @return Pointer to the relevant quarter */ - [[nodiscard]] const DeFTQuarter& findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTQuarter* findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { auto iQ = std::find_if( this->access()->m_quarters.begin(), this->access()->m_quarters.end(), [&aPoint]( const DeFTQuarter* q ) { return q && q->isInside( aPoint ); } ); - return iQ != this->access()->m_quarters.end() ? *iQ : "{}"; + return iQ != this->access()->m_quarters.end() ? iQ : nullptr; } /// Find the module for a given XYZ point - [[nodiscard]] const DeFTModule& findModule( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { auto iQ = findQuarter(aPoint); - return iQ ? iQ->findModule(aPoint) : "{}"; + return iQ ? iQ->findModule(aPoint) : nullptr; } /** Const method to return the layer for a given channel id diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index eae7738f..fe48adc4 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -46,11 +46,11 @@ namespace LHCb::Detector { unsigned int moduleID() const{return this->access()->m_id;} /// Find the layer for a given XYZ point - const DeFTMat& findMat( const ROOT::Math::XYZPoint& aPoint ) const { + const DeFTMat* findMat( const ROOT::Math::XYZPoint& aPoint ) const { /// Find the layer and return a pointer to the layer from XYZ point auto iter = std::find_if( this->access()->m_mats.begin(), this->access()->m_mats.end(), [&aPoint]( const DeFTMat* m ) { return m && m->isInside( aPoint ); } ); - return iter != this->access()->m_mats.end() ? iter : "{}"; + return iter != this->access()->m_mats.end() ? iter : nullptr; } [[nodiscard]] const DeFTMat& findMat( const FTChannelID& id ) const { diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index 8db26a66..5fbdb4d5 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -40,10 +40,10 @@ namespace LHCb::Detector { /** Find the FT Module corresponding to the point * @return Pointer to the relevant module */ - [[nodiscard]] const DeFTModule& findModule( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { auto iM = std::find_if( this->access()->m_modules.begin(), this->access()->m_modules.end(), [&aPoint]( const DeFTModule* m ) { return m && m->isInside( aPoint ); } ); - return iM != this->access()->m_modules.end() ? *iM : "{}"; + return iM != this->access()->m_modules.end() ? iM : nullptr; } /** Const method to return the module for a given channel id * @param aChannel an FT channel id diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index 2763adce..8a89ab46 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -40,10 +40,10 @@ namespace LHCb::Detector { /** Find the FT Layer corresponding to the point * @return Pointer to the relevant layer */ - [[nodiscard]] const DeFTLayer& findLayer( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTLayer* findLayer( const ROOT::Math::XYZPoint& aPoint ) const { auto iter = std::find_if( this->access()->m_layers.begin(), this->access()->m_layers.end(), [&aPoint]( const DeFTLayer* l ) { return l->isInside( aPoint );} ); - return iter != this->access()->m_layers.end() ? *iter : "{}"; + return iter != this->access()->m_layers.end() ? *iter : nullptr; } /** Const method to return the layer for a given channel id -- GitLab From f5572ed5315d2262021e78d308ebaec0a1b38e4c Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Thu, 30 Sep 2021 09:33:58 +0200 Subject: [PATCH 13/37] Reverted to pointers, changed a constness --- Detector/FT/include/Detector/FT/DeFT.h | 31 ++++++++++--------- Detector/FT/include/Detector/FT/DeFTLayer.h | 8 ++--- Detector/FT/include/Detector/FT/DeFTMat.h | 2 +- Detector/FT/include/Detector/FT/DeFTModule.h | 6 ++-- Detector/FT/include/Detector/FT/DeFTQuarter.h | 4 +-- Detector/FT/include/Detector/FT/DeFTStation.h | 6 ++-- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 86b2d888..b5bc8f84 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -57,71 +57,71 @@ namespace LHCb::Detector { * @return Pointer to the relevant station */ [[nodiscard]] const DeFTStation* findStation( const ROOT::Math::XYZPoint& aPoint ) const { - auto iS = std::find_if( std::begin( this->access()->m_stations ), std::end( this->access()->m_stations ), + const auto* iS = std::find_if( std::begin( this->access()->m_stations ), std::end( this->access()->m_stations ), [&aPoint]( const DeFTStation& s ) { return s.isInside( aPoint ); } ); return iS != this->access()->m_stations.end() ? iS : nullptr; } /// Find the layer for a given XYZ point [[nodiscard]] const DeFTLayer* findLayer( const ROOT::Math::XYZPoint& aPoint ) const { - auto s = findStation( aPoint ); + const auto* s = findStation( aPoint ); return s ? s->findLayer( aPoint ) : nullptr; } /// Find the quarter for a given XYZ point [[nodiscard]] const DeFTQuarter* findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { - auto l = findLayer( aPoint ); + const auto* l = findLayer( aPoint ); return l ? l->findQuarter( aPoint ) : nullptr; } /// Find the module for a given XYZ point [[nodiscard]] const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { - auto l = findLayer( aPoint ); // is faster than via DeFTQuarter + const auto* l = findLayer( aPoint ); // is faster than via DeFTQuarter return l ? l->findModule( aPoint ) : nullptr; } /// Find the mat for a given XYZ point [[nodiscard]] const DeFTMat* findMat( const ROOT::Math::XYZPoint& aPoint ) const { - auto m = findModule( aPoint ); + const auto* m = findModule( aPoint ); return m ? m->findMat( aPoint ) : nullptr; } /** Find the FT Station corresponding to the channel id * @return Pointer to the relevant station */ - [[nodiscard]] const DeFTStation& findStation( const FTChannelID& aChannel ) const { - return this->access()->m_stations[to_unsigned( aChannel.station() ) - 1u]; + [[nodiscard]] const DeFTStation* findStation( const FTChannelID& aChannel ) const { + return &(this->access()->m_stations[to_unsigned( aChannel.station() ) - 1u]); } /** Find the FT Layer corresponding to the channel id * @return Pointer to the relevant layer */ - [[nodiscard]] const DeFTLayer& findLayer( const FTChannelID& aChannel ) const { - const auto& s = findStation( aChannel ); + [[nodiscard]] const DeFTLayer* findLayer( const FTChannelID& aChannel ) const { + const auto* s = findStation( aChannel ); return s.findLayer( aChannel ); } /** Find the FT Quarter corresponding to the channel id * @return Pointer to the relevant quarter */ - [[nodiscard]] const DeFTQuarter& findQuarter( const FTChannelID& aChannel ) const { - const auto& l = findLayer( aChannel ); + [[nodiscard]] const DeFTQuarter* findQuarter( const FTChannelID& aChannel ) const { + const auto* l = findLayer( aChannel ); return l.findQuarter( aChannel ); } /** Find the FT Module corresponding to the channel id * @return Pointer to the relevant module */ - [[nodiscard]] const DeFTModule& findModule( const FTChannelID& aChannel ) const { - const auto& q = findQuarter( aChannel ); + [[nodiscard]] const DeFTModule* findModule( const FTChannelID& aChannel ) const { + const auto* q = findQuarter( aChannel ); return q.findModule( aChannel ); } /** Find the FT Mat corresponding to the channel id * @return Pointer to the relevant module */ - [[nodiscard]] const DeFTMat& findMat( const FTChannelID& aChannel ) const { - const auto& m = findModule( aChannel ); + [[nodiscard]] const DeFTMat* findMat( const FTChannelID& aChannel ) const { + const auto* m = findModule( aChannel ); return m.findMat( aChannel ); } @@ -171,3 +171,4 @@ namespace LHCb::Detector { using DeFT = DeFTElement; } // End namespace LHCb::Detector + diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 0c326630..d6cbf90c 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -43,14 +43,14 @@ namespace LHCb::Detector { * @return Pointer to the relevant quarter */ [[nodiscard]] const DeFTQuarter* findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { - auto iQ = std::find_if( this->access()->m_quarters.begin(), this->access()->m_quarters.end(), + const auto* iQ = std::find_if( this->access()->m_quarters.begin(), this->access()->m_quarters.end(), [&aPoint]( const DeFTQuarter* q ) { return q && q->isInside( aPoint ); } ); return iQ != this->access()->m_quarters.end() ? iQ : nullptr; } /// Find the module for a given XYZ point [[nodiscard]] const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { - auto iQ = findQuarter(aPoint); + const auto* iQ = findQuarter(aPoint); return iQ ? iQ->findModule(aPoint) : nullptr; } @@ -58,8 +58,8 @@ namespace LHCb::Detector { * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTQuarter& findQuarter( const FTChannelID& aChannel ) const { - return this->access()->m_quarters[to_unsigned( aChannel.quarter() )]; + [[nodiscard]] const DeFTQuarter* findQuarter( const FTChannelID& aChannel ) const { + return &(this->access()->m_quarters[to_unsigned( aChannel.quarter() )]); } }; diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index 0b959006..c94dfa0b 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -41,7 +41,7 @@ namespace LHCb::Detector { } // End namespace detail template struct DeFTMatElement : DeIOVElement { - unsigned int matID(){return this->access()->matID;} + unsigned int matID() const{return this->access()->matID;} }; using DeFTMat = DeFTMatElement; diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index fe48adc4..bfe39e9c 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -48,13 +48,13 @@ namespace LHCb::Detector { /// Find the layer for a given XYZ point const DeFTMat* findMat( const ROOT::Math::XYZPoint& aPoint ) const { /// Find the layer and return a pointer to the layer from XYZ point - auto iter = std::find_if( this->access()->m_mats.begin(), this->access()->m_mats.end(), + const auto* iter = std::find_if( this->access()->m_mats.begin(), this->access()->m_mats.end(), [&aPoint]( const DeFTMat* m ) { return m && m->isInside( aPoint ); } ); return iter != this->access()->m_mats.end() ? iter : nullptr; } - [[nodiscard]] const DeFTMat& findMat( const FTChannelID& id ) const { - return this->access()->m_mats[to_unsigned( id.mat() )]; + [[nodiscard]] const DeFTMat* findMat( const FTChannelID& id ) const { + return &(this->access()->m_mats[to_unsigned( id.mat() )]); } [[nodiscard]] const FTChannelID& elementID() const { return this->access()->m_elementid; } diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index 5fbdb4d5..da2b6a17 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -49,9 +49,9 @@ namespace LHCb::Detector { * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTModule& findModule( const FTChannelID aChannel ) const { + [[nodiscard]] const DeFTModule* findModule( const FTChannelID aChannel ) const { auto m = to_unsigned( aChannel.module() ); - return this->access()->m_modules[m]; + return &(this->access()->m_modules[m]); } /** Flat vector of all FT modules * @return vector of modules diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index 8a89ab46..1c8e24c9 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -43,15 +43,15 @@ namespace LHCb::Detector { [[nodiscard]] const DeFTLayer* findLayer( const ROOT::Math::XYZPoint& aPoint ) const { auto iter = std::find_if( this->access()->m_layers.begin(), this->access()->m_layers.end(), [&aPoint]( const DeFTLayer* l ) { return l->isInside( aPoint );} ); - return iter != this->access()->m_layers.end() ? *iter : nullptr; + return iter != this->access()->m_layers.end() ? iter : nullptr; } /** Const method to return the layer for a given channel id * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTLayer& findLayer( const FTChannelID& aChannel ) const { - return this->access()->m_layers[to_unsigned( aChannel.layer() )]; + [[nodiscard]] const DeFTLayer* findLayer( const FTChannelID& aChannel ) const { + return &(this->access()->m_layers[to_unsigned( aChannel.layer() )]); } }; -- GitLab From a74f9fca23de089173f21ac699741c4051d2c1cf Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Thu, 30 Sep 2021 13:54:04 +0200 Subject: [PATCH 14/37] Updating for checks --- Detector/FT/include/Detector/FT/DeFT.h | 8 ++++---- Detector/FT/include/Detector/FT/DeFTModule.h | 2 +- Detector/FT/include/Detector/FT/FTChannelID.h | 3 --- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index b5bc8f84..a7d589ed 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -98,7 +98,7 @@ namespace LHCb::Detector { */ [[nodiscard]] const DeFTLayer* findLayer( const FTChannelID& aChannel ) const { const auto* s = findStation( aChannel ); - return s.findLayer( aChannel ); + return s->findLayer( aChannel ); } /** Find the FT Quarter corresponding to the channel id @@ -106,7 +106,7 @@ namespace LHCb::Detector { */ [[nodiscard]] const DeFTQuarter* findQuarter( const FTChannelID& aChannel ) const { const auto* l = findLayer( aChannel ); - return l.findQuarter( aChannel ); + return l->findQuarter( aChannel ); } /** Find the FT Module corresponding to the channel id @@ -114,7 +114,7 @@ namespace LHCb::Detector { */ [[nodiscard]] const DeFTModule* findModule( const FTChannelID& aChannel ) const { const auto* q = findQuarter( aChannel ); - return q.findModule( aChannel ); + return q->findModule( aChannel ); } /** Find the FT Mat corresponding to the channel id @@ -122,7 +122,7 @@ namespace LHCb::Detector { */ [[nodiscard]] const DeFTMat* findMat( const FTChannelID& aChannel ) const { const auto* m = findModule( aChannel ); - return m.findMat( aChannel ); + return m->findMat( aChannel ); } /// Get a random FTChannelID (useful for the thermal noise, which is ~flat) diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index bfe39e9c..4ea34794 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -49,7 +49,7 @@ namespace LHCb::Detector { const DeFTMat* findMat( const ROOT::Math::XYZPoint& aPoint ) const { /// Find the layer and return a pointer to the layer from XYZ point const auto* iter = std::find_if( this->access()->m_mats.begin(), this->access()->m_mats.end(), - [&aPoint]( const DeFTMat* m ) { return m && m->isInside( aPoint ); } ); + [&aPoint]( const DeFTMat* m ) { return m && m->isInside( aPoint ); } ); return iter != this->access()->m_mats.end() ? iter : nullptr; } diff --git a/Detector/FT/include/Detector/FT/FTChannelID.h b/Detector/FT/include/Detector/FT/FTChannelID.h index 4cd1feba..615bd46a 100644 --- a/Detector/FT/include/Detector/FT/FTChannelID.h +++ b/Detector/FT/include/Detector/FT/FTChannelID.h @@ -93,9 +93,6 @@ namespace LHCb::Detector { /// Constructor from int constexpr explicit FTChannelID( unsigned int id ) : m_channelID{id} {} - // /// Constructor from int - // constexpr explicit FTChannelID( const FTChannelID& id ) : m_channelID{id.channelID()} {} - /// Explicit constructor from the geometrical location constexpr FTChannelID( StationID station, LayerID layer, QuarterID quarter, ModuleID module, MatID mat, unsigned int sipm, unsigned int channel ) -- GitLab From 16b4fda80a4a2dad7b0d8412e7790a414fdb36e8 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Thu, 30 Sep 2021 18:06:07 +0200 Subject: [PATCH 15/37] Changed pointers to objects in return type --- Detector/FT/include/Detector/FT/DeFT.h | 30 +++++++++---------- Detector/FT/include/Detector/FT/DeFTLayer.h | 8 ++--- Detector/FT/include/Detector/FT/DeFTMat.h | 4 +-- Detector/FT/include/Detector/FT/DeFTModule.h | 10 +++---- Detector/FT/include/Detector/FT/DeFTQuarter.h | 6 ++-- Detector/FT/include/Detector/FT/DeFTStation.h | 6 ++-- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index a7d589ed..ba6d5e12 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -56,47 +56,47 @@ namespace LHCb::Detector { /** Find the FT Station corresponding to the point * @return Pointer to the relevant station */ - [[nodiscard]] const DeFTStation* findStation( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTStation findStation( const ROOT::Math::XYZPoint& aPoint ) const { const auto* iS = std::find_if( std::begin( this->access()->m_stations ), std::end( this->access()->m_stations ), [&aPoint]( const DeFTStation& s ) { return s.isInside( aPoint ); } ); - return iS != this->access()->m_stations.end() ? iS : nullptr; + return iS != this->access()->m_stations.end() ? iS : DeFTStation{}; } /// Find the layer for a given XYZ point - [[nodiscard]] const DeFTLayer* findLayer( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTLayer findLayer( const ROOT::Math::XYZPoint& aPoint ) const { const auto* s = findStation( aPoint ); - return s ? s->findLayer( aPoint ) : nullptr; + return s ? s->findLayer( aPoint ) : DeFTLayer{}; } /// Find the quarter for a given XYZ point - [[nodiscard]] const DeFTQuarter* findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTQuarter findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { const auto* l = findLayer( aPoint ); - return l ? l->findQuarter( aPoint ) : nullptr; + return l ? l->findQuarter( aPoint ) : DeFTQuarter{}; } /// Find the module for a given XYZ point - [[nodiscard]] const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTModule findModule( const ROOT::Math::XYZPoint& aPoint ) const { const auto* l = findLayer( aPoint ); // is faster than via DeFTQuarter - return l ? l->findModule( aPoint ) : nullptr; + return l ? l->findModule( aPoint ) : DeFTModule{}; } /// Find the mat for a given XYZ point - [[nodiscard]] const DeFTMat* findMat( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTMat findMat( const ROOT::Math::XYZPoint& aPoint ) const { const auto* m = findModule( aPoint ); - return m ? m->findMat( aPoint ) : nullptr; + return m ? m->findMat( aPoint ) : DeFTMat{}; } /** Find the FT Station corresponding to the channel id * @return Pointer to the relevant station */ - [[nodiscard]] const DeFTStation* findStation( const FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTStation findStation( const FTChannelID& aChannel ) const { return &(this->access()->m_stations[to_unsigned( aChannel.station() ) - 1u]); } /** Find the FT Layer corresponding to the channel id * @return Pointer to the relevant layer */ - [[nodiscard]] const DeFTLayer* findLayer( const FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTLayer findLayer( const FTChannelID& aChannel ) const { const auto* s = findStation( aChannel ); return s->findLayer( aChannel ); } @@ -104,7 +104,7 @@ namespace LHCb::Detector { /** Find the FT Quarter corresponding to the channel id * @return Pointer to the relevant quarter */ - [[nodiscard]] const DeFTQuarter* findQuarter( const FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTQuarter findQuarter( const FTChannelID& aChannel ) const { const auto* l = findLayer( aChannel ); return l->findQuarter( aChannel ); } @@ -112,7 +112,7 @@ namespace LHCb::Detector { /** Find the FT Module corresponding to the channel id * @return Pointer to the relevant module */ - [[nodiscard]] const DeFTModule* findModule( const FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTModule findModule( const FTChannelID& aChannel ) const { const auto* q = findQuarter( aChannel ); return q->findModule( aChannel ); } @@ -120,7 +120,7 @@ namespace LHCb::Detector { /** Find the FT Mat corresponding to the channel id * @return Pointer to the relevant module */ - [[nodiscard]] const DeFTMat* findMat( const FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTMat findMat( const FTChannelID& aChannel ) const { const auto* m = findModule( aChannel ); return m->findMat( aChannel ); } diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index d6cbf90c..443b122f 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -42,16 +42,16 @@ namespace LHCb::Detector { /** Find the FT Quarter corresponding to the point * @return Pointer to the relevant quarter */ - [[nodiscard]] const DeFTQuarter* findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTQuarter findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { const auto* iQ = std::find_if( this->access()->m_quarters.begin(), this->access()->m_quarters.end(), [&aPoint]( const DeFTQuarter* q ) { return q && q->isInside( aPoint ); } ); - return iQ != this->access()->m_quarters.end() ? iQ : nullptr; + return iQ != this->access()->m_quarters.end() ? iQ : DeFTQuarter{}; } /// Find the module for a given XYZ point - [[nodiscard]] const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTModule findModule( const ROOT::Math::XYZPoint& aPoint ) const { const auto* iQ = findQuarter(aPoint); - return iQ ? iQ->findModule(aPoint) : nullptr; + return iQ ? iQ->findModule(aPoint) : DeFTModule{}; } /** Const method to return the layer for a given channel id diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index c94dfa0b..af9d993f 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -40,8 +40,8 @@ namespace LHCb::Detector { }; } // End namespace detail template - struct DeFTMatElement : DeIOVElement { - unsigned int matID() const{return this->access()->matID;} + struct DeFTMatElement : DeIOVElement { + FTChannelID::MatID matID() const{return FTChannelID::MatID{this->access()->matID};} }; using DeFTMat = DeFTMatElement; diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 4ea34794..5cb1098a 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -43,20 +43,20 @@ namespace LHCb::Detector { template struct DeFTModuleElement : DeIOVElement { - unsigned int moduleID() const{return this->access()->m_id;} + FTChannelID::ModuleID moduleID() const{return FTChannelID::ModuleID{this->access()->m_id};} /// Find the layer for a given XYZ point - const DeFTMat* findMat( const ROOT::Math::XYZPoint& aPoint ) const { + const DeFTMat findMat( const ROOT::Math::XYZPoint& aPoint ) const { /// Find the layer and return a pointer to the layer from XYZ point const auto* iter = std::find_if( this->access()->m_mats.begin(), this->access()->m_mats.end(), [&aPoint]( const DeFTMat* m ) { return m && m->isInside( aPoint ); } ); - return iter != this->access()->m_mats.end() ? iter : nullptr; + return iter != this->access()->m_mats.end() ? iter : DeFTMat{}; } - [[nodiscard]] const DeFTMat* findMat( const FTChannelID& id ) const { + [[nodiscard]] const DeFTMat findMat( const FTChannelID& id ) const { return &(this->access()->m_mats[to_unsigned( id.mat() )]); } - [[nodiscard]] const FTChannelID& elementID() const { return this->access()->m_elementid; } + [[nodiscard]] FTChannelID elementID() const { return this->access()->m_elementid; } [[nodiscard]] FTChannelID channelFromPseudo( const int pseudoChannel ) const { const auto& obj = this->access(); diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index da2b6a17..42cd9cfa 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -40,16 +40,16 @@ namespace LHCb::Detector { /** Find the FT Module corresponding to the point * @return Pointer to the relevant module */ - [[nodiscard]] const DeFTModule* findModule( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTModule findModule( const ROOT::Math::XYZPoint& aPoint ) const { auto iM = std::find_if( this->access()->m_modules.begin(), this->access()->m_modules.end(), [&aPoint]( const DeFTModule* m ) { return m && m->isInside( aPoint ); } ); - return iM != this->access()->m_modules.end() ? iM : nullptr; + return iM != this->access()->m_modules.end() ? iM : DeFTModule{}; } /** Const method to return the module for a given channel id * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTModule* findModule( const FTChannelID aChannel ) const { + [[nodiscard]] const DeFTModule findModule( const FTChannelID aChannel ) const { auto m = to_unsigned( aChannel.module() ); return &(this->access()->m_modules[m]); } diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index 1c8e24c9..504ad14c 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -40,17 +40,17 @@ namespace LHCb::Detector { /** Find the FT Layer corresponding to the point * @return Pointer to the relevant layer */ - [[nodiscard]] const DeFTLayer* findLayer( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const DeFTLayer findLayer( const ROOT::Math::XYZPoint& aPoint ) const { auto iter = std::find_if( this->access()->m_layers.begin(), this->access()->m_layers.end(), [&aPoint]( const DeFTLayer* l ) { return l->isInside( aPoint );} ); - return iter != this->access()->m_layers.end() ? iter : nullptr; + return iter != this->access()->m_layers.end() ? iter : DeFTLayer{}; } /** Const method to return the layer for a given channel id * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTLayer* findLayer( const FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTLayer findLayer( const FTChannelID& aChannel ) const { return &(this->access()->m_layers[to_unsigned( aChannel.layer() )]); } }; -- GitLab From 84db20f6b3b15554ffa0ec092e1264b571a66c62 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Mon, 4 Oct 2021 14:46:33 +0200 Subject: [PATCH 16/37] Solved handle-related compilation issues --- Detector/FT/include/Detector/FT/DeFT.h | 36 +++++++++---------- Detector/FT/include/Detector/FT/DeFTLayer.h | 22 ++++++------ Detector/FT/include/Detector/FT/DeFTMat.h | 3 +- Detector/FT/include/Detector/FT/DeFTModule.h | 10 +++--- Detector/FT/include/Detector/FT/DeFTQuarter.h | 8 ++--- Detector/FT/include/Detector/FT/DeFTStation.h | 8 ++--- Detector/FT/src/DeFT.cpp | 4 +-- 7 files changed, 46 insertions(+), 45 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index ba6d5e12..7f220664 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -56,34 +56,34 @@ namespace LHCb::Detector { /** Find the FT Station corresponding to the point * @return Pointer to the relevant station */ - [[nodiscard]] const DeFTStation findStation( const ROOT::Math::XYZPoint& aPoint ) const { - const auto* iS = std::find_if( std::begin( this->access()->m_stations ), std::end( this->access()->m_stations ), - [&aPoint]( const DeFTStation& s ) { return s.isInside( aPoint ); } ); - return iS != this->access()->m_stations.end() ? iS : DeFTStation{}; + [[nodiscard]] const std::optional findStation( const ROOT::Math::XYZPoint& aPoint ) const { + const auto iS = std::find_if( std::begin( this->access()->m_stations ), std::end( this->access()->m_stations ), + [&aPoint]( detail::DeFTStationObject const& s ) { return DeFTStation{&s}.isInside( aPoint ); } ); + return iS != this->access()->m_stations.end() ? std::optional{iS} : std::optional{};//DeFTStation{}; } /// Find the layer for a given XYZ point - [[nodiscard]] const DeFTLayer findLayer( const ROOT::Math::XYZPoint& aPoint ) const { - const auto* s = findStation( aPoint ); - return s ? s->findLayer( aPoint ) : DeFTLayer{}; + [[nodiscard]] const std::optional findLayer( const ROOT::Math::XYZPoint& aPoint ) const { + const auto s = findStation( aPoint ); + return s ? s->findLayer( aPoint ) : std::optional{};//DeFTLayer{}; } /// Find the quarter for a given XYZ point - [[nodiscard]] const DeFTQuarter findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { - const auto* l = findLayer( aPoint ); - return l ? l->findQuarter( aPoint ) : DeFTQuarter{}; + [[nodiscard]] const std::optional findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { + const auto l = findLayer( aPoint ); + return l ? l->findQuarter( aPoint ) : std::optional{};//false;//DeFTQuarter{}; } /// Find the module for a given XYZ point - [[nodiscard]] const DeFTModule findModule( const ROOT::Math::XYZPoint& aPoint ) const { - const auto* l = findLayer( aPoint ); // is faster than via DeFTQuarter - return l ? l->findModule( aPoint ) : DeFTModule{}; + [[nodiscard]] const std::optional findModule( const ROOT::Math::XYZPoint& aPoint ) const { + const auto l = findLayer( aPoint ); // is faster than via DeFTQuarter + return l ? l->findModule( aPoint ) : std::optional{};//DeFTModule{}; } /// Find the mat for a given XYZ point - [[nodiscard]] const DeFTMat findMat( const ROOT::Math::XYZPoint& aPoint ) const { - const auto* m = findModule( aPoint ); - return m ? m->findMat( aPoint ) : DeFTMat{}; + [[nodiscard]] const std::optional findMat( const ROOT::Math::XYZPoint& aPoint ) const { + const auto m = findModule( aPoint ); + return m ? m->findMat( aPoint ) : std::optional{};//DeFTMat{}; } /** Find the FT Station corresponding to the channel id @@ -97,8 +97,8 @@ namespace LHCb::Detector { * @return Pointer to the relevant layer */ [[nodiscard]] const DeFTLayer findLayer( const FTChannelID& aChannel ) const { - const auto* s = findStation( aChannel ); - return s->findLayer( aChannel ); + const auto s = findStation( aChannel ); + return s.findLayer( aChannel ); } /** Find the FT Quarter corresponding to the channel id diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 443b122f..f91cf710 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -36,30 +36,30 @@ namespace LHCb::Detector { template struct DeFTLayerElement : DeIOVElement { - + using DeIOVElement::DeIOVElement; unsigned int layerID() const{return this->access()->m_id;} /** Find the FT Quarter corresponding to the point * @return Pointer to the relevant quarter */ - [[nodiscard]] const DeFTQuarter findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { - const auto* iQ = std::find_if( this->access()->m_quarters.begin(), this->access()->m_quarters.end(), - [&aPoint]( const DeFTQuarter* q ) { return q && q->isInside( aPoint ); } ); - return iQ != this->access()->m_quarters.end() ? iQ : DeFTQuarter{}; + [[nodiscard]] const std::optional findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { + const auto iQ = std::find_if( this->access()->m_quarters.begin(), this->access()->m_quarters.end(), + [&aPoint]( const detail::DeFTQuarterObject& q ) { return DeFTQuarter{&q}.isInside( aPoint ); } ); + return iQ != this->access()->m_quarters.end() ? iQ : std::optional{};//DeFTQuarter{}; } /// Find the module for a given XYZ point - [[nodiscard]] const DeFTModule findModule( const ROOT::Math::XYZPoint& aPoint ) const { - const auto* iQ = findQuarter(aPoint); - return iQ ? iQ->findModule(aPoint) : DeFTModule{}; - } + [[nodiscard]] const std::optional findModule( const ROOT::Math::XYZPoint& aPoint ) const { + const auto iQ = findQuarter(aPoint); + return iQ ? iQ->findModule(aPoint) : std::optional{};//DeFTModule{}; + }\ /** Const method to return the layer for a given channel id * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTQuarter* findQuarter( const FTChannelID& aChannel ) const { - return &(this->access()->m_quarters[to_unsigned( aChannel.quarter() )]); + [[nodiscard]] const DeFTQuarter findQuarter( const FTChannelID& aChannel ) const { + return this->access()->m_quarters[to_unsigned( aChannel.quarter() )]; } }; diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index af9d993f..b62d6554 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -41,9 +41,10 @@ namespace LHCb::Detector { } // End namespace detail template struct DeFTMatElement : DeIOVElement { + using DeIOVElement::DeIOVElement; FTChannelID::MatID matID() const{return FTChannelID::MatID{this->access()->matID};} }; - + using DeFTMat = DeFTMatElement; } // End namespace LHCb::Detector diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 5cb1098a..6df8147d 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -42,15 +42,15 @@ namespace LHCb::Detector { } // End namespace detail template struct DeFTModuleElement : DeIOVElement { - + using DeIOVElement::DeIOVElement; FTChannelID::ModuleID moduleID() const{return FTChannelID::ModuleID{this->access()->m_id};} /// Find the layer for a given XYZ point - const DeFTMat findMat( const ROOT::Math::XYZPoint& aPoint ) const { + const std::optional findMat( const ROOT::Math::XYZPoint& aPoint ) const { /// Find the layer and return a pointer to the layer from XYZ point - const auto* iter = std::find_if( this->access()->m_mats.begin(), this->access()->m_mats.end(), - [&aPoint]( const DeFTMat* m ) { return m && m->isInside( aPoint ); } ); - return iter != this->access()->m_mats.end() ? iter : DeFTMat{}; + const auto iter = std::find_if( this->access()->m_mats.begin(), this->access()->m_mats.end(), + [&aPoint]( const detail::DeFTMatObject& m ) { return DeFTMat{&m}.isInside( aPoint ); } ); + return iter != this->access()->m_mats.end() ? iter : std::optional{};//DeFTMat{}; } [[nodiscard]] const DeFTMat findMat( const FTChannelID& id ) const { diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index 42cd9cfa..966a889d 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -34,16 +34,16 @@ namespace LHCb::Detector { template struct DeFTQuarterElement : DeIOVElement { - + using DeIOVElement::DeIOVElement; unsigned int quarterID() const{return this->access()->m_id;} /** Find the FT Module corresponding to the point * @return Pointer to the relevant module */ - [[nodiscard]] const DeFTModule findModule( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const std::optional findModule( const ROOT::Math::XYZPoint& aPoint ) const { auto iM = std::find_if( this->access()->m_modules.begin(), this->access()->m_modules.end(), - [&aPoint]( const DeFTModule* m ) { return m && m->isInside( aPoint ); } ); - return iM != this->access()->m_modules.end() ? iM : DeFTModule{}; + [&aPoint]( const detail::DeFTModuleObject& m ) { return DeFTModule{&m}.isInside( aPoint ); } ); + return iM != this->access()->m_modules.end() ? iM : std::optional{};//DeFTModule{}; } /** Const method to return the module for a given channel id * @param aChannel an FT channel id diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index 504ad14c..776068ab 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -34,16 +34,16 @@ namespace LHCb::Detector { template struct DeFTStationElement : DeIOVElement { - + using DeIOVElement::DeIOVElement; unsigned int stationID() const{return this->access()->m_id;} /** Find the FT Layer corresponding to the point * @return Pointer to the relevant layer */ - [[nodiscard]] const DeFTLayer findLayer( const ROOT::Math::XYZPoint& aPoint ) const { + [[nodiscard]] const std::optional findLayer( const ROOT::Math::XYZPoint& aPoint ) const { auto iter = std::find_if( this->access()->m_layers.begin(), this->access()->m_layers.end(), - [&aPoint]( const DeFTLayer* l ) { return l->isInside( aPoint );} ); - return iter != this->access()->m_layers.end() ? iter : DeFTLayer{}; + [&aPoint]( const detail::DeFTLayerObject& l ) { return DeFTLayer{&l}.isInside( aPoint );} ); + return iter != this->access()->m_layers.end() ? iter : std::optional{};//DeFTLayer{}; } /** Const method to return the layer for a given channel id diff --git a/Detector/FT/src/DeFT.cpp b/Detector/FT/src/DeFT.cpp index 39bef9d5..4dda4b84 100644 --- a/Detector/FT/src/DeFT.cpp +++ b/Detector/FT/src/DeFT.cpp @@ -26,8 +26,8 @@ LHCb::Detector::detail::DeFTStationObject::DeFTStationObject( const dd4hep::DetE : DeIOVObject( de, ctxt ) , m_id{iStation} , m_layers{{{de.child( "X1" ), ctxt, 0, m_id}, - {de.child( "U" ), ctxt, 1, m_id}, - {de.child( "V" ), ctxt, 2, m_id}, + {de.child( "U" ), ctxt, 1, m_id}, + {de.child( "V" ), ctxt, 2, m_id}, {de.child( "X2" ), ctxt, 3, m_id}}} {} LHCb::Detector::detail::DeFTLayerObject::DeFTLayerObject( const dd4hep::DetElement& de, -- GitLab From 03ff516431683899868f47ea3333daaad8b7b4c3 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Mon, 4 Oct 2021 15:01:12 +0200 Subject: [PATCH 17/37] Solved compilation issues, added inherited constructor --- Core/include/Core/DeIOV.h | 2 ++ Detector/FT/include/Detector/FT/DeFT.h | 1 + 2 files changed, 3 insertions(+) diff --git a/Core/include/Core/DeIOV.h b/Core/include/Core/DeIOV.h index 4836f563..f4eabb3d 100644 --- a/Core/include/Core/DeIOV.h +++ b/Core/include/Core/DeIOV.h @@ -66,6 +66,8 @@ namespace LHCb::Detector { dd4hep::DetElement detector() const { return this->access()->detector; } /// Accessor to the geometry structure of this detector element dd4hep::PlacedVolume geometry() const { return this->access()->geometry; } + /// Accessor to the geometry structure of this detector element + std::string lVolumeName() const { return geometry().volume().name(); } /// Access to the alignmant object to transformideal coordinates dd4hep::Alignment detectorAlignment() const { return this->access()->detectorAlignment; } diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 7f220664..17ce05a7 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -51,6 +51,7 @@ namespace LHCb::Detector { */ template struct DeFTElement : DeIOVElement { + using DeIOVElement::DeIOVElement; int version() const { return this->access()->m_version; }; /** Find the FT Station corresponding to the point -- GitLab From f595a161b18421eb927513c67f3da2057aa20def Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Mon, 4 Oct 2021 17:45:48 +0200 Subject: [PATCH 18/37] Added applyToAllChildren and some functions (not implemented yet) --- Detector/FT/include/Detector/FT/DeFT.h | 8 +++++++- Detector/FT/include/Detector/FT/DeFTLayer.h | 6 ++++++ Detector/FT/include/Detector/FT/DeFTMat.h | 3 +++ Detector/FT/include/Detector/FT/DeFTModule.h | 3 +++ Detector/FT/include/Detector/FT/DeFTQuarter.h | 3 +++ Detector/FT/include/Detector/FT/DeFTStation.h | 3 +++ 6 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 17ce05a7..ddef2991 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -38,6 +38,12 @@ namespace LHCb::Detector { std::array m_stations; DeFTObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); + void applyToAllChildren( const std::function& func ) const override { + for ( auto& station : m_stations ) { func( LHCb::Detector::DeIOV{&station} ); }; + }; + void applyToAllLayers( const std::function& func ) const { + for ( auto& station : m_stations ) { station.applyToAllChildren(func); }; + }; }; } // End namespace detail @@ -53,7 +59,7 @@ namespace LHCb::Detector { struct DeFTElement : DeIOVElement { using DeIOVElement::DeIOVElement; int version() const { return this->access()->m_version; }; - + const std::array stations() const {const auto obj = this->access(); return {obj->m_stations[0],obj->m_stations[1],obj->m_stations[2]};}; /** Find the FT Station corresponding to the point * @return Pointer to the relevant station */ diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index f91cf710..4f4b7f56 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -31,6 +31,9 @@ namespace LHCb::Detector { std::array m_quarters; DeFTLayerObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iLayer, unsigned int stationID ); + void applyToAllChildren( const std::function& func ) const override { + for ( auto& quarter : m_quarters ) { func( LHCb::Detector::DeIOV{&quarter} ); }; + }; }; } // End namespace detail @@ -61,6 +64,9 @@ namespace LHCb::Detector { [[nodiscard]] const DeFTQuarter findQuarter( const FTChannelID& aChannel ) const { return this->access()->m_quarters[to_unsigned( aChannel.quarter() )]; } + + float globalZ() const;//FIXME + ROOT::Math::Plane3D plane() const;//FIXME }; using DeFTLayer = DeFTLayerElement; diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index b62d6554..0b5b4e2f 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -43,6 +43,9 @@ namespace LHCb::Detector { struct DeFTMatElement : DeIOVElement { using DeIOVElement::DeIOVElement; FTChannelID::MatID matID() const{return FTChannelID::MatID{this->access()->matID};} + ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& intersectionPoint ) const;//FIXME + FTChannelID calculateChannelAndFrac( float x, float frac ) const;//FIXME + }; using DeFTMat = DeFTMatElement; diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 6df8147d..1ca0d177 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -38,6 +38,9 @@ namespace LHCb::Detector { ROOT::Math::XYZPoint localToGlobal( const ROOT::Math::XYZPoint& point ) const { return ROOT::Math::XYZPoint( this->detectorAlignment.localToWorld( ROOT::Math::XYZVector( point ) ) ); } + void applyToAllChildren( const std::function& func ) const override { + for ( auto& mat : m_mats ) { func( LHCb::Detector::DeIOV{&mat} ); }; + }; }; } // End namespace detail template diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index 966a889d..9abd30f2 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -29,6 +29,9 @@ namespace LHCb::Detector { std::array m_modules; DeFTQuarterObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iQuarter, unsigned int layerID ); + void applyToAllChildren( const std::function& func ) const override { + for ( auto& module : m_modules ) { func( LHCb::Detector::DeIOV{&module} ); }; + }; }; } // End namespace detail diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index 776068ab..9f5d1973 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -29,6 +29,9 @@ namespace LHCb::Detector { std::array m_layers; DeFTStationObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iStation ); + void applyToAllChildren( const std::function& func ) const override { + for ( auto& layer : m_layers ) { func( LHCb::Detector::DeIOV{&layer} ); }; + }; }; } // End namespace detail -- GitLab From af2904c0687a24093925b030835e4aec37b2c4c8 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Mon, 4 Oct 2021 18:09:14 +0200 Subject: [PATCH 19/37] Adding methods but not their implementations --- Detector/FT/include/Detector/FT/DeFTMat.h | 3 ++- Detector/FT/include/Detector/FT/DeFTModule.h | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index 0b5b4e2f..9a0e8b6e 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -43,7 +43,8 @@ namespace LHCb::Detector { struct DeFTMatElement : DeIOVElement { using DeIOVElement::DeIOVElement; FTChannelID::MatID matID() const{return FTChannelID::MatID{this->access()->matID};} - ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& intersectionPoint ) const;//FIXME + ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const;//FIXME + ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const;//FIXME FTChannelID calculateChannelAndFrac( float x, float frac ) const;//FIXME }; diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 1ca0d177..4b96635c 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -47,6 +47,7 @@ namespace LHCb::Detector { struct DeFTModuleElement : DeIOVElement { using DeIOVElement::DeIOVElement; FTChannelID::ModuleID moduleID() const{return FTChannelID::ModuleID{this->access()->m_id};} + FTChannelID::StationID stationID() const{return this->access()->m_elementid->station();} /// Find the layer for a given XYZ point const std::optional findMat( const ROOT::Math::XYZPoint& aPoint ) const { @@ -60,6 +61,8 @@ namespace LHCb::Detector { return &(this->access()->m_mats[to_unsigned( id.mat() )]); } [[nodiscard]] FTChannelID elementID() const { return this->access()->m_elementid; } + + [[nodiscard]] int pseudoChannel( const FTChannelID channelID ) const;//FIXME [[nodiscard]] FTChannelID channelFromPseudo( const int pseudoChannel ) const { const auto& obj = this->access(); @@ -67,6 +70,7 @@ namespace LHCb::Detector { if ( obj.m_reversed ) { channelInModule = obj.m_nChannelsInModule - 1 - channelInModule; } return FTChannelID( this->elementID() + channelInModule ); } + ROOT::Math::Plane3D plane() const;//FIXME }; using DeFTModule = DeFTModuleElement; -- GitLab From 2e5be8f67eb6e1c0d873ad2166d520816b563ac4 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Mon, 4 Oct 2021 18:19:17 +0200 Subject: [PATCH 20/37] Small modifications --- Detector/FT/include/Detector/FT/DeFT.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index ddef2991..e03a53a7 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -112,24 +112,24 @@ namespace LHCb::Detector { * @return Pointer to the relevant quarter */ [[nodiscard]] const DeFTQuarter findQuarter( const FTChannelID& aChannel ) const { - const auto* l = findLayer( aChannel ); - return l->findQuarter( aChannel ); + const auto l = findLayer( aChannel ); + return l.findQuarter( aChannel ); } /** Find the FT Module corresponding to the channel id * @return Pointer to the relevant module */ [[nodiscard]] const DeFTModule findModule( const FTChannelID& aChannel ) const { - const auto* q = findQuarter( aChannel ); - return q->findModule( aChannel ); + const auto q = findQuarter( aChannel ); + return q.findModule( aChannel ); } /** Find the FT Mat corresponding to the channel id * @return Pointer to the relevant module */ [[nodiscard]] const DeFTMat findMat( const FTChannelID& aChannel ) const { - const auto* m = findModule( aChannel ); - return m->findMat( aChannel ); + const auto m = findModule( aChannel ); + return m.findMat( aChannel ); } /// Get a random FTChannelID (useful for the thermal noise, which is ~flat) -- GitLab From a51148705e7f0e265ef2c4ecfc7ead9ef673123b Mon Sep 17 00:00:00 2001 From: lohenry Date: Tue, 5 Oct 2021 09:50:57 +0200 Subject: [PATCH 21/37] Untested changes --- Detector/FT/include/Detector/FT/DeFT.h | 6 +++--- Detector/FT/include/Detector/FT/DeFTLayer.h | 10 ++++++++-- Detector/FT/include/Detector/FT/DeFTMat.h | 9 ++++++++- Detector/FT/include/Detector/FT/DeFTModule.h | 2 +- Detector/FT/include/Detector/FT/DeFTQuarter.h | 2 +- Detector/FT/include/Detector/FT/DeFTStation.h | 2 +- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index e03a53a7..7bdb6dc4 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -96,14 +96,14 @@ namespace LHCb::Detector { /** Find the FT Station corresponding to the channel id * @return Pointer to the relevant station */ - [[nodiscard]] const DeFTStation findStation( const FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTStation& findStation( const FTChannelID& aChannel ) const { return &(this->access()->m_stations[to_unsigned( aChannel.station() ) - 1u]); } /** Find the FT Layer corresponding to the channel id * @return Pointer to the relevant layer */ - [[nodiscard]] const DeFTLayer findLayer( const FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTLayer& findLayer( const FTChannelID& aChannel ) const { const auto s = findStation( aChannel ); return s.findLayer( aChannel ); } @@ -111,7 +111,7 @@ namespace LHCb::Detector { /** Find the FT Quarter corresponding to the channel id * @return Pointer to the relevant quarter */ - [[nodiscard]] const DeFTQuarter findQuarter( const FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTQuarter& findQuarter( const FTChannelID& aChannel ) const { const auto l = findLayer( aChannel ); return l.findQuarter( aChannel ); } diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 4f4b7f56..734cf74f 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -34,6 +34,12 @@ namespace LHCb::Detector { void applyToAllChildren( const std::function& func ) const override { for ( auto& quarter : m_quarters ) { func( LHCb::Detector::DeIOV{&quarter} ); }; }; + void applyToAllMats( const std::function& func ) const { + for ( auto& quarter : m_quarters ) { + for (auto& module : quarter.modules()) + module.applyToAllChildren(func); + } + }; }; } // End namespace detail @@ -61,8 +67,8 @@ namespace LHCb::Detector { * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTQuarter findQuarter( const FTChannelID& aChannel ) const { - return this->access()->m_quarters[to_unsigned( aChannel.quarter() )]; + [[nodiscard]] const DeFTQuarter& findQuarter( const FTChannelID& aChannel ) const { + return &(this->access()->m_quarters[to_unsigned( aChannel.quarter() )]); } float globalZ() const;//FIXME diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index 9a0e8b6e..4a65097e 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -46,7 +46,14 @@ namespace LHCb::Detector { ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const;//FIXME ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const;//FIXME FTChannelID calculateChannelAndFrac( float x, float frac ) const;//FIXME - + + double airGap() const {return this->access()->airGap;} + double deadRegion() const{return this->access()->deadRegion;} + double channelPitch() const{return this->access()->channelPitch;} + double sipmPitch() const;//FIXME + double halfChannelPitch() const;//FIXME + double dieGap() const {return dieGap;} + ROOT::Math::XYZVector trajectory(FTChannelID id, float fraction) const; //FIXME }; using DeFTMat = DeFTMatElement; diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 4b96635c..cd14955d 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -57,7 +57,7 @@ namespace LHCb::Detector { return iter != this->access()->m_mats.end() ? iter : std::optional{};//DeFTMat{}; } - [[nodiscard]] const DeFTMat findMat( const FTChannelID& id ) const { + [[nodiscard]] const DeFTMat& findMat( const FTChannelID& id ) const { return &(this->access()->m_mats[to_unsigned( id.mat() )]); } [[nodiscard]] FTChannelID elementID() const { return this->access()->m_elementid; } diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index 9abd30f2..6ba7ea70 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -52,7 +52,7 @@ namespace LHCb::Detector { * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTModule findModule( const FTChannelID aChannel ) const { + [[nodiscard]] const DeFTModule& findModule( const FTChannelID aChannel ) const { auto m = to_unsigned( aChannel.module() ); return &(this->access()->m_modules[m]); } diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index 9f5d1973..91e0a89b 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -53,7 +53,7 @@ namespace LHCb::Detector { * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTLayer findLayer( const FTChannelID& aChannel ) const { + [[nodiscard]] const DeFTLayer& findLayer( const FTChannelID& aChannel ) const { return &(this->access()->m_layers[to_unsigned( aChannel.layer() )]); } }; -- GitLab From 00983837d684a151c570e80be49262ae5916846f Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Tue, 5 Oct 2021 15:10:55 +0200 Subject: [PATCH 22/37] Corrected visitors and methods --- Detector/FT/include/Detector/FT/DeFT.h | 3 +++ Detector/FT/include/Detector/FT/DeFTLayer.h | 2 +- Detector/FT/include/Detector/FT/DeFTMat.h | 4 +++- Detector/FT/src/DeFT.cpp | 13 +++++++------ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 7bdb6dc4..2accfdf7 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -60,6 +60,9 @@ namespace LHCb::Detector { using DeIOVElement::DeIOVElement; int version() const { return this->access()->m_version; }; const std::array stations() const {const auto obj = this->access(); return {obj->m_stations[0],obj->m_stations[1],obj->m_stations[2]};}; + void applyToAllLayers( const std::function )>& func ) const { + this->access()->applyToAllLayers(func); + }; /** Find the FT Station corresponding to the point * @return Pointer to the relevant station */ diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 734cf74f..6aeb2dbf 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -36,7 +36,7 @@ namespace LHCb::Detector { }; void applyToAllMats( const std::function& func ) const { for ( auto& quarter : m_quarters ) { - for (auto& module : quarter.modules()) + for (auto& module : quarter.m_modules) module.applyToAllChildren(func); } }; diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index 4a65097e..e67004ca 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -35,7 +35,8 @@ namespace LHCb::Detector { int nSiPMsInMat{}; int nDiesInSiPM{}; unsigned int matID; - DeFTMatObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iMat); + FTChannelID elementID; + DeFTMatObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iMat, unsigned int iModule); using DeIOVObject::DeIOVObject; }; } // End namespace detail @@ -46,6 +47,7 @@ namespace LHCb::Detector { ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const;//FIXME ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const;//FIXME FTChannelID calculateChannelAndFrac( float x, float frac ) const;//FIXME + FTChannelID elementID() const { return this->access()->elementID; } double airGap() const {return this->access()->airGap;} double deadRegion() const{return this->access()->deadRegion;} diff --git a/Detector/FT/src/DeFT.cpp b/Detector/FT/src/DeFT.cpp index 4dda4b84..85e7d17e 100644 --- a/Detector/FT/src/DeFT.cpp +++ b/Detector/FT/src/DeFT.cpp @@ -57,10 +57,10 @@ LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetEle unsigned int iModule, unsigned int quarterID ) : DeIOVObject( de, ctxt ) , m_id{quarterID * FT::nModules + iModule} - , m_mats{{{de.child( "Mat0" ), ctxt, 0}, - {de.child( "Mat1" ), ctxt, 1}, - {de.child( "Mat2" ), ctxt, 2}, - {de.child( "Mat3" ), ctxt, 3}}} { + , m_mats{{{de.child( "Mat0" ), ctxt, 0, m_id}, + {de.child( "Mat1" ), ctxt, 1, m_id}, + {de.child( "Mat2" ), ctxt, 2, m_id}, + {de.child( "Mat3" ), ctxt, 3, m_id}}} { // Is reversed? const auto firstPoint = this->localToGlobal( {-1, 0, 0} ); const auto lastPoint = this->localToGlobal( {1, 0, 0} ); @@ -77,6 +77,7 @@ LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetEle LHCb::Detector::detail::DeFTMatObject::DeFTMatObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, - unsigned int iMat ) + unsigned int iMat, unsigned int moduleID ) : DeIOVObject( de, ctxt ) - , matID{iMat} {} + , elementID{iMat} + , matID{moduleID * FT::nMats + iMat} {} -- GitLab From dacc8eb91ab09a5803a482907a97ca8b5aa705f1 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Tue, 12 Oct 2021 18:56:07 +0200 Subject: [PATCH 23/37] Adding a few more functions --- Detector/FT/include/Detector/FT/DeFT.h | 24 +++++++++++++++++---- Detector/FT/include/Detector/FT/DeFTLayer.h | 5 +++++ Detector/FT/include/Detector/FT/DeFTMat.h | 9 +++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 2accfdf7..9570b9ef 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -44,10 +44,24 @@ namespace LHCb::Detector { void applyToAllLayers( const std::function& func ) const { for ( auto& station : m_stations ) { station.applyToAllChildren(func); }; }; - }; - - } // End namespace detail - + /* + void applyToAllMats( const std::function& func ) const { + auto stationFunc = [this] (const LHCb::Detector::DeIOV) { + auto layerFunc = [this] (const LHCb::Detector::DeIOV) { + auto quarterFunc = [this] (const LHCb::Detector::DeIOV) { + }; + + }; + }; + auto modFunc = []() + for ( auto& station : m_stations ) { + for ( auto& layer : station.layers ) { + station.applyToAllChildren(func); }; + }; + }; + */ + }; // End namespace detail + } /** * FT interface * @@ -63,6 +77,8 @@ namespace LHCb::Detector { void applyToAllLayers( const std::function )>& func ) const { this->access()->applyToAllLayers(func); }; + DeFTMat firstMat() const;//FIXNE + /** Find the FT Station corresponding to the point * @return Pointer to the relevant station */ diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 6aeb2dbf..ec35c21d 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -73,6 +73,11 @@ namespace LHCb::Detector { float globalZ() const;//FIXME ROOT::Math::Plane3D plane() const;//FIXME + float dxdy() const;//FIXME + float dzdy() const;//FIXME + float sizeX() const;//FIXME + float sizeY() const;//FIXME + }; using DeFTLayer = DeFTLayerElement; diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index e67004ca..37547de5 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -30,6 +30,7 @@ namespace LHCb::Detector { double airGap{}; double deadRegion{}; double channelPitch{}; + float uBegin{}; double dieGap{}; int nChannelsInSiPM{}; int nSiPMsInMat{}; @@ -54,7 +55,13 @@ namespace LHCb::Detector { double channelPitch() const{return this->access()->channelPitch;} double sipmPitch() const;//FIXME double halfChannelPitch() const;//FIXME - double dieGap() const {return dieGap;} + double dieGap() const {return this->access()->dieGap;} + double mirrorPoint() const;//FIXME + double ddx() const;//FIXME + double dxdy() const;//FIXME + double dzdy() const;//FIXME + double globaldy() const;//FIXME + float uBegin() const;//FIXME ROOT::Math::XYZVector trajectory(FTChannelID id, float fraction) const; //FIXME }; -- GitLab From 7c5f52a1bafda38e1ec590693b322dca9d9c8c34 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Fri, 22 Oct 2021 12:46:01 +0200 Subject: [PATCH 24/37] Adding the implementation for most methods --- Detector/FT/include/Detector/FT/DeFT.h | 31 ++--- Detector/FT/include/Detector/FT/DeFTMat.h | 134 +++++++++++++++---- Detector/FT/include/Detector/FT/DeFTModule.h | 33 +++-- Detector/FT/src/DeFT.cpp | 59 +++++++- 4 files changed, 200 insertions(+), 57 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 9570b9ef..6bea2694 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -12,6 +12,7 @@ #include "Detector/FT/DeFTStation.h" #include "Detector/FT/FTChannelID.h" +#include "Detector/FT/FTConstants.h" namespace DeFTLocation { // FT location defined in the XmlDDDB inline const std::string Default = "/dd/Structure/LHCb/AfterMagnetRegion/T/FT"; @@ -44,24 +45,15 @@ namespace LHCb::Detector { void applyToAllLayers( const std::function& func ) const { for ( auto& station : m_stations ) { station.applyToAllChildren(func); }; }; - /* - void applyToAllMats( const std::function& func ) const { - auto stationFunc = [this] (const LHCb::Detector::DeIOV) { - auto layerFunc = [this] (const LHCb::Detector::DeIOV) { - auto quarterFunc = [this] (const LHCb::Detector::DeIOV) { - }; - - }; - }; - auto modFunc = []() - for ( auto& station : m_stations ) { - for ( auto& layer : station.layers ) { - station.applyToAllChildren(func); }; - }; - }; - */ + void applyToAllMats( const std::function )>& func ) const { + for (auto& station : m_stations) + for (auto& layer : station.m_layers) + for (auto& quarter : layer.m_quarters) + for (auto& module : quarter.m_modules) + module.applyToAllChildren(func); + } }; // End namespace detail - } + } /** * FT interface * @@ -77,6 +69,9 @@ namespace LHCb::Detector { void applyToAllLayers( const std::function )>& func ) const { this->access()->applyToAllLayers(func); }; + void applyToAllMats( const std::function )>& func ) const { + this->access()->applyToAllMats(func); + } DeFTMat firstMat() const;//FIXNE /** Find the FT Station corresponding to the point @@ -111,7 +106,7 @@ namespace LHCb::Detector { const auto m = findModule( aPoint ); return m ? m->findMat( aPoint ) : std::optional{};//DeFTMat{}; } - + /** Find the FT Station corresponding to the channel id * @return Pointer to the relevant station */ diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index 37547de5..e9c182b9 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -27,42 +27,124 @@ namespace LHCb::Detector { * \version 1.0 */ struct DeFTMatObject : DeIOVObject { - double airGap{}; - double deadRegion{}; - double channelPitch{}; - float uBegin{}; - double dieGap{}; - int nChannelsInSiPM{}; - int nSiPMsInMat{}; - int nDiesInSiPM{}; - unsigned int matID; - FTChannelID elementID; + + FTChannelID m_elementID; ///< element ID + unsigned int m_matID;//FIXME: needed? + // dd4hep::_toDouble + int m_nChannelsInSiPM = {dd4hep::_toInt("FT::nChannelsInSiPM")}; ///< number of channels per SiPM // FIXME: it is constant + int m_nChannelsInDie; ///< number of channels per die + int m_nSiPMsInMat = {dd4hep::_toInt("FT::nSiPMsInMat")}; ///< number of SiPM arrays per mat // FIXME: it is constant + int m_nDiesInSiPM = {dd4hep::_toInt("FT::nDiesInSiPM")}; ///< number of dies per SiPM + + ROOT::Math::Plane3D m_plane; ///< xy-plane in the z-middle of the module + ROOT::Math::XYZPointF m_sipmPoint; ///< Location of end of fibres at x=z=0 + float m_globalZ; ///< Global z position of module closest to y-axis + float m_airGap = {dd4hep::_toFloat("FT::airGap")}; ///< air gap + float m_deadRegion = {dd4hep::_toFloat("FT::deadRegion")}; ///< dead region + float m_channelPitch = {dd4hep::_toFloat("FT::channelPitch")}; ///< readout channel pitch (250 micron) + float m_diePitch; ///< pitch between dies in SiPM + float m_sizeX; ///< Width in x of the mat + float m_sizeY; ///< Length in y of the fibre in the mat + float m_sizeZ; ///< Thickness of the fibre mat (nominal: 1.3 mm) + + // Parameters needed for decoding + ROOT::Math::XYZPointF m_mirrorPoint; ///< Location of end of fibres at x=z=0 + ROOT::Math::XYZVectorF m_ddx; ///< Global direction vector for a local displacement in unit x + float m_uBegin; ///< start in local u-coordinate of sensitive SiPM + float m_halfChannelPitch; ///< half of the readout channel pitch (125 micron) + float m_dieGap = {dd4hep::_toFloat("FT::dieGap")}; ///< gap between channel 63 and 64 + float m_sipmPitch; ///< pitch between SiPMs in mat + float m_dxdy; ///< Global slope dx/dy for a fibre mat + float m_dzdy; ///< Global slope dz/dy for a fibre mat + float m_globaldy; ///< Length of a fibre projected along global y + DeFTMatObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iMat, unsigned int iModule); + ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const;//FIXME + ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const;//FIXME + ROOT::Math::XYZPoint toGlobal( const ROOT::Math::XYZPoint& p ) const {return ROOT::Math::XYZPoint(this->detectorAlignment.localToWorld(ROOT::Math::XYZVector(p)));} + ROOT::Math::XYZVector toGlobal( const ROOT::Math::XYZVector& v ) const {return this->detectorAlignment.localToWorld(v);} + using DeIOVObject::DeIOVObject; }; } // End namespace detail template struct DeFTMatElement : DeIOVElement { using DeIOVElement::DeIOVElement; + + //Getters + FTChannelID elementID() const { return this->access()->m_elementID; } + float airGap() const {return this->access()->m_airGap;} + float deadRegion() const {return this->access()->m_deadRegion;} + float channelPitch() const {return this->access()->m_channelPitch;} + float sipmPitch() const {return this->access()->m_sipmPitch;}; + float halfChannelPitch() const {return this->access()->m_halfChannelPitch;}; + float dieGap() const {return this->access()->m_dieGap;} + ROOT::Math::XYZPointF mirrorPoint() const {return this->access()->m_mirrorPoint;} + ROOT::Math::XYZVectorF ddx() const {return this->access()->m_ddx;} + float dxdy() const {return this->access()->m_dxdy;} + float dzdy() const {return this->access()->m_dzdy;} + float globaldy() const {return this->access()->m_globaldy;} + float globalZ() const {return this->access()->m_globalZ;} + float uBegin() const {return this->access()->m_uBegin;} + + // Element ID operations + FTChannelID::StationID stationID() const {return this->elementID().stationID();} + FTChannelID::LayerID layerID() const {return this->elementID().layerID ();} + FTChannelID::QuarterID quarterID() const {return this->elementID().quarterID();} + FTChannelID::ModuleID moduleID() const {return this->elementID().moduleID ();} FTChannelID::MatID matID() const{return FTChannelID::MatID{this->access()->matID};} - ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const;//FIXME - ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const;//FIXME - FTChannelID calculateChannelAndFrac( float x, float frac ) const;//FIXME - FTChannelID elementID() const { return this->access()->elementID; } + bool isBottom() const { return this->access()->m_elementID.isBottom(); } + bool isTop() const { return this->access()->m_elementID.isTop(); } + bool hasGapRight( const FTChannelID thisChannel ) const { + return ( int( thisChannel.channel() ) == this->access()->m_nChannelsInSiPM - 1 || + int( thisChannel.channel() ) == this->access()->m_nChannelsInDie - 1 ); + } - double airGap() const {return this->access()->airGap;} - double deadRegion() const{return this->access()->deadRegion;} - double channelPitch() const{return this->access()->channelPitch;} - double sipmPitch() const;//FIXME - double halfChannelPitch() const;//FIXME - double dieGap() const {return this->access()->dieGap;} - double mirrorPoint() const;//FIXME - double ddx() const;//FIXME - double dxdy() const;//FIXME - double dzdy() const;//FIXME - double globaldy() const;//FIXME - float uBegin() const;//FIXME + // Geometrical operations + ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const {return this->access()->toLocal(p);} + ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const {return this->access()->toLocal(v);} + ROOT::Math::XYZPoint toGlobal( const ROOT::Math::XYZPoint& p ) const {return this->access()->toGlobal(p);} + ROOT::Math::XYZVector toGlobal( const ROOT::Math::XYZVector& v ) const {return this->access()->toGlobal(v);} ROOT::Math::XYZVector trajectory(FTChannelID id, float fraction) const; //FIXME + + // Others + FTChannelID calculateChannelAndFrac( float x, float frac ) const { + auto& obj = this->access(); + // Correct for the starting point of the sensitive area + float xInMat = x - obj.m_uBegin; + + // Find the sipm that is hit and the local position within the sipm + int hitSiPM = std::clamp( int( xInMat / obj.m_sipmPitch ), 0, obj.m_nSiPMsInMat - 1 ); + float xInSiPM = fma( -obj.m_sipmPitch, hitSiPM, xInMat ); + + // Find the die that is hit and the local position within the die + int hitDie = std::clamp( int( xInSiPM / obj.m_diePitch ), 0, obj.m_nDiesInSiPM - 1 ); + float chanInDie = fma( -obj.m_diePitch, hitDie, xInSiPM ) / obj.m_channelPitch; + + // Find the channel that is hit and the local position within the channel + int hitChan = std::clamp( int( chanInDie ), 0, obj.m_nChannelsInDie - 1 ); + frac = chanInDie - hitChan - 0.5f; + // Construct channelID + return FTChannelID( stationID(), layerID(), quarterID(), moduleID(), matID(), hitSiPM, + hitChan + ( hitDie * obj.m_nChannelsInDie ) ); + } + + /** Get the local x from a channelID and its fraction */ + [[nodiscard]] float localXfromChannel( const FTChannelID channelID, const int frac ) const { + auto& obj = this->access(); + float uFromChannel = obj.m_uBegin + ( 2 * channelID.channel() + 1 + frac ) * obj.m_halfChannelPitch; + if ( channelID.die() ) uFromChannel += obj.m_dieGap; + uFromChannel += channelID.sipm() * obj.m_sipmPitch; + return uFromChannel; + } + + // Get the distance between a 3D global point and a channel+fraction + float distancePointToChannel( const ROOT::Math::XYZPoint& globalPoint, const FTChannelID channelID, + const float frac ) const { + ROOT::Math::XYZPoint localPoint = toLocal( globalPoint ); + return localXfromChannel( channelID, frac ) - localPoint.x(); + } + }; using DeFTMat = DeFTMatElement; diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index cd14955d..3a723995 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -30,24 +30,41 @@ namespace LHCb::Detector { unsigned int m_id; int m_nChannelsInModule{dd4hep::_toInt( "FT:nChannelsInModule" )}; std::array m_mats; + ROOT::Math::Plane3D m_plane;///< xy-plane in the z-middle of the module bool m_reversed; - FTChannelID m_elementid; + FTChannelID m_elementID; DeFTModuleObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iModule, unsigned int quarterID ); /// Convert local position to global position - ROOT::Math::XYZPoint localToGlobal( const ROOT::Math::XYZPoint& point ) const { + ROOT::Math::XYZPoint toGlobal( const ROOT::Math::XYZPoint& point ) const { return ROOT::Math::XYZPoint( this->detectorAlignment.localToWorld( ROOT::Math::XYZVector( point ) ) ); } void applyToAllChildren( const std::function& func ) const override { for ( auto& mat : m_mats ) { func( LHCb::Detector::DeIOV{&mat} ); }; }; + FTChannelID::StationID stationID() const{return m_elementID.station();} + FTChannelID::ModuleID moduleID() const{return FTChannelID::ModuleID{m_id};} + + /// Get the pseudo-channel for a FTChannelID (useful in the monitoring) + int pseudoChannel( const FTChannelID channelID ) const { + int channelInModule = channelID.channelID() & ( m_nChannelsInModule - 1u ); + if ( m_reversed ) { channelInModule = m_nChannelsInModule - 1 - channelInModule; } + return channelInModule + to_unsigned( moduleID() ) * m_nChannelsInModule; + } + + FTChannelID channelFromPseudo( const int pseudoChannel ) const { + int channelInModule = pseudoChannel & ( m_nChannelsInModule - 1u ); + if ( m_reversed ) { channelInModule = m_nChannelsInModule - 1 - channelInModule; } + return FTChannelID( m_elementID + channelInModule ); + } + }; } // End namespace detail template struct DeFTModuleElement : DeIOVElement { using DeIOVElement::DeIOVElement; - FTChannelID::ModuleID moduleID() const{return FTChannelID::ModuleID{this->access()->m_id};} - FTChannelID::StationID stationID() const{return this->access()->m_elementid->station();} + FTChannelID::ModuleID moduleID() const{return this->access()->moduleID();} + FTChannelID::StationID stationID() const{return this->access()->stationID();} /// Find the layer for a given XYZ point const std::optional findMat( const ROOT::Math::XYZPoint& aPoint ) const { @@ -60,17 +77,17 @@ namespace LHCb::Detector { [[nodiscard]] const DeFTMat& findMat( const FTChannelID& id ) const { return &(this->access()->m_mats[to_unsigned( id.mat() )]); } - [[nodiscard]] FTChannelID elementID() const { return this->access()->m_elementid; } + [[nodiscard]] FTChannelID elementID() const { return this->access()->m_elementID; } - [[nodiscard]] int pseudoChannel( const FTChannelID channelID ) const;//FIXME - + [[nodiscard]] int pseudoChannel( const FTChannelID channelID ) const {return this->access()->pseudoChannel(channelID);} + [[nodiscard]] FTChannelID channelFromPseudo( const int pseudoChannel ) const { const auto& obj = this->access(); int channelInModule = pseudoChannel & ( obj.m_nChannelsInModule - 1u ); if ( obj.m_reversed ) { channelInModule = obj.m_nChannelsInModule - 1 - channelInModule; } return FTChannelID( this->elementID() + channelInModule ); } - ROOT::Math::Plane3D plane() const;//FIXME + ROOT::Math::Plane3D plane() const {return this->access()->m_plane;} }; using DeFTModule = DeFTModuleElement; diff --git a/Detector/FT/src/DeFT.cpp b/Detector/FT/src/DeFT.cpp index 85e7d17e..0acf3692 100644 --- a/Detector/FT/src/DeFT.cpp +++ b/Detector/FT/src/DeFT.cpp @@ -62,9 +62,15 @@ LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetEle {de.child( "Mat2" ), ctxt, 2, m_id}, {de.child( "Mat3" ), ctxt, 3, m_id}}} { // Is reversed? - const auto firstPoint = this->localToGlobal( {-1, 0, 0} ); - const auto lastPoint = this->localToGlobal( {1, 0, 0} ); + const auto firstPoint = this->toGlobal( {-1, 0, 0} ); + const auto lastPoint = this->toGlobal( {1, 0, 0} ); m_reversed = std::abs( firstPoint.x() ) > std::abs( lastPoint.x() ); + // Make the plane for the module + const ROOT::Math::XYZPoint g1 = this->toGlobal( ROOT::Math::XYZPoint( 0., 0., 0. ) ); + const ROOT::Math::XYZPoint g2 = this->toGlobal( ROOT::Math::XYZPoint( 1., 0., 0. ) ); + const ROOT::Math::XYZPoint g3 = this->toGlobal( ROOT::Math::XYZPoint( 0., 1., 0. ) ); + m_plane = ROOT::Math::Plane3D( g1, g2, g3 ); + // Build the FTChannelID auto localModuleID = FTChannelID::ModuleID{static_cast( m_id % FT::nModules )}; auto localQuarterID = FTChannelID::QuarterID{static_cast( m_id % ( FT::nModules * FT::nQuarters ) )}; @@ -72,12 +78,55 @@ LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetEle FTChannelID::LayerID{static_cast( m_id % ( FT::nModules * FT::nQuarters * FT::nLayers ) )}; auto localStationID = FTChannelID::StationID{static_cast( m_id / ( FT::nModules * FT::nQuarters * FT::nLayers ) )}; - m_elementid = FTChannelID( localStationID, localLayerID, localQuarterID, localModuleID, 0 ); + m_elementID = FTChannelID( localStationID, localLayerID, localQuarterID, localModuleID, 0 ); } LHCb::Detector::detail::DeFTMatObject::DeFTMatObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iMat, unsigned int moduleID ) : DeIOVObject( de, ctxt ) - , elementID{iMat} - , matID{moduleID * FT::nMats + iMat} {} + , m_elementID{iMat} + , m_matID{moduleID * FT::nMats + iMat} + { + //FIXME: see VP + // Get some useful geometric parameters from the database + m_halfChannelPitch = 0.5f * m_channelPitch; + + m_sipmPitch = m_nChannelsInSiPM * m_channelPitch + m_dieGap + 2 * m_airGap + 2 * m_deadRegion; + m_nChannelsInDie = m_nChannelsInSiPM / m_nDiesInSiPM; + m_diePitch = m_nChannelsInDie * m_channelPitch + m_dieGap; + m_uBegin = m_airGap + m_deadRegion - 2.f * m_sipmPitch; + + //Update cache + //FIXME + // Get the boundaries of the layer + // const SolidBox* box = dynamic_cast( geometry()->lvolume()->solid()->coverTop() ); + // m_sizeX = box->xsize(); + // m_sizeY = box->ysize(); + // m_sizeZ = box->zsize(); + + // Get the central points of the fibres at the mirror and at the SiPM locations + m_mirrorPoint = this->toGlobal( ROOT::Math::XYZPoint( 0, -0.5f * m_sizeY, 0 ) ); + m_sipmPoint = this->toGlobal( ROOT::Math::XYZPoint( 0, +0.5f * m_sizeY, 0 ) ); + + // Define the global z position to be at the point closest to the mirror + m_globalZ = m_mirrorPoint.z(); + + // Define the global length in y of the mat + m_globaldy = m_sipmPoint.y() - m_mirrorPoint.y(); + + // Make the plane for the mat + const ROOT::Math::XYZPoint g1 = this->toGlobal( ROOT::Math::XYZPoint( 0., 0., 0. ) ); + const ROOT::Math::XYZPoint g2 = this->toGlobal( ROOT::Math::XYZPoint( 1., 0., 0. ) ); + const ROOT::Math::XYZPoint g3 = this->toGlobal( ROOT::Math::XYZPoint( 0., 1., 0. ) ); + m_plane = ROOT::Math::Plane3D( g1, g2, g3 ); + + // Get the slopes in units of local delta x + m_ddx = ROOT::Math::XYZVectorF( g2 - g1 ); + + // Get the slopes in units of delta y (needed by PrFTHit, mind the sign) + ROOT::Math::XYZVectorF deltaY( g1 - g3 ); + m_dxdy = deltaY.x() / deltaY.y(); + m_dzdy = deltaY.z() / deltaY.y(); + + } -- GitLab From 10912b05b6a9c96d1f4c0a8cdeaf9445dc5fa43a Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Fri, 22 Oct 2021 14:37:32 +0200 Subject: [PATCH 25/37] Updated implementation --- Detector/FT/include/Detector/FT/DeFTMat.h | 42 +++++++++---------- Detector/FT/include/Detector/FT/FTConstants.h | 2 + 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index e9c182b9..f4262d90 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -33,14 +33,14 @@ namespace LHCb::Detector { // dd4hep::_toDouble int m_nChannelsInSiPM = {dd4hep::_toInt("FT::nChannelsInSiPM")}; ///< number of channels per SiPM // FIXME: it is constant int m_nChannelsInDie; ///< number of channels per die - int m_nSiPMsInMat = {dd4hep::_toInt("FT::nSiPMsInMat")}; ///< number of SiPM arrays per mat // FIXME: it is constant - int m_nDiesInSiPM = {dd4hep::_toInt("FT::nDiesInSiPM")}; ///< number of dies per SiPM + int m_nSiPMsInMat = FT::nSiPM; ///< number of SiPM arrays per mat // FIXME: it is constant + int m_nDiesInSiPM = FT::nChannels; ///< number of dies per SiPM ROOT::Math::Plane3D m_plane; ///< xy-plane in the z-middle of the module ROOT::Math::XYZPointF m_sipmPoint; ///< Location of end of fibres at x=z=0 float m_globalZ; ///< Global z position of module closest to y-axis - float m_airGap = {dd4hep::_toFloat("FT::airGap")}; ///< air gap - float m_deadRegion = {dd4hep::_toFloat("FT::deadRegion")}; ///< dead region + float m_airGap = {dd4hep::_toFloat("FT::airGap")}; ///< air gap + float m_deadRegion = {dd4hep::_toFloat("FT::deadRegion")}; ///< dead region float m_channelPitch = {dd4hep::_toFloat("FT::channelPitch")}; ///< readout channel pitch (250 micron) float m_diePitch; ///< pitch between dies in SiPM float m_sizeX; ///< Width in x of the mat @@ -88,11 +88,11 @@ namespace LHCb::Detector { float uBegin() const {return this->access()->m_uBegin;} // Element ID operations - FTChannelID::StationID stationID() const {return this->elementID().stationID();} - FTChannelID::LayerID layerID() const {return this->elementID().layerID ();} - FTChannelID::QuarterID quarterID() const {return this->elementID().quarterID();} - FTChannelID::ModuleID moduleID() const {return this->elementID().moduleID ();} - FTChannelID::MatID matID() const{return FTChannelID::MatID{this->access()->matID};} + FTChannelID::StationID stationID() const {return this->elementID().station();} + FTChannelID::LayerID layerID() const {return this->elementID().layer ();} + FTChannelID::QuarterID quarterID() const {return this->elementID().quarter();} + FTChannelID::ModuleID moduleID() const {return this->elementID().module ();} + FTChannelID::MatID matID() const{return FTChannelID::MatID{this->access()->m_matID};} bool isBottom() const { return this->access()->m_elementID.isBottom(); } bool isTop() const { return this->access()->m_elementID.isTop(); } bool hasGapRight( const FTChannelID thisChannel ) const { @@ -109,32 +109,32 @@ namespace LHCb::Detector { // Others FTChannelID calculateChannelAndFrac( float x, float frac ) const { - auto& obj = this->access(); + const auto& obj = this->access(); // Correct for the starting point of the sensitive area - float xInMat = x - obj.m_uBegin; + float xInMat = x - obj->m_uBegin; // Find the sipm that is hit and the local position within the sipm - int hitSiPM = std::clamp( int( xInMat / obj.m_sipmPitch ), 0, obj.m_nSiPMsInMat - 1 ); - float xInSiPM = fma( -obj.m_sipmPitch, hitSiPM, xInMat ); + int hitSiPM = std::clamp( int( xInMat / obj->m_sipmPitch ), 0, obj->m_nSiPMsInMat - 1 ); + float xInSiPM = fma( -obj->m_sipmPitch, hitSiPM, xInMat ); // Find the die that is hit and the local position within the die - int hitDie = std::clamp( int( xInSiPM / obj.m_diePitch ), 0, obj.m_nDiesInSiPM - 1 ); - float chanInDie = fma( -obj.m_diePitch, hitDie, xInSiPM ) / obj.m_channelPitch; + int hitDie = std::clamp( int( xInSiPM / obj->m_diePitch ), 0, obj->m_nDiesInSiPM - 1 ); + float chanInDie = fma( -obj->m_diePitch, hitDie, xInSiPM ) / obj->m_channelPitch; // Find the channel that is hit and the local position within the channel - int hitChan = std::clamp( int( chanInDie ), 0, obj.m_nChannelsInDie - 1 ); + int hitChan = std::clamp( int( chanInDie ), 0, obj->m_nChannelsInDie - 1 ); frac = chanInDie - hitChan - 0.5f; // Construct channelID return FTChannelID( stationID(), layerID(), quarterID(), moduleID(), matID(), hitSiPM, - hitChan + ( hitDie * obj.m_nChannelsInDie ) ); + hitChan + ( hitDie * obj->m_nChannelsInDie ) ); } /** Get the local x from a channelID and its fraction */ [[nodiscard]] float localXfromChannel( const FTChannelID channelID, const int frac ) const { - auto& obj = this->access(); - float uFromChannel = obj.m_uBegin + ( 2 * channelID.channel() + 1 + frac ) * obj.m_halfChannelPitch; - if ( channelID.die() ) uFromChannel += obj.m_dieGap; - uFromChannel += channelID.sipm() * obj.m_sipmPitch; + const auto& obj = this->access(); + float uFromChannel = obj->m_uBegin + ( 2 * channelID.channel() + 1 + frac ) * obj->m_halfChannelPitch; + if ( channelID.die() ) uFromChannel += obj->m_dieGap; + uFromChannel += channelID.sipm() * obj->m_sipmPitch; return uFromChannel; } diff --git a/Detector/FT/include/Detector/FT/FTConstants.h b/Detector/FT/include/Detector/FT/FTConstants.h index f00a4c24..c53e55cc 100644 --- a/Detector/FT/include/Detector/FT/FTConstants.h +++ b/Detector/FT/include/Detector/FT/FTConstants.h @@ -25,6 +25,8 @@ namespace LHCb::Detector { constexpr unsigned int nQuarters = 4; constexpr unsigned int nModules = 6; constexpr unsigned int nMats = 4; + constexpr unsigned int nSiPM = 4; + constexpr unsigned int nChannels = 128; } // namespace FT } // End namespace LHCb::Detector -- GitLab From 31fe6cdde6b44abb46e04186c6b8ef181c8ec605 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Sat, 23 Oct 2021 16:13:19 +0200 Subject: [PATCH 26/37] More methods implemented --- Detector/FT/include/Detector/FT/DeFT.h | 2 +- Detector/FT/include/Detector/FT/DeFTLayer.h | 12 ++++++------ Detector/FT/include/Detector/FT/DeFTMat.h | 11 ++++++++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 6bea2694..b3c7eec0 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -72,7 +72,7 @@ namespace LHCb::Detector { void applyToAllMats( const std::function )>& func ) const { this->access()->applyToAllMats(func); } - DeFTMat firstMat() const;//FIXNE + DeFTMat firstMat() const {return {};}//FIXNE /** Find the FT Station corresponding to the point * @return Pointer to the relevant station diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index ec35c21d..68651095 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -71,12 +71,12 @@ namespace LHCb::Detector { return &(this->access()->m_quarters[to_unsigned( aChannel.quarter() )]); } - float globalZ() const;//FIXME - ROOT::Math::Plane3D plane() const;//FIXME - float dxdy() const;//FIXME - float dzdy() const;//FIXME - float sizeX() const;//FIXME - float sizeY() const;//FIXME + float globalZ() const {return 0.;}//FIXME + ROOT::Math::Plane3D plane() const {return {};}//FIXME + float dxdy() const {return 0.;}//FIXME + float dzdy() const {return 0.;}//FIXME + float sizeX() const {return 0.;}//FIXME + float sizeY() const {return 0.;}//FIXME }; diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index f4262d90..4ad20d75 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -11,6 +11,7 @@ #pragma once #include "Core/DeIOV.h" +#include "Core/LineTraj.h" #include "Detector/FT/FTChannelID.h" #include "Detector/FT/FTConstants.h" @@ -59,8 +60,12 @@ namespace LHCb::Detector { float m_globaldy; ///< Length of a fibre projected along global y DeFTMatObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iMat, unsigned int iModule); - ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const;//FIXME - ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const;//FIXME + ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const{ + return ROOT::Math::XYZPoint( toLHCbUnits( this->detectorAlignment.worldToLocal(toDD4hepUnits( ROOT::Math::XYZVector( p ) ) ) ) ); + } + ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const{ + return toLHCbUnits(this->detectorAlignment.worldToLocal( toDD4hepUnits( v ) ) ); + } ROOT::Math::XYZPoint toGlobal( const ROOT::Math::XYZPoint& p ) const {return ROOT::Math::XYZPoint(this->detectorAlignment.localToWorld(ROOT::Math::XYZVector(p)));} ROOT::Math::XYZVector toGlobal( const ROOT::Math::XYZVector& v ) const {return this->detectorAlignment.localToWorld(v);} @@ -105,7 +110,7 @@ namespace LHCb::Detector { ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const {return this->access()->toLocal(v);} ROOT::Math::XYZPoint toGlobal( const ROOT::Math::XYZPoint& p ) const {return this->access()->toGlobal(p);} ROOT::Math::XYZVector toGlobal( const ROOT::Math::XYZVector& v ) const {return this->access()->toGlobal(v);} - ROOT::Math::XYZVector trajectory(FTChannelID id, float fraction) const; //FIXME + LineTraj trajectory(FTChannelID id, float fraction) const {return {};} //FIXME // Others FTChannelID calculateChannelAndFrac( float x, float frac ) const { -- GitLab From 0f63398b1819a60aa4bc46c8999b1441361b297a Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Sun, 24 Oct 2021 13:14:24 +0200 Subject: [PATCH 27/37] Use std::optional for all findX functions, eases access --- Detector/FT/include/Detector/FT/DeFT.h | 64 ++++++++++--------- Detector/FT/include/Detector/FT/DeFTLayer.h | 7 +- Detector/FT/include/Detector/FT/DeFTMat.h | 27 +++++++- Detector/FT/include/Detector/FT/DeFTModule.h | 5 +- Detector/FT/include/Detector/FT/DeFTQuarter.h | 6 +- Detector/FT/include/Detector/FT/DeFTStation.h | 4 +- 6 files changed, 71 insertions(+), 42 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index b3c7eec0..6cb01ef1 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -50,7 +50,7 @@ namespace LHCb::Detector { for (auto& layer : station.m_layers) for (auto& quarter : layer.m_quarters) for (auto& module : quarter.m_modules) - module.applyToAllChildren(func); + module.applyToAllChildren(func); } }; // End namespace detail } @@ -74,6 +74,9 @@ namespace LHCb::Detector { } DeFTMat firstMat() const {return {};}//FIXNE + int nStations() const {return 0;}//FIXME + int nChannels() const {return 0;}//FIXME + /** Find the FT Station corresponding to the point * @return Pointer to the relevant station */ @@ -110,32 +113,32 @@ namespace LHCb::Detector { /** Find the FT Station corresponding to the channel id * @return Pointer to the relevant station */ - [[nodiscard]] const DeFTStation& findStation( const FTChannelID& aChannel ) const { - return &(this->access()->m_stations[to_unsigned( aChannel.station() ) - 1u]); + [[nodiscard]] const std::optional findStation( const FTChannelID& aChannel ) const { + return (to_unsigned( aChannel.station() ) < this->access()->m_stations.size())? &(this->access()->m_stations[to_unsigned( aChannel.station() )]): std::optional{}; } - + /** Find the FT Layer corresponding to the channel id * @return Pointer to the relevant layer */ - [[nodiscard]] const DeFTLayer& findLayer( const FTChannelID& aChannel ) const { + [[nodiscard]] const std::optional findLayer( const FTChannelID& aChannel ) const { const auto s = findStation( aChannel ); - return s.findLayer( aChannel ); + return s? s->findLayer( aChannel ) : std::optional{}; } /** Find the FT Quarter corresponding to the channel id * @return Pointer to the relevant quarter */ - [[nodiscard]] const DeFTQuarter& findQuarter( const FTChannelID& aChannel ) const { + [[nodiscard]] const std::optional findQuarter( const FTChannelID& aChannel ) const { const auto l = findLayer( aChannel ); - return l.findQuarter( aChannel ); + return l? l->findQuarter( aChannel ) : std::optional{}; } /** Find the FT Module corresponding to the channel id * @return Pointer to the relevant module */ - [[nodiscard]] const DeFTModule findModule( const FTChannelID& aChannel ) const { + [[nodiscard]] const std::optional findModule( const FTChannelID& aChannel ) const { const auto q = findQuarter( aChannel ); - return q.findModule( aChannel ); + return q? q->findModule( aChannel ) : std::optional{}; } /** Find the FT Mat corresponding to the channel id @@ -150,21 +153,21 @@ namespace LHCb::Detector { FTChannelID getRandomChannelFromSeed( const float seed ) const { if ( seed < 0.f || seed > 1.f ) return FTChannelID::kInvalidChannel(); const auto& obj = this->access(); - unsigned int flatChannel = int( seed * obj.m_nTotChannels ); - unsigned int channelInModule = flatChannel & ( obj.m_nChannelsInModule - 1u ); - flatChannel /= obj.m_nChannelsInModule; - unsigned int quarter = flatChannel & ( obj.m_nQuarters - 1u ); - flatChannel /= obj.m_nQuarters; - unsigned int layer = flatChannel & ( obj.m_nLayers - 1u ); - flatChannel /= obj.m_nLayers; + unsigned int flatChannel = int( seed * obj->m_nTotChannels ); + unsigned int channelInModule = flatChannel & ( obj->m_nChannelsInModule - 1u ); + flatChannel /= obj->m_nChannelsInModule; + unsigned int quarter = flatChannel & ( obj->m_nQuarters - 1u ); + flatChannel /= obj->m_nQuarters; + unsigned int layer = flatChannel & ( obj->m_nLayers - 1u ); + flatChannel /= obj->m_nLayers; unsigned int station = 1; unsigned int module = flatChannel; - if ( flatChannel >= obj.m_nModulesT1 + obj.m_nModulesT2 ) { + if ( flatChannel >= obj->m_nModulesT1 + obj->m_nModulesT2 ) { station = 3; - module = flatChannel - obj.m_nModulesT1 - obj.m_nModulesT2; - } else if ( flatChannel >= obj.m_nModulesT1 ) { + module = flatChannel - obj->m_nModulesT1 - obj->m_nModulesT2; + } else if ( flatChannel >= obj->m_nModulesT1 ) { station = 2; - module = flatChannel - obj.m_nModulesT1; + module = flatChannel - obj->m_nModulesT1; } return FTChannelID( FTChannelID::StationID{station}, FTChannelID::LayerID{layer}, FTChannelID::QuarterID{quarter}, FTChannelID::ModuleID{module}, channelInModule ); @@ -175,17 +178,16 @@ namespace LHCb::Detector { // FIXME: moduleDet->channelFromPseudo returns invalidChannel all the time if ( seed < 0.f || seed > 1.f ) return FTChannelID::kInvalidChannel(); const auto& obj = this->access(); - unsigned int flatQuarter = int( seed * obj.m_nTotQuarters ); - auto quarter = FTChannelID::QuarterID{flatQuarter & ( obj.m_nQuarters - 1u )}; - flatQuarter /= obj.m_nQuarters; - auto layer = FTChannelID::LayerID{flatQuarter & ( obj.m_nLayers - 1u )}; - flatQuarter /= obj.m_nLayers; - auto station = FTChannelID::StationID{( flatQuarter & obj.m_stations.size() ) + 1u}; + unsigned int flatQuarter = int( seed * obj->m_nTotQuarters ); + auto quarter = FTChannelID::QuarterID{flatQuarter & ( obj->m_nQuarters - 1u )}; + flatQuarter /= obj->m_nQuarters; + auto layer = FTChannelID::LayerID{flatQuarter & ( obj->m_nLayers - 1u )}; + flatQuarter /= obj->m_nLayers; + auto station = FTChannelID::StationID{( flatQuarter & obj->m_stations.size() ) + 1u}; - auto module = FTChannelID::ModuleID{pseudoChannel / obj.m_nChannelsInModule}; - const DeFTModule* moduleDet = findModule( FTChannelID( station, layer, quarter, module, 0u ) ); - return moduleDet ? moduleDet->channelFromPseudo( pseudoChannel & ( obj.m_nChannelsInModule - 1u ) ) - : FTChannelID::kInvalidChannel(); + auto module = FTChannelID::ModuleID{pseudoChannel / obj->m_nChannelsInModule}; + const auto& moduleDet = findModule( FTChannelID( station, layer, quarter, module, 0u ) ); + return moduleDet->channelFromPseudo( pseudoChannel & ( obj->m_nChannelsInModule - 1u ) ); } }; diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 68651095..ba64eb4e 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -67,13 +67,14 @@ namespace LHCb::Detector { * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTQuarter& findQuarter( const FTChannelID& aChannel ) const { - return &(this->access()->m_quarters[to_unsigned( aChannel.quarter() )]); + [[nodiscard]] const std::optional findQuarter( const FTChannelID& id ) const { + return (to_unsigned( id.quarter() ) < this->access()->m_quarters.size())? &(this->access()->m_quarters[to_unsigned( id.quarter() )]): std::optional{}; } float globalZ() const {return 0.;}//FIXME ROOT::Math::Plane3D plane() const {return {};}//FIXME - float dxdy() const {return 0.;}//FIXME + float dxdy() const {return 0.;}//FIXME + float stereoAngle() const {return 0.;}//FIXME float dzdy() const {return 0.;}//FIXME float sizeX() const {return 0.;}//FIXME float sizeY() const {return 0.;}//FIXME diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index 4ad20d75..e8b07313 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -91,6 +91,14 @@ namespace LHCb::Detector { float globaldy() const {return this->access()->m_globaldy;} float globalZ() const {return this->access()->m_globalZ;} float uBegin() const {return this->access()->m_uBegin;} + /** Returns the width of the fibre mat */ + [[nodiscard]] float fibreMatWidth() const { return this->access()->m_sizeX; } + + /** Get the length of the fibre in this mat */ + [[nodiscard]] float fibreLength() const { return this->access()->m_sizeY; } + + /** Returns the thickness of the fibre mat (1.3 mm) */ + [[nodiscard]] float fibreMatThickness() const { return this->access()->m_sizeZ; } // Element ID operations FTChannelID::StationID stationID() const {return this->elementID().station();} @@ -133,7 +141,24 @@ namespace LHCb::Detector { return FTChannelID( stationID(), layerID(), quarterID(), moduleID(), matID(), hitSiPM, hitChan + ( hitDie * obj->m_nChannelsInDie ) ); } - + [[nodiscard]] std::vector> calculateChannels( FTChannelID thisChannel, FTChannelID endChannel ) const{ + const auto& obj = this->access(); + // Reserve memory + std::vector> channelsAndLeftEdges; + channelsAndLeftEdges.reserve( endChannel - thisChannel ); + + // Loop over the intermediate channels + bool keepAdding = true; + while ( keepAdding ) { + float channelLeftEdge = localXfromChannel( thisChannel, -0.5f ); + // Add channel and left edge to output vector. + channelsAndLeftEdges.emplace_back( thisChannel, channelLeftEdge ); + if ( thisChannel == endChannel ) keepAdding = false; + thisChannel.advance(); + } + return channelsAndLeftEdges; + } + /** Get the local x from a channelID and its fraction */ [[nodiscard]] float localXfromChannel( const FTChannelID channelID, const int frac ) const { const auto& obj = this->access(); diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 3a723995..ba368eee 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -74,9 +74,10 @@ namespace LHCb::Detector { return iter != this->access()->m_mats.end() ? iter : std::optional{};//DeFTMat{}; } - [[nodiscard]] const DeFTMat& findMat( const FTChannelID& id ) const { - return &(this->access()->m_mats[to_unsigned( id.mat() )]); + [[nodiscard]] const std::optional findMat( const FTChannelID& id ) const { + return (to_unsigned( id.mat() ) < this->access()->m_mats.size())? &(this->access()->m_mats[to_unsigned( id.mat() )]): std::optional{}; } + [[nodiscard]] FTChannelID elementID() const { return this->access()->m_elementID; } [[nodiscard]] int pseudoChannel( const FTChannelID channelID ) const {return this->access()->pseudoChannel(channelID);} diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index 6ba7ea70..e96293f9 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -52,10 +52,10 @@ namespace LHCb::Detector { * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTModule& findModule( const FTChannelID aChannel ) const { - auto m = to_unsigned( aChannel.module() ); - return &(this->access()->m_modules[m]); + [[nodiscard]] const std::optional findModule( const FTChannelID& id ) const { + return (to_unsigned( id.module() ) < this->access()->m_modules.size())? &(this->access()->m_modules[to_unsigned( id.mat() )]): std::optional{}; } + /** Flat vector of all FT modules * @return vector of modules */ diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index 91e0a89b..8be83bc7 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -53,8 +53,8 @@ namespace LHCb::Detector { * @param aChannel an FT channel id * @return pointer to detector element */ - [[nodiscard]] const DeFTLayer& findLayer( const FTChannelID& aChannel ) const { - return &(this->access()->m_layers[to_unsigned( aChannel.layer() )]); + [[nodiscard]] const std::optional findLayer( const FTChannelID& id ) const { + return (to_unsigned( id.layer() ) < this->access()->m_layers.size())? &(this->access()->m_layers[to_unsigned( id.layer() )]): std::optional{}; } }; -- GitLab From 896a53232ec78fb36dd3143626582995eb2d7925 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Sun, 24 Oct 2021 13:46:56 +0200 Subject: [PATCH 28/37] Corrected mistakes --- Detector/FT/include/Detector/FT/DeFT.h | 4 ++-- Detector/FT/include/Detector/FT/DeFTModule.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 6cb01ef1..f1f46935 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -144,9 +144,9 @@ namespace LHCb::Detector { /** Find the FT Mat corresponding to the channel id * @return Pointer to the relevant module */ - [[nodiscard]] const DeFTMat findMat( const FTChannelID& aChannel ) const { + [[nodiscard]] const std::optional findMat( const FTChannelID& aChannel ) const { const auto m = findModule( aChannel ); - return m.findMat( aChannel ); + return m ? m->findMat( aChannel ) : std::optional{}; } /// Get a random FTChannelID (useful for the thermal noise, which is ~flat) diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index ba368eee..6946d258 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -74,7 +74,7 @@ namespace LHCb::Detector { return iter != this->access()->m_mats.end() ? iter : std::optional{};//DeFTMat{}; } - [[nodiscard]] const std::optional findMat( const FTChannelID& id ) const { + const std::optional findMat( const FTChannelID& id ) const { return (to_unsigned( id.mat() ) < this->access()->m_mats.size())? &(this->access()->m_mats[to_unsigned( id.mat() )]): std::optional{}; } -- GitLab From 5f729b555e499ce6b65331b01e417c402e1250e3 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Mon, 25 Oct 2021 11:45:33 +0200 Subject: [PATCH 29/37] Added all necessary methods for Boole to compile --- Detector/FT/include/Detector/FT/DeFT.h | 7 +++- Detector/FT/include/Detector/FT/DeFTMat.h | 40 ++++++++++++++++++++ Detector/FT/include/Detector/FT/DeFTModule.h | 4 +- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index f1f46935..398a2792 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -76,7 +76,7 @@ namespace LHCb::Detector { int nStations() const {return 0;}//FIXME int nChannels() const {return 0;}//FIXME - + int sensitiveVolumeID() const {return 0;}//FIXME /** Find the FT Station corresponding to the point * @return Pointer to the relevant station */ @@ -148,6 +148,11 @@ namespace LHCb::Detector { const auto m = findModule( aChannel ); return m ? m->findMat( aChannel ) : std::optional{}; } + + int sensitiveVolumeID( const ROOT::Math::XYZPoint& point ) const { + const auto& mat = findMat( point ); + return mat ? mat->sensitiveVolumeID( point ) : -1; + } /// Get a random FTChannelID (useful for the thermal noise, which is ~flat) FTChannelID getRandomChannelFromSeed( const float seed ) const { diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index e8b07313..c23eacff 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -81,6 +81,7 @@ namespace LHCb::Detector { float airGap() const {return this->access()->m_airGap;} float deadRegion() const {return this->access()->m_deadRegion;} float channelPitch() const {return this->access()->m_channelPitch;} + int sensitiveVolumeID( const ROOT::Math::XYZPoint& ) const { return this->access()->m_elementID; } float sipmPitch() const {return this->access()->m_sipmPitch;}; float halfChannelPitch() const {return this->access()->m_halfChannelPitch;}; float dieGap() const {return this->access()->m_dieGap;} @@ -108,6 +109,9 @@ namespace LHCb::Detector { FTChannelID::MatID matID() const{return FTChannelID::MatID{this->access()->m_matID};} bool isBottom() const { return this->access()->m_elementID.isBottom(); } bool isTop() const { return this->access()->m_elementID.isTop(); } + bool hasGapLeft( const FTChannelID thisChannel ) const { + return ( thisChannel.channel() == 0u || int( thisChannel.channel() ) == this->access()->m_nChannelsInDie ); + } bool hasGapRight( const FTChannelID thisChannel ) const { return ( int( thisChannel.channel() ) == this->access()->m_nChannelsInSiPM - 1 || int( thisChannel.channel() ) == this->access()->m_nChannelsInDie - 1 ); @@ -158,6 +162,33 @@ namespace LHCb::Detector { } return channelsAndLeftEdges; } + + /** Get the list of SiPM channels traversed by the hit. + * The particle trajectory is a straight line defined by: + * @param provide local entry and exit point + * @param provide the number of additional channels to add + * Fills a vector of FTChannelIDs, and a vector of the + * corresponding left edges (along x) in the local frame. + */ + [[nodiscard]] std::vector> + calculateChannels( const float localEntry, const float localExit, const unsigned int numOfAdditionalChannels ) const{ + // set ordering in increasing local x + float xBegin = std::min( localEntry, localExit ); + float xEnd = std::max( localEntry, localExit ); + + // Find the first and last channels that are involved + float xOffset = numOfAdditionalChannels * this->access()->m_channelPitch; + float fracBegin = 0.0, fracEnd = 0.0; + FTChannelID thisChannel = calculateChannelAndFrac( xBegin - xOffset, fracBegin ); + FTChannelID endChannel = calculateChannelAndFrac( xEnd + xOffset, fracEnd ); + + // return empty vector when both channels are the same gap + if ( thisChannel.channelID() == endChannel.channelID() && std::abs( fracBegin ) > 0.5f && + std::abs( fracEnd ) > 0.5f && fracBegin * fracEnd > 0.25f ) + return std::vector>(); + + return this->calculateChannels( thisChannel, endChannel ); + } /** Get the local x from a channelID and its fraction */ [[nodiscard]] float localXfromChannel( const FTChannelID channelID, const int frac ) const { @@ -174,6 +205,15 @@ namespace LHCb::Detector { ROOT::Math::XYZPoint localPoint = toLocal( globalPoint ); return localXfromChannel( channelID, frac ) - localPoint.x(); } + + + /** Get the distance from the hit to the SiPM + * @param localPoint is the position of the half module in local coordinates + * @return the distance to the SiPM + */ + [[nodiscard]] float distanceToSiPM( const ROOT::Math::XYZPoint& localPoint ) const { + return 0.5f * this->access()->m_sizeY - localPoint.y(); + }; }; diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 6946d258..9c0cd84e 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -84,8 +84,8 @@ namespace LHCb::Detector { [[nodiscard]] FTChannelID channelFromPseudo( const int pseudoChannel ) const { const auto& obj = this->access(); - int channelInModule = pseudoChannel & ( obj.m_nChannelsInModule - 1u ); - if ( obj.m_reversed ) { channelInModule = obj.m_nChannelsInModule - 1 - channelInModule; } + int channelInModule = pseudoChannel & ( obj->m_nChannelsInModule - 1u ); + if ( obj->m_reversed ) { channelInModule = obj->m_nChannelsInModule - 1 - channelInModule; } return FTChannelID( this->elementID() + channelInModule ); } ROOT::Math::Plane3D plane() const {return this->access()->m_plane;} -- GitLab From 222c0f4b3381868a8773f1bc4f20d1d1662a0640 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Mon, 25 Oct 2021 14:32:57 +0200 Subject: [PATCH 30/37] Fixed most implementations, bug in firstMat --- Detector/FT/include/Detector/FT/DeFT.h | 26 ++++++++------- Detector/FT/include/Detector/FT/DeFTLayer.h | 34 +++++++++++++------ Detector/FT/include/Detector/FT/DeFTMat.h | 16 ++++++--- Detector/FT/src/DeFT.cpp | 37 ++++++++++++++------- 4 files changed, 75 insertions(+), 38 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 398a2792..ece13bbc 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -31,11 +31,13 @@ namespace LHCb::Detector { int m_nModulesT1{dd4hep::_toInt( "FT:nModulesT1" )}; // Number of modules in T1 int m_nModulesT2{dd4hep::_toInt( "FT:nModulesT2" )}; // Number of modules in T2 int m_nModulesT3{dd4hep::_toInt( "FT:nModulesT3" )}; // Number of modules in T3 + int m_nStations{dd4hep::_toInt( "FT:nStations" )}; // Number of stations int m_nLayers{dd4hep::_toInt( "FT:nLayers" )}; // Number of layers per station int m_nQuarters{dd4hep::_toInt( "FT:nQuarters" )}; // Number of quarters per layer int m_nChannelsInModule{dd4hep::_toInt( "FT:nChannelsInModule" )}; // Number of channels per SiPM - int m_nTotChannels; - int m_nTotQuarters; + int m_nTotQuarters = m_nStations * m_nLayers * m_nQuarters; + int m_nTotModules = m_nModulesT1 + m_nModulesT2 + m_nModulesT3; + int m_nTotChannels = m_nTotModules * m_nChannelsInModule; std::array m_stations; DeFTObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); @@ -52,6 +54,7 @@ namespace LHCb::Detector { for (auto& module : quarter.m_modules) module.applyToAllChildren(func); } + const DeFTMatObject& firstMat() const {return m_stations[0].m_layers[0].m_quarters[0].m_modules[0].m_mats[0];}; }; // End namespace detail } /** @@ -72,42 +75,42 @@ namespace LHCb::Detector { void applyToAllMats( const std::function )>& func ) const { this->access()->applyToAllMats(func); } - DeFTMat firstMat() const {return {};}//FIXNE + const DeFTMat& firstMat() const {return this->access()->firstMat();} - int nStations() const {return 0;}//FIXME - int nChannels() const {return 0;}//FIXME - int sensitiveVolumeID() const {return 0;}//FIXME + int nStations() const {return this->access()->m_nStations;} + int nChannels() const {return this->access()->m_nTotChannels;} + /** Find the FT Station corresponding to the point * @return Pointer to the relevant station */ [[nodiscard]] const std::optional findStation( const ROOT::Math::XYZPoint& aPoint ) const { const auto iS = std::find_if( std::begin( this->access()->m_stations ), std::end( this->access()->m_stations ), [&aPoint]( detail::DeFTStationObject const& s ) { return DeFTStation{&s}.isInside( aPoint ); } ); - return iS != this->access()->m_stations.end() ? std::optional{iS} : std::optional{};//DeFTStation{}; + return iS != this->access()->m_stations.end() ? std::optional{iS} : std::optional{}; } /// Find the layer for a given XYZ point [[nodiscard]] const std::optional findLayer( const ROOT::Math::XYZPoint& aPoint ) const { const auto s = findStation( aPoint ); - return s ? s->findLayer( aPoint ) : std::optional{};//DeFTLayer{}; + return s ? s->findLayer( aPoint ) : std::optional{}; } /// Find the quarter for a given XYZ point [[nodiscard]] const std::optional findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { const auto l = findLayer( aPoint ); - return l ? l->findQuarter( aPoint ) : std::optional{};//false;//DeFTQuarter{}; + return l ? l->findQuarter( aPoint ) : std::optional{}; } /// Find the module for a given XYZ point [[nodiscard]] const std::optional findModule( const ROOT::Math::XYZPoint& aPoint ) const { const auto l = findLayer( aPoint ); // is faster than via DeFTQuarter - return l ? l->findModule( aPoint ) : std::optional{};//DeFTModule{}; + return l ? l->findModule( aPoint ) : std::optional{}; } /// Find the mat for a given XYZ point [[nodiscard]] const std::optional findMat( const ROOT::Math::XYZPoint& aPoint ) const { const auto m = findModule( aPoint ); - return m ? m->findMat( aPoint ) : std::optional{};//DeFTMat{}; + return m ? m->findMat( aPoint ) : std::optional{}; } /** Find the FT Station corresponding to the channel id @@ -180,7 +183,6 @@ namespace LHCb::Detector { /// Get a random FTChannelID from a pseudoChannel (useful for the AP noise) FTChannelID getRandomChannelFromPseudo( const int pseudoChannel, const float seed ) const { - // FIXME: moduleDet->channelFromPseudo returns invalidChannel all the time if ( seed < 0.f || seed > 1.f ) return FTChannelID::kInvalidChannel(); const auto& obj = this->access(); unsigned int flatQuarter = int( seed * obj->m_nTotQuarters ); diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index ba64eb4e..c2d75b5c 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -27,7 +27,14 @@ namespace LHCb::Detector { */ struct DeFTLayerObject : DeIOVObject { /// Reference to the static information of the quarters - unsigned int m_id; + unsigned int m_layerID; ///< layer ID number + float m_globalZ; ///< Global z position of layer closest to y-axis + ROOT::Math::Plane3D m_plane; ///< xy-plane in the z-middle of the layer + float m_dzdy; ///< dz/dy of the layer (tan of the beam angle) + float m_stereoAngle = {dd4hep::_toFloat("FT::stereoAngle")}; ///< stereo angle of the layer + float m_sizeX = {dd4hep::_toFloat( "FT:StationSizeX" )}; ///< Size of the layer in x // FIXME + float m_sizeY = {dd4hep::_toFloat( "FT:StationSizeY" )}; ///< Size of the layer in y // FIXME + float m_dxdy = tan(m_stereoAngle); ///< dx/dy of the layer (ie. tan(m_stereoAngle)) std::array m_quarters; DeFTLayerObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iLayer, unsigned int stationID ); @@ -40,13 +47,21 @@ namespace LHCb::Detector { module.applyToAllChildren(func); } }; + ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const{ + return ROOT::Math::XYZPoint( toLHCbUnits( this->detectorAlignment.worldToLocal(toDD4hepUnits( ROOT::Math::XYZVector( p ) ) ) ) ); + } + ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const{ + return toLHCbUnits(this->detectorAlignment.worldToLocal( toDD4hepUnits( v ) ) ); + } + ROOT::Math::XYZPoint toGlobal( const ROOT::Math::XYZPoint& p ) const {return ROOT::Math::XYZPoint(this->detectorAlignment.localToWorld(ROOT::Math::XYZVector(p)));} + ROOT::Math::XYZVector toGlobal( const ROOT::Math::XYZVector& v ) const {return this->detectorAlignment.localToWorld(v);} }; } // End namespace detail template struct DeFTLayerElement : DeIOVElement { using DeIOVElement::DeIOVElement; - unsigned int layerID() const{return this->access()->m_id;} + unsigned int layerID() const{return this->access()->m_layerID;} /** Find the FT Quarter corresponding to the point * @return Pointer to the relevant quarter @@ -71,14 +86,13 @@ namespace LHCb::Detector { return (to_unsigned( id.quarter() ) < this->access()->m_quarters.size())? &(this->access()->m_quarters[to_unsigned( id.quarter() )]): std::optional{}; } - float globalZ() const {return 0.;}//FIXME - ROOT::Math::Plane3D plane() const {return {};}//FIXME - float dxdy() const {return 0.;}//FIXME - float stereoAngle() const {return 0.;}//FIXME - float dzdy() const {return 0.;}//FIXME - float sizeX() const {return 0.;}//FIXME - float sizeY() const {return 0.;}//FIXME - + float globalZ() const {return this->access()->m_globalZ;}//FIXME + ROOT::Math::Plane3D plane() const {return this->access()->m_plane;}//FIXME + float dxdy() const {return this->access()->m_dxdy;}//FIXME + float stereoAngle() const {return this->access()->m_stereoAngle;}//FIXME + float dzdy() const {return this->access()->m_dzdy;}//FIXME + float sizeX() const {return this->access()->m_sizeX;}//FIXME + float sizeY() const {return this->access()->m_sizeY;}//FIXME }; using DeFTLayer = DeFTLayerElement; diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index c23eacff..48d49625 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -44,9 +44,9 @@ namespace LHCb::Detector { float m_deadRegion = {dd4hep::_toFloat("FT::deadRegion")}; ///< dead region float m_channelPitch = {dd4hep::_toFloat("FT::channelPitch")}; ///< readout channel pitch (250 micron) float m_diePitch; ///< pitch between dies in SiPM - float m_sizeX; ///< Width in x of the mat - float m_sizeY; ///< Length in y of the fibre in the mat - float m_sizeZ; ///< Thickness of the fibre mat (nominal: 1.3 mm) + float m_sizeX = dd4hep::_toFloat( "FT:MatSizeX" ); ///< Width in x of the mat + float m_sizeY = dd4hep::_toFloat( "FT:MatSizeY" ); ///< Length in y of the fibre in the mat + float m_sizeZ = dd4hep::_toFloat( "FT:MatSizeZ" ); ///< Thickness of the fibre mat (nominal: 1.3 mm) // Parameters needed for decoding ROOT::Math::XYZPointF m_mirrorPoint; ///< Location of end of fibres at x=z=0 @@ -122,7 +122,15 @@ namespace LHCb::Detector { ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const {return this->access()->toLocal(v);} ROOT::Math::XYZPoint toGlobal( const ROOT::Math::XYZPoint& p ) const {return this->access()->toGlobal(p);} ROOT::Math::XYZVector toGlobal( const ROOT::Math::XYZVector& v ) const {return this->access()->toGlobal(v);} - LineTraj trajectory(FTChannelID id, float fraction) const {return {};} //FIXME + LineTraj trajectory(FTChannelID channelID, float frac) const { + float localX = localXfromChannel( channelID, frac ); + auto obj = this->access(); + ROOT::Math::XYZPoint mirrorPoint( obj->m_mirrorPoint.x() + localX * obj->m_ddx.x(), obj->m_mirrorPoint.y() + localX * obj->m_ddx.y(), + obj->m_mirrorPoint.z() + localX * obj->m_ddx.z() ); + ROOT::Math::XYZPoint sipmPoint( obj->m_sipmPoint.x() + localX * obj->m_ddx.x(), obj->m_sipmPoint.y() + localX * obj->m_ddx.y(), + obj->m_sipmPoint.z() + localX * obj->m_ddx.z() ); + return {mirrorPoint, sipmPoint}; + } // Others FTChannelID calculateChannelAndFrac( float x, float frac ) const { diff --git a/Detector/FT/src/DeFT.cpp b/Detector/FT/src/DeFT.cpp index 0acf3692..abfecdd4 100644 --- a/Detector/FT/src/DeFT.cpp +++ b/Detector/FT/src/DeFT.cpp @@ -15,6 +15,8 @@ #include "DD4hep/Printout.h" +//FIXME: ROOT vs LHCB lengths + LHCb::Detector::detail::DeFTObject::DeFTObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt ) @@ -34,11 +36,29 @@ LHCb::Detector::detail::DeFTLayerObject::DeFTLayerObject( const dd4hep::DetEleme dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iLayer, unsigned int stationID ) : DeIOVObject( de, ctxt ) - , m_id{( stationID * FT::nLayers + iLayer )} - , m_quarters{{{de.child( "Q0" ), ctxt, 0, m_id}, - {de.child( "Q1" ), ctxt, 1, m_id}, - {de.child( "Q2" ), ctxt, 2, m_id}, - {de.child( "Q3" ), ctxt, 3, m_id}}} {} + , m_layerID{( stationID * FT::nLayers + iLayer )} + , m_quarters{{{de.child( "Q0" ), ctxt, 0, m_layerID}, + {de.child( "Q1" ), ctxt, 1, m_layerID}, + {de.child( "Q2" ), ctxt, 2, m_layerID}, + {de.child( "Q3" ), ctxt, 3, m_layerID}}} { + // Get the global z position of the layer + ROOT::Math::XYZPoint globalPoint = this->toGlobal( ROOT::Math::XYZPoint( 0., 0., 0. ) ); + m_globalZ = globalPoint.z(); + + // Get the boundaries of the layer + // FIXME + // const dd4hep::Box* box = dynamic_cast( geometry()->lvolume()->solid()->coverTop() ); + // m_sizeX = box->xsize(); + // m_sizeY = box->ysize(); + + // Make the plane for the layer + const ROOT::Math::XYZPoint g1 = this->toGlobal( ROOT::Math::XYZPoint( 0., 0., 0. ) ); + const ROOT::Math::XYZPoint g2 = this->toGlobal( ROOT::Math::XYZPoint( 1., 0., 0. ) ); + const ROOT::Math::XYZPoint g3 = this->toGlobal( ROOT::Math::XYZPoint( 0., 1., 0. ) ); + m_plane = ROOT::Math::Plane3D( g1, g2, g3 ); + m_dzdy = ( g3.z() - g1.z() ) / ( g3.y() - g1.y() ); + m_dxdy = -tan( m_stereoAngle ); + } LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, @@ -98,13 +118,6 @@ LHCb::Detector::detail::DeFTMatObject::DeFTMatObject( const dd4hep::DetElement& m_uBegin = m_airGap + m_deadRegion - 2.f * m_sipmPitch; //Update cache - //FIXME - // Get the boundaries of the layer - // const SolidBox* box = dynamic_cast( geometry()->lvolume()->solid()->coverTop() ); - // m_sizeX = box->xsize(); - // m_sizeY = box->ysize(); - // m_sizeZ = box->zsize(); - // Get the central points of the fibres at the mirror and at the SiPM locations m_mirrorPoint = this->toGlobal( ROOT::Math::XYZPoint( 0, -0.5f * m_sizeY, 0 ) ); m_sipmPoint = this->toGlobal( ROOT::Math::XYZPoint( 0, +0.5f * m_sizeY, 0 ) ); -- GitLab From ed50a0defb3de879587268133c323a0f21bb1324 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Mon, 25 Oct 2021 14:42:45 +0200 Subject: [PATCH 31/37] Solved all compilation and implementation problems. Probably will try to access properties that do not exist in DD4HEP yet though --- Detector/FT/include/Detector/FT/DeFT.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index ece13bbc..32ea5602 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -75,7 +75,7 @@ namespace LHCb::Detector { void applyToAllMats( const std::function )>& func ) const { this->access()->applyToAllMats(func); } - const DeFTMat& firstMat() const {return this->access()->firstMat();} + const DeFTMat& firstMat() const {return &(this->access()->firstMat());} int nStations() const {return this->access()->m_nStations;} int nChannels() const {return this->access()->m_nTotChannels;} -- GitLab From 95154540627c17228f64a1732b60af0005580e51 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Mon, 25 Oct 2021 15:20:22 +0200 Subject: [PATCH 32/37] Changed the stereo angle definition --- Detector/FT/include/Detector/FT/DeFTLayer.h | 2 +- Detector/FT/src/DeFT.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index c2d75b5c..cedbdaca 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -31,7 +31,7 @@ namespace LHCb::Detector { float m_globalZ; ///< Global z position of layer closest to y-axis ROOT::Math::Plane3D m_plane; ///< xy-plane in the z-middle of the layer float m_dzdy; ///< dz/dy of the layer (tan of the beam angle) - float m_stereoAngle = {dd4hep::_toFloat("FT::stereoAngle")}; ///< stereo angle of the layer + float m_stereoAngle;// = {dd4hep::_toFloat("FT::stereoAngle")}; ///< stereo angle of the layer // FIXME float m_sizeX = {dd4hep::_toFloat( "FT:StationSizeX" )}; ///< Size of the layer in x // FIXME float m_sizeY = {dd4hep::_toFloat( "FT:StationSizeY" )}; ///< Size of the layer in y // FIXME float m_dxdy = tan(m_stereoAngle); ///< dx/dy of the layer (ie. tan(m_stereoAngle)) diff --git a/Detector/FT/src/DeFT.cpp b/Detector/FT/src/DeFT.cpp index abfecdd4..0c9fcbb7 100644 --- a/Detector/FT/src/DeFT.cpp +++ b/Detector/FT/src/DeFT.cpp @@ -57,7 +57,9 @@ LHCb::Detector::detail::DeFTLayerObject::DeFTLayerObject( const dd4hep::DetEleme const ROOT::Math::XYZPoint g3 = this->toGlobal( ROOT::Math::XYZPoint( 0., 1., 0. ) ); m_plane = ROOT::Math::Plane3D( g1, g2, g3 ); m_dzdy = ( g3.z() - g1.z() ) / ( g3.y() - g1.y() ); - m_dxdy = -tan( m_stereoAngle ); + // m_dxdy = -tan( m_stereoAngle ); + m_dxdy = (g3.x() - g1.x())/(g3.y()-g1.y());//FIXME: to check + m_stereoAngle = -atan( m_dxdy); } LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetElement& de, @@ -83,7 +85,7 @@ LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetEle {de.child( "Mat3" ), ctxt, 3, m_id}}} { // Is reversed? const auto firstPoint = this->toGlobal( {-1, 0, 0} ); - const auto lastPoint = this->toGlobal( {1, 0, 0} ); + const auto lastPoint = this->toGlobal( { 1, 0, 0} ); m_reversed = std::abs( firstPoint.x() ) > std::abs( lastPoint.x() ); // Make the plane for the module const ROOT::Math::XYZPoint g1 = this->toGlobal( ROOT::Math::XYZPoint( 0., 0., 0. ) ); -- GitLab From d780b804aa14827a256a385bb521e8f3a156f9db Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Mon, 25 Oct 2021 13:21:08 +0000 Subject: [PATCH 33/37] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Detector/-/jobs/17128906 --- Detector/FT/include/Detector/FT/DeFT.h | 70 +++--- Detector/FT/include/Detector/FT/DeFTLayer.h | 77 ++++--- Detector/FT/include/Detector/FT/DeFTMat.h | 209 +++++++++--------- Detector/FT/include/Detector/FT/DeFTModule.h | 52 +++-- Detector/FT/include/Detector/FT/DeFTQuarter.h | 15 +- Detector/FT/include/Detector/FT/DeFTStation.h | 13 +- Detector/FT/include/Detector/FT/FTChannelID.h | 4 +- Detector/FT/src/DeFT.cpp | 128 ++++++----- 8 files changed, 297 insertions(+), 271 deletions(-) diff --git a/Detector/FT/include/Detector/FT/DeFT.h b/Detector/FT/include/Detector/FT/DeFT.h index 32ea5602..a58199df 100644 --- a/Detector/FT/include/Detector/FT/DeFT.h +++ b/Detector/FT/include/Detector/FT/DeFT.h @@ -37,7 +37,7 @@ namespace LHCb::Detector { int m_nChannelsInModule{dd4hep::_toInt( "FT:nChannelsInModule" )}; // Number of channels per SiPM int m_nTotQuarters = m_nStations * m_nLayers * m_nQuarters; int m_nTotModules = m_nModulesT1 + m_nModulesT2 + m_nModulesT3; - int m_nTotChannels = m_nTotModules * m_nChannelsInModule; + int m_nTotChannels = m_nTotModules * m_nChannelsInModule; std::array m_stations; DeFTObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ); @@ -45,18 +45,17 @@ namespace LHCb::Detector { for ( auto& station : m_stations ) { func( LHCb::Detector::DeIOV{&station} ); }; }; void applyToAllLayers( const std::function& func ) const { - for ( auto& station : m_stations ) { station.applyToAllChildren(func); }; + for ( auto& station : m_stations ) { station.applyToAllChildren( func ); }; }; void applyToAllMats( const std::function )>& func ) const { - for (auto& station : m_stations) - for (auto& layer : station.m_layers) - for (auto& quarter : layer.m_quarters) - for (auto& module : quarter.m_modules) - module.applyToAllChildren(func); + for ( auto& station : m_stations ) + for ( auto& layer : station.m_layers ) + for ( auto& quarter : layer.m_quarters ) + for ( auto& module : quarter.m_modules ) module.applyToAllChildren( func ); } - const DeFTMatObject& firstMat() const {return m_stations[0].m_layers[0].m_quarters[0].m_modules[0].m_mats[0];}; + const DeFTMatObject& firstMat() const { return m_stations[0].m_layers[0].m_quarters[0].m_modules[0].m_mats[0]; }; }; // End namespace detail - } + } // namespace detail /** * FT interface * @@ -67,65 +66,71 @@ namespace LHCb::Detector { template struct DeFTElement : DeIOVElement { using DeIOVElement::DeIOVElement; - int version() const { return this->access()->m_version; }; - const std::array stations() const {const auto obj = this->access(); return {obj->m_stations[0],obj->m_stations[1],obj->m_stations[2]};}; + int version() const { return this->access()->m_version; }; + const std::array stations() const { + const auto obj = this->access(); + return {obj->m_stations[0], obj->m_stations[1], obj->m_stations[2]}; + }; void applyToAllLayers( const std::function )>& func ) const { - this->access()->applyToAllLayers(func); + this->access()->applyToAllLayers( func ); }; void applyToAllMats( const std::function )>& func ) const { - this->access()->applyToAllMats(func); + this->access()->applyToAllMats( func ); } - const DeFTMat& firstMat() const {return &(this->access()->firstMat());} - - int nStations() const {return this->access()->m_nStations;} - int nChannels() const {return this->access()->m_nTotChannels;} + const DeFTMat& firstMat() const { return &( this->access()->firstMat() ); } + + int nStations() const { return this->access()->m_nStations; } + int nChannels() const { return this->access()->m_nTotChannels; } /** Find the FT Station corresponding to the point * @return Pointer to the relevant station */ [[nodiscard]] const std::optional findStation( const ROOT::Math::XYZPoint& aPoint ) const { - const auto iS = std::find_if( std::begin( this->access()->m_stations ), std::end( this->access()->m_stations ), - [&aPoint]( detail::DeFTStationObject const& s ) { return DeFTStation{&s}.isInside( aPoint ); } ); + const auto iS = std::find_if( + std::begin( this->access()->m_stations ), std::end( this->access()->m_stations ), + [&aPoint]( detail::DeFTStationObject const& s ) { return DeFTStation{&s}.isInside( aPoint ); } ); return iS != this->access()->m_stations.end() ? std::optional{iS} : std::optional{}; } - + /// Find the layer for a given XYZ point [[nodiscard]] const std::optional findLayer( const ROOT::Math::XYZPoint& aPoint ) const { const auto s = findStation( aPoint ); return s ? s->findLayer( aPoint ) : std::optional{}; } - + /// Find the quarter for a given XYZ point [[nodiscard]] const std::optional findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { const auto l = findLayer( aPoint ); return l ? l->findQuarter( aPoint ) : std::optional{}; } - + /// Find the module for a given XYZ point [[nodiscard]] const std::optional findModule( const ROOT::Math::XYZPoint& aPoint ) const { const auto l = findLayer( aPoint ); // is faster than via DeFTQuarter return l ? l->findModule( aPoint ) : std::optional{}; } - + /// Find the mat for a given XYZ point [[nodiscard]] const std::optional findMat( const ROOT::Math::XYZPoint& aPoint ) const { const auto m = findModule( aPoint ); return m ? m->findMat( aPoint ) : std::optional{}; } - + /** Find the FT Station corresponding to the channel id * @return Pointer to the relevant station */ [[nodiscard]] const std::optional findStation( const FTChannelID& aChannel ) const { - return (to_unsigned( aChannel.station() ) < this->access()->m_stations.size())? &(this->access()->m_stations[to_unsigned( aChannel.station() )]): std::optional{}; + return ( to_unsigned( aChannel.station() ) < this->access()->m_stations.size() ) + ? &( this->access()->m_stations[to_unsigned( aChannel.station() )] ) + : std::optional{}; } - + /** Find the FT Layer corresponding to the channel id * @return Pointer to the relevant layer */ [[nodiscard]] const std::optional findLayer( const FTChannelID& aChannel ) const { const auto s = findStation( aChannel ); - return s? s->findLayer( aChannel ) : std::optional{}; + return s ? s->findLayer( aChannel ) : std::optional{}; } /** Find the FT Quarter corresponding to the channel id @@ -133,7 +138,7 @@ namespace LHCb::Detector { */ [[nodiscard]] const std::optional findQuarter( const FTChannelID& aChannel ) const { const auto l = findLayer( aChannel ); - return l? l->findQuarter( aChannel ) : std::optional{}; + return l ? l->findQuarter( aChannel ) : std::optional{}; } /** Find the FT Module corresponding to the channel id @@ -141,7 +146,7 @@ namespace LHCb::Detector { */ [[nodiscard]] const std::optional findModule( const FTChannelID& aChannel ) const { const auto q = findQuarter( aChannel ); - return q? q->findModule( aChannel ) : std::optional{}; + return q ? q->findModule( aChannel ) : std::optional{}; } /** Find the FT Mat corresponding to the channel id @@ -151,7 +156,7 @@ namespace LHCb::Detector { const auto m = findModule( aChannel ); return m ? m->findMat( aChannel ) : std::optional{}; } - + int sensitiveVolumeID( const ROOT::Math::XYZPoint& point ) const { const auto& mat = findMat( point ); return mat ? mat->sensitiveVolumeID( point ) : -1; @@ -192,13 +197,12 @@ namespace LHCb::Detector { flatQuarter /= obj->m_nLayers; auto station = FTChannelID::StationID{( flatQuarter & obj->m_stations.size() ) + 1u}; - auto module = FTChannelID::ModuleID{pseudoChannel / obj->m_nChannelsInModule}; + auto module = FTChannelID::ModuleID{pseudoChannel / obj->m_nChannelsInModule}; const auto& moduleDet = findModule( FTChannelID( station, layer, quarter, module, 0u ) ); - return moduleDet->channelFromPseudo( pseudoChannel & ( obj->m_nChannelsInModule - 1u ) ); + return moduleDet->channelFromPseudo( pseudoChannel & ( obj->m_nChannelsInModule - 1u ) ); } }; using DeFT = DeFTElement; } // End namespace LHCb::Detector - diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index cedbdaca..789fc577 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -27,14 +27,14 @@ namespace LHCb::Detector { */ struct DeFTLayerObject : DeIOVObject { /// Reference to the static information of the quarters - unsigned int m_layerID; ///< layer ID number - float m_globalZ; ///< Global z position of layer closest to y-axis - ROOT::Math::Plane3D m_plane; ///< xy-plane in the z-middle of the layer - float m_dzdy; ///< dz/dy of the layer (tan of the beam angle) - float m_stereoAngle;// = {dd4hep::_toFloat("FT::stereoAngle")}; ///< stereo angle of the layer // FIXME - float m_sizeX = {dd4hep::_toFloat( "FT:StationSizeX" )}; ///< Size of the layer in x // FIXME - float m_sizeY = {dd4hep::_toFloat( "FT:StationSizeY" )}; ///< Size of the layer in y // FIXME - float m_dxdy = tan(m_stereoAngle); ///< dx/dy of the layer (ie. tan(m_stereoAngle)) + unsigned int m_layerID; ///< layer ID number + float m_globalZ; ///< Global z position of layer closest to y-axis + ROOT::Math::Plane3D m_plane; ///< xy-plane in the z-middle of the layer + float m_dzdy; ///< dz/dy of the layer (tan of the beam angle) + float m_stereoAngle; // = {dd4hep::_toFloat("FT::stereoAngle")}; ///< stereo angle of the layer // FIXME + float m_sizeX = {dd4hep::_toFloat( "FT:StationSizeX" )}; ///< Size of the layer in x // FIXME + float m_sizeY = {dd4hep::_toFloat( "FT:StationSizeY" )}; ///< Size of the layer in y // FIXME + float m_dxdy = tan( m_stereoAngle ); ///< dx/dy of the layer (ie. tan(m_stereoAngle)) std::array m_quarters; DeFTLayerObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iLayer, unsigned int stationID ); @@ -42,57 +42,64 @@ namespace LHCb::Detector { for ( auto& quarter : m_quarters ) { func( LHCb::Detector::DeIOV{&quarter} ); }; }; void applyToAllMats( const std::function& func ) const { - for ( auto& quarter : m_quarters ) { - for (auto& module : quarter.m_modules) - module.applyToAllChildren(func); - } + for ( auto& quarter : m_quarters ) { + for ( auto& module : quarter.m_modules ) module.applyToAllChildren( func ); + } }; - ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const{ - return ROOT::Math::XYZPoint( toLHCbUnits( this->detectorAlignment.worldToLocal(toDD4hepUnits( ROOT::Math::XYZVector( p ) ) ) ) ); + ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const { + return ROOT::Math::XYZPoint( + toLHCbUnits( this->detectorAlignment.worldToLocal( toDD4hepUnits( ROOT::Math::XYZVector( p ) ) ) ) ); } - ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const{ - return toLHCbUnits(this->detectorAlignment.worldToLocal( toDD4hepUnits( v ) ) ); + ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const { + return toLHCbUnits( this->detectorAlignment.worldToLocal( toDD4hepUnits( v ) ) ); + } + ROOT::Math::XYZPoint toGlobal( const ROOT::Math::XYZPoint& p ) const { + return ROOT::Math::XYZPoint( this->detectorAlignment.localToWorld( ROOT::Math::XYZVector( p ) ) ); + } + ROOT::Math::XYZVector toGlobal( const ROOT::Math::XYZVector& v ) const { + return this->detectorAlignment.localToWorld( v ); } - ROOT::Math::XYZPoint toGlobal( const ROOT::Math::XYZPoint& p ) const {return ROOT::Math::XYZPoint(this->detectorAlignment.localToWorld(ROOT::Math::XYZVector(p)));} - ROOT::Math::XYZVector toGlobal( const ROOT::Math::XYZVector& v ) const {return this->detectorAlignment.localToWorld(v);} }; } // End namespace detail template struct DeFTLayerElement : DeIOVElement { using DeIOVElement::DeIOVElement; - unsigned int layerID() const{return this->access()->m_layerID;} + unsigned int layerID() const { return this->access()->m_layerID; } /** Find the FT Quarter corresponding to the point * @return Pointer to the relevant quarter */ [[nodiscard]] const std::optional findQuarter( const ROOT::Math::XYZPoint& aPoint ) const { - const auto iQ = std::find_if( this->access()->m_quarters.begin(), this->access()->m_quarters.end(), - [&aPoint]( const detail::DeFTQuarterObject& q ) { return DeFTQuarter{&q}.isInside( aPoint ); } ); - return iQ != this->access()->m_quarters.end() ? iQ : std::optional{};//DeFTQuarter{}; + const auto iQ = std::find_if( + this->access()->m_quarters.begin(), this->access()->m_quarters.end(), + [&aPoint]( const detail::DeFTQuarterObject& q ) { return DeFTQuarter{&q}.isInside( aPoint ); } ); + return iQ != this->access()->m_quarters.end() ? iQ : std::optional{}; // DeFTQuarter{}; } /// Find the module for a given XYZ point [[nodiscard]] const std::optional findModule( const ROOT::Math::XYZPoint& aPoint ) const { - const auto iQ = findQuarter(aPoint); - return iQ ? iQ->findModule(aPoint) : std::optional{};//DeFTModule{}; - }\ - + const auto iQ = findQuarter( aPoint ); + return iQ ? iQ->findModule( aPoint ) : std::optional{}; // DeFTModule{}; + } + /** Const method to return the layer for a given channel id * @param aChannel an FT channel id * @return pointer to detector element */ [[nodiscard]] const std::optional findQuarter( const FTChannelID& id ) const { - return (to_unsigned( id.quarter() ) < this->access()->m_quarters.size())? &(this->access()->m_quarters[to_unsigned( id.quarter() )]): std::optional{}; + return ( to_unsigned( id.quarter() ) < this->access()->m_quarters.size() ) + ? &( this->access()->m_quarters[to_unsigned( id.quarter() )] ) + : std::optional{}; } - - float globalZ() const {return this->access()->m_globalZ;}//FIXME - ROOT::Math::Plane3D plane() const {return this->access()->m_plane;}//FIXME - float dxdy() const {return this->access()->m_dxdy;}//FIXME - float stereoAngle() const {return this->access()->m_stereoAngle;}//FIXME - float dzdy() const {return this->access()->m_dzdy;}//FIXME - float sizeX() const {return this->access()->m_sizeX;}//FIXME - float sizeY() const {return this->access()->m_sizeY;}//FIXME + + float globalZ() const { return this->access()->m_globalZ; } // FIXME + ROOT::Math::Plane3D plane() const { return this->access()->m_plane; } // FIXME + float dxdy() const { return this->access()->m_dxdy; } // FIXME + float stereoAngle() const { return this->access()->m_stereoAngle; } // FIXME + float dzdy() const { return this->access()->m_dzdy; } // FIXME + float sizeX() const { return this->access()->m_sizeX; } // FIXME + float sizeY() const { return this->access()->m_sizeY; } // FIXME }; using DeFTLayer = DeFTLayerElement; diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index 48d49625..2ffcc9e4 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -29,106 +29,115 @@ namespace LHCb::Detector { */ struct DeFTMatObject : DeIOVObject { - FTChannelID m_elementID; ///< element ID - unsigned int m_matID;//FIXME: needed? + FTChannelID m_elementID; ///< element ID + unsigned int m_matID; // FIXME: needed? // dd4hep::_toDouble - int m_nChannelsInSiPM = {dd4hep::_toInt("FT::nChannelsInSiPM")}; ///< number of channels per SiPM // FIXME: it is constant - int m_nChannelsInDie; ///< number of channels per die + int m_nChannelsInSiPM = {dd4hep::_toInt( "FT::nChannelsInSiPM" )}; ///< number of channels per SiPM // FIXME: it + ///< is constant + int m_nChannelsInDie; ///< number of channels per die int m_nSiPMsInMat = FT::nSiPM; ///< number of SiPM arrays per mat // FIXME: it is constant - int m_nDiesInSiPM = FT::nChannels; ///< number of dies per SiPM - - ROOT::Math::Plane3D m_plane; ///< xy-plane in the z-middle of the module - ROOT::Math::XYZPointF m_sipmPoint; ///< Location of end of fibres at x=z=0 - float m_globalZ; ///< Global z position of module closest to y-axis - float m_airGap = {dd4hep::_toFloat("FT::airGap")}; ///< air gap - float m_deadRegion = {dd4hep::_toFloat("FT::deadRegion")}; ///< dead region - float m_channelPitch = {dd4hep::_toFloat("FT::channelPitch")}; ///< readout channel pitch (250 micron) - float m_diePitch; ///< pitch between dies in SiPM - float m_sizeX = dd4hep::_toFloat( "FT:MatSizeX" ); ///< Width in x of the mat - float m_sizeY = dd4hep::_toFloat( "FT:MatSizeY" ); ///< Length in y of the fibre in the mat - float m_sizeZ = dd4hep::_toFloat( "FT:MatSizeZ" ); ///< Thickness of the fibre mat (nominal: 1.3 mm) - + int m_nDiesInSiPM = FT::nChannels; ///< number of dies per SiPM + + ROOT::Math::Plane3D m_plane; ///< xy-plane in the z-middle of the module + ROOT::Math::XYZPointF m_sipmPoint; ///< Location of end of fibres at x=z=0 + float m_globalZ; ///< Global z position of module closest to y-axis + float m_airGap = {dd4hep::_toFloat( "FT::airGap" )}; ///< air gap + float m_deadRegion = {dd4hep::_toFloat( "FT::deadRegion" )}; ///< dead region + float m_channelPitch = {dd4hep::_toFloat( "FT::channelPitch" )}; ///< readout channel pitch (250 micron) + float m_diePitch; ///< pitch between dies in SiPM + float m_sizeX = dd4hep::_toFloat( "FT:MatSizeX" ); ///< Width in x of the mat + float m_sizeY = dd4hep::_toFloat( "FT:MatSizeY" ); ///< Length in y of the fibre in the mat + float m_sizeZ = dd4hep::_toFloat( "FT:MatSizeZ" ); ///< Thickness of the fibre mat (nominal: 1.3 mm) + // Parameters needed for decoding ROOT::Math::XYZPointF m_mirrorPoint; ///< Location of end of fibres at x=z=0 ROOT::Math::XYZVectorF m_ddx; ///< Global direction vector for a local displacement in unit x - float m_uBegin; ///< start in local u-coordinate of sensitive SiPM - float m_halfChannelPitch; ///< half of the readout channel pitch (125 micron) - float m_dieGap = {dd4hep::_toFloat("FT::dieGap")}; ///< gap between channel 63 and 64 - float m_sipmPitch; ///< pitch between SiPMs in mat - float m_dxdy; ///< Global slope dx/dy for a fibre mat - float m_dzdy; ///< Global slope dz/dy for a fibre mat - float m_globaldy; ///< Length of a fibre projected along global y - - DeFTMatObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iMat, unsigned int iModule); - ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const{ - return ROOT::Math::XYZPoint( toLHCbUnits( this->detectorAlignment.worldToLocal(toDD4hepUnits( ROOT::Math::XYZVector( p ) ) ) ) ); + float m_uBegin; ///< start in local u-coordinate of sensitive SiPM + float m_halfChannelPitch; ///< half of the readout channel pitch (125 micron) + float m_dieGap = {dd4hep::_toFloat( "FT::dieGap" )}; ///< gap between channel 63 and 64 + float m_sipmPitch; ///< pitch between SiPMs in mat + float m_dxdy; ///< Global slope dx/dy for a fibre mat + float m_dzdy; ///< Global slope dz/dy for a fibre mat + float m_globaldy; ///< Length of a fibre projected along global y + + DeFTMatObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iMat, + unsigned int iModule ); + ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const { + return ROOT::Math::XYZPoint( + toLHCbUnits( this->detectorAlignment.worldToLocal( toDD4hepUnits( ROOT::Math::XYZVector( p ) ) ) ) ); } - ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const{ - return toLHCbUnits(this->detectorAlignment.worldToLocal( toDD4hepUnits( v ) ) ); + ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const { + return toLHCbUnits( this->detectorAlignment.worldToLocal( toDD4hepUnits( v ) ) ); } - ROOT::Math::XYZPoint toGlobal( const ROOT::Math::XYZPoint& p ) const {return ROOT::Math::XYZPoint(this->detectorAlignment.localToWorld(ROOT::Math::XYZVector(p)));} - ROOT::Math::XYZVector toGlobal( const ROOT::Math::XYZVector& v ) const {return this->detectorAlignment.localToWorld(v);} - + ROOT::Math::XYZPoint toGlobal( const ROOT::Math::XYZPoint& p ) const { + return ROOT::Math::XYZPoint( this->detectorAlignment.localToWorld( ROOT::Math::XYZVector( p ) ) ); + } + ROOT::Math::XYZVector toGlobal( const ROOT::Math::XYZVector& v ) const { + return this->detectorAlignment.localToWorld( v ); + } + using DeIOVObject::DeIOVObject; }; } // End namespace detail template - struct DeFTMatElement : DeIOVElement { + struct DeFTMatElement : DeIOVElement { using DeIOVElement::DeIOVElement; - //Getters - FTChannelID elementID() const { return this->access()->m_elementID; } - float airGap() const {return this->access()->m_airGap;} - float deadRegion() const {return this->access()->m_deadRegion;} - float channelPitch() const {return this->access()->m_channelPitch;} - int sensitiveVolumeID( const ROOT::Math::XYZPoint& ) const { return this->access()->m_elementID; } - float sipmPitch() const {return this->access()->m_sipmPitch;}; - float halfChannelPitch() const {return this->access()->m_halfChannelPitch;}; - float dieGap() const {return this->access()->m_dieGap;} - ROOT::Math::XYZPointF mirrorPoint() const {return this->access()->m_mirrorPoint;} - ROOT::Math::XYZVectorF ddx() const {return this->access()->m_ddx;} - float dxdy() const {return this->access()->m_dxdy;} - float dzdy() const {return this->access()->m_dzdy;} - float globaldy() const {return this->access()->m_globaldy;} - float globalZ() const {return this->access()->m_globalZ;} - float uBegin() const {return this->access()->m_uBegin;} + // Getters + FTChannelID elementID() const { return this->access()->m_elementID; } + float airGap() const { return this->access()->m_airGap; } + float deadRegion() const { return this->access()->m_deadRegion; } + float channelPitch() const { return this->access()->m_channelPitch; } + int sensitiveVolumeID( const ROOT::Math::XYZPoint& ) const { return this->access()->m_elementID; } + float sipmPitch() const { return this->access()->m_sipmPitch; }; + float halfChannelPitch() const { return this->access()->m_halfChannelPitch; }; + float dieGap() const { return this->access()->m_dieGap; } + ROOT::Math::XYZPointF mirrorPoint() const { return this->access()->m_mirrorPoint; } + ROOT::Math::XYZVectorF ddx() const { return this->access()->m_ddx; } + float dxdy() const { return this->access()->m_dxdy; } + float dzdy() const { return this->access()->m_dzdy; } + float globaldy() const { return this->access()->m_globaldy; } + float globalZ() const { return this->access()->m_globalZ; } + float uBegin() const { return this->access()->m_uBegin; } /** Returns the width of the fibre mat */ [[nodiscard]] float fibreMatWidth() const { return this->access()->m_sizeX; } - + /** Get the length of the fibre in this mat */ [[nodiscard]] float fibreLength() const { return this->access()->m_sizeY; } - + /** Returns the thickness of the fibre mat (1.3 mm) */ [[nodiscard]] float fibreMatThickness() const { return this->access()->m_sizeZ; } - + // Element ID operations - FTChannelID::StationID stationID() const {return this->elementID().station();} - FTChannelID::LayerID layerID() const {return this->elementID().layer ();} - FTChannelID::QuarterID quarterID() const {return this->elementID().quarter();} - FTChannelID::ModuleID moduleID() const {return this->elementID().module ();} - FTChannelID::MatID matID() const{return FTChannelID::MatID{this->access()->m_matID};} - bool isBottom() const { return this->access()->m_elementID.isBottom(); } - bool isTop() const { return this->access()->m_elementID.isTop(); } - bool hasGapLeft( const FTChannelID thisChannel ) const { + FTChannelID::StationID stationID() const { return this->elementID().station(); } + FTChannelID::LayerID layerID() const { return this->elementID().layer(); } + FTChannelID::QuarterID quarterID() const { return this->elementID().quarter(); } + FTChannelID::ModuleID moduleID() const { return this->elementID().module(); } + FTChannelID::MatID matID() const { return FTChannelID::MatID{this->access()->m_matID}; } + bool isBottom() const { return this->access()->m_elementID.isBottom(); } + bool isTop() const { return this->access()->m_elementID.isTop(); } + bool hasGapLeft( const FTChannelID thisChannel ) const { return ( thisChannel.channel() == 0u || int( thisChannel.channel() ) == this->access()->m_nChannelsInDie ); } bool hasGapRight( const FTChannelID thisChannel ) const { return ( int( thisChannel.channel() ) == this->access()->m_nChannelsInSiPM - 1 || - int( thisChannel.channel() ) == this->access()->m_nChannelsInDie - 1 ); + int( thisChannel.channel() ) == this->access()->m_nChannelsInDie - 1 ); } // Geometrical operations - ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const {return this->access()->toLocal(p);} - ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const {return this->access()->toLocal(v);} - ROOT::Math::XYZPoint toGlobal( const ROOT::Math::XYZPoint& p ) const {return this->access()->toGlobal(p);} - ROOT::Math::XYZVector toGlobal( const ROOT::Math::XYZVector& v ) const {return this->access()->toGlobal(v);} - LineTraj trajectory(FTChannelID channelID, float frac) const { - float localX = localXfromChannel( channelID, frac ); - auto obj = this->access(); - ROOT::Math::XYZPoint mirrorPoint( obj->m_mirrorPoint.x() + localX * obj->m_ddx.x(), obj->m_mirrorPoint.y() + localX * obj->m_ddx.y(), - obj->m_mirrorPoint.z() + localX * obj->m_ddx.z() ); - ROOT::Math::XYZPoint sipmPoint( obj->m_sipmPoint.x() + localX * obj->m_ddx.x(), obj->m_sipmPoint.y() + localX * obj->m_ddx.y(), - obj->m_sipmPoint.z() + localX * obj->m_ddx.z() ); + ROOT::Math::XYZPoint toLocal( const ROOT::Math::XYZPoint& p ) const { return this->access()->toLocal( p ); } + ROOT::Math::XYZVector toLocal( const ROOT::Math::XYZVector& v ) const { return this->access()->toLocal( v ); } + ROOT::Math::XYZPoint toGlobal( const ROOT::Math::XYZPoint& p ) const { return this->access()->toGlobal( p ); } + ROOT::Math::XYZVector toGlobal( const ROOT::Math::XYZVector& v ) const { return this->access()->toGlobal( v ); } + LineTraj trajectory( FTChannelID channelID, float frac ) const { + float localX = localXfromChannel( channelID, frac ); + auto obj = this->access(); + ROOT::Math::XYZPoint mirrorPoint( obj->m_mirrorPoint.x() + localX * obj->m_ddx.x(), + obj->m_mirrorPoint.y() + localX * obj->m_ddx.y(), + obj->m_mirrorPoint.z() + localX * obj->m_ddx.z() ); + ROOT::Math::XYZPoint sipmPoint( obj->m_sipmPoint.x() + localX * obj->m_ddx.x(), + obj->m_sipmPoint.y() + localX * obj->m_ddx.y(), + obj->m_sipmPoint.z() + localX * obj->m_ddx.z() ); return {mirrorPoint, sipmPoint}; } @@ -137,36 +146,37 @@ namespace LHCb::Detector { const auto& obj = this->access(); // Correct for the starting point of the sensitive area float xInMat = x - obj->m_uBegin; - + // Find the sipm that is hit and the local position within the sipm int hitSiPM = std::clamp( int( xInMat / obj->m_sipmPitch ), 0, obj->m_nSiPMsInMat - 1 ); float xInSiPM = fma( -obj->m_sipmPitch, hitSiPM, xInMat ); - + // Find the die that is hit and the local position within the die int hitDie = std::clamp( int( xInSiPM / obj->m_diePitch ), 0, obj->m_nDiesInSiPM - 1 ); float chanInDie = fma( -obj->m_diePitch, hitDie, xInSiPM ) / obj->m_channelPitch; - + // Find the channel that is hit and the local position within the channel int hitChan = std::clamp( int( chanInDie ), 0, obj->m_nChannelsInDie - 1 ); frac = chanInDie - hitChan - 0.5f; // Construct channelID return FTChannelID( stationID(), layerID(), quarterID(), moduleID(), matID(), hitSiPM, - hitChan + ( hitDie * obj->m_nChannelsInDie ) ); + hitChan + ( hitDie * obj->m_nChannelsInDie ) ); } - [[nodiscard]] std::vector> calculateChannels( FTChannelID thisChannel, FTChannelID endChannel ) const{ + [[nodiscard]] std::vector> calculateChannels( FTChannelID thisChannel, + FTChannelID endChannel ) const { const auto& obj = this->access(); // Reserve memory std::vector> channelsAndLeftEdges; channelsAndLeftEdges.reserve( endChannel - thisChannel ); - + // Loop over the intermediate channels bool keepAdding = true; while ( keepAdding ) { - float channelLeftEdge = localXfromChannel( thisChannel, -0.5f ); - // Add channel and left edge to output vector. - channelsAndLeftEdges.emplace_back( thisChannel, channelLeftEdge ); - if ( thisChannel == endChannel ) keepAdding = false; - thisChannel.advance(); + float channelLeftEdge = localXfromChannel( thisChannel, -0.5f ); + // Add channel and left edge to output vector. + channelsAndLeftEdges.emplace_back( thisChannel, channelLeftEdge ); + if ( thisChannel == endChannel ) keepAdding = false; + thisChannel.advance(); } return channelsAndLeftEdges; } @@ -179,29 +189,30 @@ namespace LHCb::Detector { * corresponding left edges (along x) in the local frame. */ [[nodiscard]] std::vector> - calculateChannels( const float localEntry, const float localExit, const unsigned int numOfAdditionalChannels ) const{ + calculateChannels( const float localEntry, const float localExit, + const unsigned int numOfAdditionalChannels ) const { // set ordering in increasing local x float xBegin = std::min( localEntry, localExit ); float xEnd = std::max( localEntry, localExit ); - + // Find the first and last channels that are involved - float xOffset = numOfAdditionalChannels * this->access()->m_channelPitch; - float fracBegin = 0.0, fracEnd = 0.0; + float xOffset = numOfAdditionalChannels * this->access()->m_channelPitch; + float fracBegin = 0.0, fracEnd = 0.0; FTChannelID thisChannel = calculateChannelAndFrac( xBegin - xOffset, fracBegin ); FTChannelID endChannel = calculateChannelAndFrac( xEnd + xOffset, fracEnd ); - + // return empty vector when both channels are the same gap if ( thisChannel.channelID() == endChannel.channelID() && std::abs( fracBegin ) > 0.5f && - std::abs( fracEnd ) > 0.5f && fracBegin * fracEnd > 0.25f ) - return std::vector>(); - + std::abs( fracEnd ) > 0.5f && fracBegin * fracEnd > 0.25f ) + return std::vector>(); + return this->calculateChannels( thisChannel, endChannel ); } - + /** Get the local x from a channelID and its fraction */ [[nodiscard]] float localXfromChannel( const FTChannelID channelID, const int frac ) const { - const auto& obj = this->access(); - float uFromChannel = obj->m_uBegin + ( 2 * channelID.channel() + 1 + frac ) * obj->m_halfChannelPitch; + const auto& obj = this->access(); + float uFromChannel = obj->m_uBegin + ( 2 * channelID.channel() + 1 + frac ) * obj->m_halfChannelPitch; if ( channelID.die() ) uFromChannel += obj->m_dieGap; uFromChannel += channelID.sipm() * obj->m_sipmPitch; return uFromChannel; @@ -209,11 +220,10 @@ namespace LHCb::Detector { // Get the distance between a 3D global point and a channel+fraction float distancePointToChannel( const ROOT::Math::XYZPoint& globalPoint, const FTChannelID channelID, - const float frac ) const { + const float frac ) const { ROOT::Math::XYZPoint localPoint = toLocal( globalPoint ); return localXfromChannel( channelID, frac ) - localPoint.x(); - } - + } /** Get the distance from the hit to the SiPM * @param localPoint is the position of the half module in local coordinates @@ -222,9 +232,8 @@ namespace LHCb::Detector { [[nodiscard]] float distanceToSiPM( const ROOT::Math::XYZPoint& localPoint ) const { return 0.5f * this->access()->m_sizeY - localPoint.y(); }; - }; - + using DeFTMat = DeFTMatElement; } // End namespace LHCb::Detector diff --git a/Detector/FT/include/Detector/FT/DeFTModule.h b/Detector/FT/include/Detector/FT/DeFTModule.h index 9c0cd84e..e6fe442b 100644 --- a/Detector/FT/include/Detector/FT/DeFTModule.h +++ b/Detector/FT/include/Detector/FT/DeFTModule.h @@ -30,7 +30,7 @@ namespace LHCb::Detector { unsigned int m_id; int m_nChannelsInModule{dd4hep::_toInt( "FT:nChannelsInModule" )}; std::array m_mats; - ROOT::Math::Plane3D m_plane;///< xy-plane in the z-middle of the module + ROOT::Math::Plane3D m_plane; ///< xy-plane in the z-middle of the module bool m_reversed; FTChannelID m_elementID; DeFTModuleObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iModule, @@ -42,53 +42,57 @@ namespace LHCb::Detector { void applyToAllChildren( const std::function& func ) const override { for ( auto& mat : m_mats ) { func( LHCb::Detector::DeIOV{&mat} ); }; }; - FTChannelID::StationID stationID() const{return m_elementID.station();} - FTChannelID::ModuleID moduleID() const{return FTChannelID::ModuleID{m_id};} - + FTChannelID::StationID stationID() const { return m_elementID.station(); } + FTChannelID::ModuleID moduleID() const { return FTChannelID::ModuleID{m_id}; } + /// Get the pseudo-channel for a FTChannelID (useful in the monitoring) int pseudoChannel( const FTChannelID channelID ) const { - int channelInModule = channelID.channelID() & ( m_nChannelsInModule - 1u ); - if ( m_reversed ) { channelInModule = m_nChannelsInModule - 1 - channelInModule; } - return channelInModule + to_unsigned( moduleID() ) * m_nChannelsInModule; + int channelInModule = channelID.channelID() & ( m_nChannelsInModule - 1u ); + if ( m_reversed ) { channelInModule = m_nChannelsInModule - 1 - channelInModule; } + return channelInModule + to_unsigned( moduleID() ) * m_nChannelsInModule; } - + FTChannelID channelFromPseudo( const int pseudoChannel ) const { - int channelInModule = pseudoChannel & ( m_nChannelsInModule - 1u ); - if ( m_reversed ) { channelInModule = m_nChannelsInModule - 1 - channelInModule; } - return FTChannelID( m_elementID + channelInModule ); + int channelInModule = pseudoChannel & ( m_nChannelsInModule - 1u ); + if ( m_reversed ) { channelInModule = m_nChannelsInModule - 1 - channelInModule; } + return FTChannelID( m_elementID + channelInModule ); } - }; } // End namespace detail template struct DeFTModuleElement : DeIOVElement { using DeIOVElement::DeIOVElement; - FTChannelID::ModuleID moduleID() const{return this->access()->moduleID();} - FTChannelID::StationID stationID() const{return this->access()->stationID();} - + FTChannelID::ModuleID moduleID() const { return this->access()->moduleID(); } + FTChannelID::StationID stationID() const { return this->access()->stationID(); } + /// Find the layer for a given XYZ point const std::optional findMat( const ROOT::Math::XYZPoint& aPoint ) const { /// Find the layer and return a pointer to the layer from XYZ point - const auto iter = std::find_if( this->access()->m_mats.begin(), this->access()->m_mats.end(), - [&aPoint]( const detail::DeFTMatObject& m ) { return DeFTMat{&m}.isInside( aPoint ); } ); - return iter != this->access()->m_mats.end() ? iter : std::optional{};//DeFTMat{}; + const auto iter = + std::find_if( this->access()->m_mats.begin(), this->access()->m_mats.end(), + [&aPoint]( const detail::DeFTMatObject& m ) { return DeFTMat{&m}.isInside( aPoint ); } ); + return iter != this->access()->m_mats.end() ? iter : std::optional{}; // DeFTMat{}; } - + const std::optional findMat( const FTChannelID& id ) const { - return (to_unsigned( id.mat() ) < this->access()->m_mats.size())? &(this->access()->m_mats[to_unsigned( id.mat() )]): std::optional{}; + return ( to_unsigned( id.mat() ) < this->access()->m_mats.size() ) + ? &( this->access()->m_mats[to_unsigned( id.mat() )] ) + : std::optional{}; } [[nodiscard]] FTChannelID elementID() const { return this->access()->m_elementID; } - - [[nodiscard]] int pseudoChannel( const FTChannelID channelID ) const {return this->access()->pseudoChannel(channelID);} - + + [[nodiscard]] int pseudoChannel( const FTChannelID channelID ) const { + return this->access()->pseudoChannel( channelID ); + } + [[nodiscard]] FTChannelID channelFromPseudo( const int pseudoChannel ) const { const auto& obj = this->access(); int channelInModule = pseudoChannel & ( obj->m_nChannelsInModule - 1u ); if ( obj->m_reversed ) { channelInModule = obj->m_nChannelsInModule - 1 - channelInModule; } return FTChannelID( this->elementID() + channelInModule ); } - ROOT::Math::Plane3D plane() const {return this->access()->m_plane;} + ROOT::Math::Plane3D plane() const { return this->access()->m_plane; } }; using DeFTModule = DeFTModuleElement; diff --git a/Detector/FT/include/Detector/FT/DeFTQuarter.h b/Detector/FT/include/Detector/FT/DeFTQuarter.h index e96293f9..17352989 100644 --- a/Detector/FT/include/Detector/FT/DeFTQuarter.h +++ b/Detector/FT/include/Detector/FT/DeFTQuarter.h @@ -37,23 +37,26 @@ namespace LHCb::Detector { template struct DeFTQuarterElement : DeIOVElement { - using DeIOVElement::DeIOVElement; - unsigned int quarterID() const{return this->access()->m_id;} + using DeIOVElement::DeIOVElement; + unsigned int quarterID() const { return this->access()->m_id; } /** Find the FT Module corresponding to the point * @return Pointer to the relevant module */ [[nodiscard]] const std::optional findModule( const ROOT::Math::XYZPoint& aPoint ) const { - auto iM = std::find_if( this->access()->m_modules.begin(), this->access()->m_modules.end(), - [&aPoint]( const detail::DeFTModuleObject& m ) { return DeFTModule{&m}.isInside( aPoint ); } ); - return iM != this->access()->m_modules.end() ? iM : std::optional{};//DeFTModule{}; + auto iM = + std::find_if( this->access()->m_modules.begin(), this->access()->m_modules.end(), + [&aPoint]( const detail::DeFTModuleObject& m ) { return DeFTModule{&m}.isInside( aPoint ); } ); + return iM != this->access()->m_modules.end() ? iM : std::optional{}; // DeFTModule{}; } /** Const method to return the module for a given channel id * @param aChannel an FT channel id * @return pointer to detector element */ [[nodiscard]] const std::optional findModule( const FTChannelID& id ) const { - return (to_unsigned( id.module() ) < this->access()->m_modules.size())? &(this->access()->m_modules[to_unsigned( id.mat() )]): std::optional{}; + return ( to_unsigned( id.module() ) < this->access()->m_modules.size() ) + ? &( this->access()->m_modules[to_unsigned( id.mat() )] ) + : std::optional{}; } /** Flat vector of all FT modules diff --git a/Detector/FT/include/Detector/FT/DeFTStation.h b/Detector/FT/include/Detector/FT/DeFTStation.h index 8be83bc7..174543ac 100644 --- a/Detector/FT/include/Detector/FT/DeFTStation.h +++ b/Detector/FT/include/Detector/FT/DeFTStation.h @@ -38,15 +38,16 @@ namespace LHCb::Detector { template struct DeFTStationElement : DeIOVElement { using DeIOVElement::DeIOVElement; - unsigned int stationID() const{return this->access()->m_id;} + unsigned int stationID() const { return this->access()->m_id; } /** Find the FT Layer corresponding to the point * @return Pointer to the relevant layer */ [[nodiscard]] const std::optional findLayer( const ROOT::Math::XYZPoint& aPoint ) const { - auto iter = std::find_if( this->access()->m_layers.begin(), this->access()->m_layers.end(), - [&aPoint]( const detail::DeFTLayerObject& l ) { return DeFTLayer{&l}.isInside( aPoint );} ); - return iter != this->access()->m_layers.end() ? iter : std::optional{};//DeFTLayer{}; + auto iter = + std::find_if( this->access()->m_layers.begin(), this->access()->m_layers.end(), + [&aPoint]( const detail::DeFTLayerObject& l ) { return DeFTLayer{&l}.isInside( aPoint ); } ); + return iter != this->access()->m_layers.end() ? iter : std::optional{}; // DeFTLayer{}; } /** Const method to return the layer for a given channel id @@ -54,7 +55,9 @@ namespace LHCb::Detector { * @return pointer to detector element */ [[nodiscard]] const std::optional findLayer( const FTChannelID& id ) const { - return (to_unsigned( id.layer() ) < this->access()->m_layers.size())? &(this->access()->m_layers[to_unsigned( id.layer() )]): std::optional{}; + return ( to_unsigned( id.layer() ) < this->access()->m_layers.size() ) + ? &( this->access()->m_layers[to_unsigned( id.layer() )] ) + : std::optional{}; } }; diff --git a/Detector/FT/include/Detector/FT/FTChannelID.h b/Detector/FT/include/Detector/FT/FTChannelID.h index 615bd46a..696a0e53 100644 --- a/Detector/FT/include/Detector/FT/FTChannelID.h +++ b/Detector/FT/include/Detector/FT/FTChannelID.h @@ -84,11 +84,11 @@ namespace LHCb::Detector { [[nodiscard]] friend constexpr unsigned int to_unsigned( MatID id ) { return static_cast( id ); } /// Default Constructor - constexpr FTChannelID(): FTChannelID{ kInvalidChannel() } {}; + constexpr FTChannelID() : FTChannelID{kInvalidChannel()} {}; /// Partial constructor using the unique sipm and the channel constexpr FTChannelID( unsigned int uniqueSiPM, unsigned int channel ) - : m_channelID{ shift( uniqueSiPM ) | shift( channel ) } {}; + : m_channelID{shift( uniqueSiPM ) | shift( channel )} {}; /// Constructor from int constexpr explicit FTChannelID( unsigned int id ) : m_channelID{id} {} diff --git a/Detector/FT/src/DeFT.cpp b/Detector/FT/src/DeFT.cpp index 0c9fcbb7..d9243215 100644 --- a/Detector/FT/src/DeFT.cpp +++ b/Detector/FT/src/DeFT.cpp @@ -15,7 +15,7 @@ #include "DD4hep/Printout.h" -//FIXME: ROOT vs LHCB lengths +// FIXME: ROOT vs LHCB lengths LHCb::Detector::detail::DeFTObject::DeFTObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ) @@ -28,8 +28,8 @@ LHCb::Detector::detail::DeFTStationObject::DeFTStationObject( const dd4hep::DetE : DeIOVObject( de, ctxt ) , m_id{iStation} , m_layers{{{de.child( "X1" ), ctxt, 0, m_id}, - {de.child( "U" ), ctxt, 1, m_id}, - {de.child( "V" ), ctxt, 2, m_id}, + {de.child( "U" ), ctxt, 1, m_id}, + {de.child( "V" ), ctxt, 2, m_id}, {de.child( "X2" ), ctxt, 3, m_id}}} {} LHCb::Detector::detail::DeFTLayerObject::DeFTLayerObject( const dd4hep::DetElement& de, @@ -41,26 +41,26 @@ LHCb::Detector::detail::DeFTLayerObject::DeFTLayerObject( const dd4hep::DetEleme {de.child( "Q1" ), ctxt, 1, m_layerID}, {de.child( "Q2" ), ctxt, 2, m_layerID}, {de.child( "Q3" ), ctxt, 3, m_layerID}}} { - // Get the global z position of the layer - ROOT::Math::XYZPoint globalPoint = this->toGlobal( ROOT::Math::XYZPoint( 0., 0., 0. ) ); - m_globalZ = globalPoint.z(); - - // Get the boundaries of the layer - // FIXME - // const dd4hep::Box* box = dynamic_cast( geometry()->lvolume()->solid()->coverTop() ); - // m_sizeX = box->xsize(); - // m_sizeY = box->ysize(); - - // Make the plane for the layer - const ROOT::Math::XYZPoint g1 = this->toGlobal( ROOT::Math::XYZPoint( 0., 0., 0. ) ); - const ROOT::Math::XYZPoint g2 = this->toGlobal( ROOT::Math::XYZPoint( 1., 0., 0. ) ); - const ROOT::Math::XYZPoint g3 = this->toGlobal( ROOT::Math::XYZPoint( 0., 1., 0. ) ); - m_plane = ROOT::Math::Plane3D( g1, g2, g3 ); - m_dzdy = ( g3.z() - g1.z() ) / ( g3.y() - g1.y() ); - // m_dxdy = -tan( m_stereoAngle ); - m_dxdy = (g3.x() - g1.x())/(g3.y()-g1.y());//FIXME: to check - m_stereoAngle = -atan( m_dxdy); - } + // Get the global z position of the layer + ROOT::Math::XYZPoint globalPoint = this->toGlobal( ROOT::Math::XYZPoint( 0., 0., 0. ) ); + m_globalZ = globalPoint.z(); + + // Get the boundaries of the layer + // FIXME + // const dd4hep::Box* box = dynamic_cast( geometry()->lvolume()->solid()->coverTop() ); + // m_sizeX = box->xsize(); + // m_sizeY = box->ysize(); + + // Make the plane for the layer + const ROOT::Math::XYZPoint g1 = this->toGlobal( ROOT::Math::XYZPoint( 0., 0., 0. ) ); + const ROOT::Math::XYZPoint g2 = this->toGlobal( ROOT::Math::XYZPoint( 1., 0., 0. ) ); + const ROOT::Math::XYZPoint g3 = this->toGlobal( ROOT::Math::XYZPoint( 0., 1., 0. ) ); + m_plane = ROOT::Math::Plane3D( g1, g2, g3 ); + m_dzdy = ( g3.z() - g1.z() ) / ( g3.y() - g1.y() ); + // m_dxdy = -tan( m_stereoAngle ); + m_dxdy = ( g3.x() - g1.x() ) / ( g3.y() - g1.y() ); // FIXME: to check + m_stereoAngle = -atan( m_dxdy ); +} LHCb::Detector::detail::DeFTQuarterObject::DeFTQuarterObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt, @@ -85,13 +85,13 @@ LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetEle {de.child( "Mat3" ), ctxt, 3, m_id}}} { // Is reversed? const auto firstPoint = this->toGlobal( {-1, 0, 0} ); - const auto lastPoint = this->toGlobal( { 1, 0, 0} ); + const auto lastPoint = this->toGlobal( {1, 0, 0} ); m_reversed = std::abs( firstPoint.x() ) > std::abs( lastPoint.x() ); // Make the plane for the module const ROOT::Math::XYZPoint g1 = this->toGlobal( ROOT::Math::XYZPoint( 0., 0., 0. ) ); const ROOT::Math::XYZPoint g2 = this->toGlobal( ROOT::Math::XYZPoint( 1., 0., 0. ) ); const ROOT::Math::XYZPoint g3 = this->toGlobal( ROOT::Math::XYZPoint( 0., 1., 0. ) ); - m_plane = ROOT::Math::Plane3D( g1, g2, g3 ); + m_plane = ROOT::Math::Plane3D( g1, g2, g3 ); // Build the FTChannelID auto localModuleID = FTChannelID::ModuleID{static_cast( m_id % FT::nModules )}; @@ -104,44 +104,40 @@ LHCb::Detector::detail::DeFTModuleObject::DeFTModuleObject( const dd4hep::DetEle } LHCb::Detector::detail::DeFTMatObject::DeFTMatObject( const dd4hep::DetElement& de, - dd4hep::cond::ConditionUpdateContext& ctxt, - unsigned int iMat, unsigned int moduleID ) - : DeIOVObject( de, ctxt ) - , m_elementID{iMat} - , m_matID{moduleID * FT::nMats + iMat} - { - //FIXME: see VP - // Get some useful geometric parameters from the database - m_halfChannelPitch = 0.5f * m_channelPitch; - - m_sipmPitch = m_nChannelsInSiPM * m_channelPitch + m_dieGap + 2 * m_airGap + 2 * m_deadRegion; - m_nChannelsInDie = m_nChannelsInSiPM / m_nDiesInSiPM; - m_diePitch = m_nChannelsInDie * m_channelPitch + m_dieGap; - m_uBegin = m_airGap + m_deadRegion - 2.f * m_sipmPitch; - - //Update cache - // Get the central points of the fibres at the mirror and at the SiPM locations - m_mirrorPoint = this->toGlobal( ROOT::Math::XYZPoint( 0, -0.5f * m_sizeY, 0 ) ); - m_sipmPoint = this->toGlobal( ROOT::Math::XYZPoint( 0, +0.5f * m_sizeY, 0 ) ); - - // Define the global z position to be at the point closest to the mirror - m_globalZ = m_mirrorPoint.z(); - - // Define the global length in y of the mat - m_globaldy = m_sipmPoint.y() - m_mirrorPoint.y(); - - // Make the plane for the mat - const ROOT::Math::XYZPoint g1 = this->toGlobal( ROOT::Math::XYZPoint( 0., 0., 0. ) ); - const ROOT::Math::XYZPoint g2 = this->toGlobal( ROOT::Math::XYZPoint( 1., 0., 0. ) ); - const ROOT::Math::XYZPoint g3 = this->toGlobal( ROOT::Math::XYZPoint( 0., 1., 0. ) ); - m_plane = ROOT::Math::Plane3D( g1, g2, g3 ); - - // Get the slopes in units of local delta x - m_ddx = ROOT::Math::XYZVectorF( g2 - g1 ); - - // Get the slopes in units of delta y (needed by PrFTHit, mind the sign) - ROOT::Math::XYZVectorF deltaY( g1 - g3 ); - m_dxdy = deltaY.x() / deltaY.y(); - m_dzdy = deltaY.z() / deltaY.y(); - - } + dd4hep::cond::ConditionUpdateContext& ctxt, unsigned int iMat, + unsigned int moduleID ) + : DeIOVObject( de, ctxt ), m_elementID{iMat}, m_matID{moduleID * FT::nMats + iMat} { + // FIXME: see VP + // Get some useful geometric parameters from the database + m_halfChannelPitch = 0.5f * m_channelPitch; + + m_sipmPitch = m_nChannelsInSiPM * m_channelPitch + m_dieGap + 2 * m_airGap + 2 * m_deadRegion; + m_nChannelsInDie = m_nChannelsInSiPM / m_nDiesInSiPM; + m_diePitch = m_nChannelsInDie * m_channelPitch + m_dieGap; + m_uBegin = m_airGap + m_deadRegion - 2.f * m_sipmPitch; + + // Update cache + // Get the central points of the fibres at the mirror and at the SiPM locations + m_mirrorPoint = this->toGlobal( ROOT::Math::XYZPoint( 0, -0.5f * m_sizeY, 0 ) ); + m_sipmPoint = this->toGlobal( ROOT::Math::XYZPoint( 0, +0.5f * m_sizeY, 0 ) ); + + // Define the global z position to be at the point closest to the mirror + m_globalZ = m_mirrorPoint.z(); + + // Define the global length in y of the mat + m_globaldy = m_sipmPoint.y() - m_mirrorPoint.y(); + + // Make the plane for the mat + const ROOT::Math::XYZPoint g1 = this->toGlobal( ROOT::Math::XYZPoint( 0., 0., 0. ) ); + const ROOT::Math::XYZPoint g2 = this->toGlobal( ROOT::Math::XYZPoint( 1., 0., 0. ) ); + const ROOT::Math::XYZPoint g3 = this->toGlobal( ROOT::Math::XYZPoint( 0., 1., 0. ) ); + m_plane = ROOT::Math::Plane3D( g1, g2, g3 ); + + // Get the slopes in units of local delta x + m_ddx = ROOT::Math::XYZVectorF( g2 - g1 ); + + // Get the slopes in units of delta y (needed by PrFTHit, mind the sign) + ROOT::Math::XYZVectorF deltaY( g1 - g3 ); + m_dxdy = deltaY.x() / deltaY.y(); + m_dzdy = deltaY.z() / deltaY.y(); +} -- GitLab From 32ce60ba436cad0d9b300b8b715a1f119d6ce5e8 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Tue, 26 Oct 2021 11:43:25 +0200 Subject: [PATCH 34/37] Added few parameters to the FT --- compact/trunk/FT/parameters.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/compact/trunk/FT/parameters.xml b/compact/trunk/FT/parameters.xml index c51896f0..a275b3cf 100644 --- a/compact/trunk/FT/parameters.xml +++ b/compact/trunk/FT/parameters.xml @@ -169,6 +169,7 @@ + -- GitLab From c8abf352d3b6ff1e54e4c37e890235d5a6fb42c7 Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Wed, 27 Oct 2021 11:58:09 +0200 Subject: [PATCH 35/37] Added a FIXME --- Detector/FT/include/Detector/FT/DeFTLayer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Detector/FT/include/Detector/FT/DeFTLayer.h b/Detector/FT/include/Detector/FT/DeFTLayer.h index 789fc577..56fce755 100644 --- a/Detector/FT/include/Detector/FT/DeFTLayer.h +++ b/Detector/FT/include/Detector/FT/DeFTLayer.h @@ -27,6 +27,7 @@ namespace LHCb::Detector { */ struct DeFTLayerObject : DeIOVObject { /// Reference to the static information of the quarters + /// FIXME: LayerID does not mean the same thing as in DetDesc. Here it is a global layer ID. unsigned int m_layerID; ///< layer ID number float m_globalZ; ///< Global z position of layer closest to y-axis ROOT::Math::Plane3D m_plane; ///< xy-plane in the z-middle of the layer -- GitLab From 12271a14c832414b34397fc6369165553c4cdcca Mon Sep 17 00:00:00 2001 From: Louis Henry Date: Wed, 3 Nov 2021 19:44:34 +0100 Subject: [PATCH 36/37] Remove conflicting constructor --- Detector/FT/include/Detector/FT/DeFTMat.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index 2ffcc9e4..96664e1e 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -76,7 +76,6 @@ namespace LHCb::Detector { return this->detectorAlignment.localToWorld( v ); } - using DeIOVObject::DeIOVObject; }; } // End namespace detail template -- GitLab From 7277ca7ae00a038f620f937fc9a7ac4c79b44079 Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Wed, 3 Nov 2021 18:45:08 +0000 Subject: [PATCH 37/37] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Detector/-/jobs/17346041 --- Detector/FT/include/Detector/FT/DeFTMat.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Detector/FT/include/Detector/FT/DeFTMat.h b/Detector/FT/include/Detector/FT/DeFTMat.h index 96664e1e..d23f63fa 100644 --- a/Detector/FT/include/Detector/FT/DeFTMat.h +++ b/Detector/FT/include/Detector/FT/DeFTMat.h @@ -75,7 +75,6 @@ namespace LHCb::Detector { ROOT::Math::XYZVector toGlobal( const ROOT::Math::XYZVector& v ) const { return this->detectorAlignment.localToWorld( v ); } - }; } // End namespace detail template -- GitLab