LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
cmtool::CMergeManager Class Reference

#include "CMergeManager.h"

Inheritance diagram for cmtool::CMergeManager:
cmtool::CMManagerBase

Public Types

enum  CMMSGLevel_t { kPerMerging, kPerIteration, kPerEvent, kNone }
 Enum to specify message output level. More...
 

Public Member Functions

 CMergeManager ()
 
virtual ~CMergeManager ()
 Default destructor. More...
 
virtual void Reset ()
 Method to reset itself. More...
 
void AddMergeAlgo (CBoolAlgoBase *algo)
 A simple method to add an algorithm for merging. More...
 
void AddSeparateAlgo (CBoolAlgoBase *algo)
 A simple method to add an algorithm for separation. More...
 
const std::vector< cluster::ClusterParamsAlg > & GetClusters () const
 A method to obtain output clusters. More...
 
const CMergeBookKeeperGetBookKeeper () const
 A method to obtain book keeper. 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 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...
 
void RunMerge (const std::vector< cluster::ClusterParamsAlg > &in_clusters, CMergeBookKeeper &book_keeper) const
 
void RunMerge (const std::vector< cluster::ClusterParamsAlg > &in_clusters, const std::vector< bool > &merge_flag, CMergeBookKeeper &book_keeper) const
 
void RunSeparate (const std::vector< cluster::ClusterParamsAlg > &in_clusters, CMergeBookKeeper &book_keeper) const
 
void ComputePriority (const std::vector< cluster::ClusterParamsAlg > &clusters)
 Function to compute priority. More...
 

Protected Attributes

std::vector< cluster::ClusterParamsAlg_out_clusters
 Output clusters. More...
 
CMergeBookKeeper _book_keeper
 Book keeper instance. More...
 
::cmtool::CBoolAlgoBase_merge_algo
 Merging algorithm. More...
 
::cmtool::CBoolAlgoBase_separate_algo
 Separation algorithm. More...
 
size_t _iter_ctr
 
std::vector< CMergeBookKeeper_book_keeper_v
 
std::vector< std::vector< unsigned short > > _tmp_merged_indexes
 
std::vector< cluster::ClusterParamsAlg_tmp_merged_clusters
 
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...
 

Detailed Description

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

Definition at line 32 of file CMergeManager.h.

Member Enumeration Documentation

Enum to specify message output level.

Enumerator
kPerMerging 

Extremely verbose (cout per individual algorithm execution)

kPerIteration 

Somewhat verbose (cout per merging iteration)

kPerEvent 

Bit verbose (cout per event)

kNone 

Normal.

Definition at line 44 of file CMManagerBase.h.

44  {
50  kPerEvent,
52  kNone
53  };
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:48
Bit verbose (cout per event)
Definition: CMManagerBase.h:50
Extremely verbose (cout per individual algorithm execution)
Definition: CMManagerBase.h:46

Constructor & Destructor Documentation

cmtool::CMergeManager::CMergeManager ( )

Definition at line 19 of file CMergeManager.cxx.

References _iter_ctr, _merge_algo, _separate_algo, and Reset().

20  {
21  _iter_ctr = 0;
22  _merge_algo = nullptr;
23  _separate_algo = nullptr;
24  Reset();
25  }
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:93
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
Definition: CMergeManager.h:96
virtual void Reset()
Method to reset itself.
virtual cmtool::CMergeManager::~CMergeManager ( )
inlinevirtual

Default destructor.

Definition at line 37 of file CMergeManager.h.

References Reset().

37 {}

Member Function Documentation

void cmtool::CMergeManager::AddMergeAlgo ( CBoolAlgoBase algo)
inline

A simple method to add an algorithm for merging.

Definition at line 43 of file CMergeManager.h.

References _merge_algo.

43 { _merge_algo = algo; }
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:93
void cmtool::CMManagerBase::AddPriorityAlgo ( CPriorityAlgoBase algo)
inlineinherited

Setter to add an algorithm for priority determination.

Definition at line 71 of file CMManagerBase.h.

Referenced by ShowerReco3D::ShowerReco3D().

71 { _priority_algo = algo; }
::cmtool::CPriorityAlgoBase * _priority_algo
Priority algorithm.
void cmtool::CMergeManager::AddSeparateAlgo ( CBoolAlgoBase algo)
inline

A simple method to add an algorithm for separation.

Definition at line 46 of file CMergeManager.h.

References _separate_algo.

46 { _separate_algo = algo; }
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
Definition: CMergeManager.h:96
void cmtool::CMManagerBase::ComputePriority ( const std::vector< cluster::ClusterParamsAlg > &  clusters)
protectedinherited

Function to compute priority.

Definition at line 155 of file CMManagerBase.cxx.

References cmtool::CMManagerBase::_planes, cmtool::CMManagerBase::_priority, cmtool::CMManagerBase::_priority_algo, cmtool::CMManagerBase::_time_report, and cmtool::CPriorityAlgoBase::Priority().

