FairRoot/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::max;
24 using std::min;
25 using std::cout;
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 {
35  return _col;
36  }
37 
38  pixelHit(int idVal, double colVal, double rowVal) {
39  _sensorId = idVal;
40  _col = colVal;
41  _row = rowVal;
42  }
43 
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  _sensorId = -1;
64  centerCol = -1;
65  centerRow = -1; //centerZ=-1;
66  clusterSize = -1;
67  clusterReady = false;
68  }
69 
71  _sensorId = hit._sensorId;
72  pixelHits.push_back(hit);
73 
74  centerCol = -1;
75  centerRow = -1; //centerZ=-1;
76  clusterSize = -1;
77  clusterReady = false;
78  }
79 
80  pixelCluster(const pixelCluster &copy) {
81  _sensorId = copy._sensorId;
82  for (size_t i = 0; i < copy.pixelHits.size(); i++) {
83  pixelHits.push_back(copy.pixelHits[i]);
84  }
85 
86  centerCol = -1;
87  centerRow = -1; //centerZ=-1;
88  clusterSize = -1;
89  clusterReady = false;
90  }
91 
92  //checks, if two clusters lie DIRECTLY next to each other, that means any two pixels
93  //must be directly next to each other
94  //TODO: inefficient code, may be improved
95  bool isNeighbour(pixelCluster &other) {
96  //first, they must be on same sensor
97  if (_sensorId != other._sensorId) {
98  return false;
99  }
100  double _col1, _col2, _row1, _row2;
101  for (size_t i = 0; i < this->pixelHits.size(); i++) {
102  _col1 = this->pixelHits[i]._col;
103  _row1 = this->pixelHits[i]._row;
104  for (size_t j = 0; j < other.pixelHits.size(); j++) {
105  _col2 = other.pixelHits[j]._col;
106  _row2 = other.pixelHits[j]._row;
107  //check if neighboring, that means distance of pixels is smaller than 1.5 pixels
108  if ((_col2 - _col1) * (_col2 - _col1) + (_row2 - _row1) * (_row2 - _row1) < 2.25) {
109  return true;
110  }
111  }
112  }
113  return false;
114  }
115 
116  //merges other to this one
117  void merge(pixelCluster &other) {
118  for (size_t i = 0; i < other.pixelHits.size(); i++) {
119  pixelHits.push_back(other.pixelHits[i]);
120  }
121  }
122 
124  centerCol = 0;
125  centerRow = 0;
126  for (size_t i = 0; i < pixelHits.size(); i++) {
127  centerCol += pixelHits[i]._col;
128  centerRow += pixelHits[i]._row;
129  }
130  centerCol /= pixelHits.size();
131  centerRow /= pixelHits.size();
132  double tempDistance;
133  //calculate size, go from corner to corner for clusters larger than 2 pixels
134  if (pixelHits.size() == 1) {
135  clusterSize = 1;
136  }
137  else {
138  for (size_t i = 0; i < pixelHits.size(); i++) {
139  for (size_t j = i + 1; j < pixelHits.size(); j++) {
140  double deltax = (pixelHits[i]._col - pixelHits[j]._col);
141  if (deltax > 0) {
142  deltax = deltax + 1;
143  }
144  if (deltax < 0) {
145  deltax = deltax - 1;
146  }
147  double deltay = (pixelHits[i]._row - pixelHits[j]._row);
148  if (deltay > 0) {
149  deltay = deltay + 1;
150  }
151  if (deltay < 0) {
152  deltay = deltay - 1;
153  }
154  tempDistance = sqrt(deltax * deltax + deltay * deltay);
155  clusterSize = max(clusterSize, tempDistance);
156  }
157  }
158  }
159  clusterReady = true;
160  }
161 
162  void printPixels() {
163  for (size_t i = 0; i < pixelHits.size(); i++) {
164  cout << "pixelHit x:" << pixelHits[i]._col << ", y:" << pixelHits[i]._row << " on sensor "
165  << pixelHits[i]._sensorId << "\n";
166  }
167  }
168  void printCenter() {
169  cout << "clusterCenter x:" << centerCol << ", y:" << centerRow << " on sensor " << _sensorId
170  << ", contains " << pixelHits.size() << " pixels and is " << clusterSize
171  << " pixels in diameter." << "\n";
172  }
173 };
174 
175 #endif /* LMD_LMDSENSORALIGNMENT_PNDLMDALIGNSTRUCTS_H_ */
pixelHit(int idVal, double colVal, double rowVal)
Int_t i
Definition: run_full.C:25
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
pixelCluster(const pixelHit &hit)
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
bool isNeighbour(pixelCluster &other)
double x() const
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Definition: hit.C:1
vector< pixelHit > pixelHits
void merge(pixelCluster &other)
pixelCluster(const pixelCluster &copy)