KiTrack  1.7.0
SubsetSimple.h
1 #ifndef SubsetSimple_h
2 #define SubsetSimple_h
3 
4 #include <algorithm>
5 
6 #include "marlin/VerbosityLevels.h"
7 
8 #include "KiTrack/Subset.h"
9 
10 
11 
12 namespace KiTrack {
13 
14 
15  template <class T, class QI >
16  struct SorterQI
17  {
18  SorterQI( QI getQI ): _getQI( getQI ){}
19 
20  bool operator()( T a, T b ){ return ( _getQI( a ) > _getQI( b ) ); }
21 
22  QI _getQI;
23  };
24 
25 
31  template <class T >
32  class SubsetSimple : public Subset<T> {
33 
34  public:
35 
118  template< class GetQI, class AreCompatible >
119  void calculateBestSet( AreCompatible areCompatible, GetQI getQI );
120 
121 
122  };
123 
124 
125 
126 
127 
128 
129  template<class T> template<class GetQI, class AreCompatible>
130  void SubsetSimple<T>::calculateBestSet( AreCompatible areCompatible, GetQI getQI ){
131 
132 
133  unsigned nAccepted=0;
134  unsigned nRejected=0;
135 
136 
137 
138  std::vector< T > elements = this->_elements;
139 
140  // sort the vector from big QI to small QI
141  SorterQI< T, GetQI > sorterQI( getQI );
142  sort( elements.begin(), elements.end() , sorterQI );
143 
144  streamlog_out( DEBUG3 ) << "The elements and their QIs sorted:\n";
145  for( unsigned i=0; i < elements.size(); i++ ){
146 
147  double qi = getQI( elements[i] );
148  streamlog_out( DEBUG3 ) << elements[i] << "\t" << qi << "\n";
149 
150  }
151 
152  /*The idea here is: the first track is (now that we sorted) the one with the highest
153  * QI. Check all other tracks if they are complatible with it.
154  * If one of them is incompatible throw it away. Once done with that, store the
155  * first track as accepted (and delete it from the vector) and do it once more for
156  * the new highest QI track.
157  * Repeat until all tracks are stored.
158  */
159  while( elements.size() > 0 ){
160 
161 
162  // check all elements with smaller QI if they are compatible
163  for( unsigned i=1; i < elements.size(); i++){
164 
165 
166  if( areCompatible( elements[0] , elements[i] ) == false ){ // the track is incompatible
167 
168  // reject it
169  nRejected++;
170  this->_rejectedElements.push_back( elements[i] );
171 
172  streamlog_out( DEBUG2 ) << "reject " << elements[i] << "\n";
173  // and delete it from the elements we are looking at
174  elements.erase( elements.begin() + i );
175  i--;
176 
177  }
178 
179  }
180 
181  // store the first element
182  streamlog_out( DEBUG2 ) << "accept " << elements[0] << "\n";
183  nAccepted++;
184  this->_acceptedElements.push_back( elements[0] );
185 
186  // delete it from the current tracks
187  elements.erase( elements.begin() );
188 
189  }
190 
191 
192 
193  streamlog_out( DEBUG4 ) << "SubsetSimple accepted " << nAccepted
194  << " elements and rejected " << nRejected << " elements of all in all "
195  << nAccepted + nRejected << " elements.\n";
196 
197 
198  }
199 
200 
201 
202 
203 } // end namespace
204 
205 #endif
A base class for subsets.
Definition: Subset.h:19
void calculateBestSet(AreCompatible areCompatible, GetQI getQI)
Calculates the best set using a very simple method.
Definition: SubsetSimple.h:130
A class to get the best subset by taking the element with the highest quality indicator and throwing ...
Definition: SubsetSimple.h:32
Definition: SubsetSimple.h:16