Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
cmtool::CMatchManager Class Reference

#include <CMatchManager.h>

Inheritance diagram for cmtool::CMatchManager:
cmtool::CMManagerBase

Public Member Functions

 CMatchManager (size_t nplanes)
 
virtual ~CMatchManager ()
 Default destructor. More...
 
virtual void Reset ()
 Method to reset itself. More...
 
void AddMatchAlgo (CFloatAlgoBase *algo)
 A simple method to add an algorithm for merging. More...
 
const CMatchBookKeeperGetBookKeeper () const
 A method to obtain book keeper. More...
 
- Public Member Functions inherited from cmtool::CMManagerBase
 CMManagerBase ()
 Default constructor. More...
 
virtual ~CMManagerBase ()=default
 Default destructor. More...
 
void DebugMode (CMMSGLevel_t level)
 Method to enable debug mode (lots of couts) More...
 
void ReportTimings (bool time_report=true)
 Method to enable timing profile cout. More...
 
void Reset ()
 Method to reset itself. More...
 
void AddPriorityAlgo (CPriorityAlgoBase *algo)
 Setter to add an algorithm for priority determination. More...
 
void MergeTillConverge (bool doit=true)
 Switch to continue merging till converges. More...
 
void SetClusters (util::GeometryUtilities const &gser, const std::vector< std::vector< util::PxHit >> &clusters)
 A simple method to add a cluster. More...
 
void SetClusters (const std::vector< cluster::ClusterParamsAlg > &clusters)
 A simple method to add a cluster. More...
 
const std::vector< cluster::ClusterParamsAlg > & GetInputClusters () const
 A getter for input clusters. More...
 
void SetMinNHits (unsigned int n)
 A setter for minimum # of hits ... passed onto ClusterParamsAlg. More...
 
void Process (util::GeometryUtilities const &gser)
 A method to execute the main action, to be called per event. More...
 
void SetAnaFile (TFile *fout)
 A setter for an analysis output file. More...
 

Protected Member Functions

virtual void EventBegin ()
 FMWK function called @ beginning of Process() More...
 
virtual void IterationBegin ()
 FMWK function called @ beginning of iterative loop inside Process() More...
 
virtual bool IterationProcess (util::GeometryUtilities const &gser)
 FMWK function called @ iterative loop inside Process() More...
 
virtual void IterationEnd ()
 FMWK function called @ end of iterative loop inside Process() More...
 
virtual void EventEnd ()
 FMWK function called @ end of Process() More...
 
- Protected Member Functions inherited from cmtool::CMManagerBase
void ComputePriority (const std::vector< cluster::ClusterParamsAlg > &clusters)
 Function to compute priority. More...
 

Protected Attributes

CMatchBookKeeper _book_keeper
 Book keeper instance. More...
 
::cmtool::CFloatAlgoBase_match_algo
 Merging algorithm. More...
 
size_t _nplanes
 Number of planes. More...
 
- Protected Attributes inherited from cmtool::CMManagerBase
bool _time_report
 Timing verbosity flag. More...
 
unsigned int _min_nhits
 Minimum number of hits: the limit set for ClusterParamsAlg. More...
 
CMMSGLevel_t _debug_mode
 Debug mode switch. More...
 
std::vector< cluster::ClusterParamsAlg_in_clusters
 Input clusters. More...
 
::cmtool::CPriorityAlgoBase_priority_algo
 Priority algorithm. More...
 
TFile * _fout
 Output analysis plot TFile. More...
 
std::multimap< float, size_t > _priority
 Priority record. More...
 
bool _merge_till_converge
 Iteration loop switch. More...
 
std::set< UChar_t > _planes
 A holder for # of unique planes in the clusters, computed in ComputePriority() function. More...
 

Private Member Functions

 CMatchManager ()
 Default constructor is private because we need an argument to configure w/ # planes in the detector. More...
 

Additional Inherited Members

- Public Types inherited from cmtool::CMManagerBase
enum  CMMSGLevel_t { kPerMerging, kPerIteration, kPerEvent, kNone }
 Enum to specify message output level. More...
 

Detailed Description

A class that instantiates merging algorithm(s) and run. The book-keeping of merged cluster sets are done by CMatchBookKeeper.

Definition at line 30 of file CMatchManager.h.

Constructor & Destructor Documentation

cmtool::CMatchManager::CMatchManager ( )
private

Default constructor is private because we need an argument to configure w/ # planes in the detector.

Definition at line 21 of file CMatchManager.cxx.

21  : CMManagerBase()
22  {
23  throw CMTException("Default ctor needs # planes as an argument!");
24  }
CMManagerBase()
Default constructor.
cmtool::CMatchManager::CMatchManager ( size_t  nplanes)

Definition at line 26 of file CMatchManager.cxx.

