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