ATLAS Offline Software
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
TrigVSI::VtxMap< WrkVrt, Cord > Class Template Reference

The vertex map class to be used to find multi-track vertices. More...

#include <VtxMap.h>

Collaboration diagram for TrigVSI::VtxMap< WrkVrt, Cord >:

Classes

class  Cell
 The class of a cell in 3D histogram. More...
 
class  CellCluster
 Stores the result of vertex clustering performed in VtxMap. More...
 

Public Member Functions

 VtxMap (TH3D *ptr)
 
 VtxMap (std::unique_ptr< TH3D > &&uptr)
 
 VtxMap ()
 
 ~VtxMap ()
 
VtxMapoperator= (VtxMap &&)=default
 Move assignment operator. More...
 
 VtxMap (VtxMap &&)=default
 
void Fill (const WrkVrt *)
 Fill vertex map with vertex from its pointer. More...
 
bool isInMapVolume (const KDPoint< double, 3 > &) const
 Check if the point is inside the map volume. More...
 
bool isInMapVolume (double, double, double) const
 Check if the point is inside the map volume. More...
 
bool isInMapVolume (int, int, int) const
 Check if the point is inside the map volume. More...
 
KDPoint< double, 3 > getBinCenter (int) const
 Get bin center position in KDPoint with specified coordinate. More...
 
int getVtxNum (double, double, double) const
 Count vertex number in the cell at the given position. More...
 
void lock ()
 Lock the map to prevent adding vertex after clustering. More...
 
void unlock ()
 Unlock the map. Not recomended. More...
 
void Reset ()
 Reset vertex map hist, cell list and vertex list. More...
 
void ClusterizeCells (double, size_t)
 Generate clusters. More...
 
std::vector< Cluster< int > > getClustersBin () const
 Return a copy of list of clusters consist of bin ID. More...
 
size_t nClusters () const
 Return the number of the clusters. More...
 
CellCluster getCluster (size_t)
 Retrieve clustering result as CellCluster object. More...
 
std::vector< const WrkVrt * > getVtxInCluster (size_t)
 Retrieve list of vertices in i-th cluster. More...
 

Private Member Functions

void Fill (double, double, double)
 Private function to fill vertex map from position. More...
 
std::vector< int > getNeighborCells_ (const int &, double)
 Region query function to be passed to DBScan. More...
 

Private Attributes

std::unique_ptr< TH3D > m_mapHist
 
std::unordered_set< int > m_activeCells
 
std::unordered_map< int, Cellm_cellVtxDict
 
bool m_locked = false
 
DBScan< int > m_dbscan
 

Detailed Description

template<typename WrkVrt, typename Cord>
class TrigVSI::VtxMap< WrkVrt, Cord >

The vertex map class to be used to find multi-track vertices.

First, Fill() vertex map and lock() it. Once the map is locked, you can't Fill() it anymore. Then execute ClusterizeCells() to perform clustering. This can't be executed until the map is locked. You can read the result by retrieving cell clusters through getCluster().

Definition at line 40 of file VtxMap.h.

Constructor & Destructor Documentation

◆ VtxMap() [1/4]

template<typename WrkVrt , typename Cord >
TrigVSI::VtxMap< WrkVrt, Cord >::VtxMap ( TH3D *  ptr)
inline

Definition at line 45 of file VtxMap.h.

45 : m_mapHist( std::unique_ptr<TH3D>(ptr) ){};

◆ VtxMap() [2/4]

template<typename WrkVrt , typename Cord >
TrigVSI::VtxMap< WrkVrt, Cord >::VtxMap ( std::unique_ptr< TH3D > &&  uptr)
inline

Definition at line 46 of file VtxMap.h.

46 : m_mapHist( std::move(uptr) ){};

◆ VtxMap() [3/4]

template<typename WrkVrt , typename Cord >
TrigVSI::VtxMap< WrkVrt, Cord >::VtxMap ( )
inline

Definition at line 47 of file VtxMap.h.

47 {};

◆ ~VtxMap()

