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

#include "CBAlgoMergeTinyWithBig.h"

Inheritance diagram for cmtool::CBAlgoMergeTinyWithBig:
cmtool::CBoolAlgoBase cmtool::CMAlgoBase

Public Member Functions

 CBAlgoMergeTinyWithBig ()
 Default constructor. More...
 
virtual ~CBAlgoMergeTinyWithBig ()
 Default destructor. More...
 
virtual bool Bool (const ::cluster::ClusterParamsAlg &cluster1, const ::cluster::ClusterParamsAlg &cluster2)
 
virtual void Report ()
 
virtual void Reset ()
 Function to reset the algorithm instance ... maybe implemented via child class. More...
 
void SetMinHitsBig (size_t nhits)
 
void SetMaxHitsBig (size_t nhits)
 
void SetMinHitsSmall (size_t nhits)
 
void SetMaxHitsSmall (size_t nhits)
 
void SetMinDistSquared (double dist)
 
void SetDebug (bool flag)
 
virtual void EventBegin (const std::vector< cluster::ClusterParamsAlg > &)
 
virtual void EventEnd ()
 
virtual void IterationBegin (const std::vector< cluster::ClusterParamsAlg > &)
 
virtual void IterationEnd ()
 
void SetAnaFile (TFile *fout)
 Setter function for an output plot TFile pointer. More...
 
virtual void SetVerbose (bool doit=true)
 Setter function for verbosity. More...
 

Protected Attributes

TFile * _fout
 TFile pointer to an output file. More...
 
bool _verbose
 Boolean to choose verbose mode. Turned on if CMergeManager/CMatchManager's verbosity level is >= kPerMerging. More...
 

Private Attributes

size_t _min_hits_small
 
size_t _max_hits_small
 
size_t _min_hits_big
 
size_t _max_hits_big
 
double _dist_sqrd_cut
 
bool _debug
 

Detailed Description

User implementation for CBoolAlgoBase class doxygen documentation!

This algo looks for tiny clusters and looks to merge them with big clusters. It uses code from PolyShortestDist and says if the small cluster is close(ish) to the big one, merge it.

Definition at line 31 of file CBAlgoMergeTinyWithBig.h.

Constructor & Destructor Documentation

cmtool::CBAlgoMergeTinyWithBig::CBAlgoMergeTinyWithBig ( )

Default constructor.

Definition at line 8 of file CBAlgoMergeTinyWithBig.cxx.

References SetDebug(), SetMaxHitsBig(), SetMaxHitsSmall(), SetMinDistSquared(), SetMinHitsBig(), and SetMinHitsSmall().

8  : CBoolAlgoBase()
9  //-------------------------------------------------------
10  {
11  SetMinHitsBig(50);
12  SetMaxHitsBig(99999);
13  SetMinHitsSmall(0);
14  SetMaxHitsSmall(15);
16 
17  SetDebug(false);
18  }
CBoolAlgoBase()
Default constructor.
Definition: CBoolAlgoBase.h:31
virtual cmtool::CBAlgoMergeTinyWithBig::~CBAlgoMergeTinyWithBig ( )
inlinevirtual

Default destructor.

Definition at line 38 of file CBAlgoMergeTinyWithBig.h.

References Bool(), Report(), and Reset().

38 {};

Member Function Documentation

bool cmtool::CBAlgoMergeTinyWithBig::Bool ( const ::cluster::ClusterParamsAlg cluster1,
const ::cluster::ClusterParamsAlg cluster2 
)
virtual

Core function: given the CPAN input, return whether a cluster should be merged or not.

Reimplemented from cmtool::CBoolAlgoBase.

Definition at line 26 of file CBAlgoMergeTinyWithBig.cxx.

References _debug, _dist_sqrd_cut, _max_hits_big, _max_hits_small, _min_hits_big, and _min_hits_small.

Referenced by ~CBAlgoMergeTinyWithBig().

