9 #include "GaudiKernel/ConcurrencyFlags.h" 
   21     using namespace MuonStationIndex;
 
   25         m_ntechnologies = m_idHelperSvc->mdtIdHelper().technologyNameIndexMax() + 1;
 
   31         m_selectors.resize(nSelect);
 
   48         m_selectorsLoose.resize(nSelect);
 
   65         return StatusCode::SUCCESS;
 
   69         const std::vector<const MdtPrepDataCollection*>& mdtCols, 
const std::vector<const CscPrepDataCollection*>& cscCols,
 
   70         const std::vector<const TgcPrepDataCollection*>& tgcCols, 
const std::vector<const RpcPrepDataCollection*>& rpcCols,
 
   73         using namespace MuonStationIndex;
 
   74         initializeSectorMapping(ctx);
 
   83         auto getHashes = [
this](
const Identifier& 
id) {
 
   84             DetRegIdx regionIndex = m_idHelperSvc->regionIndex(
id);
 
   93             int sector = m_idHelperSvc->sector(
id);
 
   94             auto hashes = getHashes(
id);
 
  101             int sector = m_idHelperSvc->sector(
id);
 
  102             auto hashes = getHashes(
id);
 
  109             int sector = m_idHelperSvc->sector(
id);
 
  110             auto hashes = getHashes(
id);
 
  116             const std::vector<IdentifierHash>& 
hashes = m_collectionsPerSector[sector - 1].technologyRegionHashVecs[tgcTech][
sectorLayerHash];
 
  123             int sector = m_idHelperSvc->sector(
id);
 
  124             auto hashes = getHashes(
id);
 
  131             int neighbourSectorDown = sector == 1 ? 16 : sector - 1;
 
  132             if (hashInSector(col->identifyHash(), neighbourSectorDown, 
hashes.second))
 
  137             int neighbourSectorUp = sector == 16 ? 1 : sector + 1;
 
  138             if (hashInSector(col->identifyHash(), neighbourSectorUp, 
hashes.second))
 
  144         return analyse(state);
 
  150         const EventContext& ctx)
 const {
 
  151         initializeSectorMapping(ctx);
 
  159             ATH_MSG_DEBUG(
"analyse: Filling hits sector " << sit.sector);
 
  162             houghData.
sector = sit.sector;
 
  165             fillHitsPerSector(ctx, state, sit.sector, sit, mdtCont, cscCont, tgcCont, rpcCont, stgcCont, mmCont);
 
  167         return analyse(state);
 
  171         State& state)
 const {
 
  172         auto patternCombis = std::make_unique<MuonPatternCombinationCollection>();
 
  176             ATH_MSG_DEBUG(
"analyse: Filling Hough sector " << houghData.sector);
 
  181                 using namespace MuonStationIndex;
 
  184                 if (
hits.empty()) 
continue;
 
  203                 ++houghData.nlayersWithMaxima[
toInt(region)];
 
  204                 houghData.nmaxHitsInRegion[
toInt(region)] += houghData.maxVec[
layerHash].front()->max;
 
  207                               << houghData.sector << 
" " << 
regionName(region) << 
" " 
  214             std::vector<Road> roads;
 
  219             ATH_MSG_DEBUG(
"analyse: Building pattern combinations using roads " << roads.size());
 
  220             for (
auto& road : roads) {
 
  221                 std::map<MuonHough::MuonPhiLayerHough::Maximum*, MuonLayerHoughTool::MaximumVec> phiEtaAssMap;
 
  224                 int sector = road.seed->hough->m_descriptor.sector;
 
  225                 using namespace MuonStationIndex;
 
  230                               << road.maxima.size() << 
" phi " << road.phiMaxima.size() << 
" seed : sector " << sector << 
" " 
  232                               << 
" maximum " << road.seed->max << 
" position " << road.seed->pos << 
" angle " << road.seed->theta);
 
  234                 if (road.phiMaxima.empty())
 
  235                     unassociatedEtaMaxima.push_back(road.maxima);
 
  237                     for (
auto& 
max : road.mergedPhiMaxima) { phiEtaAssMap[&
max] = road.maxima; }
 
  239                 createPatternCombinations(phiEtaAssMap, *patternCombis);
 
  240                 createPatternCombinations(unassociatedEtaMaxima, *patternCombis);
 
  251             for (; spit != spit_end; ++spit) {
 
  254                 using namespace MuonStationIndex;
 
  263                                   << (*spit)->sector << 
" " << 
regionName(region) << 
" nmax " << (*spit)->maxEtaHits()
 
  276                     std::map<MuonHough::MuonPhiLayerHough::Maximum*, MaximumVec> phiEtaAssociations;
 
  277                     associateMaximaToPhiMaxima(region, houghData, phiEtaAssociations, unassociatedEtaMaxima);
 
  280                     createPatternCombinations(phiEtaAssociations, *patternCombis);
 
  283                     createPatternCombinations(unassociatedEtaMaxima, *patternCombis);
 
  288         ATH_MSG_DEBUG(
"Found " << patternCombis->size() << 
" pattern combinations " << std::endl << m_printer->print(*patternCombis));
 
  301                                         std::unique_ptr<HoughDataPerSectorVec>& houghDataPerSectorVec,
 
  302                                         std::vector<MuonLayerHoughTool::Road>& roads)
 const {
 
  304         std::stable_sort(seedMaxima.begin(), seedMaxima.end(),
 
  305                          [](
const std::shared_ptr<MuonHough::MuonLayerHough::Maximum>& 
m1,
 
  306                             const std::shared_ptr<MuonHough::MuonLayerHough::Maximum>& 
m2) { return m1->max > m2->max; });
 
  308         std::set<std::shared_ptr<MuonHough::MuonLayerHough::Maximum>> associatedMaxima;
 
  309         for (
const auto& seed : seedMaxima) {
 
  311             if (associatedMaxima.count(seed)) 
continue;
 
  316             int sector = seed->hough->m_descriptor.sector;
 
  320             DetRegIdx region = seed->hough->m_descriptor.region;
 
  326                                                << 
" position " << seed->pos << 
" angle " << seed->theta << 
" ptr " << seed.get());
 
  331             MuonHough::HitVec::const_iterator ref_itr = std::find_if(
 
  332                 seed->hits.begin(), seed->hits.end(), [](
const std::shared_ptr<MuonHough::Hit>& hit) -> 
bool { return hit->prd; });
 
  334             const bool isNSW = ref_itr != seed->hits.end() &&
 
  335                                (m_idHelperSvc->issTgc((*ref_itr)->prd->identify()) || m_idHelperSvc->isMM((*ref_itr)->prd->identify()));
 
  339             extendSeed(detectorHoughTransforms, road, houghDataPerSectorVec->vec[sector - 1]);
 
  342             int sectorN = sector - 1;
 
  343             if (sectorN < 1) sectorN = 16;
 
  344             int sectorP = sector + 1;
 
  345             if (sectorP > 16) sectorP = 1;
 
  348             associatePhiMaxima(road, houghDataPerSectorVec->vec[sector - 1].phiMaxVec[
toInt(region)]);
 
  350             if (m_addSectors && isNSW) {
 
  351                 extendSeed(detectorHoughTransforms, road, houghDataPerSectorVec->vec[sectorN - 1]);
 
  352                 associatePhiMaxima(road, houghDataPerSectorVec->vec[sectorN - 1].phiMaxVec[
toInt(region)]);
 
  353                 extendSeed(detectorHoughTransforms, road, houghDataPerSectorVec->vec[sectorP - 1]);
 
  354                 associatePhiMaxima(road, houghDataPerSectorVec->vec[sectorP - 1].phiMaxVec[
toInt(region)]);
 
  363                 extendSeed(detectorHoughTransforms, road,
 
  374             mergePhiMaxima(road);
 
  377             associatedMaxima.insert(road.
maxima.begin(), road.
maxima.end());
 
  387                                              << 
max->pos << 
" angle " << 
max->theta << 
" ptr " << 
max);
 
  391             for (
auto& oldRoad : roads) {
 
  392                 std::vector<std::shared_ptr<MuonHough::MuonLayerHough::Maximum>> 
intersection;
 
  396                 unsigned int oldRoadSize = oldRoad.maximumSet.size();
 
  397                 unsigned int roadSize = road.
maximumSet.size();
 
  398                 ATH_MSG_VERBOSE(
" Overlap check " << intersectionSize << 
" old " << oldRoadSize << 
" new " << roadSize << 
" old ptr " 
  400                 if (intersectionSize == 0) 
continue;
 
  401                 if (intersectionSize == roadSize) {
 
  404                 } 
else if (intersectionSize == oldRoadSize) {
 
  412             if (insert) roads.push_back(road);
 
  420         auto maximaSortingLambda = [road](
const std::shared_ptr<MuonHough::MuonPhiLayerHough::Maximum>& 
m1,
 
  421                                           const std::shared_ptr<MuonHough::MuonPhiLayerHough::Maximum>& 
m2) {
 
  422             if (
m1->max != 
m2->max) 
return m1->max > 
m2->max;
 
  424             if (
m1->sector != 
m2->sector) 
return m1->sector == road.
seed->hough->m_descriptor.sector;
 
  426             if (
m1->hits.size() != 
m2->hits.size()) 
return m1->hits.size() < 
m2->hits.size();  
 
  428             if (
m1->pos != 
m2->pos) 
return m1->pos < 
m2->pos;
 
  430             if (std::abs(
m1->binposmax - 
m1->binposmin) == std::abs(
m2->binposmax - 
m2->binposmin)) {
 
  431                 return (
m1->binposmin) < (
m2->binposmin);
 
  433             return std::abs(
m1->binposmax - 
m1->binposmin) < std::abs(
m2->binposmax - 
m2->binposmin);
 
  439         std::set<MuonHough::MuonPhiLayerHough::Maximum*> associatedPhiMaxima;
 
  441             if (associatedPhiMaxima.count((*pit).get())) 
continue;                     
 
  442             associatedPhiMaxima.insert((*pit).get());
 
  446             bool wasExtended = 
false;
 
  447             for (
auto pit1 = pit + 1; pit1 != road.
phiMaxima.end(); ++pit1) {
 
  448                 if ((*pit1)->binposmax >= phiMaximum.
binposmin && (*pit1)->binposmin <= phiMaximum.
binposmax) {
 
  449                     ATH_MSG_VERBOSE(
"    merging maxima " << phiMaximum.
pos << 
" val " << phiMaximum.
max << 
" " << (*pit1)->pos << 
" val " 
  451                     phiMaximum.
hits.insert(phiMaximum.
hits.end(), (*pit1)->hits.begin(), (*pit1)->hits.end());
 
  452                     associatedPhiMaxima.insert((*pit1).get());
 
  460                     60, -
M_PI, 
M_PI, ((*pit)->hough ? (*pit)->hough->m_region : DetRegIdx::DetectorRegionUnknown));
 
  467                 std::stable_sort(
hits.begin(), 
hits.end(),
 
  468                                  [](
const std::shared_ptr<MuonHough::PhiHit>& 
h1, 
const std::shared_ptr<MuonHough::PhiHit>& h2) {
 
  469                                      if (h1->layer != h2->layer) return h1->layer < h2->layer;
 
  470                                      if (h1->w != h2->w) return h1->w > h2->w;
 
  471                                      if (h1->r != h2->r) return h1->r < h2->r;
 
  473                                      const double dPhi1 = std::abs(h1->phimax - h1->phimin);
 
  474                                      const double dPhi2 = std::abs(h2->phimax - h2->phimin);
 
  475                                      if (dPhi1 != dPhi2) return dPhi1 < dPhi2;
 
  476                                      if (h1->phimin == h2->phimin) return h1->phimax < h2->phimax;
 
  477                                      return h1->phimin < h2->phimin;
 
  481                                                           << 
" number of hits " << 
hits.size());
 
  487                                                         << 
" number of hits " << phiMaximum.
hits.size());
 
  488                 phiMaximum.
hough = (*pit)->hough;  
 
  503         if (!road.
seed) 
return;
 
  510         DetRegIdx region = seed.hough->m_descriptor.region;
 
  515             if (
layer == seedLayer && seed.hough->m_descriptor.sector == sectorData.
sector) 
continue;
 
  519             double distanceCut = 
layer == seedLayer ? 500. : (
double)m_extrapolationDistance;
 
  525             if (maxima.empty()) 
continue;
 
  528                                                    << 
" size " << maxima.size());
 
  530             for (
const auto& candMaximum : maxima) {
 
  535                     ATH_MSG_VERBOSE(
" Adding maximum position " << candMaximum->pos << 
" intersect diff" << yloc_diff);
 
  536                     road.
add(candMaximum);
 
  539                                     << candMaximum->pos << 
" x " << candMaximum->hough->m_descriptor.referencePosition << 
" seed y " 
  540                                     << seed.hough->m_descriptor.referencePosition << 
" x " << seed.pos << 
" intersect diff " << yloc_diff);
 
  548         ATH_MSG_DEBUG(
"Checking Barrel/Endcap overlaps: min dist edge " 
  549                       << seed.pos - seed.hough->m_descriptor.yMinRange << 
" max dist edge " << seed.pos - seed.hough->m_descriptor.yMaxRange
 
  550                       << 
" pos " << seed.pos << 
" range " << seed.hough->m_descriptor.yMinRange << 
" " 
  551                       << seed.hough->m_descriptor.yMaxRange);
 
  553         if (std::abs(seed.pos - seed.hough->m_descriptor.yMinRange) < 4000. ||
 
  554             std::abs(seed.pos - seed.hough->m_descriptor.yMaxRange) < 4000.) {
 
  559                     neighbourRegion = DetRegIdx::EndcapC;
 
  561                     neighbourRegion = DetRegIdx::EndcapA;
 
  571                 double distanceCut = 1000.;
 
  576                 if (maxima.empty()) 
continue;
 
  579                                                                            << 
" size " << maxima.size());
 
  582                 for (
const auto& candMaximum : maxima) {
 
  586                                     << candMaximum->pos << 
" x " << candMaximum->hough->m_descriptor.referencePosition << 
" seed y " 
  587                                     << seed.hough->m_descriptor.referencePosition << 
" x " << seed.pos << 
" intersect diff " << yloc_diff);
 
  589                     if (std::abs(yloc_diff) < distanceCut) {
 
  590                         road.
add(candMaximum);
 
  598         std::set<const TgcClusterObj3D*> tgcClusters;
 
  599         std::set<Identifier> triggerLayers;
 
  601         for (
const auto& maximum : maxima) {
 
  602             if (maximum->hough->m_descriptor.sector != sectorData.
sector)
 
  606             for (
auto ehit = maximum->hits.begin(); ehit != maximum->hits.end(); ++ehit) {
 
  610                 } 
else if (etaHit.
prd) {
 
  611                     triggerLayers.insert(m_idHelperSvc->gasGapId(etaHit.
prd->
identify()));
 
  617             detectorHoughTransforms.
phiHough(region);  
 
  622         for (
const auto& phiHit : phiHits) {
 
  624                 if (tgcClusters.find(phiHit->tgc) != tgcClusters.end()) phiHitsInMaximum.push_back(phiHit);
 
  625             } 
else if (phiHit->prd) {
 
  626                 if (triggerLayers.find(m_idHelperSvc->gasGapId(phiHit->prd->identify())) != triggerLayers.end())
 
  627                     phiHitsInMaximum.push_back(phiHit);
 
  633                                               << phiHitsInMaximum.size() << 
" phi hits:  " << phiHits.size());
 
  635         if (!findMaxima(phiHough, phiHitsInMaximum, sectorData.
phiMaxVec[
toInt(region)], sectorData.
sector) ||
 
  653         ATH_MSG_DEBUG(
"associateMaximaToPhiMaxima: phi maxima " << phiMaxima.size());
 
  654         if (!road.
seed) 
return;
 
  657         for (
const auto& pmaximum : phiMaxima) {
 
  660             ATH_MSG_DEBUG(
" new phi maximum " << pmaximum->max << 
" hits " << pmaximum->hits.size());
 
  663             std::map<Identifier, std::pair<float, float>> triggerLayersPhiMinMax;
 
  664             std::map<MuonStationIndex::StIndex, std::set<const TgcClusterObj3D*>> tgcClusters;
 
  667             for (
const auto& phiHit : pmaximum->hits) {
 
  672                     if (phiHit->tgc->phiCluster.empty())
 
  675                         tgcClusters[m_idHelperSvc->stationIndex(phiHit->tgc->phiCluster.front()->identify())].insert(phiHit->tgc);
 
  676                 } 
else if (phiHit->prd) {
 
  677                     Identifier gpId = m_idHelperSvc->gasGapId(phiHit->prd->identify());
 
  678                     auto mit = triggerLayersPhiMinMax.find(gpId);
 
  679                     if (mit == triggerLayersPhiMinMax.end())
 
  680                         triggerLayersPhiMinMax[gpId] = std::make_pair(phiHit->phimin, phiHit->phimax);
 
  682                         mit->second.first = 
std::min(phiHit->phimin, mit->second.first);
 
  683                         mit->second.second = 
std::max(phiHit->phimax, mit->second.second);
 
  689                 ATH_MSG_DEBUG(
"Trigger layers " << triggerLayersPhiMinMax.size() << 
" tgc layers " << tgcClusters.size());
 
  690                 for (
auto tgcit = triggerLayersPhiMinMax.begin(); tgcit != triggerLayersPhiMinMax.end(); ++tgcit) {
 
  695                 std::map<MuonStationIndex::StIndex, std::set<const TgcClusterObj3D*>>::const_iterator stit = tgcClusters.begin();
 
  696                 std::map<MuonStationIndex::StIndex, std::set<const TgcClusterObj3D*>>::const_iterator stit_end = tgcClusters.end();
 
  697                 for (; stit != stit_end; ++stit) {
 
  698                     std::set<const TgcClusterObj3D*>::const_iterator ttit = stit->second.begin();
 
  699                     std::set<const TgcClusterObj3D*>::const_iterator ttit_end = stit->second.end();
 
  700                     for (; ttit != ttit_end; ++ttit) {
 
  701                         ATH_MSG_VERBOSE(
"  " << m_idHelperSvc->toString((*ttit)->phiCluster.front()->identify()) << 
"  nhits " 
  702                                              << (*ttit)->phiCluster.size());
 
  711             float phimin{10}, phimax{-10};
 
  714             for (
const auto& road_max : road.
maxima) {
 
  719                 for (
const auto& etaHit : road_max->hits) {
 
  721                         if (etaHit->tgc->etaCluster.empty())
 
  724                             if (tgcClusters[stIndex].
count(etaHit->tgc)) {
 
  726                                 for (
const auto& phiHit : pmaximum->hits) {
 
  727                                     if (phiHit->tgc == etaHit->tgc) {
 
  728                                         phimin = 
std::min(phiHit->phimin, phimin);
 
  729                                         phimax = 
std::max(phiHit->phimax, phimax);
 
  738                     } 
else if (etaHit->prd) {
 
  739                         if (!m_idHelperSvc->isRpc(etaHit->prd->identify()) && !m_idHelperSvc->issTgc(etaHit->prd->identify())) 
continue;
 
  740                         Identifier gpId = m_idHelperSvc->gasGapId(etaHit->prd->identify());
 
  741                         auto mit = triggerLayersPhiMinMax.find(gpId);
 
  742                         if (mit == triggerLayersPhiMinMax.end())
 
  745                             phimin = 
std::min(mit->second.first, phimin);
 
  746                             phimax = 
std::max(mit->second.second, phimax);
 
  757                 std::vector<int> sectors;
 
  758                 m_sectorMapping.getSectors(phimin, sectors);
 
  759                 if (sectors.size() > 1) {
 
  760                     for (
const int& sec : sectors) {
 
  764                     std::vector<int> sectors;
 
  765                     m_sectorMapping.getSectors(phimax, sectors);
 
  766                     if (sectors.size() > 1) {
 
  767                         for (
const int& sec : sectors) {
 
  773             ATH_MSG_DEBUG(
" Overlap with Phi maximum: overlap " << noverlaps << 
" no overlap " << nNoOverlaps << 
" phimin " << phimin
 
  774                                                                 << 
" phimax " << phimax << 
" neighbouring sector " 
  782         std::vector<MuonLayerHoughTool::HoughDataPerSector>& houghDataPerSectorVec)
 const {
 
  786         for (
unsigned int regLay = 0; regLay < houghData.
maxVec.size(); ++regLay) {
 
  788             int sector = houghData.
sector;
 
  791             for (
int i = 0; 
i < 2; ++
i) {
 
  793                 int sectorN = (
i == 0) ? sector - 1 : sector + 1;
 
  794                 if (
i == 0 && sector == 1) sectorN = 16;
 
  795                 if (
i == 1 && sector == 16) sectorN = 1;
 
  802                 for (
const auto& maximum : maxima) {
 
  805                     if (!maximum->hough) {
 
  811                     for (
const auto& maximumN : maximaN) {
 
  813                         if (!maximumN->hough) {
 
  819                         double rcor = maximumN->hough->m_descriptor.referencePosition *
 
  820                                       m_sectorMapping.transformRToNeighboringSector(maximum->pos, sector, sectorN) /
 
  821                                       maximum->hough->m_descriptor.referencePosition;
 
  822                         double dist = rcor - maximumN->pos;
 
  823                         ATH_MSG_DEBUG(
" maximumN->hough " << maximumN->hough->m_descriptor.referencePosition << 
" maximum->hough " 
  824                                                           << maximum->hough->m_descriptor.referencePosition << 
" maximumN->pos " 
  825                                                           << maximumN->pos << 
" maximum->pos " << maximum->pos << rcor << 
" distance " 
  827                         if (std::abs(dist) > 100) 
continue;
 
  831                         ATH_MSG_DEBUG(
" Found maximum in neighbouring sector: max " << maximum->max << 
" pos " << rcor << 
" maxN " 
  832                                                                                     << maximumN->max << 
" pos " << maximumN->pos
 
  833                                                                                     << 
" distance " << dist);
 
  836                         for (
int nn = 0; nn < 2; ++nn) {
 
  838                             const auto& maxi = nn == 0 ? maximum : maximumN;
 
  839                             const auto& maxi2 = nn == 0 ? maximumN : maximum;
 
  841                             for (
auto& hit : maxi->hits) {
 
  842                                 if (hit->debugInfo()) {
 
  843                                     hit->debugInfo()->phn = maxi2->max;
 
  844                                     Identifier id = hit->tgc ? hit->tgc->etaCluster.front()->identify() : hit->prd->identify();
 
  845                                     ATH_MSG_VERBOSE(
" " << m_idHelperSvc->toString(
id) << 
" setphn " << hit->debugInfo()->phn);
 
  857         std::map<MuonHough::MuonPhiLayerHough::Maximum*, MuonLayerHoughTool::MaximumVec>& phiEtaAssociations,
 
  859         std::set<std::shared_ptr<MuonHough::MuonLayerHough::Maximum>> associatedMaxima;
 
  863         ATH_MSG_DEBUG(
"associateMaximaToPhiMaxima in sector " << houghData.
sector << 
": phi maxima " << phiMaxima.size());  
 
  865         for (
const auto& phiMaximum : phiMaxima) {
 
  868             ATH_MSG_DEBUG(
" Considering phi maximum " << phiMaximum->max << 
" hits " << phiMaximum->hits.size());  
 
  875             std::set<Identifier> triggerLayers;
 
  876             std::map<MuonStationIndex::StIndex, std::set<const TgcClusterObj3D*>> tgcClusters;
 
  879             for (
const auto& phiHit : phiMaximum->hits) {
 
  881                     if (phiHit->tgc->phiCluster.empty())
 
  884                         tgcClusters[m_idHelperSvc->stationIndex(phiHit->tgc->phiCluster.front()->identify())].insert(phiHit->tgc);
 
  885                 } 
else if (phiHit->prd) {
 
  887                     Identifier layId = m_idHelperSvc->gasGapId(colId);
 
  888                     triggerLayers.insert(layId);
 
  892                 ATH_MSG_DEBUG(
"Trigger layers " << triggerLayers.size() << 
" tgc layers " << tgcClusters.size());
 
  895                 std::map<MuonStationIndex::StIndex, std::set<const TgcClusterObj3D*>>::const_iterator stit = tgcClusters.begin();
 
  896                 std::map<MuonStationIndex::StIndex, std::set<const TgcClusterObj3D*>>::const_iterator stit_end = tgcClusters.end();
 
  897                 for (; stit != stit_end; ++stit) {
 
  898                     std::set<const TgcClusterObj3D*>::const_iterator ttit = stit->second.begin();
 
  899                     std::set<const TgcClusterObj3D*>::const_iterator ttit_end = stit->second.end();
 
  900                     for (; ttit != ttit_end; ++ttit) {
 
  901                         ATH_MSG_VERBOSE(
"  " << m_idHelperSvc->toString((*ttit)->phiCluster.front()->identify()) << 
"  nhits " 
  902                                              << (*ttit)->phiCluster.size());
 
  914                 if (maxima.empty()) 
continue;
 
  918                 for (
const auto& maximum : maxima) {
 
  924                     int ntrigconfirm = 0;
 
  927                         for (
const auto& max_itr : 
pos->second) {
 
  928                             totmax = 
std::max(max_itr->max, totmax);
 
  929                             ntrigconfirm += max_itr->triggerConfirmed;
 
  932                     totmax += maximum->max;
 
  933                     ntrigconfirm += maximum->triggerConfirmed;
 
  936                                                         << 
" neightbour confirmed value " << totmax << 
" trigger confirmations " 
  940                     int nmmHits{0}, ntgcOverlaps{0}, nrpcOverlaps{0}, nstgcOverlaps{0}, nstgcNoOverlaps{0};
 
  943                     for (
const auto& etaHit : maximum->hits) {
 
  945                             if (tgcClusters[stIndex].
count(etaHit->tgc))
 
  948                         } 
else if (etaHit->prd) {
 
  949                             Identifier layId = m_idHelperSvc->gasGapId(etaHit->prd->identify());
 
  951                             if (m_idHelperSvc->isMM(layId)) ++nmmHits;
 
  952                             if (triggerLayers.count(layId)) {
 
  953                                 if (m_idHelperSvc->isRpc(layId))
 
  955                                 else if (m_idHelperSvc->issTgc(layId))
 
  958                                 if (m_idHelperSvc->issTgc(layId))
 
  965                     if (nmmHits + nstgcNoOverlaps + nstgcOverlaps > 0) {
 
  967                         if (maximum->pos < 1200.) {
 
  969                                 ATH_MSG_DEBUG(
"  maximum failed cut " << totmax << 
" cut 8, position " << maximum->pos);
 
  972                         } 
else if (maximum->pos > 4300.) {
 
  974                                 ATH_MSG_DEBUG(
"  maximum failed cut " << totmax << 
" cut 8, position " << maximum->pos);
 
  979                                 ATH_MSG_DEBUG(
"  maximum failed cut " << totmax << 
" cut 12, position " << maximum->pos);
 
  985                     ATH_MSG_DEBUG(
" Overlap with Phi maximum: tgc " << ntgcOverlaps << 
" stgc " << nstgcOverlaps << 
" rpc " << nrpcOverlaps
 
  986                                                                     << 
" nphiTgc " << tgcClusters[stIndex].
size() << 
" trigLay " 
  987                                                                     << triggerLayers.size());
 
  988                     if (stIndex == 
StIndex::EM && !tgcClusters[stIndex].empty() && ntgcOverlaps == 0) {
 
  990                                                                            << ntgcOverlaps << 
" on phi maximum " 
  991                                                                            << tgcClusters[stIndex].
size());
 
  994                     if (stIndex == 
StIndex::EI && !tgcClusters[stIndex].empty() && ntgcOverlaps == 0) {
 
  996                                                                            << ntgcOverlaps << 
" on phi maximum " 
  997                                                                            << tgcClusters[stIndex].
size());
 
 1000                     if (stIndex ==  
StIndex::EI && nstgcOverlaps == 0 && nstgcNoOverlaps != 0) {
 
 1002                                                                            << 
" stgcs without overlaps " << nstgcNoOverlaps);
 
 1006                     if (m_requireTriggerConfirmationNSW && nmmHits > 0 && ntrigconfirm == 0) 
continue;
 
 1008                     associatedMaxima.insert(maximum);
 
 1009                     associatedMaximaVec.push_back(maximum);
 
 1013                         associatedMaxima.insert(
pos->second.begin(), 
pos->second.end());
 
 1014                         associatedMaximaVec.insert(associatedMaximaVec.end(), 
pos->second.begin(), 
pos->second.end());
 
 1019             if (associatedMaximaVec.empty()) 
continue;
 
 1020             ATH_MSG_DEBUG(
" processed phi maximum, associated eta maxima " << associatedMaximaVec.size());
 
 1021             phiEtaAssociations[phiMaximum.get()] = std::move(associatedMaximaVec);
 
 1030             if (lay >= unassEtaMaxima.size()) {
 
 1031                 ATH_MSG_WARNING(
" size of unassEtaMaxima too small for region " << unassEtaMaxima.size() << 
" region " 
 1038             for (
const auto& mit : maxima) {
 
 1039                 if (associatedMaxima.count(mit)) 
continue;
 
 1040                 unassEtaMaxima[lay].push_back(mit);
 
 1048         ATH_MSG_DEBUG(
"Creating pattern combinations for eta patterns ");
 
 1050         std::vector<MuonPatternChamberIntersect> chamberData;
 
 1055         for (
const auto& max_sec : maxima) {
 
 1057             std::map<Identifier, std::set<const Trk::PrepRawData*>> prdsPerChamber;
 
 1060             for (
const auto& 
max : max_sec) {
 
 1064                 if (
max->hits.empty()) {
 
 1071                 for (
const auto& hit : 
max->hits) {
 
 1073                         const Identifier chId = m_idHelperSvc->chamberId(hit->tgc->etaCluster.front()->identify());
 
 1074                         prdsPerChamber[chId].insert(hit->tgc->etaCluster.begin(), hit->tgc->etaCluster.end());
 
 1075                     } 
else if (hit->prd) {
 
 1076                         const Identifier chId = m_idHelperSvc->chamberId(hit->prd->identify());
 
 1077                         prdsPerChamber[chId].insert(hit->prd);
 
 1083                 return prd1->
identify() < prd2->identify();
 
 1085             std::map<Identifier, std::set<const Trk::PrepRawData*>>
::iterator chit = prdsPerChamber.begin();
 
 1086             std::map<Identifier, std::set<const Trk::PrepRawData*>>
::iterator chit_end = prdsPerChamber.end();
 
 1087             for (; chit != chit_end; ++chit) {
 
 1088                 ATH_MSG_DEBUG(
"Adding chamber " << m_idHelperSvc->toStringChamber(chit->first) << 
" hits " << chit->second.size());
 
 1089                 std::vector<const Trk::PrepRawData*> prds;
 
 1090                 prds.insert(prds.end(), chit->second.begin(), chit->second.end());
 
 1095                 ATH_MSG_DEBUG(
"Adding chamber with intersect phi direction " << gpos.phi() << 
" theta " << gpos.theta());
 
 1096                 MuonPatternChamberIntersect 
intersect(gpos, gpos.unit(), prds);
 
 1100         if (chamberData.empty()) 
return;
 
 1102         MuonPatternCombination* combi = 
new MuonPatternCombination(
nullptr, chamberData);
 
 1104         ATH_MSG_DEBUG(
" creating new unassociated " << m_printer->print(*combi));
 
 1109         std::map<MuonHough::MuonPhiLayerHough::Maximum*, MuonLayerHoughTool::MaximumVec>& phiEtaAssociations,
 
 1111         ATH_MSG_DEBUG(
"Creating pattern combinations from eta/phi combinations " << phiEtaAssociations.size());
 
 1114         std::map<MuonHough::MuonPhiLayerHough::Maximum*, MaximumVec>::const_iterator pit = phiEtaAssociations.begin();
 
 1115         std::map<MuonHough::MuonPhiLayerHough::Maximum*, MaximumVec>::const_iterator pit_end = phiEtaAssociations.end();
 
 1116         for (; pit != pit_end; ++pit) {
 
 1117             if (pit->second.empty()) 
continue;
 
 1120             std::map<Identifier, std::set<const Trk::PrepRawData*>> phiHitsPerChamber;
 
 1123             for (
const auto& hit : pit->first->hits) {
 
 1125                     const Identifier chId = m_idHelperSvc->chamberId(hit->tgc->phiCluster.front()->identify());
 
 1126                     phiHitsPerChamber[chId].insert(hit->tgc->phiCluster.begin(), hit->tgc->phiCluster.end());
 
 1127                 } 
else if (hit->prd) {
 
 1128                     const Identifier chId = m_idHelperSvc->chamberId(hit->prd->identify());
 
 1129                     phiHitsPerChamber[chId].insert(hit->prd);
 
 1134             std::vector<MuonPatternChamberIntersect> chamberData;
 
 1135             std::set<Identifier> addedPhiHits;
 
 1138             std::map<Identifier, std::set<const Trk::PrepRawData*>> prdsPerChamber;
 
 1141             std::map<MuonStationIndex::ChIndex, std::pair<Amg::Vector3D, Amg::Vector3D>> directionsPerChamberLayer;
 
 1144             for (
const auto& 
max : pit->second) {
 
 1150                 if (
max->hits.empty()) {
 
 1157                 for (
const auto& hit : 
max->hits) {
 
 1160                         chId = m_idHelperSvc->chamberId(hit->tgc->etaCluster.front()->identify());
 
 1161                         prdsPerChamber[chId].insert(hit->tgc->etaCluster.begin(), hit->tgc->etaCluster.end());
 
 1162                     } 
else if (hit->prd) {
 
 1163                         chId = m_idHelperSvc->chamberId(hit->prd->identify());
 
 1164                         prdsPerChamber[chId].insert(hit->prd);
 
 1171                     if (!directionsPerChamberLayer.count(
chIndex)) {
 
 1173                         double maxpos = 
max->pos;
 
 1174                         double refPlane = 0.;
 
 1177                             refPlane = 
max->hough->m_descriptor.referencePosition;
 
 1179                             refPlane = hit->tgc->getEdge(TgcEdge::LowEtaLowPhi).z();
 
 1181                             refPlane = hit->prd->detectorElement()->surface(hit->prd->identify()).center().perp();
 
 1183                             refPlane = hit->prd->detectorElement()->surface(hit->prd->identify()).center().z();
 
 1185                         double r = 
isBarrel ? refPlane : maxpos;
 
 1186                         double z = 
isBarrel ? maxpos : refPlane;
 
 1197                         double phi = pit->first->pos;  
 
 1200                         double sinphi = scphi.
sn;
 
 1201                         double cosphi = scphi.
cs;
 
 1204                         double sintheta = sctheta.
sn;
 
 1205                         double costheta = sctheta.
cs;
 
 1207                         std::pair<Amg::Vector3D, Amg::Vector3D>& posDir = directionsPerChamberLayer[
chIndex];
 
 1211                                       << 
" setting position: perp " << posDir.first.perp() << 
" z " << posDir.first.z() << 
" phi pos " 
 1212                                       << posDir.first.phi() << 
" direction phi  " << posDir.second.phi() << 
" theta pos " 
 1213                                       << posDir.first.theta() << 
" direction theta " << posDir.second.theta() << 
" ref perp " << 
r << 
" z " 
 1214                                       << 
z << 
" phi " << 
phi << 
" theta " << 
theta);
 
 1215                         if (posDir.first.dot(posDir.second) < 0.) {
 
 1216                             ATH_MSG_WARNING(
" direction not pointing to IP " << posDir.first.unit().dot(posDir.second));
 
 1220                     std::map<Identifier, std::set<const Trk::PrepRawData*>>
::iterator pos = phiHitsPerChamber.find(chId);
 
 1221                     if (
pos != phiHitsPerChamber.end()) {
 
 1223                         if (ipos.second) { prdsPerChamber[chId].insert(
pos->second.begin(), 
pos->second.end()); }
 
 1229                 return prd1->
identify() < prd2->identify();
 
 1231             std::map<Identifier, std::set<const Trk::PrepRawData*>>
::iterator chit = prdsPerChamber.begin();
 
 1232             std::map<Identifier, std::set<const Trk::PrepRawData*>>
::iterator chit_end = prdsPerChamber.end();
 
 1233             for (; chit != chit_end; ++chit) {
 
 1234                 ATH_MSG_DEBUG(
"Adding chamber " << m_idHelperSvc->toStringChamber(chit->first) << 
" hits " << chit->second.size());
 
 1235                 std::vector<const Trk::PrepRawData*> prds;
 
 1236                 prds.insert(prds.end(), chit->second.begin(), chit->second.end());
 
 1237                 std::stable_sort(prds.begin(), prds.end(), sortPrdIds);
 
 1241                 std::map<MuonStationIndex::ChIndex, std::pair<Amg::Vector3D, Amg::Vector3D>>::const_iterator 
pos =
 
 1242                     directionsPerChamberLayer.find(
chIndex);
 
 1245                 if (
pos != directionsPerChamberLayer.end()) {
 
 1246                     gpos = 
pos->second.first;
 
 1247                     gdir = 
pos->second.second;
 
 1249                     ATH_MSG_WARNING(
"No global position and direction found, calculating from surface");
 
 1251                     gdir = -1 * gpos.unit();
 
 1255                                                        << 
" z " << gpos.z() << 
" phi pos " << gpos.phi() << 
" direction phi " << gdir.phi()
 
 1256                                                        << 
" theta pos " << gpos.theta() << 
" theta " << gdir.theta() << 
" hits " 
 1264             if (chamberData.empty()) 
continue;
 
 1265             if (addedPhiHits.empty()) {
 
 1270             ATH_MSG_DEBUG(
"adding pattern combination with chambers " << chamberData.size() << 
" phi layers " << addedPhiHits.size()
 
 1272                                                                       << m_printer->print(*combi));
 
 1280         if (
hits.empty()) 
return false;
 
 1282         using namespace MuonStationIndex;
 
 1284             Identifier id = 
hits.front()->tgc ? 
hits.front()->tgc->etaCluster.front()->identify() : 
hits.front()->prd->identify();
 
 1291         if (m_debugHough) 
hough.setDebug(
true);
 
 1294         Identifier id_hit = 
hits.front()->tgc ? 
hits.front()->tgc->etaCluster.front()->identify() : 
hits.front()->prd->identify();
 
 1298         if (m_idHelperSvc->issTgc(id_hit) || m_idHelperSvc->isMM(id_hit)) {
 
 1302             selectorLoose = m_selectorsLoose[
toInt(
hough.m_descriptor.chIndex)];
 
 1307         unsigned int nmaxima = 0;
 
 1308         while (nmaxima < 5) {
 
 1310             if (
hough.findMaximum(maximum, selectorLoose)) {
 
 1311                 hough.associateHitsToMaximum(maximum, 
hits);
 
 1313                               << nmaxima << 
"  " << maximum.
max << 
" trigConfirmed " << maximum.
triggerConfirmed << 
" pos " << maximum.
pos 
 1314                               << 
" theta " << maximum.
theta << 
" binPos " << maximum.
binpos << 
" binRange " << maximum.
binposmin << 
" -- " 
 1321                 const unsigned int nHitsInMaximum = maximum.
hits.size();
 
 1322                 for (
unsigned int i = 0; 
i < nHitsInMaximum; ++
i) {
 
 1327                     nmdt += m_idHelperSvc->isMdt(
id);
 
 1328                     nstgc  += m_idHelperSvc->issTgc(
id);
 
 1329                     nmm += m_idHelperSvc->isMM(
id);
 
 1331                     ATH_MSG_VERBOSE(
"findMaxima: hit " << hit.
layer << 
"  " << m_idHelperSvc->toString(
id) << 
" hits " << nhits);
 
 1335                 if (nmdt > 0 || (nmm + nstgc) > 0) {
 
 1336                     maxima.emplace_back(std::make_unique<MuonHough::MuonLayerHough::Maximum>(maximum));
 
 1338                     if (maximum.
max > 
selector.getCutValue(maximum.
pos)) seedMaxima.push_back(maxima.back());
 
 1343                 if (nmaxima > 0) { 
ATH_MSG_VERBOSE(
"findMaxima: No more maxima found " << nmaxima); }
 
 1353         if (
hits.empty()) 
return false;
 
 1356         if (m_debugHough) 
hough.setDebug(
true);
 
 1359         unsigned int nmaxima = 0;
 
 1360         while (nmaxima < 5) {
 
 1362             if (
hough.findMaximum(maximum, 1.9)) {
 
 1363                 hough.associateHitsToMaximum(maximum, 
hits);
 
 1365                 ATH_MSG_DEBUG(
"findMaxima(Phi): Found Phi maximum " << nmaxima << 
" height " << maximum.
max << 
" pos " << maximum.
pos 
 1367                                                                     << 
" -- " << maximum.
binposmax << 
" nHits " << maximum.
hits.size());
 
 1369                 const unsigned int nHitsInMaximum = maximum.
hits.size();
 
 1370                 for (
unsigned int i = 0; 
i < nHitsInMaximum; ++
i) {
 
 1375                     ATH_MSG_VERBOSE(
"findMaxima(Phi) phiHit " << m_idHelperSvc->toString(
id) << 
" hits " << nhits);
 
 1381                 bool maximum_matched = 
false;
 
 1382                 for (
auto pit = maxima.begin(); pit != maxima.end(); ++pit) {
 
 1388                         ATH_MSG_DEBUG(
"extendSeed: sector has already been added! Skip. ");
 
 1389                         bool maximum_hitmatched = 
true;  
 
 1390                         for (
unsigned int k = 0; 
k < maximum.
hits.size(); ++
k) {
 
 1392                                 maximum_hitmatched = 
false;
 
 1396                         if (maximum_hitmatched) {
 
 1397                             maximum_matched = 
true;
 
 1404                 if (maximum_matched) {
 
 1408                     maxima.push_back(std::make_shared<MuonHough::MuonPhiLayerHough::Maximum>(maximum));
 
 1412                 if (nmaxima > 0) { 
ATH_MSG_VERBOSE(
"findMaxima(Phi): No more maxima found " << nmaxima); }
 
 1427         houghData.
sector = sector;
 
 1429         for (
unsigned int tech = 0; tech < m_ntechnologies; ++tech) {
 
 1432                 if (
hashes.empty()) 
continue;
 
 1452                                  collectionsPerSector.
sector);
 
 1464         typedef PRD_MultiTruthCollection::const_iterator iprdt;
 
 1465         std::pair<iprdt, iprdt> 
range = truthCol.equal_range(
id);
 
 1468             if (!
i->second.isValid()) {
 
 1469                 ATH_MSG_WARNING(
"Unexpected invalid HepMcParticleLink in PRD_MultiTruthCollection");
 
 1472                 if (link.
cptr() && abs(link.
cptr()->pdg_id()) == 13) {
 
 1475                   truthHits.insert(
id);
 
 1483         if (mdts.
empty()) 
return;
 
 1484         auto truthCollections = m_truthNames.makeHandles(ctx);
 
 1486         DetRegIdx region = m_idHelperSvc->regionIndex(chid);
 
 1488         int sector = m_idHelperSvc->sector(chid);
 
 1489         unsigned int technology = 
toInt(m_idHelperSvc->technologyIndex(chid));
 
 1491         unsigned int nmdts(mdts.
size()), nmdtsBad{0};
 
 1498             float r = rCor(*prd);
 
 1499             float x = barrelLike ? 
r : prd->globalPosition().z();
 
 1500             float y = barrelLike ? prd->globalPosition().z() : 
r;
 
 1501             int sublayer = sublay(
id);
 
 1506             debug->time = prd->tdc();
 
 1509             std::map<unsigned int, unsigned int>::const_iterator 
pos = m_techToTruthNameIdx.find(technology);
 
 1510             if (
pos != m_techToTruthNameIdx.end()) { matchTruth(truthHits, *truthCollections[
pos->second], 
id, *
debug); }
 
 1512             hits.emplace_back(hit);
 
 1515         ATH_MSG_DEBUG(
"fillMDT: Filling " << m_idHelperSvc->toStringChamber(chid) << 
": loc s" << sector << 
" " 
 1517                                           << 
" -> hits: " << nmdts << 
" bad " << nmdtsBad << 
" isSmallChamber " 
 1518                                           << m_idHelperSvc->isSmallChamber(chid));
 
 1525         auto truthCollections = m_truthNames.makeHandles(ctx);
 
 1527         unsigned int technology = 
toInt(m_idHelperSvc->technologyIndex(chid));
 
 1529         DetRegIdx region = m_idHelperSvc->regionIndex(chid);
 
 1530         int sector = m_idHelperSvc->sector(chid);
 
 1531         unsigned int neta{0}, nphi{0};
 
 1533             const bool meas_phi = m_idHelperSvc->rpcIdHelper().measuresPhi(prd->
identify());
 
 1537         ATH_MSG_DEBUG(
"fillCscs: Filling " << m_idHelperSvc->toStringChamber(chid) << 
": loc s" << sector << 
" " 
 1539                                            << 
" -> eta hits " << neta << 
" phi hits " << nphi);
 
 1542             int sublayer = sublay(
id);
 
 1544             debug->isEtaPhi = (neta && nphi);
 
 1545             debug->trigConfirm = 1;
 
 1546             debug->time = prd->time();
 
 1547             std::map<unsigned int, unsigned int>::const_iterator 
pos = m_techToTruthNameIdx.find(technology);
 
 1548             if (
pos != m_techToTruthNameIdx.end()) { matchTruth(truthHits, *truthCollections[
pos->second], 
id, *
debug); }
 
 1549             float weight = (neta && nphi) ? 2 : 1;
 
 1550             if (m_idHelperSvc->rpcIdHelper().measuresPhi(
id)) {
 
 1551                 const float r = rCor(*prd);
 
 1552                 const float phi = prd->globalPosition().phi();
 
 1553                 const double phi1 = 
phi;  
 
 1556                 phiHits.emplace_back(hit);
 
 1558                 const float x = rCor(*prd);
 
 1559                 const float y = prd->globalPosition().z();
 
 1560                 const float stripCor = 0.5 * prd->
detectorElement()->StripWidth(
false);
 
 1561                 const float ymin = 
y - stripCor;
 
 1562                 const float ymax = 
y + stripCor;
 
 1563                 debug->r = stripCor;
 
 1565                 hits.emplace_back(hit);
 
 1571         if (rpcs.
empty()) 
return;
 
 1572         auto truthCollections = m_truthNames.makeHandles(ctx);
 
 1574         unsigned int technology = 
toInt(m_idHelperSvc->technologyIndex(chid));
 
 1576         DetRegIdx region = m_idHelperSvc->regionIndex(chid);
 
 1577         int sector = m_idHelperSvc->sector(chid);
 
 1579         unsigned int neta{0}, nphi{0};
 
 1581             const bool meas_phi = m_idHelperSvc->rpcIdHelper().measuresPhi(prd->
identify());
 
 1585         ATH_MSG_DEBUG(
"fillRPC: Filling " << m_idHelperSvc->toStringChamber(chid) << 
": loc s" << sector << 
" " 
 1587                                           << 
" -> eta hits " << neta << 
" phi hits " << nphi);
 
 1591             int sublayer = sublay(
id);
 
 1593             debug->isEtaPhi = (neta && nphi);
 
 1594             debug->trigConfirm = 1;
 
 1595             debug->time = prd->time();
 
 1596             std::map<unsigned int, unsigned int>::const_iterator 
pos = m_techToTruthNameIdx.find(technology);
 
 1597             if (
pos != m_techToTruthNameIdx.end()) { matchTruth(truthHits, *truthCollections[
pos->second], 
id, *
debug); }
 
 1598             float weight = (neta && nphi) ? 2 : 1;
 
 1599             if (m_idHelperSvc->rpcIdHelper().measuresPhi(
id)) {
 
 1600                 const float r = rCor(*prd);
 
 1601                 const float phi = prd->globalPosition().phi();
 
 1602                 const double phi1 = 
phi;  
 
 1605                 phiHits.emplace_back(hit);
 
 1607                 const float x = rCor(*prd);
 
 1608                 const float y = prd->globalPosition().z();
 
 1609                 const float stripCor = 0.5 * prd->
detectorElement()->StripWidth(
false);
 
 1610                 const float ymin = 
y - stripCor;
 
 1611                 const float ymax = 
y + stripCor;
 
 1612                 debug->r = stripCor;
 
 1614                 hits.emplace_back(hit);
 
 1621         if (mms.
empty()) 
return;
 
 1622         auto truthCollections = m_truthNames.makeHandles(ctx);
 
 1624         DetRegIdx region = m_idHelperSvc->regionIndex(chid);
 
 1626         int sector = m_idHelperSvc->sector(chid);
 
 1627         unsigned int technology = 
toInt(m_idHelperSvc->technologyIndex(chid));
 
 1628         ATH_MSG_DEBUG(
"fillMM: Filling " << m_idHelperSvc->toStringChamber(chid) << 
": loc s" << sector << 
" " 
 1632         std::array<double,8> multiplicity{};
 
 1635             int sublayer = sublay(
id) % 10;
 
 1636             multiplicity[sublayer]++;
 
 1640             for (
int i = 0; 
i<8 ; 
i++) 
if(multiplicity[
i]>0) 
ATH_MSG_DEBUG(
" sublayer " << 
i << 
" hits " <<  multiplicity[
i]);
 
 1645             float x = prd->globalPosition().z();
 
 1646             float y = rCor(*prd);
 
 1647             int sublayer = sublay(
id) % 10;
 
 1649             float ymin = 
y - stripCor;
 
 1650             float ymax = 
y + stripCor;
 
 1656             debug->r = stripCor;
 
 1657             std::map<unsigned int, unsigned int>::const_iterator 
pos = m_techToTruthNameIdx.find(technology);
 
 1658             if (
pos != m_techToTruthNameIdx.end()) { matchTruth(truthHits, *truthCollections[
pos->second], 
id, *
debug); }
 
 1659             std::unique_ptr<MuonHough::Hit> hit = std::make_unique<MuonHough::Hit>(sublayer, 
x, 
ymin, 
ymax, 
weight, 
debug, prd);
 
 1660             hits.emplace_back(std::move(hit));
 
 1666         if (stgcs.
empty()) 
return;
 
 1667         auto truthCollections = m_truthNames.makeHandles(ctx);
 
 1669         DetRegIdx region = m_idHelperSvc->regionIndex(chid);
 
 1671         int sector = m_idHelperSvc->sector(chid);
 
 1672         bool isNeighbouringSector = sector != selectedSector;
 
 1673         unsigned int technology = 
toInt(m_idHelperSvc->technologyIndex(chid));
 
 1674         ATH_MSG_DEBUG(
"fillsTGC: Filling " << m_idHelperSvc->toStringChamber(chid) << 
": loc s" << sector << 
" " 
 1676                                            << 
" -> hits: " << stgcs.
size());
 
 1680             int channelType = m_idHelperSvc->stgcIdHelper().channelType(
id);
 
 1683             if (isNeighbouringSector && channelType == 1) 
continue;
 
 1684             int sublayer = sublay(
id);
 
 1686             std::unique_ptr<MuonHough::HitDebugInfo> 
debug =
 
 1687                 std::make_unique<MuonHough::HitDebugInfo>(technology, sector, region, 
layer, sublayer);
 
 1688             debug->isEtaPhi = 1;
 
 1689             debug->trigConfirm = 
true;
 
 1691             std::map<unsigned int, unsigned int>::const_iterator 
pos = m_techToTruthNameIdx.find(technology);
 
 1692             if (
pos != m_techToTruthNameIdx.end()) { matchTruth(truthHits, *truthCollections[
pos->second], 
id, *
debug); }
 
 1693             if (m_idHelperSvc->stgcIdHelper().channelType(
id) == 1) {
 
 1695                 float x = prd->globalPosition().z();
 
 1696                 float y = rCor(*prd);
 
 1697                 float stripCor = 1.5;  
 
 1701                     double stripLength = design->
channelLength(m_idHelperSvc->stgcIdHelper().channel(
id));
 
 1702                     if (m_debugHough) 
ATH_MSG_DEBUG(
" eta strip width " << stripWidth << 
" stripLength " << stripLength);
 
 1703                     stripCor = 0.5 * stripWidth;
 
 1705                 debug->r = stripCor;
 
 1706                 float ymin = 
y - stripCor;
 
 1707                 float ymax = 
y + stripCor;
 
 1709                 hits.emplace_back(hit);
 
 1713                 if (m_idHelperSvc->stgcIdHelper().channelType(
id) == 0) {
 
 1716                         ATH_MSG_WARNING(
"No design found for " << m_idHelperSvc->toString(
id));
 
 1721                     ATH_MSG_DEBUG(
" Pad chWidth " << chWidth << 
" phi global " << prd->globalPosition().phi());
 
 1722                 } 
else if (m_idHelperSvc->stgcIdHelper().channelType(
id) == 2) {
 
 1725                         ATH_MSG_WARNING(
"No design found for " << m_idHelperSvc->toString(
id));
 
 1729                     ATH_MSG_DEBUG(
" Wire Gang chWidth " << chWidth << 
" phi global " << prd->globalPosition().phi());
 
 1740                 double phi1 = gp1.phi();
 
 1741                 double phi2 = gp2.phi();
 
 1742                 double phi1c = phi1;  
 
 1743                 double phi2c = phi2;  
 
 1745                 if (phi_check > 0.3) {
 
 1746                     ATH_MSG_WARNING(
"bad local phi: in " << phi1 << 
", " << phi2 << 
" sector phi " 
 1747                                                          << m_sectorMapping.sectorPhi(selectedSector) << 
" phicor " << phi1c << 
", " 
 1750                 if (isNeighbouringSector &&
 
 1751                     !(m_sectorMapping.insideSector(selectedSector, phi1) || m_sectorMapping.insideSector(selectedSector, phi2))) {
 
 1752                     ATH_MSG_DEBUG(
"Dropping phi hit in neighbouring sector " << m_idHelperSvc->toString(
id) << 
" phi min " 
 1754                                                                              << 
" global phi: in " << phi1 << 
", " << phi2 << 
" sector phi " 
 1755                                                                              << m_sectorMapping.sectorPhi(selectedSector));
 
 1758                 float r = rCor(*prd);
 
 1759                 float phiMin = 
std::min(phi1c, phi2c);
 
 1760                 float phiMax = 
std::max(phi1c, phi2c);
 
 1761                 ATH_MSG_VERBOSE(
"Phi hit " << m_idHelperSvc->toString(
id) << 
" r " << 
r << 
" phi min " << phiMin << 
" phi max " 
 1762                                            << phiMax << 
" bc " << 
debug->uniqueID << 
" chw " << chWidth << 
" trigC " 
 1763                                            << 
debug->trigConfirm << 
" g phi " << phi1 << 
" " << phi2);
 
 1766                 phiHits.emplace_back(phiHit);
 
 1772                                   std::vector<std::unique_ptr<TgcHitClusteringObj>>& tgcClusteringObjs, 
const TgcPrepDataCollection& tgcs,
 
 1774         if (tgcs.
empty()) 
return;
 
 1775         tgcClusteringObjs.push_back(std::make_unique<TgcHitClusteringObj>(&m_idHelperSvc->tgcIdHelper()));
 
 1777         std::vector<const TgcPrepData*> prds;
 
 1778         prds.insert(prds.begin(), tgcs.
begin(), tgcs.
end());
 
 1783         DetRegIdx region = m_idHelperSvc->regionIndex(chid);
 
 1794             ATH_MSG_DEBUG(
"TgcHitClusteringObj, no eta cluster selected! ");
 
 1800         auto truthCollections = m_truthNames.makeHandles(ctx);
 
 1801         std::vector<int> sectors;
 
 1802         getSectors(clustering.
clusters3D.front(), sectors);
 
 1803         unsigned int technology = 
toInt(m_idHelperSvc->technologyIndex(chid));
 
 1804         for (
unsigned int si = 0; si < sectors.size(); ++si) {
 
 1805             if (sectors[si] != sector) 
continue;
 
 1808                 const Identifier id = 
cl.etaCluster.front()->identify();
 
 1810                 double x = 
cl.getEdge(TgcEdge::LowEtaLowPhi).z();
 
 1811                 double y11 = rCor(
cl, TgcEdge::LowEtaLowPhi, sector);
 
 1812                 double y12 = rCor(
cl, TgcEdge::LowEtaHighPhi, sector);
 
 1813                 double y21 = rCor(
cl, TgcEdge::LowEtaLowPhi, sector);
 
 1814                 double y22 = rCor(
cl, TgcEdge::HighEtaHighPhi, sector);
 
 1815                 double phi11 = 
cl.getEdge(TgcEdge::LowEtaLowPhi).phi();
 
 1816                 double phi12 = 
cl.getEdge(TgcEdge::LowEtaHighPhi).phi();
 
 1817                 double phi21 = 
cl.getEdge(TgcEdge::LowEtaLowPhi).phi();
 
 1818                 double phi22 = 
cl.getEdge(TgcEdge::HighEtaHighPhi).phi();
 
 1823                 double phi1 = phimin;  
 
 1824                 double phi2 = phimax;  
 
 1825                 int sublayer = sublay(
id, 
x);
 
 1826                 ATH_MSG_VERBOSE(
"Cluster "<<m_idHelperSvc->toString(
id)<<
" x: "<<
x<<
", y11: "<<y11
 
 1827                              <<
", y12: "<<y12<<
", y21: "<<y21<<
", y22: "<<y22<<
", phi11: "<<phi11<<
", " 
 1828                              <<
"phi12: "<<phi12<<
", phi21: "<<phi21<<
", phi22: "<<phi22<<
" ymin: "<<
ymin<<
", ymax: "<<
ymax 
 1829                              <<
", phimin: "<<phimin<<
", phimax: "<<phimax);
 
 1832                 debug->clusterSize = 
cl.etaCluster.size();
 
 1833                 debug->clusterLayers = 2;
 
 1834                 debug->isEtaPhi = 
true;
 
 1835                 debug->time = 
cl.etaCluster.front()->getBcBitMap();
 
 1836                 std::map<unsigned int, unsigned int>::const_iterator 
pos = m_techToTruthNameIdx.find(technology);
 
 1837                 if (
pos != m_techToTruthNameIdx.end()) { matchTruth(truthHits, *truthCollections[
pos->second], 
id, *
debug); }
 
 1844                 std::unique_ptr<MuonHough::Hit> hit = std::make_unique<MuonHough::Hit>(sublayer, 
x, 
ymin, 
ymax, 2, 
debug, 
nullptr, &
cl);
 
 1845                 std::unique_ptr<MuonHough::PhiHit> phiHit =
 
 1846                     std::make_unique<MuonHough::PhiHit>(sublayer, y11, phi1, phi2, 2, phiDebug, 
nullptr, &
cl);
 
 1847                 hits.emplace_back(std::move(hit));
 
 1848                 phiHits.emplace_back(std::move(phiHit));
 
 1851         ATH_MSG_DEBUG(
"fillTGC: Filling " << m_idHelperSvc->toStringChamber(chid) << 
": loc s" << sector << 
" " 
 1853                                           << 
" -> etaHits: " << 
hits.size() << 
" phiHits: " << phiHits.size()
 
 1854                                           << 
" sectors: " << sectors.size());
 
 1858         insertHash(m_idHelperSvc->sector(
id), 
hash, 
id);
 
 1869         if (m_sectorSetup) 
return;
 
 1870         std::lock_guard kuchen(m_mutex);
 
 1872         if (m_sectorSetup) 
return;
 
 1877         for (
unsigned int i = 0; 
i < m_collectionsPerSector.size(); ++
i) {
 
 1878             m_collectionsPerSector[
i].sector = 
i + 1;
 
 1879             m_collectionsPerSector[
i].technologyRegionHashVecs.resize(m_ntechnologies);
 
 1880             for (
auto it = m_collectionsPerSector[
i].technologyRegionHashVecs.begin();
 
 1881                  it != m_collectionsPerSector[
i].technologyRegionHashVecs.end(); ++
it) {
 
 1882                 it->resize(nsectorHashMax);
 
 1886                                                                 << m_ntechnologies << 
" sectorLayers " 
 1890         auto loadHashes = [
this] (
const MuonIdHelper& idHelper){
 
 1891             auto it = idHelper.module_begin();
 
 1892             const auto it_end = idHelper.module_end();
 
 1893             for (; 
it != it_end; ++
it) {
 
 1895                 idHelper.get_module_hash(*
it, 
hash);
 
 1900         if (m_idHelperSvc->hasMDT()) {
 
 1901             loadHashes(m_idHelperSvc->mdtIdHelper());
 
 1903         if (m_idHelperSvc->hasRPC()) {
 
 1904             loadHashes(m_idHelperSvc->rpcIdHelper());
 
 1906         if (m_idHelperSvc->hasCSC()) {
 
 1907             loadHashes(m_idHelperSvc->cscIdHelper());
 
 1910         if (m_idHelperSvc->hasMM()) {
 
 1911             auto it = m_idHelperSvc->mmIdHelper().detectorElement_begin();
 
 1912             const auto it_end = m_idHelperSvc->mmIdHelper().detectorElement_end();
 
 1913             for (; 
it != it_end; ++
it) {
 
 1915                 m_idHelperSvc->mmIdHelper().get_module_hash(*
it, 
hash);
 
 1920         if (m_idHelperSvc->hasSTGC()) {
 
 1921             auto it = m_idHelperSvc->stgcIdHelper().detectorElement_begin();
 
 1922             const auto it_end = m_idHelperSvc->stgcIdHelper().detectorElement_end();
 
 1923             for (; 
it != it_end; ++
it) {
 
 1925                 m_idHelperSvc->stgcIdHelper().get_module_hash(*
it, 
hash);
 
 1926                 int sector = m_idHelperSvc->sector(*
it);
 
 1927                 insertHash(sector, 
hash, *
it);
 
 1928                 int sectorU = sector != 1 ? sector - 1 : 16;
 
 1929                 int sectorD = sector != 16 ? sector + 1 : 1;
 
 1930                 insertHash(sectorU, 
hash, *
it);
 
 1931                 insertHash(sectorD, 
hash, *
it);
 
 1935         if (m_idHelperSvc->hasTGC()) {
 
 1937             auto it = m_idHelperSvc->tgcIdHelper().module_begin();
 
 1938             const auto it_end = m_idHelperSvc->tgcIdHelper().module_end();
 
 1939             for (; 
it != it_end; ++
it) {
 
 1942                 m_idHelperSvc->tgcIdHelper().get_module_hash(*
it, 
hash);
 
 1943                 int nstrips = detEl->
nStrips(1);
 
 1946                 std::vector<int> sectors1{}, sectors2{};
 
 1947                 getSectors(
p1, sectors1);
 
 1948                 getSectors(
p2, sectors2);
 
 1949                 std::unordered_set<int> added{};
 
 1950                 for (
const int sector : sectors1) {
 
 1951                     insertHash(sector, 
hash, *
it);
 
 1952                     added.insert(sector);
 
 1954                 for (
const int sector: sectors2) {
 
 1955                     if (added.insert(sector).second){
 
 1956                         insertHash(sector, 
hash, *
it);
 
 1963         ATH_MSG_DEBUG(
" Printing collections per sector, number of technologies " << m_ntechnologies);
 
 1964         for (
int sector = 1; sector <= 16; ++sector) {
 
 1965             DetRegIdx currentRegion = DetRegIdx::DetectorRegionUnknown;
 
 1968             for (
unsigned int hash = 0; 
hash < nsectorHashMax; ++
hash) {
 
 1969                 std::pair<DetRegIdx, MuonStationIndex::LayerIndex> regionLayer =
 
 1974                 currentRegion = regionLayer.first;
 
 1975                 for (
unsigned int tech = 0; tech < m_ntechnologies; ++tech) {
 
 1977                     if (!
vec[tech][
hash].empty()) {
 
 1985                                               << 
" " << std::setw(4) << 
vec[tech][
hash].
size());
 
 1991         m_sectorSetup = 
true;
 
 1995         if (truth.size() == 
found.size()) {
 
 1996             ATH_MSG_DEBUG(
" All hits found: truth " << truth.size() << 
" found " << 
found.size());
 
 1998             ATH_MSG_DEBUG(
" Some truth hits not found: truth " << truth.size() << 
" found " << 
found.size());
 
 1999             std::vector<Identifier> 
result(truth.size() - 
found.size());
 
 2001                 std::set_difference(truth.begin(), truth.end(), 
found.begin(), 
found.end(), 
result.begin());