4#ifndef TRIGTOOLS_TRIG_VSI_VTXMAP
5#define TRIGTOOLS_TRIG_VSI_VTXMAP
21#include <unordered_set>
37template<
typename WrkVrt,
typename Cord>
39 static_assert(std::is_base_of<TrigVSI::IWrkVrt, WrkVrt>::value,
"WrkVrt must be derived from IWrkVrt.");
106 for (
auto& cell_ptr : v ) n_vtx += cell_ptr->
nVtx();
107 std::vector<const WrkVrt*> tmp_vtx_cls;
108 tmp_vtx_cls.reserve(n_vtx);
111 TVector3 tmp_vec(0.,0.,0.);
112 for (
auto& cell_ptr : v ) {
113 std::vector<const WrkVrt*> tmp_vtx_cell = cell_ptr->getVtxList();
114 tmp_vtx_cls.insert( tmp_vtx_cls.end(), tmp_vtx_cell.begin(), tmp_vtx_cell.end() );
116 tmp_vec += cell_ptr->getWeight() * cell_ptr->getPosVect();
117 w += cell_ptr->getWeight();
157 void Fill(
const WrkVrt*);
164 inline int getVtxNum(
double,
double,
double)
const;
204 void Fill(
double,
double,
double);
216template<
typename WrkVrt,
typename Cord>
230template<
typename WrkVrt,
typename Cord>
246template<
typename WrkVrt,
typename Cord>
249 if ( ibinx < 1 || ibinx >
m_mapHist->GetNbinsX() )
return false;
250 if ( ibiny < 1 || ibiny >
m_mapHist->GetNbinsY() )
return false;
251 if ( ibinz < 1 || ibinz >
m_mapHist->GetNbinsZ() )
return false;
260template<
typename WrkVrt,
typename Cord>
272template<
typename WrkVrt,
typename Cord>
275 int xbin;
int ybin;
int zbin;
276 m_mapHist->GetBinXYZ(ibin, xbin, ybin, zbin);
277 double x =
m_mapHist->GetXaxis()->GetBinCenter(xbin);
278 double y =
m_mapHist->GetYaxis()->GetBinCenter(ybin);
279 double z =
m_mapHist->GetZaxis()->GetBinCenter(zbin);
291template<
typename WrkVrt,
typename Cord>
305template<
typename WrkVrt,
typename Cord>
311 TVector3
vec( vtx_ptr->x(), vtx_ptr->y(), vtx_ptr->z() );
323 if ( cell_itr !=
m_cellVtxDict.end() && cell_itr->second.getId() ==
static_cast<int>(ibin) ) {
324 cell_itr->second.emplace_back( vtx_ptr );
339template<
typename WrkVrt,
typename Cord>
355template<
typename WrkVrt,
typename Cord>
358 std::vector<int> tmp;
359 int d =
static_cast<int>(eps);
364 m_mapHist->GetBinXYZ(glob_bin, binx, biny, binz);
370 for (
int ix = binx - d; ix <= binx + d; ix++) {
371 for (
int iy = biny - d; iy <= biny + d; iy++) {
372 for (
int iz = binz - d; iz <= binz + d; iz++) {
374 v_ibin[0] = ix; v_ibin[1] = iy; v_ibin[2] = iz;
377 v_ibin = Cord::ProjBin(v_ibin,
m_mapHist);
380 if ( v_ibin[0] == binx && v_ibin[1] == biny && v_ibin[2] == binz )
continue;
383 if ( !(
isInMapVolume(v_ibin[0], v_ibin[1], v_ibin[2])) )
continue;
386 if (
m_mapHist->GetBinContent(
m_mapHist->GetBin(v_ibin[0], v_ibin[1], v_ibin[2])) < 1. )
continue;
387 tmp.emplace_back(
m_mapHist->GetBin(v_ibin[0], v_ibin[1], v_ibin[2]));
400template<
typename WrkVrt,
typename Cord>
405 std::vector<const WrkVrt*> v_tmp;
406 for (
const auto& ibin : cls.Points()) {
407 std::vector<const WrkVrt*> v_vtx =
m_cellVtxDict[ibin].getVtxList();
408 v_tmp.insert( v_tmp.end(), v_vtx.begin(), v_vtx.end() );
417template<
typename WrkVrt,
typename Cord>
421 std::vector<Cell*> v_tmp;
423 std::vector<int> cell_ids = cls.getPoints();
424 for (
const auto ibin : cell_ids) {
426 if ( ibin != cell.getId() )
continue;
427 v_tmp.emplace_back( &cell );
std::vector< size_t > vec
Clustering algorithm for vertex merging based on DBSCAN.
point classes for clustering
Class for operating DBSCAN clustering.
std::function< std::vector< pointType >(const pointType &, double)> RegionFunc
Function type for region query function.
Class for k-dimensional point.
Stores the result of vertex clustering performed in VtxMap.
KDPoint< double, 3 > m_posAvr
const KDPoint< double, 3 > & PosCoord() const
CellCluster(std::vector< Cell * > &&v)
Constructor.
void emplace_back(const WrkVrt *)=delete
Vertex cannot be added after initialization.
The class of a cell in 3D histogram.
Cell(size_t id, const KDPoint< double, 3 > &p)
Cell(size_t id, const KDPoint< double, 3 > &p, std::vector< const WrkVrt * > &&v)
TVector3 getPosVect() const
Return center position in TVector3.
KDPoint< double, 3 > m_pos
Cell(size_t id, const KDPoint< double, 3 > &p, std::vector< const WrkVrt * > &v)
Constructor.
KDPoint< double, 3 > getPosPoint()
Return center position as a KDPoint in specified coordinate.
Cell(size_t id, const KDPoint< double, 3 > &p, const WrkVrt *vtx_ptr)
The vertex map class to be used to find multi-track vertices.
size_t nClusters() const
Return the number of the clusters.
std::unique_ptr< TH3D > m_mapHist
void ClusterizeCells(double, size_t)
Generate clusters.
std::vector< const WrkVrt * > getVtxInCluster(size_t)
Retrieve list of vertices in i-th cluster.
std::unordered_map< int, Cell > m_cellVtxDict
VtxMap(std::unique_ptr< TH3D > &&uptr)
void Reset()
Reset vertex map hist, cell list and vertex list.
int getVtxNum(double, double, double) const
Count vertex number in the cell at the given position.
KDPoint< double, 3 > getBinCenter(int) const
Get bin center position in KDPoint with specified coordinate.
VtxMap & operator=(VtxMap &&)=default
Move assignment operator.
CellCluster getCluster(size_t)
Retrieve clustering result as CellCluster object.
std::vector< Cluster< int > > getClustersBin() const
Return a copy of list of clusters consist of bin ID.
std::vector< int > getNeighborCells_(const int &, double)
Region query function to be passed to DBScan.
void unlock()
Unlock the map. Not recomended.
void lock()
Lock the map to prevent adding vertex after clustering.
bool isInMapVolume(const KDPoint< double, 3 > &) const
Check if the point is inside the map volume.
VtxMap(VtxMap &&)=default
void Fill(const WrkVrt *)
Fill vertex map with vertex from its pointer.
std::unordered_set< int > m_activeCells
std::vector< const WrkVrt * > m_vtxLists
VtxPack(std::vector< const WrkVrt * > &v)
Constructor.
size_t nVtx()
Return the number of vertices.
void updateLists()
Update set of tracks and incompatible track pair list.
double getWeight()
Return the weight of the container.
static constexpr bool value