Referenced by cmtool::CMatchManager::IterationProcess(), and IterationProcess().

156  {
157 
158  TStopwatch localWatch;
159  localWatch.Start();
160 
161  _priority.clear();
162  _planes.clear();
163 
164  if (!clusters.size()) return;
165 
166  // Priority is computed cluster-by-cluster. In case of two clusters having the same priority
167  // value the one with lower cluster index gets the priority. Also, clusters with priority < 0
168  // are not logged (assumed not to be used)
169 
170  for (size_t i = 0; i < clusters.size(); ++i) {
171 
172  size_t c_index = clusters.size() - i - 1;
173 
174  float priority = clusters.at(c_index).GetNHits();
175 
176  if (_priority_algo) { priority = _priority_algo->Priority(clusters.at(c_index)); }
177 
178  if (priority > 0) {
179 
180  _priority.insert(std::make_pair(priority, c_index));
181 
182  if (_planes.find(clusters.at(c_index).Plane()) == _planes.end())
183 
184  _planes.insert(clusters.at(c_index).Plane());
185  }
186  }
187 
188  if (_time_report)
189  std::cout << Form(" CMManagerBase Time Report: ComputePriority = %g [s]",
190  localWatch.RealTime())
191  << std::endl;
192  }
bool _time_report
Timing verbosity flag.
std::multimap< float, size_t > _priority
Priority record.
virtual float Priority(const cluster::ClusterParamsAlg &cluster)
::cmtool::CPriorityAlgoBase * _priority_algo
Priority algorithm.
std::set< UChar_t > _planes
A holder for # of unique planes in the clusters, computed in ComputePriority() function.
void cmtool::CMManagerBase::DebugMode ( CMMSGLevel_t  level)
inlineinherited

Method to enable debug mode (lots of couts)

Definition at line 62 of file CMManagerBase.h.

62 { _debug_mode = level; }
CMMSGLevel_t _debug_mode
Debug mode switch.
void cmtool::CMergeManager::EventBegin ( )
protectedvirtual

FMWK function called @ beginning of Process()

Reimplemented from cmtool::CMManagerBase.

Definition at line 41 of file CMergeManager.cxx.

References _book_keeper, _book_keeper_v, cmtool::CMManagerBase::_debug_mode, cmtool::CMManagerBase::_fout, cmtool::CMManagerBase::_in_clusters, _iter_ctr, _merge_algo, cmtool::CMManagerBase::_priority_algo, _separate_algo, _tmp_merged_clusters, _tmp_merged_indexes, cmtool::CMAlgoBase::EventBegin(), cmtool::CMManagerBase::kPerMerging, cmtool::CMergeBookKeeper::Reset(), cmtool::CMAlgoBase::SetAnaFile(), and cmtool::CMAlgoBase::SetVerbose().

Referenced by GetBookKeeper().

42  {
43  // Initialization per event
44  if (!_merge_algo) throw CMTException("No algorithm to run!");
45 
46  // Merging algorithm
49 
50  // Separation algorithm
51  if (_separate_algo) {
54  }
55 
56  // Priority ordering algorithm
57  if (_priority_algo) {
60  }
61 
62  // Verbosity setting
63  if (_debug_mode <= kPerMerging) {
64  _merge_algo->SetVerbose(true);
67  }
68 
69  // Book keeper reinitialization
71 
72  // Clear temporary variables
73  _iter_ctr = 0;
74  _tmp_merged_clusters.clear();
75  _tmp_merged_indexes.clear();
76  _book_keeper_v.clear();
77  }
std::vector< CMergeBookKeeper > _book_keeper_v
TFile * _fout
Output analysis plot TFile.
std::vector< std::vector< unsigned short > > _tmp_merged_indexes
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:93
std::vector< cluster::ClusterParamsAlg > _tmp_merged_clusters
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
Definition: CMergeManager.h:96
CMergeBookKeeper _book_keeper
Book keeper instance.
Definition: CMergeManager.h:90
CMMSGLevel_t _debug_mode
Debug mode switch.
void SetAnaFile(TFile *fout)
Setter function for an output plot TFile pointer.
Definition: CMAlgoBase.h:72
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:75
Extremely verbose (cout per individual algorithm execution)
Definition: CMManagerBase.h:46
void Reset(unsigned short nclusters=0)
Reset method.
virtual void EventBegin(const std::vector< cluster::ClusterParamsAlg > &)
Definition: CMAlgoBase.h:45
void cmtool::CMergeManager::EventEnd ( )
protectedvirtual

FMWK function called @ end of Process()

Reimplemented from cmtool::CMManagerBase.

Definition at line 142 of file CMergeManager.cxx.

References _book_keeper, _book_keeper_v, _merge_algo, cmtool::CMManagerBase::_priority_algo, _separate_algo, _tmp_merged_clusters, _tmp_merged_indexes, cmtool::CMergeBookKeeper::Combine(), and cmtool::CMAlgoBase::EventEnd().

