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 38 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 43 of file VtxMap.h.

43 : 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 44 of file VtxMap.h.

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

◆ VtxMap() [3/4]

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

Definition at line 45 of file VtxMap.h.

45 {};

◆ ~VtxMap()

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

Definition at line 46 of file VtxMap.h.

46 {};

◆ 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 340 of file VtxMap.h.

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

◆ 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 306 of file VtxMap.h.

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

◆ 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 292 of file VtxMap.h.

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

◆ 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 273 of file VtxMap.h.

274 {
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);
280 
281  KDPoint<double, 3> pos_tmp({x,y,z});
282  return pos_tmp;
283 }

◆ 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 418 of file VtxMap.h.

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

◆ 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 184 of file VtxMap.h.

184 { 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 356 of file VtxMap.h.

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

◆ 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 401 of file VtxMap.h.

402 {
403  Cluster<int> cls = m_dbscan.getClusters().at(icls);
404 
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() );
409  }
410  return v_tmp;
411 }

◆ 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 261 of file VtxMap.h.

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

◆ 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 217 of file VtxMap.h.

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

◆ 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 231 of file VtxMap.h.

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

◆ 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 247 of file VtxMap.h.

248 {
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;
252  return true;
253 }

◆ 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 167 of file VtxMap.h.

167 { 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 186 of file VtxMap.h.

186 { 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 172 of file VtxMap.h.

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

◆ unlock()

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

Unlock the map. Not recomended.

Definition at line 169 of file VtxMap.h.

169 { 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 196 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 197 of file VtxMap.h.

◆ m_dbscan

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

Definition at line 199 of file VtxMap.h.

◆ m_locked

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

Definition at line 198 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 195 of file VtxMap.h.


The documentation for this class was generated from the following file:
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:215
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
TrigVSI::VtxMap::m_locked
bool m_locked
Definition: VtxMap.h:198
hist_file_dump.d
d
Definition: hist_file_dump.py:142
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:217
TrigVSI::VtxMap::m_activeCells
std::unordered_set< int > m_activeCells
Definition: VtxMap.h:196
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:306
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:9
TrigVSI::VtxMap::getNeighborCells_
std::vector< int > getNeighborCells_(const int &, double)
Region query function to be passed to DBScan.
Definition: VtxMap.h:356
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:217
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:199
TrigVSI::VtxMap::m_mapHist
std::unique_ptr< TH3D > m_mapHist
Definition: VtxMap.h:195
TrigVSI::VtxMap::m_cellVtxDict
std::unordered_map< int, Cell > m_cellVtxDict
Definition: VtxMap.h:197
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
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:273