KNNClusterAlg.cxx
Go to the documentation of this file.
1 //
2 // KNNClusterAlg.cxx
3 //
4 // Created by Eldwan Brianne on 10.02.2019
5 //
6 
9 
10 #include "RecoAlg/KNNClusterAlg.h"
11 #include "RecoAlg/NNClusters.h"
12 
13 #include "Geometry/GeometryGAr.h"
14 #include "CoreUtils/ServiceUtil.h"
15 #include <algorithm>
16 
17 namespace gar {
18  namespace rec{
19  namespace alg{
20 
21  //----------------------------------------------------------------------------
23  {
24  fGeo = gar::providerFrom<geo::GeometryGAr>();
25  this->reconfigure(pset);
26  ClearLists();
27  return;
28  }
29  //----------------------------------------------------------------------------
31  {
32  return;
33  }
34  //----------------------------------------------------------------------------
36  {
37  fClusterAlgName = pset.get<std::string>("ClusterAlgName");
38 
39  //Algorithm parameters
40  m_EnergyCut = pset.get<float>("EnergyCut", 0.);
41  m_DistanceCut = pset.get<float>("DistanceCut", 5.f);
42 
43  return;
44  }
45  //----------------------------------------------------------------------------
47  {
48  clusterVector.clear();
49  m_CaloHitVec.clear();
50  m_TrackVec.clear();
51 
52  return;
53  }
54 
55  //----------------------------------------------------------------------------
56  void KNNClusterAlg::PrepareAlgo(const std::vector< art::Ptr<gar::rec::Track> > &trkVector, const std::vector< art::Ptr<gar::rec::CaloHit> > &hitVector, std::unordered_map< const gar::rec::Track*, art::Ptr<gar::rec::Track> > &trkMaptoArtPtr, std::unordered_map< const gar::rec::CaloHit*, art::Ptr<gar::rec::CaloHit> > &hitMaptoArtPtr)
57  {
58  //Clear the lists
59  ClearLists();
60 
61  //Loop over all tracks
62  for (std::vector< art::Ptr<gar::rec::Track> >::const_iterator iter = trkVector.begin(), iterEnd = trkVector.end(); iter != iterEnd; ++iter)
63  {
64  art::Ptr<gar::rec::Track> trkPtr = *iter;
65  const gar::rec::Track *track = trkPtr.get();
66  m_TrackVec.push_back( const_cast<gar::rec::Track *>(track) );
67  //update the track art ptr map
68  trkMaptoArtPtr.insert( std::make_pair(track, trkPtr) );
69  }
70  //Loop over all hits
71  for (std::vector< art::Ptr<gar::rec::CaloHit> >::const_iterator iter = hitVector.begin(), iterEnd = hitVector.end(); iter != iterEnd; ++iter)
72  {
73  art::Ptr<gar::rec::CaloHit> hitPtr = *iter;
74  const gar::rec::CaloHit *hit = hitPtr.get();
75  m_CaloHitVec.push_back( const_cast<gar::rec::CaloHit *>(hit) );
76  //update the hit art ptr map
77  hitMaptoArtPtr.insert( std::make_pair(hit, hitPtr) );
78  }
79 
80  return;
81  }
82 
83  //----------------------------------------------------------------------------
85  {
87 
89 
91 
92  XIndex< gar::rec::CaloHit, 280 > xIndex( -350 , 350. );
93 
95 
96  /* DEBLEO fGeo>GetECALEndcapStartX() returns 260 cm, which seems wrong;
97  and fGeo->GetECALEndcapOuterX() returns 374.4 cm, also seems wrong. */
99 
100  int nHit = 0;
101  nHit += m_CaloHitVec.size();
102 
103  // create a vector of generic hits from the collection applying an energy cut
104  addToGenericHitVec( h , m_CaloHitVec , eCut , xIndex ) ;
105 
106  // cluster the hits with a nearest neighbour condition
107  cluster( h.begin() , h.end() , std::back_inserter( cl ) , &dist ) ;
108 
109  MF_LOG_DEBUG("KNNClusterAlg::DoClustering()")
110  << " Passing " << h.size() << " of " << nHit
111  << " hits to clustering (E_cut: " << m_EnergyCut << ") "
112  << " found " << cl.size() << " clusters ";
113 
114  // create Clusters from the clustered GenericHits
115  std::transform( cl.begin(), cl.end(), std::back_inserter( clusterVector ), converter ) ;
116 
117  return;
118  }
119 
120  }// end namespace alg
121  }// end namespace rec
122 }// end namespace gar
rec
Definition: tracks.py:88
void cluster(In first, In last, Out result, Pred *pred)
Definition: NNClusters.h:41
std::string string
Definition: nybbler.cc:12
struct vector vector
void addToGenericHitVec(GenericHitVec< T > &v, CaloHitVec vec, Pred pred)
Definition: NNClusters.h:208
QAsciiDict< Entry > cl
gar::geo::GeometryCore const * fGeo
geometry information
Definition: KNNClusterAlg.h:61
T get(std::string const &key) const
Definition: ParameterSet.h:271
void PrepareAlgo(const std::vector< art::Ptr< gar::rec::Track > > &trkVector, const std::vector< art::Ptr< gar::rec::CaloHit > > &hitVector, std::unordered_map< const gar::rec::Track *, art::Ptr< gar::rec::Track > > &trkMaptoArtPtr, std::unordered_map< const gar::rec::CaloHit *, art::Ptr< gar::rec::CaloHit > > &hitMaptoArtPtr)
KNNClusterAlg(fhicl::ParameterSet const &pset)
Detector simulation of raw signals on wires.
float GetECALEndcapStartX() const
Definition: GeometryCore.h:975
General GArSoft Utilities.
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
#define MF_LOG_DEBUG(id)
void reconfigure(fhicl::ParameterSet const &pset)
T const * get() const
Definition: Ptr.h:149
art framework interface to geometry description