Referenced by GetBookKeeper().

143  {
144  // Gather the full book keeping result
145  for (auto const& bk : _book_keeper_v)
146 
147  _book_keeper.Combine(bk);
148 
149  // Call EventEnd for algorithms
153 
154  _book_keeper_v.clear();
155  _tmp_merged_clusters.clear();
156  _tmp_merged_indexes.clear();
157  }
std::vector< CMergeBookKeeper > _book_keeper_v
std::vector< std::vector< unsigned short > > _tmp_merged_indexes
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:93
std::vector< cluster::ClusterParamsAlg > _tmp_merged_clusters
virtual void EventEnd()
Definition: CMAlgoBase.h:50
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
Definition: CMergeManager.h:96
CMergeBookKeeper _book_keeper
Book keeper instance.
Definition: CMergeManager.h:90
void Combine(const CMergeBookKeeper &another)
::cmtool::CPriorityAlgoBase * _priority_algo
Priority algorithm.
const CMergeBookKeeper& cmtool::CMergeManager::GetBookKeeper ( ) const
inline

A method to obtain book keeper.

Definition at line 52 of file CMergeManager.h.

References _book_keeper, EventBegin(), EventEnd(), IterationBegin(), IterationEnd(), IterationProcess(), RunMerge(), and RunSeparate().

Referenced by cluster::ClusterMergeHelper::Process().

52 { return _book_keeper; }
CMergeBookKeeper _book_keeper
Book keeper instance.
Definition: CMergeManager.h:90
const std::vector<cluster::ClusterParamsAlg>& cmtool::CMergeManager::GetClusters ( ) const
inline

A method to obtain output clusters.

Definition at line 49 of file CMergeManager.h.

References _out_clusters.

Referenced by cluster::ClusterMergeHelper::GetMergedCPAN(), and cluster::ClusterMergeHelper::Process().

49 { return _out_clusters; }
std::vector< cluster::ClusterParamsAlg > _out_clusters
Output clusters.
Definition: CMergeManager.h:87
const std::vector<cluster::ClusterParamsAlg>& cmtool::CMManagerBase::GetInputClusters ( ) const
inlineinherited

A getter for input clusters.

Definition at line 84 of file CMManagerBase.h.

Referenced by showerreco::ShowerRecoManager::Process().

84 { return _in_clusters; }
std::vector< cluster::ClusterParamsAlg > _in_clusters
Input clusters.
void cmtool::CMergeManager::IterationBegin ( )
protectedvirtual

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

Reimplemented from cmtool::CMManagerBase.

Definition at line 80 of file CMergeManager.cxx.

References cmtool::CMManagerBase::_debug_mode, cmtool::CMManagerBase::_in_clusters, _iter_ctr, _merge_algo, _out_clusters, cmtool::CMManagerBase::_priority_algo, _separate_algo, _tmp_merged_clusters, cmtool::CMAlgoBase::IterationBegin(), and cmtool::CMManagerBase::kPerIteration.

Referenced by GetBookKeeper().

81  {
82 
83  if (!_iter_ctr) {
84 
88  }
89  else {
90 
94  }
95 
96  if (_debug_mode <= kPerIteration) {
97 
98  size_t nclusters = _tmp_merged_clusters.size();
99 
100  if (!_iter_ctr) nclusters = _in_clusters.size();
101 
102  std::cout << std::endl
103  << Form(" Merging iteration %zu: processing %zu clusters...", _iter_ctr, nclusters)
104  << std::endl;
105  }
106  }
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:48
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:93
std::vector< cluster::ClusterParamsAlg > _out_clusters
Output clusters.
Definition: CMergeManager.h:87
std::vector< cluster::ClusterParamsAlg > _tmp_merged_clusters
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
Definition: CMergeManager.h:96
CMMSGLevel_t _debug_mode
Debug mode switch.
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:57
void cmtool::CMergeManager::IterationEnd ( )
protectedvirtual

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

Reimplemented from cmtool::CMManagerBase.

Definition at line 109 of file CMergeManager.cxx.

References cmtool::CMManagerBase::_debug_mode, _iter_ctr, _merge_algo, cmtool::CMManagerBase::_merge_till_converge, _out_clusters, cmtool::CMManagerBase::_priority_algo, _separate_algo, _tmp_merged_clusters, cmtool::CMAlgoBase::IterationEnd(), cmtool::CMManagerBase::kPerIteration, and cmtool::CMAlgoBase::Report().

Referenced by GetBookKeeper().

