LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 ()
 Default constructor. More...
 
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 (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 ()
 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 ()
 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 30 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 34 of file CMManagerBase.h.

34  {
40  kPerEvent,
42  kNone
43  };
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:38
Bit verbose (cout per event)
Definition: CMManagerBase.h:40
Extremely verbose (cout per individual algorithm execution)
Definition: CMManagerBase.h:36

Constructor & Destructor Documentation

cmtool::CMergeManager::CMergeManager ( )

Default constructor.

Definition at line 8 of file CMergeManager.cxx.

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

8  : CMManagerBase()
9  {
10  _iter_ctr=0;
11  _merge_algo = nullptr;
12  _separate_algo = nullptr;
13  Reset();
14  }
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:97
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
virtual void Reset()
Method to reset itself.
CMManagerBase()
Default constructor.
virtual cmtool::CMergeManager::~CMergeManager ( )
inlinevirtual

Default destructor.

Definition at line 38 of file CMergeManager.h.

References Reset().

38 {}

Member Function Documentation

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

A simple method to add an algorithm for merging.

Definition at line 44 of file CMergeManager.h.

References _merge_algo.

Referenced by cluster::FuzzyClusterMerger::FuzzyClusterMerger(), and cluster::SimpleClusterMerger::SimpleClusterMerger().

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

Setter to add an algorithm for priority determination.

Definition at line 63 of file CMManagerBase.h.

References cmtool::CMManagerBase::_priority_algo.

Referenced by cluster::FuzzyClusterMerger::FuzzyClusterMerger(), and ShowerReco3D::ShowerReco3D().

63 { _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 47 of file CMergeManager.h.

References _separate_algo.

Referenced by cluster::FuzzyClusterMerger::FuzzyClusterMerger(), and cluster::SimpleClusterMerger::SimpleClusterMerger().

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

Function to compute priority.

Definition at line 147 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(), IterationProcess(), and cmtool::CMManagerBase::SetAnaFile().

147  {
148 
149  TStopwatch localWatch;
150  localWatch.Start();
151 
152  _priority.clear();
153  _planes.clear();
154 
155  if(!clusters.size()) return;
156 
157  // Priority is computed cluster-by-cluster. In case of two clusters having the same priority
158  // value the one with lower cluster index gets the priority. Also, clusters with priority < 0
159  // are not logged (assumed not to be used)
160 
161  for(size_t i=0; i<clusters.size(); ++i) {
162 
163  size_t c_index = clusters.size() - i - 1;
164 
165  float priority = clusters.at(c_index).GetNHits();
166 
167  if(_priority_algo) {
168 
169  priority = _priority_algo->Priority(clusters.at(c_index));
170 
171  }
172 
173  if(priority>0) {
174 
175  _priority.insert(std::make_pair(priority,c_index));
176 
177  if( _planes.find(clusters.at(c_index).Plane()) == _planes.end() )
178 
179  _planes.insert(clusters.at(c_index).Plane());
180 
181  }
182 
183  }
184 
185  if(_time_report) std::cout << Form(" CMManagerBase Time Report: ComputePriority = %g [s]",
186  localWatch.RealTime())
187  << std::endl;
188 
189  }
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 54 of file CMManagerBase.h.

References cmtool::CMManagerBase::_debug_mode.

Referenced by cluster::SimpleClusterMerger::SimpleClusterMerger().

54 {_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 30 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().

31  {
32  // Initialization per event
33  if(!_merge_algo) throw CMTException("No algorithm to run!");
34 
35  // Merging algorithm
38 
39  // Separation algorithm
40  if(_separate_algo) {
43  }
44 
45  // Priority ordering algorithm
46  if(_priority_algo) {
49  }
50 
51  // Verbosity setting
52  if(_debug_mode <= kPerMerging) {
53  _merge_algo->SetVerbose(true);
56  }
57 
58  // Book keeper reinitialization
60 
61  // Clear temporary variables
62  _iter_ctr = 0;
63  _tmp_merged_clusters.clear();
64  _tmp_merged_indexes.clear();
65  _book_keeper_v.clear();
66 
67  }
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:97
std::vector< cluster::ClusterParamsAlg > _tmp_merged_clusters
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
CMergeBookKeeper _book_keeper
Book keeper instance.
Definition: CMergeManager.h:94
CMMSGLevel_t _debug_mode
Debug mode switch.
void SetAnaFile(TFile *fout)
Setter function for an output plot TFile pointer.
Definition: CMAlgoBase.h:77
virtual void EventBegin(const std::vector< cluster::ClusterParamsAlg > &clusters)
Definition: CMAlgoBase.h:45
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:80
Extremely verbose (cout per individual algorithm execution)
Definition: CMManagerBase.h:36
void Reset(unsigned short nclusters=0)
Reset method.
void cmtool::CMergeManager::EventEnd ( )
protectedvirtual

FMWK function called @ end of Process()

Reimplemented from cmtool::CMManagerBase.

Definition at line 138 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().

139  {
140  // Gather the full book keeping result
141  for(auto const& bk : _book_keeper_v)
142 
143  _book_keeper.Combine(bk);
144 
145  // Call EventEnd for algorithms
149 
150  _book_keeper_v.clear();
151  _tmp_merged_clusters.clear();
152  _tmp_merged_indexes.clear();
153  }
std::vector< CMergeBookKeeper > _book_keeper_v
std::vector< std::vector< unsigned short > > _tmp_merged_indexes
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:97
std::vector< cluster::ClusterParamsAlg > _tmp_merged_clusters
virtual void EventEnd()
Definition: CMAlgoBase.h:51
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
CMergeBookKeeper _book_keeper
Book keeper instance.
Definition: CMergeManager.h:94
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 53 of file CMergeManager.h.

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

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

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

A method to obtain output clusters.

Definition at line 50 of file CMergeManager.h.

References _out_clusters.

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

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

A getter for input clusters.

Definition at line 76 of file CMManagerBase.h.

References cmtool::CMManagerBase::_in_clusters.

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

77  { 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 70 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().

71  {
72 
73  if(!_iter_ctr) {
74 
78 
79  }else{
80 
84 
85  }
86 
87  if(_debug_mode <= kPerIteration) {
88 
89  size_t nclusters = _tmp_merged_clusters.size();
90 
91  if(!_iter_ctr) nclusters = _in_clusters.size();
92 
93  std::cout
94  << std::endl
95  << Form(" Merging iteration %zu: processing %zu clusters...",_iter_ctr,nclusters)
96  << std::endl;
97 
98  }
99 
100  }
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:38
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:97
std::vector< cluster::ClusterParamsAlg > _out_clusters
Output clusters.
Definition: CMergeManager.h:91
std::vector< cluster::ClusterParamsAlg > _tmp_merged_clusters
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
CMMSGLevel_t _debug_mode
Debug mode switch.
virtual void IterationBegin(const std::vector< cluster::ClusterParamsAlg > &clusters)
Definition: CMAlgoBase.h:59
std::vector< cluster::ClusterParamsAlg > _in_clusters
Input clusters.
::cmtool::CPriorityAlgoBase * _priority_algo
Priority algorithm.
void cmtool::CMergeManager::IterationEnd ( )
protectedvirtual

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

Reimplemented from cmtool::CMManagerBase.

Definition at line 103 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().

104  {
105 
109 
110  if(_debug_mode <= kPerIteration) {
111 
112  _merge_algo->Report();
115 
116  std::cout
117  << Form(" Input / Output cluster length: %zu/%zu",_tmp_merged_clusters.size(),_out_clusters.size())
118  << std::endl;
119 
120  if(_tmp_merged_clusters.size() == _out_clusters.size())
121 
122  std::cout << " Did not find any newly merged clusters..." <<std::endl;
123 
124  if(_out_clusters.size()==1)
125 
126  std::cout << " Output cluster length is 1 (= no more merging needed)" << std::endl;
127 
129 
130  std::cout << " Non-iterative option: terminating..." << std::endl;
131 
132  }
133 
134  _iter_ctr++;
135  }
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:38
bool _merge_till_converge
Iteration loop switch.
virtual void Report()
Definition: CMAlgoBase.h:73
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:97
std::vector< cluster::ClusterParamsAlg > _out_clusters
Output clusters.
Definition: CMergeManager.h:91
std::vector< cluster::ClusterParamsAlg > _tmp_merged_clusters
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
CMMSGLevel_t _debug_mode
Debug mode switch.
::cmtool::CPriorityAlgoBase * _priority_algo
Priority algorithm.
virtual void IterationEnd()
Definition: CMAlgoBase.h:65
bool cmtool::CMergeManager::IterationProcess ( )
protectedvirtual

FMWK function called @ iterative loop inside Process()

Implements cmtool::CMManagerBase.

Definition at line 155 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().

156  {
157 
158  // Configure input for RunMerge
159  CMergeBookKeeper bk;
160 
163  _out_clusters.clear();
164 
165  bk.Reset(_tmp_merged_clusters.size());
166 
167  std::vector<bool> merge_switch(_tmp_merged_clusters.size(),true);
168 
169  for(size_t i=0; i<_tmp_merged_indexes.size(); ++i)
170 
171  if(_tmp_merged_indexes.at(i).size()==1)
172 
173  merge_switch.at(i) = false;
174 
176 
177  // Run separation algorithm
178  if(_separate_algo)
179 
181 
182  // Run merging algorithm
183  RunMerge(_tmp_merged_clusters, merge_switch, bk);
185 
186  _merge_algo->Report();
187 
188  // Save output
189  bk.PassResult(_tmp_merged_indexes);
190 
191  if(bk.size() == _tmp_merged_indexes.size())
193  else {
194  _out_clusters.reserve(_tmp_merged_indexes.size());
195  for(auto const& indexes_v : _tmp_merged_indexes) {
196 
197  if(indexes_v.size()==1) {
198  _out_clusters.push_back(_tmp_merged_clusters.at(indexes_v.at(0)));
199  continue;
200  }
201 
202  size_t tmp_hit_counts=0;
203  for(auto const& index : indexes_v)
204  tmp_hit_counts += _tmp_merged_clusters.at(index).GetHitVector().size();
205  //std::vector<larutil::PxHit> tmp_hits;
206  std::vector<util::PxHit> tmp_hits;
207  tmp_hits.reserve(tmp_hit_counts);
208 
209  for(auto const& index : indexes_v) {
210  for(auto const& hit : _tmp_merged_clusters.at(index).GetHitVector())
211  tmp_hits.push_back(hit);
212  }
214  (*_out_clusters.rbegin()).SetVerbose(false);
215  (*_out_clusters.rbegin()).DisableFANN();
216 
217  if((*_out_clusters.rbegin()).SetHits(tmp_hits) < 1) continue;
218  (*_out_clusters.rbegin()).FillParams(true,true,true,true,true,false);
219  (*_out_clusters.rbegin()).FillPolygon();
220  }
221  _book_keeper_v.push_back(bk);
222  }
223 
224  // Break if no more merging occurred
225  if(_tmp_merged_clusters.size() == _out_clusters.size())
226 
227  return false;
228 
229  if(_out_clusters.size() == _planes.size())
230 
231  return false;
232 
233  return true;
234  }
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:38
std::vector< CMergeBookKeeper > _book_keeper_v
virtual void Report()
Definition: CMAlgoBase.h:73
std::vector< std::vector< unsigned short > > _tmp_merged_indexes
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:97
std::vector< cluster::ClusterParamsAlg > _out_clusters
Output clusters.
Definition: CMergeManager.h:91
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.
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
void cmtool::CMManagerBase::Process ( )
inherited

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

Definition at line 83 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(), showerreco::ShowerRecoManager::Reconstruct(), and cmtool::CMManagerBase::SetMinNHits().

84  {
85 
86  if(!(_in_clusters.size()))
87 
88  return;
89 
90  TStopwatch localWatch;
91 
92  localWatch.Start();
93 
94  EventBegin();
95 
96  if(_time_report) std::cout << Form(" CMManagerBase Time Report: EventBegin = %g [s]",
97  localWatch.RealTime())
98  << std::endl;
99 
100  bool keep_going = true;
101 
102  while(keep_going) {
103 
104  localWatch.Start();
105 
106  IterationBegin();
107 
108  if(_time_report) std::cout << Form(" CMManagerBase Time Report: IterationBegin = %g [s]",
109  localWatch.RealTime())
110  << std::endl;
111 
112  localWatch.Start();
113 
114  keep_going = IterationProcess();
115 
116  if(_time_report) std::cout << Form(" CMManagerBase Time Report: IterationProcess = %g [s]",
117  localWatch.RealTime())
118  << std::endl;
119  localWatch.Start();
120 
121  IterationEnd();
122 
123  if(_time_report) std::cout << Form(" CMManagerBase Time Report: IterationEnd = %g [s]",
124  localWatch.RealTime())
125  << std::endl;
126 
127  if(!_merge_till_converge) {
128 
130 
131  std::cout << "\033[93m Iterative approach = OFF ... exiting from iteration loop. \033[00m" << std::endl;
132 
133  break;
134  }
135  }
136 
137  localWatch.Start();
138 
139  EventEnd();
140 
141  if(_time_report) std::cout << Form(" CMManagerBase Time Report: EventEnd = %g [s]",
142  localWatch.RealTime())
143  << std::endl;
144 
145  }
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:38
bool _time_report
Timing verbosity flag.
bool _merge_till_converge
Iteration loop switch.
virtual void EventBegin()
FMWK function called @ beginning of Process()
Definition: CMManagerBase.h:94
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()
Definition: CMManagerBase.h:97
virtual bool IterationProcess()=0
FMWK function called @ 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 57 of file CMManagerBase.h.

References cmtool::CMManagerBase::_time_report, and cmtool::CMManagerBase::Reset().

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

Method to reset itself.

Definition at line 16 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(), cluster::ClusterMergeHelper::SetClusters(), and ~CMergeManager().

17  {
19  _tmp_merged_clusters.clear();
20  _tmp_merged_indexes.clear();
21  _out_clusters.clear();
23  _book_keeper_v.clear();
26  _iter_ctr = 0;
27  }
std::vector< CMergeBookKeeper > _book_keeper_v
std::vector< std::vector< unsigned short > > _tmp_merged_indexes
::cmtool::CBoolAlgoBase * _merge_algo
Merging algorithm.
Definition: CMergeManager.h:97
std::vector< cluster::ClusterParamsAlg > _out_clusters
Output clusters.
Definition: CMergeManager.h:91
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.
CMergeBookKeeper _book_keeper
Book keeper instance.
Definition: CMergeManager.h:94
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 236 of file CMergeManager.cxx.

Referenced by GetBookKeeper(), and IterationProcess().

238  {
239  RunMerge(in_clusters,
240  std::vector<bool>(in_clusters.size(),true),
241  book_keeper);
242  }
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 244 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().

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

Definition at line 337 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().

339  {
340  /*
341  if(separate_flag.size() != in_clusters.size())
342  throw CMTException(Form("in_clusters (%zu) and separate_flag (%zu) vectors must be of same length!",
343  in_clusters.size(),
344  separate_flag.size()
345  )
346  );
347  */
348  if(_debug_mode <= kPerIteration){
349 
350  std::cout
351  << Form(" Calling %s with %zu clusters...",__FUNCTION__,in_clusters.size())
352  <<std::endl;
353 
354  }
355 
356  //
357  // Separation
358  //
359 
360  // Run over clusters and execute merging algorithms
361  for(size_t cindex1 = 0; cindex1 < in_clusters.size(); ++cindex1) {
362 
363  UChar_t plane1 = in_clusters.at(cindex1).Plane();
364 
365  for(size_t cindex2 = cindex1+1; cindex2 < in_clusters.size(); ++cindex2) {
366 
367  // Skip if not on the same plane
368  UChar_t plane2 = in_clusters.at(cindex2).Plane();
369  if(plane1 != plane2) continue;
370 
371  // Skip if this combination is not meant to be compared
372  //if(!(separate_flag.at(cindex2))) continue;
373 
374  if(_debug_mode <= kPerMerging){
375 
376  std::cout
377  << Form(" \033[93mInspecting a pair (%zu, %zu) for separation... \033[00m",cindex1,cindex2)
378  << std::endl;
379  }
380 
381  bool separate = _separate_algo->Bool(in_clusters.at(cindex1),in_clusters.at(cindex2));
382 
383  if(_debug_mode <= kPerMerging) {
384 
385  if(separate)
386  std::cout << " \033[93mfound to be separated!\033[00m "
387  << std::endl
388  << std::endl;
389 
390  else
391  std::cout << " \033[93mfound NOT to be separated...\033[00m"
392  << std::endl
393  << std::endl;
394 
395  } // end looping over all sets of algorithms
396 
397  if(separate)
398 
399  book_keeper.ProhibitMerge(cindex1,cindex2);
400 
401  } // end looping over all cluster pairs for citer1
402 
403  } // end looping over clusters
404 
405  }
Somewhat verbose (cout per merging iteration)
Definition: CMManagerBase.h:38
virtual bool Bool(const ::cluster::ClusterParamsAlg &cluster1, const ::cluster::ClusterParamsAlg &cluster2)
Definition: CBoolAlgoBase.h:41
::cmtool::CBoolAlgoBase * _separate_algo
Separation algorithm.
CMMSGLevel_t _debug_mode
Debug mode switch.
Extremely verbose (cout per individual algorithm execution)
Definition: CMManagerBase.h:36
void cmtool::CMManagerBase::SetAnaFile ( TFile *  fout)
inlineinherited

A setter for an analysis output file.

Definition at line 86 of file CMManagerBase.h.

References cmtool::CMManagerBase::_fout, and cmtool::CMManagerBase::ComputePriority().

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

A simple method to add a cluster.

Definition at line 26 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 cmtool::CMManagerBase::MergeTillConverge(), showerreco::ShowerRecoManager::Reconstruct(), and cluster::ClusterMergeHelper::SetClusters().

27  {
28 
29  TStopwatch localWatch;
30 
31  // Reset
32  this->Reset();
33 
34  // Clear & fill cluster info
35 
36  _in_clusters.clear();
37 
38  _in_clusters.reserve(clusters.size());
39 
41  tmp_alg.SetMinNHits(_min_nhits);
42  tmp_alg.SetVerbose(false);
43 
44  for(auto const &c : clusters) {
45 
46  _in_clusters.push_back(tmp_alg);
47  (*_in_clusters.rbegin()).Initialize();
48 
49  if((*_in_clusters.rbegin()).SetHits(c) < 3) continue;
50  (*_in_clusters.rbegin()).DisableFANN();
51  //(*_in_clusters.rbegin()).FillParams(true,true,true,true,true,false);
52  (*_in_clusters.rbegin()).FillParams(false,false,false,false,false,false);
53  (*_in_clusters.rbegin()).FillPolygon();
54 
55  }
56 
57  if(_time_report) {
58  std::cout << Form(" CMManagerBase Time Report: SetClusters (CPAN computation) = %g [s]",
59  localWatch.RealTime())
60  << " ... details below." << std::endl;
61 
62  for(auto const& c : _in_clusters)
63 
64  c.TimeReport(std::cout);
65 
66  }
67 
68  }
bool _time_report
Timing verbosity flag.
void Initialize()
Definition: errprop.cc:101
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 70 of file CMManagerBase.cxx.

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

71  {
72  TStopwatch localWatch;
73 
74  localWatch.Start();
75 
76  _in_clusters = clusters;
77 
78  if(_time_report) std::cout << Form(" CMManagerBase Time Report: SetClusters (copy) = %g [s]",
79  localWatch.RealTime())
80  << std::endl;
81  }
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 80 of file CMManagerBase.h.

References cmtool::CMManagerBase::_min_nhits, n, and cmtool::CMManagerBase::Process().

80 { _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 94 of file CMergeManager.h.

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

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

Definition at line 104 of file CMergeManager.h.

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

TFile* cmtool::CMManagerBase::_fout
protectedinherited

Output analysis plot TFile.

Definition at line 126 of file CMManagerBase.h.

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

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

Minimum number of hits: the limit set for ClusterParamsAlg.

Definition at line 114 of file CMManagerBase.h.

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

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

Output clusters.

Definition at line 91 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 135 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 106 of file CMergeManager.h.

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


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