29  {
30 
31  if (_debug)
32  std::cout << "MergeTinyWithBig. One cluster has " << cluster1.GetNHits()
33  << " hits, the other has " << cluster2.GetNHits() << " hits." << std::endl;
34 
35  bool is_1_small = false;
36  bool is_2_small = false;
37  bool is_1_big = false;
38  bool is_2_big = false;
39 
40  //if the first cluster counts as "small"
41  if (cluster1.GetNHits() > _min_hits_small && cluster1.GetNHits() < _max_hits_small)
42  is_1_small = true;
43  //if the second cluster counts as "small"
44  if (cluster2.GetNHits() > _min_hits_small && cluster2.GetNHits() < _max_hits_small)
45  is_2_small = true;
46  if (cluster1.GetNHits() > _min_hits_big && cluster1.GetNHits() < _max_hits_big) is_1_big = true;
47  if (cluster2.GetNHits() > _min_hits_big && cluster2.GetNHits() < _max_hits_big) is_2_big = true;
48 
49  if (_debug)
50  std::cout << "is_1_small, is_1_big, is_2_small, is_2_big are: " << is_1_small << ", "
51  << is_1_big << ", " << is_2_small << ", " << is_2_big << std::endl;
52 
53  //if neither of the clusters is small don't merge
54  if (!is_1_small && !is_2_small) return false;
55  //if neither of the clusters is big, don't merge
56  if (!is_1_big && !is_2_big) return false;
57  //if both are small, don't merge
58  if (is_1_small && is_2_small) return false;
59  //if both are big, don't merge
60  if (is_1_big && is_2_big) return false;
61 
62  if (_debug) std::cout << "Looks like one of them is big, and one is small." << std::endl;
63  //god this code is ugly
64 
65  //now we know which one of them is big & the other is small.
66 
67  //loop over the points on the first polygon and calculate
68  //distance to each point on the second polygon
69  //if any two points are close enough to each other,
70  //merge the two clusters
71 
72  unsigned int npoints1 = cluster1.GetParams().PolyObject.Size();
73  unsigned int npoints2 = cluster2.GetParams().PolyObject.Size();
74  //loop over points on first polygon
75  for (unsigned int i = 0; i < npoints1; ++i) {
76  float pt1w = cluster1.GetParams().PolyObject.Point(i).first;
77  float pt1t = cluster1.GetParams().PolyObject.Point(i).second;
78  //loop over points on second polygon
79  for (unsigned int j = 0; j < npoints2; ++j) {
80  float pt2w = cluster2.GetParams().PolyObject.Point(j).first;
81  float pt2t = cluster2.GetParams().PolyObject.Point(j).second;
82  double distsqrd = pow(pt2w - pt1w, 2) + pow(pt2t - pt1t, 2);
83 
84  if (_debug) { std::cout << "two polygon points dist2 is " << distsqrd << std::endl; }
85  if (distsqrd < _dist_sqrd_cut) return true;
86  }
87  }
88 
89  return false;
90  }
Polygon2D PolyObject
Polygon Object...see Polygon2D.hh.
Definition: ClusterParams.h:21
const std::pair< float, float > & Point(unsigned int p) const
Definition: Polygon2D.cxx:158
unsigned int Size() const
Create Intersection Polygon.
Definition: Polygon2D.h:41
const cluster_params & GetParams() const
virtual void cmtool::CMAlgoBase::EventBegin ( const std::vector< cluster::ClusterParamsAlg > &  )
inlinevirtualinherited

Optional function: called at the beginning of 1st iteration. This is called per event.

Reimplemented in cmtool::CPAlgoArray, cmtool::CBAlgoArray, and cmtool::CBAlgoPolyShortestDist.

Definition at line 45 of file CMAlgoBase.h.

Referenced by cmtool::CMergeManager::EventBegin().

45 {}
virtual void cmtool::CMAlgoBase::EventEnd ( )
inlinevirtualinherited

Optional function: called at the end of event ... after the last merging iteration is over.

Reimplemented in cmtool::CPAlgoArray, and cmtool::CBAlgoArray.

Definition at line 50 of file CMAlgoBase.h.

Referenced by cmtool::CMatchManager::EventEnd(), and cmtool::CMergeManager::EventEnd().

50 {}
virtual void cmtool::CMAlgoBase::IterationBegin ( const std::vector< cluster::ClusterParamsAlg > &  )
inlinevirtualinherited

Optional function: called at the beggining of each iteration over all pairs of clusters. This provides all clusters' information in case the algorithm need them. Note this is called per iteration which may be more than once per event.

Reimplemented in cmtool::CPAlgoArray, and cmtool::CBAlgoArray.

Definition at line 57 of file CMAlgoBase.h.

Referenced by cmtool::CMatchManager::EventBegin(), cmtool::CMatchManager::IterationBegin(), and cmtool::CMergeManager::IterationBegin().

57 {}
virtual void cmtool::CMAlgoBase::IterationEnd ( )
inlinevirtualinherited

Optional function: called at the end of each iteration over all pairs of clusters.

Reimplemented in cmtool::CPAlgoArray, and cmtool::CBAlgoArray.

Definition at line 62 of file CMAlgoBase.h.

Referenced by cmtool::CMatchManager::IterationEnd(), and cmtool::CMergeManager::IterationEnd().

62 {}
void cmtool::CBAlgoMergeTinyWithBig::Report ( )
virtual

Optional function: called after each Merge() function call by CMergeManager IFF CMergeManager is run with verbosity level kPerMerging. Maybe useful for debugging.

Reimplemented from cmtool::CMAlgoBase.

Definition at line 93 of file CBAlgoMergeTinyWithBig.cxx.

Referenced by ~CBAlgoMergeTinyWithBig().

95  {}
void cmtool::CBAlgoMergeTinyWithBig::Reset ( )
virtual

Function to reset the algorithm instance ... maybe implemented via child class.

Reimplemented from cmtool::CMAlgoBase.