110  {
111 
115 
116  if (_debug_mode <= kPerIteration) {
117 
118  _merge_algo->Report();
121 
122  std::cout << Form(" Input / Output cluster length: %zu/%zu",
123  _tmp_merged_clusters.size(),
124  _out_clusters.size())
125  << std::endl;
126 
127  if (_tmp_merged_clusters.size() == _out_clusters.size())
128 
129  std::cout << " Did not find any newly merged clusters..." << std::endl;
130 
131  if (_out_clusters.size() == 1)
132 
133  std::cout << " Output cluster length is 1 (= no more merging needed)" << std::endl;
134 
135  if (!_merge_till_converge) std::cout << " Non-iterative option: terminating..." << std::endl;
136  }
137 
138  _iter_ctr++;
139  }
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:48
bool _merge_till_converge
Iteration loop switch.
virtual void Report()
Definition: CMAlgoBase.h:69
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:93
std::vector< cluster::ClusterParamsAlg > _out_clusters
Output clusters.
Definition: CMergeManager.h:87
std::vector< cluster::ClusterParamsAlg > _tmp_merged_clusters
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
Definition: CMergeManager.h:96
CMMSGLevel_t _debug_mode
Debug mode switch.
::cmtool::CPriorityAlgoBase * _priority_algo
Priority algorithm.
virtual void IterationEnd()
Definition: CMAlgoBase.h:62
bool cmtool::CMergeManager::IterationProcess ( util::GeometryUtilities const &  gser)
protectedvirtual

FMWK function called @ iterative loop inside Process()

Implements cmtool::CMManagerBase.

Definition at line 159 of file CMergeManager.cxx.

References _book_keeper_v, cmtool::CMManagerBase::_debug_mode, cmtool::CMManagerBase::_in_clusters, _iter_ctr, _merge_algo, _out_clusters, cmtool::CMManagerBase::_planes, _separate_algo, _tmp_merged_clusters, _tmp_merged_indexes, cmtool::CMManagerBase::ComputePriority(), cmtool::CMManagerBase::kPerIteration, cmtool::CMergeBookKeeper::PassResult(), cmtool::CMAlgoBase::Report(), cmtool::CMergeBookKeeper::Reset(), RunMerge(), and RunSeparate().

Referenced by GetBookKeeper().

160  {
161  // Configure input for RunMerge
162  CMergeBookKeeper bk;
163 
164  if (!_iter_ctr)
166  else
168  _out_clusters.clear();
169 
170  bk.Reset(_tmp_merged_clusters.size());
171 
172  std::vector<bool> merge_switch(_tmp_merged_clusters.size(), true);
173 
174  for (size_t i = 0; i < _tmp_merged_indexes.size(); ++i)
175  if (_tmp_merged_indexes.at(i).size() == 1) merge_switch.at(i) = false;
176 
178 
179  // Run separation algorithm
181 
182  // Run merging algorithm
183  RunMerge(_tmp_merged_clusters, merge_switch, bk);
185 
186  // Save output
187  bk.PassResult(_tmp_merged_indexes);
188 
189  if (bk.size() == _tmp_merged_indexes.size())
191  else {
192  _out_clusters.reserve(_tmp_merged_indexes.size());
193  for (auto const& indexes_v : _tmp_merged_indexes) {
194 
195  if (indexes_v.size() == 1) {
196  _out_clusters.push_back(_tmp_merged_clusters.at(indexes_v.at(0)));
197  continue;
198  }
199 
200  size_t tmp_hit_counts = 0;
201  for (auto const& index : indexes_v)
202  tmp_hit_counts += _tmp_merged_clusters.at(index).GetHitVector().size();
203  //std::vector<larutil::PxHit> tmp_hits;
204  std::vector<util::PxHit> tmp_hits;
205  tmp_hits.reserve(tmp_hit_counts);
206 
207  for (auto const& index : indexes_v) {
208  for (auto const& hit : _tmp_merged_clusters.at(index).GetHitVector())
209  tmp_hits.push_back(hit);
210  }
212  (*_out_clusters.rbegin()).SetVerbose(false);
213  (*_out_clusters.rbegin()).DisableFANN();
214 
215  if ((*_out_clusters.rbegin()).SetHits(tmp_hits) < 1) continue;
216  (*_out_clusters.rbegin()).FillParams(gser, true, true, true, true, true, false);
217  (*_out_clusters.rbegin()).FillPolygon(gser);
218  }
219  _book_keeper_v.push_back(bk);
220  }
221 
222  // Break if no more merging occurred
223  if (_tmp_merged_clusters.size() == _out_clusters.size()) return false;
224 
225  if (_out_clusters.size() == _planes.size()) return false;
226 
227  return true;
228  }
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:48
std::vector< CMergeBookKeeper > _book_keeper_v
virtual void Report()
Definition: CMAlgoBase.h:69
std::vector< std::vector< unsigned short > > _tmp_merged_indexes
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:93
std::vector< cluster::ClusterParamsAlg > _out_clusters
Output clusters.
Definition: CMergeManager.h:87
std::vector< cluster::ClusterParamsAlg > _tmp_merged_clusters
void ComputePriority(const std::vector< cluster::ClusterParamsAlg > &clusters)
Function to compute priority.
void RunMerge(const std::vector< cluster::ClusterParamsAlg > &in_clusters, CMergeBookKeeper &book_keeper) const
void RunSeparate(const std::vector< cluster::ClusterParamsAlg > &in_clusters, CMergeBookKeeper &book_keeper) const
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
Definition: CMergeManager.h:96
CMMSGLevel_t _debug_mode
Debug mode switch.
Detector simulation of raw signals on wires.
std::vector< cluster::ClusterParamsAlg > _in_clusters
Input clusters.
std::set< UChar_t > _planes
A holder for # of unique planes in the clusters, computed in ComputePriority() function.
void cmtool::CMManagerBase::MergeTillConverge ( bool  doit = true)
inlineinherited

