diff --git a/Pr/PrKernel/include/PrKernel/PrFTZoneHandler.h b/Pr/PrKernel/include/PrKernel/PrFTZoneHandler.h index be22f900d237da3b0b192f2068fb3a3211c7e6a6..a6e5b2d6e96b450a9ad9143644dce9ac7d5c58d2 100644 --- a/Pr/PrKernel/include/PrKernel/PrFTZoneHandler.h +++ b/Pr/PrKernel/include/PrKernel/PrFTZoneHandler.h @@ -15,6 +15,8 @@ #include "FTDet/DeFTDetector.h" #include "Kernel/DetectorSegment.h" #include "PrKernel/PrHitZone.h" +#include <cassert> +#include <stdexcept> namespace FTZoneCache { @@ -31,32 +33,35 @@ namespace FTZoneCache { PrFTZoneHandler( DeFT const& ftDet ) { #ifdef USE_DD4HEP auto func = [this]( const DeFTLayer& layer ) { - int id = layer.layerID(); + const auto id = layer.layerID(); // fixme DetectorSegment seg( 0, layer.globalZ(), layer.dxdy(), layer.dzdy(), 0., 0. ); - float xmax = 0.5f * layer.sizeX(); - float ymax = 0.5f * layer.sizeY(); + const auto xmax = 0.5f * layer.sizeX(); + const auto ymax = 0.5f * layer.sizeY(); // The setGeometry defines the z at y=0, the dxDy and the dzDy, as well as the isX properties of the zone. // This is important, since these are used in the following. // They are set once for each zone in this method. - this->MakeZone( 2 * id + 1, seg, -xmax, xmax, -25.f, ymax ); // Small overlap (25 mm) for stereo layers - this->MakeZone( 2 * id, seg, -xmax, xmax, -ymax, 25.f ); // Small overlap (25 mm) for stereo layers + const bool ok = + ( this->MakeZone( 2 * id + 1, seg, -xmax, xmax, -25.f, ymax ) && // Small overlap (25 mm) for stereo layers + this->MakeZone( 2 * id, seg, -xmax, xmax, -ymax, 25.f ) ); // Small overlap (25 mm) for stereo layers + if ( !ok ) { throw std::runtime_error( "Failed to create DeFT Zones for ID = " + std::to_string( id ) ); } }; ftDet.applyToAllLayers( func ); #else for ( auto station : ftDet.stations() ) { for ( auto layer : station->layers() ) { - int id = 4 * ( station->stationID() - 1 ) + layer->layerID(); - + const auto id = 4 * ( station->stationID() - 1 ) + layer->layerID(); DetectorSegment seg( 0, layer->globalZ(), layer->dxdy(), layer->dzdy(), 0., 0. ); - float xmax = 0.5f * layer->sizeX(); - float ymax = 0.5f * layer->sizeY(); - + const auto xmax = 0.5f * layer->sizeX(); + const auto ymax = 0.5f * layer->sizeY(); // The setGeometry defines the z at y=0, the dxDy and the dzDy, as well as the isX properties of the zone. // This is important, since these are used in the following. // They are set once for each zone in this method. - this->MakeZone( 2 * id + 1, seg, -xmax, xmax, -25.f, ymax ); // Small overlap (25 mm) for stereo layers - this->MakeZone( 2 * id, seg, -xmax, xmax, -ymax, 25.f ); // Small overlap (25 mm) for stereo layers + const bool ok = + ( this->MakeZone( 2 * id + 1, seg, -xmax, xmax, -25.f, ymax ) && // Small overlap (25 mm) for stereo + // layers + this->MakeZone( 2 * id, seg, -xmax, xmax, -ymax, 25.f ) ); // Small overlap (25 mm) for stereo layers + if ( !ok ) { throw std::runtime_error( "Failed to create DeFT Zones for ID = " + std::to_string( id ) ); } } } #endif @@ -64,10 +69,20 @@ namespace FTZoneCache { /// Standard constructor PrFTZoneHandler() = default; - void MakeZone( unsigned int n, DetectorSegment& seg, float xMin, float xMax, float yMin, float yMax ) { - m_zones[n].setZone( n, seg, xMin, xMax, yMin, yMax ); + bool MakeZone( unsigned int n, DetectorSegment& seg, float xMin, float xMax, float yMin, float yMax ) { + if ( n < m_zones.size() ) { + m_zones[n].setZone( n, seg, xMin, xMax, yMin, yMax ); + return true; + } else { + return false; + } + } + const PrHitZone& zone( unsigned int n ) const { + if ( n >= m_zones.size() ) { + throw std::runtime_error( "Zone index " + std::to_string( n ) + " is out-of-range" ); + } + return m_zones[n]; } - const PrHitZone& zone( unsigned int n ) const { return m_zones[n]; } template <PrHitZone::Side SIDE> static int getXZone( int layer ) { @@ -112,7 +127,6 @@ namespace FTZoneCache { std::array<float, PrFTInfo::NFTZones> zoneDxDy{std::numeric_limits<float>::signaling_NaN()}; std::array<float, PrFTInfo::NFTZones> zoneDzDy{std::numeric_limits<float>::signaling_NaN()}; std::array<float, PrFTInfo::NFTZones> zoneZPos{std::numeric_limits<float>::signaling_NaN()}; - ZoneCache() = default; // Needed by DD4hep even if unused ! ZoneCache( const DeFT& ftDet ) : handler( ftDet ) { for ( int i{0}; i < PrFTInfo::NFTLayers; ++i ) { zoneZPos[2 * i] = handler.zone( 2 * i ).z(); diff --git a/Pr/PrKernel/include/PrKernel/PrHitZone.h b/Pr/PrKernel/include/PrKernel/PrHitZone.h index 160f88279fd7838ddc35c1b448221d51289f4ad1..4c6bf8376ea93f9846286fdbf1f740c44e63f2bd 100644 --- a/Pr/PrKernel/include/PrKernel/PrHitZone.h +++ b/Pr/PrKernel/include/PrKernel/PrHitZone.h @@ -8,8 +8,8 @@ * granted to it by virtue of its status as an Intergovernmental Organization * * or submit itself to any jurisdiction. * \*****************************************************************************/ -#ifndef PRKERNEL_PRHITZONE_H -#define PRKERNEL_PRHITZONE_H 1 + +#pragma once // Include files #include "Kernel/DetectorSegment.h" @@ -58,15 +58,14 @@ public: float dxOnAFibre() const { return ( m_yMax - m_yMin ) * m_dxDy; } private: - unsigned int m_number; - unsigned int m_planeCode; - float m_z; - float m_dxDy; - float m_dzDy; - bool m_isX; - float m_xMin; - float m_xMax; - float m_yMin; - float m_yMax; + unsigned int m_number{}; + unsigned int m_planeCode{}; + float m_z{}; + float m_dxDy{}; + float m_dzDy{}; + bool m_isX{}; + float m_xMin{}; + float m_xMax{}; + float m_yMin{}; + float m_yMax{}; }; -#endif // PRKERNEL_PRHITZONE_H