24 declareInterface<IMuonSegmentCombinationCleanerTool>(
this);
34 return StatusCode::SUCCESS;
39 std::unique_ptr<MuonSegmentCombinationCollection> combiCleanCol = std::make_unique<MuonSegmentCombinationCollection>();
47 std::unique_ptr<MuonSegmentCombinationCollection>& combiCleanCol,
51 std::vector<MuonSegmentCombiSummary> summaries;
63 if (
summary.stations.size() < 2) {
66 ATH_MSG_VERBOSE(
" Keeping single station endcap middle MuonSegmentCombination ");
69 ATH_MSG_DEBUG(
" MuonSegmentCombination has too few station layers, rejecting ");
74 if (
summary.stationsGood.empty()) {
75 ATH_MSG_DEBUG(
" MuonSegmentCombination has no station layer with good segment, rejecting ");
93 finalCombi = std::make_unique<MuonSegmentCombination>(*
summary.get());
100 unsigned int count = segPattMap->count(originalCombi);
102 ATH_MSG_INFO(
" This list should only have one entry!! ");
104 std::pair<MuonSegmentCombPatternCombAssociationMap::const_iterator,
105 MuonSegmentCombPatternCombAssociationMap::const_iterator>
106 range = segPattMap->equal_range(originalCombi);
109 segPattMap->insert(std::make_pair(finalCombi.get(),
pat));
111 ATH_MSG_INFO(
" The pattern pointer should never be zero!!!! ");
114 combiCleanCol->
push_back(std::move(finalCombi));
119 std::vector<MuonSegmentCombiSummary>& summaries)
const {
120 if (summaries.empty())
return false;
123 bool hasOverlap =
false;
131 if (overlap.
shared.empty()) {
156 unsigned int overlappingSegments1 = overlap.
subsetFirst.size() + overlap.
shared.size();
157 unsigned int overlappingSegments2 = overlap.
subsetSecond.size() + overlap.
shared.size();
159 unsigned int uniqueSegments1 = overlap.
uniqueFirst.size();
160 unsigned int uniqueSegments2 = overlap.
uniqueSecond.size();
161 if (overlappingSegments1 > uniqueSegments1 || overlappingSegments2 > uniqueSegments2 ||
m_mergeAllCombis) {
165 std::set<MuonSegment*> addedSegments;
169 for (std::pair<MuonSegment*, MuonSegment*>& sh_iter : overlap.
shared) {
173 double chi2First = fq1 ? fq1->
chiSquared() : 1e10;
174 double chi2Second = fq2 ? fq2->
chiSquared() : 1e10;
175 MuonSegment* bestSegment = chi2First < chi2Second ? sh_iter.first : sh_iter.second;
178 if (addedSegments.count(bestSegment))
continue;
179 addedSegments.insert(bestSegment);
182 segmentsPerChamberLayer[chIndex].push_back(bestSegment);
187 if (addedSegments.count(bestSegment))
continue;
188 addedSegments.insert(bestSegment);
191 segmentsPerChamberLayer[chIndex].push_back(bestSegment);
196 if (addedSegments.count(bestSegment))
continue;
197 addedSegments.insert(bestSegment);
200 segmentsPerChamberLayer[chIndex].push_back(bestSegment);
203 for (std::pair<MuonSegment*, MuonSegment*>& sh_iter : overlap.
subsetFirst) {
208 if (addedSegments.count(bestSegment))
continue;
209 addedSegments.insert(bestSegment);
212 segmentsPerChamberLayer[chIndex].push_back(bestSegment);
215 for (
const std::pair<MuonSegment*, MuonSegment*>& sh_iter : overlap.
subsetSecond) {
219 if (addedSegments.count(bestSegment))
continue;
220 addedSegments.insert(bestSegment);
223 segmentsPerChamberLayer[chIndex].push_back(bestSegment);
227 std::unique_ptr<MuonSegmentCombination> newCombi = std::make_unique<MuonSegmentCombination>();
230 for (
const std::vector<MuonSegment*>& chamber_hits : segmentsPerChamberLayer) {
232 if (chamber_hits.empty())
continue;
234 std::unique_ptr<MuonSegmentCombination::SegmentVec> segVec = std::make_unique<MuonSegmentCombination::SegmentVec>();
235 segVec->reserve(chamber_hits.size());
236 for (
MuonSegment* seg : chamber_hits) segVec->emplace_back(seg->clone());
237 newCombi->addSegments(std::move(segVec));
245 existing = std::move(newSummary);
267 if (chamberVec1.empty() && chamberVec2.empty())
continue;
270 if (!chamberVec1.empty() && !chamberVec2.empty()) {
276 if (!chamberVec1.empty())
summary.uniqueFirst.insert(
summary.uniqueFirst.begin(), chamberVec1.begin(), chamberVec1.end());
277 if (!chamberVec2.empty())
summary.uniqueSecond.insert(
summary.uniqueSecond.begin(), chamberVec2.begin(), chamberVec2.end());
285 const std::vector<MuonSegment*>& chamberVec2,
289 std::vector<int> uniqueFirst(chamberVec1.size(), 1);
290 std::vector<int> uniqueSecond(chamberVec2.size(), 1);
295 std::set<Identifier> chIds1 =
m_edmHelperSvc->chamberIds(*seg_chamb1);
300 if (!uniqueSecond[
index2]) {
306 std::set<Identifier> chIds2 =
m_edmHelperSvc->chamberIds(*seg_chamb2);
309 bool hasOverlap = std::find_if(chIds2.begin(), chIds2.end(),
310 [&chIds1](
const Identifier&
id) { return chIds1.count(id) > 0; }) != chIds2.end();
320 ATH_MSG_VERBOSE(
" overlap Result: " << compareKeys.print(overlapResult));
323 summary.shared.emplace_back(seg_chamb1, seg_chamb2);
327 summary.subsetSecond.emplace_back(seg_chamb1, seg_chamb2);
331 summary.subsetFirst.emplace_back(seg_chamb1, seg_chamb2);
338 if (compareKeys.intersectionSize == compareKeys.segment1Size &&
339 compareKeys.intersectionSize == compareKeys.segment2Size) {
341 double intersectFrac1 = compareKeys.intersectionSizeTrigger == 0
343 : compareKeys.intersectionSizeTrigger / (
double)compareKeys.segment1SizeTrigger;
344 double intersectFrac2 = compareKeys.intersectionSizeTrigger == 0
346 : compareKeys.intersectionSizeTrigger / (
double)compareKeys.segment2SizeTrigger;
347 double openingAngle = seg_chamb1->globalDirection().dot(seg_chamb2->globalDirection());
348 ATH_MSG_VERBOSE(
" Partial overlap: (" << intersectFrac1 <<
"," << intersectFrac2 <<
"), opening angle "
350 if (intersectFrac1 > 0.75 && intersectFrac2 > 0.75 && openingAngle > 0.99) {
351 summary.shared.emplace_back(seg_chamb1, seg_chamb2);
359 ATH_MSG_WARNING(
" Got invalid return argument comparing segments: " << compareKeys.print(overlapResult));
368 if (uniqueFirst[
index1])
summary.uniqueFirst.push_back(seg_chamb1);
374 if (uniqueSecond[
index2])
summary.uniqueSecond.push_back(seg_chamb2);
385 for (
unsigned int i = 0;
i < nstations; ++
i) {
390 if (!stationSegs || stationSegs->empty())
continue;
397 summary.stations.insert(stIndex);
401 chamberVec.reserve(chamberVec.size() + stationSegs->size());
403 summary.nsegments += stationSegs->size();
404 for (
const std::unique_ptr<MuonSegment>& seg : *stationSegs) {
405 if (seg->numberOfContainedROTs() > 3) {
summary.stationsGood.insert(stIndex); }
406 chamberVec.push_back(seg.get());
416 std::set<MuonSegment*> segmentsToBeKept;
417 unsigned int nsegments = 0;
423 for (
unsigned int i = 0;
i < nstations; ++
i) {
427 if (!stationSegs || stationSegs->empty())
continue;
428 nsegments += stationSegs->size();
430 std::vector<std::pair<MuonSegmentKey, MuonSegment*> >
keys;
431 keys.reserve(stationSegs->size());
433 for (
const std::unique_ptr<MuonSegment>& seg : *stationSegs) {
439 bool addSegment =
true;
440 for (std::pair<MuonSegmentKey, MuonSegment*>& key_pair :
keys) {
442 ATH_MSG_VERBOSE(
" overlap Result: " << compareKeys.print(overlapResult));
448 key_pair.first =
key;
449 key_pair.second = seg.get();
453 ATH_MSG_WARNING(
" Got invalid return argument comparing segments: " << compareKeys.print(overlapResult));
456 if (addSegment)
keys.emplace_back(std::move(
key), seg.get());
458 for (
const std::pair<MuonSegmentKey, MuonSegment*>& key_pair :
keys) segmentsToBeKept.insert(key_pair.second);
462 if (nsegments == segmentsToBeKept.size()) {
467 std::unique_ptr<MuonSegmentCombination> newCombi = std::make_unique<MuonSegmentCombination>();
470 for (
unsigned int i = 0;
i < nstations; ++
i) {
475 if (!stationSegs || stationSegs->empty())
continue;
477 std::unique_ptr<MuonSegmentCombination::SegmentVec> segVec = std::make_unique<MuonSegmentCombination::SegmentVec>();
478 segVec->reserve(stationSegs->size());
480 for (std::unique_ptr<MuonSegment>& seg : *stationSegs) {
481 if (!segmentsToBeKept.count(seg.get())) {
486 segVec->push_back(std::move(seg));
488 newCombi->addSegments(std::move(segVec));
495 std::ostringstream sout;
501 sout <<
"SegmentCombi " << std::endl;
505 if (chiit.empty())
continue;
508 <<
" segments " << std::endl;
519 std::ostringstream sout;
521 sout <<
"SegmentCombi overlap " << std::endl
522 <<
" shared: " <<
summary.shared.size() << std::endl
523 <<
" uniqueFirst: " <<
summary.uniqueFirst.size() << std::endl
524 <<
" uniqueSecond: " <<
summary.uniqueSecond.size() << std::endl
525 <<
" subsetFirst: " <<
summary.subsetFirst.size() << std::endl
526 <<
" subsetSecond: " <<
summary.subsetSecond.size() << std::endl;