Switch to continue merging till converges.

Definition at line 74 of file CMManagerBase.h.

References lar::dump::vector().

74 { _merge_till_converge = doit; }
bool _merge_till_converge
Iteration loop switch.
void cmtool::CMManagerBase::Process ( util::GeometryUtilities const &  gser)
inherited

A method to execute the main action, to be called per event.

Definition at line 89 of file CMManagerBase.cxx.

References cmtool::CMManagerBase::_debug_mode, cmtool::CMManagerBase::_in_clusters, cmtool::CMManagerBase::_merge_till_converge, cmtool::CMManagerBase::_time_report, cmtool::CMManagerBase::EventBegin(), cmtool::CMManagerBase::EventEnd(), cmtool::CMManagerBase::IterationBegin(), cmtool::CMManagerBase::IterationEnd(), cmtool::CMManagerBase::IterationProcess(), and cmtool::CMManagerBase::kPerIteration.

Referenced by cluster::ClusterMergeHelper::Process(), and showerreco::ShowerRecoManager::Reconstruct().

90  {
91 
92  if (!(_in_clusters.size())) return;
93 
94  TStopwatch localWatch;
95 
96  localWatch.Start();
97 
98  EventBegin();
99 
100  if (_time_report)
101  std::cout << Form(" CMManagerBase Time Report: EventBegin = %g [s]", localWatch.RealTime())
102  << std::endl;
103 
104  bool keep_going = true;
105 
106  while (keep_going) {
107 
108  localWatch.Start();
109 
110  IterationBegin();
111 
112  if (_time_report)
113  std::cout << Form(" CMManagerBase Time Report: IterationBegin = %g [s]",
114  localWatch.RealTime())
115  << std::endl;
116 
117  localWatch.Start();
118 
119  keep_going = IterationProcess(gser);
120 
121  if (_time_report)
122  std::cout << Form(" CMManagerBase Time Report: IterationProcess = %g [s]",
123  localWatch.RealTime())
124  << std::endl;
125  localWatch.Start();
126 
127  IterationEnd();
128 
129  if (_time_report)
130  std::cout << Form(" CMManagerBase Time Report: IterationEnd = %g [s]",
131  localWatch.RealTime())
132  << std::endl;
133 
134  if (!_merge_till_converge) {
135 
136  if (_debug_mode <= kPerIteration)
137 
138  std::cout
139  << "\033[93m Iterative approach = OFF ... exiting from iteration loop. \033[00m"
140  << std::endl;
141 
142  break;
143  }
144  }
145 
146  localWatch.Start();
147 
148  EventEnd();
149 
150  if (_time_report)
151  std::cout << Form(" CMManagerBase Time Report: EventEnd = %g [s]", localWatch.RealTime())
152  << std::endl;
153  }
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:48
bool _time_report
Timing verbosity flag.
bool _merge_till_converge
Iteration loop switch.
virtual void EventBegin()
FMWK function called @ beginning of Process()
virtual bool IterationProcess(util::GeometryUtilities const &gser)=0
FMWK function called @ iterative loop inside Process()
virtual void IterationEnd()
FMWK function called @ end of iterative loop inside Process()
CMMSGLevel_t _debug_mode
Debug mode switch.
virtual void IterationBegin()
FMWK function called @ beginning of iterative loop inside Process()
std::vector< cluster::ClusterParamsAlg > _in_clusters
Input clusters.
virtual void EventEnd()
FMWK function called @ end of Process()
void cmtool::CMManagerBase::ReportTimings ( bool  time_report = true)
inlineinherited

Method to enable timing profile cout.

Definition at line 65 of file CMManagerBase.h.

References Reset().

65 { _time_report = time_report; }
bool _time_report
Timing verbosity flag.
void cmtool::CMergeManager::Reset ( )
virtual

Method to reset itself.

Definition at line 27 of file CMergeManager.cxx.

References _book_keeper, _book_keeper_v, _iter_ctr, _merge_algo, _out_clusters, _separate_algo, _tmp_merged_clusters, _tmp_merged_indexes, cmtool::CMAlgoBase::Reset(), cmtool::CMergeBookKeeper::Reset(), and cmtool::CMManagerBase::Reset().

Referenced by CMergeManager(), and ~CMergeManager().