template<typename WrkVrt , typename Cord >
TrigVSI::VtxMap< WrkVrt, Cord >::~VtxMap ( )
inline

Definition at line 48 of file VtxMap.h.

48 {};

◆ VtxMap() [4/4]

template<typename WrkVrt , typename Cord >
TrigVSI::VtxMap< WrkVrt, Cord >::VtxMap ( VtxMap< WrkVrt, Cord > &&  )
default

Member Function Documentation

◆ ClusterizeCells()

template<typename WrkVrt , typename Cord >
void TrigVSI::VtxMap< WrkVrt, Cord >::ClusterizeCells ( double  eps,
size_t  minN 
)

Generate clusters.

This command locks the map so you cannot add any additional vertex after this process. If you need to add some, Reset() or unlock() and execute ClusterizeCells() again.

Parameters
[in]epsRadius to search neighbor points.
[in]minNLower threshold to determine the cell as a core.

Definition at line 342 of file VtxMap.h.

343 {
344  m_locked = true;
345  DBScan<int>::RegionFunc region_query = [this](const int& glob_bin, double eps)
346  {
347  return getNeighborCells_(glob_bin, eps);
348  };
349  m_dbscan = DBScan<int>(m_activeCells, region_query);
350  m_dbscan.clusterize(eps, minN);
351 }

◆ Fill() [1/2]

template<typename WrkVrt , typename Cord >
void TrigVSI::VtxMap< WrkVrt, Cord >::Fill ( const WrkVrt *  vtx_ptr)

Fill vertex map with vertex from its pointer.

Do nothing when the map is locked.

Parameters
[in]vtx_ptrVertex to be added to the vertex map.

Definition at line 308 of file VtxMap.h.

309 {
310  if (m_locked) return;
311 
312  // Get position of vertex with projection to map region.
313  TVector3 vec( vtx_ptr->x(), vtx_ptr->y(), vtx_ptr->z() );
314  KDPoint<double,3> pos = Cord::Proj( Cord::XYZtoX123(vec) );
315  double x = pos[0];
316  double y = pos[1];
317  double z = pos[2];
318 
319  if ( !isInMapVolume(x,y,z) ) return;
320 
321  Fill(x,y,z);
322 
323  size_t ibin = m_mapHist->FindFixBin(x, y, z);
324  auto cell_itr = m_cellVtxDict.find( ibin );
325  if ( cell_itr != m_cellVtxDict.end() && cell_itr->second.getId() == static_cast<int>(ibin) ) {
326  cell_itr->second.emplace_back( vtx_ptr );
327  }
328  else {
329  m_cellVtxDict.emplace( ibin, Cell(ibin, getBinCenter(ibin), vtx_ptr) );
330  }
331 }

◆ Fill() [2/2]

template<typename WrkVrt , typename Cord >
void TrigVSI::VtxMap< WrkVrt, Cord >::Fill ( double  x,
double  y,
double  z 
)
private

Private function to fill vertex map from position.

Takes the position in specified coordinate as inputs.

Definition at line 294 of file VtxMap.h.

295 {
296  if (m_locked) return;
297  m_mapHist->Fill(x, y, z);
298  m_activeCells.emplace( m_mapHist->FindFixBin(x, y, z) );
299 }

◆ getBinCenter()

template<typename WrkVrt , typename Cord >
KDPoint< double, 3 > TrigVSI::VtxMap< WrkVrt, Cord >::getBinCenter ( int  ibin) const
inline

Get bin center position in KDPoint with specified coordinate.

Definition at line 275 of file VtxMap.h.

276 {
277  int xbin; int ybin; int zbin;
278  m_mapHist->GetBinXYZ(ibin, xbin, ybin, zbin);
279  double x = m_mapHist->GetXaxis()->GetBinCenter(xbin);
280  double y = m_mapHist->GetYaxis()->GetBinCenter(ybin);
281  double z = m_mapHist->GetZaxis()->GetBinCenter(zbin);
282 
283  KDPoint<double, 3> pos_tmp({x,y,z});
284  return pos_tmp;
285 }

