Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SpsClustering.cpp
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "cheetah/sps_clustering/SpsClustering.h"
25 
26 
27 namespace ska {
28 namespace cheetah {
29 namespace sps_clustering {
30 
31 template<typename NumRepType>
32 std::shared_ptr<data::SpCcl<NumRepType>> SpsClustering::operator()(std::shared_ptr<data::SpCcl<NumRepType>> const& cands)
33 {
34  if (! _config.active())
35  return cands;
36 
37  std::shared_ptr<data::SpCcl<NumRepType>> merged_cands = std::make_shared<data::SpCcl<NumRepType>>(cands->tf_blocks());
38  std::vector<std::vector<size_t>> groups = _clustered_candidates(*cands);
39 
40  PANDA_LOG_DEBUG << "Picking best candidate from " << groups.size() << " clusters...";
41  std::vector<data::SpCandidate<Cpu, float>> group_cands;
42  for ( auto const& group : groups )
43  {
44  // use the max sigma candidate as the representative of any group
45  // Filter out all candidates with these indices into a separate vector
46  PANDA_LOG_DEBUG << "Size of each cluster: " << group.size();
47  std::size_t max_sigma_index = group[0];
48  typename data::SpCcl<NumRepType>::SpCandidateType::NumericalRep max_sigma = (*cands)[max_sigma_index].sigma();
49  for (std::size_t ii=1; ii < group.size(); ++ii)
50  {
51  auto const& candidate = (*cands)[group[ii]];
52  if( candidate.sigma() > max_sigma ) {
53  max_sigma = candidate.sigma();
54  max_sigma_index = group[ii];
55  }
56  }
57  PANDA_LOG_DEBUG << "Parameters for max S/N candidate";
58  PANDA_LOG_DEBUG << "DM: " << (*cands)[max_sigma_index].dm();
59  PANDA_LOG_DEBUG << "Width: " << (*cands)[max_sigma_index].width();
60  PANDA_LOG_DEBUG << "S/N: " << (*cands)[max_sigma_index].sigma();
61  if ((*cands)[max_sigma_index].dm() >= (*cands).dm_range().first + (1.0 * pss::astrotypes::units::parsecs_per_cube_cm))
62  {
63  merged_cands->push_back((*cands)[max_sigma_index]);
64  }
65  }
66  return merged_cands;
67 }
68 
69 } // namespace sps_clustering
70 } // namespace cheetah
71 } // namespace ska
void push_back(SpCandidateType const &cand)
Push back method for inserting Single pulse Candidates but without calculating tend They will be ins...
Definition: SpCcl.cpp:98
std::shared_ptr< data::SpCcl< NumRepType > > operator()(std::shared_ptr< data::SpCcl< NumRepType >> const &cands)
remove duplicate candidates
Some limits and constants for FLDO.
Definition: Brdz.h:35
SpCandidate list.
Definition: SpCcl.h:52