28  {
30  _tmp_merged_clusters.clear();
31  _tmp_merged_indexes.clear();
32  _out_clusters.clear();
34  _book_keeper_v.clear();
37  _iter_ctr = 0;
38  }
std::vector< CMergeBookKeeper > _book_keeper_v
std::vector< std::vector< unsigned short > > _tmp_merged_indexes
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:93
std::vector< cluster::ClusterParamsAlg > _out_clusters
Output clusters.
Definition: CMergeManager.h:87
std::vector< cluster::ClusterParamsAlg > _tmp_merged_clusters
virtual void Reset()
Function to reset the algorithm instance called within CMergeManager/CMatchManager&#39;s Reset() ...
Definition: CMAlgoBase.h:40
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
Definition: CMergeManager.h:96
CMergeBookKeeper _book_keeper
Book keeper instance.
Definition: CMergeManager.h:90
void Reset(unsigned short nclusters=0)
Reset method.
void Reset()
Method to reset itself.
void cmtool::CMergeManager::RunMerge ( const std::vector< cluster::ClusterParamsAlg > &  in_clusters,
CMergeBookKeeper book_keeper 
) const
protected

Definition at line 230 of file CMergeManager.cxx.

Referenced by GetBookKeeper(), and IterationProcess().

232  {
233  RunMerge(in_clusters, std::vector<bool>(in_clusters.size(), true), book_keeper);
234  }
void RunMerge(const std::vector< cluster::ClusterParamsAlg > &in_clusters, CMergeBookKeeper &book_keeper) const
void cmtool::CMergeManager::RunMerge ( const std::vector< cluster::ClusterParamsAlg > &  in_clusters,
const std::vector< bool > &  merge_flag,
CMergeBookKeeper book_keeper 
) const
protected

Definition at line 236 of file CMergeManager.cxx.

References cmtool::CMManagerBase::_debug_mode, _merge_algo, cmtool::CMManagerBase::_priority, cmtool::CBoolAlgoBase::Bool(), cmtool::CMergeBookKeeper::GetResult(), cmtool::CMManagerBase::kPerIteration, cmtool::CMManagerBase::kPerMerging, cmtool::CMergeBookKeeper::Merge(), and cmtool::CMergeBookKeeper::MergeAllowed().

239  {
240  if (merge_flag.size() != in_clusters.size())
241  throw CMTException(
242  Form("in_clusters (%zu) and merge_flag (%zu) vectors must be of same length!",
243  in_clusters.size(),
244  merge_flag.size()));
245  if (_debug_mode <= kPerIteration) {
246 
247  std::cout << Form(" Calling %s with %zu clusters...", __FUNCTION__, in_clusters.size())
248  << std::endl;
249  }
250 
251  //
252  // Merging
253  //
254 
255  // Run over clusters and execute merging algorithms
256  for (auto citer1 = _priority.rbegin(); citer1 != _priority.rend(); ++citer1) {
257 
258  auto citer2 = citer1;
259 
260  UChar_t plane1 = in_clusters.at((*citer1).second).Plane();
261 
262  while (1) {
263  citer2++;
264  if (citer2 == _priority.rend()) break;
265 
266  // Skip if not on the same plane
267  UChar_t plane2 = in_clusters.at((*citer2).second).Plane();
268  if (plane1 != plane2) continue;
269 
270  // Skip if this combination is not meant to be compared
271  if (!(merge_flag.at((*citer2).second)) && !(merge_flag.at((*citer1).second))) continue;
272 
273  // Skip if this combination is not allowed to merge
274  if (!(book_keeper.MergeAllowed((*citer1).second, (*citer2).second))) continue;
275 
276  if (_debug_mode <= kPerMerging) {
277 
278  std::cout << Form(" \033[93mInspecting a pair (%zu, %zu) for merging... \033[00m",
279  (*citer1).second,
280  (*citer2).second)
281  << std::endl;
282  }
283 
284  bool merge =
285  _merge_algo->Bool(in_clusters.at((*citer1).second), in_clusters.at((*citer2).second));
286 
287  if (_debug_mode <= kPerMerging) {
288 
289  if (merge)
290  std::cout << " \033[93mfound to be merged!\033[00m " << std::endl << std::endl;
291 
292  else
293  std::cout << " \033[93mfound NOT to be merged...\033[00m" << std::endl << std::endl;
294 
295  } // end looping over all sets of algorithms
296 
297  if (merge) book_keeper.Merge((*citer1).second, (*citer2).second);
298 
299  } // end looping over all cluster pairs for citer1
300 
301  } // end looping over clusters
302 
303  if (_debug_mode <= kPerIteration && book_keeper.GetResult().size() != in_clusters.size()) {
304 
305  std::cout << " Found following clusters to be merged..." << std::endl;
306  for (auto const& indexes_v : book_keeper.GetResult()) {
307 
308  if (indexes_v.size() == 1) continue;
309  std::cout << " ";
310  for (auto index : indexes_v)
311 
312  std::cout << index << " ";
313  std::cout << " ... indexes to be merged!" << std::endl;
314  }
315  }
316  }
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:48
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:93
virtual bool Bool(const ::cluster::ClusterParamsAlg &cluster1, const ::cluster::ClusterParamsAlg &cluster2)
Definition: CBoolAlgoBase.h:40
std::multimap< float, size_t > _priority
Priority record.
CMMSGLevel_t _debug_mode
Debug mode switch.
Extremely verbose (cout per individual algorithm execution)
Definition: CMManagerBase.h:46
void cmtool::CMergeManager::RunSeparate ( const std::vector< cluster::ClusterParamsAlg > &  in_clusters,
CMergeBookKeeper book_keeper 
) const
protected

