LDMX Software
trigger::ClusterGeometry Class Reference

Public Member Functions

int getId (int cell_id, int module_id)
 
float getDist (int id1, int id2)
 
void addTp (int tid, int cell_id, int module_id, float x, float y)
 
void addNeighbor (int id1, int id2)
 
bool checkNeighbor (int id1, int id2)
 
void initialize ()
 

Public Attributes

bool is_initialized_ = false
 
std::map< std::pair< int, int >, int > reverse_id_map_
 
std::map< int, std::pair< int, int > > id_map_
 
std::map< int, std::pair< float, float > > positions_
 
std::map< std::pair< int, int >, float > distances_
 
std::map< int, std::vector< int > > neighbors_
 

Detailed Description

Definition at line 18 of file IdealClusterBuilder.h.

Member Function Documentation

◆ addNeighbor()

void trigger::ClusterGeometry::addNeighbor ( int id1,
int id2 )

Definition at line 11 of file IdealClusterBuilder.cxx.

11 {
12 if (neighbors_.count(id1))
13 neighbors_[id1].push_back(id2);
14 else
15 neighbors_[id1] = {id2};
16 if (neighbors_.count(id2))
17 neighbors_[id2].push_back(id1);
18 else
19 neighbors_[id2] = {id1};
20 // cout << "Nbs: " << id1 << " " << id2 << endl;
21}

◆ addTp()

void trigger::ClusterGeometry::addTp ( int tid,
int cell_id,
int module_id,
float x,
float y )

Definition at line 5 of file IdealClusterBuilder.cxx.

6 {
7 id_map_[tid] = std::make_pair(cell_id, module_id);
8 reverse_id_map_[std::make_pair(cell_id, module_id)] = tid;
9 positions_[tid] = std::make_pair(x, y);
10}

◆ checkNeighbor()

bool trigger::ClusterGeometry::checkNeighbor ( int id1,
int id2 )

Definition at line 22 of file IdealClusterBuilder.cxx.

22 {
23 // true if neighbors
24 auto &ns = neighbors_[id1];
25 return std::find(ns.begin(), ns.end(), id2) != ns.end();
26}

◆ getDist()

float trigger::ClusterGeometry::getDist ( int id1,
int id2 )
inline

Definition at line 38 of file IdealClusterBuilder.h.

38 {
39 return distances_[std::make_pair(id1, id2)];
40 }

◆ getId()

int trigger::ClusterGeometry::getId ( int cell_id,
int module_id )
inline

Definition at line 35 of file IdealClusterBuilder.h.

35 {
36 return reverse_id_map_[std::make_pair(cell_id, module_id)];
37 }

◆ initialize()

void trigger::ClusterGeometry::initialize ( )

Definition at line 27 of file IdealClusterBuilder.cxx.

27 {
28 // calculate pairwise distances
29 distances_.clear();
30 for (auto pair1 = id_map_.begin(); pair1 != id_map_.end(); pair1++) {
31 for (auto pair2 = pair1; pair2 != id_map_.end(); pair2++) {
32 if (pair1 == pair2) continue;
33 auto &id1 = pair1->first;
34 auto &id2 = pair2->first;
35 auto &xy1 = positions_[id1];
36 auto &xy2 = positions_[id2];
37 float d =
38 sqrt(pow(xy1.first - xy2.first, 2) + pow(xy1.second - xy2.second, 2));
39 distances_[std::make_pair(id1, id2)] = d;
40 distances_[std::make_pair(id2, id1)] = d;
41 }
42 }
43 // find neighbors
44 float n_dist = 1.8 * getDist(getId(0, 0), getId(1, 0));
45 for (auto pair1 = id_map_.begin(); pair1 != id_map_.end(); pair1++) {
46 for (auto pair2 = pair1; pair2 != id_map_.end(); pair2++) {
47 if (pair1 == pair2) continue;
48 if (getDist(pair1->first, pair2->first) < n_dist)
49 addNeighbor(pair1->first, pair2->first);
50 }
51 }
52 is_initialized_ = true;
53}

Member Data Documentation

◆ distances_

std::map<std::pair<int, int>, float> trigger::ClusterGeometry::distances_

Definition at line 30 of file IdealClusterBuilder.h.

◆ id_map_

std::map<int, std::pair<int, int> > trigger::ClusterGeometry::id_map_

Definition at line 24 of file IdealClusterBuilder.h.

◆ is_initialized_

bool trigger::ClusterGeometry::is_initialized_ = false

Definition at line 20 of file IdealClusterBuilder.h.

◆ neighbors_

std::map<int, std::vector<int> > trigger::ClusterGeometry::neighbors_

Definition at line 33 of file IdealClusterBuilder.h.

◆ positions_

std::map<int, std::pair<float, float> > trigger::ClusterGeometry::positions_

Definition at line 27 of file IdealClusterBuilder.h.

◆ reverse_id_map_

std::map<std::pair<int, int>, int> trigger::ClusterGeometry::reverse_id_map_

Definition at line 23 of file IdealClusterBuilder.h.


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