From 8fdf8d18bff83e88541c0dd1e11c913c07075eaf Mon Sep 17 00:00:00 2001 From: Mark Sutton <mark.sutton@cern.ch> Date: Mon, 16 Mar 2020 15:46:29 +0000 Subject: [PATCH] Updates to the RegSelTool implementation including addition of MDT tables These include several updates to the RegSelTool implementation with respect to merge request !30981 Firstly better memory handling for the RegSelLUTCondData where the payload is now stored using a unique_ptr to better avoid memory leaks. Additionally there is an new class for the MDT_RegSelCondAlg which uses the new MDT cabling conditions data to create the table for the RegSelTool. The RegSelToolConfig.py now has an improved private builder function, whoch is used to provide public builders for the Pixel, SCT, TRT and MDT. The SCT Cabling conditions data are now used for the EventIDRange for the SCT table, rather than using the pixel cabling. Some of the old RegSelSvc code has been retained, but commented since we are still developing. One additional factor regarding the MDT table creation code: The createTable() method is essentially a cut and past of the original MDT code from the MDT_RegionSelectorTable class. I did not originally write this code, and don't want to touch it as that would require a great deal of validation beyond the scope of the changes for this merge request. There are a good many places where that code itself could be improved, but that should be left for the Muon developers for a later day. For this code we are implementing the framework to provide the full functionality for the new RegSelTool implementation so there will be quite a lot of copying of code from the older implementation over the coming weeks for the additional Muon and Calorimeter tables. --- .../IRegionSelector/RegSelCondData.h | 11 +- .../RegionSelector/python/RegSelToolConfig.py | 104 +++-- .../RegionSelector/src/RegSelTool.cxx | 36 +- .../RegionSelector/src/RegSelTool.h | 24 +- .../src/components/RegionSelector_entries.cxx | 1 + .../src/SiRegSelCondAlg.cxx | 56 ++- .../InDetRegionSelector/src/SiRegSelCondAlg.h | 10 +- .../src/TRT_RegSelCondAlg.cxx | 16 +- .../MuonRegionSelector/CMakeLists.txt | 5 +- .../src/CSC_RegSelCondAlg.cxx | 360 +++++++++++++++++ .../src/CSC_RegSelCondAlg.h | 28 ++ .../src/MDT_RegSelCondAlg.cxx | 361 ++++++++++++++++++ .../src/MDT_RegSelCondAlg.h | 27 ++ .../src/MM_RegSelCondAlg.cxx | 156 ++++++++ .../MuonRegionSelector/src/MM_RegSelCondAlg.h | 28 ++ .../src/MuonRegSelCondAlg.cxx | 109 ++++++ .../src/MuonRegSelCondAlg.h | 60 +++ .../src/RPC_RegSelCondAlg.cxx | 271 +++++++++++++ .../src/RPC_RegSelCondAlg.h | 27 ++ .../src/RPC_RegionSelectorTable.cxx | 2 - .../src/TGC_RegSelCondAlg.cxx | 185 +++++++++ .../src/TGC_RegSelCondAlg.h | 27 ++ .../components/MuonRegionSelector_entries.cxx | 14 + .../src/sTGC_RegSelCondAlg.cxx | 155 ++++++++ .../src/sTGC_RegSelCondAlg.h | 32 ++ .../python/TrigFastTrackFinder_Config.py | 2 +- 26 files changed, 1993 insertions(+), 114 deletions(-) create mode 100644 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/CSC_RegSelCondAlg.cxx create mode 100755 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/CSC_RegSelCondAlg.h create mode 100644 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MDT_RegSelCondAlg.cxx create mode 100755 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MDT_RegSelCondAlg.h create mode 100644 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MM_RegSelCondAlg.cxx create mode 100755 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MM_RegSelCondAlg.h create mode 100644 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MuonRegSelCondAlg.cxx create mode 100755 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MuonRegSelCondAlg.h create mode 100644 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/RPC_RegSelCondAlg.cxx create mode 100755 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/RPC_RegSelCondAlg.h create mode 100644 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/TGC_RegSelCondAlg.cxx create mode 100755 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/TGC_RegSelCondAlg.h create mode 100644 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/sTGC_RegSelCondAlg.cxx create mode 100755 MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/sTGC_RegSelCondAlg.h diff --git a/DetectorDescription/IRegionSelector/IRegionSelector/RegSelCondData.h b/DetectorDescription/IRegionSelector/IRegionSelector/RegSelCondData.h index a6533b03772..dd2c34cd840 100644 --- a/DetectorDescription/IRegionSelector/IRegionSelector/RegSelCondData.h +++ b/DetectorDescription/IRegionSelector/IRegionSelector/RegSelCondData.h @@ -18,6 +18,7 @@ #define REGSELCONDDATA_H #include <iostream> +#include <memory> template<typename T> @@ -25,15 +26,15 @@ class RegSelCondData { public: - RegSelCondData( const T& t ) : m_payload(t) { } - + RegSelCondData( std::unique_ptr<T> t ) : m_payload(std::move(t)) { } + virtual ~RegSelCondData() { } - - const T* payload() const { return &m_payload; } /// could return the actual payload reference, but have everything using pointers + + const T* payload() const { return m_payload.get(); } /// could return the actual payload reference, but have everything using pointers protected: - T m_payload; + std::unique_ptr<T> m_payload; }; diff --git a/DetectorDescription/RegionSelector/python/RegSelToolConfig.py b/DetectorDescription/RegionSelector/python/RegSelToolConfig.py index 545ff35a18a..8b92557bac0 100644 --- a/DetectorDescription/RegionSelector/python/RegSelToolConfig.py +++ b/DetectorDescription/RegionSelector/python/RegSelToolConfig.py @@ -11,33 +11,34 @@ # - -def _makeSiRegSelTool(detector, enable) : +def _makeRegSelTool( detector, enable, CondAlgConstructor ) : from RegionSelector.RegionSelectorConf import RegSelTool tool = RegSelTool(name="RegSelTool_"+detector) - # should we enable the look up table access ? + # should we enable the look up table access for this subsystem ? if ( enable ) : - + # add the lookup table to retrieve - + tool.RegSelLUT = "RegSelLUTCondData_"+detector + tool.Initialised = True # add the conditions algorithm to create the lookup table from AthenaCommon.AlgSequence import AthSequencer condseq = AthSequencer('AthCondSeq') - if not hasattr(condseq, 'RegSelCondAlg_'+detector): - from InDetRegionSelector.InDetRegionSelectorConf import SiRegSelCondAlg - CondAlg = SiRegSelCondAlg( name = ("RegSelCondAlg_"+detector), - ManagerName = detector, - PrintTable = False) - CondAlg.RegSelLUT = "RegSelLUTCondData_"+detector + if not hasattr( condseq, 'RegSelCondAlg_'+detector ) : + CondAlg = CondAlgConstructor( name = ("RegSelCondAlg_"+detector), + ManagerName = detector, + PrintTable = False, + RegSelLUT = ("RegSelLUTCondData_"+detector) ) + condseq += CondAlg + else: # detector not configured so don't enable # lookup table access @@ -48,50 +49,71 @@ def _makeSiRegSelTool(detector, enable) : +# inner detector toold + def makeRegSelTool_Pixel() : from AthenaCommon.DetFlags import DetFlags enabled = DetFlags.detdescr.pixel_on() - return _makeSiRegSelTool( 'Pixel', enabled ) - + from InDetRegionSelector.InDetRegionSelectorConf import SiRegSelCondAlg + return _makeRegSelTool( 'Pixel', enabled, SiRegSelCondAlg ) def makeRegSelTool_SCT() : from AthenaCommon.DetFlags import DetFlags enabled = DetFlags.detdescr.SCT_on() - return _makeSiRegSelTool( 'SCT', enabled ) - + from InDetRegionSelector.InDetRegionSelectorConf import SiRegSelCondAlg + return _makeRegSelTool( 'SCT', enabled, SiRegSelCondAlg ) def makeRegSelTool_TRT() : - from AthenaCommon.DetFlags import DetFlags enabled = DetFlags.detdescr.TRT_on() - - from RegionSelector.RegionSelectorConf import RegSelTool - tool = RegSelTool(name="RegSelTool_TRT") - - # should we enable the look up table access ? + from InDetRegionSelector.InDetRegionSelectorConf import TRT_RegSelCondAlg + return _makeRegSelTool( 'TRT', enabled, TRT_RegSelCondAlg ) - if ( enabled ) : - # add the lookup table to retrieve +# muon spectrimeter tools - tool.RegSelLUT = "RegSelLUTCondData_TRT" +def makeRegSelTool_MDT() : + from AthenaCommon.DetFlags import DetFlags + enabled = DetFlags.detdescr.MDT_on() + from MuonRegionSelector.MuonRegionSelectorConf import MDT_RegSelCondAlg + return _makeRegSelTool( "MDT", enabled, MDT_RegSelCondAlg ) - # add the conditions algorithm to create the lookup table +def makeRegSelTool_RPC() : + from AthenaCommon.DetFlags import DetFlags + enabled = DetFlags.detdescr.RPC_on() + from MuonRegionSelector.MuonRegionSelectorConf import RPC_RegSelCondAlg + return _makeRegSelTool( "RPC", enabled, RPC_RegSelCondAlg ) - from AthenaCommon.AlgSequence import AthSequencer - condseq = AthSequencer('AthCondSeq') - - if not hasattr(condseq, 'RegSelCondAlg_TRT'): - from InDetRegionSelector.InDetRegionSelectorConf import TRT_RegSelCondAlg - CondAlg = TRT_RegSelCondAlg( name = "RegSelCondAlg_TRT", - ManagerName = "TRT", - PrintTable = False) - CondAlg.RegSelLUT = "RegSelLUTCondData_TRT" - condseq += CondAlg - else: - # detector subsystem not configured so don't enable - # lookup table access +def makeRegSelTool_TGC() : + from AthenaCommon.DetFlags import DetFlags + enabled = DetFlags.detdescr.TGC_on() + from MuonRegionSelector.MuonRegionSelectorConf import TGC_RegSelCondAlg + return _makeRegSelTool( "TGC", enabled, TGC_RegSelCondAlg ) + +def makeRegSelTool_CSC() : + from AthenaCommon.DetFlags import DetFlags + enabled = DetFlags.detdescr.CSC_on() + from MuonRegionSelector.MuonRegionSelectorConf import CSC_RegSelCondAlg + return _makeRegSelTool( "CSC", enabled, CSC_RegSelCondAlg ) + + +# new small wheel + +def makeRegSelTool_MM() : + from AtlasGeoModel.MuonGMJobProperties import MuonGeometryFlags + from AthenaCommon.DetFlags import DetFlags + enabled = False + if MuonGeometryFlags.hasMM() : + enabled = DetFlags.detdescr.Micromegas_on() + from MuonRegionSelector.MuonRegionSelectorConf import MM_RegSelCondAlg + return _makeRegSelTool( "MM", enabled, MM_RegSelCondAlg ) + +def makeRegSelTool_sTGC() : + from AtlasGeoModel.MuonGMJobProperties import MuonGeometryFlags + from AthenaCommon.DetFlags import DetFlags + enabled = False + if MuonGeometryFlags.hasSTGC() : + enabled = DetFlags.detdescr.sTGC_on() + from MuonRegionSelector.MuonRegionSelectorConf import sTGC_RegSelCondAlg + return _makeRegSelTool( "sTGC", enabled, sTGC_RegSelCondAlg ) - tool.Initialised = False - - return tool diff --git a/DetectorDescription/RegionSelector/src/RegSelTool.cxx b/DetectorDescription/RegionSelector/src/RegSelTool.cxx index 60fa55581c0..7a314e7b332 100644 --- a/DetectorDescription/RegionSelector/src/RegSelTool.cxx +++ b/DetectorDescription/RegionSelector/src/RegSelTool.cxx @@ -7,7 +7,7 @@ ** @date Sun 22 Sep 2019 10:21:50 BST ** ** - ** Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration **/ @@ -27,12 +27,13 @@ //! Constructor RegSelTool::RegSelTool( const std::string& type, const std::string& name, const IInterface* parent ) : base_class( type, name, parent ), - m_initialised(true), - m_dumpTable(false) + m_initialised(false), + m_dumpTable(false), + m_rpcflag(false) { //! Declare properties - declareProperty( "WriteTable", m_dumpTable, "write out maps to files for debugging" ); - declareProperty( "Initialised", m_initialised=true, "flag to determine whether the corresponding subsystem is initilised" ); + declareProperty( "WriteTable", m_dumpTable, "write out maps to files for debugging" ); + declareProperty( "Initialised", m_initialised=false, "flag to determine whether the corresponding subsystem is initilised" ); } @@ -43,20 +44,19 @@ RegSelTool::~RegSelTool() { } const RegSelSiLUT* RegSelTool::lookup() const { if ( !m_initialised ) return nullptr; SG::ReadCondHandle< RegSelCondData<RegSelSiLUT> > table_handle( m_tableKey ); - // ATH_CHECK( table_handle.isSuccess() ); const RegSelSiLUT* lookup_table = (*table_handle)->payload(); - return lookup_table; - + return lookup_table; } - StatusCode RegSelTool::initialize() { - if ( m_initialised ) { - ATH_CHECK( m_tableKey.initialize() ); - ATH_MSG_INFO( "Initialising " << name() << "\tkey " << m_tableKey ); + ATH_CHECK( m_tableKey.initialize() ); + ATH_MSG_DEBUG( "Initialising RegSelTool " << name() << "\ttable: " << m_tableKey ); + if ( !m_initialised ) { + ATH_MSG_WARNING( "Lookup table will not be iitialised " << name() << "\tkey " << m_tableKey ); } + if ( name().find( "RPC") != std::string::npos ) m_rpcflag = true; return StatusCode::SUCCESS; } @@ -68,12 +68,14 @@ StatusCode RegSelTool::finalize() { } -bool RegSelTool::handle() { - return true; +void RegSelTool::cleanup( std::vector<IdentifierHash>& idvec ) const { + for ( size_t i=idvec.size() ; i-- ; ) idvec[i] = IdentifierHash( ((unsigned)idvec[i]) & 0xfff ); + RegSelSiLUT::removeDuplicates( idvec ); } + // new RegionSelector interface for the Innner Detector void RegSelTool::getRoIData( const IRoiDescriptor& roi, std::vector<const RegSelModule*>& modules ) const { @@ -113,6 +115,8 @@ void RegSelTool::HashIDList( const IRoiDescriptor& roi, std::vector<IdentifierHa const RegSelSiLUT* lookuptable = lookup(); if ( lookuptable ) lookuptable->getHashList( roitmp, idlist ); + if ( m_rpcflag ) cleanup( idlist ); + } @@ -136,6 +140,8 @@ void RegSelTool::HashIDList( long layer, const IRoiDescriptor& roi, std::vector< const RegSelSiLUT* lookuptable = lookup(); if ( lookuptable ) lookuptable->getHashList( roitmp, layer, idlist ); + if ( m_rpcflag ) cleanup( idlist ); + } @@ -202,6 +208,7 @@ void RegSelTool::ROBIDList( long layer, const IRoiDescriptor& roi, std::vector<u void RegSelTool::HashIDList( std::vector<IdentifierHash>& idlist ) const { const RegSelSiLUT* lookuptable = lookup(); if ( lookuptable ) lookuptable->getHashList( idlist ); + if ( m_rpcflag ) cleanup( idlist ); } /// fullscan hashid for specific layer @@ -209,6 +216,7 @@ void RegSelTool::HashIDList( std::vector<IdentifierHash>& idlist ) const { void RegSelTool::HashIDList( long layer, std::vector<IdentifierHash>& idlist ) const { const RegSelSiLUT* lookuptable = lookup(); if ( lookuptable ) lookuptable->getHashList( layer, idlist ); + if ( m_rpcflag ) cleanup( idlist ); } /// full scan robid diff --git a/DetectorDescription/RegionSelector/src/RegSelTool.h b/DetectorDescription/RegionSelector/src/RegSelTool.h index 4a7f728bb96..c34d06220cf 100644 --- a/DetectorDescription/RegionSelector/src/RegSelTool.h +++ b/DetectorDescription/RegionSelector/src/RegSelTool.h @@ -7,7 +7,7 @@ /// /// @author Mark Sutton /// -/// Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +/// Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration /// #ifndef REGIONSELECTOR_REGSELTOOL_H @@ -35,10 +35,9 @@ class RegSelSiLUT; class IInterface; - class RegSelTool : public extends<AthAlgTool, IRegSelTool> { - public: +public: /** @c Standard constructor for tool (obviously). */ @@ -74,9 +73,11 @@ class RegSelTool : public extends<AthAlgTool, IRegSelTool> { protected: // full scan + virtual void HashIDList( std::vector<IdentifierHash>& idlist ) const; // full scan for a specific layer + virtual void HashIDList( long layer, std::vector<IdentifierHash>& idlist ) const; // Methods to obtain the rob id list @@ -90,12 +91,13 @@ protected: // get list of modules void getRoIData( const IRoiDescriptor& roi, std::vector<const RegSelModule*>& modulelist ) const; - //! @method handle, handles the actual lookup table - bool handle(); - //! @method lookup, actually retrieve the lookup table as conditions data - might combine with handle() const RegSelSiLUT* lookup() const; +protected: + + void cleanup( std::vector<IdentifierHash>& idvec ) const; + private: //! Flag to determine whether it has yet been initialised @@ -106,7 +108,15 @@ private: //! Flag to dump loaded table in data file. BooleanProperty m_dumpTable; - SG::ReadCondHandleKey<RegSelLUTCondData> m_tableKey{ this, "RegSelLUT", "RegSelLUTCondData", "Region Selector lookup table" }; + SG::ReadCondHandleKey<RegSelLUTCondData> m_tableKey{ this, "RegSelLUT", "Tool_Not_Initalised", "Region Selector lookup table" }; + + /// flag to avoid the need for a separate rpc lookup table class + /// FixMe: this flag may be replaced by custom derived RegSelTool + /// class for the RPC. The tools are retrieved only via + /// the IRegSelTool interface so this would also be + /// transaprent to the user + + bool m_rpcflag; }; diff --git a/DetectorDescription/RegionSelector/src/components/RegionSelector_entries.cxx b/DetectorDescription/RegionSelector/src/components/RegionSelector_entries.cxx index 60ec7559170..4aa5fb2f1b7 100644 --- a/DetectorDescription/RegionSelector/src/components/RegionSelector_entries.cxx +++ b/DetectorDescription/RegionSelector/src/components/RegionSelector_entries.cxx @@ -1,4 +1,5 @@ #include "../RegSelSvc.h" + #include "../RegSelTool.h" DECLARE_COMPONENT( RegSelSvc ) diff --git a/InnerDetector/InDetDetDescr/InDetRegionSelector/src/SiRegSelCondAlg.cxx b/InnerDetector/InDetDetDescr/InDetRegionSelector/src/SiRegSelCondAlg.cxx index 87fca7134c3..a00d9e024a9 100644 --- a/InnerDetector/InDetDetDescr/InDetRegionSelector/src/SiRegSelCondAlg.cxx +++ b/InnerDetector/InDetDetDescr/InDetRegionSelector/src/SiRegSelCondAlg.cxx @@ -33,7 +33,7 @@ SiRegSelCondAlg::SiRegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocat AthReentrantAlgorithm( name, pSvcLocator ), m_managerName(""), m_printTable(false), - m_sctCablingToolInc("SCT_CablingToolInc") + m_sctCablingTool("SCT_CablingTool") { ATH_MSG_DEBUG( "SiRegSelCondAlg::SiRegSelCondAlg() " << name ); declareProperty( "PrintTable", m_printTable=false ); @@ -46,7 +46,8 @@ SiRegSelCondAlg::SiRegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocat StatusCode SiRegSelCondAlg::initialize() { ATH_MSG_DEBUG("SiRegSelCondAlg::initialize() "); - ATH_CHECK(m_condCablingKey.initialize()); + ATH_CHECK(m_pixCablingKey.initialize()); + ATH_CHECK(m_sctCablingKey.initialize()); ATH_CHECK(m_tableKey.initialize()); ATH_MSG_INFO("SiRegSelCondAlg::initialize() " << m_tableKey ); return StatusCode::SUCCESS; @@ -76,45 +77,39 @@ StatusCode SiRegSelCondAlg::execute(const EventContext& ctx) const ATH_MSG_DEBUG( "Found Manager " << m_managerName ); } - /// Since there are only really ~ 10 lines that would be different between the - /// SCT and pixel versions of this code, we chose to do everything in one class - /// Sadly, the pixel and SCT cabling don't inherit from the same interface - /// so we can't get the cabling using a generic call, and have to have separate - /// code blocks for each - /// As such, we need to set the cabling from inside conditional blocks, so have - /// to create the cabling as pointers so that we can set inside the blocks and - /// subsequently access them outside the blocks - - /// FIXME: since we store the LUT as conditions data, we need an EventIDRange for - /// the WriteCondHandle, but the SCT cabling is not yet conditions data so - /// have to get the pixelCabling for the SCT case also so that the - /// EventIDRange can be extracted - /// Once the SCT cabling is iself conditions data, we will be able to get - /// the corresponding EventIDRange from there + /// Need to get the SCT cabling conditions for the EventIDRange, but + /// still need to use the SCT_CablingTool to get the rob ids std::unique_ptr<SG::ReadCondHandle<PixelCablingCondData> > pixCabling; + std::unique_ptr<SG::ReadCondHandle<SCT_CablingData> > sctCabling; EventIDRange id_range; if (!manager->isPixel()) { // SCT - if (m_sctCablingToolInc.retrieve().isFailure()) { - msg(MSG::ERROR) << "Can't get the SCT_CablingToolInc." << endmsg; + sctCabling = std::make_unique<SG::ReadCondHandle<SCT_CablingData> >( m_sctCablingKey, ctx ); + if( !sctCabling->range( id_range ) ) { + ATH_MSG_ERROR("Failed to retrieve validity range for " << sctCabling->key()); + return StatusCode::FAILURE; + } + + /// keep explicit failure check for enhanced error reporting + if (m_sctCablingTool.retrieve().isFailure()) { + msg(MSG::ERROR) << "Can't get the SCT_CablingTool" << endmsg; return StatusCode::FAILURE; } } - // else { - pixCabling = std::make_unique<SG::ReadCondHandle<PixelCablingCondData> >( m_condCablingKey, ctx ); - + else { // PIXEL + pixCabling = std::make_unique<SG::ReadCondHandle<PixelCablingCondData> >( m_pixCablingKey, ctx ); if( !pixCabling->range( id_range ) ) { ATH_MSG_ERROR("Failed to retrieve validity range for " << pixCabling->key()); return StatusCode::FAILURE; } - // } + } - RegSelSiLUT* rd; + std::unique_ptr<RegSelSiLUT> rd; - if ( manager->isPixel() ) rd = new RegSelSiLUT(RegSelSiLUT::PIXEL); - else rd = new RegSelSiLUT(RegSelSiLUT::SCT); + if ( manager->isPixel() ) rd = std::make_unique<RegSelSiLUT>(RegSelSiLUT::PIXEL); + else rd = std::make_unique<RegSelSiLUT>(RegSelSiLUT::SCT); InDetDD::SiDetectorElementCollection::const_iterator iter = manager->getDetectorElementBegin(); @@ -163,7 +158,7 @@ StatusCode SiRegSelCondAlg::execute(const EventContext& ctx) const if ( sctId!=0 ) { barrelEC = sctId->barrel_ec(element->identify()); layerDisk = sctId->layer_disk(element->identify()); - robId=m_sctCablingToolInc->getRobIdFromOfflineId(element->identify()); + robId=m_sctCablingTool->getRobIdFromOfflineId(element->identify()); } else { ATH_MSG_ERROR("Could not get SCT_ID for " << element->getIdHelper() ); @@ -195,12 +190,9 @@ StatusCode SiRegSelCondAlg::execute(const EventContext& ctx) const rd->initialise(); // write out new new LUT to a file if need be - if ( m_printTable ) { - if ( manager->isPixel() ) rd->write("RegSelLUT_Pixel"); - else rd->write("RegSelLUT_SCT"); - } + if ( m_printTable ) rd->write( name()+".map" ); - RegSelLUTCondData* rcd = new RegSelLUTCondData( *rd ); + RegSelLUTCondData* rcd = new RegSelLUTCondData( std::move(rd) ); try { SG::WriteCondHandle<RegSelLUTCondData> lutCondData( m_tableKey, ctx ); diff --git a/InnerDetector/InDetDetDescr/InDetRegionSelector/src/SiRegSelCondAlg.h b/InnerDetector/InDetDetDescr/InDetRegionSelector/src/SiRegSelCondAlg.h index fc433a9e809..1998a05d65f 100755 --- a/InnerDetector/InDetDetDescr/InDetRegionSelector/src/SiRegSelCondAlg.h +++ b/InnerDetector/InDetDetDescr/InDetRegionSelector/src/SiRegSelCondAlg.h @@ -21,6 +21,7 @@ #include "PixelConditionsData/PixelCablingCondData.h" +#include "SCT_Cabling/SCT_CablingData.h" #include "StoreGate/ReadCondHandleKey.h" #include "StoreGate/WriteCondHandleKey.h" @@ -49,11 +50,16 @@ public: /// Sadly the PIxel and SCT cabling are different classes so need both, /// even if only one is to be used - ToolHandle<ISCT_CablingTool> m_sctCablingToolInc; // This class accesses SCT cabling during initialization. + ToolHandle<ISCT_CablingTool> m_sctCablingTool; // This class accesses SCT cabling during table creation - SG::ReadCondHandleKey<PixelCablingCondData> m_condCablingKey + SG::ReadCondHandleKey<SCT_CablingData> m_sctCablingKey + {this, "SCT_CablingData", "SCT_CablingData", "SCT cabling key"}; + + SG::ReadCondHandleKey<PixelCablingCondData> m_pixCablingKey {this, "PixelCablingCondData", "PixelCablingCondData", "Pixel cabling key"}; + + /// Output conditions object SG::WriteCondHandleKey<RegSelLUTCondData> m_tableKey { this, "RegSelLUT", "RegSelLUTCondData", "Region Selector lookup table" }; diff --git a/InnerDetector/InDetDetDescr/InDetRegionSelector/src/TRT_RegSelCondAlg.cxx b/InnerDetector/InDetDetDescr/InDetRegionSelector/src/TRT_RegSelCondAlg.cxx index f701c83b95a..fd8f9e758ed 100644 --- a/InnerDetector/InDetDetDescr/InDetRegionSelector/src/TRT_RegSelCondAlg.cxx +++ b/InnerDetector/InDetDetDescr/InDetRegionSelector/src/TRT_RegSelCondAlg.cxx @@ -130,17 +130,15 @@ StatusCode TRT_RegSelCondAlg::execute(const EventContext& ctx) const return StatusCode::FAILURE; } - - //----------------------------------------------------- - unsigned int maxHash = idHelper->straw_layer_hash_max(); - // // Try and iterate over all elements. // There is no iterator but we can get the elements via the idHash. - // - // MS create the new TRT look up table - RegSelSiLUT *rd = new RegSelSiLUT(RegSelSiLUT::TRT); + unsigned int maxHash = idHelper->straw_layer_hash_max(); + + // create the new TRT look up table + + std::unique_ptr<RegSelSiLUT> rd = std::make_unique<RegSelSiLUT>(RegSelSiLUT::TRT); constexpr double twoPi=2.*M_PI; constexpr double InnerRadiusOfStraw = 2.; //hardcoded. No method? (it will NEVER change anyway) @@ -229,9 +227,9 @@ StatusCode TRT_RegSelCondAlg::execute(const EventContext& ctx) const rd->initialise(); // write out new new LUT to a file if need be - if ( m_printTable ) rd->write("RegSelLUT_TRT"); + if ( m_printTable ) rd->write( name()+".map" ); - RegSelLUTCondData* rcd = new RegSelLUTCondData( *rd ); + RegSelLUTCondData* rcd = new RegSelLUTCondData( std::move(rd) ); try { SG::WriteCondHandle<RegSelLUTCondData> lutCondData( m_tableKey, ctx ); diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/CMakeLists.txt b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/CMakeLists.txt index 558400cab47..bbd48c67f07 100644 --- a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/CMakeLists.txt +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/CMakeLists.txt @@ -13,8 +13,9 @@ atlas_depends_on_subdirs( PUBLIC GaudiKernel PRIVATE DetectorDescription/Identifier + DetectorDescription/IRegionSelector + MuonSpectrometer/MuonCablings/MuonCablingData MuonSpectrometer/MuonCablings/CSCcabling - MuonSpectrometer/MuonCablings/MuonMDT_Cabling MuonSpectrometer/MuonCablings/MuonTGC_Cabling MuonSpectrometer/MuonCablings/RPCcablingInterface MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry @@ -31,8 +32,10 @@ atlas_add_component( MuonRegionSelector INCLUDE_DIRS ${CLHEP_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS} LINK_LIBRARIES ${CLHEP_LIBRARIES} ${EIGEN_LIBRARIES} AthenaBaseComps GeoPrimitives RegSelLUT GaudiKernel Identifier CSCcablingLib + MuonCablingData MuonMDT_CablingLib MuonTGC_CablingLib RPCcablingInterfaceLib MuonReadoutGeometry + MuonAGDDDescription ) # Install files from the package: diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/CSC_RegSelCondAlg.cxx b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/CSC_RegSelCondAlg.cxx new file mode 100644 index 00000000000..315462d996d --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/CSC_RegSelCondAlg.cxx @@ -0,0 +1,360 @@ +/** + ** @file CSC_RegSelCondAlg.cxx + ** + ** conditions algorithm to create the Si detector + ** lookup tables + ** + ** @author sutt + ** @date Sun 22 Sep 2019 10:21:50 BST + ** + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + + +#include "GaudiKernel/EventIDRange.h" +#include "StoreGate/WriteCondHandle.h" + +#include "CLHEP/Units/SystemOfUnits.h" +#include "Identifier/IdentifierHash.h" + +#include <iostream> +#include <fstream> +#include <string> +#include <cmath> + +#include "MuonCablingData/MuonMDT_CablingMap.h" +#include "CSCcabling/CSCcablingSvc.h" + +#include "MuonReadoutGeometry/MuonDetectorManager.h" +#include "MuonReadoutGeometry/MuonReadoutElement.h" +#include "MuonReadoutGeometry/MdtReadoutElement.h" +#include "MuonReadoutGeometry/CscReadoutElement.h" +#include "MuonReadoutGeometry/RpcReadoutElement.h" +#include "MuonReadoutGeometry/TgcReadoutElement.h" +#include "MuonReadoutGeometry/RpcReadoutSet.h" +#include "MuonReadoutGeometry/MuonStation.h" + + +#include "CSC_RegSelCondAlg.h" + + +CSC_RegSelCondAlg::CSC_RegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocator): + MuonRegSelCondAlg( name, pSvcLocator ) +{ + ATH_MSG_DEBUG( "CSC_RegSelCondAlg::CSC_RegSelCondAlg() " << name ); +} + + + + + +std::unique_ptr<RegSelSiLUT> CSC_RegSelCondAlg::createTable( const MuonMDT_CablingMap* /* mdtCabling */ ) const { + + /// now get the CSC cabling service ... + + const CSCcablingSvc* cabling = nullptr; + + if ( service( "CSCcablingSvc", cabling ).isFailure() ) { + ATH_MSG_ERROR( "Could not retrieve CSC cabling for " << name() ); + return std::unique_ptr<RegSelSiLUT>(nullptr); + } + + /// get the CSC detector manager + + const MuonGM::MuonDetectorManager* manager = nullptr; + + if ( (detStore()->retrieve( manager ).isFailure() ) ) { + ATH_MSG_ERROR( "Could not retrieve CSC Manager for " << name() ); + return std::unique_ptr<RegSelSiLUT>(nullptr); + } + + const CscIdHelper* helper = manager->cscIdHelper(); + + std::vector<Identifier>::const_iterator idfirst = helper->module_begin(); + std::vector<Identifier>::const_iterator idlast = helper->module_end(); + + const IdContext ModuleContext = helper->module_context(); + + ATH_MSG_DEBUG("createTable()"); + + std::unique_ptr<RegSelSiLUT> lut = std::make_unique<RegSelSiLUT>(); + + + + for ( std::vector<Identifier>::const_iterator itr=idfirst ; itr!=idlast ; itr++ ) { + Identifier Id = *itr; + IdentifierHash Idhash; + + helper->get_hash(Id, Idhash, &ModuleContext); + + ExpandedIdentifier exp_id; + if (helper->get_expanded_id( Id, exp_id, &ModuleContext)) { + ATH_MSG_DEBUG("Failed retrieving ExpandedIdentifier for PRD Identifier = " << Id.getString() << ". Skipping to the next PRD."); + continue; + } + + int detid = ( exp_id[2]<0 ? -1 : 1 ); + int layerid = exp_id[1]+1; + + + // retrieve CscReadoutElement + + Identifier Id2ndLayer; + int chamberLayer = 2; + const MuonGM::CscReadoutElement *csc = manager->getCscReadoutElement(Id); + if (csc == NULL) { + + // std::cout << "Csc Readout Element not found for this Id ---- try 2nd layer"<<std::endl; + Id2ndLayer = helper->parentID(Id); + Id2ndLayer = helper->channelID(Id2ndLayer, chamberLayer, 1, 0, 1); + csc = manager->getCscReadoutElement(Id2ndLayer); + if (csc == NULL) + { + // std::cout << "Csc Readout Element not found for 2nd layer too ---- skip"<<std::endl; + continue; + } + } + + double eta_min = 99999999.; + double eta_max = -99999999.; + double phi_min = 999999.; + double phi_max = -999999.; + + double zmin = 999999999; + double zmax = -999999999; + + double rmin = 0; + double rmax = 0; + + double phi_test = 0.; + Identifier Id_phi_max; + Identifier Id_phi_min; + Identifier Id_eta_max; + Identifier Id_eta_min; + + // only use the extreme chamber layers and wirelayers + + int chlayer_inc = helper->chamberLayerMax(Id)-1; + if ( chlayer_inc<1 ) chlayer_inc = 1; + for ( int chlayer=1 ; chlayer<=helper->chamberLayerMax(Id) ; chlayer+=chlayer_inc ) { + + + int wlayer_inc = helper->wireLayerMax(Id)-1; + if ( wlayer_inc<1 ) wlayer_inc = 1; + for ( int wlayer=1 ; wlayer<=helper->wireLayerMax(Id) ; wlayer+=wlayer_inc ){ + + for ( int phis=1 ; phis<=csc->NphiStrips(wlayer) ; phis++ ) { + + + Identifier phis_id = helper->channelID(Id, chlayer, wlayer, 1, phis); + Amg::Vector3D phis_x = csc->localStripPos(phis_id); + double phis_lenght = csc->stripLength(phis_id); + + // positions of the strip endpoints + + Amg::Vector3D phis_x1 = phis_x; + Amg::Vector3D phis_x2 = phis_x; + + //phis_x1.setZ(phis_x.z()-phis_lenght/2.0); + //phis_x2.setZ(phis_x.z()+phis_lenght/2.0); + phis_x1[2] = phis_x.z()-phis_lenght/2.0; + phis_x2[2] = phis_x.z()+phis_lenght/2.0; + + Amg::Vector3D gphis_x1 = csc->globalPos(phis_x1); + Amg::Vector3D gphis_x2 = csc->globalPos(phis_x2); + + phi_test=gphis_x1.phi(); + // for detector in (-0.25,0.25) phi interval use +-3,14 phi interval + // if(!(aux1==51 && aux3==1))if (phi_test < 0) phi_test += 2.*M_PI; + if(!(exp_id[1]==51 && exp_id[3]==1))if (phi_test < 0) phi_test += 2.*M_PI; + + + if ( zmin>gphis_x1.z() ) zmin = gphis_x1.z(); + if ( zmax<gphis_x1.z() ) zmax = gphis_x1.z(); + + if ( rmin==0 || rmin>gphis_x1.perp() ) rmin = gphis_x1.perp(); + if ( rmax==0 || rmax<gphis_x1.perp() ) rmax = gphis_x1.perp(); + + if ( zmin>gphis_x2.z() ) zmin = gphis_x2.z(); + if ( zmax<gphis_x2.z() ) zmax = gphis_x2.z(); + + if ( rmin==0 || rmin>gphis_x2.perp() ) rmin = gphis_x2.perp(); + if ( rmax==0 || rmax<gphis_x2.perp() ) rmax = gphis_x2.perp(); + + // position of the strip centre + + + Amg::Vector3D gphis_x = csc->globalPos(phis_x); + + if ( rmin==0 || rmin>gphis_x.perp() ) rmin = gphis_x.perp(); + if ( rmax==0 || rmax<gphis_x.perp() ) rmax = gphis_x.perp(); + + // phi + if(phi_test > phi_max){ + Id_phi_max=phis_id; + phi_max=phi_test; + } + if(phi_test < phi_min){ + Id_phi_min=phis_id; + phi_min=phi_test; + } + // eta + if(gphis_x1.eta() > eta_max) { + Id_eta_max=phis_id; + eta_max=gphis_x1.eta(); + } + if(gphis_x1.eta() < eta_min) { + Id_eta_min=phis_id; + eta_min=gphis_x1.eta(); + } + + phi_test=gphis_x2.phi(); + // for detector in (-0.25,0.25) phi interval use +-3,14 phi interval + // if(!(aux1==51 && aux3==1)) if (phi_test < 0) phi_test += 2.*M_PI; + if(!(exp_id[1]==51 && exp_id[3]==1)) if (phi_test < 0) phi_test += 2.*M_PI; + + // phi + if(phi_test > phi_max) { + Id_phi_max=phis_id; + phi_max=phi_test; + } + if(phi_test < phi_min) { + Id_phi_min=phis_id; + phi_min=phi_test; + } + // eta + if(gphis_x2.eta() > eta_max) { + Id_eta_max=phis_id; + eta_max=gphis_x2.eta(); + } + if(gphis_x2.eta() < eta_min) { + Id_eta_min=phis_id; + eta_min=gphis_x2.eta(); + } + + } + + // only use the extreme and middle strips + + int eta_inc = csc->NetaStrips(wlayer)/2; + if ( eta_inc<1 ) eta_inc = 1; + for ( int etas=1 ; etas<=csc->NetaStrips(wlayer) ; etas+=eta_inc ) { + + + Identifier etas_id = helper->channelID(Id, chlayer, wlayer, 0, etas); + Amg::Vector3D etas_x = csc->localStripPos(etas_id); + double etas_lenght = csc->stripLength(etas_id); + + // strip endpoints + + Amg::Vector3D etas_x1 = etas_x; + Amg::Vector3D etas_x2 = etas_x; + + //etas_x1.setY(etas_x.y()-etas_lenght/2.0); + //etas_x2.setY(etas_x.y()+etas_lenght/2.0); + etas_x1[1] = etas_x.y()-etas_lenght/2.0; + etas_x2[1] = etas_x.y()+etas_lenght/2.0; + + Amg::Vector3D getas_x1 = csc->globalPos(etas_x1); + Amg::Vector3D getas_x2 = csc->globalPos(etas_x2); + + if ( zmin>getas_x1.z() ) zmin = getas_x1.z(); + if ( zmax<getas_x1.z() ) zmax = getas_x1.z(); + + if ( zmin>getas_x2.z() ) zmin = getas_x2.z(); + if ( zmax<getas_x2.z() ) zmax = getas_x2.z(); + + if ( rmin==0 || rmin>getas_x1.perp() ) rmin = getas_x1.perp(); + if ( rmax==0 || rmax<getas_x1.perp() ) rmax = getas_x1.perp(); + + if ( rmin==0 || rmin>getas_x2.perp() ) rmin = getas_x2.perp(); + if ( rmax==0 || rmax<getas_x2.perp() ) rmax = getas_x2.perp(); + + // position of the strip centre + + Amg::Vector3D getas_x = csc->globalPos(etas_x); + + if ( rmin==0 || rmin>getas_x.perp() ) rmin = getas_x.perp(); + if ( rmax==0 || rmax<getas_x.perp() ) rmax = getas_x.perp(); + + phi_test = getas_x1.phi(); + // for detector in (-0.25,0.25) phi interval use +-3,14 phi interval + // if(!(aux1==51 && aux3==1)) if (phi_test < 0) phi_test += 2.*M_PI; + if(!(exp_id[1]==51 && exp_id[3]==1)) if (phi_test < 0) phi_test += 2.*M_PI; + // phi + if(phi_test > phi_max){ + Id_phi_max=etas_id; + phi_max=phi_test; + } + if(phi_test < phi_min){ + Id_phi_min=etas_id; + phi_min=phi_test; + } + // eta + if(getas_x1.eta() > eta_max) { + Id_eta_max=etas_id; + eta_max=getas_x1.eta(); + } + if(getas_x1.eta() < eta_min) { + Id_eta_min=etas_id; + eta_min=getas_x1.eta(); + } + + phi_test = getas_x2.phi(); + // for detector in (-0.25,0.25) phi interval use +-3,14 phi interval + // if (!(aux1==51 && aux3==1)) if (phi_test < 0) phi_test += 2.*M_PI; + if (!(exp_id[1]==51 && exp_id[3]==1)) if (phi_test < 0) phi_test += 2.*M_PI; + // phi + if(phi_test > phi_max){ + Id_phi_max=etas_id; + phi_max=phi_test; + } + if(phi_test < phi_min){ + Id_phi_min=etas_id; + phi_min=phi_test; + } + // eta + if(getas_x2.eta() > eta_max) { + Id_eta_max=etas_id; + eta_max=getas_x2.eta(); + } + if(getas_x2.eta() < eta_min) { + Id_eta_min=etas_id; + eta_min=getas_x2.eta(); + } + + } + } //gas gaps + } // chamber layers + + // if(aux1==51 && aux3==1)if (phi_min < 0) phi_min += 2.*M_PI; + // if(aux1==51 && aux3==1)if (phi_max < 0) phi_max += 2.*M_PI; + if(exp_id[1]==51 && exp_id[3]==1) { + if (phi_max < 0) phi_max += 2.*M_PI; + if (phi_min < 0) phi_min += 2.*M_PI; + } + + uint16_t subDetectorId = (detid == -1) ? 0x6a : 0x69; + uint32_t cscrob = 0x0; + cabling->hash2Rob(Idhash.value(),cscrob); + cscrob = ((subDetectorId << 16) | cscrob); + RegSelModule m( zmin, zmax, rmin, rmax, phi_min, phi_max, layerid, detid, cscrob, Idhash ); + lut->addModule( m ); + + + } // modules + + + lut->initialise(); + + return lut; + +} + + + + + + + diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/CSC_RegSelCondAlg.h b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/CSC_RegSelCondAlg.h new file mode 100755 index 00000000000..fa51fe5f81d --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/CSC_RegSelCondAlg.h @@ -0,0 +1,28 @@ +/** emacs: this is -*- c++ -*- **/ +/** + ** @file CSC_RegSelCondAlg.h + ** + ** @author sutt + ** @date Tue 4 Feb 2020 15:25:00 CET + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + +#ifndef CSC_RegSelCondAlg_h +#define CSC_RegSelCondAlg_h + + +#include "MuonRegSelCondAlg.h" + + +class CSC_RegSelCondAlg : public MuonRegSelCondAlg { + +public: + + CSC_RegSelCondAlg( const std::string& name, ISvcLocator* pSvcLocator ); + + std::unique_ptr<RegSelSiLUT> createTable( const MuonMDT_CablingMap* mdtCabling ) const; + +}; + +#endif // CSC_RegSelCondAlg_h diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MDT_RegSelCondAlg.cxx b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MDT_RegSelCondAlg.cxx new file mode 100644 index 00000000000..93d4e4ebd2f --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MDT_RegSelCondAlg.cxx @@ -0,0 +1,361 @@ +/** + ** @file MDT_RegSelCondAlg.cxx + ** + ** conditions algorithm to create the Si detector + ** lookup tables + ** + ** @author sutt + ** @date Sun 22 Sep 2019 10:21:50 BST + ** + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + +#include "MDT_RegSelCondAlg.h" + +#include "CLHEP/Units/SystemOfUnits.h" +#include "Identifier/IdentifierHash.h" + +#include <iostream> +#include <fstream> +#include <string> + +#include "MuonReadoutGeometry/MuonDetectorManager.h" +#include "MuonReadoutGeometry/MuonReadoutElement.h" +#include "MuonReadoutGeometry/MdtReadoutElement.h" +#include "MuonReadoutGeometry/CscReadoutElement.h" +#include "MuonReadoutGeometry/RpcReadoutElement.h" +#include "MuonReadoutGeometry/TgcReadoutElement.h" +#include "MuonReadoutGeometry/RpcReadoutSet.h" +#include "MuonReadoutGeometry/MuonStation.h" + + + +MDT_RegSelCondAlg::MDT_RegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocator): + MuonRegSelCondAlg( name, pSvcLocator ) +{ + ATH_MSG_DEBUG( "MDT_RegSelCondAlg::MDT_RegSelCondAlg() " << name ); +} + + + +std::unique_ptr<RegSelSiLUT> MDT_RegSelCondAlg::createTable( const MuonMDT_CablingMap* cabling ) const { + + const MuonGM::MuonDetectorManager* manager = nullptr; // again 0 would do as well here + + StatusCode sc = detStore()->retrieve( manager ); + + /// can't use ATH_CHECK here as we can;'t return the StatusCode + if ( sc.isFailure() ) { + ATH_MSG_ERROR( "Could not retrieve MDT Manager for " << name() ); + return std::unique_ptr<RegSelSiLUT>(nullptr); + } + + const MdtIdHelper* helper = manager->mdtIdHelper(); + + /// ne wlookup table + std::unique_ptr<RegSelSiLUT> lut = std::make_unique<RegSelSiLUT>(); + + + IdContext ModuleContext = helper->module_context(); + + std::vector<Identifier>::const_iterator itr = helper->module_begin(); + std::vector<Identifier>::const_iterator idlast = helper->module_end(); + + for ( ; itr!=idlast; itr++ ) { + + Identifier Id = *itr; + IdentifierHash Idhash; + + helper->get_hash(Id, Idhash, &ModuleContext); + + ExpandedIdentifier exp_id; + if (helper->get_expanded_id( Id, exp_id, &ModuleContext)) { + ATH_MSG_DEBUG("Failed retrieving ExpandedIdentifier for PRD Identifier = " << Id.getString() << ". Skipping to the next PRD."); + continue; + } + + int detid = ( exp_id[2]<0 ? -1 : 1 ); + int layerid = exp_id[1]+1; + + IdContext mdtChannelContext = helper->channel_context(); + + // get the element corresponding to multilayer = 1 + const MuonGM::MdtReadoutElement* mdt1 = manager->getMdtReadoutElement(Id); + if (mdt1 == NULL) { + continue; + } + + Identifier Id2 = helper->channelID(Id, 2, 1, 1); + + // get the element corresponding to multilayer = 2 + const MuonGM::MdtReadoutElement* mdt2 = manager->getMdtReadoutElement(Id2); + + double tubePitch = mdt1->tubePitch(); + + int ntlay = mdt1->getNLayers(); + int ntubesl1 = mdt1->getNtubesperlayer(); + int ntubesl2 = 0; + + if (mdt2 != NULL) ntubesl2 = mdt2->getNtubesperlayer(); + + Identifier Idv[4]; + Idv[0] = helper->channelID(Id, 1, 1, 1); + Idv[1] = helper->channelID(Id, 1, 1, ntubesl1); + Idv[2] = helper->channelID(Id, 2, ntlay, 1); + Idv[3] = helper->channelID(Id, 2, ntlay, ntubesl2); + + // std::cout<<" Number of tube layers "<<ntlay; + // std::cout<<" Number of tubes / layer (1 ,2) "<<ntubesl1<<", "<<ntubesl2; + + double rmin = 99999999.; + double rmax = -99999999.; + double zmin = 99999999.; + double zmax = -99999999.; + double emin = 99999999.; + double emax = -99999999.; + double phimin = 999999.; + double phimax = -999999.; + + double zpos21 = 0.; + Identifier Idsl = helper->channelID(Id, 1, 2, 1); + if (mdt1->barrel()) { + zpos21 = (mdt1->tubePos(Idsl)).z()-(mdt1->tubePos(Idv[0])).z(); + } + else { + zpos21 = (mdt1->tubePos(Idsl)).perp()-(mdt1->tubePos(Idv[0])).perp(); + } + + /// what is this loop over? This is awful code, this i parameter hides + /// the "i" from loop over the iterators, or it did until I changed it + // to a more sensibly named "itr" + for (int i=0; i<4; i++) { + + const MuonGM::MdtReadoutElement* mdt = NULL; + + if ( i<2 ) mdt = mdt1; + else mdt = mdt2; + if (mdt == NULL) { + // std::cout<<" element not found for index i = "<<i<<" --------- "<<std::endl; + if (i==2) { + Idv[2] = helper->channelID(Id, 1, ntlay, 1); + mdt = manager->getMdtReadoutElement(Idv[2]); + } + else if (i==3) { + Idv[3] = helper->channelID(Id, 1, ntlay, ntubesl1); + mdt = manager->getMdtReadoutElement(Idv[3]); + } + else { + // std::cout<<" Skipping element; i = "<<i<<" ----- "<<std::endl; + continue; + } + + } + + Amg::Vector3D mdtPos = mdt->tubePos(Idv[i]); + + Amg::Vector3D mdtPos1 = mdtPos; + Amg::Vector3D mdtPos2 = mdtPos; + + double scaleMin = (mdtPos.perp()-tubePitch/2.)/mdtPos.perp(); + double scalePlus = (mdtPos.perp()+tubePitch/2.)/mdtPos.perp(); + + if (mdt->barrel()) { + + // these are z ranges of the first or last tube layer + // mdtPos1.setZ(mdtPos.z()-tubePitch/2.); + // mdtPos2.setZ(mdtPos.z()+tubePitch/2.); + mdtPos1[2] = mdtPos.z()-tubePitch/2.; + mdtPos2[2] = mdtPos.z()+tubePitch/2.; + + // correct the z ranges of the first or last tube layer to account for tube staggering + if (zpos21 > 1.) { + // mdtPos2.setZ(mdtPos2.z()+tubePitch/2.); + mdtPos2[2] = mdtPos2.z()+tubePitch/2.; + } + else if (zpos21 < -1.) { + //mdtPos1.setZ(mdtPos1.z()-tubePitch/2.); + mdtPos1[2] = mdtPos1.z()-tubePitch/2.; + } + + if (i<2) { + mdtPos1[0] *= scaleMin; + mdtPos1[1] *= scaleMin; + mdtPos2[0] *= scaleMin; + mdtPos2[1] *= scaleMin; + // mdtPos1.setPerp(mdtPos.perp()-tubePitch/2.); + // mdtPos2.setPerp(mdtPos.perp()-tubePitch/2.); + } + else { + mdtPos1[0] *= scalePlus; + mdtPos1[1] *= scalePlus; + mdtPos2[0] *= scalePlus; + mdtPos2[1] *= scalePlus; + // mdtPos1.setPerp(mdtPos.perp()+tubePitch/2.); + // mdtPos2.setPerp(mdtPos.perp()+tubePitch/2.); + } + } + else { + + // these are z ranges of the first or last tube layer + mdtPos1[0] *= scaleMin; + mdtPos1[1] *= scaleMin; + mdtPos2[0] *= scalePlus; + mdtPos2[1] *= scalePlus; + // mdtPos1.setPerp(mdtPos.perp()-tubePitch/2.); + // mdtPos2.setPerp(mdtPos.perp()+tubePitch/2.); + // correct the z ranges of the first or last tube layer to account for tube staggering + if (zpos21 > 1.) { + scalePlus = (mdtPos2.perp()+tubePitch/2.)/mdtPos2.perp(); + mdtPos2[0] *= scalePlus; + mdtPos2[1] *= scalePlus; + // mdtPos2.setPerp(mdtPos2.perp()+tubePitch/2.); + } + else if (zpos21 < -1.) { + scaleMin = (mdtPos1.perp()-tubePitch/2.)/mdtPos1.perp(); + mdtPos1[0] *= scaleMin; + mdtPos1[1] *= scaleMin; + // mdtPos1.setPerp(mdtPos1.perp()-tubePitch/2.); + } + if (i<2) { + if (mdt->sideA()){ + // mdtPos1.setZ(mdtPos.z()-tubePitch/2.); + // mdtPos2.setZ(mdtPos.z()-tubePitch/2.); + mdtPos1[2] = mdtPos.z()-tubePitch/2.; + mdtPos2[2] = mdtPos.z()-tubePitch/2.; + } + else { + // mdtPos1.setZ(mdtPos.z()+tubePitch/2.); + // mdtPos2.setZ(mdtPos.z()+tubePitch/2.); + mdtPos1[2] = mdtPos.z()+tubePitch/2.; + mdtPos2[2] = mdtPos.z()+tubePitch/2.; + } + } + else { + if (mdt->sideA()) { + // mdtPos1.setZ(mdtPos.z()+tubePitch/2.); + // mdtPos2.setZ(mdtPos.z()+tubePitch/2.); + mdtPos1[2] = mdtPos.z()+tubePitch/2.; + mdtPos2[2] = mdtPos.z()+tubePitch/2.; + } + else { + // mdtPos1.setZ(mdtPos.z()-tubePitch/2.); + // mdtPos2.setZ(mdtPos.z()-tubePitch/2.); + mdtPos1[2] = mdtPos.z()-tubePitch/2.; + mdtPos2[2] = mdtPos.z()-tubePitch/2.; + } + } + } + + double eminMod = 0.; + double emaxMod = 0.; + double zminMod = 0.; + double zmaxMod = 0.; + double rminMod = 0.; + double rmaxMod = 0.; + double dphi = 0.; + + if (mdt->barrel()) { + eminMod = mdtPos1.eta(); + emaxMod = mdtPos2.eta(); + + zminMod = mdtPos1.z(); + zmaxMod = mdtPos2.z(); + + rminMod = mdtPos1.perp(); + rmaxMod = mdtPos2.perp(); + + dphi = atan2(mdt->getSsize()/2., (mdtPos.perp()-tubePitch/2.)); + } + else { + if (mdt->sideA()) { + eminMod = mdtPos2.eta(); + emaxMod = mdtPos1.eta(); + + zminMod = mdtPos2.z(); + zmaxMod = mdtPos1.z(); + + rminMod = mdtPos1.perp(); + rmaxMod = mdtPos2.perp(); + } + else { + eminMod = mdtPos1.eta(); + emaxMod = mdtPos2.eta(); + + zminMod = mdtPos1.z(); + zmaxMod = mdtPos2.z(); + + rminMod = mdtPos1.perp(); + rmaxMod = mdtPos2.perp(); + } + + dphi = atan2(mdt->tubeLength(Idv[i])/2., (mdtPos.perp()-tubePitch/2.)); + } + + double pminMod = mdtPos.phi() - dphi; + double pmaxMod = mdtPos.phi() + dphi; + + if (zminMod < zmin) { + zmin = zminMod; + } + + if (zmaxMod > zmax) { + zmax = zmaxMod; + } + + if (pminMod < phimin) phimin = pminMod; + if (pmaxMod > phimax) phimax = pmaxMod; + if (eminMod < emin) emin = eminMod; + if (emaxMod > emax) emax = emaxMod; + if (rminMod < rmin) rmin = rminMod; + if (rmaxMod > rmax) rmax = rmaxMod; + // std::cout<<" Module emin - emax "<<emin<<" "<<emax<<" phimin - phimax "<<phimin<<" "<<phimax<<std::endl; + + } + + // here define the eta and phi(0-2*pi) ranges + if (phimin<0) phimin = phimin + 2*M_PI; + if (phimax<0) phimax = phimax + 2*M_PI; + + // calculate 4 sub detectors for the mdt, fore and aft barrel, + // and fore and aft endcaps + + if ( mdt1->barrel() ) { + if ( mdt1->sideA() ) detid = 1; + else if ( mdt1->sideC() ) detid = -1; + } + else { + if ( mdt1->sideA() ) detid = 2; + else if ( mdt1->sideC() ) detid = -2; + } + + + // std::cout << "detid " << detid; + + // if ( mdt1->barrel() ) detid = 0; + // if ( mdt1->sideA() ) detid = 1; + // if ( mdt1->sideC() ) detid = -1; + + // std::cout << " -> " << detid << std::endl; + + uint32_t RobId = cabling->getROBId(Idhash); + + RegSelModule m( zmin, zmax, rmin, rmax, phimin, phimax, layerid, detid, RobId, Idhash ); + + lut->addModule( m ); + + } + + + lut->initialise(); + + return lut; + +} + + + + + + + diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MDT_RegSelCondAlg.h b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MDT_RegSelCondAlg.h new file mode 100755 index 00000000000..1de2560110d --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MDT_RegSelCondAlg.h @@ -0,0 +1,27 @@ +/** emacs: this is -*- c++ -*- **/ +/** + ** @file MDT_RegSelCondAlg.h + ** + ** @author sutt + ** @date Tue 4 Feb 2020 15:25:00 CET + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + +#ifndef MDT_RegSelCondAlg_h +#define MDT_RegSelCondAlg_h + +#include "MuonRegSelCondAlg.h" + + +class MDT_RegSelCondAlg : public MuonRegSelCondAlg { + +public: + + MDT_RegSelCondAlg( const std::string& name, ISvcLocator* pSvcLocator ); + + std::unique_ptr<RegSelSiLUT> createTable( const MuonMDT_CablingMap* cabling ) const override; + +}; + +#endif // MDT_RegSelCondAlg_h diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MM_RegSelCondAlg.cxx b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MM_RegSelCondAlg.cxx new file mode 100644 index 00000000000..686fdc8981f --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MM_RegSelCondAlg.cxx @@ -0,0 +1,156 @@ +/** + ** @file MM_RegSelCondAlg.cxx + ** + ** conditions algorithm to create the Si detector + ** lookup tables + ** + ** @author sutt + ** @date Sun 22 Sep 2019 10:21:50 BST + ** + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + +#include "GaudiKernel/EventIDRange.h" +#include "StoreGate/WriteCondHandle.h" + +#include "CLHEP/Units/SystemOfUnits.h" +#include "Identifier/IdentifierHash.h" + +#include <iostream> +#include <fstream> +#include <string> +#include <cmath> + +#include "MuonCablingData/MuonMDT_CablingMap.h" + +#include "MuonReadoutGeometry/MuonDetectorManager.h" +#include "MuonReadoutGeometry/MuonReadoutElement.h" + +#include "MuonReadoutGeometry/MMReadoutElement.h" +#include "MuonAGDDDescription/MMDetectorHelper.h" +#include "MuonAGDDDescription/MMDetectorDescription.h" + +#include "MuonReadoutGeometry/MuonStation.h" + +#include "RegSelLUT/RegSelSiLUT.h" + +/// not implemented yet +/// #include "MuonMM_Cabling/MuonMM_CablingSvc.h" + + +#include "MM_RegSelCondAlg.h" + + +MM_RegSelCondAlg::MM_RegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocator): + MuonRegSelCondAlg( name, pSvcLocator ) +{ + ATH_MSG_DEBUG( "MM_RegSelCondAlg::MM_RegSelCondAlg() " << name ); +} + + + + + +std::unique_ptr<RegSelSiLUT> MM_RegSelCondAlg::createTable( const MuonMDT_CablingMap* /* mdtCabling */ ) const { + + /// no NSW cabling available at the moment ... + + /// get the MM detector manager + + const MuonGM::MuonDetectorManager* manager = nullptr; + + if ( (detStore()->retrieve( manager ).isFailure() ) ) { + ATH_MSG_ERROR( "Could not retrieve CSC Manager for " << name() ); + return std::unique_ptr<RegSelSiLUT>(nullptr); + } + + const MmIdHelper* helper = manager->mmIdHelper(); + + + std::vector<Identifier>::const_iterator idfirst = helper->module_begin(); + std::vector<Identifier>::const_iterator idlast = helper->module_end(); + + /// do we want the module context ... + /// const IdContext ModuleContext = helper->module_context(); + + /// or the detector element context ? Keep them both untill we are sure + const IdContext ModuleContext = helper->detectorElement_context(); + + ATH_MSG_DEBUG("createTable()"); + + std::unique_ptr<RegSelSiLUT> lut = std::make_unique<RegSelSiLUT>(); + + + for ( std::vector<Identifier>::const_iterator i=idfirst ; i!=idlast ; i++ ) { + + Identifier Id = *i; + IdentifierHash hashId; + + helper->get_hash( Id, hashId, &ModuleContext ); + + const MuonGM::MMReadoutElement* mm = manager->getMMReadoutElement(Id); + if (!mm) continue; + + int multilayer = helper->multilayer(Id); + + char side = mm->getStationEta() < 0 ? 'C' : 'A'; + + char sector_l = mm->getStationName().substr(2,1)=="L" ? 'L' : 'S'; + + MMDetectorHelper aHelper; + MMDetectorDescription* md = aHelper.Get_MMDetector( sector_l, std::abs(mm->getStationEta()), mm->getStationPhi(), multilayer, side ); + + /// now calculate the required limits + + Amg::Vector3D mmPos = mm->center(); + + + double swidth = md->sWidth(); + double lwidth = md->lWidth(); + + double length = md->Length(); + double depth = md->Tck(); + + double moduleR = std::sqrt( mmPos.mag()*mmPos.mag() - mmPos.z()*mmPos.z()); + + double zmin = mmPos.z()-0.5*depth; + double zmax = mmPos.z()+0.5*depth; + + // std::cout << "MM:module: rcen: " << moduleR << "\tlength: " << length << "\tswidth: " << swidth << "\tlwidth: " << lwidth << std::endl; + + double rmin = moduleR-0.5*length; + double rmax = std::sqrt( (moduleR+0.5*length)*(moduleR+0.5*length) + 0.25*lwidth*lwidth ); + + double dphi1 = std::atan( (0.5*lwidth)/(moduleR+0.5*length) ); + double dphi2 = std::atan( (0.5*swidth)/(moduleR-0.5*length) ); + + double dphi = ( dphi1 > dphi2 ? dphi1 : dphi2 ); + + double phimin = mmPos.phi()-dphi; + double phimax = mmPos.phi()+dphi; + + if ( phimin > M_PI ) phimin -= 2*M_PI; + if ( phimin < -M_PI ) phimin += 2*M_PI; + + if ( phimax > M_PI ) phimax -= 2*M_PI; + if ( phimax < -M_PI ) phimax += 2*M_PI; + + int layerid = multilayer; + int detid = ( side == 'C' ? -1 : 1 ); + + /// no cabling map at the moment - don't store robID + int robId = 0; + + RegSelModule m( zmin, zmax, rmin, rmax, phimin, phimax, int(layerid), int(detid), uint32_t(robId), hashId ); + + lut->addModule( m ); + + } + + lut->initialise(); + + return lut; + +} + diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MM_RegSelCondAlg.h b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MM_RegSelCondAlg.h new file mode 100755 index 00000000000..f21403219f3 --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MM_RegSelCondAlg.h @@ -0,0 +1,28 @@ +/** emacs: this is -*- c++ -*- **/ +/** + ** @file MM_RegSelCondAlg.h + ** + ** @author sutt + ** @date Tue 4 Feb 2020 15:25:00 CET + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + +#ifndef MM_RegSelCondAlg_h +#define MM_RegSelCondAlg_h + + +#include "MuonRegSelCondAlg.h" + + +class MM_RegSelCondAlg : public MuonRegSelCondAlg { + +public: + + MM_RegSelCondAlg( const std::string& name, ISvcLocator* pSvcLocator ); + + std::unique_ptr<RegSelSiLUT> createTable( const MuonMDT_CablingMap* mdtCabling ) const; + +}; + +#endif // CSC_RegSelCondAlg_h diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MuonRegSelCondAlg.cxx b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MuonRegSelCondAlg.cxx new file mode 100644 index 00000000000..093503e8e68 --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MuonRegSelCondAlg.cxx @@ -0,0 +1,109 @@ +/** + ** @file MuonRegSelCondAlg.cxx + ** + ** conditions algorithm to create the Si detector + ** lookup tables + ** + ** @author sutt + ** @date Sun 22 Sep 2019 10:21:50 BST + ** + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + + +#include "GaudiKernel/EventIDRange.h" +#include "StoreGate/WriteCondHandle.h" + +#include <iostream> +#include <fstream> +#include <string> + + +#include "MuonCablingData/MuonMDT_CablingMap.h" + +#include "MDT_RegSelCondAlg.h" + + + +MuonRegSelCondAlg::MuonRegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocator): + AthReentrantAlgorithm( name, pSvcLocator ), + m_managerName(""), + m_printTable(false) +{ + ATH_MSG_DEBUG( "MuonRegSelCondAlg::MuonRegSelCondAlg() " << name ); + declareProperty( "PrintTable", m_printTable=false ); + declareProperty( "ManagerName", m_managerName ); +} + + + + +StatusCode MuonRegSelCondAlg::initialize() +{ + ATH_MSG_DEBUG("MuonRegSelCondAlg::initialize() "); + ATH_CHECK(m_cablingKey.initialize()); + ATH_CHECK(m_tableKey.initialize()); + ATH_MSG_INFO("MuonRegSelCondAlg::initialize() " << m_tableKey ); + return StatusCode::SUCCESS; +} + + + +StatusCode MuonRegSelCondAlg::execute(const EventContext& ctx) const +{ + ATH_MSG_DEBUG("MuonRegSelCondAlg::execute() -- enter -- "); + + /// do stuff here ... + ATH_MSG_DEBUG( "Creating region selector table " << m_tableKey ); + + + SG::ReadCondHandle<MuonMDT_CablingMap> cabling( m_cablingKey, ctx ); + + EventIDRange id_range; + + if( !cabling.range( id_range ) ) { + ATH_MSG_ERROR("Failed to retrieve validity range for " << cabling.key()); + return StatusCode::FAILURE; + } + + /// create the new lookuo table + + std::unique_ptr<RegSelSiLUT> rd = createTable( *cabling ); + + if ( !rd ) return StatusCode::FAILURE; + + ATH_MSG_DEBUG( "Initialising new map " );; + + // write out new new LUT to a file if need be + + if ( m_printTable ) rd->write( name()+".map" ); + + /// create the conditions data for storage + + RegSelLUTCondData* rcd = new RegSelLUTCondData( std::move(rd) ); + + try { + SG::WriteCondHandle<RegSelLUTCondData> lutCondData( m_tableKey, ctx ); + if( lutCondData.record( id_range, rcd ).isFailure() ) { + ATH_MSG_ERROR( "Could not record " << m_tableKey + << " " << lutCondData.key() + << " with range " << id_range ); + return StatusCode::FAILURE; + } + ATH_MSG_INFO( "RegSelCondAlg LUT recorded: " << m_tableKey); + } + catch (...) { + ATH_MSG_ERROR("MuonRegSelCondAlg::execute() failed to record table: " << m_tableKey); + return StatusCode::FAILURE; + } + + + ATH_MSG_DEBUG("MuonRegSelCondAlg::execute() -- exit -- "); + + return StatusCode::SUCCESS; +} + + + + diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MuonRegSelCondAlg.h b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MuonRegSelCondAlg.h new file mode 100755 index 00000000000..bcccb38e924 --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/MuonRegSelCondAlg.h @@ -0,0 +1,60 @@ +/** emacs: this is -*- c++ -*- **/ +/** + ** @file MuonRegSelCondAlg.h + ** + ** @author sutt + ** @date Tue 4 Feb 2020 15:25:00 CET + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + +#ifndef MuonRegSelCondAlg_h +#define MuonRegSelCondAlg_h + +#include "GaudiKernel/ISvcLocator.h" + +#include "AthenaBaseComps/AthReentrantAlgorithm.h" +#include "AthenaBaseComps/AthAlgTool.h" + +#include "GaudiKernel/ToolHandle.h" + +#include "MuonCablingData/MuonMDT_CablingMap.h" + +#include "StoreGate/ReadCondHandleKey.h" +#include "StoreGate/WriteCondHandleKey.h" + +#include "IRegionSelector/RegSelLUTCondData.h" + +#include <string> + + +///////////////////////////////////////////////////////////////////////////// + +class MuonRegSelCondAlg : public AthReentrantAlgorithm { + +public: + + MuonRegSelCondAlg( const std::string& name, ISvcLocator* pSvcLocator ); + + virtual StatusCode initialize() override; + virtual StatusCode execute (const EventContext& ctx) const override; + + virtual std::unique_ptr<RegSelSiLUT> createTable( const MuonMDT_CablingMap* cabling ) const = 0; + + private: + + std::string m_managerName; + bool m_printTable; + + SG::ReadCondHandleKey<MuonMDT_CablingMap> m_cablingKey + { this, "Cabling", "MuonMDT_CablingMap", "Key of output MDT cabling map" }; + + /// Output conditions object + SG::WriteCondHandleKey<RegSelLUTCondData> m_tableKey + { this, "RegSelLUT", "RegSelLUTCondData", "Region Selector lookup table" }; + + + +}; + +#endif // MuonRegSelCondAlg_h diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/RPC_RegSelCondAlg.cxx b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/RPC_RegSelCondAlg.cxx new file mode 100644 index 00000000000..34b375b253c --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/RPC_RegSelCondAlg.cxx @@ -0,0 +1,271 @@ +/** + ** @file RPC_RegSelCondAlg.cxx + ** + ** conditions algorithm to create the Si detector + ** lookup tables + ** + ** @author sutt + ** @date Sun 22 Sep 2019 10:21:50 BST + ** + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + + +#include "GaudiKernel/EventIDRange.h" +#include "StoreGate/WriteCondHandle.h" + +#include "CLHEP/Units/SystemOfUnits.h" +#include "Identifier/IdentifierHash.h" + +#include <iostream> +#include <fstream> +#include <string> + + +#include "MuonCablingData/MuonMDT_CablingMap.h" + +#include "MuonReadoutGeometry/MuonDetectorManager.h" +#include "MuonReadoutGeometry/MuonReadoutElement.h" +#include "MuonReadoutGeometry/MdtReadoutElement.h" +#include "MuonReadoutGeometry/CscReadoutElement.h" +#include "MuonReadoutGeometry/RpcReadoutElement.h" +#include "MuonReadoutGeometry/TgcReadoutElement.h" +#include "MuonReadoutGeometry/RpcReadoutSet.h" +#include "MuonReadoutGeometry/MuonStation.h" + +#include "RPC_RegSelCondAlg.h" + +#include "RPCcablingInterface/IRPCcablingServerSvc.h" +#include "RPCcablingInterface/IRPCcablingSvc.h" + + + +RPC_RegSelCondAlg::RPC_RegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocator): + MuonRegSelCondAlg( name, pSvcLocator ) +{ + ATH_MSG_DEBUG( "RPC_RegSelCondAlg::RPC_RegSelCondAlg() " << name ); +} + + + +std::unique_ptr<RegSelSiLUT> RPC_RegSelCondAlg::createTable( const MuonMDT_CablingMap* /* mdtCabling */ ) const { + + /// now get the RPC cabling service ... + + const IRPCcablingServerSvc* cabling_server = nullptr; + + if ( service( "RPCcablingServerSvc", cabling_server ).isFailure() ) { + ATH_MSG_ERROR( "Could not retieve RPC cabling server"); + return std::unique_ptr<RegSelSiLUT>(nullptr); + } + + const IRPCcablingSvc* cabling = nullptr; + + if ( cabling_server->giveCabling( cabling ).isFailure() ) { + ATH_MSG_ERROR( "Could not retieve RPC cabling service"); + return std::unique_ptr<RegSelSiLUT>(nullptr); + } + + const MuonGM::MuonDetectorManager* manager = nullptr; + + if ( detStore()->retrieve( manager ).isFailure() ) { + ATH_MSG_ERROR( "Could not retrieve RPC Manager for " << name() ); + return std::unique_ptr<RegSelSiLUT>(nullptr); + } + + const RpcIdHelper* helper = manager->rpcIdHelper(); + + std::vector<Identifier>::const_iterator idfirst = helper->module_begin(); + std::vector<Identifier>::const_iterator idlast = helper->module_end(); + + IdContext ModuleContext = helper->module_context(); + + ATH_MSG_DEBUG("createTable()"); + + std::unique_ptr<RegSelSiLUT> lut = std::make_unique<RegSelSiLUT>(); + + + //loop over modules (PrepRawData collections) + for ( std::vector<Identifier>::const_iterator itr=idfirst ; itr!=idlast ; itr++ ) { + + Identifier prdId = *itr; + IdentifierHash prdHashId; + int gethash_code = helper->get_hash(prdId, prdHashId, &ModuleContext); + if (gethash_code != 0 ) { + ATH_MSG_DEBUG("Failed retrieving IdentifierHash for PRD Identifier = " << prdId.getString() << ". Skipping to the next PRD."); + continue; + } + + std::vector<uint32_t> robIds; + StatusCode sc = cabling->giveROB_fromPRD(prdHashId, robIds); + if ( (cabling->giveROB_fromPRD(prdHashId, robIds)).isFailure() ) { + ATH_MSG_ERROR( "RegSelCondAlg_RPC could not get ROBid" ); + return std::unique_ptr<RegSelSiLUT>(nullptr); + } + + + if (robIds.size() < 1) { + ATH_MSG_DEBUG("There is no ROB associated with the PRD HashId = " << (unsigned int)prdHashId << ". Skipping to the next PRD."); + continue; + } + if (robIds.size()!=1 && robIds.size()!=2 && robIds.size()!=4) { + ATH_MSG_WARNING("Unhandled number of ROBs per one PRD. Expected 1, 2 or 4, got " << robIds.size() << ". Omitting the PRD HashId = " << (unsigned int)prdHashId); + continue; + } + + ExpandedIdentifier exp_id; + if ( helper->get_expanded_id( prdId, exp_id, &ModuleContext) ) { + ATH_MSG_DEBUG("Failed retrieving ExpandedIdentifier for PRD Identifier = " << prdId.getString() << ". Skipping to the next PRD."); + continue; + } + + int detid = ( exp_id[2]<0 ? -1 : 1 ); + int layerid = exp_id[1]; + if ( layerid==0 ) layerid = 11; // this line should never be executed + + MuonGM::RpcReadoutSet Set( manager, prdId ); + //int nmod = Set.NreadoutElements(); + int ndbz = Set.NdoubletZ(); + + //std::cout<<" Number of modules in this RpcSet "<<nmod<<" Number of doubletZ in this RpcSet "<<Set.NdoubletZ()<<std::endl; + //std::cout<<" Number of modules in Phi/DoubletZ: "; + //for (int i=1; i<=ndbz; i++) std::cout<<Set.NPhimodules(i)<<" "; + //std::cout<<std::endl; + + double zmin = 99999999; + double zmax = -99999999; + double rmin = 99999999; + double rmax = -99999999; + double phimin = 999999; + double phimax = -999999; + Amg::Vector3D Pzmin; + Amg::Vector3D Pzmax; + unsigned nmodules = 0; + + for (int dbz=1; dbz<=ndbz; dbz++) { + + const MuonGM::RpcReadoutElement* rpcold = NULL; + int ndbp = Set.NPhimodules(dbz); + + for (int dbp=1; dbp<=ndbp; dbp++) { + + const MuonGM::RpcReadoutElement* rpc = Set.readoutElement(dbz, dbp); + + if ( rpc != rpcold ) { + + // here a new module + nmodules ++; + rpcold = rpc; + + Amg::Vector3D rpcPos = rpc->center(); + double zminMod = rpcPos.z()-0.5*rpc->getZsize(); + double zmaxMod = rpcPos.z()+0.5*rpc->getZsize(); + + //double rcen = std::sqrt(rpcPos.r()*rpcPos.r()-rpcPos.z()*rpcPos.z()); + double rcen = std::sqrt(rpcPos.mag()*rpcPos.mag()-rpcPos.z()*rpcPos.z()); + + double rminMod = rcen-0.5*rpc->getRsize(); + double rmaxMod = rcen+0.5*rpc->getRsize(); + + // double dphi = std::atan2(rpc->getSsize()/2.,rpcPos.perp()); + double dphi = std::atan2(rpc->getSsize()/2,rpcPos.perp()); + double pminMod = rpcPos.phi() - dphi; + double pmaxMod = rpcPos.phi() + dphi; + + if (zminMod < zmin) { + zmin = zminMod; + Pzmin = rpcPos; + //Pzmin.setZ(zmin); + Pzmin[2] = zmin; + } + if (zmaxMod > zmax) { + zmax = zmaxMod; + Pzmax = rpcPos; + //Pzmax.setZ(zmax); + Pzmax[2] = zmax; + } + if (rminMod < rmin) { + rmin = rminMod; + } + if (rmaxMod > rmax) { + rmax = rmaxMod; + } + if (pminMod < phimin) phimin = pminMod; + if (pmaxMod > phimax) phimax = pmaxMod; + + } + } + } + + double phiMinFirst = phimin; + double phiMaxFirst = 0.5*(phimin+phimax); + double phiMinSecond = 0.5*(phimin+phimax); + double phiMaxSecond = phimax; + + if (phiMinFirst < 0) phiMinFirst += 2*M_PI; + if (phiMaxFirst < 0) phiMaxFirst += 2*M_PI; + if (phiMinSecond < 0) phiMinSecond += 2*M_PI; + if (phiMaxSecond < 0) phiMaxSecond += 2*M_PI; + + + if (robIds.size()==1) { + IdentifierHash lowerHashId( (1<<16) | (unsigned int)prdHashId ); + + RegSelModule m1( zmin, zmax, rmin, rmax, phiMinFirst, phiMaxSecond, layerid, detid, robIds[0], lowerHashId ); + lut->addModule( m1 ); + } + //the code below exploits the fact that ROB Ids are sorted!!! They go in order: SIDE A, ROBs 0..15, then SIDE C ROBs 0..15 + //it is also assumed that if there are 4 ROBs, then zmin<0 and zmax>0 + else if (robIds.size()==2) { + uint32_t lowerRobId=0; + uint32_t higherRobId=0; + if ( ((robIds[0] & 0xff) == 0) && ((robIds[1] & 0xff) == 15) ) { //the two ROBs around phi=0 + lowerRobId = robIds[1]; + higherRobId = robIds[0]; + } + else { + lowerRobId = robIds[0]; + higherRobId = robIds[1]; + } + IdentifierHash lowerHashId( (1<<16) | (unsigned int)prdHashId ); + IdentifierHash higherHashId( (2<<16) | (unsigned int)prdHashId ); + + RegSelModule m1( zmin, zmax, rmin, rmax, phiMinFirst, phiMaxFirst, layerid, detid, lowerRobId, lowerHashId ); + RegSelModule m2( zmin, zmax, rmin, rmax, phiMinSecond, phiMaxSecond, layerid, detid, higherRobId, higherHashId ); + lut->addModule( m1 ); + lut->addModule( m2 ); + } + else if (robIds.size()==4) { //this is the case only for two BOG chambers at z=0 read by ROBs 10-11 and 12-13, each on both sides A and C + uint32_t sideA_lowerRobId = robIds[0]; + uint32_t sideA_higherRobId = robIds[1]; + uint32_t sideC_lowerRobId = robIds[2]; + uint32_t sideC_higherRobId = robIds[3]; + IdentifierHash sideA_lowerHashId( (1<<16) | (unsigned int)prdHashId ); + IdentifierHash sideA_higherHashId( (2<<16) | (unsigned int)prdHashId ); + IdentifierHash sideC_lowerHashId( (3<<16) | (unsigned int)prdHashId ); + IdentifierHash sideC_higherHashId( (4<<16) | (unsigned int)prdHashId ); + + RegSelModule m1( 0, zmax, rmin, rmax, phiMinFirst, phiMaxFirst, layerid, detid, sideA_lowerRobId, sideA_lowerHashId ); + RegSelModule m2( 0, zmax, rmin, rmax, phiMinSecond, phiMaxSecond, layerid, detid, sideA_higherRobId, sideA_higherHashId ); + RegSelModule m3( zmin, 0, rmin, rmax, phiMinFirst, phiMaxFirst, layerid, detid, sideC_lowerRobId, sideC_lowerHashId ); + RegSelModule m4( zmin, 0, rmin, rmax, phiMinSecond, phiMaxSecond, layerid, detid, sideC_higherRobId, sideC_higherHashId ); + lut->addModule( m1 ); + lut->addModule( m2 ); + lut->addModule( m3 ); + lut->addModule( m4 ); + } + } //end of loop over modules (PrepRawData collections) + + lut->initialise(); + + return lut; + +} + + + + + + + diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/RPC_RegSelCondAlg.h b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/RPC_RegSelCondAlg.h new file mode 100755 index 00000000000..e68633d4466 --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/RPC_RegSelCondAlg.h @@ -0,0 +1,27 @@ +/** emacs: this is -*- c++ -*- **/ +/** + ** @file RPC_RegSelCondAlg.h + ** + ** @author sutt + ** @date Tue 4 Feb 2020 15:25:00 CET + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + +#ifndef RPC_RegSelCondAlg_h +#define RPC_RegSelCondAlg_h + +#include "MuonRegSelCondAlg.h" + + +class RPC_RegSelCondAlg : public MuonRegSelCondAlg { + +public: + + RPC_RegSelCondAlg( const std::string& name, ISvcLocator* pSvcLocator ); + + std::unique_ptr<RegSelSiLUT> createTable( const MuonMDT_CablingMap* mdtCabling ) const override; + +}; + +#endif // RPC_RegSelCondAlg_h diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/RPC_RegionSelectorTable.cxx b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/RPC_RegionSelectorTable.cxx index 850400e7649..340119d40ed 100644 --- a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/RPC_RegionSelectorTable.cxx +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/RPC_RegionSelectorTable.cxx @@ -231,7 +231,6 @@ StatusCode RPC_RegionSelectorTable::createTable() { RegSelModule m1( zmin, zmax, rmin, rmax, phiMinFirst, phiMaxSecond, layerid, detid, robIds[0], lowerHashId ); rpclut->addModule( m1 ); } - //the code below exploits the fact that ROB Ids are sorted!!! They go in order: SIDE A, ROBs 0..15, then SIDE C ROBs 0..15 //it is also assumed that if there are 4 ROBs, then zmin<0 and zmax>0 else if (robIds.size()==2) { @@ -253,7 +252,6 @@ StatusCode RPC_RegionSelectorTable::createTable() { rpclut->addModule( m1 ); rpclut->addModule( m2 ); } - else if (robIds.size()==4) { //this is the case only for two BOG chambers at z=0 read by ROBs 10-11 and 12-13, each on both sides A and C uint32_t sideA_lowerRobId = robIds[0]; uint32_t sideA_higherRobId = robIds[1]; diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/TGC_RegSelCondAlg.cxx b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/TGC_RegSelCondAlg.cxx new file mode 100644 index 00000000000..634918e7a81 --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/TGC_RegSelCondAlg.cxx @@ -0,0 +1,185 @@ +/** + ** @file TGC_RegSelCondAlg.cxx + ** + ** conditions algorithm to create the Si detector + ** lookup tables + ** + ** @author sutt + ** @date Sun 22 Sep 2019 10:21:50 BST + ** + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + + +#include "GaudiKernel/EventIDRange.h" +#include "StoreGate/WriteCondHandle.h" + +#include "CLHEP/Units/SystemOfUnits.h" +#include "Identifier/IdentifierHash.h" + +#include <iostream> +#include <fstream> +#include <string> +#include <cmath> + +#include "MuonCablingData/MuonMDT_CablingMap.h" + +#include "MuonReadoutGeometry/MuonDetectorManager.h" +#include "MuonReadoutGeometry/MuonReadoutElement.h" +#include "MuonReadoutGeometry/MdtReadoutElement.h" +#include "MuonReadoutGeometry/CscReadoutElement.h" +#include "MuonReadoutGeometry/RpcReadoutElement.h" +#include "MuonReadoutGeometry/TgcReadoutElement.h" +#include "MuonReadoutGeometry/RpcReadoutSet.h" +#include "MuonReadoutGeometry/MuonStation.h" + +#include "MuonTGC_Cabling/MuonTGC_CablingSvc.h" + +#include "TGC_RegSelCondAlg.h" + + + +TGC_RegSelCondAlg::TGC_RegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocator): + MuonRegSelCondAlg( name, pSvcLocator ) +{ + ATH_MSG_DEBUG( "TGC_RegSelCondAlg::TGC_RegSelCondAlg() " << name ); +} + + + + + + +std::unique_ptr<RegSelSiLUT> TGC_RegSelCondAlg::createTable( const MuonMDT_CablingMap* /* mdtCabling */ ) const { + + /// now get the TGC cabling service ... + + const MuonTGC_CablingSvc* cabling = nullptr; + + if ( service( "MuonTGC_CablingSvc", cabling ).isFailure() ) { + ATH_MSG_ERROR( "Could not retrieve TGC cabling for " << name() ); + return std::unique_ptr<RegSelSiLUT>(nullptr); + } + + /// now get the TGC detector manager ... + + const MuonGM::MuonDetectorManager* manager = nullptr; + + if ( (detStore()->retrieve( manager ).isFailure() ) ) { + ATH_MSG_ERROR( "Could not retrieve TGC Manager for " << name() ); + return std::unique_ptr<RegSelSiLUT>(nullptr); + } + + const TgcIdHelper* helper = manager->tgcIdHelper(); + + std::vector<Identifier>::const_iterator idfirst = helper->module_begin(); + std::vector<Identifier>::const_iterator idlast = helper->module_end(); + + const IdContext ModuleContext = helper->module_context(); + + ATH_MSG_DEBUG("createTable()"); + + std::unique_ptr<RegSelSiLUT> lut = std::make_unique<RegSelSiLUT>(); + + int maxRodId = 0; + int maxSswId = 0; + int maxSbloc = 0; + int minChannelId = 0; + int maxChannelId = 0; + cabling->getReadoutIDRanges(maxRodId, maxSswId, maxSbloc, minChannelId, maxChannelId); + + for (std::vector<Identifier>::const_iterator i = idfirst; i != idlast; i++) { + + Identifier Id = *i; + IdentifierHash hashId; + + helper->get_hash( Id,hashId,&ModuleContext); + + ExpandedIdentifier exp_id; + if (helper->get_expanded_id( Id, exp_id, &ModuleContext)) { + ATH_MSG_DEBUG("Failed retrieving ExpandedIdentifier for PRD Identifier = " << Id.getString() << ". Skipping to the next PRD."); + continue; + } + + int detid = ( exp_id[2]<0 ? -1 : 1 ); + int layerid = exp_id[1]+1; + + const MuonGM::TgcReadoutElement* tgc = manager->getTgcReadoutElement(Id); + if (tgc == NULL) { + continue; + } + + int gapMin = helper->gasGapMin(Id); + int gapMax = helper->gasGapMax(Id); + + Identifier chId; + chId = helper -> channelID(Id,gapMin,0,1); + const int chmax = helper -> channelMax(chId); + Amg::Vector3D posmax = tgc->channelPos(gapMin,0,chmax); // gapMax gives posmax! + chId = helper -> channelID(Id,gapMax,0,1); + const int chmin = helper -> channelMin(chId); + Amg::Vector3D posmin = tgc->channelPos(gapMax,0,chmin); // gapMin gives posmin! + + // caliculation based on max/min channels in a module + // etamin = -logf(tan(atan(posmin.perp()/fabs(posmin.z()))/2.)); + // etamax = -logf(tan(atan(posmax.perp()/fabs(posmax.z()))/2.)); + + // caliculation based on active sensitive area + + Amg::Vector3D posctr = tgc->globalPosition(); + double activeheight = tgc->length(); + + double etamin = -logf(std::tan(std::atan((posctr.perp()-0.5*activeheight)/std::fabs(posmin.z()))*0.5)); + double etamax = -logf(std::tan(std::atan((posctr.perp()+0.5*activeheight)/std::fabs(posmax.z()))*0.5)); + + double zmin = posmin.z(); + double zmax = posmax.z(); + + double rmin = posctr.perp()-0.5*activeheight; + double rmax = posctr.perp()+0.5*activeheight; + + + if (helper->stationEta(Id) < 0) { + etamin = -etamin; + etamax = -etamax; + } + + + // caliculation based on active sensitive area + double activelongside = tgc->longWidth()-tgc->frameXwidth()*2.; + /// Should use std::atan2 etc, but atan2f is not definied in cmath, so for backwards + /// compatability we are forced to use the old versions + double phimin = atan2f(posctr.y(),posctr.x()) - atan2f(activelongside/2.,posctr.perp()+activeheight/2.); + double phimax = atan2f(posctr.y(),posctr.x()) + atan2f(activelongside/2.,posctr.perp()+activeheight/2.); + + if (phimin < 0) phimin += 2.*M_PI; + if (phimax < 0) phimax += 2.*M_PI; + + // get ROB id + int subDetectorId = 0; // 0x67 (A side) or 0x68 (C side) + int rodId = 0; // 1-12 + cabling->getReadoutIDfromElementID(Id, subDetectorId, rodId); + //int isAside = (subDetectorId==0x67) ? 0 : 1; + //uint32_t robId = static_cast<uint32_t>(isAside*(maxRodId) + rodId -1); // 0-23 + // using Source ID :see Muon::TGC_Hid2RESrcID::getRodID()/getRobId() + uint32_t robId = ( ((0x0ff) & subDetectorId)<<16 ) | (rodId); + // end part to get ROB id + + RegSelModule m( zmin, zmax, rmin, rmax, phimin, phimax, layerid, detid, robId, hashId ); + lut->addModule( m ); + + } + + lut->initialise(); + + return lut; + +} + + + + + + + diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/TGC_RegSelCondAlg.h b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/TGC_RegSelCondAlg.h new file mode 100755 index 00000000000..aa0ce6d5bfa --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/TGC_RegSelCondAlg.h @@ -0,0 +1,27 @@ +/** emacs: this is -*- c++ -*- **/ +/** + ** @file TGC_RegSelCondAlg.h + ** + ** @author sutt + ** @date Tue 4 Feb 2020 15:25:00 CET + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + +#ifndef TGC_RegSelCondAlg_h +#define TGC_RegSelCondAlg_h + +#include "MuonRegSelCondAlg.h" + + +class TGC_RegSelCondAlg : public MuonRegSelCondAlg { + +public: + + TGC_RegSelCondAlg( const std::string& name, ISvcLocator* pSvcLocator ); + + std::unique_ptr<RegSelSiLUT> createTable( const MuonMDT_CablingMap* mdtCabling ) const; + +}; + +#endif // TGC_RegSelCondAlg_h diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/components/MuonRegionSelector_entries.cxx b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/components/MuonRegionSelector_entries.cxx index 0838295a11e..df0b13f9670 100644 --- a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/components/MuonRegionSelector_entries.cxx +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/components/MuonRegionSelector_entries.cxx @@ -13,3 +13,17 @@ DECLARE_COMPONENT( CSC_RegionSelectorTable ) DECLARE_COMPONENT( MM_RegionSelectorTable ) DECLARE_COMPONENT( sTGC_RegionSelectorTable ) +#include "../MDT_RegSelCondAlg.h" +#include "../RPC_RegSelCondAlg.h" +#include "../TGC_RegSelCondAlg.h" +#include "../CSC_RegSelCondAlg.h" +#include "../MM_RegSelCondAlg.h" +#include "../sTGC_RegSelCondAlg.h" + +DECLARE_COMPONENT( MDT_RegSelCondAlg ) +DECLARE_COMPONENT( RPC_RegSelCondAlg ) +DECLARE_COMPONENT( TGC_RegSelCondAlg ) +DECLARE_COMPONENT( CSC_RegSelCondAlg ) +DECLARE_COMPONENT( MM_RegSelCondAlg ) +DECLARE_COMPONENT( sTGC_RegSelCondAlg ) + diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/sTGC_RegSelCondAlg.cxx b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/sTGC_RegSelCondAlg.cxx new file mode 100644 index 00000000000..dcafed58827 --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/sTGC_RegSelCondAlg.cxx @@ -0,0 +1,155 @@ +/** + ** @file sTGC_RegSelCondAlg.cxx + ** + ** conditions algorithm to create the Si detector + ** lookup tables + ** + ** @author sutt + ** @date Sun 22 Sep 2019 10:21:50 BST + ** + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + + +#include <iostream> +#include <fstream> +#include <string> + +#include "CLHEP/Units/SystemOfUnits.h" +#include "Identifier/IdentifierHash.h" + +#include "RegSelLUT/RegSelModule.h" +#include "RegSelLUT/RegSelSiLUT.h" + +#include "MuonReadoutGeometry/MuonDetectorManager.h" +#include "MuonReadoutGeometry/MuonReadoutElement.h" + +/// sTGC naming convention headers +#include "MuonReadoutGeometry/sTgcReadoutElement.h" +#include "MuonAGDDDescription/sTGCDetectorHelper.h" +#include "MuonAGDDDescription/sTGCDetectorDescription.h" + +#include "MuonReadoutGeometry/MuonStation.h" + +#include "RegSelLUT/RegSelSiLUT.h" + + +/// not implemented yet +/// #include "Muon_sTGC_Cabling/MuonMM_CablingSvc.h" + +#include "sTGC_RegSelCondAlg.h" + + +sTGC_RegSelCondAlg::sTGC_RegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocator): + MuonRegSelCondAlg( name, pSvcLocator ) +{ + ATH_MSG_DEBUG( "sTGC_RegSelCondAlg::sTGC_RegSelCondAlg() " << name ); +} + + + + + +std::unique_ptr<RegSelSiLUT> sTGC_RegSelCondAlg::createTable( const MuonMDT_CablingMap* /* mdtCabling */ ) const { + + /// no NSW cabling available at the moment ... + + /// get the MM detector manager + + const MuonGM::MuonDetectorManager* manager = nullptr; + + if ( (detStore()->retrieve( manager ).isFailure() ) ) { + ATH_MSG_ERROR( "Could not retrieve Muon Manager for " << name() ); + return std::unique_ptr<RegSelSiLUT>(nullptr); + } + + const sTgcIdHelper* helper = manager->stgcIdHelper(); + + std::vector<Identifier>::const_iterator idfirst = helper->module_begin(); + std::vector<Identifier>::const_iterator idlast = helper->module_end(); + + /// do we want the module context ... + /// const IdContext ModuleContext = helper->module_context(); + + /// or the detector element context ? Keep them both untill we are sure + const IdContext ModuleContext = helper->detectorElement_context(); + + ATH_MSG_DEBUG("createTable()"); + + std::unique_ptr<RegSelSiLUT> lut = std::make_unique<RegSelSiLUT>(); + + + for ( std::vector<Identifier>::const_iterator i=idfirst ; i!=idlast ; i++ ) { + + Identifier Id = *i; + IdentifierHash hashId; + + helper->get_hash( Id, hashId, &ModuleContext ); + + const MuonGM::sTgcReadoutElement* mm = manager->getsTgcReadoutElement(Id); + if (!mm) continue; + + // std::cout << "stgc station name: " << mm->getStationName() << "\teta: " << mm->getStationEta() << "\tphi: " << mm->getStationPhi() << std::endl; + + int multilayer = helper->multilayer(Id); + + char side = mm->getStationEta() < 0 ? 'C' : 'A'; + + char sector_l = mm->getStationName().substr(2,1)=="L" ? 'L' : 'S'; + + sTGCDetectorHelper aHelper; + sTGCDetectorDescription* md = aHelper.Get_sTGCDetector( sector_l, std::abs(mm->getStationEta()), mm->getStationPhi(), multilayer, side ); + + Amg::Vector3D mmPos = mm->center(); + + double swidth = md->sWidth(); + double lwidth = md->lWidth(); + + double ycutout = md->yCutout(); + + double length = md->Length(); + double depth = md->Tck(); + + double moduleR = std::sqrt( mmPos.mag()*mmPos.mag() - mmPos.z()*mmPos.z()); + + double zmin = mmPos.z()-0.5*depth; + double zmax = mmPos.z()+0.5*depth; + + double rmin = moduleR-0.5*length; + double rmax = std::sqrt( (moduleR+0.5*length)*(moduleR+0.5*length) + lwidth*lwidth/4 ); + + double dphi1 = std::atan( (0.5*lwidth)/(moduleR+0.5*length) ); + double dphi2 = std::atan( (0.5*swidth)/(moduleR-0.5*length) ); + + double dphi = ( dphi1 > dphi2 ? dphi1 : dphi2 ); + + if ( ycutout > 0 ) { + double rcutout = moduleR+0.5*length - ycutout; + double dphicutout = std::atan( (0.5*lwidth)/rcutout ); + if ( dphi < dphicutout ) dphi = dphicutout; + } + + double phimin = mmPos.phi()-dphi; + double phimax = mmPos.phi()+dphi; + + if ( phimin > M_PI ) phimin -= 2*M_PI; + if ( phimin < -M_PI ) phimin += 2*M_PI; + + int layerid = multilayer; + int detid = ( side == 'C' ? -1 : 1 ); + + int robId = 0; + + // std::cout << "sTGC::module r: " << moduleR << "\tlength: " << length << "\tswidth: " << swidth << "\tlwidth: " << lwidth << "\tycut: " << ycutout << std::endl; + + RegSelModule m( zmin, zmax, rmin, rmax, phimin, phimax, int(layerid), int(detid), uint32_t(robId), hashId ); + + lut->addModule( m ); + + } + + lut->initialise(); + + return lut; +} diff --git a/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/sTGC_RegSelCondAlg.h b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/sTGC_RegSelCondAlg.h new file mode 100755 index 00000000000..ace1a281544 --- /dev/null +++ b/MuonSpectrometer/MuonDetDescr/MuonRegionSelector/src/sTGC_RegSelCondAlg.h @@ -0,0 +1,32 @@ +/** emacs: this is -*- c++ -*- **/ +/** + ** @file sTGC_RegSelCondAlg.h + ** + ** @author sutt + ** @date Tue 4 Feb 2020 15:25:00 CET + ** + ** Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + **/ + +#ifndef sTGC_RegSelCondAlg_h +#define sTGC_RegSelCondAlg_h + + +#include "MuonRegSelCondAlg.h" + + +/// NB: this sTGC class follows the naming convention from the +/// sTGC detector code base hence the non-standard naming +/// convention sTGC rather than STGC etc + +class sTGC_RegSelCondAlg : public MuonRegSelCondAlg { + +public: + + sTGC_RegSelCondAlg( const std::string& name, ISvcLocator* pSvcLocator ); + + std::unique_ptr<RegSelSiLUT> createTable( const MuonMDT_CablingMap* mdtCabling ) const; + +}; + +#endif // sTGC_RegSelCondAlg_h diff --git a/Trigger/TrigAlgorithms/TrigFastTrackFinder/python/TrigFastTrackFinder_Config.py b/Trigger/TrigAlgorithms/TrigFastTrackFinder/python/TrigFastTrackFinder_Config.py index da837120375..0a3dde84435 100755 --- a/Trigger/TrigAlgorithms/TrigFastTrackFinder/python/TrigFastTrackFinder_Config.py +++ b/Trigger/TrigAlgorithms/TrigFastTrackFinder/python/TrigFastTrackFinder_Config.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration from TrigFastTrackFinder.TrigFastTrackFinderConf import TrigFastTrackFinder -- GitLab