Definition at line 318 of file CMergeManager.cxx.

References cmtool::CMManagerBase::_debug_mode, _separate_algo, cmtool::CBoolAlgoBase::Bool(), cmtool::CMManagerBase::kPerIteration, cmtool::CMManagerBase::kPerMerging, and cmtool::CMergeBookKeeper::ProhibitMerge().

Referenced by GetBookKeeper(), and IterationProcess().

320  {
321  /*
322  if(separate_flag.size() != in_clusters.size())
323  throw CMTException(Form("in_clusters (%zu) and separate_flag (%zu) vectors must be of same length!",
324  in_clusters.size(),
325  separate_flag.size()
326  )
327  );
328  */
329  if (_debug_mode <= kPerIteration) {
330 
331  std::cout << Form(" Calling %s with %zu clusters...", __FUNCTION__, in_clusters.size())
332  << std::endl;
333  }
334 
335  //
336  // Separation
337  //
338 
339  // Run over clusters and execute merging algorithms
340  for (size_t cindex1 = 0; cindex1 < in_clusters.size(); ++cindex1) {
341 
342  UChar_t plane1 = in_clusters.at(cindex1).Plane();
343 
344  for (size_t cindex2 = cindex1 + 1; cindex2 < in_clusters.size(); ++cindex2) {
345 
346  // Skip if not on the same plane
347  UChar_t plane2 = in_clusters.at(cindex2).Plane();
348  if (plane1 != plane2) continue;
349 
350  // Skip if this combination is not meant to be compared
351  //if(!(separate_flag.at(cindex2))) continue;
352 
353  if (_debug_mode <= kPerMerging) {
354 
355  std::cout << Form(" \033[93mInspecting a pair (%zu, %zu) for separation... \033[00m",
356  cindex1,
357  cindex2)
358  << std::endl;
359  }
360 
361  bool separate = _separate_algo->Bool(in_clusters.at(cindex1), in_clusters.at(cindex2));
362 
363  if (_debug_mode <= kPerMerging) {
364 
365  if (separate)
366  std::cout << " \033[93mfound to be separated!\033[00m " << std::endl << std::endl;
367 
368  else
369  std::cout << " \033[93mfound NOT to be separated...\033[00m" << std::endl
370  << std::endl;
371 
372  } // end looping over all sets of algorithms
373 
374  if (separate) book_keeper.ProhibitMerge(cindex1, cindex2);
375 
376  } // end looping over all cluster pairs for citer1
377 
378  } // end looping over clusters
379  }
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:48
virtual bool Bool(const ::cluster::ClusterParamsAlg &cluster1, const ::cluster::ClusterParamsAlg &cluster2)
Definition: CBoolAlgoBase.h:40
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
Definition: CMergeManager.h:96
CMMSGLevel_t _debug_mode
Debug mode switch.
Extremely verbose (cout per individual algorithm execution)
Definition: CMManagerBase.h:46
void cmtool::CMManagerBase::SetAnaFile ( TFile *  fout)
inlineinherited

A setter for an analysis output file.

Definition at line 93 of file CMManagerBase.h.

93 { _fout = fout; }
TFile * _fout
Output analysis plot TFile.
void cmtool::CMManagerBase::SetClusters ( util::GeometryUtilities const &  gser,
const std::vector< std::vector< util::PxHit >> &  clusters 
)
inherited

A simple method to add a cluster.

Definition at line 34 of file CMManagerBase.cxx.

References cmtool::CMManagerBase::_in_clusters, cmtool::CMManagerBase::_min_nhits, cmtool::CMManagerBase::_time_report, Initialize(), cmtool::CMManagerBase::Reset(), cluster::ClusterParamsAlg::SetMinNHits(), and cluster::ClusterParamsAlg::SetVerbose().

Referenced by showerreco::ShowerRecoManager::Reconstruct().

