-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdedoppler_hit_group.cpp
More file actions
64 lines (53 loc) · 1.61 KB
/
Copy pathdedoppler_hit_group.cpp
File metadata and controls
64 lines (53 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <algorithm>
#include <assert.h>
#include "dedoppler_hit_group.h"
using namespace std;
DedopplerHitGroup::DedopplerHitGroup(DedopplerHit hit)
: coarse_channel(hit.coarse_channel) {
hits.push_back(hit);
low_index = hit.lowIndex();
high_index = hit.highIndex();
top_hit_index = 0;
}
void DedopplerHitGroup::add(DedopplerHit hit) {
assert(hit.coarse_channel == coarse_channel);
low_index = min(low_index, hit.lowIndex());
high_index = max(high_index, hit.highIndex());
if (hit.score() > topHit().score()) {
top_hit_index = hits.size();
}
hits.push_back(hit);
}
const DedopplerHit& DedopplerHitGroup::topHit() const {
return hits[top_hit_index];
}
/*
Sorts so that the highest top hit scores come first
*/
bool operator<(const DedopplerHitGroup& lhs, const DedopplerHitGroup& rhs) {
return rhs.topHit().score() < lhs.topHit().score();
}
/*
Group together any hits that do not have 'margin' columns between them.
This does modify the input hits by sorting them.
*/
vector<DedopplerHitGroup> makeHitGroups(vector<DedopplerHit>& hits, int margin) {
vector<DedopplerHitGroup> output;
sort(hits.begin(), hits.end());
for (const DedopplerHit& hit : hits) {
if (output.empty()) {
// Start the first group with this hit
output.emplace_back(hit);
continue;
}
if (hit.coarse_channel == output.back().coarse_channel &&
hit.lowIndex() <= output.back().high_index + margin) {
// Merge this hit into the last group
output.back().add(hit);
continue;
}
output.emplace_back(hit);
}
sort(output.begin(), output.end());
return output;
}