26  : CMManagerBase()
27  {
28  _match_algo = nullptr;
29  _nplanes = nplanes;
30  Reset();
31  }
virtual void Reset()
Method to reset itself.
::cmtool::CFloatAlgoBase * _match_algo
Merging algorithm.
Definition: CMatchManager.h:84
size_t _nplanes
Number of planes.
Definition: CMatchManager.h:87
CMManagerBase()
Default constructor.
virtual cmtool::CMatchManager::~CMatchManager ( )
inlinevirtual

Default destructor.

Definition at line 40 of file CMatchManager.h.

40 {}

Member Function Documentation

void cmtool::CMatchManager::AddMatchAlgo ( CFloatAlgoBase algo)
inline

A simple method to add an algorithm for merging.

Definition at line 47 of file CMatchManager.h.

48  {
49  _match_algo = algo;
50  }
::cmtool::CFloatAlgoBase * _match_algo
Merging algorithm.
Definition: CMatchManager.h:84
void cmtool::CMatchManager::EventBegin ( )
protectedvirtual

FMWK function called @ beginning of Process()

Reimplemented from cmtool::CMManagerBase.

Definition at line 43 of file CMatchManager.cxx.

44  {
45  if (_debug_mode <= kPerMerging) {
48  }
49 
52  }
::cmtool::CFloatAlgoBase * _match_algo
Merging algorithm.
Definition: CMatchManager.h:84
CMMSGLevel_t _debug_mode
Debug mode switch.
std::vector< cluster::ClusterParamsAlg > _in_clusters
Input clusters.
::cmtool::CPriorityAlgoBase * _priority_algo
Priority algorithm.
virtual void SetVerbose(bool doit=true)
Setter function for verbosity.
Definition: CMAlgoBase.h:92
virtual void IterationBegin(const std::vector< cluster::ClusterParamsAlg > &)
Definition: CMAlgoBase.h:64
Extremely verbose (cout per individual algorithm execution)
Definition: CMManagerBase.h:46
void cmtool::CMatchManager::EventEnd ( )
protectedvirtual

FMWK function called @ end of Process()

Reimplemented from cmtool::CMManagerBase.

Definition at line 69 of file CMatchManager.cxx.

70  {
73  }
::cmtool::CFloatAlgoBase * _match_algo
Merging algorithm.
Definition: CMatchManager.h:84
virtual void EventEnd()
Definition: CMAlgoBase.h:55
::cmtool::CPriorityAlgoBase * _priority_algo
Priority algorithm.
const CMatchBookKeeper& cmtool::CMatchManager::GetBookKeeper ( ) const
inline

A method to obtain book keeper.

Definition at line 54 of file CMatchManager.h.

55  {
56  return _book_keeper;
57  }
CMatchBookKeeper _book_keeper
Book keeper instance.
Definition: CMatchManager.h:81
void cmtool::CMatchManager::IterationBegin ( )
protectedvirtual

FMWK function called @ beginning of iterative loop inside Process()

Reimplemented from cmtool::CMManagerBase.

Definition at line 55 of file CMatchManager.cxx.

56  {
59  }
::cmtool::CFloatAlgoBase * _match_algo
Merging algorithm.
Definition: CMatchManager.h:84
std::vector< cluster::ClusterParamsAlg > _in_clusters
Input clusters.
::cmtool::CPriorityAlgoBase * _priority_algo
Priority algorithm.
virtual void IterationBegin(const std::vector< cluster::ClusterParamsAlg > &)
Definition: CMAlgoBase.h:64
void cmtool::CMatchManager::IterationEnd ( )
protectedvirtual

FMWK function called @ end of iterative loop inside Process()

Reimplemented from cmtool::CMManagerBase.

Definition at line 62 of file CMatchManager.cxx.

63  {
66  }
::cmtool::CFloatAlgoBase * _match_algo
Merging algorithm.
Definition: CMatchManager.h:84
::cmtool::CPriorityAlgoBase * _priority_algo
Priority algorithm.
virtual void IterationEnd()
Definition: CMAlgoBase.h:71
bool cmtool::CMatchManager::IterationProcess ( util::GeometryUtilities const &  gser)
protectedvirtual

FMWK function called @ iterative loop inside Process()

Implements cmtool::CMManagerBase.

Definition at line 181 of file CMatchManager.cxx.