Definition at line 21 of file CBAlgoMergeTinyWithBig.cxx.

Referenced by ~CBAlgoMergeTinyWithBig().

23  {}
void cmtool::CMAlgoBase::SetAnaFile ( TFile *  fout)
inlineinherited

Setter function for an output plot TFile pointer.

Definition at line 72 of file CMAlgoBase.h.

References cmtool::CMAlgoBase::_fout.

Referenced by cmtool::CMergeManager::EventBegin().

72 { _fout = fout; }
TFile * _fout
TFile pointer to an output file.
Definition: CMAlgoBase.h:79
void cmtool::CBAlgoMergeTinyWithBig::SetDebug ( bool  flag)
inline

Definition at line 95 of file CBAlgoMergeTinyWithBig.h.

References _debug.

Referenced by CBAlgoMergeTinyWithBig().

void cmtool::CBAlgoMergeTinyWithBig::SetMaxHitsBig ( size_t  nhits)
inline

Definition at line 87 of file CBAlgoMergeTinyWithBig.h.

References _max_hits_big.

Referenced by CBAlgoMergeTinyWithBig().

void cmtool::CBAlgoMergeTinyWithBig::SetMaxHitsSmall ( size_t  nhits)
inline

Definition at line 91 of file CBAlgoMergeTinyWithBig.h.

References _max_hits_small.

Referenced by CBAlgoMergeTinyWithBig().

void cmtool::CBAlgoMergeTinyWithBig::SetMinDistSquared ( double  dist)
inline

Definition at line 93 of file CBAlgoMergeTinyWithBig.h.

References _dist_sqrd_cut, and larg4::dist().

Referenced by CBAlgoMergeTinyWithBig().

93 { _dist_sqrd_cut = dist; }
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
void cmtool::CBAlgoMergeTinyWithBig::SetMinHitsBig ( size_t  nhits)
inline

Optional function: called at the beginning of 1st iteration. This is called per event. Optional function: called at the end of event ... after the last merging iteration is over. Optional function: called at the beggining of each iteration over all pairs of clusters. This provides all clusters' information in case the algorithm need them. Note this is called per iteration which may be more than once per event. Optional function: called at the end of each iteration over all pairs of clusters.

Definition at line 85 of file CBAlgoMergeTinyWithBig.h.

References _min_hits_big.

Referenced by CBAlgoMergeTinyWithBig().

void cmtool::CBAlgoMergeTinyWithBig::SetMinHitsSmall ( size_t  nhits)
inline

Definition at line 89 of file CBAlgoMergeTinyWithBig.h.

References _min_hits_small.

Referenced by CBAlgoMergeTinyWithBig().

virtual void cmtool::CMAlgoBase::SetVerbose ( bool  doit = true)
inlinevirtualinherited

Setter function for verbosity.

Reimplemented in cmtool::CBAlgoArray, and cmtool::CFAlgoTimeOverlap.

Definition at line 75 of file CMAlgoBase.h.

References cmtool::CMAlgoBase::_verbose.

Referenced by cmtool::CMatchManager::EventBegin(), and cmtool::CMergeManager::EventBegin().

75 { _verbose = doit; }
bool _verbose
Boolean to choose verbose mode. Turned on if CMergeManager/CMatchManager&#39;s verbosity level is >= kPer...
Definition: CMAlgoBase.h:82

Member Data Documentation

bool cmtool::CBAlgoMergeTinyWithBig::_debug
private

Definition at line 102 of file CBAlgoMergeTinyWithBig.h.

Referenced by Bool(), and SetDebug().

double cmtool::CBAlgoMergeTinyWithBig::_dist_sqrd_cut
private

Definition at line 100 of file CBAlgoMergeTinyWithBig.h.

Referenced by Bool(), and SetMinDistSquared().

TFile* cmtool::CMAlgoBase::_fout
protectedinherited

TFile pointer to an output file.

Definition at line 79 of file CMAlgoBase.h.

Referenced by cmtool::CMAlgoBase::CMAlgoBase(), and cmtool::CMAlgoBase::SetAnaFile().

size_t cmtool::CBAlgoMergeTinyWithBig::_max_hits_big
private

Definition at line 98 of file CBAlgoMergeTinyWithBig.h.

Referenced by Bool(), and SetMaxHitsBig().

size_t cmtool::CBAlgoMergeTinyWithBig::_max_hits_small
private

Definition at line 98 of file CBAlgoMergeTinyWithBig.h.

Referenced by Bool(), and SetMaxHitsSmall().

size_t cmtool::CBAlgoMergeTinyWithBig::_min_hits_big
private

Definition at line 98 of file CBAlgoMergeTinyWithBig.h.

Referenced by Bool(), and SetMinHitsBig().

size_t cmtool::CBAlgoMergeTinyWithBig::_min_hits_small
private

Definition at line 98 of file CBAlgoMergeTinyWithBig.h.

Referenced by Bool(), and SetMinHitsSmall().


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