36  {
37 
38  TStopwatch localWatch;
39 
40  // Reset
41  this->Reset();
42 
43  // Clear & fill cluster info
44 
45  _in_clusters.clear();
46 
47  _in_clusters.reserve(clusters.size());
48 
50  tmp_alg.SetMinNHits(_min_nhits);
51  tmp_alg.SetVerbose(false);
52 
53  for (auto const& c : clusters) {
54 
55  _in_clusters.push_back(tmp_alg);
56  (*_in_clusters.rbegin()).Initialize();
57 
58  if ((*_in_clusters.rbegin()).SetHits(c) < 3) continue;
59  (*_in_clusters.rbegin()).DisableFANN();
60  (*_in_clusters.rbegin()).FillParams(gser, false, false, false, false, false, false);
61  (*_in_clusters.rbegin()).FillPolygon(gser);
62  }
63 
64  if (_time_report) {
65  std::cout << Form(" CMManagerBase Time Report: SetClusters (CPAN computation) = %g [s]",
66  localWatch.RealTime())
67  << " ... details below." << std::endl;
68 
69  for (auto const& c : _in_clusters)
70 
71  c.TimeReport(std::cout);
72  }
73  }
bool _time_report
Timing verbosity flag.
void Initialize()
Definition: errprop.cc:100
void SetMinNHits(size_t nhit)
unsigned int _min_nhits
Minimum number of hits: the limit set for ClusterParamsAlg.
std::vector< cluster::ClusterParamsAlg > _in_clusters
Input clusters.
void SetVerbose(bool yes=true)
void Reset()
Method to reset itself.
void cmtool::CMManagerBase::SetClusters ( const std::vector< cluster::ClusterParamsAlg > &  clusters)
inherited

A simple method to add a cluster.

Definition at line 75 of file CMManagerBase.cxx.

References cmtool::CMManagerBase::_in_clusters, and cmtool::CMManagerBase::_time_report.

76  {
77  TStopwatch localWatch;
78 
79  localWatch.Start();
80 
81  _in_clusters = clusters;
82 
83  if (_time_report)
84  std::cout << Form(" CMManagerBase Time Report: SetClusters (copy) = %g [s]",
85  localWatch.RealTime())
86  << std::endl;
87  }
bool _time_report
Timing verbosity flag.
std::vector< cluster::ClusterParamsAlg > _in_clusters
Input clusters.
void cmtool::CMManagerBase::SetMinNHits ( unsigned int  n)
inlineinherited

A setter for minimum # of hits ... passed onto ClusterParamsAlg.

Definition at line 87 of file CMManagerBase.h.

References n.

87 { _min_nhits = n; }
unsigned int _min_nhits
Minimum number of hits: the limit set for ClusterParamsAlg.
Char_t n[5]

Member Data Documentation

CMergeBookKeeper cmtool::CMergeManager::_book_keeper
protected

Book keeper instance.

Definition at line 90 of file CMergeManager.h.

Referenced by EventBegin(), EventEnd(), GetBookKeeper(), and Reset().

std::vector<CMergeBookKeeper> cmtool::CMergeManager::_book_keeper_v
protected

Definition at line 100 of file CMergeManager.h.

Referenced by EventBegin(), EventEnd(), IterationProcess(), and Reset().

TFile* cmtool::CMManagerBase::_fout
protectedinherited

Output analysis plot TFile.

Definition at line 131 of file CMManagerBase.h.

Referenced by cmtool::CMManagerBase::CMManagerBase(), and EventBegin().

size_t cmtool::CMergeManager::_iter_ctr
protected
::cmtool::CBoolAlgoBase* cmtool::CMergeManager::_merge_algo
protected
bool cmtool::CMManagerBase::_merge_till_converge
protectedinherited

Iteration loop switch.

Definition at line 137 of file CMManagerBase.h.

Referenced by cmtool::CMManagerBase::CMManagerBase(), IterationEnd(), and cmtool::CMManagerBase::Process().

unsigned int cmtool::CMManagerBase::_min_nhits
protectedinherited

Minimum number of hits: the limit set for ClusterParamsAlg.

Definition at line 119 of file CMManagerBase.h.

Referenced by cmtool::CMManagerBase::CMManagerBase(), and cmtool::CMManagerBase::SetClusters().

std::vector<cluster::ClusterParamsAlg> cmtool::CMergeManager::_out_clusters
protected

Output clusters.

Definition at line 87 of file CMergeManager.h.

Referenced by GetClusters(), IterationBegin(), IterationEnd(), IterationProcess(), and Reset().

std::set<UChar_t> cmtool::CMManagerBase::_planes
protectedinherited

A holder for # of unique planes in the clusters, computed in ComputePriority() function.

Definition at line 140 of file CMManagerBase.h.

Referenced by cmtool::CMManagerBase::ComputePriority(), cmtool::CMatchManager::IterationProcess(), IterationProcess(), and cmtool::CMManagerBase::Reset().

std::multimap<float, size_t> cmtool::CMManagerBase::_priority
protectedinherited
::cmtool::CBoolAlgoBase* cmtool::CMergeManager::_separate_algo
protected
bool cmtool::CMManagerBase::_time_report
protectedinherited
std::vector<cluster::ClusterParamsAlg> cmtool::CMergeManager::_tmp_merged_clusters
protected
std::vector<std::vector<unsigned short> > cmtool::CMergeManager::_tmp_merged_indexes
protected

Definition at line 102 of file CMergeManager.h.

Referenced by EventBegin(), EventEnd(), IterationProcess(), and Reset().


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