182  {
183  TStopwatch localWatch;
184 
185  //
186  // Create plane-by-plane vectors
187  //
189 
190  if (_planes.size() < 2) return false;
191 
192  if (_planes.size() > _nplanes)
193  throw CMTException("Found more plane IDs than specified number of planes!");
194 
195  // Index array of clusters per plane
196  std::vector<std::vector<size_t>> cluster_array;
197 
198  // Resize to # of planes w/ clusters
199  cluster_array.reserve(_planes.size());
200 
201  // plane-to-index map
202  std::vector<size_t> plane_to_index(_nplanes, _nplanes);
203 
204  // Fill plane-to-index map
205  for (size_t plane = 0; plane < _nplanes; ++plane) {
206  if (_planes.find(plane) != _planes.end()) {
207  plane_to_index[plane] = cluster_array.size();
208 
209  cluster_array.push_back(std::vector<size_t>());
210  }
211  }
212 
213  // Fill cluster_array
214  for (auto riter = _priority.rbegin(); riter != _priority.rend(); ++riter)
215  cluster_array.at(plane_to_index.at(_in_clusters.at((*riter).second).Plane()))
216  .push_back((*riter).second);
217 
218  // Find combinations
219  std::vector<size_t> seed;
220  seed.reserve(cluster_array.size());
221  for (auto const& clusters_per_plane : cluster_array)
222  seed.push_back(clusters_per_plane.size());
223 
224  auto const& combinations = PlaneClusterCombinations(seed);
225 
226  // Loop over combinations and call algorithm
227  for (auto const& comb : combinations) {
228 
229  std::vector<const cluster::ClusterParamsAlg*> ptr_v;
230 
231  std::vector<unsigned int> tmp_index_v;
232  tmp_index_v.reserve(comb.size());
233 
234  ptr_v.reserve(comb.size());
235 
236  for (auto const& plane_cluster : comb) {
237  auto const& in_cluster_index =
238  cluster_array.at(plane_cluster.first).at(plane_cluster.second);
239 
240  tmp_index_v.push_back(in_cluster_index);
241 
242  ptr_v.push_back(&(_in_clusters.at(in_cluster_index)));
243  }
244 
245  if (_debug_mode <= kPerMerging) {
246  std::cout << " \033[93m"
247  << "Inspecting a pair (";
248  for (auto const& index : tmp_index_v)
249  std::cout << index << " ";
250  std::cout << ") \033[00m" << std::flush;
251 
252  localWatch.Start();
253  }
254 
255  auto const& score = _match_algo->Float(gser, ptr_v);
256 
257  if (_debug_mode <= kPerMerging)
258  std::cout << " ... Time taken = " << localWatch.RealTime() << " [s]" << std::endl;
259 
260  if (score > 0) _book_keeper.Match(tmp_index_v, score);
261  }
262 
263  if (_debug_mode <= kPerIteration) {
266  }
267 
268  return false;
269  }
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:48
virtual void Report()
Definition: CMAlgoBase.h:80
std::vector< std::vector< std::pair< size_t, size_t > > > PlaneClusterCombinations(const std::vector< size_t > &seed)
::cmtool::CFloatAlgoBase * _match_algo
Merging algorithm.
Definition: CMatchManager.h:84
virtual float Float(util::GeometryUtilities const &, const std::vector< const cluster::ClusterParamsAlg * > &clusters)
CMatchBookKeeper _book_keeper
Book keeper instance.
Definition: CMatchManager.h:81
void ComputePriority(const std::vector< cluster::ClusterParamsAlg > &clusters)
Function to compute priority.
void Match(const std::vector< unsigned int > &matched_indexes, const float &score)
Method to register matched clusters.
std::multimap< float, size_t > _priority
Priority record.
QTextStream & flush(QTextStream &s)
CMMSGLevel_t _debug_mode
Debug mode switch.
std::vector< cluster::ClusterParamsAlg > _in_clusters
Input clusters.
::cmtool::CPriorityAlgoBase * _priority_algo
Priority algorithm.
std::set< UChar_t > _planes
A holder for # of unique planes in the clusters, computed in ComputePriority() function.
Extremely verbose (cout per individual algorithm execution)
Definition: CMManagerBase.h:46
size_t _nplanes
Number of planes.
Definition: CMatchManager.h:87
QTextStream & endl(QTextStream &s)
void cmtool::CMatchManager::Reset ( void  )
virtual

Method to reset itself.

Definition at line 34 of file CMatchManager.cxx.

35  {
40  }
::cmtool::CFloatAlgoBase * _match_algo
Merging algorithm.
Definition: CMatchManager.h:84
CMatchBookKeeper _book_keeper
Book keeper instance.
Definition: CMatchManager.h:81
virtual void Reset()
Function to reset the algorithm instance called within CMergeManager/CMatchManager&#39;s Reset() ...
Definition: CMAlgoBase.h:41
::cmtool::CPriorityAlgoBase * _priority_algo
Priority algorithm.
void Reset()
Reset method.
void Reset()
Method to reset itself.

Member Data Documentation

CMatchBookKeeper cmtool::CMatchManager::_book_keeper
protected

Book keeper instance.

Definition at line 81 of file CMatchManager.h.

::cmtool::CFloatAlgoBase* cmtool::CMatchManager::_match_algo
protected

Merging algorithm.

Definition at line 84 of file CMatchManager.h.

size_t cmtool::CMatchManager::_nplanes
protected

Number of planes.

Definition at line 87 of file CMatchManager.h.


The documentation for this class was generated from the following files: