16 declareInterface<IMuonSegmentOverlapRemovalTool>(
this);
24 return StatusCode::SUCCESS;
33 std::vector<std::pair<MuonSegmentKey, MuonSegment*>> goodSegments;
34 goodSegments.reserve(segments.
size());
35 std::vector<MuonSegment*> segmentsToErase;
50 bool insertAsGood =
true;
53 for (std::pair<MuonSegmentKey, MuonSegment*>& good_seg : goodSegments) {
59 double chi2good = fq1 ? fq1->
chiSquared() : 1e10;
60 double chi2current = fq2 ? fq2->
chiSquared() : 1e10;
62 if (chi2good > chi2current) {
67 segmentsToErase.push_back(good_seg.second);
69 good_seg.second = seg;
73 segmentsToErase.push_back(seg);
80 segmentsToErase.push_back(seg);
87 segmentsToErase.push_back(good_seg.second);
89 good_seg.second = seg;
97 if (compareSegmentKeys.segment1Size < compareSegmentKeys.segment2Size) {
102 segmentsToErase.push_back(good_seg.second);
104 good_seg.second = seg;
105 insertAsGood =
false;
107 }
else if (compareSegmentKeys.segment1Size == compareSegmentKeys.segment2Size) {
111 if (compareSegmentKeys.segment1SizeTrigger > compareSegmentKeys.segment2SizeTrigger) {
113 segmentsToErase.push_back(seg);
114 insertAsGood =
false;
116 }
else if (compareSegmentKeys.segment1SizeTrigger < compareSegmentKeys.segment2SizeTrigger) {
120 segmentsToErase.push_back(good_seg.second);
122 good_seg.second = seg;
123 insertAsGood =
false;
125 }
else if (compareSegmentKeys.segment1SizeTrigger == compareSegmentKeys.segment2SizeTrigger) {
129 double overlapFraction = (
double)compareSegmentKeys.intersectionSize / (
double)compareSegmentKeys.segment1Size;
132 segmentsToErase.push_back(seg);
133 insertAsGood =
false;
140 segmentsToErase.push_back(seg);
142 insertAsGood =
false;
148 ATH_MSG_WARNING(
" Got invalid return argument comparing segments: " << compareSegmentKeys.print(overlapResult));
156 goodSegments.emplace_back(std::move(sk), seg);
165 if (to_erase ==
dynamic_cast<MuonSegment*
>(tseg)) {
175 std::set<MuonSegment*> segmentsToBeKept;
176 unsigned int nsegments = 0;
180 ATH_MSG_DEBUG(
" removing duplicate from MuonSegmentCombination with " << nstations <<
" stations");
184 for (
unsigned int i = 0;
i < nstations; ++
i) {
189 if (!stationSegs || stationSegs->empty())
continue;
191 nsegments += stationSegs->size();
195 segmentsToBeKept.insert(cleanedSegments.begin(), cleanedSegments.end());
199 if (nsegments == segmentsToBeKept.size()) {
204 std::unique_ptr<MuonSegmentCombination> newCombi = std::make_unique<MuonSegmentCombination>();
207 for (
unsigned int i = 0;
i < nstations; ++
i) {
212 if (!stationSegs || stationSegs->empty())
continue;
214 std::unique_ptr<std::vector<std::unique_ptr<MuonSegment>>> segVec =
215 std::make_unique<std::vector<std::unique_ptr<MuonSegment>>>();
216 segVec->reserve(stationSegs->size());
219 for (
const std::unique_ptr<MuonSegment>& seg : *stationSegs) {
220 if (!segmentsToBeKept.count(seg.get())) {
223 segVec->emplace_back(seg->clone());
227 if (!segVec->empty()) newCombi->addSegments(std::move(segVec));
230 ATH_MSG_DEBUG(
" removed " << nsegments - segmentsToBeKept.size() <<
" duplicates, new size " << segmentsToBeKept.size());
239 ATH_MSG_DEBUG(
" working on segment vector of size " << segments.size());
244 std::vector<std::pair<MuonSegmentKey, MuonSegment*>> goodSegments;
245 goodSegments.reserve(segments.size());
248 for (
const std::unique_ptr<MuonSegment>& seg : segments) {
255 bool insertAsGood(
true);
258 for (std::pair<MuonSegmentKey, MuonSegment*>& good_seg : goodSegments) {
264 double chi2good = fq1 ? fq1->
chiSquared() : 1e10;
265 double chi2current = fq2 ? fq2->
chiSquared() : 1e10;
267 if (chi2good > chi2current) {
273 good_seg.second = seg.get();
277 insertAsGood =
false;
282 insertAsGood =
false;
289 good_seg.second = seg.get();
290 insertAsGood =
false;
297 if (compareSegmentKeys.segment1Size < compareSegmentKeys.segment2Size) {
303 good_seg.second = seg.get();
304 }
else if (compareSegmentKeys.segment1Size == compareSegmentKeys.segment2Size) {
308 if (compareSegmentKeys.segment1SizeTrigger > compareSegmentKeys.segment2SizeTrigger) {
310 insertAsGood =
false;
312 }
else if (compareSegmentKeys.segment1SizeTrigger < compareSegmentKeys.segment2SizeTrigger) {
317 good_seg.second = seg.get();
318 insertAsGood =
false;
320 }
else if (compareSegmentKeys.segment1SizeTrigger == compareSegmentKeys.segment2SizeTrigger) {
324 double overlapFraction = (
double)compareSegmentKeys.intersectionSize / (
double)compareSegmentKeys.segment1Size;
327 insertAsGood =
false;
335 insertAsGood =
false;
341 ATH_MSG_WARNING(
" Got invalid return argument comparing segments: " << compareSegmentKeys.print(overlapResult));
349 goodSegments.emplace_back(sk, seg.get());
354 for (
const std::pair<MuonSegmentKey, MuonSegment*>& good_seg : goodSegments) { cleanedSegments.push_back(good_seg.second); }
355 ATH_MSG_DEBUG(
" Segments after removal " << cleanedSegments.size() <<
" total number of removed segments "
356 << segments.size() - cleanedSegments.size());
358 return cleanedSegments;