PandaRoot
PndLmdAlignStructs.h
Go to the documentation of this file.
1 /*
2  * PndLmdAlignStructs.h
3  *
4  * Header-only file to collect all structs used during SensorAlignment
5  *
6  * Created on: Jul 20, 2017
7  * Author: Roman Klasen, roklasen@uni-mainz.de or klasen@kph.uni-mainz.de
8  */
9 
10 #ifndef LMD_LMDSENSORALIGNMENT_PNDLMDALIGNSTRUCTS_H_
11 #define LMD_LMDSENSORALIGNMENT_PNDLMDALIGNSTRUCTS_H_
12 
13 #include "PndLmdHitPair.h"
14 
15 #include <TH1D.h>
16 #include <TCanvas.h>
17 
18 #include <cmath>
19 #include <iostream>
20 #include <string>
21 #include <vector>
22 
23 using std::cout;
24 using std::max;
25 using std::min;
26 using std::vector;
27 
28 // simple pixel hit, maybe not even necessary
29 struct pixelHit {
30  int _sensorId;
31  double _col;
32  double _row;
33 
34  double x() const { return _col; }
35 
36  pixelHit(int idVal, double colVal, double rowVal)
37  {
38  _sensorId = idVal;
39  _col = colVal;
40  _row = rowVal;
41  }
42 
44  {
45  _col = -1;
46  _row = -1;
47  _sensorId = -1;
48  }
49 };
50 
51 /*
52  * contains multiple pixelHits that form a cluster. most routines are for checking,
53  * if two separate pixelHits belong to the same cluster
54  */
55 struct pixelCluster {
56  int _sensorId;
57  double centerCol, centerRow; //,centerZ;
58  double clusterSize;
59  vector<pixelHit> pixelHits;
61 
63  {
64  _sensorId = -1;
65  centerCol = -1;
66  centerRow = -1; // centerZ=-1;
67  clusterSize = -1;
68  clusterReady = false;
69  }
70 
71  pixelCluster(const pixelHit &hit)
72  {
73  _sensorId = hit._sensorId;
74  pixelHits.push_back(hit);
75 
76  centerCol = -1;
77  centerRow = -1; // centerZ=-1;
78  clusterSize = -1;
79  clusterReady = false;
80  }
81 
83  {
84  _sensorId = copy._sensorId;
85  for (size_t i = 0; i < copy.pixelHits.size(); i++) {
86  pixelHits.push_back(copy.pixelHits[i]);
87  }
88 
89  centerCol = -1;
90  centerRow = -1; // centerZ=-1;
91  clusterSize = -1;
92  clusterReady = false;
93  }
94 
95  // checks, if two clusters lie DIRECTLY next to each other, that means any two pixels
96  // must be directly next to each other
97  // TODO: inefficient code, may be improved
99  {
100  // first, they must be on same sensor
101  if (_sensorId != other._sensorId) {
102  return false;
103  }
104  double _col1, _col2, _row1, _row2;
105  for (size_t i = 0; i < this->pixelHits.size(); i++) {
106  _col1 = this->pixelHits[i]._col;
107  _row1 = this->pixelHits[i]._row;
108  for (size_t j = 0; j < other.pixelHits.size(); j++) {
109  _col2 = other.pixelHits[j]._col;
110  _row2 = other.pixelHits[j]._row;
111  // check if neighboring, that means distance of pixels is smaller than 1.5 pixels
112  if ((_col2 - _col1) * (_col2 - _col1) + (_row2 - _row1) * (_row2 - _row1) < 2.25) {
113  return true;
114  }
115  }
116  }
117  return false;
118  }
119 
120  // merges other to this one
121  void merge(pixelCluster &other)
122  {
123  for (size_t i = 0; i < other.pixelHits.size(); i++) {
124  pixelHits.push_back(other.pixelHits[i]);
125  }
126  }
127 
129  {
130  centerCol = 0;
131  centerRow = 0;
132  for (size_t i = 0; i < pixelHits.size(); i++) {
133  centerCol += pixelHits[i]._col;
134  centerRow += pixelHits[i]._row;
135  }
136  centerCol /= pixelHits.size();
137  centerRow /= pixelHits.size();
138  double tempDistance;
139  // calculate size, go from corner to corner for clusters larger than 2 pixels
140  if (pixelHits.size() == 1) {
141  clusterSize = 1;
142  } else {
143  for (size_t i = 0; i < pixelHits.size(); i++) {
144  for (size_t j = i + 1; j < pixelHits.size(); j++) {
145  double deltax = (pixelHits[i]._col - pixelHits[j]._col);
146  if (deltax > 0) {
147  deltax = deltax + 1;
148  }
149  if (deltax < 0) {
150  deltax = deltax - 1;
151  }
152  double deltay = (pixelHits[i]._row - pixelHits[j]._row);
153  if (deltay > 0) {
154  deltay = deltay + 1;
155  }
156  if (deltay < 0) {
157  deltay = deltay - 1;
158  }
159  tempDistance = sqrt(deltax * deltax + deltay * deltay);
160  clusterSize = max(clusterSize, tempDistance);
161  }
162  }
163  }
164  clusterReady = true;
165  }
166 
167  void printPixels()
168  {
169  for (size_t i = 0; i < pixelHits.size(); i++) {
170  cout << "pixelHit x:" << pixelHits[i]._col << ", y:" << pixelHits[i]._row << " on sensor " << pixelHits[i]._sensorId << "\n";
171  }
172  }
173  void printCenter()
174  {
175  cout << "clusterCenter x:" << centerCol << ", y:" << centerRow << " on sensor " << _sensorId << ", contains " << pixelHits.size() << " pixels and is " << clusterSize
176  << " pixels in diameter."
177  << "\n";
178  }
179 };
180 
181 #endif /* LMD_LMDSENSORALIGNMENT_PNDLMDALIGNSTRUCTS_H_ */
pixelHit(int idVal, double colVal, double rowVal)
double x() const
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:28
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
unsigned int i
Definition: P4_F32vec4.h:21
pixelCluster(const pixelHit &hit)
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:24
bool isNeighbour(pixelCluster &other)
vector< pixelHit > pixelHits
void merge(pixelCluster &other)
pixelCluster(const pixelCluster &copy)