diff --git a/DetectorDescription/IRegionSelector/IRegionSelector/RegSelEnums.h b/DetectorDescription/IRegionSelector/IRegionSelector/RegSelEnums.h index d2d0c4c50c78f314d383bf5dbf4c9a94a2e2cd37..6760b837c8f394465fb7ba102d131581bb2abc61 100644 --- a/DetectorDescription/IRegionSelector/IRegionSelector/RegSelEnums.h +++ b/DetectorDescription/IRegionSelector/IRegionSelector/RegSelEnums.h @@ -34,7 +34,9 @@ enum DETID{ CSC, FCALEM, FCALHAD, - FTK + FTK, + MM, + STGC }; diff --git a/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h b/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h index c5a8e95e846bdcaa85f8f13fc5a84ac6b5edcd1a..b170efc64c2910cc8bf9342d36c83f752697d8e7 100644 --- a/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h +++ b/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h @@ -48,7 +48,7 @@ namespace MuonGM { class MdtReadoutElement; class MuonClusterReadoutElement; class MuonStation; - // for nSW + // New Small Wheel class sTgcReadoutElement; class MMReadoutElement; @@ -108,19 +108,22 @@ namespace MuonGM { const RpcReadoutElement* getRpcReadoutElement(Identifier) const;//!< access via extended identifier (requires unpacking) const TgcReadoutElement* getTgcReadoutElement(Identifier) const;//!< access via extended identifier (requires unpacking) const CscReadoutElement* getCscReadoutElement(Identifier) const;//!< access via extended identifier (requires unpacking) + // New Small Wheel const MMReadoutElement* getMMReadoutElement(Identifier) const;//!< access via extended identifier (requires unpacking) const sTgcReadoutElement* getsTgcReadoutElement(Identifier) const;//!< access via extended identifier (requires unpacking) const MuonClusterReadoutElement* getMuonClusterReadoutElement(Identifier) const;//!< access via extended identifier (requires unpacking) + const MdtReadoutElement* getMdtReadoutElement(int i1, int i2, int i3, int i4) const; //!< access via internally defined array indices; not friendly to users + // FIX: New Small Wheel ? No equivalent in .cxx file const sTgcReadoutElement* getsTgcReadoutElement(int i1, int i2, int i3, int i4) const; //!< access via internally defined array indices; not friendly to users - const MMReadoutElement* getMMReadoutElement(int i1, int i2, int i3, int i4) const; //!< access via internally defined array indices; not friendly to users + // const RpcReadoutElement* getRpcReadoutElement(int i1, int i2, int i3, int i4, int i5) const; //!< access via internally defined array indices; not friendly to users @@ -131,6 +134,7 @@ namespace MuonGM { const CscReadoutElement* getCscReadoutElement(int i1, int i2, int i3, int i4) const; //!< access via internally defined array indices; not friendly to users + const MdtReadoutElement* getMdtRElement_fromIdFields(int i1, int i2, int i3, int i4) const; //!< access via extended identifier field (no unpacking) @@ -153,6 +157,7 @@ namespace MuonGM { inline const RpcReadoutElement* getRpcReadoutElement(IdentifierHash id) const;//!< access via detector-element hash id inline const TgcReadoutElement* getTgcReadoutElement(IdentifierHash id) const;//!< access via detector-element hash id inline const CscReadoutElement* getCscReadoutElement(IdentifierHash id) const;//!< access via detector-element hash id + // TODO: New Small Wheel // void addMdtDetectorElement(MdtDetectorElement*); // void addRpcDetectorElement(RpcDetectorElement*); @@ -165,18 +170,22 @@ namespace MuonGM { inline const RpcDetectorElement* getRpcDetectorElement(IdentifierHash id) const; inline const TgcDetectorElement* getTgcDetectorElement(IdentifierHash id) const; inline const CscDetectorElement* getCscDetectorElement(IdentifierHash id) const; + // TODO: New Small Wheel inline unsigned int nMuonStation() const; //!< Number of MuonStations + inline unsigned int nMdtRE() const;//!< Number of Mdt ReadoutElements - inline unsigned int nsTgcRE() const;//!< Number of Mdt ReadoutElements - inline unsigned int nMMRE() const;//!< Number of Mdt ReadoutElements + inline unsigned int nsTgcRE() const;//!< Number of sTgc ReadoutElements + inline unsigned int nMMRE() const;//!< Number of MM ReadoutElements inline unsigned int nCscRE() const;//!< Number of Csc ReadoutElements inline unsigned int nRpcRE() const;//!< Number of Rpc ReadoutElements inline unsigned int nTgcRE() const;//!< Number of Tgc ReadoutElements + inline unsigned int nMdtDE() const;//!< Number of Mdt DetectorElements inline unsigned int nCscDE() const;//!< Number of Csc DetectorElements inline unsigned int nRpcDE() const;//!< Number of Rpc DetectorElements inline unsigned int nTgcDE() const;//!< Number of Tgc DetectorElements + // TODO: New Small Wheel // Geometry versioning inline std::string geometryVersion() const; //!< it can be Rome-Initial or P03, or ... it's the name of the layout @@ -189,7 +198,7 @@ namespace MuonGM { inline const CscIdHelper* cscIdHelper() const; inline const RpcIdHelper* rpcIdHelper() const; inline const TgcIdHelper* tgcIdHelper() const; - // for nSW + // New Small Wheel inline const sTgcIdHelper* stgcIdHelper() const; inline const MmIdHelper* mmIdHelper() const; @@ -198,7 +207,7 @@ namespace MuonGM { inline void set_cscIdHelper(const CscIdHelper* idh); inline void set_rpcIdHelper(const RpcIdHelper* idh); inline void set_tgcIdHelper(const TgcIdHelper* idh); - // for nSW + // New Small Wheel inline void set_stgcIdHelper(const sTgcIdHelper* idh); inline void set_mmIdHelper(const MmIdHelper* idh); @@ -211,6 +220,7 @@ namespace MuonGM { inline const GenericCSCCache* getGenericCscDescriptor() const; inline void setGenericTgcDescriptor(const GenericTGCCache& tc); inline const GenericTGCCache* getGenericTgcDescriptor() const; + // TODO: New Small Wheel inline void setCachingFlag(int value); inline int cachingFlag() const; @@ -244,6 +254,7 @@ namespace MuonGM { CscRElMaxHash = 130, RpcRElMaxHash = 1200, TgcRElMaxHash = 1600 + // TODO: New Small Wheel }; enum detElementHashMax @@ -252,6 +263,7 @@ namespace MuonGM { CscDetElMaxHash = 65, RpcDetElMaxHash = 650, TgcDetElMaxHash = 1600 + // TODO: New Small Wheel }; @@ -326,6 +338,7 @@ namespace MuonGM { void clearRpcCache() const; void clearCscCache() const; void clearTgcCache() const; + // New Small Wheel void clearsTgcCache() const; void clearMMCache() const; @@ -333,6 +346,7 @@ namespace MuonGM { void refreshRpcCache() const; void refreshCscCache() const; void refreshTgcCache() const; + // New Small Wheel void refreshsTgcCache() const; void refreshMMCache() const; @@ -340,6 +354,7 @@ namespace MuonGM { void fillRpcCache() const; void fillCscCache() const; void fillTgcCache() const; + // New Small Wheel void fillsTgcCache() const; void fillMMCache() const; @@ -388,6 +403,7 @@ namespace MuonGM { GenericMDTCache m_genericMDT; GenericRPCCache m_genericRPC; GenericTGCCache m_genericTGC; + // TODO: New Small Wheel // Geometry versioning @@ -399,7 +415,7 @@ namespace MuonGM { const CscIdHelper* m_cscIdHelper; const RpcIdHelper* m_rpcIdHelper; const TgcIdHelper* m_tgcIdHelper; - //for nSW + // New Small Wheel const sTgcIdHelper* m_stgcIdHelper; const MmIdHelper* m_mmIdHelper; @@ -422,6 +438,7 @@ namespace MuonGM { unsigned int m_n_cscRE; unsigned int m_n_rpcRE; unsigned int m_n_tgcRE; + // New Small Wheel unsigned int m_n_stgRE; unsigned int m_n_mmcRE; @@ -429,6 +446,7 @@ namespace MuonGM { unsigned int m_n_cscDE; unsigned int m_n_rpcDE; unsigned int m_n_tgcDE; + // TODO: New Small Wheel // pointers to the XxxDetectorElements (with granularity a la EDM) std::vector<TgcReadoutParams*> m_TgcReadoutParamsVec; @@ -438,6 +456,7 @@ namespace MuonGM { RpcDetectorElement* m_rpcDEArray[RpcDetElMaxHash]; TgcDetectorElement* m_tgcDEArray[TgcDetElMaxHash]; CscDetectorElement* m_cscDEArray[CscDetElMaxHash]; + // TODO: New Small Wheel mutable ALineMapContainer * m_aLineContainer; mutable BLineMapContainer * m_bLineContainer; @@ -456,7 +475,7 @@ namespace MuonGM { const CscIdHelper* MuonDetectorManager::cscIdHelper() const {return m_cscIdHelper;} const RpcIdHelper* MuonDetectorManager::rpcIdHelper() const {return m_rpcIdHelper;} const TgcIdHelper* MuonDetectorManager::tgcIdHelper() const {return m_tgcIdHelper;} - //for nSW + // New Small Wheel const sTgcIdHelper* MuonDetectorManager::stgcIdHelper() const {return m_stgcIdHelper;} const MmIdHelper* MuonDetectorManager::mmIdHelper() const {return m_mmIdHelper;} @@ -464,7 +483,7 @@ namespace MuonGM { void MuonDetectorManager::set_cscIdHelper(const CscIdHelper* idh) {m_cscIdHelper = idh;} void MuonDetectorManager::set_rpcIdHelper(const RpcIdHelper* idh) {m_rpcIdHelper = idh;} void MuonDetectorManager::set_tgcIdHelper(const TgcIdHelper* idh) {m_tgcIdHelper = idh;} - //for nSW + // New Small Wheel void MuonDetectorManager::set_stgcIdHelper(const sTgcIdHelper* idh) {m_stgcIdHelper = idh;} void MuonDetectorManager::set_mmIdHelper(const MmIdHelper* idh) {m_mmIdHelper = idh;} @@ -534,10 +553,12 @@ namespace MuonGM { unsigned int MuonDetectorManager::nTgcRE() const {return m_n_tgcRE;} unsigned int MuonDetectorManager::nsTgcRE() const {return m_n_stgRE;} unsigned int MuonDetectorManager::nMMRE() const {return m_n_mmcRE;} + unsigned int MuonDetectorManager::nMdtDE() const {return m_n_mdtDE;} unsigned int MuonDetectorManager::nCscDE() const {return m_n_cscDE;} unsigned int MuonDetectorManager::nRpcDE() const {return m_n_rpcDE;} - unsigned int MuonDetectorManager::nTgcDE() const {return m_n_tgcDE;} + unsigned int MuonDetectorManager::nTgcDE() const {return m_n_tgcDE;} + // TODO: New Small Wheel ALineMapContainer* MuonDetectorManager::ALineContainer() const @@ -689,6 +710,7 @@ namespace MuonGM { #endif return m_rpcDEArray[id]; } +// TODO: New Small Wheel (missing all the above functions) } // namespace MuonGM diff --git a/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx b/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx index 39df08b75c46f4374554e42b22f7634cf27c7657..963f94fc2e53aa48cd36cf145ff9fcbce4758e29 100644 --- a/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx +++ b/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx @@ -661,6 +661,9 @@ const MuonClusterReadoutElement* MuonDetectorManager::getMuonClusterReadoutEleme if( m_tgcIdHelper->is_tgc(id) ) return getTgcReadoutElement(id); if( m_rpcIdHelper->is_rpc(id) ) return getRpcReadoutElement(id); if( m_cscIdHelper->is_csc(id) ) return getCscReadoutElement(id); + // New Small Wheel + if( m_mmIdHelper->is_mm(id) ) return getMMReadoutElement(id); + if( m_stgcIdHelper->is_stgc(id) ) return getsTgcReadoutElement(id); return 0; } diff --git a/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonAmbiTrackSelectionTool/src/MuonAmbiTrackSelectionTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonAmbiTrackSelectionTool/src/MuonAmbiTrackSelectionTool.cxx index cad29e9bfc53b4ca30755dbb54e022a57e65e410..b8de8906f1a688aa473a026c99853f68b9dbb1e9 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonAmbiTrackSelectionTool/src/MuonAmbiTrackSelectionTool.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonAmbiTrackSelectionTool/src/MuonAmbiTrackSelectionTool.cxx @@ -25,13 +25,13 @@ //================ Constructor ================================================= Muon::MuonAmbiTrackSelectionTool::MuonAmbiTrackSelectionTool(const std::string& t, - const std::string& n, - const IInterface* p ) + const std::string& n, + const IInterface* p ) : - AthAlgTool(t,n,p), + AthAlgTool(t, n, p), m_assoTool("Trk::PRD_AssociationTool/PRD_AssociationTool"), m_printer("Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"), - m_idHelperTool("Muon::MuonIdHelperTool/MuonIdHelperTool") + m_idHelperTool("Muon::MuonIdHelperTool/MuonIdHelperTool") { declareInterface<IAmbiTrackSelectionTool>(this); @@ -53,25 +53,25 @@ Muon::MuonAmbiTrackSelectionTool::~MuonAmbiTrackSelectionTool() StatusCode Muon::MuonAmbiTrackSelectionTool::initialize() { - + StatusCode sc = AthAlgTool::initialize(); if (sc.isFailure()) return sc; sc = m_assoTool.retrieve(); - if (sc.isFailure()) - { - ATH_MSG_ERROR("Failed to retrieve tool " << m_assoTool); - return StatusCode::FAILURE; - } + if (sc.isFailure()) + { + ATH_MSG_ERROR("Failed to retrieve tool " << m_assoTool); + return StatusCode::FAILURE; + } else ATH_MSG_DEBUG("Retrieved tool " << m_assoTool); sc = m_printer.retrieve(); - if (sc.isSuccess()){ + if (sc.isSuccess()) { ATH_MSG_DEBUG("Retrieved " << m_printer); - }else{ - ATH_MSG_ERROR("Could not get " << m_printer); + } else { + ATH_MSG_ERROR("Could not get " << m_printer); return sc; } @@ -87,102 +87,103 @@ StatusCode Muon::MuonAmbiTrackSelectionTool::finalize() } //============================================================================================ -const Trk::Track* Muon::MuonAmbiTrackSelectionTool::getCleanedOutTrack(const Trk::Track* ptrTrack, const Trk::TrackScore /*score*/) +const Trk::Track* Muon::MuonAmbiTrackSelectionTool::getCleanedOutTrack(const Trk::Track* ptrTrack, const Trk::TrackScore /*score*/) { unsigned int numshared = 0; unsigned int numhits = 0; - - if( !ptrTrack ) return 0; + + if ( !ptrTrack ) return 0; // get all TSOS const DataVector<const Trk::TrackStateOnSurface>* tsos = ptrTrack->trackStateOnSurfaces(); - - + + ATH_MSG_VERBOSE("New Track " << m_printer->print(*ptrTrack)); - std::map<Muon::MuonStationIndex::StIndex,int> sharedPrecisionPerLayer; - std::map<Muon::MuonStationIndex::StIndex,int> precisionPerLayer; - + std::map<Muon::MuonStationIndex::StIndex, int> sharedPrecisionPerLayer; + std::map<Muon::MuonStationIndex::StIndex, int> precisionPerLayer; + // loop over TSOS DataVector<const Trk::TrackStateOnSurface>::const_iterator iTsos = tsos->begin(); - DataVector<const Trk::TrackStateOnSurface>::const_iterator iTsosEnd = tsos->end(); + DataVector<const Trk::TrackStateOnSurface>::const_iterator iTsosEnd = tsos->end(); for ( ; iTsos != iTsosEnd ; ++iTsos) { - + // get measurment from TSOS const Trk::MeasurementBase* meas = (*iTsos)->measurementOnTrack(); if (!meas) continue; // only look at measurements - if( !(*iTsos)->type(Trk::TrackStateOnSurface::Measurement ) ) continue; - + if ( !(*iTsos)->type(Trk::TrackStateOnSurface::Measurement ) ) continue; + const Trk::RIO_OnTrack* rot = dynamic_cast <const Trk::RIO_OnTrack*> (meas); if (!rot) { // we are only interested in precision hits since only they have the resolution to distinguish between close-by tracks // so we only take competing ROTs if they are CSC eta hits const Trk::CompetingRIOsOnTrack* competingROT = dynamic_cast <const Trk::CompetingRIOsOnTrack*> (meas); - if(competingROT){ + if (competingROT) { const unsigned int numROTs = competingROT->numberOfContainedROTs(); - for( unsigned int i=0;i<numROTs;++i ){ + for ( unsigned int i = 0; i < numROTs; ++i ) { const Trk::RIO_OnTrack* rot = &competingROT->rioOnTrack(i); - if( !rot || !rot->prepRawData() || !m_idHelperTool->isMuon(rot->identify()) ) continue; + if ( !rot || !rot->prepRawData() || !m_idHelperTool->isMuon(rot->identify()) ) continue; //only use precision hits for muon track overlap - if(!m_idHelperTool->isMdt(rot->identify()) && !(m_idHelperTool->isCsc(rot->identify()) && !m_idHelperTool->measuresPhi(rot->identify())) && !m_idHelperTool->isMM(rot->identify()) && !m_idHelperTool->issTgc(rot->identify())) continue; - Muon::MuonStationIndex::StIndex stIndex = m_idHelperTool->stationIndex(rot->identify()); - ++precisionPerLayer[stIndex]; - if ( m_assoTool->isUsed(*(rot->prepRawData()))) { - ATH_MSG_VERBOSE("Track overlap found! " << m_idHelperTool->toString(rot->identify())); - ++numshared; - ++sharedPrecisionPerLayer[stIndex]; - } - } + if (!m_idHelperTool->isMdt(rot->identify()) && !(m_idHelperTool->isCsc(rot->identify()) && !m_idHelperTool->measuresPhi(rot->identify())) && !m_idHelperTool->isMM(rot->identify()) && !m_idHelperTool->issTgc(rot->identify())) continue; + Muon::MuonStationIndex::StIndex stIndex = m_idHelperTool->stationIndex(rot->identify()); + ++precisionPerLayer[stIndex]; + if ( m_assoTool->isUsed(*(rot->prepRawData()))) { + ATH_MSG_VERBOSE("Track overlap found! " << m_idHelperTool->toString(rot->identify())); + ++numshared; + ++sharedPrecisionPerLayer[stIndex]; + } + } } - }else{ + } else { - if(!m_idHelperTool->isMuon(rot->identify())) continue; - if(!m_idHelperTool->isMdt(rot->identify()) && !(m_idHelperTool->isCsc(rot->identify()) && !m_idHelperTool->measuresPhi(rot->identify())) && !m_idHelperTool->isMM(rot->identify()) && !m_idHelperTool->issTgc(rot->identify())) continue; //only precision hits used for overlap + if (!m_idHelperTool->isMuon(rot->identify())) continue; + if (!m_idHelperTool->isMdt(rot->identify()) && !(m_idHelperTool->isCsc(rot->identify()) && !m_idHelperTool->measuresPhi(rot->identify())) && !m_idHelperTool->isMM(rot->identify()) && !m_idHelperTool->issTgc(rot->identify())) continue; //only precision hits used for overlap ++numhits; + Muon::MuonStationIndex::StIndex stIndex = m_idHelperTool->stationIndex(rot->identify()); ++precisionPerLayer[stIndex]; // allow no overlap if ( m_assoTool->isUsed(*(rot->prepRawData()))) { - ATH_MSG_VERBOSE("Track overlap found! " << m_idHelperTool->toString(rot->identify())); - ++numshared; - ++sharedPrecisionPerLayer[stIndex]; + ATH_MSG_VERBOSE("Track overlap found! " << m_idHelperTool->toString(rot->identify())); + ++numshared; + ++sharedPrecisionPerLayer[stIndex]; } } } - if( numhits == 0 ) { + if ( numhits == 0 ) { ATH_MSG_WARNING("Got track without Muon hits " << m_printer->print(*ptrTrack)); return 0; } - double overlapFraction = (double)numshared/(double)numhits; + double overlapFraction = (double)numshared / (double)numhits; - ATH_MSG_DEBUG("Track "<< ptrTrack<<" has "<< numhits <<" hit, shared " << numshared - << " overlap fraction " << overlapFraction << " layers " << precisionPerLayer.size() - << " shared " << sharedPrecisionPerLayer.size() ); + ATH_MSG_DEBUG("Track " << ptrTrack << " has " << numhits << " hit, shared " << numshared + << " overlap fraction " << overlapFraction << " layers " << precisionPerLayer.size() + << " shared " << sharedPrecisionPerLayer.size() ); - if( overlapFraction > m_maxOverlapFraction ) { - if( m_keepPartial ){ - if( sharedPrecisionPerLayer.empty() ) { - ATH_MSG_DEBUG("Track is not sharing precision hits, keeping "); - return ptrTrack; + if ( overlapFraction > m_maxOverlapFraction ) { + if ( m_keepPartial ) { + if ( sharedPrecisionPerLayer.empty() ) { + ATH_MSG_DEBUG("Track is not sharing precision hits, keeping "); + return ptrTrack; } - if( overlapFraction < 0.25 && precisionPerLayer.size() > 2 && precisionPerLayer.size() - sharedPrecisionPerLayer.size() == 1 ) { - ATH_MSG_DEBUG("Three station track differing by one precision layer, keeping "); - return ptrTrack; + if ( overlapFraction < 0.25 && precisionPerLayer.size() > 2 && precisionPerLayer.size() - sharedPrecisionPerLayer.size() == 1 ) { + ATH_MSG_DEBUG("Three station track differing by one precision layer, keeping "); + return ptrTrack; } - if( overlapFraction < 0.35 && precisionPerLayer.size() > 2 && precisionPerLayer.size() - sharedPrecisionPerLayer.size() > 1 && m_keepMoreThanOne) { - ATH_MSG_DEBUG("Three station track differing by more than one precision layer, keeping "); - return ptrTrack; + if ( overlapFraction < 0.35 && precisionPerLayer.size() > 2 && precisionPerLayer.size() - sharedPrecisionPerLayer.size() > 1 && m_keepMoreThanOne) { + ATH_MSG_DEBUG("Three station track differing by more than one precision layer, keeping "); + return ptrTrack; } } return 0; } - + return ptrTrack; } diff --git a/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonRecToolInterfaces/MuonRecToolInterfaces/IMuonSeededSegmentFinder.h b/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonRecToolInterfaces/MuonRecToolInterfaces/IMuonSeededSegmentFinder.h index 322128b6ea786ad27fd78c99e07ba781104206aa..61d4ddebe52974919bee4e69ceb4e2afd6c9d6da 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonRecToolInterfaces/MuonRecToolInterfaces/IMuonSeededSegmentFinder.h +++ b/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonRecToolInterfaces/MuonRecToolInterfaces/IMuonSeededSegmentFinder.h @@ -4,7 +4,7 @@ #ifndef MUON_IMUONSEEDEDSEGMENTFINDER #define MUON_IMUONSEEDEDSEGMENTFINDER - + #include "GaudiKernel/IAlgTool.h" #include "TrkParameters/TrackParameters.h" #include "Identifier/Identifier.h" @@ -15,55 +15,66 @@ #include "MuonPrepRawData/RpcPrepDataCollection.h" #include "MuonPrepRawData/TgcPrepDataCollection.h" #include "MuonPrepRawData/CscPrepDataCollection.h" +// New Small Wheel +#include "MuonPrepRawData/sTgcPrepDataCollection.h" +#include "MuonPrepRawData/MMPrepDataCollection.h" + #include <set> #include <vector> -static const InterfaceID IID_IMuonSeededSegmentFinder("Muon::IMuonSeededSegmentFinder",1,0); +static const InterfaceID IID_IMuonSeededSegmentFinder("Muon::IMuonSeededSegmentFinder", 1, 0); namespace Muon { - class MuonSegment; +class MuonSegment; } namespace Muon { - /** @brief The IMuonSegmentMaker is a pure virtual interface for tools to find tracks starting from MuonSegmentCombinations */ - class IMuonSeededSegmentFinder : virtual public IAlgTool - { - public: - /** access to tool interface */ - static const InterfaceID& interfaceID(); +/** @brief The IMuonSegmentMaker is a pure virtual interface for tools to find tracks starting from MuonSegmentCombinations */ +class IMuonSeededSegmentFinder : virtual public IAlgTool +{ +public: + /** access to tool interface */ + static const InterfaceID& interfaceID(); + + /** @brief find segments in a set of chambers starting from seeding TrackParameters */ + virtual std::vector<const MuonSegment*>* find( const Trk::TrackParameters& pars, const std::set<Identifier>& chIds ) const = 0; + + /** @brief find segments in a set of chambers starting from seeding TrackParameters (version with Hashes) */ + virtual std::vector<const MuonSegment*>* find( const Trk::TrackParameters& pars, const std::set<IdentifierHash>& chIdHs ) const = 0; - /** @brief find segments in a set of chambers starting from seeding TrackParameters */ - virtual std::vector<const MuonSegment*>* find( const Trk::TrackParameters& pars, const std::set<Identifier>& chIds ) const = 0; - - /** @brief find segments in a set of chambers starting from seeding TrackParameters (version with Hashes) */ - virtual std::vector<const MuonSegment*>* find( const Trk::TrackParameters& pars, const std::set<IdentifierHash>& chIdHs ) const = 0; + /** @brief find segments in a set of MdtPrepData starting from seeding TrackParameters */ + virtual std::vector<const MuonSegment*>* find( const Trk::TrackParameters& pars, const std::vector<const MdtPrepData*>& mdtPrds ) const = 0; - /** @brief find segments in a set of MdtPrepData starting from seeding TrackParameters */ - virtual std::vector<const MuonSegment*>* find( const Trk::TrackParameters& pars, const std::vector<const MdtPrepData*>& mdtPrds ) const = 0; + /** @brief retrieve MDT PRD collections for the given hashes */ + virtual void extractMdtPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const MdtPrepDataCollection*>& target ) const = 0; - /** @brief retrieve MDT PRD collections for the given hashes */ - virtual void extractMdtPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const MdtPrepDataCollection*>& target ) const = 0; + /** @brief retrieve RPC PRD collections for the given hashes */ + virtual void extractRpcPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const RpcPrepDataCollection*>& target ) const = 0; - /** @brief retrieve RPC PRD collections for the given hashes */ - virtual void extractRpcPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const RpcPrepDataCollection*>& target ) const = 0; + /** @brief retrieve TGC PRD collections for the given hashes */ + virtual void extractTgcPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const TgcPrepDataCollection*>& target ) const = 0; - /** @brief retrieve TGC PRD collections for the given hashes */ - virtual void extractTgcPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const TgcPrepDataCollection*>& target ) const = 0; + /** @brief retrieve CSC PRD collections for the given hashes */ + virtual void extractCscPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const CscPrepDataCollection*>& target ) const = 0; - /** @brief retrieve CSC PRD collections for the given hashes */ - virtual void extractCscPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const CscPrepDataCollection*>& target ) const = 0; + // New Small Wheel + /** @brief retrieve STGC PRD collections for the given hashes */ + virtual void extractsTgcPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const sTgcPrepDataCollection*>& target ) const = 0; + /** @brief retrieve MM PRD collections for the given hashes */ + virtual void extractMMPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const MMPrepDataCollection*>& target ) const = 0; - }; - - inline const InterfaceID& IMuonSeededSegmentFinder::interfaceID() - { - return IID_IMuonSeededSegmentFinder; - } + +}; + +inline const InterfaceID& IMuonSeededSegmentFinder::interfaceID() +{ + return IID_IMuonSeededSegmentFinder; +} } // end of name space -#endif +#endif diff --git a/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonTrackSummaryHelperTool/src/MuonTrackSummaryHelperTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonTrackSummaryHelperTool/src/MuonTrackSummaryHelperTool.cxx index 0aa1bc75c19b2cb16e86b35e0a88b6443a61f0c6..21896b4c3f42b0ab5f0ae2baee3e3c66ff0d1e5d 100755 --- a/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonTrackSummaryHelperTool/src/MuonTrackSummaryHelperTool.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonTrackSummaryHelperTool/src/MuonTrackSummaryHelperTool.cxx @@ -376,6 +376,15 @@ void Muon::MuonTrackSummaryHelperTool::addDetailedTrackSummary( const Trk::Track } if( pars->associatedSurface().associatedDetectorElement() ){ Identifier id = pars->associatedSurface().associatedDetectorElement()->identify(); + bool issTgc = m_idHelperTool->issTgc(id); + if(issTgc) { +// get the identifier for phi or eta holes + Identifier idh = pars->associatedSurface().associatedDetectorElementIdentifier(); + if(idh.is_valid()) { + id = idh; +// ATH_MSG_VERBOSE(" For sTGC hole use associatedDetectorElementIdentifier "); + } + } if( !id.is_valid() || !m_idHelperTool->isMuon(id) ) continue; Identifier chId = m_idHelperTool->chamberId(id); //Identifier layId = m_idHelperTool->layerId(id); @@ -408,9 +417,22 @@ void Muon::MuonTrackSummaryHelperTool::addDetailedTrackSummary( const Trk::Track currentChamberSummary = &trackSummary.m_chamberHitSummary.back(); currentChamberPars = pars; } - Trk::MuonTrackSummary::ChamberHitSummary::Projection& proj = - isFirst ? currentChamberSummary->m_first : currentChamberSummary->m_second; - ++proj.nholes; + if(!issTgc) { + Trk::MuonTrackSummary::ChamberHitSummary::Projection& proj = + isFirst ? currentChamberSummary->m_first : currentChamberSummary->m_second; + ++proj.nholes; + } else { +// sTgc holes keep track of phi and eta + if( m_idHelperTool->measuresPhi(id) ) { + ATH_MSG_VERBOSE(" counting sTGC phi hole "); + Trk::MuonTrackSummary::ChamberHitSummary::Projection& proj = currentChamberSummary->m_second; + ++proj.nholes; + } else { + ATH_MSG_VERBOSE(" counting sTGC eta hole "); + Trk::MuonTrackSummary::ChamberHitSummary::Projection& proj = currentChamberSummary->m_first; + ++proj.nholes; + } + } } continue; } @@ -562,9 +584,20 @@ void Muon::MuonTrackSummaryHelperTool::addDetailedTrackSummary( const Trk::Track } void Muon::MuonTrackSummaryHelperTool::updateHoleContent( Trk::MuonTrackSummary::ChamberHitSummary& chamberHitSummary ) const { -// ATH_MSG_INFO("updateHoleContent " << m_idHelperTool->toString(chamberHitSummary.chamberId()) +// ATH_MSG_DEBUG("updateHoleContent " << m_idHelperTool->toString(chamberHitSummary.chamberId()) // << " nphi " << chamberHitSummary.phiProjection().nhits << " holes " << chamberHitSummary.phiProjection().nholes // << " neta " << chamberHitSummary.etaProjection().nhits << " holes " << chamberHitSummary.etaProjection().nholes ); + + if( m_idHelperTool->issTgc(chamberHitSummary.chamberId()) ){ + ATH_MSG_DEBUG(" holes eta " << chamberHitSummary.etaProjection().nholes + << " phi " << chamberHitSummary.phiProjection().nholes ); + } + + if( m_idHelperTool->issTgc(chamberHitSummary.chamberId()) + || m_idHelperTool->isMM(chamberHitSummary.chamberId()) ){ + return; + } + bool isCsc = m_idHelperTool->isCsc(chamberHitSummary.chamberId()); int neta = isCsc ? 4 : 2; int nphi = isCsc ? 4 : 2; diff --git a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonChamberHoleRecoveryTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonChamberHoleRecoveryTool.cxx index 0bfbfaf05a0185185121e0eea0e574a3cb21117d..1e4a73712a2323c7643acf210b4f1898571ffb26 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonChamberHoleRecoveryTool.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonChamberHoleRecoveryTool.cxx @@ -27,6 +27,10 @@ #include "MuonRIO_OnTrack/CscClusterOnTrack.h" #include "MuonRIO_OnTrack/RpcClusterOnTrack.h" #include "MuonRIO_OnTrack/TgcClusterOnTrack.h" +// New Small Wheel +#include "MuonRIO_OnTrack/sTgcClusterOnTrack.h" +#include "MuonRIO_OnTrack/MMClusterOnTrack.h" + #include "MuonCompetingRIOsOnTrack/CompetingMuonClustersOnTrack.h" #include "MuonPrepRawData/MuonCluster.h" @@ -44,6 +48,10 @@ #include "MuonIdHelpers/RpcIdHelper.h" #include "MuonIdHelpers/CscIdHelper.h" #include "MuonIdHelpers/TgcIdHelper.h" +// New Small Wheel +#include "MuonIdHelpers/sTgcIdHelper.h" +#include "MuonIdHelpers/MmIdHelper.h" + #include "EventPrimitives/EventPrimitivesHelpers.h" #include "GeoPrimitives/GeoPrimitivesToStringConverter.h" @@ -71,10 +79,6 @@ namespace Muon { - declareProperty("MdtPrepDataContainer", m_key_mdt="MDT_DriftCircles"); - declareProperty("CscPrepDataContainer", m_key_csc="CSC_Clusters"); - declareProperty("TgcPrepDataContainer", m_key_tgc="TGC_Measurements"); - declareProperty("RpcPrepDataContainer", m_key_rpc="RPC_Measurements"); declareProperty("MuonStationIntersectSvc", m_intersectSvc); declareProperty("Extrapolator", m_extrapolator); declareProperty("MdtRotCreator", m_mdtRotCreator); @@ -93,7 +97,7 @@ namespace Muon { } - MuonChamberHoleRecoveryTool::~MuonChamberHoleRecoveryTool(){} + MuonChamberHoleRecoveryTool::~MuonChamberHoleRecoveryTool() {} StatusCode MuonChamberHoleRecoveryTool::initialize() @@ -104,22 +108,25 @@ namespace Muon { ATH_CHECK( m_printer.retrieve() ); ATH_CHECK( m_extrapolator.retrieve() ); ATH_CHECK( m_mdtRotCreator.retrieve() ); - - if( !m_cscRotCreator.empty() ) { + + if ( !m_cscRotCreator.empty() ) { ATH_CHECK( m_cscRotCreator.retrieve() ); - }else{ + } else { ATH_MSG_INFO("CSC rot creation disabled" ); } - + ATH_CHECK( m_clusRotCreator.retrieve() ); ATH_CHECK( m_pullCalculator.retrieve() ); ATH_CHECK( m_idHelperTool.retrieve() ); ATH_CHECK( m_intersectSvc.retrieve() ); - + ATH_CHECK(m_key_mdt.initialize()); ATH_CHECK(m_key_csc.initialize()); ATH_CHECK(m_key_tgc.initialize()); ATH_CHECK(m_key_rpc.initialize()); + ATH_CHECK(m_key_stgc.initialize()); + ATH_CHECK(m_key_mm.initialize()); + return StatusCode::SUCCESS; } @@ -147,483 +154,602 @@ namespace Muon { // loop over track and calculate residuals const DataVector<const Trk::TrackStateOnSurface>* trkstates = track.trackStateOnSurfaces(); - if( !trkstates ){ + if ( !trkstates ) { ATH_MSG_DEBUG(" track without states, discarding track " ); return 0; } - if( msgLvl(MSG::DEBUG) ) { - msg(MSG::DEBUG) << " performing hole search track " << std::endl + if ( msgLvl(MSG::DEBUG) ) { + msg(MSG::DEBUG) << " performing hole search track " << std::endl << m_printer->print(track ); - if( msgLvl(MSG::VERBOSE) ){ + if ( msgLvl(MSG::VERBOSE) ) { msg(MSG::VERBOSE) << std::endl << m_printer->printMeasurements( track ); } msg(MSG::DEBUG) << endmsg; } - // vector to store states, the boolean indicated whether the state was create in this routine (true) or belongs to the track (false) - // If any new state is created, all states will be cloned and a new track will beformed from them. - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > > newStates; - newStates.reserve(trkstates->size()+5); - + // vector to store states, the boolean indicated whether the state was created in this routine (true) + // or belongs to the track (false). + // If any new state is created, all states will be cloned and a new track will be formed from them. + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > > newStates; + newStates.reserve(trkstates->size() + 5); + std::vector<const Trk::TrackStateOnSurface*> states; states.reserve(trkstates->size()); - states.insert(states.end(),trkstates->begin(),trkstates->end()); - + states.insert(states.end(), trkstates->begin(), trkstates->end()); + std::set<MuonStationIndex::StIndex> stations; Identifier currentMdtChId; unsigned int nholes = 0; // loop over TSOSs std::vector<const Trk::TrackStateOnSurface*>::const_iterator tsit = states.begin(); std::vector<const Trk::TrackStateOnSurface*>::const_iterator tsit_end = states.end(); - for( ; tsit!=tsit_end ; ++tsit ){ + for ( ; tsit != tsit_end ; ++tsit ) { - if( !*tsit ) continue; //sanity check + if ( !*tsit ) continue; //sanity check // drop existing holes on track - if( (*tsit)->type(Trk::TrackStateOnSurface::Hole) ) { + if ( (*tsit)->type(Trk::TrackStateOnSurface::Hole) ) { ATH_MSG_VERBOSE(" new TSOS is holes state, dropping " ); ++nholes; continue; } - + // check whether state is a measurement const Trk::TrackParameters* pars = (*tsit)->trackParameters(); - if( !pars ) { + if ( !pars ) { ATH_MSG_VERBOSE(" new TSOS without parameters, copying " ); - newStates.push_back( std::make_pair(false,*tsit) ); + newStates.push_back( std::make_pair(false, *tsit) ); continue; } - + // check whether state is a measurement const Trk::MeasurementBase* meas = (*tsit)->measurementOnTrack(); - if( !meas ) { + if ( !meas ) { ATH_MSG_VERBOSE(" new TSOS without measurement, copying " ); - newStates.push_back( std::make_pair(false,*tsit) ); + newStates.push_back( std::make_pair(false, *tsit) ); continue; } - + Identifier id = m_helperTool->getIdentifier(*meas); // Not a ROT, else it would have had an identifier. Keep the TSOS. - if( !id.is_valid() || !m_idHelperTool->mdtIdHelper().is_muon(id) ){ - if( msgLvl(MSG::VERBOSE)){ - if(!id.is_valid() ) ATH_MSG_VERBOSE(" new TSOS without valid identifier, copying " ); - else if( !m_idHelperTool->mdtIdHelper().is_muon(id) ) ATH_MSG_VERBOSE(" new TSOS with none muon identifier, copying " ); + if ( !id.is_valid() || !m_idHelperTool->mdtIdHelper().is_muon(id) ) { + if ( msgLvl(MSG::VERBOSE)) { + if (!id.is_valid() ) ATH_MSG_VERBOSE(" new TSOS without valid identifier, copying " ); + else if ( !m_idHelperTool->mdtIdHelper().is_muon(id) ) ATH_MSG_VERBOSE(" new TSOS with none muon identifier, copying " ); } - newStates.push_back( std::make_pair(false,*tsit) ); + newStates.push_back( std::make_pair(false, *tsit) ); continue; } - - if( m_idHelperTool->isMdt(id) ) { + + if ( m_idHelperTool->isMdt(id) ) { // get station index Identifier chId = m_idHelperTool->chamberId(id); MuonStationIndex::StIndex stIndex = m_idHelperTool->stationIndex(chId); stations.insert(stIndex); - + // MDT case: Run hole search in chamber. tsit = insertMdtsWithHoleSearch( tsit, tsit_end, newStates ); continue; - - }else if( m_idHelperTool->isTrigger(id) || m_idHelperTool->isCsc(id) || m_idHelperTool->isMM(id) || m_idHelperTool->issTgc(id) ) { - - // TGC case: Look for missing layers in chamber, add them to track + } else if ( m_idHelperTool->isTrigger(id) || m_idHelperTool->isCsc(id) || m_idHelperTool->isMM(id) || m_idHelperTool->issTgc(id) ) { + // Non-MDT case: Look for missing layers in chamber, add them to track tsit = insertClustersWithHoleSearch( tsit, tsit_end, newStates ); continue; - - }else{ + } else { ATH_MSG_WARNING(" unknown Identifier " ); } - + } - - if( newStates.size() + nholes < states.size() ) + + if ( newStates.size() + nholes < states.size() ) ATH_MSG_DEBUG("Invalid number of states: collected " << newStates.size() - << " holes " << nholes << " original " << states.size() ); - + << " holes " << nholes << " original " << states.size() ); + // NOTE: no return ? + ATH_MSG_DEBUG(" track has stations: " << stations.size() << " original states " << states.size() << " new states " << newStates.size() ); // states were added, create a new track DataVector<const Trk::TrackStateOnSurface>* trackStateOnSurfaces = new DataVector<const Trk::TrackStateOnSurface>(); trackStateOnSurfaces->reserve( newStates.size() ); - - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >::iterator nit = newStates.begin(); - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >::iterator nit_end = newStates.end(); - for( ;nit!=nit_end;++nit ){ + + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator nit = newStates.begin(); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator nit_end = newStates.end(); + for ( ; nit != nit_end; ++nit ) { // add states. If nit->first is true we have a new state. If it is false the state is from the old track and has to be cloned trackStateOnSurfaces->push_back( nit->first ? nit->second : nit->second->clone() ); } - Trk::Track* newTrack = new Trk::Track( track.info(), trackStateOnSurfaces, track.fitQuality() ? track.fitQuality()->clone():0 ); + Trk::Track* newTrack = new Trk::Track( track.info(), trackStateOnSurfaces, track.fitQuality() ? track.fitQuality()->clone() : 0 ); - return newTrack; + return newTrack; } -std::vector<const Trk::TrackStateOnSurface*>::const_iterator -MuonChamberHoleRecoveryTool::insertClustersWithHoleSearch( std::vector<const Trk::TrackStateOnSurface*>::const_iterator tsit, - std::vector<const Trk::TrackStateOnSurface*>::const_iterator tsit_end, - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >& states + std::vector<const Trk::TrackStateOnSurface*>::const_iterator + MuonChamberHoleRecoveryTool::insertClustersWithHoleSearch( std::vector<const Trk::TrackStateOnSurface*>::const_iterator tsit, + std::vector<const Trk::TrackStateOnSurface*>::const_iterator tsit_end, + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >& states ) const { // iterator should point to a valid element - if( tsit == tsit_end ) { + if ( tsit == tsit_end ) { ATH_MSG_WARNING(" iterator pointing to end of vector, this should no happen " ); return --tsit; } - + // check whether state is a measurement const Trk::MeasurementBase* meas = (*tsit)->measurementOnTrack(); const Trk::TrackParameters* pars = (*tsit)->trackParameters(); - if( !meas || !pars ){ - if( tsit+1 == tsit_end ) --tsit; + if ( !meas || !pars ) { + if ( tsit + 1 == tsit_end ) --tsit; return tsit; } - + // loop over states until we reached the last tgc hit in this detector element // keep trackof the identifiers and the states std::set<Identifier> layIds; Identifier* detectorElId = 0; // pointer to detector element ID, created when finding the first TGC - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > > newStates; - for( ;tsit!=tsit_end;++tsit ){ + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > > newStates; + for ( ; tsit != tsit_end; ++tsit ) { + + if ( !*tsit ) continue; - if( !*tsit ) continue; - // skip existing holes as they will be recalculated - if( (*tsit)->type(Trk::TrackStateOnSurface::Hole) ) continue; + if ( (*tsit)->type(Trk::TrackStateOnSurface::Hole) ) continue; // check whether state is a measurement, keep if not const Trk::MeasurementBase* meas = (*tsit)->measurementOnTrack(); - if( !meas ) { - newStates.push_back( std::make_pair(false,*tsit) ); + if ( !meas ) { + newStates.push_back( std::make_pair(false, *tsit) ); continue; } - + // get identifier, keep state if it has no identifier. Identifier id = m_helperTool->getIdentifier(*meas); - if( !id.is_valid() ) { - newStates.push_back( std::make_pair(false,*tsit) ); + if ( !id.is_valid() ) { + newStates.push_back( std::make_pair(false, *tsit) ); continue; } // get chamber Id Identifier detElId = m_idHelperTool->detElId(id); - if( !detectorElId ) detectorElId = new Identifier( detElId ); - + if ( !detectorElId ) detectorElId = new Identifier( detElId ); + // check whether we are still in the same chamber, stop loop if not - if( detElId != *detectorElId ) break; - - // sanity check, this SHOULD be a RPC, TGC or CSC measurement - if( !( m_idHelperTool->isTrigger(id) || m_idHelperTool->isCsc(id) || m_idHelperTool->isMM(id) || m_idHelperTool->issTgc(id) ) ){ - newStates.push_back( std::make_pair(false,*tsit) ); + if ( detElId != *detectorElId ) break; + + // sanity check, this SHOULD be a RPC, TGC, MM, STGC or CSC measurement + if ( !( m_idHelperTool->isTrigger(id) || m_idHelperTool->isCsc(id) || m_idHelperTool->isMM(id) || m_idHelperTool->issTgc(id) ) ) { + newStates.push_back( std::make_pair(false, *tsit) ); ATH_MSG_WARNING(" Identifier should be TGC/RPC/CSC/MM/STGC: " << m_idHelperTool->toString(id) ); continue; } - - + + // split competing ROTs into constituents const CompetingMuonClustersOnTrack* comp = dynamic_cast<const CompetingMuonClustersOnTrack*>(meas); - if( comp ) { + if ( comp ) { std::vector<const MuonClusterOnTrack*>::const_iterator clit = comp->containedROTs().begin(); std::vector<const MuonClusterOnTrack*>::const_iterator clit_end = comp->containedROTs().end(); - for( ;clit!=clit_end;++clit ){ + for ( ; clit != clit_end; ++clit ) { // get layer Identifier and insert it into set Identifier layId = m_idHelperTool->layerId( (*clit)->identify() ); layIds.insert(layId); } - }else{ + } else { // get layer Identifier and insert it into set Identifier layId = m_idHelperTool->layerId(id); layIds.insert(layId); } - if( msgLvl(MSG::VERBOSE) ) { + if ( msgLvl(MSG::VERBOSE) ) { msg(MSG::VERBOSE) << " new hit " << m_idHelperTool->toString(id); - if( comp ) msg(MSG::VERBOSE) << " competing, layers: " << layIds.size(); + if ( comp ) msg(MSG::VERBOSE) << " competing, layers: " << layIds.size(); msg(MSG::VERBOSE) << endmsg; } - newStates.push_back( std::make_pair(false,*tsit) ); + newStates.push_back( std::make_pair(false, *tsit) ); } - + // create holes - if( detectorElId ){ - createHoleTSOSsForClusterChamber( *detectorElId,*pars,layIds,newStates ); + if ( detectorElId ) { + createHoleTSOSsForClusterChamber( *detectorElId, *pars, layIds, newStates ); delete detectorElId; - }else{ + } else { ATH_MSG_WARNING(" no chamber identifier set, this should not happen " ); } - + // sort all states in this chamber - std::stable_sort(newStates.begin(),newStates.end(),SortTSOSByDistanceToPars(pars) ); - - // insert the states into - states.insert( states.end(),newStates.begin(),newStates.end() ); - + std::stable_sort(newStates.begin(), newStates.end(), SortTSOSByDistanceToPars(pars) ); + + // insert the states into + states.insert( states.end(), newStates.begin(), newStates.end() ); + // iterator should point to the last TGC in this chamber return --tsit; } - -std::vector<const Trk::TrackStateOnSurface*>::const_iterator -MuonChamberHoleRecoveryTool::insertMdtsWithHoleSearch( std::vector<const Trk::TrackStateOnSurface*>::const_iterator tsit, - std::vector<const Trk::TrackStateOnSurface*>::const_iterator tsit_end, - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >& states + std::vector<const Trk::TrackStateOnSurface*>::const_iterator + MuonChamberHoleRecoveryTool::insertMdtsWithHoleSearch( std::vector<const Trk::TrackStateOnSurface*>::const_iterator tsit, + std::vector<const Trk::TrackStateOnSurface*>::const_iterator tsit_end, + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >& states ) const { // iterator should point to a valid element - if( tsit == tsit_end ) { + if ( tsit == tsit_end ) { ATH_MSG_WARNING(" iterator pointing to end of vector, this should no happen " ); return --tsit; } - + // check whether state is a measurement const Trk::MeasurementBase* meas = (*tsit)->measurementOnTrack(); const Trk::TrackParameters* pars = (*tsit)->trackParameters(); - if( !meas || !pars ){ - if( tsit+1 == tsit_end ) --tsit; + if ( !meas || !pars ) { + if ( tsit + 1 == tsit_end ) --tsit; return tsit; } - + // this should be a MDT const MdtDriftCircleOnTrack* mdtFirst = dynamic_cast<const MdtDriftCircleOnTrack*>(meas); - if( !mdtFirst ){ + if ( !mdtFirst ) { ATH_MSG_WARNING("Bad hit: not a MDT " << m_idHelperTool->toString(m_helperTool->getIdentifier(*meas)) ); - if( tsit+1 == tsit_end ) --tsit; + if ( tsit + 1 == tsit_end ) --tsit; return tsit; } - + // get chamber identifier MuonStationIndex::ChIndex currentChIndex = m_idHelperTool->chamberIndex(mdtFirst->identify()); Identifier chId = m_idHelperTool->chamberId(mdtFirst->identify()); - + // to correctly handle low pt tracks average the direction of the track in the chamber const Trk::TrackParameters* parsLast = 0; - + // loop over states until we reached the last mdt hit in this chamber // keep trackof the identifiers and the states std::set<Identifier> ids; - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > > newStates; - for( ;tsit!=tsit_end;++tsit ){ + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > > newStates; + for ( ; tsit != tsit_end; ++tsit ) { - if( !*tsit ) continue; + if ( !*tsit ) continue; // skip existing holes as they will be recalculated - if( (*tsit)->type(Trk::TrackStateOnSurface::Hole) ) continue; - + if ( (*tsit)->type(Trk::TrackStateOnSurface::Hole) ) continue; + // check whether state is a measurement const Trk::MeasurementBase* meas = (*tsit)->measurementOnTrack(); - if( !meas ) { - newStates.push_back( std::make_pair(false,*tsit) ); + if ( !meas ) { + newStates.push_back( std::make_pair(false, *tsit) ); continue; } - + // don't break on pseudo measurements const Trk::PseudoMeasurementOnTrack* psmeas = dynamic_cast<const Trk::PseudoMeasurementOnTrack*>(meas); - if( psmeas ){ - newStates.push_back( std::make_pair(false,*tsit) ); + if ( psmeas ) { + newStates.push_back( std::make_pair(false, *tsit) ); continue; } // only use MDTs const MdtDriftCircleOnTrack* mdt = dynamic_cast<const MdtDriftCircleOnTrack*>(meas); - if( !mdt ) break; - + if ( !mdt ) break; + const Identifier& id = mdt->identify(); - + // check whether we are still in the same chamber layer - if( currentChIndex != m_idHelperTool->chamberIndex(id) ) break; + if ( currentChIndex != m_idHelperTool->chamberIndex(id) ) break; ids.insert(id); // insert identifier - newStates.push_back( std::make_pair(false,*tsit) ); + newStates.push_back( std::make_pair(false, *tsit) ); - // get pointer to last parameters + // get pointer to last parameters parsLast = (*tsit)->trackParameters(); } - + // check if chamber index is already processed bool doHoleSearch = true; - if( m_checkForBadSort ){ - if( m_chamberLayersOnTrack.count(currentChIndex) ){ - if( m_detectBadSort ) ATH_MSG_WARNING("Detected badly sorted track, not adding holes in current chamber"); + if ( m_checkForBadSort ) { + if ( m_chamberLayersOnTrack.count(currentChIndex) ) { + if ( m_detectBadSort ) ATH_MSG_WARNING("Detected badly sorted track, not adding holes in current chamber"); else ATH_MSG_DEBUG("Detected badly sorted track, not adding holes in current chamber"); doHoleSearch = false; - }else{ + } else { m_chamberLayersOnTrack.insert(currentChIndex); } } - - if( doHoleSearch ){ - + + if ( doHoleSearch ) { + // ensure that we are not passing in the same parameters - if( parsLast == pars ) parsLast = 0; - + if ( parsLast == pars ) parsLast = 0; + // create holes - createHoleTSOSsForMdtChamber( chId,*pars, parsLast,ids,newStates ); + createHoleTSOSsForMdtChamber( chId, *pars, parsLast, ids, newStates ); - ATH_MSG_DEBUG(" Chamber " << m_idHelperTool->toStringChamber(chId) + ATH_MSG_DEBUG(" Chamber " << m_idHelperTool->toStringChamber(chId) << " has hits " << ids.size() << " new states " << newStates.size() - ids.size() ); - + // sort all states in this chamber - std::stable_sort(newStates.begin(),newStates.end(),SortTSOSByDistanceToPars(pars) ); + std::stable_sort(newStates.begin(), newStates.end(), SortTSOSByDistanceToPars(pars) ); } - - // insert the states into - states.insert( states.end(),newStates.begin(),newStates.end() ); - + + // insert the states into + states.insert( states.end(), newStates.begin(), newStates.end() ); + // iterator should point to the last MDT in this chamber return --tsit; } - + void MuonChamberHoleRecoveryTool::createHoleTSOSsForClusterChamber( const Identifier& detElId, const Trk::TrackParameters& pars, - std::set<Identifier>& layIds, - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >& states ) const { + std::set<Identifier>& layIds, + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >& states ) const { + + ATH_MSG_VERBOSE(" performing holes search in chamber " << m_idHelperTool->toString(detElId) ); + + if ( m_idHelperTool->isCsc(detElId) ) createHoleTSOSsForCscChamber(detElId, pars, layIds, states); + else if ( m_idHelperTool->isTgc(detElId) ) createHoleTSOSsForTgcChamber(detElId, pars, layIds, states); + else if ( m_idHelperTool->isRpc(detElId) ) createHoleTSOSsForRpcChamber(detElId, pars, layIds, states); + else if ( m_idHelperTool->isMM(detElId) ) createHoleTSOSsForMmChamber(detElId, pars, layIds, states); + else if ( m_idHelperTool->issTgc(detElId) ) createHoleTSOSsForStgcChamber(detElId, pars, layIds, states); + // else if( m_idHelperTool->isMM(detElId) || m_idHelperTool->issTgc(detElId) ) ATH_MSG_DEBUG(" NSW hole recovery not implemented yet"); + else ATH_MSG_WARNING(" unexpected Identifier, cannot perform holes search" ); + } - ATH_MSG_VERBOSE(" performing holes search in chamber " << m_idHelperTool->toString(detElId) ); - if( m_idHelperTool->isCsc(detElId) ) createHoleTSOSsForCscChamber(detElId,pars,layIds,states); - else if( m_idHelperTool->isTgc(detElId) ) createHoleTSOSsForTgcChamber(detElId,pars,layIds,states); - else if( m_idHelperTool->isRpc(detElId) ) createHoleTSOSsForRpcChamber(detElId,pars,layIds,states); - else if( m_idHelperTool->isMM(detElId) || m_idHelperTool->issTgc(detElId) ) ATH_MSG_DEBUG(" NSW hole recovery not implemented yet"); - else ATH_MSG_WARNING(" unexpected Identifier, cannot perform holes search" ); + void MuonChamberHoleRecoveryTool::createHoleTSOSsForStgcChamber( const Identifier& detElId, const Trk::TrackParameters& pars, + std::set<Identifier>& layIds, + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >& states ) const { + // get detector element + const MuonGM::sTgcReadoutElement* detEl = m_detMgr->getsTgcReadoutElement(detElId); + if ( !detEl ) { + ATH_MSG_WARNING(" No detector element found for " << m_idHelperTool->toStringChamber(detElId) ); + return; + } + + // get list of layers with a hole + unsigned int nGasGaps = detEl->numberOfLayers(false); + int multilayer = m_idHelperTool->stgcIdHelper().multilayer(detElId); + LayerHoleVec holeVec = holesInClusterChamber( pars, detElId, layIds, nGasGaps ); + if ( holeVec.empty() ) return; + + // create identifiers from LayerHoleVec + std::set<Identifier> chHoles; + LayerHoleVec::iterator it = holeVec.begin(); + LayerHoleVec::iterator it_end = holeVec.end(); + + Identifier layId = m_idHelperTool->stgcIdHelper().channelID(detElId, multilayer, it->first, 1, 1); + bool measuresPhi1 = m_idHelperTool->measuresPhi(layId); + layId = m_idHelperTool->stgcIdHelper().channelID(detElId, multilayer, it->first, 0, 1); + bool measuresPhi0 = m_idHelperTool->measuresPhi(layId); + layId = m_idHelperTool->stgcIdHelper().channelID(detElId, multilayer, it->first, 2, 1); + bool measuresPhi2 = m_idHelperTool->measuresPhi(layId); + + ATH_MSG_DEBUG(" createHoleTSOSsFor StgcChamber measuresPhi type 0" << (int) measuresPhi0 << " measuresPhi type 1 " << (int) measuresPhi1 << " measuresPhi type 2 " << (int) measuresPhi2 ); + for ( ; it != it_end; ++it ) { + // the second gas gap of the three layer stations does not have a phi measurement + // type = 0 1 and 2 pad/eta/wires + // Identifier id = m_idHelper->channelID(parentId, m_idHelper->multilayer(layid), m_idHelper->gasGap(layid),type,1,m_checkIds); + if (it->second == 0) { + // eta strip + chHoles.insert( m_idHelperTool->stgcIdHelper().channelID(detElId, multilayer, it->first, 1, 1) ); + } else { + if (abs(m_idHelperTool->stationEta(detElId)) > 2) { + // wires + chHoles.insert( m_idHelperTool->stgcIdHelper().channelID(detElId, multilayer, it->first, 2, 1) ); + } else { + // pads + chHoles.insert( m_idHelperTool->stgcIdHelper().channelID(detElId, multilayer, it->first, 0, 1) ); + } + } + } + + if ( chHoles.empty() ) return; + + // loop over Tgc Prds and try to find prds of tubes with holes + const sTgcPrepDataCollection* prdCol = findStgcPrdCollection( detElId ); + if ( !prdCol ) { + ATH_MSG_DEBUG(" Retrieval of sTgcPrepDataCollection failed!! " ); + return; + } + + // copy TGC prds into generic MuonCluster vector + std::vector<const MuonCluster*> prds; + prds.reserve(prdCol->size()); + sTgcPrepDataCollection::const_iterator hit = prdCol->begin(); + sTgcPrepDataCollection::const_iterator hit_end = prdCol->end(); + for ( ; hit != hit_end; ++hit ) { + if ( detElId == m_idHelperTool->detElId( (*hit)->identify() ) ) prds.push_back(*hit); + } + + createHoleTSOSsForClusterChamber( detElId, pars, layIds, chHoles, prds, states ); + + return ; + } + + void MuonChamberHoleRecoveryTool::createHoleTSOSsForMmChamber( const Identifier& detElId, const Trk::TrackParameters& pars, + std::set<Identifier>& layIds, + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >& states ) const { + // get detector element + const MuonGM::MMReadoutElement* detEl = m_detMgr->getMMReadoutElement(detElId); + if ( !detEl ) { + ATH_MSG_WARNING(" No detector element found for " << m_idHelperTool->toStringChamber(detElId) ); + return; + } + + // get list of layers with a hole + unsigned int nGasGaps = detEl->numberOfLayers(false); + int multilayer = m_idHelperTool->mmIdHelper().multilayer(detElId); + LayerHoleVec holeVec = holesInClusterChamber( pars, detElId, layIds, nGasGaps ); + if ( holeVec.empty() ) return; + + // create identifiers from LayerHoleVec + std::set<Identifier> chHoles; + LayerHoleVec::iterator it = holeVec.begin(); + LayerHoleVec::iterator it_end = holeVec.end(); + for ( ; it != it_end; ++it ) { + // eta strip + if (it->second == 0) chHoles.insert( m_idHelperTool->mmIdHelper().channelID(detElId, multilayer, it->first, 1) ); + } + + if ( chHoles.empty() ) return; + + // loop over MM Prds and try to find prds of tubes with holes + const MMPrepDataCollection* prdCol = findMmPrdCollection( detElId ); + if ( !prdCol ) { + ATH_MSG_DEBUG(" Retrieval of MMPrepDataCollection failed!! " ); + return; + } + + // copy MM prds into generic MuonCluster vector + std::vector<const MuonCluster*> prds; + prds.reserve(prdCol->size()); + MMPrepDataCollection::const_iterator hit = prdCol->begin(); + MMPrepDataCollection::const_iterator hit_end = prdCol->end(); + for ( ; hit != hit_end; ++hit ) { + if ( detElId == m_idHelperTool->detElId( (*hit)->identify() ) ) prds.push_back(*hit); + } + + createHoleTSOSsForClusterChamber( detElId, pars, layIds, chHoles, prds, states ); + + return ; } void MuonChamberHoleRecoveryTool::createHoleTSOSsForCscChamber( const Identifier& detElId, const Trk::TrackParameters& pars, - std::set<Identifier>& layIds, - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >& states ) const { + std::set<Identifier>& layIds, + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >& states ) const { // get list of layers with a hole unsigned int nGasGaps = 4; - LayerHoleVec holeVec = holesInClusterChamber( pars,detElId,layIds, nGasGaps ); - if( holeVec.empty() ) return; - + LayerHoleVec holeVec = holesInClusterChamber( pars, detElId, layIds, nGasGaps ); + if ( holeVec.empty() ) return; + // create identifiers from LayerHoleVec std::set<Identifier> chHoles; LayerHoleVec::iterator it = holeVec.begin(); LayerHoleVec::iterator it_end = holeVec.end(); - for( ;it!=it_end;++it ){ + for ( ; it != it_end; ++it ) { Identifier parentId = m_idHelperTool->cscIdHelper().parentID(detElId); - Identifier layId = m_idHelperTool->cscIdHelper().channelID(parentId,2,it->first,it->second,1); + Identifier layId = m_idHelperTool->cscIdHelper().channelID(parentId, 2, it->first, it->second, 1); bool measuresPhi = m_idHelperTool->measuresPhi(layId); // sanity check this should always be true!!! - if( measuresPhi != (bool)it->second ){ - ATH_MSG_WARNING(" Problem spotted creating CSC identifier, measures Phi not correctly set " ); + if ( measuresPhi != (bool)it->second ) { + ATH_MSG_WARNING(" Problem spotted creating CSC identifier, measures Phi not correctly set " ); continue; } ATH_MSG_VERBOSE(" adding hole layer " << m_idHelperTool->toString(layId) - << " layer " << it->first << " measPhi " << it->second ); + << " layer " << it->first << " measPhi " << it->second ); chHoles.insert( layId ); } - - if( chHoles.empty() ) return; - + + if ( chHoles.empty() ) return; + // loop over CSC Prds and try to find prds of tubes with holes const CscPrepDataCollection* prdCol = findCscPrdCollection( detElId ); - if( !prdCol ) { + if ( !prdCol ) { ATH_MSG_DEBUG(" Retrieval of CscPrepDataCollection failed!! " ); //return; } - + // copy CSC prds into generic MuonCluster vector std::vector<const MuonCluster*> prds; - if( prdCol ){ + if ( prdCol ) { prds.reserve(prdCol->size()); - prds.insert(prds.begin(),prdCol->begin(),prdCol->end()); + prds.insert(prds.begin(), prdCol->begin(), prdCol->end()); } - createHoleTSOSsForClusterChamber( detElId, pars, layIds, chHoles, prds, states ); + createHoleTSOSsForClusterChamber( detElId, pars, layIds, chHoles, prds, states ); } void MuonChamberHoleRecoveryTool::createHoleTSOSsForTgcChamber( const Identifier& detElId, const Trk::TrackParameters& pars, - std::set<Identifier>& layIds, - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >& states ) const { - + std::set<Identifier>& layIds, + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >& states ) const { + // get detector element const MuonGM::TgcReadoutElement* detEl = m_detMgr->getTgcReadoutElement(detElId); - if( !detEl ){ - ATH_MSG_WARNING(" No detector element found for " << m_idHelperTool->toStringChamber(detElId) ); + if ( !detEl ) { + ATH_MSG_WARNING(" No detector element found for " << m_idHelperTool->toStringChamber(detElId) ); return; - } - + } + // get list of layers with a hole unsigned int nGasGaps = detEl->Ngasgaps(); - LayerHoleVec holeVec = holesInClusterChamber( pars,detElId,layIds, nGasGaps ); - if( holeVec.empty() ) return; - + LayerHoleVec holeVec = holesInClusterChamber( pars, detElId, layIds, nGasGaps ); + if ( holeVec.empty() ) return; + // create identifiers from LayerHoleVec std::set<Identifier> chHoles; LayerHoleVec::iterator it = holeVec.begin(); LayerHoleVec::iterator it_end = holeVec.end(); - for( ;it!=it_end;++it ){ + for ( ; it != it_end; ++it ) { // the second gas gap of the three layer stations does not have a phi measurement - if( nGasGaps == 3 && it->first == 2 && it->second ) continue; - - chHoles.insert( m_idHelperTool->tgcIdHelper().channelID(detElId,it->first,it->second,1) ); + if ( nGasGaps == 3 && it->first == 2 && it->second ) continue; + + chHoles.insert( m_idHelperTool->tgcIdHelper().channelID(detElId, it->first, it->second, 1) ); } - if( chHoles.empty() ) return; - - // loop over Mdt Prds and try to find prds of tubes with holes + if ( chHoles.empty() ) return; + + // loop over Tgc Prds and try to find prds of tubes with holes const TgcPrepDataCollection* prdCol = findTgcPrdCollection( detElId ); - if( !prdCol ) { + if ( !prdCol ) { ATH_MSG_DEBUG(" Retrieval of TgcPrepDataCollection failed!! " ); return; } - + // copy TGC prds into generic MuonCluster vector std::vector<const MuonCluster*> prds; prds.reserve(prdCol->size()); TgcPrepDataCollection::const_iterator hit = prdCol->begin(); TgcPrepDataCollection::const_iterator hit_end = prdCol->end(); - for( ;hit!=hit_end;++hit ){ - if( detElId == m_idHelperTool->detElId( (*hit)->identify() ) ) prds.push_back(*hit); + for ( ; hit != hit_end; ++hit ) { + if ( detElId == m_idHelperTool->detElId( (*hit)->identify() ) ) prds.push_back(*hit); } //prds.insert(prds.begin(),prdCol->begin(),prdCol->end()); - - createHoleTSOSsForClusterChamber( detElId, pars, layIds, chHoles, prds, states ); - + + createHoleTSOSsForClusterChamber( detElId, pars, layIds, chHoles, prds, states ); + } void MuonChamberHoleRecoveryTool::createHoleTSOSsForRpcChamber( const Identifier& detElId, const Trk::TrackParameters& pars, - std::set<Identifier>& layIds, - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >& states ) const { + std::set<Identifier>& layIds, + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >& states ) const { // get list of layers with a hole unsigned int nGasGaps = 2; - LayerHoleVec holeVec = holesInClusterChamber( pars,detElId,layIds, nGasGaps ); - if( holeVec.empty() ) return; + LayerHoleVec holeVec = holesInClusterChamber( pars, detElId, layIds, nGasGaps ); + if ( holeVec.empty() ) return; const MuonGM::RpcReadoutElement* detEl = m_detMgr->getRpcReadoutElement(detElId); - if( !detEl ){ + if ( !detEl ) { ATH_MSG_WARNING("Could not find ReadoutElement for " << m_idHelperTool->toString(detElId) ); return; } int dbZ = detEl->getDoubletZ(); int dbPhi = detEl->getDoubletPhi(); - + ATH_MSG_DEBUG("Looking up RPC structure: dbZ " << dbZ << " dbPhi " << dbPhi << " nphi gp " << detEl->Nphigasgaps()); - + // create identifiers from LayerHoleVec std::set<Identifier> chHoles; LayerHoleVec::iterator it = holeVec.begin(); LayerHoleVec::iterator it_end = holeVec.end(); - for( ;it!=it_end;++it ){ - Identifier clusId = m_idHelperTool->rpcIdHelper().channelID(detElId,dbZ,dbPhi,it->first,it->second,1); + for ( ; it != it_end; ++it ) { + Identifier clusId = m_idHelperTool->rpcIdHelper().channelID(detElId, dbZ, dbPhi, it->first, it->second, 1); chHoles.insert( clusId ); ATH_MSG_VERBOSE("Adding hole " << m_idHelperTool->toString(clusId) ); } - - // loop over Mdt Prds and try to find prds of tubes with holes + + // loop over Rpc Prds and try to find prds of tubes with holes const RpcPrepDataCollection* prdCol = findRpcPrdCollection( detElId ); - if( !prdCol ) { + if ( !prdCol ) { ATH_MSG_DEBUG(" Retrieval of RpcPrepDataCollection failed!! " ); return; } - + // copy RPC prds into generic MuonCluster vector std::vector<const MuonCluster*> prds; prds.reserve(prdCol->size()); RpcPrepDataCollection::const_iterator hit = prdCol->begin(); RpcPrepDataCollection::const_iterator hit_end = prdCol->end(); - for( ;hit!=hit_end;++hit ){ - if( detElId == m_idHelperTool->detElId( (*hit)->identify() ) ) prds.push_back(*hit); + for ( ; hit != hit_end; ++hit ) { + if ( detElId == m_idHelperTool->detElId( (*hit)->identify() ) ) prds.push_back(*hit); } //prds.insert(prds.begin(),prdCol->begin(),prdCol->end()); - - createHoleTSOSsForClusterChamber( detElId, pars, layIds, chHoles, prds, states ); + + createHoleTSOSsForClusterChamber( detElId, pars, layIds, chHoles, prds, states ); } @@ -634,207 +760,216 @@ MuonChamberHoleRecoveryTool::insertMdtsWithHoleSearch( std::vector<const Trk::Tr }; void MuonChamberHoleRecoveryTool::createHoleTSOSsForClusterChamber( const Identifier& detElId, const Trk::TrackParameters& pars, - std::set<Identifier>& layIds, std::set<Identifier>& chHoles, + std::set<Identifier>& layIds, std::set<Identifier>& chHoles, const std::vector<const MuonCluster*>& prds, - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >& states ) const { + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >& states ) const { - if( msgLvl(MSG::DEBUG) ) { - msg() << " chamber " << m_idHelperTool->toString(detElId) + if ( msgLvl(MSG::DEBUG) ) { + msg() << " chamber " << m_idHelperTool->toString(detElId) << " PRDs in chamber " << prds.size() << " holes " << chHoles.size(); - if( msgLvl(MSG::VERBOSE) ) { - if( pars.covariance() ) msg() << MSG::VERBOSE << " extrapolation error " << Amg::error(*pars.covariance(),Trk::locX); + if ( msgLvl(MSG::VERBOSE) ) { + if ( pars.covariance() ) msg() << MSG::VERBOSE << " extrapolation error " << Amg::error(*pars.covariance(), Trk::locX); } msg() << endmsg; } std::vector<const Trk::TrackParameters*> parsToBeDeleted; - parsToBeDeleted.reserve(prds.size()+10); - - typedef std::map<Identifier,PullCluster> ClusterLayerMap; + parsToBeDeleted.reserve(prds.size() + 10); + + typedef std::map<Identifier, PullCluster> ClusterLayerMap; ClusterLayerMap clusterLayerMap; - + const Trk::TrkDetElementBase* detEl = 0; - if( m_idHelperTool->isTgc(detElId) ) detEl = m_detMgr->getTgcReadoutElement(detElId); - else if( m_idHelperTool->isRpc(detElId) ) detEl = m_detMgr->getRpcReadoutElement(detElId); - else if( m_idHelperTool->isCsc(detElId) ) detEl = m_detMgr->getCscReadoutElement(detElId); + if ( m_idHelperTool->isTgc(detElId) ) detEl = m_detMgr->getTgcReadoutElement(detElId); + else if ( m_idHelperTool->isRpc(detElId) ) detEl = m_detMgr->getRpcReadoutElement(detElId); + else if ( m_idHelperTool->isCsc(detElId) ) detEl = m_detMgr->getCscReadoutElement(detElId); + // New Small Wheel + else if ( m_idHelperTool->issTgc(detElId) ) detEl = m_detMgr->getsTgcReadoutElement(detElId); + else if ( m_idHelperTool->isMM(detElId) ) detEl = m_detMgr->getMMReadoutElement(detElId); unsigned int nNewHits = 0; // loop over prds std::vector<const MuonCluster*>::const_iterator it = prds.begin(); std::vector<const MuonCluster*>::const_iterator it_end = prds.end(); - for( ; it!=it_end;++it ){ + for ( ; it != it_end; ++it ) { // get Identifier, check whether we have a hole in that layer. If not go to next cluster const MuonCluster& clus = **it; - if( !detEl ) detEl = clus.detectorElement(); + if ( !detEl ) detEl = clus.detectorElement(); const Identifier& id = clus.identify(); Identifier layId = m_idHelperTool->layerId(id); - + // do not add hits in layers that are already on track - if( layIds.count(layId) ){ - continue; + if ( layIds.count(layId) ) { + continue; } const Trk::Surface& surf = clus.detectorElement()->surface(id); - + const Trk::TrackParameters* exPars = 0; - if( pars.associatedSurface() == surf ) { + if ( pars.associatedSurface() == surf ) { ATH_MSG_VERBOSE(" Same surface, cloning parameters " ); exPars = &pars; - }else{ - exPars = m_extrapolator->extrapolateDirectly(pars,surf,Trk::anyDirection,false,Trk::muon); - if( !exPars ) { + } else { + exPars = m_extrapolator->extrapolateDirectly(pars, surf, Trk::anyDirection, false, Trk::muon); + if ( !exPars ) { ATH_MSG_WARNING(" Propagation cluster PRD failed!! "); continue; } //parsToBeDeleted.push_back(exPars); } - if( msgLvl(MSG::VERBOSE) ) { - msg() << MSG::VERBOSE << " --- " << m_idHelperTool->toString(id) << " error " << Amg::error(clus.localCovariance(),Trk::locX); - if( exPars->covariance() ) msg() << MSG::VERBOSE << " measured parameters, error " << Amg::error(*exPars->covariance(),Trk::locX); + if ( msgLvl(MSG::VERBOSE) ) { + msg() << MSG::VERBOSE << " --- " << m_idHelperTool->toString(id) << " error " << Amg::error(clus.localCovariance(), Trk::locX); + if ( exPars->covariance() ) msg() << MSG::VERBOSE << " measured parameters, error " << Amg::error(*exPars->covariance(), Trk::locX); msg() << endmsg; } - + const MuonClusterOnTrack* clusterOnTrack = 0; - if( m_idHelperTool->isTrigger(clus.identify()) ){ + if ( m_idHelperTool->isTrigger(clus.identify()) || m_idHelperTool->isMM(clus.identify()) || m_idHelperTool->issTgc(clus.identify()) ) { clusterOnTrack = m_clusRotCreator->createRIO_OnTrack( clus, exPars->position(), exPars->momentum().unit() ); - }else{ + } else { if ( m_cscRotCreator.empty() ) { clusterOnTrack = 0; } else { clusterOnTrack = m_cscRotCreator->createRIO_OnTrack( clus, exPars->position(), exPars->momentum().unit() ); } } - if( !clusterOnTrack ) { - if( &pars != exPars ) delete exPars; + if ( !clusterOnTrack ) { + if ( &pars != exPars ) delete exPars; continue; } - + const Trk::ResidualPull* resPull = m_pullCalculator->residualPull( clusterOnTrack, exPars, Trk::ResidualPull::Unbiased ); - if( !resPull ){ - if( &pars != exPars ) delete exPars; + if ( !resPull ) { + if ( &pars != exPars ) delete exPars; delete clusterOnTrack; continue; } - if( resPull->pull().empty() ){ - if( &pars != exPars ) delete exPars; + if ( resPull->pull().empty() ) { + if ( &pars != exPars ) delete exPars; delete clusterOnTrack; delete resPull; continue; } - + double pullCut = m_idHelperTool->measuresPhi(id) ? m_associationPullCutPhi : m_associationPullCutEta; double pull = fabs(resPull->pull().front()); - Amg::Vector2D locExPos(exPars->parameters()[Trk::locX],exPars->parameters()[Trk::locY]); - bool inbounds = surf.insideBounds(locExPos,10.,10.); + Amg::Vector2D locExPos(exPars->parameters()[Trk::locX], exPars->parameters()[Trk::locY]); + bool inbounds = surf.insideBounds(locExPos, 10., 10.); - if( msgLvl(MSG::VERBOSE) ) { + if ( msgLvl(MSG::VERBOSE) ) { std::string boundStr = inbounds ? " inside bounds " : " outside bounds "; double residual = resPull->residual().front(); ATH_MSG_VERBOSE(" found prd: " << m_idHelperTool->toString(id) << " res " << residual << " pull " << pull << boundStr); } delete resPull; - + // check whether hit within cut and in bounds - if( pull < pullCut && inbounds ){ + if ( pull < pullCut && inbounds ) { // check whether there are other hits in the same layer with smaller residual, if not add ClusterLayerMap::iterator clit = clusterLayerMap.find(layId); - if( clit != clusterLayerMap.end() ){ - if( pull < clit->second.pull ) { + if ( clit != clusterLayerMap.end() ) { + if ( pull < clit->second.pull ) { clit->second.pull = pull; - if( &pars != clit->second.pars ) delete clit->second.pars; + if ( &pars != clit->second.pars ) delete clit->second.pars; delete clit->second.clus; clit->second.pars = exPars; clit->second.clus = clusterOnTrack; - }else{ - if( &pars != exPars ) delete exPars; + } else { + if ( &pars != exPars ) delete exPars; delete clusterOnTrack; } - }else{ + } else { PullCluster pullClus; pullClus.pull = pull; pullClus.pars = exPars; pullClus.clus = clusterOnTrack; clusterLayerMap[layId] = pullClus; } - }else{ - if( &pars != exPars ) delete exPars; + } else { + if ( &pars != exPars ) delete exPars; delete clusterOnTrack; } } - + // loop over cluster layer map and add the clusters to the state vector ClusterLayerMap::iterator clit = clusterLayerMap.begin(); ClusterLayerMap::iterator clit_end = clusterLayerMap.end(); - for( ;clit!=clit_end;++clit ){ - -// bool addMeasurements = true; - Trk::TrackStateOnSurface* tsos = MuonTSOSHelper::createMeasTSOS( clit->second.clus, clit->second.pars != &pars ? clit->second.pars : clit->second.pars->clone() , + for ( ; clit != clit_end; ++clit ) { + + // bool addMeasurements = true; + Trk::TrackStateOnSurface* tsos = MuonTSOSHelper::createMeasTSOS( clit->second.clus, clit->second.pars != &pars ? clit->second.pars : clit->second.pars->clone() , Trk::TrackStateOnSurface::Measurement ); -// addMeasurements ? Trk::TrackStateOnSurface::Measurement : Trk::TrackStateOnSurface::Outlier ); - states.push_back( std::make_pair(true,tsos) ); - ATH_MSG_VERBOSE(" added hit " << m_idHelperTool->toString(clit->second.clus->identify())); + // addMeasurements ? Trk::TrackStateOnSurface::Measurement : Trk::TrackStateOnSurface::Outlier ); + states.push_back( std::make_pair(true, tsos) ); + ATH_MSG_VERBOSE(" added hit " << m_idHelperTool->toString(clit->second.clus->identify())); ++nNewHits; } - + unsigned int nholes = 0; std::set<Identifier>::iterator hit = chHoles.begin(); std::set<Identifier>::iterator hit_end = chHoles.end(); - for( ;hit!=hit_end;++hit ){ + for ( ; hit != hit_end; ++hit ) { const Identifier& id = *hit; - - if( clusterLayerMap.count(id) ) continue; + + if ( clusterLayerMap.count(id) ) continue; // if no detEl yet try retrieving if from the detMgr - if( !detEl ) { - if( m_idHelperTool->isTgc(id) ) detEl = m_detMgr->getTgcReadoutElement(id); - else if( m_idHelperTool->isRpc(id) ) detEl = m_detMgr->getRpcReadoutElement(id); - else if( m_idHelperTool->isCsc(id) ) detEl = m_detMgr->getCscReadoutElement(id); - if( !detEl ){ + if ( !detEl ) { + if ( m_idHelperTool->isTgc(id) ) detEl = m_detMgr->getTgcReadoutElement(id); + else if ( m_idHelperTool->isRpc(id) ) detEl = m_detMgr->getRpcReadoutElement(id); + else if ( m_idHelperTool->isCsc(id) ) detEl = m_detMgr->getCscReadoutElement(id); + // New Small Wheel + else if ( m_idHelperTool->issTgc(id) ) detEl = m_detMgr->getsTgcReadoutElement(id); + else if ( m_idHelperTool->isMM(id) ) detEl = m_detMgr->getMMReadoutElement(id); + + + if ( !detEl ) { ATH_MSG_DEBUG("No detector element found for " << m_idHelperTool->toString(id) ); continue; } } const Trk::Surface& surf = detEl->surface(id); - + const Trk::TrackParameters* exPars = 0; - if( pars.associatedSurface() == surf ) { + if ( pars.associatedSurface() == surf ) { ATH_MSG_DEBUG(" Same surface, cloning parameters " ); exPars = &pars; - }else{ - exPars = m_extrapolator->extrapolateDirectly(pars,surf,Trk::anyDirection,false,Trk::muon); - if( !exPars ) { + } else { + exPars = m_extrapolator->extrapolateDirectly(pars, surf, Trk::anyDirection, false, Trk::muon); + if ( !exPars ) { ATH_MSG_DEBUG(" Propagation cluster hole failed!! "); continue; } parsToBeDeleted.push_back(exPars); } - + bool inBounds = false; - Amg::Vector2D locPos; - if( surf.globalToLocal(exPars->position(),exPars->momentum(),locPos) ){ - inBounds = surf.insideBounds(locPos,-100.,-100.); + Amg::Vector2D locPos;; + if ( surf.globalToLocal(exPars->position(), exPars->momentum(), locPos) ) { + inBounds = surf.insideBounds(locPos, -100., -100.); } - if( msgLvl(MSG::VERBOSE) ) { + if ( msgLvl(MSG::VERBOSE) ) { std::string boundStr = inBounds ? " inside bounds " : " outside bounds "; - ATH_MSG_VERBOSE(" new hole " << m_idHelperTool->toString(id) << " position " + ATH_MSG_VERBOSE(" new hole " << m_idHelperTool->toString(id) << " position " << exPars->parameters()[Trk::locR] << boundStr); } - - if( !inBounds ){ + + if ( !inBounds ) { continue; } + if ( msgLvl(MSG::VERBOSE) ) if (m_idHelperTool->issTgc(id)) ATH_MSG_VERBOSE(" new hole sTgc measuresPhi " << (int) m_idHelperTool->measuresPhi(id)); Trk::TrackStateOnSurface* tsos = MuonTSOSHelper::createHoleTSOS(exPars->clone()); - states.push_back( std::make_pair(true,tsos) ); + states.push_back( std::make_pair(true, tsos) ); ++nholes; //break; // only add one hole per det el } ATH_MSG_DEBUG(" chamber " << m_idHelperTool->toStringChamber(detElId) << " added hits " << nNewHits << " found holes " << nholes ); - + // clean up parameters std::for_each( parsToBeDeleted.begin(), parsToBeDeleted.end(), MuonDeleteObject<const Trk::TrackParameters>() ); @@ -842,204 +977,197 @@ MuonChamberHoleRecoveryTool::insertMdtsWithHoleSearch( std::vector<const Trk::Tr void MuonChamberHoleRecoveryTool::createHoleTSOSsForMdtChamber( const Identifier& chId, const Trk::TrackParameters& pars, const Trk::TrackParameters* parsLast, - std::set<Identifier>& ids, - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >& states ) const { - + std::set<Identifier>& ids, + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >& states ) const { + Amg::Vector3D direction = pars.momentum().unit(); - + // check whether we need to average the parameters - if( parsLast ) direction = (parsLast->position() - pars.position()).unit(); - - std::set<Identifier> chHoles = holesInMdtChamber( pars.position(),direction,chId,ids ); + if ( parsLast ) direction = (parsLast->position() - pars.position()).unit(); + std::set<Identifier> chHoles = holesInMdtChamber( pars.position(), direction, chId, ids ); ATH_MSG_VERBOSE(" chamber " << m_idHelperTool->toStringChamber(chId) << " has holes " << chHoles.size() ); - if( chHoles.empty() ) return; - - + if ( chHoles.empty() ) return; + + unsigned int nholes = 0; unsigned int nstates = 0; - + std::vector<const Trk::TrackParameters*> parsToBeDeleted; parsToBeDeleted.reserve(10); - + // set to store chambers that were already handled std::set<Identifier> chIds; - + // loop over holes, find prd data collection belonging to hole, recover hole std::set<Identifier>::iterator hit = chHoles.begin(); std::set<Identifier>::iterator hit_end = chHoles.end(); - for( ;hit!=hit_end; ++hit ){ - + for ( ; hit != hit_end; ++hit ) { + // only handle chamers once Identifier chIdentifier = m_idHelperTool->chamberId(*hit); - if( chIds.count(chIdentifier) ) continue; + if ( chIds.count(chIdentifier) ) continue; chIds.insert(chIdentifier); // loop over Mdt Prds and try to find prds of tubes with holes const MdtPrepDataCollection* mdtPrdCol = findMdtPrdCollection( chIdentifier ); - if( !mdtPrdCol ) { + if ( !mdtPrdCol ) { ATH_MSG_DEBUG(" Retrieval of MdtPrepDataCollection failed!! " ); break; } - + std::set<Identifier> associatedHoles; // holes in tubes that also have a prd - + MdtPrepDataCollection::const_iterator pit = mdtPrdCol->begin(); MdtPrepDataCollection::const_iterator pit_end = mdtPrdCol->end(); - for( ;pit!=pit_end; ++pit ){ + for ( ; pit != pit_end; ++pit ) { const MdtPrepData& mdtPrd = **pit; const Identifier& id = mdtPrd.identify(); // only consider holes - if( !chHoles.count(id) ) continue; + if ( !chHoles.count(id) ) continue; // ensure that Identifiers are not added twice - if( associatedHoles.count(id) ) continue; - + if ( associatedHoles.count(id) ) continue; + const Trk::Surface& surf = mdtPrd.detectorElement()->surface(id); - + const Trk::TrackParameters* exPars = 0; - if( pars.associatedSurface() == surf ){ + if ( pars.associatedSurface() == surf ) { exPars = &pars; - }else{ - exPars = m_extrapolator->extrapolateDirectly(pars,surf,Trk::anyDirection,false,Trk::muon); - if( !exPars ) { + } else { + exPars = m_extrapolator->extrapolateDirectly(pars, surf, Trk::anyDirection, false, Trk::muon); + if ( !exPars ) { ATH_MSG_WARNING(" Propagation to MDT prd failed!! "); continue; } parsToBeDeleted.push_back(exPars); } - + // calibrate Mdt PRD - const MdtDriftCircleOnTrack* mdtROT = m_mdtRotCreator->createRIO_OnTrack(mdtPrd,exPars->position(),&(exPars->momentum())); + const MdtDriftCircleOnTrack* mdtROT = m_mdtRotCreator->createRIO_OnTrack(mdtPrd, exPars->position(), &(exPars->momentum())); // sanity check - if( !mdtROT ){ + if ( !mdtROT ) { ATH_MSG_DEBUG(" failed to calibrate MdtPrepData " << m_idHelperTool->toString(id) ); continue; } - - + + const Trk::StraightLineSurface* slSurf = dynamic_cast<const Trk::StraightLineSurface*>( &mdtROT->associatedSurface() ); - if( !slSurf ){ + if ( !slSurf ) { ATH_MSG_WARNING(" dynamic cast to StraightLineSurface failed for mdt!!! " ); - }else{ + } else { // calculate Amg::Vector2D using surf to obtain sign Amg::Vector2D locPos; - if( !slSurf->globalToLocal(exPars->position(),exPars->momentum(),locPos) ){ + if ( !slSurf->globalToLocal(exPars->position(), exPars->momentum(), locPos) ) { ATH_MSG_DEBUG(" failed to calculate drift sign " ); - }else{ + } else { // calculate side Trk::DriftCircleSide side = locPos[Trk::driftRadius] < 0 ? Trk::LEFT : Trk::RIGHT; - - // cast away constness + + // cast away constness MdtDriftCircleOnTrack* changeMdtROT = const_cast<MdtDriftCircleOnTrack*>(mdtROT); // sanity check -// if( !changeMdtROT ){ -// ATH_MSG_WARNING(" failed to cast away constness of mdtROt " << m_idHelperTool->toString(id) ); -// continue; -// } - + // if( !changeMdtROT ){ + // ATH_MSG_WARNING(" failed to cast away constness of mdtROt " << m_idHelperTool->toString(id) ); + // continue; + // } + // update sign m_mdtRotCreator->updateSign( *changeMdtROT, side ); } } - + // check whether MDT ROT has sagged wire surface, if so redo propagation - if( slSurf != &mdtPrd.detectorElement()->surface(id) ){ - exPars = m_extrapolator->extrapolateDirectly(pars,*slSurf,Trk::anyDirection,false,Trk::muon); - if( !exPars ) { + if ( slSurf != &mdtPrd.detectorElement()->surface(id) ) { + exPars = m_extrapolator->extrapolateDirectly(pars, *slSurf, Trk::anyDirection, false, Trk::muon); + if ( !exPars ) { ATH_MSG_WARNING( " Propagation to sagged surface failed!! "); continue; } parsToBeDeleted.push_back(exPars); } - - if( msgLvl(MSG::VERBOSE) ) { + + if ( msgLvl(MSG::VERBOSE) ) { DistanceToPars distToPars(&pars); double distance = distToPars(exPars->position()); - msg(MSG::VERBOSE) << std::setprecision(4) - << " radius " << std::setw(7) << mdtROT->localParameters()[Trk::locR] + msg(MSG::VERBOSE) << std::setprecision(4) + << " radius " << std::setw(7) << mdtROT->localParameters()[Trk::locR] << " exPos " << std::setw(7) << exPars->parameters()[Trk::locR] << " distToPar " << distance << " "; } - + // pointer to resPull const Trk::ResidualPull* resPull = m_pullCalculator->residualPull( mdtROT, exPars, Trk::ResidualPull::Unbiased ); - if( !resPull ){ + if ( !resPull ) { delete mdtROT; continue; } - - + + double pull = resPull->pull().front(); double radialResidual = fabs(mdtROT->localParameters()[Trk::locR]) - fabs(exPars->parameters()[Trk::locR]); - + unsigned int hitFlag = 1; - if( mdtPrd.adc() < m_adcCut || mdtPrd.status() != MdtStatusDriftTime ) hitFlag = 3; // noise - else if( fabs(pull) < m_associationPullCutEta ) hitFlag = 0; // hit on track - else if( radialResidual > 0. ) hitFlag = 2; // out of time - - // else { - // // replace hit by tube hit - // delete mdtROT; - // mdtROT = m_tubeRotCreator->createRIO_OnTrack(mdtPrd,exPars->position()); - // } - + if ( mdtPrd.adc() < m_adcCut || mdtPrd.status() != MdtStatusDriftTime ) hitFlag = 3; // noise + else if ( fabs(pull) < m_associationPullCutEta ) hitFlag = 0; // hit on track + else if ( radialResidual > 0. ) hitFlag = 2; // out of time + bool inBounds = false; // calculate Amg::Vector2D using surf to obtain sign Amg::Vector2D locPos; - if( mdtROT->associatedSurface().globalToLocal(exPars->position(),exPars->momentum(),locPos) ){ + if ( mdtROT->associatedSurface().globalToLocal(exPars->position(), exPars->momentum(), locPos) ) { inBounds = mdtROT->associatedSurface().insideBounds(locPos); } - if( msgLvl(MSG::VERBOSE) ){ + if ( msgLvl(MSG::VERBOSE) ) { std::string idString = m_idHelperTool->toString( id ); - std::string boundCheck = inBounds ? "inBounds" : "outBounds"; + std::string boundCheck = inBounds ? "inBounds" : "outBounds"; msg(MSG::VERBOSE) << m_printer->print( *resPull ) << " " << idString << " " << boundCheck; std::string hitType = " delta"; - if( hitFlag == 0 ) hitType = " ROT"; - else if( hitFlag == 2 ) hitType = " Out of Time"; - else if( hitFlag == 3 ) hitType = " Noise"; + if ( hitFlag == 0 ) hitType = " ROT"; + else if ( hitFlag == 2 ) hitType = " Out of Time"; + else if ( hitFlag == 3 ) hitType = " Noise"; msg(MSG::VERBOSE) << hitType << endmsg; } delete resPull; - + // if we get here we are sure that this is not a hole associatedHoles.insert(id); - if( !inBounds ) { + if ( !inBounds ) { delete mdtROT; continue; } - Trk::TrackStateOnSurface* tsos = MuonTSOSHelper::createMeasTSOS( mdtROT, exPars->clone(), - (hitFlag != 0 || !m_addMeasurements) ? + Trk::TrackStateOnSurface* tsos = MuonTSOSHelper::createMeasTSOS( mdtROT, exPars->clone(), + (hitFlag != 0 || !m_addMeasurements) ? Trk::TrackStateOnSurface::Outlier : Trk::TrackStateOnSurface::Measurement ); - states.push_back( std::make_pair(true,tsos) ); + states.push_back( std::make_pair(true, tsos) ); ++nstates; - if( nstates == chHoles.size() ) { + if ( nstates == chHoles.size() ) { ATH_MSG_DEBUG(" recovered Mdts " << nstates << " all holes recovered " << nholes ); // clean up parameters std::for_each( parsToBeDeleted.begin(), parsToBeDeleted.end(), MuonDeleteObject<const Trk::TrackParameters>() ); return; } } - + std::set<Identifier>::iterator hit = chHoles.begin(); std::set<Identifier>::iterator hit_end = chHoles.end(); - for( ;hit!=hit_end;++hit ){ - if( associatedHoles.count(*hit) ) continue; + for ( ; hit != hit_end; ++hit ) { + if ( associatedHoles.count(*hit) ) continue; // only create holes in the current chamber Identifier ch = m_idHelperTool->chamberId(*hit); - if( ch != chIdentifier ) continue; + if ( ch != chIdentifier ) continue; const MuonGM::MdtReadoutElement* detEl = m_detMgr->getMdtReadoutElement(*hit); const Trk::Surface& surf = detEl->surface(*hit); - + const Trk::TrackParameters* exPars = 0; - if( pars.associatedSurface() == surf ){ + if ( pars.associatedSurface() == surf ) { exPars = &pars; - }else{ - exPars = m_extrapolator->extrapolateDirectly(pars,surf,Trk::anyDirection,false,Trk::muon); - if( !exPars ) { + } else { + exPars = m_extrapolator->extrapolateDirectly(pars, surf, Trk::anyDirection, false, Trk::muon); + if ( !exPars ) { ATH_MSG_WARNING(" Propagation to MDT hole failed!! "); continue; } @@ -1048,75 +1176,75 @@ MuonChamberHoleRecoveryTool::insertMdtsWithHoleSearch( std::vector<const Trk::Tr bool inBounds = false; Amg::Vector2D locPos; - if( surf.globalToLocal(exPars->position(),exPars->momentum(),locPos) ){ + if ( surf.globalToLocal(exPars->position(), exPars->momentum(), locPos) ) { // perform bound check do not count holes with 100. mm of bound edge - inBounds = surf.bounds().insideLoc2(locPos,-100.); - if( inBounds ) { - if( fabs( locPos[Trk::locR] ) > 14.4 ) inBounds = false; + inBounds = surf.bounds().insideLoc2(locPos, -100.); + if ( inBounds ) { + if ( fabs( locPos[Trk::locR] ) > 14.4 ) inBounds = false; } } - if( !inBounds ){ - ATH_MSG_VERBOSE(" discarding hole " << m_idHelperTool->toString(*hit) << " dist wire " - << exPars->parameters()[Trk::locR] << " outside bounds " ); + if ( !inBounds ) { + ATH_MSG_VERBOSE(" discarding hole " << m_idHelperTool->toString(*hit) << " dist wire " + << exPars->parameters()[Trk::locR] << " outside bounds " ); continue; } - ATH_MSG_VERBOSE(" new hole " << m_idHelperTool->toString(*hit) << " dist wire " - << exPars->parameters()[Trk::locR] ); + ATH_MSG_VERBOSE(" new hole " << m_idHelperTool->toString(*hit) << " dist wire " + << exPars->parameters()[Trk::locR] ); Trk::TrackStateOnSurface* tsos = MuonTSOSHelper::createHoleTSOS(exPars->clone()); - states.push_back( std::make_pair(true,tsos) ); + states.push_back( std::make_pair(true, tsos) ); ++nholes; ++nstates; - } + } } ATH_MSG_DEBUG(" new states " << nstates << " number of holes " << nholes ); - + // clean up parameters std::for_each( parsToBeDeleted.begin(), parsToBeDeleted.end(), MuonDeleteObject<const Trk::TrackParameters>() ); - + } - MuonChamberHoleRecoveryTool::LayerHoleVec + MuonChamberHoleRecoveryTool::LayerHoleVec MuonChamberHoleRecoveryTool::holesInClusterChamber( const Trk::TrackParameters& /*pars*/, const Identifier& /*detElId*/, const std::set<Identifier>& layIds, unsigned nGasGaps ) const { LayerHoleVec holes; // if the number of layers is equal to the number of gas gaps times two in the chamber, there are no holes - if( layIds.size() == 2*nGasGaps ) return holes; - + if ( layIds.size() == 2 * nGasGaps ) return holes; + // create layer matrix - typedef std::vector< std::pair<int,int> > LayerMatrix; - LayerMatrix layerMatrix(nGasGaps,std::make_pair(0,0)); + typedef std::vector< std::pair<int, int> > LayerMatrix; + LayerMatrix layerMatrix(nGasGaps, std::make_pair(0, 0)); // loop over layer identifiers and fill std::set<Identifier>::const_iterator it = layIds.begin(); std::set<Identifier>::const_iterator it_end = layIds.end(); - for( ;it!=it_end; ++it ){ + for ( ; it != it_end; ++it ) { int gasGap = m_idHelperTool->gasGap(*it); bool measuresPhi = m_idHelperTool->measuresPhi(*it); // sanity check - if( gasGap < 0 && gasGap >= (int)nGasGaps ){ + if ( gasGap < 0 && gasGap >= (int)nGasGaps ) { ATH_MSG_WARNING(" gas gap index out of range " << m_idHelperTool->toString(*it) ); continue; } // counter starts at 1! - if( measuresPhi ) layerMatrix[gasGap-1].second = 1; - else layerMatrix[gasGap-1].first = 1; + if ( measuresPhi ) layerMatrix[gasGap - 1].second = 1; + else layerMatrix[gasGap - 1].first = 1; } - + // loop over the matrix, if a field is zero we have a hole. unsigned int gasGap = 1; LayerMatrix::iterator lit = layerMatrix.begin(); LayerMatrix::iterator lit_end = layerMatrix.end(); - for( ;lit!=lit_end;++lit ){ + for ( ; lit != lit_end; ++lit ) { // check whether the eta or phi hit is missing, create a hole if that is the case - if( !lit->first ) holes.push_back( std::make_pair(gasGap,0) ); - if( !lit->second ) holes.push_back( std::make_pair(gasGap,1) ); + if ( !lit->first ) holes.push_back( std::make_pair(gasGap, 0) ); + if ( !lit->second ) holes.push_back( std::make_pair(gasGap, 1) ); ++gasGap; } - return holes; + return holes; } @@ -1124,31 +1252,29 @@ MuonChamberHoleRecoveryTool::insertMdtsWithHoleSearch( std::vector<const Trk::Tr const Amg::Vector3D& direction, const Identifier& chId, const std::set<Identifier>& tubeIds ) const { - + // calculate crossed tubes const MuonStationIntersect& intersect = m_intersectSvc->tubesCrossedByTrack( chId, position, direction ); // clear hole vector std::set<Identifier> holes; - for( unsigned int ii=0;ii<intersect.tubeIntersects().size();++ii ){ + for ( unsigned int ii = 0; ii < intersect.tubeIntersects().size(); ++ii ) { const MuonTubeIntersect& tint = intersect.tubeIntersects()[ii]; - - //if( m_idHelperTool->chamberId(tint.tubeId) != chId ) continue; - - if( tubeIds.count( tint.tubeId ) ) { + + if ( tubeIds.count( tint.tubeId ) ) { continue; } - if( msgLvl(MSG::VERBOSE) ){ - msg(MSG::VERBOSE) << " intersect " << m_idHelperTool->toString(tint.tubeId) + if ( msgLvl(MSG::VERBOSE) ) { + msg(MSG::VERBOSE) << " intersect " << m_idHelperTool->toString(tint.tubeId) << " dist wire " << tint.rIntersect << " dist to tube end " << tint.xIntersect; } - if( fabs( tint.rIntersect ) > 14.4 || tint.xIntersect > -10. ){ + if ( fabs( tint.rIntersect ) > 14.4 || tint.xIntersect > -10. ) { ATH_MSG_VERBOSE(" not counted" ); - }else{ - // check whether there is a hit in this tube - + } else { + // check whether there is a hit in this tube + ATH_MSG_VERBOSE(" hole tube" ); - + holes.insert( tint.tubeId ); } } @@ -1170,18 +1296,18 @@ MuonChamberHoleRecoveryTool::insertMdtsWithHoleSearch( std::vector<const Trk::Tr } IdentifierHash hash_id; m_idHelperTool->mdtIdHelper().get_module_hash(chId,hash_id ); - + MdtPrepDataContainer::const_iterator colIt = mdtPrdContainer->indexFind(hash_id); if( colIt == mdtPrdContainer->end() ){ - ATH_MSG_DEBUG(" MdtPrepDataCollection for: " << m_idHelperTool->toStringChamber(chId) - << " not found in container " ); + ATH_MSG_DEBUG(" MdtPrepDataCollection for: " << m_idHelperTool->toStringChamber(chId) + << " not found in container " ); return 0; } return *colIt; } const CscPrepDataCollection* MuonChamberHoleRecoveryTool::findCscPrdCollection( const Identifier& detElId ) const { - + SG::ReadHandle<Muon::CscPrepDataContainer> h_cscPrdCont(m_key_csc); const Muon::CscPrepDataContainer *cscPrdContainer; if (h_cscPrdCont.isValid()) { @@ -1193,11 +1319,11 @@ MuonChamberHoleRecoveryTool::insertMdtsWithHoleSearch( std::vector<const Trk::Tr } IdentifierHash hash_id; m_idHelperTool->cscIdHelper().get_module_hash(detElId,hash_id ); - + CscPrepDataContainer::const_iterator colIt = cscPrdContainer->indexFind(hash_id); if( colIt == cscPrdContainer->end() ){ - ATH_MSG_DEBUG(" CscPrepDataCollection for: " << m_idHelperTool->toStringChamber(detElId) - << " not found in container " ); + ATH_MSG_DEBUG(" CscPrepDataCollection for: " << m_idHelperTool->toStringChamber(detElId) + << " not found in container " ); return 0; } return *colIt; @@ -1227,7 +1353,7 @@ MuonChamberHoleRecoveryTool::insertMdtsWithHoleSearch( std::vector<const Trk::Tr } const RpcPrepDataCollection* MuonChamberHoleRecoveryTool::findRpcPrdCollection( const Identifier& detElId ) const { - + SG::ReadHandle<Muon::RpcPrepDataContainer> h_rpcPrdCont(m_key_rpc); const Muon::RpcPrepDataContainer *rpcPrdContainer; if(h_rpcPrdCont.isValid()) { @@ -1247,6 +1373,51 @@ MuonChamberHoleRecoveryTool::insertMdtsWithHoleSearch( std::vector<const Trk::Tr return *colIt; } + const sTgcPrepDataCollection* MuonChamberHoleRecoveryTool::findStgcPrdCollection( const Identifier& detElId ) const { + + SG::ReadHandle<Muon::sTgcPrepDataContainer> h_stgcPrdCont(m_key_stgc); + const Muon::sTgcPrepDataContainer *stgcPrdContainer; + if (h_stgcPrdCont.isValid()) { + stgcPrdContainer = h_stgcPrdCont.cptr(); + } + else{ + ATH_MSG_WARNING("Cannot retrieve stgcPrepDataContainer " << m_key_stgc.key() ); + return 0; + } + IdentifierHash hash_id; + m_idHelperTool->stgcIdHelper().get_module_hash(detElId, hash_id ); + + sTgcPrepDataContainer::const_iterator colIt = stgcPrdContainer->indexFind(hash_id); + if ( colIt == stgcPrdContainer->end() ) { + ATH_MSG_DEBUG(" StgcPrepDataCollection for: " << m_idHelperTool->toStringChamber(detElId) + << " not found in container " ); + return 0; + } + return *colIt; + } + + const MMPrepDataCollection* MuonChamberHoleRecoveryTool::findMmPrdCollection( const Identifier& detElId ) const { + SG::ReadHandle<Muon::MMPrepDataContainer> h_mmPrdCont(m_key_mm); + const Muon::MMPrepDataContainer *mmPrdContainer; + if (h_mmPrdCont.isValid()) { + mmPrdContainer = h_mmPrdCont.cptr(); + } + else{ + ATH_MSG_WARNING("Cannot retrieve stgcPrepDataContainer " << m_key_mm.key() ); + return 0; + } + + IdentifierHash hash_id; + m_idHelperTool->mmIdHelper().get_module_hash(detElId, hash_id ); + + MMPrepDataContainer::const_iterator colIt = mmPrdContainer->indexFind(hash_id); + if ( colIt == mmPrdContainer->end() ) { + ATH_MSG_DEBUG(" MmPrepDataCollection for: " << m_idHelperTool->toStringChamber(detElId) + << " not found in container " ); + return 0; + } + return *colIt; + } } diff --git a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonChamberHoleRecoveryTool.h b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonChamberHoleRecoveryTool.h index 87d8c37f77ff015ee6680a429826e2b10d057a20..c8ca59eceba12e76467342d19b7a13995bc7e8ad 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonChamberHoleRecoveryTool.h +++ b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonChamberHoleRecoveryTool.h @@ -32,6 +32,9 @@ class RpcIdHelper; class MdtIdHelper; class CscIdHelper; class TgcIdHelper; +// New Small Wheel +class sTgcIdHelper; +class MmIdHelper; namespace MuonGM { class MuonDetectorManager; @@ -75,7 +78,7 @@ namespace Muon { /** @brief destructor */ virtual ~MuonChamberHoleRecoveryTool (); - /** @brief AlgTool initilize */ + /** @brief AlgTool initialize */ StatusCode initialize(); /** @brief AlgTool finalize */ @@ -149,6 +152,16 @@ namespace Muon { void createHoleTSOSsForRpcChamber( const Identifier& detElId, const Trk::TrackParameters& pars, std::set<Identifier>& layIds, std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >& states ) const; + + // New Small Wheel + void createHoleTSOSsForStgcChamber( const Identifier& detElId, const Trk::TrackParameters& pars, + std::set<Identifier>& layIds, + std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >& states ) const; + + void createHoleTSOSsForMmChamber( const Identifier& detElId, const Trk::TrackParameters& pars, + std::set<Identifier>& layIds, + std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >& states ) const; + void createHoleTSOSsForClusterChamber( const Identifier& detElId, const Trk::TrackParameters& pars, std::set<Identifier>& layIds, std::set<Identifier>& chHoles, @@ -164,6 +177,9 @@ namespace Muon { const CscPrepDataCollection* findCscPrdCollection( const Identifier& detElId ) const; const TgcPrepDataCollection* findTgcPrdCollection( const Identifier& detElId ) const; const RpcPrepDataCollection* findRpcPrdCollection( const Identifier& detElId ) const; + // New Small Wheel + const sTgcPrepDataCollection* findStgcPrdCollection( const Identifier& detElId ) const; + const MMPrepDataCollection* findMmPrdCollection( const Identifier& detElId ) const; ServiceHandle<MuonStationIntersectSvc> m_intersectSvc; //<! pointer to hole search service @@ -179,11 +195,12 @@ namespace Muon { const MuonGM::MuonDetectorManager* m_detMgr; - SG::ReadHandleKey<Muon::MdtPrepDataContainer> m_key_mdt; //!< storegate location of the MdtPrepData - SG::ReadHandleKey<Muon::CscPrepDataContainer> m_key_csc; //!< storegate location of the CscPrepData - SG::ReadHandleKey<Muon::TgcPrepDataContainer> m_key_tgc; //!< storegate location of the TgcPrepData - SG::ReadHandleKey<Muon::RpcPrepDataContainer> m_key_rpc; //!< storegate location of the RpcPrepData - + SG::ReadHandleKey<Muon::MdtPrepDataContainer> m_key_mdt{this,"MdtPrepDataContainer","MDT_DriftCircles","MDT PRDs"}; + SG::ReadHandleKey<Muon::CscPrepDataContainer> m_key_csc{this,"CscPrepDataContainer","CSC_Clusters","CSC PRDS"}; + SG::ReadHandleKey<Muon::TgcPrepDataContainer> m_key_tgc{this,"TgcPrepDataContainer","TGC_Measurements","TGC PRDs"}; + SG::ReadHandleKey<Muon::RpcPrepDataContainer> m_key_rpc{this,"RpcPrepDataContainer","RPC_Measurements","RPC PRDs"}; + SG::ReadHandleKey<Muon::sTgcPrepDataContainer> m_key_stgc{this,"sTgcPrepDataContainer","STGC_Measurements","sTGC PRDs"}; + SG::ReadHandleKey<Muon::MMPrepDataContainer> m_key_mm{this,"MMPrepDataContainer","MM_Measurements","MM PRDs"}; bool m_addMeasurements; double m_associationPullCutEta; diff --git a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSeededSegmentFinder.cxx b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSeededSegmentFinder.cxx index 3e0fc3a3bc0227fd69f46c7ab8fc3f75ee804920..11d44de1450b42d7478ccbd3b8a245910f17bb72 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSeededSegmentFinder.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSeededSegmentFinder.cxx @@ -58,16 +58,12 @@ namespace Muon { declareProperty("Propagator", m_propagator ); declareProperty("SegmentMaker", m_segMaker); declareProperty("SegmentMakerNoHoles", m_segMakerNoHoles); - declareProperty("MdtPrepDataContainer", m_key_mdt="MDT_DriftCircles"); - declareProperty("RpcPrepDataContainer", m_key_rpc="RPC_Measurements"); - declareProperty("TgcPrepDataContainer", m_key_tgc="TGC_Measurements"); - declareProperty("CscPrepDataContainer", m_key_csc="CSC_Clusters"); declareProperty("AdcCut", m_adcCut = 50 ); declareProperty("MdtSigmaFromTrack",m_maxSigma = 3); } - MuonSeededSegmentFinder::~MuonSeededSegmentFinder(){} + MuonSeededSegmentFinder::~MuonSeededSegmentFinder() {} StatusCode MuonSeededSegmentFinder::initialize() @@ -83,30 +79,33 @@ namespace Muon { ATH_CHECK(m_key_mdt.initialize()); ATH_CHECK(m_key_csc.initialize()); - ATH_CHECK(m_key_rpc.initialize()); ATH_CHECK(m_key_tgc.initialize()); - + ATH_CHECK(m_key_rpc.initialize()); + ATH_CHECK(m_key_stgc.initialize()); + ATH_CHECK(m_key_mm.initialize()); + return StatusCode::SUCCESS; } + + StatusCode MuonSeededSegmentFinder::finalize() { return StatusCode::SUCCESS; } - std::vector<const MuonSegment*>* MuonSeededSegmentFinder::find( const Trk::TrackParameters& pars, const std::set<Identifier>& chIds ) const { // get MdtPrepData collections correspondign to the chamber Identifiers std::vector<const MdtPrepData*> mdtPrds = extractPrds( chIds ); - - if( mdtPrds.empty() ){ + + if ( mdtPrds.empty() ) { ATH_MSG_DEBUG(" no MdtPrepData found "); return 0; } - + // find segments - return find(pars,mdtPrds); + return find(pars, mdtPrds); } std::vector<const MuonSegment*>* MuonSeededSegmentFinder::find( const Trk::TrackParameters& pars, const std::set<IdentifierHash>& chIdHs ) const { @@ -114,17 +113,17 @@ namespace Muon { // get MdtPrepData collections correspondign to the chamber Identifiers std::vector<const MdtPrepData*> mdtPrds = extractPrds( chIdHs ); - if( mdtPrds.empty() ){ + if ( mdtPrds.empty() ) { ATH_MSG_DEBUG(" no MdtPrepData found "); return 0; } - + // find segments - return find(pars,mdtPrds); + return find(pars, mdtPrds); } - - std::vector<const MuonSegment*>* MuonSeededSegmentFinder::find( const Trk::TrackParameters& pars, + + std::vector<const MuonSegment*>* MuonSeededSegmentFinder::find( const Trk::TrackParameters& pars, const std::vector<const MdtPrepData*>& mdtPrds ) const { // are we close to the chamber edge? @@ -135,38 +134,38 @@ namespace Muon { mdtROTs.reserve( mdtPrds.size() ); selectAndCalibrate( pars, mdtPrds, mdtROTs, doHoleSearch ); - if( mdtROTs.empty() ){ + if ( mdtROTs.empty() ) { ATH_MSG_DEBUG(" no MdtDriftCircles selected "); return 0; } // create track road double roadWidthEta = 1.; - if( pars.covariance() ){ - double trackError = Amg::error(*pars.covariance(),Trk::theta); + if ( pars.covariance() ) { + double trackError = Amg::error(*pars.covariance(), Trk::theta); ATH_MSG_DEBUG(" local track Error on theta " << trackError); - if( trackError < 0.2 ) trackError = 0.2; + if ( trackError < 0.2 ) trackError = 0.2; roadWidthEta = 5.*trackError; } Trk::TrackRoad road( pars.position(), pars.momentum(), roadWidthEta, 1. ); - + // create dummy vector<vector> std::vector< std::vector<const MdtDriftCircleOnTrack*> > mdtROTsVec; mdtROTsVec.push_back(mdtROTs); std::vector< std::vector<const MuonClusterOnTrack*> > clusterROTsVec; // call segment finder - std::vector<const MuonSegment*>* segments = doHoleSearch ? + std::vector<const MuonSegment*>* segments = doHoleSearch ? m_segMaker->find( road, mdtROTsVec, clusterROTsVec, true ) : m_segMakerNoHoles->find( road, mdtROTsVec, clusterROTsVec, true ); - + // delete ROTs std::for_each( mdtROTs.begin(), mdtROTs.end(), MuonDeleteObject<const MdtDriftCircleOnTrack>() ); - if( !segments ){ + if ( !segments ) { ATH_MSG_DEBUG(" No segments found "); return 0; - }else{ + } else { ATH_MSG_DEBUG(" Number of segments found: " << segments->size() << std::endl << m_printer->print(*segments)); } @@ -176,32 +175,32 @@ namespace Muon { std::vector<const MdtPrepData*> MuonSeededSegmentFinder::extractPrds( const std::set<Identifier>& chIds ) const { // set of IdHashes corresponding to these identifiers std::set<IdentifierHash> chIdHs; - + // loop over chambers and get collections std::set<Identifier>::const_iterator chit = chIds.begin(); std::set<Identifier>::const_iterator chit_end = chIds.end(); - for( ;chit!=chit_end;++chit ){ - - if( !m_idHelper->isMdt(*chit) ) { + for ( ; chit != chit_end; ++chit ) { + + if ( !m_idHelper->isMdt(*chit) ) { ATH_MSG_WARNING(" Requested chamber is not an MDT: " << m_idHelper->toStringChamber(*chit)); continue; } - + const MuonGM::MdtReadoutElement* detEl = m_detMgr->getMdtReadoutElement(*chit); - if( !detEl ) { + if ( !detEl ) { ATH_MSG_WARNING(" Requested chamber does not exist in geometry: " << m_idHelper->toStringChamber(*chit)); continue; } IdentifierHash hash_id = detEl->collectionHash(); chIdHs.insert(hash_id); } - - // vector to store pointers to collections + + // vector to store pointers to collections std::vector<const MdtPrepData*> mdtPrds = extractPrds( chIdHs ); - + return mdtPrds; - } - + } + std::vector<const MdtPrepData*> MuonSeededSegmentFinder::extractPrds( const std::set<IdentifierHash>& chIdHs ) const { SG::ReadHandle<Muon::MdtPrepDataContainer> h_mdtPrdCont(m_key_mdt); @@ -266,6 +265,7 @@ namespace Muon { } } + void MuonSeededSegmentFinder::extractRpcPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const RpcPrepDataCollection*>& target ) const { @@ -299,6 +299,7 @@ namespace Muon { } } + void MuonSeededSegmentFinder::extractTgcPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const TgcPrepDataCollection*>& target ) const { @@ -332,6 +333,7 @@ namespace Muon { } } + void MuonSeededSegmentFinder::extractCscPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const CscPrepDataCollection*>& target ) const { @@ -366,45 +368,145 @@ namespace Muon { } } - void MuonSeededSegmentFinder::selectAndCalibrate( const Trk::TrackParameters& pars, + + // New Small Wheel + // sTGC + void MuonSeededSegmentFinder::extractsTgcPrdCols( const std::set<IdentifierHash>& chIdHs, + std::vector<const sTgcPrepDataCollection*>& target ) const { + + SG::ReadHandle<Muon::sTgcPrepDataContainer> h_stgcPrdCont(m_key_stgc); + const Muon::sTgcPrepDataContainer *stgcPrdContainer; + if(h_stgcPrdCont.isValid()) { + stgcPrdContainer = h_stgcPrdCont.cptr(); + } + else{ + ATH_MSG_WARNING("Cannot retrieve stgcPrepDataContainer " << m_key_stgc.key()); + return; + } + + + // loop over chambers and get collections + std::set<IdentifierHash>::const_iterator chit = chIdHs.begin(); + std::set<IdentifierHash>::const_iterator chit_end = chIdHs.end(); + for( ;chit!=chit_end;++chit ){ + sTgcPrepDataContainer::const_iterator colIt = stgcPrdContainer->indexFind(*chit); + if( colIt == stgcPrdContainer->end() || (*colIt)->empty() ){ + //ATH_MSG_DEBUG(" TgcPrepDataCollection for: " + // << m_idHelper->toStringChamber(*chit) << " not found in container "); + continue; + } + ATH_MSG_DEBUG(" Adding for: " + << m_idHelper->toStringChamber( (*colIt)->front()->identify() ) << " size " + << (*colIt)->size()); + + // reserve space for the new PRDs + target.push_back(*colIt); + } + + if(chIdHs.size()==0) { + // Temp fix because Region selector is not implemented + sTgcPrepDataContainer::const_iterator colIt = stgcPrdContainer->begin(); + sTgcPrepDataContainer::const_iterator colIt_end = stgcPrdContainer->end(); + for ( ; colIt != colIt_end; ++colIt ) { + if((*colIt)->size()>0) { + ATH_MSG_DEBUG(" Adding ALL Prds for: " + << m_idHelper->toStringChamber( (*colIt)->front()->identify() ) << " size " + << (*colIt)->size()); + // reserve space for the new PRDs + target.push_back(*colIt); + } + } + } + } + + // MM + void MuonSeededSegmentFinder::extractMMPrdCols( const std::set<IdentifierHash>& chIdHs, + std::vector<const MMPrepDataCollection*>& target ) const { + + SG::ReadHandle<Muon::MMPrepDataContainer> h_mmPrdCont(m_key_mm); + const Muon::MMPrepDataContainer *mmPrdContainer; + if(h_mmPrdCont.isValid()) { + mmPrdContainer = h_mmPrdCont.cptr(); + } + else{ + ATH_MSG_WARNING("Cannot retrieve mmPrepDataContainer " << m_key_mm.key()); + return; + } + + // loop over chambers and get collections + std::set<IdentifierHash>::const_iterator chit = chIdHs.begin(); + std::set<IdentifierHash>::const_iterator chit_end = chIdHs.end(); + for ( ; chit != chit_end; ++chit ) { + MMPrepDataContainer::const_iterator colIt = mmPrdContainer->indexFind(*chit); + if ( colIt == mmPrdContainer->end() || (*colIt)->empty() ) { + //ATH_MSG_DEBUG(" TgcPrepDataCollection for: " + // << m_idHelper->toStringChamber(*chit) << " not found in container "); + continue; + } + ATH_MSG_DEBUG(" Adding for: " + << m_idHelper->toStringChamber( (*colIt)->front()->identify() ) << " size " + << (*colIt)->size()); + + target.push_back(*colIt); + } + + if(chIdHs.size()==0) { + // Temp fix because Region selector is not implemented + MMPrepDataContainer::const_iterator colIt = mmPrdContainer->begin(); + MMPrepDataContainer::const_iterator colIt_end = mmPrdContainer->end(); + for ( ; colIt != colIt_end; ++colIt ) { + if((*colIt)->size()>0) { + ATH_MSG_DEBUG(" Adding ALL Prds for: " + << m_idHelper->toStringChamber( (*colIt)->front()->identify() ) << " size " + << (*colIt)->size()); + target.push_back(*colIt); + } + } + } + + } + + + + void MuonSeededSegmentFinder::selectAndCalibrate( const Trk::TrackParameters& pars, const std::vector<const MdtPrepData*>& mdtPrdCols, std::vector<const MdtDriftCircleOnTrack*>& mdtROTs, bool& doHoleSearch ) const { - + ATH_MSG_VERBOSE(" in selectAndCalibrate, get PRDs " << mdtPrdCols.size()); // loop over MdtPrepDataCollections std::vector<const MdtPrepData*>::const_iterator mit = mdtPrdCols.begin(); std::vector<const MdtPrepData*>::const_iterator mit_end = mdtPrdCols.end(); - for( ;mit!=mit_end;++mit ){ - if((*mit)->status() != 1) continue; + for ( ; mit != mit_end; ++mit ) { + if ((*mit)->status() != 1) continue; // calibrate MDT const MdtDriftCircleOnTrack* mdt = handleMdtPrd( pars, **mit, doHoleSearch ); - + // not selected - if( !mdt ) continue; - + if ( !mdt ) continue; + mdtROTs.push_back(mdt); } ATH_MSG_VERBOSE(" calibrated " << mdtROTs.size() << " prds out of " << mdtPrdCols.size() ); } - const MdtDriftCircleOnTrack* MuonSeededSegmentFinder::handleMdtPrd( const Trk::TrackParameters& pars, + const MdtDriftCircleOnTrack* MuonSeededSegmentFinder::handleMdtPrd( const Trk::TrackParameters& pars, const MdtPrepData& mdtPrd, bool& doHoleSearch ) const { - + // skip noise hits - if( mdtPrd.adc() < m_adcCut ) return 0; + if ( mdtPrd.adc() < m_adcCut ) return 0; // get surface of PRD const Identifier& id = mdtPrd.identify(); const MuonGM::MdtReadoutElement& detEl = *mdtPrd.detectorElement(); const Trk::StraightLineSurface& surf = detEl.surface(id); - + // propagate segment parameters to first measurement - const Trk::TrackParameters* exPars = m_propagator->propagate(pars,surf,Trk::anyDirection,false,m_magFieldProperties); - if( !exPars ) { + const Trk::TrackParameters* exPars = m_propagator->propagate(pars, surf, Trk::anyDirection, false, m_magFieldProperties); + if ( !exPars ) { ATH_MSG_DEBUG(" Propagation failed!! "); return 0; } @@ -412,68 +514,68 @@ namespace Muon { // calculate position on wire + error double distanceToWire = exPars->parameters()[Trk::locR]; double posAlongWire = exPars->parameters()[Trk::locZ]; - - double errorR = exPars->covariance() ? fabs(Amg::error(*exPars->covariance(),Trk::locR)) : 500.; - double errorZ = exPars->covariance() ? fabs(Amg::error(*exPars->covariance(),Trk::locZ)) : 300.; + + double errorR = exPars->covariance() ? fabs(Amg::error(*exPars->covariance(), Trk::locR)) : 500.; + double errorZ = exPars->covariance() ? fabs(Amg::error(*exPars->covariance(), Trk::locZ)) : 300.; // range check - bool isOnSurface = surf.isOnSurface(exPars->position(),true,5*errorR,5*errorZ); - + bool isOnSurface = surf.isOnSurface(exPars->position(), true, 5 * errorR, 5 * errorZ); + // get tube length int layer = m_idHelper->mdtIdHelper().tubeLayer(id); int tube = m_idHelper->mdtIdHelper().tube(id); - double halfTubeLength = 0.5*detEl.getActiveTubeLength(layer,tube); + double halfTubeLength = 0.5 * detEl.getActiveTubeLength(layer, tube); double tubeRadius = detEl.innerTubeRadius(); // take into account the tube width - double roadWidthR = 5*errorR + 4*tubeRadius; - double roadWidthZ = 5*errorZ + 100.; - - double driftdr = Amg::error(mdtPrd.localCovariance(),Trk::locR); - double nSigmaFromTrack = fabs(fabs(distanceToWire) - mdtPrd.localPosition()[Trk::locR])/sqrt(errorR*errorR+driftdr*driftdr); + double roadWidthR = 5 * errorR + 4 * tubeRadius; + double roadWidthZ = 5 * errorZ + 100.; + + double driftdr = Amg::error(mdtPrd.localCovariance(), Trk::locR); + double nSigmaFromTrack = fabs(fabs(distanceToWire) - mdtPrd.localPosition()[Trk::locR]) / sqrt(errorR * errorR + driftdr * driftdr); - if( msgLvl(MSG::VERBOSE) ) { + if ( msgLvl(MSG::VERBOSE) ) { std::string boundCheckStr = isOnSurface ? " onSurface" : " outOfSurface"; - msg() << MSG::VERBOSE << " " << m_idHelper->toString(mdtPrd.identify()) + msg() << MSG::VERBOSE << " " << m_idHelper->toString(mdtPrd.identify()) << " r " << distanceToWire << " range " << roadWidthR << " z " << posAlongWire << " range " << halfTubeLength + roadWidthZ << boundCheckStr; } //if( fabs(distanceToWire) > roadWidthR || fabs(posAlongWire) > halfTubeLength + roadWidthZ ){ - if(nSigmaFromTrack > m_maxSigma || fabs(posAlongWire) > halfTubeLength + roadWidthZ ){ - if( msgLvl(MSG::VERBOSE) ) msg() << " --- dropped" << endmsg; + if (nSigmaFromTrack > m_maxSigma || fabs(posAlongWire) > halfTubeLength + roadWidthZ ) { + if ( msgLvl(MSG::VERBOSE) ) msg() << " --- dropped" << endmsg; delete exPars; - return 0; + return 0; } // update hole search flag, set to false if we are close to the tube edge - if( doHoleSearch && fabs(posAlongWire) < halfTubeLength + roadWidthZ ) doHoleSearch = false; - + if ( doHoleSearch && fabs(posAlongWire) < halfTubeLength + roadWidthZ ) doHoleSearch = false; + // pointer to ROT - const MdtDriftCircleOnTrack* mdtROT = m_mdtRotCreator->createRIO_OnTrack(mdtPrd,exPars->position(), &(exPars->momentum())); - + const MdtDriftCircleOnTrack* mdtROT = m_mdtRotCreator->createRIO_OnTrack(mdtPrd, exPars->position(), &(exPars->momentum())); + // clean up pointers delete exPars; - // check whether ROT is create - if( !mdtROT ){ + // check whether ROT is created + if ( !mdtROT ) { ATH_MSG_DEBUG(" failed to calibrate MdtPrepData " << m_idHelper->toString(mdtPrd.identify())); return 0; } - - if( msgLvl(MSG::VERBOSE) ) { + + if ( msgLvl(MSG::VERBOSE) ) { double radius = mdtROT->localParameters()[Trk::locR]; double error = driftdr; double residual = radius - fabs(distanceToWire); - double fullError = sqrt( errorR*errorR + error*error ); - double radialPull = residual/fullError; + double fullError = sqrt( errorR * errorR + error * error ); + double radialPull = residual / fullError; std::string hitType; - if( fabs(radialPull) < 5 ) hitType = "onTrack"; - else if( fabs(radialPull) > 5 && residual > 0 ) hitType = "delta"; + if ( fabs(radialPull) < 5 ) hitType = "onTrack"; + else if ( fabs(radialPull) > 5 && residual > 0 ) hitType = "delta"; else hitType = "outOfTime"; msg() << " r_drift " << radius << " res " << residual << " pull " << radialPull << " " << hitType << endmsg; } diff --git a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSeededSegmentFinder.h b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSeededSegmentFinder.h index c47ec1611d41da445ebd0d72bdd665c6d464fe51..cdc9b00340635b29a092678018c3efcbd3ed7449 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSeededSegmentFinder.h +++ b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSeededSegmentFinder.h @@ -31,104 +31,118 @@ class RpcIdHelper; class MdtIdHelper; class CscIdHelper; class TgcIdHelper; +// New Small Wheel +class sTgcIdHelper; +class MmIdHelper; namespace Muon { - class IMdtDriftCircleOnTrackCreator; - class MuonIdHelperTool; - class MuonEDMPrinterTool; - class MdtDriftCircleOnTrack; - class MuonSegment; - class IMuonSegmentMaker; - class MdtPrepData; +class IMdtDriftCircleOnTrackCreator; +class MuonIdHelperTool; +class MuonEDMPrinterTool; +class MdtDriftCircleOnTrack; +class MuonSegment; +class IMuonSegmentMaker; +class MdtPrepData; } namespace MuonGM { - class MuonDetectorManager; +class MuonDetectorManager; } namespace Trk { - class IPropagator; +class IPropagator; } namespace Muon { - /** - @brief seeded segment finder that gets its data directly from storegate for a give set of Identifiers or IdentifierHashes - - */ - class MuonSeededSegmentFinder : virtual public IMuonSeededSegmentFinder, public AthAlgTool { - public: - /** @brief constructor */ - MuonSeededSegmentFinder(const std::string&,const std::string&,const IInterface*); - - /** @brief destructor */ - ~MuonSeededSegmentFinder (); - - /** @brief AlgTool initilize */ - StatusCode initialize(); - - /** @brief AlgTool finalize */ - StatusCode finalize(); - - /** @brief find segments in a set of chambers starting from seeding TrackParameters */ - std::vector<const MuonSegment*>* find( const Trk::TrackParameters& pars, const std::set<Identifier>& chIds ) const; - - /** @brief find segments in a set of chambers starting from seeding TrackParameters (version with Hashes) */ - std::vector<const MuonSegment*>* find( const Trk::TrackParameters& pars, const std::set<IdentifierHash>& chIdHs ) const; - - /** @brief find segments in a set of MdtPrepData starting from seeding TrackParameters */ - std::vector<const MuonSegment*>* find( const Trk::TrackParameters& pars, const std::vector<const MdtPrepData*>& mdtPrds ) const; - - - /** @brief retrieve MDT PRD collections for the given hashes */ - void extractMdtPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const MdtPrepDataCollection*>& target ) const; - - /** @brief retrieve RPC PRD collections for the given hashes */ - void extractRpcPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const RpcPrepDataCollection*>& target ) const; - - /** @brief retrieve TGC PRD collections for the given hashes */ - void extractTgcPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const TgcPrepDataCollection*>& target ) const; - - /** @brief retrieve CSC PRD collections for the given hashes */ - void extractCscPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const CscPrepDataCollection*>& target ) const; - - private: - /** @brief retrieve the MdtPrepDataCollections for the give Identifiers */ - std::vector<const MdtPrepData*> extractPrds( const std::set<Identifier>& chIds ) const; - - /** @brief retrieve the MdtPrepDataCollections for the give Identifier Hashes */ - std::vector<const MdtPrepData*> extractPrds( const std::set<IdentifierHash>& chIdHs ) const; - - /** @brief select a set of Mdt hits and calibrate them */ - void selectAndCalibrate( const Trk::TrackParameters& pars, - const std::vector<const MdtPrepData*>& mdtPrdCols, - std::vector<const MdtDriftCircleOnTrack*>& mdtROTs, - bool& doHoleSearch ) const; - - /** @brief select and calibrate a single MdtPrepData */ - const MdtDriftCircleOnTrack* handleMdtPrd( const Trk::TrackParameters& pars, - const MdtPrepData& mdtPrd, - bool& doHoleSearch ) const; - - - const MuonGM::MuonDetectorManager* m_detMgr; - - ToolHandle<Muon::IMuonSegmentMaker> m_segMaker; //!< actual segment maker with hole search - ToolHandle<Muon::IMuonSegmentMaker> m_segMakerNoHoles; //!< actual segment maker no hole search - ToolHandle<Trk::IPropagator> m_propagator; //!< propagator - ToolHandle<Muon::IMdtDriftCircleOnTrackCreator> m_mdtRotCreator; //!< IMdtDriftCircleOnTrackCreator - Trk::MagneticFieldProperties m_magFieldProperties; //!< magnetic field properties - ToolHandle<Muon::MuonIdHelperTool> m_idHelper; //!< IdHelper tool - ToolHandle<Muon::MuonEDMPrinterTool> m_printer; //!< EDM printer tool - - SG::ReadHandleKey<Muon::MdtPrepDataContainer> m_key_mdt; //!< storegate location of the MdtPrepData - SG::ReadHandleKey<Muon::RpcPrepDataContainer> m_key_rpc; //!< storegate location of the RpcPrepData - SG::ReadHandleKey<Muon::TgcPrepDataContainer> m_key_tgc; //!< storegate location of the TgcPrepData - SG::ReadHandleKey<Muon::CscPrepDataContainer> m_key_csc; //!< storegate location of the CscPrepData - - double m_adcCut; - double m_maxSigma; - }; +/** + @brief seeded segment finder that gets its data directly from storegate for a give set of Identifiers or IdentifierHashes + +*/ +class MuonSeededSegmentFinder : virtual public IMuonSeededSegmentFinder, public AthAlgTool { +public: + /** @brief constructor */ + MuonSeededSegmentFinder(const std::string&, const std::string&, const IInterface*); + + /** @brief destructor */ + ~MuonSeededSegmentFinder (); + + /** @brief AlgTool initilize */ + StatusCode initialize(); + + /** @brief AlgTool finalize */ + StatusCode finalize(); + + /** @brief find segments in a set of chambers starting from seeding TrackParameters */ + std::vector<const MuonSegment*>* find( const Trk::TrackParameters& pars, const std::set<Identifier>& chIds ) const; + + /** @brief find segments in a set of chambers starting from seeding TrackParameters (version with Hashes) */ + std::vector<const MuonSegment*>* find( const Trk::TrackParameters& pars, const std::set<IdentifierHash>& chIdHs ) const; + + /** @brief find segments in a set of MdtPrepData starting from seeding TrackParameters */ + std::vector<const MuonSegment*>* find( const Trk::TrackParameters& pars, const std::vector<const MdtPrepData*>& mdtPrds ) const; + + + /** @brief retrieve MDT PRD collections for the given hashes */ + void extractMdtPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const MdtPrepDataCollection*>& target ) const; + + /** @brief retrieve RPC PRD collections for the given hashes */ + void extractRpcPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const RpcPrepDataCollection*>& target ) const; + + /** @brief retrieve TGC PRD collections for the given hashes */ + void extractTgcPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const TgcPrepDataCollection*>& target ) const; + + /** @brief retrieve CSC PRD collections for the given hashes */ + void extractCscPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const CscPrepDataCollection*>& target ) const; + + // New Small Wheel + + /** @brief retrieve STGC PRD collections for the given hashes */ + void extractsTgcPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const sTgcPrepDataCollection*>& target ) const; + + /** @brief retrieve MM PRD collections for the given hashes */ + void extractMMPrdCols( const std::set<IdentifierHash>& chIdHs, std::vector<const MMPrepDataCollection*>& target ) const; + + +private: + /** @brief retrieve the MdtPrepDataCollections for the give Identifiers */ + std::vector<const MdtPrepData*> extractPrds( const std::set<Identifier>& chIds ) const; + + /** @brief retrieve the MdtPrepDataCollections for the give Identifier Hashes */ + std::vector<const MdtPrepData*> extractPrds( const std::set<IdentifierHash>& chIdHs ) const; + + /** @brief select a set of Mdt hits and calibrate them */ + void selectAndCalibrate( const Trk::TrackParameters& pars, + const std::vector<const MdtPrepData*>& mdtPrdCols, + std::vector<const MdtDriftCircleOnTrack*>& mdtROTs, + bool& doHoleSearch ) const; + + /** @brief select and calibrate a single MdtPrepData */ + const MdtDriftCircleOnTrack* handleMdtPrd( const Trk::TrackParameters& pars, + const MdtPrepData& mdtPrd, + bool& doHoleSearch ) const; + + + const MuonGM::MuonDetectorManager* m_detMgr; + + ToolHandle<Muon::IMuonSegmentMaker> m_segMaker; //!< actual segment maker with hole search + ToolHandle<Muon::IMuonSegmentMaker> m_segMakerNoHoles; //!< actual segment maker no hole search + ToolHandle<Trk::IPropagator> m_propagator; //!< propagator + ToolHandle<Muon::IMdtDriftCircleOnTrackCreator> m_mdtRotCreator; //!< IMdtDriftCircleOnTrackCreator + Trk::MagneticFieldProperties m_magFieldProperties; //!< magnetic field properties + ToolHandle<Muon::MuonIdHelperTool> m_idHelper; //!< IdHelper tool + ToolHandle<Muon::MuonEDMPrinterTool> m_printer; //!< EDM printer tool + + SG::ReadHandleKey<Muon::MdtPrepDataContainer> m_key_mdt{this,"MdtPrepDataContainer","MDT_DriftCircles","MDT PRDs"}; + SG::ReadHandleKey<Muon::CscPrepDataContainer> m_key_csc{this,"CscPrepDataContainer","CSC_Clusters","CSC PRDS"}; + SG::ReadHandleKey<Muon::TgcPrepDataContainer> m_key_tgc{this,"TgcPrepDataContainer","TGC_Measurements","TGC PRDs"}; + SG::ReadHandleKey<Muon::RpcPrepDataContainer> m_key_rpc{this,"RpcPrepDataContainer","RPC_Measurements","RPC PRDs"}; + SG::ReadHandleKey<Muon::sTgcPrepDataContainer> m_key_stgc{this,"sTgcPrepDataContainer","STGC_Measurements","sTGC PRDs"}; + SG::ReadHandleKey<Muon::MMPrepDataContainer> m_key_mm{this,"MMPrepDataContainer","MM_Measurements","MM PRDs"}; + + double m_adcCut; + double m_maxSigma; +}; } diff --git a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSegmentRegionRecoveryTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSegmentRegionRecoveryTool.cxx index 34d603ee7b2339d7a993a03d4b75cb8cbc03e826..2707ac3b5cac5f6545010072660d2d859e867ca4 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSegmentRegionRecoveryTool.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSegmentRegionRecoveryTool.cxx @@ -31,11 +31,18 @@ #include "MuonPrepRawData/RpcPrepDataCollection.h" #include "MuonPrepRawData/TgcPrepDataCollection.h" #include "MuonPrepRawData/CscPrepDataCollection.h" +// New Small Wheel +#include "MuonPrepRawData/sTgcPrepDataCollection.h" +#include "MuonPrepRawData/MMPrepDataCollection.h" #include "MuonRIO_OnTrack/MdtDriftCircleOnTrack.h" #include "MuonRIO_OnTrack/RpcClusterOnTrack.h" #include "MuonRIO_OnTrack/TgcClusterOnTrack.h" #include "MuonRIO_OnTrack/CscClusterOnTrack.h" +// New Small Wheel +#include "MuonRIO_OnTrack/sTgcClusterOnTrack.h" +#include "MuonRIO_OnTrack/MMClusterOnTrack.h" + #include "MuonSegment/MuonSegment.h" #include "MuonCompetingRIOsOnTrack/CompetingMuonClustersOnTrack.h" @@ -70,924 +77,1113 @@ namespace Muon { - MuonSegmentRegionRecoveryTool::MuonSegmentRegionRecoveryTool(const std::string& ty,const std::string& na,const IInterface* pa) - : AthAlgTool(ty,na,pa), - m_seededSegmentFinder("Muon::MuonSeededSegmentFinder/MuonSeededSegmentFinder"), - m_trackSegmentMatchingTool("Muon::MooCandidateMatchingTool/MooCandidateMatchingTool"), - m_chamberHoleRecoveryTool("Muon::MuonChamberHoleRecoveryTool/MuonChamberHoleRecoveryTool"), - m_extrapolator("Trk::Extrapolator/MuonExtrapolator"), - m_fitter("Rec::CombinedMuonTrackBuilder/CombinedMuonTrackBuilder"), - m_intersectSvc("MuonStationIntersectSvc",name()), - m_idHelperTool("Muon::MuonIdHelperTool/MuonIdHelperTool"), - m_helperTool("Muon::MuonEDMHelperTool/MuonEDMHelperTool"), - m_printer("Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"), - m_hitSummaryTool("Muon::MuonHitSummaryTool/MuonHitSummaryTool"), - m_regionSelector("RegSelSvc", name()) - { - declareInterface<IMuonHoleRecoveryTool>(this); - declareProperty("SeededSegmentFinder", m_seededSegmentFinder); - declareProperty("TrackSegmentMatchingTool",m_trackSegmentMatchingTool); - declareProperty("ChamberHoleRecoveryTool", m_chamberHoleRecoveryTool); - declareProperty("Extrapolator", m_extrapolator); - declareProperty("Fitter", m_fitter ); - declareProperty("MuonStationIntersectSvc", m_intersectSvc); - declareProperty("IdHelper", m_idHelperTool); - declareProperty("EDMHelper", m_helperTool); - declareProperty("EDMPrinter", m_printer); - declareProperty("HitSummaryTool", m_hitSummaryTool); - declareProperty("RegionSelector", m_regionSelector); - - declareProperty("DeltaEtaRegion", m_deta = 0.05); - declareProperty("DeltaPhiRegion", m_dphi = 0.1); - declareProperty("ExcludeEES", m_excludeEES = true); - declareProperty("OnlyEO", m_onlyEO = false); - declareProperty("UseFitterOutlierLogic", m_useFitterOutlierLogic = true ); +MuonSegmentRegionRecoveryTool::MuonSegmentRegionRecoveryTool(const std::string& ty, const std::string& na, const IInterface* pa) + : AthAlgTool(ty, na, pa), + m_seededSegmentFinder("Muon::MuonSeededSegmentFinder/MuonSeededSegmentFinder"), + m_trackSegmentMatchingTool("Muon::MooCandidateMatchingTool/MooCandidateMatchingTool"), + m_chamberHoleRecoveryTool("Muon::MuonChamberHoleRecoveryTool/MuonChamberHoleRecoveryTool"), + m_extrapolator("Trk::Extrapolator/MuonExtrapolator"), + m_fitter("Rec::CombinedMuonTrackBuilder/CombinedMuonTrackBuilder"), + m_intersectSvc("MuonStationIntersectSvc", name()), + m_idHelperTool("Muon::MuonIdHelperTool/MuonIdHelperTool"), + m_helperTool("Muon::MuonEDMHelperTool/MuonEDMHelperTool"), + m_printer("Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"), + m_hitSummaryTool("Muon::MuonHitSummaryTool/MuonHitSummaryTool"), + m_regionSelector("RegSelSvc", name()) +{ + declareInterface<IMuonHoleRecoveryTool>(this); + declareProperty("SeededSegmentFinder", m_seededSegmentFinder); + declareProperty("TrackSegmentMatchingTool", m_trackSegmentMatchingTool); + declareProperty("ChamberHoleRecoveryTool", m_chamberHoleRecoveryTool); + declareProperty("Extrapolator", m_extrapolator); + declareProperty("Fitter", m_fitter ); + declareProperty("MuonStationIntersectSvc", m_intersectSvc); + declareProperty("IdHelper", m_idHelperTool); + declareProperty("EDMHelper", m_helperTool); + declareProperty("EDMPrinter", m_printer); + declareProperty("HitSummaryTool", m_hitSummaryTool); + declareProperty("RegionSelector", m_regionSelector); + + declareProperty("DeltaEtaRegion", m_deta = 0.05); + declareProperty("DeltaPhiRegion", m_dphi = 0.1); + declareProperty("ExcludeEES", m_excludeEES = true); + declareProperty("OnlyEO", m_onlyEO = false); + declareProperty("UseFitterOutlierLogic", m_useFitterOutlierLogic = true ); + declareProperty("DoNSW", m_doNSW = true); // assume that if NSW no CSC chambers are present +} + +MuonSegmentRegionRecoveryTool::~MuonSegmentRegionRecoveryTool() {} + +StatusCode MuonSegmentRegionRecoveryTool::initialize() +{ + + ATH_CHECK( detStore()->retrieve( m_detMgr ) ); + ATH_CHECK( m_helperTool.retrieve() ); + ATH_CHECK( m_intersectSvc.retrieve() ); + ATH_CHECK( m_printer.retrieve() ); + ATH_CHECK( m_seededSegmentFinder.retrieve() ); + + if ( !m_trackSegmentMatchingTool.empty() ) { + ATH_CHECK( m_trackSegmentMatchingTool.retrieve() ); + ATH_MSG_INFO("Using matching tool " << m_trackSegmentMatchingTool ); + } else { + ATH_MSG_DEBUG("No matching tool selected " ); } - - MuonSegmentRegionRecoveryTool::~MuonSegmentRegionRecoveryTool(){} - StatusCode MuonSegmentRegionRecoveryTool::initialize() - { + ATH_CHECK( m_chamberHoleRecoveryTool.retrieve() ); + ATH_CHECK( m_extrapolator.retrieve() ); + ATH_CHECK( m_fitter.retrieve() ); + ATH_CHECK( m_idHelperTool.retrieve() ); + ATH_CHECK( m_hitSummaryTool.retrieve() ); + ATH_CHECK( m_regionSelector.retrieve() ); - ATH_CHECK( detStore()->retrieve( m_detMgr ) ); - ATH_CHECK( m_helperTool.retrieve() ); - ATH_CHECK( m_intersectSvc.retrieve() ); - ATH_CHECK( m_printer.retrieve() ); - ATH_CHECK( m_seededSegmentFinder.retrieve() ); + return StatusCode::SUCCESS; +} - if( !m_trackSegmentMatchingTool.empty() ){ - ATH_CHECK( m_trackSegmentMatchingTool.retrieve() ); - ATH_MSG_INFO("Using matching tool " << m_trackSegmentMatchingTool ); - }else{ - ATH_MSG_DEBUG("No matching tool selected " ); - } +StatusCode MuonSegmentRegionRecoveryTool::finalize() +{ + return StatusCode::SUCCESS; +} - ATH_CHECK( m_chamberHoleRecoveryTool.retrieve() ); - ATH_CHECK( m_extrapolator.retrieve() ); - ATH_CHECK( m_fitter.retrieve() ); - ATH_CHECK( m_idHelperTool.retrieve() ); - ATH_CHECK( m_hitSummaryTool.retrieve() ); - ATH_CHECK( m_regionSelector.retrieve() ); - return StatusCode::SUCCESS; - } - - StatusCode MuonSegmentRegionRecoveryTool::finalize() - { - return StatusCode::SUCCESS; - } +Trk::Track* MuonSegmentRegionRecoveryTool::recover( const Trk::Track& track ) const { - - Trk::Track* MuonSegmentRegionRecoveryTool::recover( const Trk::Track& track ) const { + Trk::Track* result = recoverImp(track);; + if ( result ) ATH_MSG_DEBUG("Final track " << m_printer->print(*result) << std::endl << m_printer->printStations(*result) ); + else ATH_MSG_DEBUG("Track lost during recovery"); + return result; +} + +/**Algorithmic part + Strategy: + 1) Extrapolate back to MS entry record + 2) Collect hashes of chambers close to where the track passed + 3) Compare collected Hashes with the ones already on track + 4) Recover segments on the missing chambers by launching the SeededSegmentFinder +*/ - Trk::Track* result = recoverImp(track); - if( result ) ATH_MSG_DEBUG("Final track " << m_printer->print(*result) << std::endl << m_printer->printStations(*result) ); - else ATH_MSG_DEBUG("Track lost during recovery"); - return result; +Trk::Track* MuonSegmentRegionRecoveryTool::recoverImp( const Trk::Track& track ) const { + //Welcome into the implementation of the recovery method + ATH_MSG_VERBOSE(" Entering segment recovery method " << m_printer->print(track) << std::endl << m_printer->printStations(track) ); + + //First run the MuonChamberHoleRecoveryTool on the input track + const Trk::Track* chRecTrack = m_chamberHoleRecoveryTool->recover(track); + if (!chRecTrack) { + ATH_MSG_DEBUG(" MuonChamberHoleRecoveryTool failed to create a new track " + << " Returning input (unrecovered) track " ); + return new Trk::Track( track ); + } + ATH_MSG_VERBOSE(" After chamber hole recovery " << m_printer->print(track) << std::endl << m_printer->printStations(track) ); + + // only run this on single station EM tracks + if ( m_onlyEO ) { + // should be a sl track + if ( !m_helperTool->isSLTrack(*chRecTrack) ) return const_cast<Trk::Track*>(chRecTrack); + + // get hit summary + IMuonHitSummaryTool::CompactSummary hitSummary = m_hitSummaryTool->summary(*chRecTrack); + // should be single station + if ( hitSummary.stationLayers.size() != 1 || + !hitSummary.stationLayers.count(MuonStationIndex::EM) ) return const_cast<Trk::Track*>(chRecTrack); + ATH_MSG_DEBUG("Single station track, checking for EO hits"); } - /**Algorithmic part - Strategy: - 1) Extrapolate back to MS entry record - 2) Collect hashes of chambers close to where the track passed - 3) Compare collected Hashes with the ones already on track - 4) Recover segments on the missing chambers by launching the SeededSegmentFinder - */ - - Trk::Track* MuonSegmentRegionRecoveryTool::recoverImp( const Trk::Track& track ) const { - //Welcome into the implementation of the recovery method - ATH_MSG_VERBOSE(" Entering segment recovery method " << m_printer->print(track) << std::endl << m_printer->printStations(track) ); - - //First run the MuonChamberHoleRecoveryTool on the input track - const Trk::Track* chRecTrack = m_chamberHoleRecoveryTool->recover(track); - if(!chRecTrack){ - ATH_MSG_DEBUG(" MuonChamberHoleRecoveryTool failed to create a new track " - << " Returning input (unrecovered) track " ); - return new Trk::Track( track ); - } - ATH_MSG_VERBOSE(" After chamber hole recovery " << m_printer->print(track) << std::endl << m_printer->printStations(track) ); - - // only run this on single station EM tracks - if( m_onlyEO ){ - // should be a sl track - if( !m_helperTool->isSLTrack(*chRecTrack) ) return const_cast<Trk::Track*>(chRecTrack); - - // get hit summary - IMuonHitSummaryTool::CompactSummary hitSummary = m_hitSummaryTool->summary(*chRecTrack); - // should be single station - if( hitSummary.stationLayers.size() != 1 || - !hitSummary.stationLayers.count(MuonStationIndex::EM) ) return const_cast<Trk::Track*>(chRecTrack); - ATH_MSG_DEBUG("Single station track, checking for EO hits"); - } - - //1) Extrapolate back to MS entry record + //1) Extrapolate back to MS entry record // const Trk::TrackParameters* msEntryPars = goToMSEntryRecord( *chRecTrack ); // if(!msEntryPars) return chRecTrack; - - /** 2) Collect hashes of chambers close to where the track passed - 2a) Extrapolate forward to the next station - 2b) Launch selector to get IDHashes - 2c) push_back hashes for this station into a set - 2d) stop where outer layers are - 2e) the outcome of all of this is a std::set of collected hashes - (some are already on the track, no need to recover) */ - - - MuonData muonData; - // extract the hashes already on track - fillOnTrackChambers ( *chRecTrack, muonData ); - - // collect the hashes not in track close to the track - collectCrossedChambers( *chRecTrack, muonData ); - - //3b) compare the two std::sets and make a final std::set of not-yet-on-track Hashes - const Trk::Track* triggerRecTrack = addMissingChambers( *chRecTrack, muonData, false ); - if( triggerRecTrack ){ - if( chRecTrack != &track ) delete chRecTrack; - chRecTrack = triggerRecTrack; - } - - const Trk::Track* mdtRecTrack = addMissingChambers( *chRecTrack, muonData, true ); - if( mdtRecTrack ){ - if( chRecTrack != &track ) delete chRecTrack; - chRecTrack = mdtRecTrack; - } - - - const Trk::Track* mdtRecTrackWithHoles = findHoles( *chRecTrack, muonData ); - if( mdtRecTrackWithHoles ){ - if( chRecTrack != &track ) delete chRecTrack; - chRecTrack = mdtRecTrackWithHoles; - } - - //recovered track, success! - return const_cast<Trk::Track*>(chRecTrack); + + /** 2) Collect hashes of chambers close to where the track passed + 2a) Extrapolate forward to the next station + 2b) Launch selector to get IDHashes + 2c) push_back hashes for this station into a set + 2d) stop where outer layers are + 2e) the outcome of all of this is a std::set of collected hashes + (some are already on the track, no need to recover) */ + + + MuonData muonData; + // extract the hashes already on track + fillOnTrackChambers ( *chRecTrack, muonData ); + + // collect the hashes not in track close to the track + collectCrossedChambers( *chRecTrack, muonData ); + + //3b) compare the two std::sets and make a final std::set of not-yet-on-track Hashes + const Trk::Track* triggerRecTrack = addMissingChambers( *chRecTrack, muonData, false ); + if ( triggerRecTrack ) { + if ( chRecTrack != &track ) delete chRecTrack; + chRecTrack = triggerRecTrack; } - - - //// NO, NO, NO, should pass in an IRoiDescriptor - // void MuonSegmentRegionRecoveryTool::addHashes( DETID type, double etamin, double etamax, double phimin, double phimax, - void MuonSegmentRegionRecoveryTool::addHashes( DETID type, const IRoiDescriptor& roi, - std::set<IdentifierHash>& hashes, const std::set<IdentifierHash>& exclusion ) const { - - // if only looking at EO, skip all but MDT chambers - if( m_onlyEO && type != MDT ) return; - - std::vector<IdentifierHash> crossed; - - m_regionSelector->DetHashIDList(type, roi, crossed ); - - //if( type == MDT ) ATH_MSG_VERBOSE(" adding hashes for type " << type << " size " << crossed.size() << " eta,phi " << eta << " " << phi ); - for( std::vector<IdentifierHash>::iterator it = crossed.begin(); it!=crossed.end(); ++it ){ - if( !exclusion.count(*it) && !hashes.count(*it) ) { - if( type == MDT ) { - Identifier chId; - IdContext otCont = m_idHelperTool->mdtIdHelper().module_context(); - m_idHelperTool->mdtIdHelper().get_id(*it, chId, &otCont); - - if( m_excludeEES && m_idHelperTool->chamberIndex(chId) == MuonStationIndex::EES ){ - ATH_MSG_VERBOSE(" excluding " << *it << " " << m_idHelperTool->toStringChamber(chId) ); - continue; - } - if( m_onlyEO && m_idHelperTool->stationIndex(chId) != MuonStationIndex::EO ){ - ATH_MSG_VERBOSE(" excluding " << *it << " " << m_idHelperTool->toStringChamber(chId) ); - continue; - } - ATH_MSG_VERBOSE(" -- hash " << *it << " " << m_idHelperTool->toStringChamber(chId) ); - } - if( type == CSC ) { - Identifier chId; - IdContext otCont = m_idHelperTool->cscIdHelper().module_context(); - m_idHelperTool->cscIdHelper().get_id(*it, chId, &otCont); - ATH_MSG_VERBOSE(" -- csc hash " << *it << " " << m_idHelperTool->toStringChamber(chId) ); - } - hashes.insert(*it); - } - } + + const Trk::Track* mdtRecTrack = addMissingChambers( *chRecTrack, muonData, true ); + if ( mdtRecTrack ) { + if ( chRecTrack != &track ) delete chRecTrack; + chRecTrack = mdtRecTrack; } - void MuonSegmentRegionRecoveryTool::collectCrossedChambers( const Trk::Track& track, - MuonSegmentRegionRecoveryTool::MuonData& data ) const { - ATH_MSG_VERBOSE(" Collecting all crossed chambers" ); + const Trk::Track* mdtRecTrackWithHoles = findHoles( *chRecTrack, muonData ); + if ( mdtRecTrackWithHoles ) { + if ( chRecTrack != &track ) delete chRecTrack; + chRecTrack = mdtRecTrackWithHoles; + } + + //recovered track, success! + return const_cast<Trk::Track*>(chRecTrack); +} - const DataVector<const Trk::TrackStateOnSurface>* states = track.trackStateOnSurfaces(); - if( !states ){ - ATH_MSG_WARNING(" track without states, cannot perform cleaning "); - return; - } - - std::set<MuonStationIndex::StIndex> stations; - double etamin = 1e9; - double etamax= -1e9; - double phimin = 1e9; - double phimax= -1e9; - // loop over TSOSs - DataVector<const Trk::TrackStateOnSurface>::const_iterator tsit = states->begin(); - DataVector<const Trk::TrackStateOnSurface>::const_iterator tsit_end = states->end(); - - for( ; tsit!=tsit_end ; ++tsit ){ - - const Trk::TrackParameters* pars = (*tsit)->trackParameters(); - if( !pars ) continue; - - double rpos = pars->position().perp(); - double zpos = fabs(pars->position().z()); - double eta = pars->position().eta(); - double phi = pars->position().phi(); - if( msgLvl(MSG::DEBUG) ){ - msg() << "All State parameters: eta: " << eta << " ,phi: " << phi << " pos r " << rpos << " z " << zpos; - if( pars->covariance() ) msg() << MSG::DEBUG << " extrapolation error " << Amg::error(*pars->covariance(),Trk::locX); - msg() << endmsg; +//// NO, NO, NO, should pass in an IRoiDescriptor +// void MuonSegmentRegionRecoveryTool::addHashes( DETID type, double etamin, double etamax, double phimin, double phimax, +void MuonSegmentRegionRecoveryTool::addHashes( DETID type, const IRoiDescriptor& roi, + std::set<IdentifierHash>& hashes, const std::set<IdentifierHash>& exclusion ) const { + + // if only looking at EO, skip all but MDT chambers + if ( m_onlyEO && type != MDT ) return; + + std::vector<IdentifierHash> crossed; + + m_regionSelector->DetHashIDList(type, roi, crossed ); + + //if( type == MDT ) ATH_MSG_VERBOSE(" adding hashes for type " << type << " size " << crossed.size() << " eta,phi " << eta << " " << phi ); + for ( std::vector<IdentifierHash>::iterator it = crossed.begin(); it != crossed.end(); ++it ) { + if ( !exclusion.count(*it) && !hashes.count(*it) ) { + if ( type == MDT ) { + Identifier chId; + IdContext otCont = m_idHelperTool->mdtIdHelper().module_context(); + m_idHelperTool->mdtIdHelper().get_id(*it, chId, &otCont); + + if ( m_excludeEES && m_idHelperTool->chamberIndex(chId) == MuonStationIndex::EES ) { + ATH_MSG_VERBOSE(" excluding " << *it << " " << m_idHelperTool->toStringChamber(chId) ); + continue; + } + if ( m_onlyEO && m_idHelperTool->stationIndex(chId) != MuonStationIndex::EO ) { + ATH_MSG_VERBOSE(" excluding " << *it << " " << m_idHelperTool->toStringChamber(chId) ); + continue; + } + if ( m_doNSW && m_idHelperTool->stationIndex(chId) == MuonStationIndex::EI && abs(m_idHelperTool->stationEta(chId)) < 4) { + ATH_MSG_VERBOSE(" NSW excluding " << *it << " " << m_idHelperTool->toStringChamber(chId) ); + continue; + } + ATH_MSG_VERBOSE(" -- hash " << *it << " " << m_idHelperTool->toStringChamber(chId) ); } - if( rpos < 2500 && zpos < 4000 ) continue; - - // check whether state is a measurement - const Trk::MeasurementBase* meas = (*tsit)->measurementOnTrack(); - if( !meas ) continue; - - Identifier id = m_helperTool->getIdentifier(*meas); - bool pseudo = !id.is_valid(); - - if( pseudo || !m_idHelperTool->mdtIdHelper().is_muon(id) ) continue; - - if( eta > etamax ) etamax = eta; - if( eta < etamin ) etamin = eta; - if( phi > phimax ) phimax = phi; - if( phi < phimin ) phimin = phi; - if( msgLvl(MSG::DEBUG) ){ - msg() << "Selected State parameters: eta: " << eta << " ,phi: " << phi << " pos r " << rpos << " z " << zpos; - if( pars->covariance() ) msg() << MSG::DEBUG << " extrapolation error " << Amg::error(*pars->covariance(),Trk::locX); - msg() << endmsg; + if ( type == CSC ) { + Identifier chId; + IdContext otCont = m_idHelperTool->cscIdHelper().module_context(); + m_idHelperTool->cscIdHelper().get_id(*it, chId, &otCont); + ATH_MSG_VERBOSE(" -- csc hash " << *it << " " << m_idHelperTool->toStringChamber(chId) ); } + // New Small Wheel + if ( type == STGC ) { + Identifier chId; +// IdContext otCont = m_idHelperTool->stgcIdHelper().module_context(); + IdContext otCont = m_idHelperTool->stgcIdHelper().detectorElement_context(); + m_idHelperTool->stgcIdHelper().get_id(*it, chId, &otCont); + ATH_MSG_VERBOSE(" -- stgc hash " << *it << " " << m_idHelperTool->toStringChamber(chId) ); + } + if ( type == MM ) { + Identifier chId; +// IdContext otCont = m_idHelperTool->mmIdHelper().module_context(); + IdContext otCont = m_idHelperTool->mmIdHelper().detectorElement_context(); + m_idHelperTool->mmIdHelper().get_id(*it, chId, &otCont); + ATH_MSG_VERBOSE(" -- mm hash " << *it << " " << m_idHelperTool->toStringChamber(chId) ); + } + hashes.insert(*it); + } + } +} - MuonStationIndex::StIndex stIndex = m_idHelperTool->stationIndex(id); - if( stations.count(stIndex) ) continue; - stations.insert(stIndex); - - - //At each station launch the Reg Sel and stuff the Id hashes in a vector - } - etamin -= m_deta; - etamax += m_deta; - phimin -= m_dphi; - phimax += m_dphi; - - ATH_MSG_DEBUG("Eta range: " << etamin << " " << etamax << " Phi range " << phimin << " " << phimax ); - if(etamin>etamax){ //something went wrong with the fit and no hits were selected in the loop - ATH_MSG_DEBUG("no hits selected, nothing further will be done"); - return; - } - - RoiDescriptor roi( etamin, etamax, phimin, phimax ); - - // addHashes(MDT,etamin,etamax,phimin,phimax,data.mdt,data.mdtTrack); - // addHashes(RPC,etamin,etamax,phimin,phimax,data.rpc,data.rpcTrack); - // addHashes(TGC,etamin,etamax,phimin,phimax,data.tgc,data.tgcTrack); - // addHashes(CSC,etamin,etamax,phimin,phimax,data.csc,data.cscTrack); - - addHashes(MDT, roi, data.mdt,data.mdtTrack); - addHashes(RPC, roi, data.rpc,data.rpcTrack); - addHashes(TGC, roi, data.tgc,data.tgcTrack); - addHashes(CSC, roi, data.csc,data.cscTrack); - - - std::set<IdentifierHash>::iterator hsit = data.mdt.begin(); - std::set<IdentifierHash>::iterator hsit_end = data.mdt.end(); - for( ; hsit != hsit_end; ++hsit ){ - Identifier chId; - IdContext otCont = m_idHelperTool->mdtIdHelper().module_context(); - m_idHelperTool->mdtIdHelper().get_id(*hsit, chId, &otCont); - MuonStationIndex::ChIndex chIndex = m_idHelperTool->chamberIndex(chId); - data.mdtPerStation[chIndex].insert(*hsit); - ATH_MSG_VERBOSE(" chamberlayer " << MuonStationIndex::chName(chIndex) << " " << m_idHelperTool->toStringChamber(chId) ); - } - hsit = data.csc.begin(); - hsit_end = data.csc.end(); - for( ; hsit != hsit_end; ++hsit ){ - Identifier chId; - IdContext otCont = m_idHelperTool->cscIdHelper().module_context(); - m_idHelperTool->cscIdHelper().get_id(*hsit, chId, &otCont); - chId = m_idHelperTool->chamberId(chId); - MuonStationIndex::ChIndex chIndex = m_idHelperTool->chamberIndex(chId); - ATH_MSG_VERBOSE(" chamberlayer " << MuonStationIndex::chName(chIndex) << " " << m_idHelperTool->toString(chId) ); - } - } - - void MuonSegmentRegionRecoveryTool::fillOnTrackChambers ( const Trk::Track& track, MuonData& data ) const { - ATH_MSG_VERBOSE(" making set of already-on-track chambers" ); - - //Collect track PRD's - const DataVector<const Trk::TrackStateOnSurface>* states = track.trackStateOnSurfaces(); - if( !states ){ - ATH_MSG_WARNING(" track without states, cannot perform cleaning "); - return; + +void MuonSegmentRegionRecoveryTool::collectCrossedChambers( const Trk::Track& track, + MuonSegmentRegionRecoveryTool::MuonData& data ) const { + ATH_MSG_VERBOSE(" Collecting all crossed chambers" ); + + + const DataVector<const Trk::TrackStateOnSurface>* states = track.trackStateOnSurfaces(); + if ( !states ) { + ATH_MSG_WARNING(" track without states, cannot perform cleaning "); + return; + } + + std::set<MuonStationIndex::StIndex> stations; + double etamin = 1e9; + double etamax = -1e9; + double phimin = 1e9; + double phimax = -1e9; + // loop over TSOSs + DataVector<const Trk::TrackStateOnSurface>::const_iterator tsit = states->begin(); + DataVector<const Trk::TrackStateOnSurface>::const_iterator tsit_end = states->end(); + + for ( ; tsit != tsit_end ; ++tsit ) { + + const Trk::TrackParameters* pars = (*tsit)->trackParameters(); + if ( !pars ) continue; + + double rpos = pars->position().perp(); + double zpos = fabs(pars->position().z()); + double eta = pars->position().eta(); + double phi = pars->position().phi(); + if ( msgLvl(MSG::DEBUG) ) { + msg() << "All State parameters: eta: " << eta << " ,phi: " << phi << " pos r " << rpos << " z " << zpos; + if ( pars->covariance() ) msg() << MSG::DEBUG << " extrapolation error " << Amg::error(*pars->covariance(), Trk::locX); + msg() << endmsg; } + if ( rpos < 2500 && zpos < 4000 ) continue; - std::set<MuonStationIndex::StIndex> stations; + // check whether state is a measurement + const Trk::MeasurementBase* meas = (*tsit)->measurementOnTrack(); + if ( !meas ) continue; - // loop over TSOSs - DataVector<const Trk::TrackStateOnSurface>::const_iterator tsit = states->begin(); - DataVector<const Trk::TrackStateOnSurface>::const_iterator tsit_end = states->end(); - for( ; tsit!=tsit_end ; ++tsit ){ + Identifier id = m_helperTool->getIdentifier(*meas); + bool pseudo = !id.is_valid(); - const Trk::TrackParameters* pars = (*tsit)->trackParameters(); - if( !pars ) continue; + if ( pseudo || !m_idHelperTool->mdtIdHelper().is_muon(id) ) continue; - // check whether state is a measurement - const Trk::MeasurementBase* meas = (*tsit)->measurementOnTrack(); - if( !meas ) continue; + if ( eta > etamax ) etamax = eta; + if ( eta < etamin ) etamin = eta; + if ( phi > phimax ) phimax = phi; + if ( phi < phimin ) phimin = phi; + if ( msgLvl(MSG::DEBUG) ) { + msg() << "Selected State parameters: eta: " << eta << " ,phi: " << phi << " pos r " << rpos << " z " << zpos; + if ( pars->covariance() ) msg() << MSG::DEBUG << " extrapolation error " << Amg::error(*pars->covariance(), Trk::locX); + msg() << endmsg; + } - const Muon::MdtDriftCircleOnTrack* mdt = dynamic_cast<const Muon::MdtDriftCircleOnTrack*>(meas); - if(mdt && !data.mdtTrack.count(mdt->collectionHash()) ){ - data.mdtTrack.insert( mdt->collectionHash() ); - ATH_MSG_VERBOSE("Adding " << m_idHelperTool->toStringChamber(mdt->identify()) << " hash " << mdt->collectionHash() ); - continue; - } + MuonStationIndex::StIndex stIndex = m_idHelperTool->stationIndex(id); + if ( stations.count(stIndex) ) continue; + stations.insert(stIndex); - const MuonClusterOnTrack* clus = 0; - const CompetingMuonClustersOnTrack* compRot = dynamic_cast<const CompetingMuonClustersOnTrack*>(meas); - if( compRot ){ - clus = &compRot->rioOnTrack(0); - }else{ - clus = dynamic_cast<const MuonClusterOnTrack*>(meas); - } - if( !clus ) continue; - - const RpcClusterOnTrack* rpc=dynamic_cast<const RpcClusterOnTrack*>(clus); - if(rpc && !data.rpcTrack.count(rpc->collectionHash()) ){ - data.rpcTrack.insert( rpc->collectionHash() ); - ATH_MSG_VERBOSE("Adding " << m_idHelperTool->toStringChamber(clus->identify()) << " hash " << clus->collectionHash() ); - continue; - } - const TgcClusterOnTrack* tgc=dynamic_cast<const TgcClusterOnTrack*>(clus); - if(tgc && !data.tgcTrack.count(tgc->collectionHash()) ){ - data.tgcTrack.insert( tgc->collectionHash() ); - ATH_MSG_VERBOSE("Adding " << m_idHelperTool->toStringChamber(clus->identify()) << " hash " << clus->collectionHash() ); - continue; - } - const CscClusterOnTrack* csc=dynamic_cast<const CscClusterOnTrack*>(clus); - if(csc && !data.cscTrack.count(csc->collectionHash())){ - data.cscTrack.insert( csc->collectionHash() ); - ATH_MSG_VERBOSE("Adding " << m_idHelperTool->toStringChamber(clus->identify()) << " hash " << clus->collectionHash() ); - continue; - } + + //At each station launch the Reg Sel and stuff the Id hashes in a vector + } + etamin -= m_deta; + etamax += m_deta; + phimin -= m_dphi; + phimax += m_dphi; + + ATH_MSG_DEBUG("Eta range: " << etamin << " " << etamax << " Phi range " << phimin << " " << phimax ); + if (etamin > etamax) { //something went wrong with the fit and no hits were selected in the loop + ATH_MSG_DEBUG("no hits selected, nothing further will be done"); + return; + } + + RoiDescriptor roi( etamin, etamax, phimin, phimax ); + + // addHashes(MDT,etamin,etamax,phimin,phimax,data.mdt,data.mdtTrack); + // addHashes(RPC,etamin,etamax,phimin,phimax,data.rpc,data.rpcTrack); + // addHashes(TGC,etamin,etamax,phimin,phimax,data.tgc,data.tgcTrack); + // addHashes(CSC,etamin,etamax,phimin,phimax,data.csc,data.cscTrack); + + addHashes(MDT, roi, data.mdt, data.mdtTrack); + addHashes(RPC, roi, data.rpc, data.rpcTrack); + addHashes(TGC, roi, data.tgc, data.tgcTrack); + if (!m_doNSW) addHashes(CSC, roi, data.csc, data.cscTrack); + // New Small Wheel + addHashes(STGC, roi, data.stgc, data.stgcTrack); + addHashes(MM, roi, data.mm, data.mmTrack); + + + std::set<IdentifierHash>::iterator hsit = data.mdt.begin(); + std::set<IdentifierHash>::iterator hsit_end = data.mdt.end(); + for ( ; hsit != hsit_end; ++hsit ) { + Identifier chId; + IdContext otCont = m_idHelperTool->mdtIdHelper().module_context(); + m_idHelperTool->mdtIdHelper().get_id(*hsit, chId, &otCont); + MuonStationIndex::ChIndex chIndex = m_idHelperTool->chamberIndex(chId); + data.mdtPerStation[chIndex].insert(*hsit); + ATH_MSG_VERBOSE(" chamberlayer " << MuonStationIndex::chName(chIndex) << " " << m_idHelperTool->toStringChamber(chId) ); + } + hsit = data.csc.begin(); + hsit_end = data.csc.end(); + for ( ; hsit != hsit_end; ++hsit ) { + Identifier chId; + IdContext otCont = m_idHelperTool->cscIdHelper().module_context(); + m_idHelperTool->cscIdHelper().get_id(*hsit, chId, &otCont); + chId = m_idHelperTool->chamberId(chId); + MuonStationIndex::ChIndex chIndex = m_idHelperTool->chamberIndex(chId); + ATH_MSG_VERBOSE(" chamberlayer " << MuonStationIndex::chName(chIndex) << " " << m_idHelperTool->toString(chId) ); + } +} + +void MuonSegmentRegionRecoveryTool::fillOnTrackChambers ( const Trk::Track& track, MuonData& data ) const { + ATH_MSG_VERBOSE(" making set of already-on-track chambers" ); + + //Collect track PRD's + const DataVector<const Trk::TrackStateOnSurface>* states = track.trackStateOnSurfaces(); + if ( !states ) { + ATH_MSG_WARNING(" track without states, cannot perform cleaning "); + return; + } + + std::set<MuonStationIndex::StIndex> stations; + + // loop over TSOSs + DataVector<const Trk::TrackStateOnSurface>::const_iterator tsit = states->begin(); + DataVector<const Trk::TrackStateOnSurface>::const_iterator tsit_end = states->end(); + for ( ; tsit != tsit_end ; ++tsit ) { + + const Trk::TrackParameters* pars = (*tsit)->trackParameters(); + if ( !pars ) continue; + + // check whether state is a measurement + const Trk::MeasurementBase* meas = (*tsit)->measurementOnTrack(); + if ( !meas ) continue; + + const Muon::MdtDriftCircleOnTrack* mdt = dynamic_cast<const Muon::MdtDriftCircleOnTrack*>(meas); + if (mdt && !data.mdtTrack.count(mdt->collectionHash()) ) { + data.mdtTrack.insert( mdt->collectionHash() ); + ATH_MSG_VERBOSE("Adding " << m_idHelperTool->toStringChamber(mdt->identify()) << " hash " << mdt->collectionHash() ); + continue; + } + + const MuonClusterOnTrack* clus = 0; + const CompetingMuonClustersOnTrack* compRot = dynamic_cast<const CompetingMuonClustersOnTrack*>(meas); + if ( compRot ) { + clus = &compRot->rioOnTrack(0); + } else { + clus = dynamic_cast<const MuonClusterOnTrack*>(meas); + } + if ( !clus ) continue; + + const RpcClusterOnTrack* rpc = dynamic_cast<const RpcClusterOnTrack*>(clus); + if (rpc && !data.rpcTrack.count(rpc->collectionHash()) ) { + data.rpcTrack.insert( rpc->collectionHash() ); + ATH_MSG_VERBOSE("Adding " << m_idHelperTool->toStringChamber(clus->identify()) << " hash " << clus->collectionHash() ); + continue; + } + const TgcClusterOnTrack* tgc = dynamic_cast<const TgcClusterOnTrack*>(clus); + if (tgc && !data.tgcTrack.count(tgc->collectionHash()) ) { + data.tgcTrack.insert( tgc->collectionHash() ); + ATH_MSG_VERBOSE("Adding " << m_idHelperTool->toStringChamber(clus->identify()) << " hash " << clus->collectionHash() ); + continue; + } + const CscClusterOnTrack* csc = dynamic_cast<const CscClusterOnTrack*>(clus); + if (csc && !data.cscTrack.count(csc->collectionHash())) { + data.cscTrack.insert( csc->collectionHash() ); + ATH_MSG_VERBOSE("Adding " << m_idHelperTool->toStringChamber(clus->identify()) << " hash " << clus->collectionHash() ); + continue; + } + // New Small Wheel + const sTgcClusterOnTrack* stgc = dynamic_cast<const sTgcClusterOnTrack*>(clus); + if (stgc && !data.stgcTrack.count(stgc->collectionHash()) ) { + data.stgcTrack.insert( stgc->collectionHash() ); + ATH_MSG_VERBOSE("Adding " << m_idHelperTool->toStringChamber(clus->identify()) << " hash " << clus->collectionHash() ); + continue; + } + const MMClusterOnTrack* mm = dynamic_cast<const MMClusterOnTrack*>(clus); + if (mm && !data.mmTrack.count(mm->collectionHash()) ) { + data.mmTrack.insert( mm->collectionHash() ); + ATH_MSG_VERBOSE("Adding " << m_idHelperTool->toStringChamber(clus->identify()) << " hash " << clus->collectionHash() ); + continue; } } +} - const Trk::Track* MuonSegmentRegionRecoveryTool::findHoles( const Trk::Track& track, MuonData& data ) const { +const Trk::Track* MuonSegmentRegionRecoveryTool::findHoles( const Trk::Track& track, MuonData& data ) const { - const DataVector<const Trk::TrackStateOnSurface>* oldStates = track.trackStateOnSurfaces(); - if( !oldStates ){ - ATH_MSG_WARNING(" track without states, cannot perform mdt hole search "); - return 0; + const DataVector<const Trk::TrackStateOnSurface>* oldStates = track.trackStateOnSurfaces(); + if ( !oldStates ) { + ATH_MSG_WARNING(" track without states, cannot perform mdt hole search "); + return 0; + } + + std::vector<const Trk::TrackStateOnSurface*> states; + unsigned int nholes = 0; + std::set<Identifier> chambersInSearch; + std::set<IdentifierHash>::const_iterator ith = data.mdt.begin(); + std::set<IdentifierHash>::const_iterator ith_end = data.mdt.end(); + for ( ; ith != ith_end; ith++ ) { + + // ignore hashes already on track + if ( data.mdtTrack.count(*ith) ) { + ATH_MSG_VERBOSE("Chamber already on track " << *ith ); + continue; + } + Identifier chId; + IdContext otCont = m_idHelperTool->mdtIdHelper().module_context(); + m_idHelperTool->mdtIdHelper().get_id(*ith, chId, &otCont); + + // ignore chambers that already had a hole search + if ( chambersInSearch.count(chId) ) { + ATH_MSG_VERBOSE("Chamber already on track " << *ith << " " << m_idHelperTool->toStringChamber(chId) ); + continue; } + const MuonGM::MdtReadoutElement* detEl = m_detMgr->getMdtReadoutElement(chId); + if ( !detEl ) { + ATH_MSG_WARNING("Found no detector element for " << *ith ); + continue; + } + const Trk::TrackParameters* exPars = reachableDetEl(track, *detEl, true ); + if ( !exPars ) { + ATH_MSG_DEBUG("Did not reach " << m_idHelperTool->toStringChamber(chId) << " hash " << *ith ); + continue; + } + //Identifier chId = m_idHelperTool->chamberId(detEl->identify()); + ATH_MSG_DEBUG("Reached " << m_idHelperTool->toStringChamber(chId) << " hash " << *ith ); - std::vector<const Trk::TrackStateOnSurface*> states; - unsigned int nholes = 0; - std::set<Identifier> chambersInSearch; - std::set<IdentifierHash>::const_iterator ith = data.mdt.begin(); - std::set<IdentifierHash>::const_iterator ith_end = data.mdt.end(); - for( ; ith != ith_end; ith++ ) { + // calculate crossed tubes + const MuonStationIntersect& intersect = m_intersectSvc->tubesCrossedByTrack(chId , exPars->position(), exPars->momentum().unit() ); - // ignore hashes already on track - if( data.mdtTrack.count(*ith) ) { - ATH_MSG_VERBOSE("Chamber already on track " << *ith ); - continue; - } - Identifier chId; - IdContext otCont = m_idHelperTool->mdtIdHelper().module_context(); - m_idHelperTool->mdtIdHelper().get_id(*ith, chId, &otCont); - - // ignore chambers that already had a hole search - if( chambersInSearch.count(chId) ) { - ATH_MSG_VERBOSE("Chamber already on track " << *ith << " " << m_idHelperTool->toStringChamber(chId) ); - continue; - } - const MuonGM::MdtReadoutElement* detEl = m_detMgr->getMdtReadoutElement(chId); - if( !detEl ){ - ATH_MSG_WARNING("Found no detector element for " << *ith ); - continue; + // clear hole vector + for ( unsigned int ii = 0; ii < intersect.tubeIntersects().size(); ++ii ) { + const MuonTubeIntersect& tint = intersect.tubeIntersects()[ii]; + const Identifier& id = tint.tubeId; + const MuonGM::MdtReadoutElement* detElLoc = m_detMgr->getMdtReadoutElement(id); + + // addition skip for cases when the track crosses inbetween two chambers + if ( data.mdtTrack.count(detElLoc->collectionHash()) ) continue; + + Identifier ch = m_idHelperTool->chamberId(id); + chambersInSearch.insert( ch ); + + const Trk::Surface& surf = detElLoc->surface(id); + const Trk::TrackParameters* tubePars = m_extrapolator->extrapolateDirectly(*exPars, surf, Trk::anyDirection, false, Trk::muon); + if ( !tubePars ) { + ATH_MSG_WARNING( "Failed to extrapolate to tube " << m_idHelperTool->toString(id) ); + continue; } - const Trk::TrackParameters* exPars = reachableDetEl(track,*detEl,true ); - if( !exPars ) { - ATH_MSG_DEBUG("Did not reach " << m_idHelperTool->toStringChamber(chId) << " hash " << *ith ); - continue; + int lay = m_idHelperTool->mdtIdHelper().tubeLayer(id); + int tube = m_idHelperTool->mdtIdHelper().tube(id); + double tubeLen = detElLoc->getActiveTubeLength(lay, tube); + double distEdge = fabs(tubePars->parameters()[Trk::locZ]) - 0.5 * tubeLen; + double pullEdge = tubePars->covariance() ? distEdge / Amg::error(*tubePars->covariance(), Trk::locZ) : distEdge / 20.; + const Amg::Vector2D* locPos = surf.Trk::Surface::globalToLocal(tubePars->position()); + bool inBounds = false; + if ( locPos ) { + + // perform bound check do not count holes with 100. mm of bound edge + inBounds = surf.bounds().insideLoc2(*locPos, -100.); + if ( inBounds ) { + if ( fabs( (*locPos)[Trk::locR] ) > 14.4 ) inBounds = false; + } + delete locPos; } - //Identifier chId = m_idHelperTool->chamberId(detEl->identify()); - ATH_MSG_DEBUG("Reached " << m_idHelperTool->toStringChamber(chId) << " hash " << *ith ); - - // calculate crossed tubes - const MuonStationIntersect& intersect = m_intersectSvc->tubesCrossedByTrack(chId , exPars->position(), exPars->momentum().unit() ); - - // clear hole vector - for( unsigned int ii=0;ii<intersect.tubeIntersects().size();++ii ){ - const MuonTubeIntersect& tint = intersect.tubeIntersects()[ii]; - const Identifier& id = tint.tubeId; - const MuonGM::MdtReadoutElement* detElLoc = m_detMgr->getMdtReadoutElement(id); - - // addition skip for cases when the track crosses inbetween two chambers - if( data.mdtTrack.count(detElLoc->collectionHash()) ) continue; - - Identifier ch = m_idHelperTool->chamberId(id); - chambersInSearch.insert( ch ); - - const Trk::Surface& surf = detElLoc->surface(id); - const Trk::TrackParameters* tubePars = m_extrapolator->extrapolateDirectly(*exPars,surf,Trk::anyDirection,false,Trk::muon); - if( !tubePars ){ - ATH_MSG_WARNING( "Failed to extrapolate to tube " << m_idHelperTool->toString(id) ); - continue; - } - int lay = m_idHelperTool->mdtIdHelper().tubeLayer(id); - int tube = m_idHelperTool->mdtIdHelper().tube(id); - double tubeLen = detElLoc->getActiveTubeLength(lay,tube); - double distEdge = fabs(tubePars->parameters()[Trk::locZ]) - 0.5*tubeLen; - double pullEdge = tubePars->covariance() ? distEdge/Amg::error(*tubePars->covariance(),Trk::locZ) : distEdge/20.; - const Amg::Vector2D* locPos = surf.Trk::Surface::globalToLocal(tubePars->position()); - bool inBounds = false; - if( locPos ){ - - // perform bound check do not count holes with 100. mm of bound edge - inBounds = surf.bounds().insideLoc2(*locPos,-100.); - if( inBounds ) { - if( fabs( (*locPos)[Trk::locR] ) > 14.4 ) inBounds = false; - } - delete locPos; - } - if( !inBounds ){ - ATH_MSG_VERBOSE(" discarding hole " << m_idHelperTool->toString(id) << " dist wire " - << tubePars->parameters()[Trk::locR] << " outside bounds " ); - delete tubePars; - continue; - } - ATH_MSG_VERBOSE(" new hole " << m_idHelperTool->toString(id) << " dist wire " << tubePars->parameters()[Trk::locR] - << " dist tube edge " << distEdge << " pullEdge " << pullEdge); - ++nholes; - Trk::TrackStateOnSurface* tsos = MuonTSOSHelper::createHoleTSOS(tubePars); - //std::cout << " adding TSOS " << tsos << std::endl; - states.push_back( tsos ); + if ( !inBounds ) { + ATH_MSG_VERBOSE(" discarding hole " << m_idHelperTool->toString(id) << " dist wire " + << tubePars->parameters()[Trk::locR] << " outside bounds " ); + delete tubePars; + continue; } - if( !nholes ) ATH_MSG_DEBUG("found holes " << nholes ); - delete exPars; + ATH_MSG_VERBOSE(" new hole " << m_idHelperTool->toString(id) << " dist wire " << tubePars->parameters()[Trk::locR] + << " dist tube edge " << distEdge << " pullEdge " << pullEdge); + ++nholes; + Trk::TrackStateOnSurface* tsos = MuonTSOSHelper::createHoleTSOS(tubePars); + //std::cout << " adding TSOS " << tsos << std::endl; + states.push_back( tsos ); } + if ( !nholes ) ATH_MSG_DEBUG("found holes " << nholes ); + delete exPars; + } - ith = data.csc.begin(); - ith_end = data.csc.end(); - for( ; ith != ith_end; ith++ ) { + ith = data.csc.begin(); + ith_end = data.csc.end(); + for ( ; ith != ith_end; ith++ ) { - // ignore hashes already on track - if( data.cscTrack.count(*ith) ) { - ATH_MSG_VERBOSE("Chamber already on track " << *ith ); - continue; - } - Identifier chId; - IdContext otCont = m_idHelperTool->cscIdHelper().module_context(); - m_idHelperTool->cscIdHelper().get_id(*ith, chId, &otCont); - chId = m_idHelperTool->chamberId(chId); - - const MuonGM::CscReadoutElement* detEl = m_detMgr->getCscReadoutElement(chId); - if( !detEl ){ - ATH_MSG_WARNING("Found no detector element for " << *ith << " " << m_idHelperTool->toString(chId) ); - continue; - } + // ignore hashes already on track + if ( data.cscTrack.count(*ith) ) { + ATH_MSG_VERBOSE("Chamber already on track " << *ith ); + continue; + } + Identifier chId; + IdContext otCont = m_idHelperTool->cscIdHelper().module_context(); + m_idHelperTool->cscIdHelper().get_id(*ith, chId, &otCont); + chId = m_idHelperTool->chamberId(chId); + + const MuonGM::CscReadoutElement* detEl = m_detMgr->getCscReadoutElement(chId); + if ( !detEl ) { + ATH_MSG_WARNING("Found no detector element for " << *ith << " " << m_idHelperTool->toString(chId) ); + continue; + } - const Trk::TrackParameters* exPars = reachableDetEl(track,*detEl, true ); - if( !exPars ) { - ATH_MSG_DEBUG("Did not reach " << m_idHelperTool->toStringChamber(chId) << " hash " << *ith ); - continue; + const Trk::TrackParameters* exPars = reachableDetEl(track, *detEl, true ); + if ( !exPars ) { + ATH_MSG_DEBUG("Did not reach " << m_idHelperTool->toStringChamber(chId) << " hash " << *ith ); + continue; + } + //Identifier chId = m_idHelperTool->chamberId(detEl->identify()); + Identifier detElId = m_idHelperTool->detElId( chId ); + std::set<Identifier> layIds; + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > > cscstates; + m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars, layIds, cscstates ); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator cscit = cscstates.begin(); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator cscit_end = cscstates.end(); + ATH_MSG_DEBUG("Reached " << m_idHelperTool->toString(chId) << " hash " << *ith << " holes " << cscstates.size() ); + + for ( ; cscit != cscit_end; ++cscit ) { + if ( cscit->first ) { + ATH_MSG_VERBOSE("Adding " << cscit->second ); + states.push_back( cscit->second ); } - //Identifier chId = m_idHelperTool->chamberId(detEl->identify()); - Identifier detElId = m_idHelperTool->detElId( chId ); - std::set<Identifier> layIds; - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > > cscstates; - m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars,layIds, cscstates ); - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >::iterator cscit = cscstates.begin(); - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >::iterator cscit_end = cscstates.end(); - ATH_MSG_DEBUG("Reached " << m_idHelperTool->toString(chId) << " hash " << *ith << " holes " << cscstates.size() ); - - for( ;cscit !=cscit_end;++cscit ){ - if( cscit->first ) { - ATH_MSG_VERBOSE("Adding " << cscit->second ); - states.push_back( cscit->second ); - } + } + delete exPars; + } + ith = data.tgc.begin(); + ith_end = data.tgc.end(); + for ( ; ith != ith_end; ith++ ) { + + // ignore hashes already on track + if ( data.tgcTrack.count(*ith) ) { + ATH_MSG_VERBOSE("Chamber already on track " << *ith ); + continue; + } + Identifier chId; + IdContext otCont = m_idHelperTool->tgcIdHelper().module_context(); + m_idHelperTool->tgcIdHelper().get_id(*ith, chId, &otCont); + chId = m_idHelperTool->chamberId(chId); + + const MuonGM::TgcReadoutElement* detEl = m_detMgr->getTgcReadoutElement(chId); + if ( !detEl ) { + ATH_MSG_WARNING("Found no detector element for " << *ith << " " << m_idHelperTool->toString(chId) ); + continue; + } + + const Trk::TrackParameters* exPars = reachableDetEl(track, *detEl, true ); + if ( !exPars ) { + ATH_MSG_DEBUG("Did not reach " << m_idHelperTool->toStringChamber(chId) << " hash " << *ith ); + continue; + } + //Identifier chId = m_idHelperTool->chamberId(detEl->identify()); + Identifier detElId = m_idHelperTool->detElId( chId ); + std::set<Identifier> layIds; + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > > tgcstates; + m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars, layIds, tgcstates ); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator tgcit = tgcstates.begin(); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator tgcit_end = tgcstates.end(); + ATH_MSG_DEBUG("Reached " << m_idHelperTool->toString(chId) << " hash " << *ith << " holes " << tgcstates.size() ); + + for ( ; tgcit != tgcit_end; ++tgcit ) { + if ( tgcit->first ) { + ATH_MSG_VERBOSE("Adding " << tgcit->second ); + states.push_back( tgcit->second ); } - delete exPars; - } + } + delete exPars; + } - ith = data.tgc.begin(); - ith_end = data.tgc.end(); - for( ; ith != ith_end; ith++ ) { + ith = data.rpc.begin(); + ith_end = data.rpc.end(); + for ( ; ith != ith_end; ith++ ) { - // ignore hashes already on track - if( data.tgcTrack.count(*ith) ) { - ATH_MSG_VERBOSE("Chamber already on track " << *ith ); - continue; - } - Identifier chId; - IdContext otCont = m_idHelperTool->tgcIdHelper().module_context(); - m_idHelperTool->tgcIdHelper().get_id(*ith, chId, &otCont); - chId = m_idHelperTool->chamberId(chId); - - const MuonGM::TgcReadoutElement* detEl = m_detMgr->getTgcReadoutElement(chId); - if( !detEl ){ - ATH_MSG_WARNING("Found no detector element for " << *ith << " " << m_idHelperTool->toString(chId) ); - continue; - } + // ignore hashes already on track + if ( data.rpcTrack.count(*ith) ) { + ATH_MSG_VERBOSE("Chamber already on track " << *ith ); + continue; + } + Identifier chId; + IdContext otCont = m_idHelperTool->rpcIdHelper().module_context(); + m_idHelperTool->rpcIdHelper().get_id(*ith, chId, &otCont); + chId = m_idHelperTool->chamberId(chId); + + const MuonGM::RpcReadoutElement* detEl = m_detMgr->getRpcReadoutElement(chId); + if ( !detEl ) { + ATH_MSG_WARNING("Found no detector element for " << *ith << " " << m_idHelperTool->toString(chId) ); + continue; + } - const Trk::TrackParameters* exPars = reachableDetEl(track,*detEl, true ); - if( !exPars ) { - ATH_MSG_DEBUG("Did not reach " << m_idHelperTool->toStringChamber(chId) << " hash " << *ith ); - continue; - } - //Identifier chId = m_idHelperTool->chamberId(detEl->identify()); - Identifier detElId = m_idHelperTool->detElId( chId ); - std::set<Identifier> layIds; - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > > tgcstates; - m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars,layIds, tgcstates ); - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >::iterator tgcit = tgcstates.begin(); - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >::iterator tgcit_end = tgcstates.end(); - ATH_MSG_DEBUG("Reached " << m_idHelperTool->toString(chId) << " hash " << *ith << " holes " << tgcstates.size() ); - - for( ;tgcit !=tgcit_end;++tgcit ){ - if( tgcit->first ) { - ATH_MSG_VERBOSE("Adding " << tgcit->second ); - states.push_back( tgcit->second ); - } + const Trk::TrackParameters* exPars = reachableDetEl(track, *detEl, true ); + if ( !exPars ) { + ATH_MSG_DEBUG("Did not reach " << m_idHelperTool->toStringChamber(chId) << " hash " << *ith ); + continue; + } + //Identifier chId = m_idHelperTool->chamberId(detEl->identify()); + Identifier detElId = m_idHelperTool->detElId( chId ); + std::set<Identifier> layIds; + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > > rpcstates; + m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars, layIds, rpcstates ); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator rpcit = rpcstates.begin(); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator rpcit_end = rpcstates.end(); + ATH_MSG_DEBUG("Reached " << m_idHelperTool->toString(chId) << " hash " << *ith << " holes " << rpcstates.size() ); + + for ( ; rpcit != rpcit_end; ++rpcit ) { + if ( rpcit->first ) { + ATH_MSG_VERBOSE("Adding " << rpcit->second ); + states.push_back( rpcit->second ); } - delete exPars; - } + } + delete exPars; + } - ith = data.rpc.begin(); - ith_end = data.rpc.end(); - for( ; ith != ith_end; ith++ ) { - // ignore hashes already on track - if( data.rpcTrack.count(*ith) ) { - ATH_MSG_VERBOSE("Chamber already on track " << *ith ); - continue; - } - Identifier chId; - IdContext otCont = m_idHelperTool->rpcIdHelper().module_context(); - m_idHelperTool->rpcIdHelper().get_id(*ith, chId, &otCont); - chId = m_idHelperTool->chamberId(chId); - - const MuonGM::RpcReadoutElement* detEl = m_detMgr->getRpcReadoutElement(chId); - if( !detEl ){ - ATH_MSG_WARNING("Found no detector element for " << *ith << " " << m_idHelperTool->toString(chId) ); - continue; - } + // New Small Wheel + // sTGC + ith = data.stgc.begin(); + ith_end = data.stgc.end(); + for ( ; ith != ith_end; ith++ ) { - const Trk::TrackParameters* exPars = reachableDetEl(track,*detEl, true ); - if( !exPars ) { - ATH_MSG_DEBUG("Did not reach " << m_idHelperTool->toStringChamber(chId) << " hash " << *ith ); - continue; + // ignore hashes already on track + if ( data.stgcTrack.count(*ith) ) { + ATH_MSG_VERBOSE("Chamber already on track " << *ith ); + continue; + } + Identifier chId; + IdContext otCont = m_idHelperTool->stgcIdHelper().module_context(); + m_idHelperTool->stgcIdHelper().get_id(*ith, chId, &otCont); + chId = m_idHelperTool->chamberId(chId); + + const MuonGM::sTgcReadoutElement* detEl = m_detMgr->getsTgcReadoutElement(chId); + if ( !detEl ) { + ATH_MSG_WARNING("Found no detector element for " << *ith << " " << m_idHelperTool->toString(chId) ); + continue; + } + + const Trk::TrackParameters* exPars = reachableDetEl(track, *detEl, true ); + if ( !exPars ) { + ATH_MSG_DEBUG("Did not reach " << m_idHelperTool->toStringChamber(chId) << " hash " << *ith ); + continue; + } + //Identifier chId = m_idHelperTool->chamberId(detEl->identify()); + Identifier detElId = m_idHelperTool->detElId( chId ); + std::set<Identifier> layIds; + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > > stgcstates; + m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars, layIds, stgcstates ); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator stgcit = stgcstates.begin(); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator stgcit_end = stgcstates.end(); + ATH_MSG_DEBUG("Reached " << m_idHelperTool->toString(chId) << " hash " << *ith << " holes " << stgcstates.size() ); + + for ( ; stgcit != stgcit_end; ++stgcit ) { + if ( stgcit->first ) { + ATH_MSG_VERBOSE("Adding " << stgcit->second ); + states.push_back( stgcit->second ); } - //Identifier chId = m_idHelperTool->chamberId(detEl->identify()); - Identifier detElId = m_idHelperTool->detElId( chId ); - std::set<Identifier> layIds; - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > > rpcstates; - m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars,layIds, rpcstates ); - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >::iterator rpcit = rpcstates.begin(); - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >::iterator rpcit_end = rpcstates.end(); - ATH_MSG_DEBUG("Reached " << m_idHelperTool->toString(chId) << " hash " << *ith << " holes " << rpcstates.size() ); - - for( ;rpcit !=rpcit_end;++rpcit ){ - if( rpcit->first ) { - ATH_MSG_VERBOSE("Adding " << rpcit->second ); - states.push_back( rpcit->second ); - } + } + delete exPars; + } + + // MM + ith = data.mm.begin(); + ith_end = data.mm.end(); + for ( ; ith != ith_end; ith++ ) { + + // ignore hashes already on track + if ( data.mmTrack.count(*ith) ) { + ATH_MSG_VERBOSE("Chamber already on track " << *ith ); + continue; + } + Identifier chId; + IdContext otCont = m_idHelperTool->mmIdHelper().module_context(); + m_idHelperTool->mmIdHelper().get_id(*ith, chId, &otCont); + chId = m_idHelperTool->chamberId(chId); + + const MuonGM::MMReadoutElement* detEl = m_detMgr->getMMReadoutElement(chId); + if ( !detEl ) { + ATH_MSG_WARNING("Found no detector element for " << *ith << " " << m_idHelperTool->toString(chId) ); + continue; + } + + const Trk::TrackParameters* exPars = reachableDetEl(track, *detEl, true ); + if ( !exPars ) { + ATH_MSG_DEBUG("Did not reach " << m_idHelperTool->toStringChamber(chId) << " hash " << *ith ); + continue; + } + //Identifier chId = m_idHelperTool->chamberId(detEl->identify()); + Identifier detElId = m_idHelperTool->detElId( chId ); + std::set<Identifier> layIds; + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > > mmstates; + m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars, layIds, mmstates ); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator mmit = mmstates.begin(); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator mmit_end = mmstates.end(); + ATH_MSG_DEBUG("Reached " << m_idHelperTool->toString(chId) << " hash " << *ith << " holes " << mmstates.size() ); + + for ( ; mmit != mmit_end; ++mmit ) { + if ( mmit->first ) { + ATH_MSG_VERBOSE("Adding " << mmit->second ); + states.push_back( mmit->second ); } - delete exPars; - } + } + delete exPars; + } - if( !states.empty() ){ - //std::cout << " adding new states " << states.size() << std::endl; - // states were added, create a new track - DataVector<const Trk::TrackStateOnSurface>* trackStateOnSurfaces = new DataVector<const Trk::TrackStateOnSurface>(); - trackStateOnSurfaces->reserve( oldStates->size() + states.size() ); - std::vector<const Trk::TrackStateOnSurface*> toBeSorted; - toBeSorted.reserve( oldStates->size() + states.size() ); - - DataVector<const Trk::TrackStateOnSurface>::const_iterator sit = oldStates->begin(); - DataVector<const Trk::TrackStateOnSurface>::const_iterator sit_end = oldStates->end(); - for( ;sit!=sit_end;++sit ) toBeSorted.push_back( (*sit)->clone() ); + if ( !states.empty() ) { + //std::cout << " adding new states " << states.size() << std::endl; - std::vector<const Trk::TrackStateOnSurface*>::iterator sit1 = states.begin(); - std::vector<const Trk::TrackStateOnSurface*>::iterator sit1_end = states.end(); - //for( ;sit1!=sit1_end;++sit1 ) trackStateOnSurfaces->push_back( *sit1 ); - for( ;sit1!=sit1_end;++sit1 ) toBeSorted.push_back( *sit1 ); + // states were added, create a new track + DataVector<const Trk::TrackStateOnSurface>* trackStateOnSurfaces = new DataVector<const Trk::TrackStateOnSurface>(); + trackStateOnSurfaces->reserve( oldStates->size() + states.size() ); - std::stable_sort(toBeSorted.begin(),toBeSorted.end(),SortTSOSs(&*m_helperTool,&*m_idHelperTool)); + std::vector<const Trk::TrackStateOnSurface*> toBeSorted; + toBeSorted.reserve( oldStates->size() + states.size() ); - trackStateOnSurfaces->insert(trackStateOnSurfaces->begin(),toBeSorted.begin(),toBeSorted.end()); - Trk::Track* trackWithHoles = new Trk::Track( track.info(), trackStateOnSurfaces, track.fitQuality() ? track.fitQuality()->clone():0 ); - ATH_MSG_DEBUG("Track with holes " << m_printer->print(*trackWithHoles) << std::endl << m_printer->printStations(*trackWithHoles) ); - return trackWithHoles; - } - return 0; + DataVector<const Trk::TrackStateOnSurface>::const_iterator sit = oldStates->begin(); + DataVector<const Trk::TrackStateOnSurface>::const_iterator sit_end = oldStates->end(); + for ( ; sit != sit_end; ++sit ) toBeSorted.push_back( (*sit)->clone() ); + + std::vector<const Trk::TrackStateOnSurface*>::iterator sit1 = states.begin(); + std::vector<const Trk::TrackStateOnSurface*>::iterator sit1_end = states.end(); + //for( ;sit1!=sit1_end;++sit1 ) trackStateOnSurfaces->push_back( *sit1 ); + for ( ; sit1 != sit1_end; ++sit1 ) toBeSorted.push_back( *sit1 ); + + std::stable_sort(toBeSorted.begin(), toBeSorted.end(), SortTSOSs(&*m_helperTool, &*m_idHelperTool)); + + trackStateOnSurfaces->insert(trackStateOnSurfaces->begin(), toBeSorted.begin(), toBeSorted.end()); + Trk::Track* trackWithHoles = new Trk::Track( track.info(), trackStateOnSurfaces, track.fitQuality() ? track.fitQuality()->clone() : 0 ); + ATH_MSG_DEBUG("Track with holes " << m_printer->print(*trackWithHoles) << std::endl << m_printer->printStations(*trackWithHoles) ); + return trackWithHoles; } - - const Trk::Track* MuonSegmentRegionRecoveryTool::addMissingChambers( const Trk::Track& track, MuonData& data, bool addMdt ) const { + return 0; +} - // states were added, create a new track - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > > states; - std::set<IdentifierHash> newMdtHashes; - std::set<IdentifierHash> newRpcHashes; - std::set<IdentifierHash> newTgcHashes; - std::set<IdentifierHash> newCscHashes; - if( addMdt){ - ATH_MSG_DEBUG("Adding Missing MDT chambers: regions " << data.mdtPerStation.size() ); - std::map<MuonStationIndex::ChIndex, std::set<IdentifierHash> >::iterator chit = data.mdtPerStation.begin(); - std::map<MuonStationIndex::ChIndex, std::set<IdentifierHash> >::iterator chit_end = data.mdtPerStation.end(); - std::vector<const MdtPrepDataCollection*> newmcols; - for( ;chit!=chit_end;++chit ){ - ATH_MSG_VERBOSE("Region " << MuonStationIndex::chName(chit->first) << " size " << chit->second.size() ); - std::vector<const MdtPrepDataCollection*> cols; - m_seededSegmentFinder->extractMdtPrdCols( chit->second, cols ); - std::vector<const MdtPrepDataCollection*>::iterator mit = cols.begin(); - std::vector<const MdtPrepDataCollection*>::iterator mit_end = cols.end(); - std::map<int,std::vector<const MdtPrepData*> > mdtPrds; - const Trk::TrackParameters* exParsFirst = 0; - for( ;mit!=mit_end;++mit ){ - const Trk::TrackParameters* exPars = reachableDetEl( track, *(*mit)->front()->detectorElement() ); - if( exPars ){ - int sector = m_idHelperTool->sector((*mit)->identify()); - ATH_MSG_DEBUG("New chamber " << m_idHelperTool->toStringChamber((*mit)->identify()) << " hash " << (*mit)->identifyHash() << " sector " << sector ); - newmcols.push_back(*mit); - std::vector<const MdtPrepData*>& col = mdtPrds[sector]; - col.insert(col.end(),(*mit)->begin(),(*mit)->end()); - if( !exParsFirst ) exParsFirst = exPars; - else delete exPars; - }else{ - ATH_MSG_DEBUG("Did not reach chamber " << m_idHelperTool->toStringChamber((*mit)->identify()) << " hash " << (*mit)->identifyHash() ); - } - } - std::vector<const MdtPrepData*>* prds = 0; - std::map<int,std::vector<const MdtPrepData*> >::iterator sectorIt = mdtPrds.begin(); - if( mdtPrds.empty() ){ - ATH_MSG_VERBOSE("No hits selected"); - }else if( mdtPrds.size() == 1 ){ - prds = §orIt->second; - }else{ - IMuonHitSummaryTool::CompactSummary hitSummary = m_hitSummaryTool->summary(track); - ATH_MSG_VERBOSE("Multiple sectors selected, using main sector: " << hitSummary.mainSector); - std::map<int,std::vector<const MdtPrepData*> >::iterator pos = mdtPrds.find(hitSummary.mainSector); - if( pos != mdtPrds.end() ) prds = &pos->second; - else{ - ATH_MSG_DEBUG("Failed to find prds in main sector: " << hitSummary.mainSector); - } - } - if( prds && exParsFirst){ - std::vector<const MuonSegment*>* segments = m_seededSegmentFinder->find(*exParsFirst,*prds ); - if( segments ){ - if( !segments->empty() ) ATH_MSG_DEBUG("found segments " << segments->size() ); - std::vector<const MuonSegment*>::iterator sit = segments->begin(); - std::vector<const MuonSegment*>::iterator sit_end = segments->end(); - - const MuonSegment* bestSegment = 0; - const Trk::TrackParameters* bestSegmentPars = 0; - for( ;sit!=sit_end;++sit ) { - - if( m_trackSegmentMatchingTool.empty() ) ATH_MSG_VERBOSE("No track/segment matching"); - else if( !m_trackSegmentMatchingTool->match(track,**sit,true) ) { - ATH_MSG_DEBUG(" Segment does not match with track "); - continue; - }else{ - ATH_MSG_DEBUG(" Segment/track matched successfully using " << m_trackSegmentMatchingTool ); - } - const Trk::TrackParameters* segPars = m_extrapolator->extrapolateDirectly(*exParsFirst,(*sit)->associatedSurface(), - Trk::anyDirection,false,Trk::muon); - if( segPars ){ - double resy = (*sit)->localParameters()[Trk::locY] - segPars->parameters()[Trk::locY]; - Trk::LocalDirection locDir; - (*sit)->associatedSurface().globalToLocalDirection(segPars->momentum(),locDir); - double dangleYZ = (*sit)->localDirection().angleYZ() - locDir.angleYZ(); - ATH_MSG_DEBUG("resy " << resy << " dangleYZ " << dangleYZ << " " << m_printer->print(**sit) ); - if( fabs(dangleYZ) < 0.05 ){ - bestSegment = *sit; - if( bestSegmentPars ) delete bestSegmentPars; - bestSegmentPars = segPars->clone(); - } - }else{ - ATH_MSG_DEBUG("Did not reach " << m_printer->print(**sit) ); - } - delete segPars; - } - if( bestSegment ){ - std::vector< const Trk::MeasurementBase* >::const_iterator hit = bestSegment->containedMeasurements().begin(); - std::vector< const Trk::MeasurementBase* >::const_iterator hit_end = bestSegment->containedMeasurements().end(); - for( ;hit!=hit_end;++hit ){ - const Trk::TrackParameters* hitPars = m_extrapolator->extrapolateDirectly(*bestSegmentPars,(*hit)->associatedSurface(), - Trk::anyDirection,false,Trk::muon); - if( hitPars ){ - std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern; - typePattern.set(Trk::TrackStateOnSurface::Measurement); - Trk::TrackStateOnSurface* tsos = new Trk::TrackStateOnSurface( (*hit)->clone(),hitPars,0,0,typePattern ); - states.push_back( std::make_pair(true,tsos) ); - const MdtDriftCircleOnTrack* mdt = dynamic_cast<const MdtDriftCircleOnTrack*>(*hit); - if( mdt ) newMdtHashes.insert( mdt->collectionHash() ); - }else{ - ATH_MSG_WARNING("Failed to extrapolate to MDT hit "); - } - } - } - if( bestSegmentPars ) delete bestSegmentPars; - for( sit=segments->begin();sit!=sit_end;++sit ) delete *sit; - delete segments; - } - } - delete exParsFirst; +const Trk::Track* MuonSegmentRegionRecoveryTool::addMissingChambers( const Trk::Track& track, MuonData& data, bool addMdt ) const { + + // states were added, create a new track + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > > states; + std::set<IdentifierHash> newMdtHashes; + std::set<IdentifierHash> newRpcHashes; + std::set<IdentifierHash> newTgcHashes; + std::set<IdentifierHash> newCscHashes; + // New Small Wheel + std::set<IdentifierHash> newMMHashes; + std::set<IdentifierHash> newsTgcHashes; + if ( addMdt) { + ATH_MSG_DEBUG("Adding Missing MDT chambers: regions " << data.mdtPerStation.size() ); + std::map<MuonStationIndex::ChIndex, std::set<IdentifierHash> >::iterator chit = data.mdtPerStation.begin(); + std::map<MuonStationIndex::ChIndex, std::set<IdentifierHash> >::iterator chit_end = data.mdtPerStation.end(); + std::vector<const MdtPrepDataCollection*> newmcols; + for ( ; chit != chit_end; ++chit ) { + ATH_MSG_VERBOSE("Region " << MuonStationIndex::chName(chit->first) << " size " << chit->second.size() ); + std::vector<const MdtPrepDataCollection*> cols; + m_seededSegmentFinder->extractMdtPrdCols( chit->second, cols ); + std::vector<const MdtPrepDataCollection*>::iterator mit = cols.begin(); + std::vector<const MdtPrepDataCollection*>::iterator mit_end = cols.end(); + std::map<int, std::vector<const MdtPrepData*> > mdtPrds; + const Trk::TrackParameters* exParsFirst = 0; + for ( ; mit != mit_end; ++mit ) { + const Trk::TrackParameters* exPars = reachableDetEl( track, *(*mit)->front()->detectorElement() ); + if ( exPars ) { + int sector = m_idHelperTool->sector((*mit)->identify()); + ATH_MSG_DEBUG("New chamber " << m_idHelperTool->toStringChamber((*mit)->identify()) << " hash " << (*mit)->identifyHash() << " sector " << sector ); + newmcols.push_back(*mit); + std::vector<const MdtPrepData*>& col = mdtPrds[sector]; + col.insert(col.end(), (*mit)->begin(), (*mit)->end()); + if ( !exParsFirst ) exParsFirst = exPars; + else delete exPars; + } else { + ATH_MSG_DEBUG("Did not reach chamber " << m_idHelperTool->toStringChamber((*mit)->identify()) << " hash " << (*mit)->identifyHash() ); + } + } + std::vector<const MdtPrepData*>* prds = 0; + std::map<int, std::vector<const MdtPrepData*> >::iterator sectorIt = mdtPrds.begin(); + if ( mdtPrds.empty() ) { + ATH_MSG_VERBOSE("No hits selected"); + } else if ( mdtPrds.size() == 1 ) { + prds = §orIt->second; + } else { + IMuonHitSummaryTool::CompactSummary hitSummary = m_hitSummaryTool->summary(track); + ATH_MSG_VERBOSE("Multiple sectors selected, using main sector: " << hitSummary.mainSector); + std::map<int, std::vector<const MdtPrepData*> >::iterator pos = mdtPrds.find(hitSummary.mainSector); + if ( pos != mdtPrds.end() ) prds = &pos->second; + else { + ATH_MSG_DEBUG("Failed to find prds in main sector: " << hitSummary.mainSector); + } + } + if ( prds && exParsFirst) { + std::vector<const MuonSegment*>* segments = m_seededSegmentFinder->find(*exParsFirst, *prds ); + if ( segments ) { + if ( !segments->empty() ) ATH_MSG_DEBUG("found segments " << segments->size() ); + std::vector<const MuonSegment*>::iterator sit = segments->begin(); + std::vector<const MuonSegment*>::iterator sit_end = segments->end(); + + const MuonSegment* bestSegment = 0; + const Trk::TrackParameters* bestSegmentPars = 0; + for ( ; sit != sit_end; ++sit ) { + + if ( m_trackSegmentMatchingTool.empty() ) ATH_MSG_VERBOSE("No track/segment matching"); + else if ( !m_trackSegmentMatchingTool->match(track, **sit, true) ) { + ATH_MSG_DEBUG(" Segment does not match with track "); + continue; + } else { + ATH_MSG_DEBUG(" Segment/track matched successfully using " << m_trackSegmentMatchingTool ); + } + const Trk::TrackParameters* segPars = m_extrapolator->extrapolateDirectly(*exParsFirst, (*sit)->associatedSurface(), + Trk::anyDirection, false, Trk::muon); + if ( segPars ) { + double resy = (*sit)->localParameters()[Trk::locY] - segPars->parameters()[Trk::locY]; + Trk::LocalDirection locDir; + (*sit)->associatedSurface().globalToLocalDirection(segPars->momentum(), locDir); + double dangleYZ = (*sit)->localDirection().angleYZ() - locDir.angleYZ(); + ATH_MSG_DEBUG("resy " << resy << " dangleYZ " << dangleYZ << " " << m_printer->print(**sit) ); + if ( fabs(dangleYZ) < 0.05 ) { + bestSegment = *sit; + if ( bestSegmentPars ) delete bestSegmentPars; + bestSegmentPars = segPars->clone(); + } + } else { + ATH_MSG_DEBUG("Did not reach " << m_printer->print(**sit) ); + } + delete segPars; + } + if ( bestSegment ) { + std::vector< const Trk::MeasurementBase* >::const_iterator hit = bestSegment->containedMeasurements().begin(); + std::vector< const Trk::MeasurementBase* >::const_iterator hit_end = bestSegment->containedMeasurements().end(); + for ( ; hit != hit_end; ++hit ) { + const Trk::TrackParameters* hitPars = m_extrapolator->extrapolateDirectly(*bestSegmentPars, (*hit)->associatedSurface(), + Trk::anyDirection, false, Trk::muon); + if ( hitPars ) { + std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern; + typePattern.set(Trk::TrackStateOnSurface::Measurement); + Trk::TrackStateOnSurface* tsos = new Trk::TrackStateOnSurface( (*hit)->clone(), hitPars, 0, 0, typePattern ); + states.push_back( std::make_pair(true, tsos) ); + const MdtDriftCircleOnTrack* mdt = dynamic_cast<const MdtDriftCircleOnTrack*>(*hit); + if ( mdt ) newMdtHashes.insert( mdt->collectionHash() ); + } else { + ATH_MSG_WARNING("Failed to extrapolate to MDT hit "); + } + } + } + if ( bestSegmentPars ) delete bestSegmentPars; + for ( sit = segments->begin(); sit != sit_end; ++sit ) delete *sit; + delete segments; + } } - data.mdtCols = newmcols; - }else{ - unsigned int nstates = states.size(); - m_seededSegmentFinder->extractRpcPrdCols( data.rpc, data.rpcCols ); - std::vector<const RpcPrepDataCollection*>::iterator rit = data.rpcCols.begin(); - std::vector<const RpcPrepDataCollection*>::iterator rit_end = data.rpcCols.end(); - std::vector<const RpcPrepDataCollection*> newrcols; - for( ;rit!=rit_end;++rit ){ - const Trk::TrackParameters* exPars = reachableDetEl( track, *(*rit)->front()->detectorElement() ); - if( exPars ){ - Identifier detElId = m_idHelperTool->detElId( (*rit)->identify() ); - std::set<Identifier> layIds; - m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars,layIds, states ); - if( states.size() != nstates ){ - nstates = states.size(); - newRpcHashes.insert( (*rit)->identifyHash() ); - } - delete exPars; - } + delete exParsFirst; + } + data.mdtCols = newmcols; + } else { + unsigned int nstates = states.size(); + m_seededSegmentFinder->extractRpcPrdCols( data.rpc, data.rpcCols ); + std::vector<const RpcPrepDataCollection*>::iterator rit = data.rpcCols.begin(); + std::vector<const RpcPrepDataCollection*>::iterator rit_end = data.rpcCols.end(); + std::vector<const RpcPrepDataCollection*> newrcols; + for ( ; rit != rit_end; ++rit ) { + const Trk::TrackParameters* exPars = reachableDetEl( track, *(*rit)->front()->detectorElement() ); + if ( exPars ) { + Identifier detElId = m_idHelperTool->detElId( (*rit)->identify() ); + std::set<Identifier> layIds; + m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars, layIds, states ); + if ( states.size() != nstates ) { + nstates = states.size(); + newRpcHashes.insert( (*rit)->identifyHash() ); + } + delete exPars; } - data.rpcCols = newrcols; - - m_seededSegmentFinder->extractTgcPrdCols( data.tgc, data.tgcCols ); - std::vector<const TgcPrepDataCollection*>::const_iterator tit = data.tgcCols.begin(); - std::vector<const TgcPrepDataCollection*>::const_iterator tit_end = data.tgcCols.end(); - std::vector<const TgcPrepDataCollection*> newtcols; - for( ;tit!=tit_end;++tit ){ - const Trk::TrackParameters* exPars = reachableDetEl( track, *(*tit)->front()->detectorElement() ); - if( exPars ){ - newtcols.push_back(*tit); - Identifier detElId = m_idHelperTool->detElId( (*tit)->identify() ); - std::set<Identifier> layIds; - m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars,layIds, states ); - if( states.size() != nstates ){ - nstates = states.size(); - newTgcHashes.insert( (*tit)->identifyHash() ); - } - - delete exPars; - } + } + data.rpcCols = newrcols; + + m_seededSegmentFinder->extractTgcPrdCols( data.tgc, data.tgcCols ); + std::vector<const TgcPrepDataCollection*>::const_iterator tit = data.tgcCols.begin(); + std::vector<const TgcPrepDataCollection*>::const_iterator tit_end = data.tgcCols.end(); + std::vector<const TgcPrepDataCollection*> newtcols; + for ( ; tit != tit_end; ++tit ) { + const Trk::TrackParameters* exPars = reachableDetEl( track, *(*tit)->front()->detectorElement() ); + if ( exPars ) { + newtcols.push_back(*tit); + Identifier detElId = m_idHelperTool->detElId( (*tit)->identify() ); + std::set<Identifier> layIds; + m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars, layIds, states ); + if ( states.size() != nstates ) { + nstates = states.size(); + newTgcHashes.insert( (*tit)->identifyHash() ); + } + + delete exPars; } - data.tgcCols = newtcols; + } + data.tgcCols = newtcols; + if (!m_doNSW) { m_seededSegmentFinder->extractCscPrdCols( data.csc, data.cscCols ); std::vector<const CscPrepDataCollection*>::const_iterator cit = data.cscCols.begin(); std::vector<const CscPrepDataCollection*>::const_iterator cit_end = data.cscCols.end(); std::vector<const CscPrepDataCollection*> newccols; - for( ;cit!=cit_end;++cit ){ - const Trk::TrackParameters* exPars = reachableDetEl( track, *(*cit)->front()->detectorElement() ); - if( exPars ){ - newccols.push_back(*cit); - Identifier detElId = m_idHelperTool->detElId( (*cit)->identify() ); - std::set<Identifier> layIds; - m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars,layIds, states ); - if( states.size() != nstates ){ - nstates = states.size(); - newCscHashes.insert( (*cit)->identifyHash() ); - } - - delete exPars; - } + for ( ; cit != cit_end; ++cit ) { + const Trk::TrackParameters* exPars = reachableDetEl( track, *(*cit)->front()->detectorElement() ); + if ( exPars ) { + newccols.push_back(*cit); + Identifier detElId = m_idHelperTool->detElId( (*cit)->identify() ); + std::set<Identifier> layIds; + m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars, layIds, states ); + if ( states.size() != nstates ) { + nstates = states.size(); + newCscHashes.insert( (*cit)->identifyHash() ); + } + + delete exPars; + } } data.cscCols = newccols; } - if( !states.empty() ) { - ATH_MSG_DEBUG("Collected new states: " << states.size()); - - const DataVector<const Trk::TrackStateOnSurface>* oldStates = track.trackStateOnSurfaces(); - if( !oldStates ){ - ATH_MSG_WARNING(" track without states, cannot perform cleaning "); - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >::iterator nit = states.begin(); - std::vector< std::pair<bool,const Trk::TrackStateOnSurface* > >::iterator nit_end = states.end(); - for( ;nit!=nit_end;++nit ){ - if( nit->first ) delete nit->second; - } - return 0; - } - - - // states were added, create a new track - std::vector<const Trk::TrackStateOnSurface*> newStates; - newStates.reserve( oldStates->size() + states.size() ); - - ATH_MSG_DEBUG("Copying old TSOSs " << oldStates->size()); - DataVector<const Trk::TrackStateOnSurface>::const_iterator tsit = oldStates->begin(); - DataVector<const Trk::TrackStateOnSurface>::const_iterator tsit_end = oldStates->end(); - for( ;tsit!=tsit_end;++tsit ) newStates.push_back( (*tsit)->clone() ); - - - ATH_MSG_DEBUG("Adding new TSOSs " << states.size() << " current size " << newStates.size()); - std::vector< std::pair<bool,const Trk::TrackStateOnSurface*> >::iterator nit = states.begin(); - std::vector< std::pair<bool,const Trk::TrackStateOnSurface*> >::iterator nit_end = states.end(); - for( ;nit!=nit_end;++nit ){ - // add states. If nit->first is true we have a new state. If it is false the state is from the old track and has to be cloned - newStates.push_back( nit->first ? nit->second : nit->second->clone() ); + } + + if(m_doNSW) { + // New Small Wheel + // sTGC + unsigned int nstates = states.size(); + m_seededSegmentFinder->extractsTgcPrdCols( data.stgc, data.stgcCols ); + std::vector<const sTgcPrepDataCollection*>::const_iterator stit = data.stgcCols.begin(); + std::vector<const sTgcPrepDataCollection*>::const_iterator stit_end = data.stgcCols.end(); + std::vector<const sTgcPrepDataCollection*> newstcols; + ATH_MSG_DEBUG(" extractsTgcPrdCols data.stgcCols.size() " << data.stgcCols.size()); + for ( ; stit != stit_end; ++stit ) { + const Trk::TrackParameters* exPars = reachableDetEl( track, *(*stit)->front()->detectorElement() ); + if ( exPars ) { + newstcols.push_back(*stit); + Identifier detElId = m_idHelperTool->detElId( (*stit)->identify() ); + std::set<Identifier> layIds; + m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars, layIds, states ); + ATH_MSG_DEBUG("Collected new sTgc states: " << states.size()); + if ( states.size() != nstates ) { + nstates = states.size(); + newsTgcHashes.insert( (*stit)->identifyHash() ); + } + + delete exPars; } - std::stable_sort(newStates.begin(),newStates.end(),SortTSOSs(&*m_helperTool,&*m_idHelperTool)); - - ATH_MSG_DEBUG("Filling DataVector with TSOSs " << newStates.size()); - DataVector<const Trk::TrackStateOnSurface>* trackStateOnSurfaces = new DataVector<const Trk::TrackStateOnSurface>(); - trackStateOnSurfaces->reserve( newStates.size() ); - trackStateOnSurfaces->insert( trackStateOnSurfaces->begin(), newStates.begin(), newStates.end() ); - - ATH_MSG_DEBUG("Creating new Track " << newStates.size()); - Trk::Track* newTrack = new Trk::Track( track.info(), trackStateOnSurfaces, track.fitQuality() ? track.fitQuality()->clone():0 ); - const Trk::Track* refittedTrack = m_fitter->fit(*newTrack,m_useFitterOutlierLogic,Trk::muon); - delete newTrack; - if( refittedTrack ){ - ATH_MSG_DEBUG("New Track " << m_printer->print(*refittedTrack) << std::endl << m_printer->printStations(*refittedTrack) ); - - // fit ok, add new hashs to lists - data.mdtTrack.insert(newMdtHashes.begin(),newMdtHashes.end()); - data.rpcTrack.insert(newRpcHashes.begin(),newRpcHashes.end()); - data.tgcTrack.insert(newTgcHashes.begin(),newTgcHashes.end()); - data.cscTrack.insert(newCscHashes.begin(),newCscHashes.end()); + } + data.stgcCols = newstcols; + + // MM + m_seededSegmentFinder->extractMMPrdCols( data.mm, data.mmCols ); + ATH_MSG_DEBUG(" extractMMPrdCols data.mmCols.size() " << data.mmCols.size()); + std::vector<const MMPrepDataCollection*>::const_iterator mit = data.mmCols.begin(); + std::vector<const MMPrepDataCollection*>::const_iterator mit_end = data.mmCols.end(); + std::vector<const MMPrepDataCollection*> newmcols; + for ( ; mit != mit_end; ++mit ) { + const Trk::TrackParameters* exPars = reachableDetEl( track, *(*mit)->front()->detectorElement() ); + if ( exPars ) { + newmcols.push_back(*mit); + Identifier detElId = m_idHelperTool->detElId( (*mit)->identify() ); + std::set<Identifier> layIds; + m_chamberHoleRecoveryTool->createHoleTSOSsForClusterChamber( detElId, *exPars, layIds, states ); + ATH_MSG_DEBUG("Collected new Mm states: " << states.size()); + if ( states.size() != nstates ) { + nstates = states.size(); + newMMHashes.insert( (*mit)->identifyHash() ); + } + + delete exPars; } - return refittedTrack; } - return 0; - //delete newStates; + data.mmCols = newmcols; + } - - const Trk::TrackParameters* MuonSegmentRegionRecoveryTool::reachableDetEl( const Trk::Track& track, const Trk::TrkDetElementBase& detEl, bool smallerBounds ) const{ - - ATH_MSG_VERBOSE( "reachableDetEl() " << m_idHelperTool->toStringDetEl( detEl.identify() ) << " at " << detEl.center() ); - const Trk::TrackParameters* exPars = 0; - Trk::TrackParameters* closest = MuonGetClosestParameters::closestParameters(track,detEl.surface(),true); - if( closest ){ - if( msgLvl(MSG::VERBOSE) ){ - ATH_MSG_VERBOSE( "Extrapolating from closest point:\n" << m_printer->print( *closest ) ); - } - exPars = m_extrapolator->extrapolateDirectly(*closest,detEl.surface(),Trk::anyDirection,false,Trk::muon); - delete closest; - }else{ - ATH_MSG_VERBOSE( "Extrapolating from track (no closest point found):\n" << m_printer->print( track ) ); - exPars = m_extrapolator->extrapolate(track,detEl.surface(),Trk::anyDirection,false,Trk::muon); - } - if( !exPars ) return 0; - Amg::Vector2D locPos( exPars->parameters()[Trk::locX], exPars->parameters()[Trk::locY] ); - - double tolx = 100.; // positive -> large surface - double toly = 100.; // positive -> large surface - const AmgSymMatrix(5)* errMat = exPars->covariance(); - if( errMat ) { - ATH_MSG_VERBOSE( "Extrapolated local Position & Error matrix\n:" << locPos << "\n" << Amg::toString(*errMat) ); - // MJW check validity of errors before using them (fix for bug #82920) - double covx = (*errMat)(Trk::locX,Trk::locX); - double covy = (*errMat)(Trk::locY,Trk::locY); - if ( covx > 0.0 && covy > 0.0 ) { - tolx = 3 * covx ; - toly = 3 * covy; + + if ( !states.empty() ) { + ATH_MSG_DEBUG("Collected new states: " << states.size()); + + const DataVector<const Trk::TrackStateOnSurface>* oldStates = track.trackStateOnSurfaces(); + if ( !oldStates ) { + ATH_MSG_WARNING(" track without states, cannot perform cleaning "); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator nit = states.begin(); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface* > >::iterator nit_end = states.end(); + for ( ; nit != nit_end; ++nit ) { + if ( nit->first ) delete nit->second; } + return 0; } - // in case we are looking for holes, only ignore stations if we are within 100 mm of the chamber edge - // all other holes are counted even if the extrapolation errors are large. - if( smallerBounds ) { - if( tolx > 10. ) tolx = 10.; - if( toly > 10. ) toly = 10.; - // refer sign to check 'inside' the bounds - tolx *= -1.; - toly *= -1.; - } - bool inbounds = detEl.surface().insideBounds(locPos,tolx,toly); - - if( msgLvl(MSG::DEBUG) ){ - - std::ostringstream parsType; - parsType << "pos=(" << locPos[Trk::locX] - << "," << locPos[Trk::locY] << ")"; - if( errMat ) { - parsType << " exError=(" << Amg::error(*errMat,Trk::locX) << "," << Amg::error(*errMat,Trk::locY) << ")"; - } - parsType << " tolerance=(" << tolx << "," << toly << ")"; - if( inbounds ) parsType << " => inbounds"; - else parsType << " => outbounds"; - ATH_MSG_DEBUG(" " << m_idHelperTool->toStringChamber( detEl.identify() ) << " pars " << parsType.str() ); + + // states were added, create a new track + std::vector<const Trk::TrackStateOnSurface*> newStates; + newStates.reserve( oldStates->size() + states.size() ); + + ATH_MSG_DEBUG("Copying old TSOSs " << oldStates->size()); + DataVector<const Trk::TrackStateOnSurface>::const_iterator tsit = oldStates->begin(); + DataVector<const Trk::TrackStateOnSurface>::const_iterator tsit_end = oldStates->end(); + for ( ; tsit != tsit_end; ++tsit ) newStates.push_back( (*tsit)->clone() ); + + + ATH_MSG_DEBUG("Adding new TSOSs " << states.size() << " current size " << newStates.size()); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface*> >::iterator nit = states.begin(); + std::vector< std::pair<bool, const Trk::TrackStateOnSurface*> >::iterator nit_end = states.end(); + for ( ; nit != nit_end; ++nit ) { + // add states. If nit->first is true we have a new state. If it is false the state is from the old track and has to be cloned + newStates.push_back( nit->first ? nit->second : nit->second->clone() ); } - if( !inbounds ) { - delete exPars; - return 0; + std::stable_sort(newStates.begin(), newStates.end(), SortTSOSs(&*m_helperTool, &*m_idHelperTool)); + + ATH_MSG_DEBUG("Filling DataVector with TSOSs " << newStates.size()); + DataVector<const Trk::TrackStateOnSurface>* trackStateOnSurfaces = new DataVector<const Trk::TrackStateOnSurface>(); + trackStateOnSurfaces->reserve( newStates.size() ); + trackStateOnSurfaces->insert( trackStateOnSurfaces->begin(), newStates.begin(), newStates.end() ); + + ATH_MSG_DEBUG("Creating new Track " << newStates.size()); + Trk::Track* newTrack = new Trk::Track( track.info(), trackStateOnSurfaces, track.fitQuality() ? track.fitQuality()->clone() : 0 ); + const Trk::Track* refittedTrack = m_fitter->fit(*newTrack, m_useFitterOutlierLogic, Trk::muon); + delete newTrack; + if ( refittedTrack ) { + ATH_MSG_DEBUG("New Track " << m_printer->print(*refittedTrack) << std::endl << m_printer->printStations(*refittedTrack) ); + + // fit ok, add new hashs to lists + data.mdtTrack.insert(newMdtHashes.begin(), newMdtHashes.end()); + data.rpcTrack.insert(newRpcHashes.begin(), newRpcHashes.end()); + data.tgcTrack.insert(newTgcHashes.begin(), newTgcHashes.end()); + data.cscTrack.insert(newCscHashes.begin(), newCscHashes.end()); + // New Small Wheel + data.stgcTrack.insert(newsTgcHashes.begin(), newsTgcHashes.end()); + data.mmTrack.insert(newMMHashes.begin(), newMMHashes.end()); } + return refittedTrack; + } + return 0; + //delete newStates; +} - return exPars; +const Trk::TrackParameters* MuonSegmentRegionRecoveryTool::reachableDetEl( const Trk::Track& track, const Trk::TrkDetElementBase& detEl, bool smallerBounds ) const { + + ATH_MSG_VERBOSE( "reachableDetEl() " << m_idHelperTool->toStringDetEl( detEl.identify() ) << " at " << detEl.center() ); + const Trk::TrackParameters* exPars = 0; + Trk::TrackParameters* closest = MuonGetClosestParameters::closestParameters(track, detEl.surface(), true); + if ( closest ) { + if ( msgLvl(MSG::VERBOSE) ) { + ATH_MSG_VERBOSE( "Extrapolating from closest point:\n" << m_printer->print( *closest ) ); + } + exPars = m_extrapolator->extrapolateDirectly(*closest, detEl.surface(), Trk::anyDirection, false, Trk::muon); + delete closest; + } else { + ATH_MSG_VERBOSE( "Extrapolating from track (no closest point found):\n" << m_printer->print( track ) ); + exPars = m_extrapolator->extrapolate(track, detEl.surface(), Trk::anyDirection, false, Trk::muon); } + if ( !exPars ) return 0; + Amg::Vector2D locPos( exPars->parameters()[Trk::locX], exPars->parameters()[Trk::locY] ); + + double tolx = 100.; // positive -> large surface + double toly = 100.; // positive -> large surface + const AmgSymMatrix(5)* errMat = exPars->covariance(); + if ( errMat ) { + ATH_MSG_VERBOSE( "Extrapolated local Position & Error matrix\n:" << locPos << "\n" << Amg::toString(*errMat) ); + // MJW check validity of errors before using them (fix for bug #82920) + double covx = (*errMat)(Trk::locX, Trk::locX); + double covy = (*errMat)(Trk::locY, Trk::locY); + if ( covx > 0.0 && covy > 0.0 ) { + tolx = 3 * covx ; + toly = 3 * covy; + } + } + + // in case we are looking for holes, only ignore stations if we are within 100 mm of the chamber edge + // all other holes are counted even if the extrapolation errors are large. + if ( smallerBounds ) { + if ( tolx > 10. ) tolx = 10.; + if ( toly > 10. ) toly = 10.; + // refer sign to check 'inside' the bounds + tolx *= -1.; + toly *= -1.; + } + bool inbounds = detEl.surface().insideBounds(locPos, tolx, toly); + + if ( msgLvl(MSG::DEBUG) ) { + + std::ostringstream parsType; + parsType << "pos=(" << locPos[Trk::locX] + << "," << locPos[Trk::locY] << ")"; + if ( errMat ) { + parsType << " exError=(" << Amg::error(*errMat, Trk::locX) << "," << Amg::error(*errMat, Trk::locY) << ")"; + } + parsType << " tolerance=(" << tolx << "," << toly << ")"; + if ( inbounds ) parsType << " => inbounds"; + else parsType << " => outbounds"; + ATH_MSG_DEBUG(" " << m_idHelperTool->toStringChamber( detEl.identify() ) << " pars " << parsType.str() ); + } + if ( !inbounds ) { + delete exPars; + return 0; + } + + return exPars; +} + - } diff --git a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSegmentRegionRecoveryTool.h b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSegmentRegionRecoveryTool.h index fc8db5d0d9286f30d8568f2cfbe006d12f441399..ca517c0b3775f8947a914e63394c0fc88a59c3dc 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSegmentRegionRecoveryTool.h +++ b/MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSegmentRegionRecoveryTool.h @@ -32,6 +32,10 @@ #include "MuonPrepRawData/RpcPrepDataCollection.h" #include "MuonPrepRawData/TgcPrepDataCollection.h" #include "MuonPrepRawData/CscPrepDataCollection.h" +// New Small Wheel +#include "MuonPrepRawData/sTgcPrepDataCollection.h" +#include "MuonPrepRawData/MMPrepDataCollection.h" + #include "MuonIdHelpers/MuonStationIndex.h" #include "IRegionSelector/RegSelEnums.h" @@ -48,6 +52,9 @@ class MdtIdHelper; class RpcIdHelper; class TgcIdHelper; class CscIdHelper; +// New Small Wheel +class sTgcIdHelper; +class MMIdHelper; class IRegSelSvc; class IRoiDescriptor; @@ -108,6 +115,13 @@ namespace Muon { std::set<IdentifierHash> csc; std::set<IdentifierHash> cscTrack; std::vector<const CscPrepDataCollection*> cscCols; + // New Small Wheel + std::set<IdentifierHash> stgc; + std::set<IdentifierHash> stgcTrack; + std::vector<const sTgcPrepDataCollection*> stgcCols; + std::set<IdentifierHash> mm; + std::set<IdentifierHash> mmTrack; + std::vector<const MMPrepDataCollection*> mmCols; }; public: /** @brief constructor */ @@ -168,6 +182,8 @@ namespace Muon { bool m_excludeEES; bool m_onlyEO; bool m_useFitterOutlierLogic; + bool m_doNSW; + }; }