◆ getCluster()

template<typename WrkVrt , typename Cord >
VtxMap< WrkVrt, Cord >::CellCluster TrigVSI::VtxMap< WrkVrt, Cord >::getCluster ( size_t  icls)

Retrieve clustering result as CellCluster object.

Definition at line 420 of file VtxMap.h.

421 {
422  const Cluster<int>& cls = m_dbscan.getCluster(icls);
423  std::vector<Cell*> v_tmp;
424 
425  std::vector<int> cell_ids = cls.getPoints();
426  for (const auto ibin : cell_ids) {
427  Cell& cell = m_cellVtxDict[ibin];
428  if ( ibin != cell.getId() ) continue;
429  v_tmp.emplace_back( &cell );
430  }
431  VtxMap<WrkVrt,Cord>::CellCluster cls_tmp( std::move(v_tmp) );
432  return cls_tmp;
433 }

◆ getClustersBin()

template<typename WrkVrt , typename Cord >
std::vector<Cluster<int> > TrigVSI::VtxMap< WrkVrt, Cord >::getClustersBin ( ) const
inline

Return a copy of list of clusters consist of bin ID.

Definition at line 186 of file VtxMap.h.

186 { return m_dbscan.getClusters(); };

◆ getNeighborCells_()

template<typename WrkVrt , typename Cord >
std::vector< int > TrigVSI::VtxMap< WrkVrt, Cord >::getNeighborCells_ ( const int &  glob_bin,
double  eps 
)
private

Region query function to be passed to DBScan.

Definition at line 358 of file VtxMap.h.

359 {
360  std::vector<int> tmp;
361  int d = static_cast<int>(eps);
362 
363  int binx = 0;
364  int biny = 0;
365  int binz = 0;
366  m_mapHist->GetBinXYZ(glob_bin, binx, biny, binz);
367 
368  KDPoint<int,3> v_ibin;
369 
370  if ( !(isInMapVolume(binx, biny, binz)) ) return tmp;
371 
372  for (int ix = binx - d; ix <= binx + d; ix++) {
373  for (int iy = biny - d; iy <= biny + d; iy++) {
374  for (int iz = binz - d; iz <= binz + d; iz++) {
375  //
376  v_ibin[0] = ix; v_ibin[1] = iy; v_ibin[2] = iz;
377 
378  // Convert coordinate with projection function
379  v_ibin = Cord::ProjBin(v_ibin, m_mapHist);
380 
381  // If current cell is self, skip it.
382  if ( v_ibin[0] == binx && v_ibin[1] == biny && v_ibin[2] == binz ) continue;
383 
384  // If cerrent cell is not in map volme, skip it.
385  if ( !(isInMapVolume(v_ibin[0], v_ibin[1], v_ibin[2])) ) continue;
386 
387  // If there is no entry in current cell, skip it.
388  if ( m_mapHist->GetBinContent(m_mapHist->GetBin(v_ibin[0], v_ibin[1], v_ibin[2])) < 1. ) continue;
389  tmp.emplace_back(m_mapHist->GetBin(v_ibin[0], v_ibin[1], v_ibin[2]));
390  //
391  }
392  }
393  }
394  //
395  return tmp;
396 }

◆ getVtxInCluster()

template<typename WrkVrt , typename Cord >
std::vector< const WrkVrt * > TrigVSI::VtxMap< WrkVrt, Cord >::getVtxInCluster ( size_t  icls)

Retrieve list of vertices in i-th cluster.

Definition at line 403 of file VtxMap.h.

404 {
405  Cluster<int> cls = m_dbscan.getClusters().at(icls);
406 
407  std::vector<const WrkVrt*> v_tmp;
408  for (const auto& ibin : cls.Points()) {
409  std::vector<const WrkVrt*> v_vtx = m_cellVtxDict[ibin].getVtxList();
410  v_tmp.insert( v_tmp.end(), v_vtx.begin(), v_vtx.end() );
411  }
412  return v_tmp;
413 }

◆ getVtxNum()

