Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TpcPrototypeCluster.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TpcPrototypeCluster.cc
1 
7 #include "TpcPrototypeCluster.h"
8 
9 #include <cmath>
10 #include <utility> // for swap
11 
12 namespace
13 {
14 // square convenience function
15 template <class T>
16 inline constexpr T square(const T& x)
17 {
18  return x * x;
19 }
20 
21 // get unique index in cov. matrix array from i and j
22 inline unsigned int covarIndex(unsigned int i, unsigned int j)
23 {
24  if (i > j) std::swap(i, j);
25  return i + 1 + (j + 1) * (j) / 2 - 1;
26 }
27 
28 // rotate size or covariant matrix to polar coordinates and return the phi component
29 template <float (TpcPrototypeCluster::*accessor)(unsigned int, unsigned int) const>
30 float rotate(const TpcPrototypeCluster* cluster)
31 {
32  const auto phi = -std::atan2(cluster->getY(), cluster->getX());
33  const auto cosphi = std::cos(phi);
34  const auto sinphi = std::sin(phi);
35 
36  return square(sinphi) * (cluster->*accessor)(0, 0) +
37  square(cosphi) * (cluster->*accessor)(1, 1) +
38  2. * cosphi * sinphi * (cluster->*accessor)(0, 1);
39 }
40 
41 } // namespace
42 
44  : m_cluskey(TrkrDefs::CLUSKEYMAX)
45  , m_isGlobal(true)
46  , m_adc(0xFFFFFFFF)
47  , min_sample(-1)
48  , max_sample(-1)
49  , min_pad_azimuth(-1)
50  , max_pad_azimuth(-1)
51  , peak(NAN)
52  , peak_sample(NAN)
53  , pedstal(NAN)
54  , avg_pad_radial(-1)
55  , avg_pad_azimuth(NAN)
56  , size_pad_radial(-1)
57  , size_pad_azimuth(-1)
58  , delta_azimuth_bin(NAN)
59  , delta_z(NAN)
60 {
61  for (int i = 0; i < 3; ++i) m_pos[i] = NAN;
62 
63  for (int j = 0; j < 3; ++j)
64  {
65  for (int i = j; i < 3; ++i)
66  {
69  }
70  }
71 }
72 
73 void TpcPrototypeCluster::identify(std::ostream& os) const
74 {
75  os << "---TpcPrototypeCluster--------------------" << std::endl;
76  os << "clusid: " << getClusKey() << std::dec << std::endl;
77 
78  os << " (x,y,z) = (" << getPosition(0);
79  os << ", " << getPosition(1) << ", ";
80  os << getPosition(2) << ") cm";
81  if (m_isGlobal)
82  os << " - global coordinates" << std::endl;
83  else
84  os << " - local coordinates" << std::endl;
85 
86  os << " adc = " << getAdc() << std::endl;
87 
88  os << " size phi = " << getPhiSize();
89  os << " cm, size z = " << getZSize() << " cm" << std::endl;
90 
91  os << " ( ";
92  os << getSize(0, 0) << " , ";
93  os << getSize(0, 1) << " , ";
94  os << getSize(0, 2) << " )" << std::endl;
95  os << " size = ( ";
96  os << getSize(1, 0) << " , ";
97  os << getSize(1, 1) << " , ";
98  os << getSize(1, 2) << " )" << std::endl;
99  os << " ( ";
100  os << getSize(2, 0) << " , ";
101  os << getSize(2, 1) << " , ";
102  os << getSize(2, 2) << " )" << std::endl;
103 
104  os << " ( ";
105  os << getError(0, 0) << " , ";
106  os << getError(0, 1) << " , ";
107  os << getError(0, 2) << " )" << std::endl;
108  os << " err = ( ";
109  os << getError(1, 0) << " , ";
110  os << getError(1, 1) << " , ";
111  os << getError(1, 2) << " )" << std::endl;
112  os << " ( ";
113  os << getError(2, 0) << " , ";
114  os << getError(2, 1) << " , ";
115  os << getError(2, 2) << " )" << std::endl;
116 
117  // std::set<int> pad_radials;
118  os << " pad_radials = ( ";
119  for (auto& element : pad_radials) os << element << " ";
120  os << ")" << std::endl;
121 
122  // std::set<int> pad_azimuths;
123  os << " pad_azimuths = ( ";
124  for (auto& element : pad_azimuths) os << element << " ";
125  os << ")" << std::endl;
126  // std::set<int> samples;
127  os << " samples = ( ";
128  for (auto& element : samples) os << element << " ";
129  os << ")" << std::endl;
130  //
131  // std::map<int, std::vector<double>> pad_radial_samples;
132  os << " pad_radial_samples = [ " << std::endl;
133  for (auto& pair : pad_radial_samples)
134  {
135  os << pair.first << "->( ";
136  for (auto& element : pair.second) os << element << " ";
137  os << ")" << std::endl;
138  }
139  os << "]" << std::endl;
140  // std::map<int, std::vector<double>> pad_azimuth_samples;
141  os << " pad_azimuth_samples = [ " << std::endl;
142  for (auto& pair : pad_azimuth_samples)
143  {
144  os << pair.first << "->( ";
145  for (auto& element : pair.second) os << element << " ";
146  os << ")" << std::endl;
147  }
148  os << "]" << std::endl;
149  // std::vector<double> sum_samples;
150  os << " sum_samples = ( ";
151  for (auto& element : sum_samples) os << element << " ";
152  os << ")" << std::endl;
153  //
154  // int min_sample;
155  os << " min_sample = " << min_sample << std::endl;
156  // int max_sample;
157  os << " max_sample = " << max_sample << std::endl;
158  // int min_pad_azimuth;
159  os << " min_pad_azimuth = " << min_pad_azimuth << std::endl;
160  // int max_pad_azimuth;
161  os << " max_pad_azimuth = " << max_pad_azimuth << std::endl;
162  //
163  // double peak;
164  os << " peak = " << peak << std::endl;
165  // double peak_sample;
166  os << " peak_sample = " << peak_sample << std::endl;
167  // double pedstal;
168  os << " pedstal = " << pedstal << std::endl;
169  //
170  // // std::map<int, double> pad_radial_peaks; // radial always have size = 1 in this analysis
171  // std::map<int, double> pad_azimuth_peaks;
172  os << " pad_azimuth_peaks = ( ";
173  for (auto& element : pad_azimuth_peaks) os << element.first << "->" << element.second << " ";
174  os << ")" << std::endl;
175  //
176  // //! pad coordinate
177  // int avg_pad_radial;
178  os << " avg_pad_radial = " << avg_pad_radial << std::endl;
179  // double avg_pad_azimuth;
180  os << " avg_pad_azimuth = " << avg_pad_azimuth << std::endl;
181  //
182  // //! cluster size in units of pad bins
183  // int size_pad_radial;
184  os << " size_pad_radial = " << size_pad_radial << std::endl;
185  // int size_pad_azimuth;
186  os << " size_pad_azimuth = " << size_pad_azimuth << std::endl;
187  //
188  // //! pad bin size
189  // //! phi size per pad in rad
190  // double delta_azimuth_bin;
191  os << " delta_azimuth_bin = " << delta_azimuth_bin << std::endl;
192  // //! z size per ADC sample bin
193  // double delta_z;
194  os << " delta_z = " << delta_z << std::endl;
195 
196  os << std::endl;
197  os << "-----------------------------------------------" << std::endl;
198 
199  return;
200 }
201 
203 {
204  if (m_cluskey == TrkrDefs::CLUSKEYMAX) return 0;
205  for (int i = 0; i < 3; ++i)
206  {
207  if (isnan(getPosition(i))) return 0;
208  }
209  if (m_adc == 0xFFFFFFFF) return 0;
210  for (int j = 0; j < 3; ++j)
211  {
212  for (int i = j; i < 3; ++i)
213  {
214  if (isnan(getSize(i, j))) return 0;
215  if (isnan(getError(i, j))) return 0;
216  }
217  }
218 
219  return 1;
220 }
221 
222 void TpcPrototypeCluster::setSize(unsigned int i, unsigned int j, float value)
223 {
224  m_size[covarIndex(i, j)] = value;
225  return;
226 }
227 
228 float TpcPrototypeCluster::getSize(unsigned int i, unsigned int j) const
229 {
230  return m_size[covarIndex(i, j)];
231 }
232 
233 void TpcPrototypeCluster::setError(unsigned int i, unsigned int j, float value)
234 {
235  m_err[covarIndex(i, j)] = value;
236  return;
237 }
238 
239 float TpcPrototypeCluster::getError(unsigned int i, unsigned int j) const
240 {
241  return m_err[covarIndex(i, j)];
242 }
243 
245 {
246  return 2 * std::sqrt(rotate<&TpcPrototypeCluster::getSize>(this));
247 }
248 
250 {
251  return 2. * sqrt(getSize(2, 2));
252 }
253 
255 {
256  const float rad = std::sqrt(square(m_pos[0]) + square(m_pos[1]));
257  if (rad > 0) return getRPhiError() / rad;
258  return 0;
259 }
260 
262 {
263  return std::sqrt(rotate<&TpcPrototypeCluster::getError>(this));
264 }
265 
267 {
268  return std::sqrt(getError(2, 2));
269 }