diff --git a/MuonSpectrometer/MuonReconstruction/MuonPatternFinders/MuonPatternFinderTools/MuonHoughPatternTools/MuonHoughPatternTools/MuonLayerHoughTool.h b/MuonSpectrometer/MuonReconstruction/MuonPatternFinders/MuonPatternFinderTools/MuonHoughPatternTools/MuonHoughPatternTools/MuonLayerHoughTool.h index 874adb2e859d8225ea4efcc6ea6684e4f3ff41de..19ad160753d7c90e4bbbe54f5eb19b806e2bacde 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonPatternFinders/MuonPatternFinderTools/MuonHoughPatternTools/MuonHoughPatternTools/MuonLayerHoughTool.h +++ b/MuonSpectrometer/MuonReconstruction/MuonPatternFinders/MuonPatternFinderTools/MuonHoughPatternTools/MuonHoughPatternTools/MuonLayerHoughTool.h @@ -52,7 +52,51 @@ namespace MuonHough { class HitDebugInfo; } +namespace Muon { + struct HoughDataPerSec { + typedef std::vector<MuonHough::Hit*> HitVec; + typedef std::vector< HitVec > RegionHitVec; + typedef std::vector<MuonHough::PhiHit*> PhiHitVec; + typedef std::vector< PhiHitVec > RegionPhiHitVec; + typedef std::vector<MuonHough::MuonLayerHough::Maximum*> MaximumVec; + typedef std::vector<MuonHough::MuonPhiLayerHough::Maximum*> PhiMaximumVec; + typedef std::map<MuonHough::MuonLayerHough::Maximum*, MaximumVec > MaximumAssociationMap; + typedef std::vector< MaximumVec > RegionMaximumVec; + typedef std::vector< PhiMaximumVec > RegionPhiMaximumVec; + + HoughDataPerSec() { + sector = -1; + hitVec.resize(MuonStationIndex::sectorLayerHashMax()); + maxVec.resize(MuonStationIndex::sectorLayerHashMax()); + phiHitVec.resize(MuonStationIndex::DetectorRegionIndexMax); + phiMaxVec.resize(MuonStationIndex::DetectorRegionIndexMax); + nlayersWithMaxima.resize(MuonStationIndex::DetectorRegionIndexMax); + nphilayersWithMaxima.resize(MuonStationIndex::DetectorRegionIndexMax); + nmaxHitsInRegion.resize(MuonStationIndex::DetectorRegionIndexMax); + nphimaxHitsInRegion.resize(MuonStationIndex::DetectorRegionIndexMax); + } + void cleanUp(); + int sector; + RegionHitVec hitVec; + RegionPhiHitVec phiHitVec; + RegionMaximumVec maxVec; + RegionPhiMaximumVec phiMaxVec; + std::vector<int> nlayersWithMaxima; + std::vector<int> nphilayersWithMaxima; + std::vector<int> nmaxHitsInRegion; + std::vector<int> nphimaxHitsInRegion; + MaximumAssociationMap maxAssociationMap; // stores association of a given maximium with other maxima in neighbouring sectors + std::set<MuonHough::MuonLayerHough::Maximum*> associatedToOtherSector; // used to flagged maxima that were already associated to another sector + // returns the number of phi and eta hits in the region with most eta hits + // regions with phi hits are always prefered over regions without + int maxEtaHits() const{ + return std::max( nmaxHitsInRegion[0], std::max( nmaxHitsInRegion[1], nmaxHitsInRegion[2] ) ); + } + }; +} +CLASS_DEF(Muon::HoughDataPerSec, 163257499, 1) +CLASS_DEF(std::vector<Muon::HoughDataPerSec>, 118215228, 1) static const InterfaceID IID_MuonLayerHoughTool("Muon::MuonLayerHoughTool",1,0); @@ -76,50 +120,20 @@ namespace Muon { typedef std::vector<CollectionsPerSector> CollectionsPerSectorVec; typedef CollectionsPerSectorVec::const_iterator CollectionsPerSectorCit; - typedef std::vector<MuonHough::Hit*> HitVec; - typedef std::vector< HitVec > RegionHitVec; - typedef std::vector<MuonHough::PhiHit*> PhiHitVec; - typedef std::vector< PhiHitVec > RegionPhiHitVec; - typedef std::vector<MuonHough::MuonLayerHough::Maximum*> MaximumVec; - typedef std::vector<MuonHough::MuonPhiLayerHough::Maximum*> PhiMaximumVec; - typedef std::map<MuonHough::MuonLayerHough::Maximum*, MaximumVec > MaximumAssociationMap; - - typedef std::vector< MaximumVec > RegionMaximumVec; - typedef std::vector< PhiMaximumVec > RegionPhiMaximumVec; - - struct HoughDataPerSector { - HoughDataPerSector() { - sector = -1; - hitVec.resize(MuonStationIndex::sectorLayerHashMax()); - maxVec.resize(MuonStationIndex::sectorLayerHashMax()); - phiHitVec.resize(MuonStationIndex::DetectorRegionIndexMax); - phiMaxVec.resize(MuonStationIndex::DetectorRegionIndexMax); - nlayersWithMaxima.resize(MuonStationIndex::DetectorRegionIndexMax); - nphilayersWithMaxima.resize(MuonStationIndex::DetectorRegionIndexMax); - nmaxHitsInRegion.resize(MuonStationIndex::DetectorRegionIndexMax); - nphimaxHitsInRegion.resize(MuonStationIndex::DetectorRegionIndexMax); - } - void cleanUp(); - int sector; - RegionHitVec hitVec; - RegionPhiHitVec phiHitVec; - RegionMaximumVec maxVec; - RegionPhiMaximumVec phiMaxVec; - std::vector<int> nlayersWithMaxima; - std::vector<int> nphilayersWithMaxima; - std::vector<int> nmaxHitsInRegion; - std::vector<int> nphimaxHitsInRegion; - MaximumAssociationMap maxAssociationMap; // stores association of a given maximium with other maxima in neighbouring sectors - std::set<MuonHough::MuonLayerHough::Maximum*> associatedToOtherSector; // used to flagged maxima that were already associated to another sector - // returns the number of phi and eta hits in the region with most eta hits - // regions with phi hits are always prefered over regions without - int maxEtaHits() const{ - return std::max( nmaxHitsInRegion[0], std::max( nmaxHitsInRegion[1], nmaxHitsInRegion[2] ) ); - } - }; - + typedef HoughDataPerSec::HitVec HitVec; + typedef HoughDataPerSec::RegionHitVec RegionHitVec; + typedef HoughDataPerSec::PhiHitVec PhiHitVec; + typedef HoughDataPerSec::RegionPhiHitVec RegionPhiHitVec; + typedef HoughDataPerSec::MaximumVec MaximumVec; + typedef HoughDataPerSec::PhiMaximumVec PhiMaximumVec; + typedef HoughDataPerSec::MaximumAssociationMap MaximumAssociationMap; + typedef HoughDataPerSec::RegionMaximumVec RegionMaximumVec; + typedef HoughDataPerSec::RegionPhiMaximumVec RegionPhiMaximumVec; + + typedef HoughDataPerSec HoughDataPerSector; typedef std::vector<HoughDataPerSector> HoughDataPerSectorVec; typedef HoughDataPerSectorVec::const_iterator HoughDataPerSectorCit; + class Road { @@ -193,7 +207,7 @@ namespace Muon { struct State { MaximumVec seedMaxima; MuonHough::MuonDetectorHough detectorHoughTransforms; - HoughDataPerSectorVec houghDataPerSectorVec; + std::unique_ptr<HoughDataPerSectorVec> houghDataPerSectorVec { std::make_unique<HoughDataPerSectorVec>() }; std::set<Identifier> truthHits; std::set<Identifier> foundTruthHits; std::set<Identifier> outputTruthHits; @@ -274,6 +288,8 @@ namespace Muon { TTree* m_tree; mutable MuonHough::HitNtuple* m_ntuple; + SG::WriteHandleKey<HoughDataPerSectorVec> m_houghDataPerSectorVecKey {this, + "Key_MuonLayerHoughToolHoughDataPerSectorVec", "HoughDataPerSectorVec", "HoughDataPerSectorVec key"}; SG::ReadHandleKeyArray< PRD_MultiTruthCollection > m_truthNames; SG::ReadHandleKey<xAOD::TruthParticleContainer> m_MuonTruthParticlesKey; SG::ReadHandleKey<xAOD::MuonSegmentContainer> m_MuonTruthSegmentsKey; diff --git a/MuonSpectrometer/MuonReconstruction/MuonPatternFinders/MuonPatternFinderTools/MuonHoughPatternTools/src/MuonLayerHoughTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonPatternFinders/MuonPatternFinderTools/MuonHoughPatternTools/src/MuonLayerHoughTool.cxx index ac56733465a1a7ce53868e4790e72cc49bee270b..079615d0d4ef9d4d39e04c33a4f4be2d7e475d15 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonPatternFinders/MuonPatternFinderTools/MuonHoughPatternTools/src/MuonLayerHoughTool.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonPatternFinders/MuonPatternFinderTools/MuonHoughPatternTools/src/MuonLayerHoughTool.cxx @@ -251,8 +251,8 @@ namespace Muon { // create structure to hold data per sector and set the sector indices - state.houghDataPerSectorVec.resize(16); - for( unsigned int i=0;i<state.houghDataPerSectorVec.size();++i ) state.houghDataPerSectorVec[i].sector=i+1; + (*state.houghDataPerSectorVec).resize(16); + for( unsigned int i=0;i<(*state.houghDataPerSectorVec).size();++i ) (*state.houghDataPerSectorVec)[i].sector=i+1; // return DetectorRegionIndex and sectorLayerHash auto getHashes = [this]( const Identifier& id ){ @@ -267,7 +267,7 @@ namespace Muon { Identifier id = col->identify(); int sector = m_idHelper->sector(id); auto hashes = getHashes(id); - fill(state,*col,state.houghDataPerSectorVec[sector-1].hitVec[hashes.second]); + fill(state,*col,(*state.houghDataPerSectorVec)[sector-1].hitVec[hashes.second]); } for( auto col : rpcCols ){ @@ -275,7 +275,7 @@ namespace Muon { Identifier id = col->identify(); int sector = m_idHelper->sector(id); auto hashes = getHashes(id); - fill(state,*col,state.houghDataPerSectorVec[sector-1].hitVec[hashes.second],state.houghDataPerSectorVec[sector-1].phiHitVec[hashes.first]); + fill(state,*col,(*state.houghDataPerSectorVec)[sector-1].hitVec[hashes.second],(*state.houghDataPerSectorVec)[sector-1].phiHitVec[hashes.first]); } auto hashInSector = [this]( IdentifierHash hash, int sector, unsigned int sectorLayerHash ) { @@ -289,19 +289,19 @@ namespace Muon { int sector = m_idHelper->sector(id); auto hashes = getHashes(id); // fill current sector - fill(state, *col,state.houghDataPerSectorVec[sector-1].hitVec[hashes.second], - state.houghDataPerSectorVec[sector-1].phiHitVec[hashes.first],sector); + fill(state, *col,(*state.houghDataPerSectorVec)[sector-1].hitVec[hashes.second], + (*state.houghDataPerSectorVec)[sector-1].phiHitVec[hashes.first],sector); // fill neighbours if in overlap int neighbourSectorDown = sector == 1 ? 16 : sector-1; if( hashInSector(col->identifyHash(),neighbourSectorDown,hashes.second) ) - fill(state, *col,state.houghDataPerSectorVec[neighbourSectorDown-1].hitVec[hashes.second], - state.houghDataPerSectorVec[neighbourSectorDown-1].phiHitVec[hashes.first],neighbourSectorDown); + fill(state, *col,(*state.houghDataPerSectorVec)[neighbourSectorDown-1].hitVec[hashes.second], + (*state.houghDataPerSectorVec)[neighbourSectorDown-1].phiHitVec[hashes.first],neighbourSectorDown); int neighbourSectorUp = sector == 16 ? 1 : sector+1; if( hashInSector(col->identifyHash(),neighbourSectorUp,hashes.second) ) - fill(state, *col,state.houghDataPerSectorVec[neighbourSectorUp-1].hitVec[hashes.second], - state.houghDataPerSectorVec[neighbourSectorUp-1].phiHitVec[hashes.first],neighbourSectorUp); + fill(state, *col,(*state.houghDataPerSectorVec)[neighbourSectorUp-1].hitVec[hashes.second], + (*state.houghDataPerSectorVec)[neighbourSectorUp-1].phiHitVec[hashes.first],neighbourSectorUp); } @@ -319,7 +319,7 @@ namespace Muon { ATH_MSG_DEBUG("MuonLayerHoughTool::analyse"); if( m_doTruth ) getTruth(); - state.houghDataPerSectorVec.resize(16); + (*state.houghDataPerSectorVec).resize(16); // loops over all sectors, contains hashes for technology and region and chamber (?) CollectionsPerSectorCit sit = m_collectionsPerSector.begin(); @@ -328,7 +328,7 @@ namespace Muon { ATH_MSG_DEBUG("analyse: Filling hits sector " << sit->sector); - HoughDataPerSector& houghData = state.houghDataPerSectorVec[sit->sector-1]; + HoughDataPerSector& houghData = (*state.houghDataPerSectorVec)[sit->sector-1]; houghData.sector = sit->sector; // fill hits for this sector -> hitsVec and PhiHitsVec are known now @@ -343,7 +343,7 @@ namespace Muon { MuonPatternCombinationCollection* patternCombis = new MuonPatternCombinationCollection(); // loop over data and fill the hough transform - for( auto& houghData : state.houghDataPerSectorVec ){ + for( auto& houghData : (*state.houghDataPerSectorVec) ){ ATH_MSG_DEBUG("analyse: Filling Hough sector " << houghData.sector); @@ -416,8 +416,8 @@ namespace Muon { } else{ // now that the full hough transform is filled, order sectors by maxima - std::vector<HoughDataPerSector*> sectorData(state.houghDataPerSectorVec.size()); - for( unsigned int i=0;i<state.houghDataPerSectorVec.size();++i) sectorData[i] = &state.houghDataPerSectorVec[i]; + std::vector<HoughDataPerSector*> sectorData((*state.houghDataPerSectorVec).size()); + for( unsigned int i=0;i<(*state.houghDataPerSectorVec).size();++i) sectorData[i] = &(*state.houghDataPerSectorVec)[i]; std::stable_sort(sectorData.begin(),sectorData.end(),SortHoughDataPerSector()); std::vector<HoughDataPerSector*>::iterator spit = sectorData.begin(); @@ -439,7 +439,7 @@ namespace Muon { << " layers with phi maxima " << houghData.nphilayersWithMaxima[region] << " hits " << houghData.nphimaxHitsInRegion[region] ); // look for maxima in the overlap regions of sectors - associateMaximaInNeighbouringSectors(houghData,state.houghDataPerSectorVec); + associateMaximaInNeighbouringSectors(houghData,(*state.houghDataPerSectorVec)); // layers in this region int nlayers = MuonStationIndex::LayerIndexMax; @@ -459,7 +459,7 @@ namespace Muon { } if( m_ntuple ) { - fillNtuple(state.houghDataPerSectorVec); + fillNtuple((*state.houghDataPerSectorVec)); m_tree->Fill(); } @@ -472,6 +472,10 @@ namespace Muon { printTruthSummary(state.foundTruthHits,state.outputTruthHits); } + // write hough data to SG + SG::WriteHandle<HoughDataPerSectorVec> handle {m_houghDataPerSectorVecKey}; + handle.record(std::move(state.houghDataPerSectorVec)); + return patternCombis; } @@ -504,7 +508,7 @@ namespace Muon { bool isNSW=m_idHelper->issTgc(seed.hits[0]->prd->identify()) || m_idHelper->isMM(seed.hits[0]->prd->identify()); // extend seed within the current sector // sector indices have an offset of -1 because the numbering of the sectors are from 1 to 16 but the indices in the vertices are of course 0 to 15 - extendSeed( state, road, state.houghDataPerSectorVec[sector-1] ); + extendSeed( state, road, (*state.houghDataPerSectorVec)[sector-1] ); // look for maxima in the overlap regions of sectors int sectorN = sector-1; @@ -513,28 +517,28 @@ namespace Muon { if(sectorP>16) sectorP = 1; // associate the road with phi maxima - associatePhiMaxima( road, state.houghDataPerSectorVec[sector-1].phiMaxVec[region] ); + associatePhiMaxima( road, (*state.houghDataPerSectorVec)[sector-1].phiMaxVec[region] ); // if(m_addSectors && isNSW) { - extendSeed(state, road, state.houghDataPerSectorVec[sectorN-1] ); - associatePhiMaxima( road, state.houghDataPerSectorVec[sectorN-1].phiMaxVec[region] ); - extendSeed(state, road, state.houghDataPerSectorVec[sectorP-1] ); - associatePhiMaxima( road, state.houghDataPerSectorVec[sectorP-1].phiMaxVec[region] ); + extendSeed(state, road, (*state.houghDataPerSectorVec)[sectorN-1] ); + associatePhiMaxima( road, (*state.houghDataPerSectorVec)[sectorN-1].phiMaxVec[region] ); + extendSeed(state, road, (*state.houghDataPerSectorVec)[sectorP-1] ); + associatePhiMaxima( road, (*state.houghDataPerSectorVec)[sectorP-1].phiMaxVec[region] ); } if( road.neighbouringRegion != MuonStationIndex::DetectorRegionUnknown ) { - associatePhiMaxima( road, state.houghDataPerSectorVec[sector-1].phiMaxVec[road.neighbouringRegion] ); + associatePhiMaxima( road, (*state.houghDataPerSectorVec)[sector-1].phiMaxVec[road.neighbouringRegion] ); } // if close to a sector boundary, try adding maxima in that sector as well if( road.neighbouringSector != -1 ) { ATH_MSG_DEBUG(" Adding neighbouring sector " << road.neighbouringSector ); - extendSeed(state, road, state.houghDataPerSectorVec[road.neighbouringSector-1] ); - associatePhiMaxima( road, state.houghDataPerSectorVec[road.neighbouringSector-1].phiMaxVec[region] ); + extendSeed(state, road, (*state.houghDataPerSectorVec)[road.neighbouringSector-1] ); + associatePhiMaxima( road, (*state.houghDataPerSectorVec)[road.neighbouringSector-1].phiMaxVec[region] ); } // finally deal with the case that we have both neighbouring region and sector if( road.neighbouringRegion != MuonStationIndex::DetectorRegionUnknown && road.neighbouringSector != -1) { - associatePhiMaxima( road, state.houghDataPerSectorVec[ road.neighbouringSector-1].phiMaxVec[road.neighbouringRegion] ); + associatePhiMaxima( road, (*state.houghDataPerSectorVec)[ road.neighbouringSector-1].phiMaxVec[road.neighbouringRegion] ); } // merge phi maxima