template<typename WrkVrt , typename Cord >
int TrigVSI::VtxMap< WrkVrt, Cord >::getVtxNum ( double  x,
double  y,
double  z 
) const
inline

Count vertex number in the cell at the given position.

Return -1 when given position is out from the range ( Without considering projection).

Definition at line 263 of file VtxMap.h.

264 {
265  if ( !isInMapVolume(x, y, z) ) return -1;
266  int ibin = m_mapHist->FindFixBin(x, y, z);
267  return m_mapHist->GetBinContent(ibin);
268 }

◆ isInMapVolume() [1/3]

template<typename WrkVrt , typename Cord >
bool TrigVSI::VtxMap< WrkVrt, Cord >::isInMapVolume ( const KDPoint< double, 3 > &  point) const
inline

Check if the point is inside the map volume.

Parameters
[in]pointKDPoint to check.

This check does not consider the projection.

Definition at line 219 of file VtxMap.h.

220 {
221  return VtxMap<WrkVrt,Cord>::isInMapVolume(point[0], point[1], point[2]);
222 }

◆ isInMapVolume() [2/3]

template<typename WrkVrt , typename Cord >
bool TrigVSI::VtxMap< WrkVrt, Cord >::isInMapVolume ( double  x1,
double  x2,
double  x3 
) const
inline

Check if the point is inside the map volume.

Parameters
[in]x1x1 component in specified coordinate.
[in]x2x2 component in specified coordinate.
[in]x3x3 component in specified coordinate.

This check does not consider the projection.

Definition at line 233 of file VtxMap.h.

234 {
235  if ( m_mapHist->GetXaxis()->FindFixBin(x1) < 1 || m_mapHist->GetXaxis()->FindFixBin(x1) > m_mapHist->GetNbinsX() ) return false;
236  if ( m_mapHist->GetYaxis()->FindFixBin(x2) < 1 || m_mapHist->GetYaxis()->FindFixBin(x2) > m_mapHist->GetNbinsY() ) return false;
237  if ( m_mapHist->GetZaxis()->FindFixBin(x3) < 1 || m_mapHist->GetZaxis()->FindFixBin(x3) > m_mapHist->GetNbinsZ() ) return false;
238  return true;
239 }

◆ isInMapVolume() [3/3]

template<typename WrkVrt , typename Cord >
bool TrigVSI::VtxMap< WrkVrt, Cord >::isInMapVolume ( int  ibinx,
int  ibiny,
int  ibinz 
) const
inline

Check if the point is inside the map volume.

Parameters
[in]ibinxibin in x1 axis.
[in]ibinyibin in x2 axis.
[in]ibinzibin in x3 axis.

Definition at line 249 of file VtxMap.h.

250 {
251  if ( ibinx < 1 || ibinx > m_mapHist->GetNbinsX() ) return false;
252  if ( ibiny < 1 || ibiny > m_mapHist->GetNbinsY() ) return false;
253  if ( ibinz < 1 || ibinz > m_mapHist->GetNbinsZ() ) return false;
254  return true;
255 }

◆ lock()

template<typename WrkVrt , typename Cord >
void TrigVSI::VtxMap< WrkVrt, Cord >::lock ( )
inline

Lock the map to prevent adding vertex after clustering.

Definition at line 169 of file VtxMap.h.

169 { m_locked = true; };

◆ nClusters()

template<typename WrkVrt , typename Cord >
size_t TrigVSI::VtxMap< WrkVrt, Cord >::nClusters ( ) const
inline

Return the number of the clusters.

Definition at line 188 of file VtxMap.h.

188 { return m_dbscan.nClusters(); };

◆ operator=()

template<typename WrkVrt , typename Cord >
VtxMap& TrigVSI::VtxMap< WrkVrt, Cord >::operator= ( VtxMap< WrkVrt, Cord > &&  )
default

Move assignment operator.

◆ Reset()

template<typename WrkVrt , typename Cord >
void TrigVSI::VtxMap< WrkVrt, Cord >::Reset ( )
inline

Reset vertex map hist, cell list and vertex list.

Definition at line 174 of file VtxMap.h.

175  {
176  m_mapHist->Reset();
177  m_activeCells.clear();
178  m_cellVtxDict.clear();
179  m_locked = false;
180  m_dbscan = DBScan<int>();
181  }

◆ unlock()

template<typename WrkVrt , typename Cord >
void TrigVSI::VtxMap< WrkVrt, Cord >::unlock ( )
inline

Unlock the map. Not recomended.

Definition at line 171 of file VtxMap.h.

171 { m_locked = false; };

Member Data Documentation

◆ m_activeCells

template<typename WrkVrt , typename Cord >
std::unordered_set<int> TrigVSI::VtxMap< WrkVrt, Cord >::m_activeCells
private

Definition at line 198 of file VtxMap.h.

◆ m_cellVtxDict

template<typename WrkVrt , typename Cord >
std::unordered_map<int, Cell> TrigVSI::VtxMap< WrkVrt, Cord >::m_cellVtxDict
private

Definition at line 199 of file VtxMap.h.

◆ m_dbscan

template<typename WrkVrt , typename Cord >
DBScan<int> TrigVSI::VtxMap< WrkVrt, Cord >::m_dbscan
private

Definition at line 201 of file VtxMap.h.

◆ m_locked

template<typename WrkVrt , typename Cord >
bool TrigVSI::VtxMap< WrkVrt, Cord >::m_locked = false
private

Definition at line 200 of file VtxMap.h.

◆ m_mapHist

template<typename WrkVrt , typename Cord >
std::unique_ptr<TH3D> TrigVSI::VtxMap< WrkVrt, Cord >::m_mapHist
private

Definition at line 197 of file VtxMap.h.


The documentation for this class was generated from the following file:
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
TrigVSI::VtxMap::m_locked
bool m_locked
Definition: VtxMap.h:200
hist_file_dump.d
d
Definition: hist_file_dump.py:137
TrigVSI::DBScan::getClusters
std::vector< Cluster< pointType > > getClusters() const
Retrun the list of clusters along with noise clusters.
Definition: DBScan.h:107
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
TrigVSI::VtxMap::m_activeCells
std::unordered_set< int > m_activeCells
Definition: VtxMap.h:198
TrigVSI::DBScan< int >::RegionFunc
std::function< std::vector< int >(const int &, double)> RegionFunc
Function type for region query function.
Definition: DBScan.h:45
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
TrigVSI::VtxMap::Fill
void Fill(const WrkVrt *)
Fill vertex map with vertex from its pointer.
Definition: VtxMap.h:308
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
TrigVSI::VtxMap::getNeighborCells_
std::vector< int > getNeighborCells_(const int &, double)
Region query function to be passed to DBScan.
Definition: VtxMap.h:358
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
x
#define x
TrigVSI::VtxMap::isInMapVolume
bool isInMapVolume(const KDPoint< double, 3 > &) const
Check if the point is inside the map volume.
Definition: VtxMap.h:219
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
z
#define z
TrigVSI::DBScan::getCluster
const Cluster< pointType > & getCluster(size_t) const
Retrieve cluster.
Definition: DBScan.h:128
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
TrigVSI::VtxMap::m_dbscan
DBScan< int > m_dbscan
Definition: VtxMap.h:201
TrigVSI::VtxMap::m_mapHist
std::unique_ptr< TH3D > m_mapHist
Definition: VtxMap.h:197
TrigVSI::VtxMap::m_cellVtxDict
std::unordered_map< int, Cell > m_cellVtxDict
Definition: VtxMap.h:199
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
y
#define y
TrigVSI::DBScan::nClusters
size_t nClusters() const
Definition: DBScan.h:54
TrigVSI::DBScan::clusterize
void clusterize(double, size_t)
Generate clusters with DBSCAN algorithim.
Definition: DBScan.h:142
TrigVSI::VtxMap::getBinCenter
KDPoint< double, 3 > getBinCenter(int) const
Get bin center position in KDPoint with specified coordinate.
Definition: VtxMap.h:275