Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawTowerGeomContainer_Cylinderv1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RawTowerGeomContainer_Cylinderv1.cc
2 
3 #include <cassert>
4 #include <cmath>
5 #include <cstdlib>
6 #include <iostream>
7 #include <memory>
8 
9 using namespace std;
10 
12  : RawTowerGeomContainerv1(caloid)
13  , radius(NAN)
14  , thickness(NAN)
15 {
16  return;
17 }
18 
20 {
21  eta_bound_map.clear();
22 
23  phi_bound_map.clear();
24 
26 }
27 
29 {
30  assert(i > 0);
31  bound_t invalid_bound(NAN, NAN);
32  eta_bound_map.resize(i, invalid_bound);
33 }
34 
36 {
37  assert(i > 0);
38  bound_t invalid_bound(NAN, NAN);
39  phi_bound_map.resize(i, invalid_bound);
40 }
41 
43 {
44  os << "RawTowerGeomContainer_Cylinderv1: radius: " << radius
45  << ", thickness: " << thickness << ", etabins: " << get_etabins()
46  << ", phibins: " << get_phibins();
47 
48  int i = 0;
49  for (const auto& iter : eta_bound_map)
50  {
51  os << "eta_bin[" << i << "](" << iter.first << ", " << iter.second
52  << ") ";
53  i++;
54  }
55  os << endl;
56  i = 0;
57  for (const auto& iter : phi_bound_map)
58  {
59  os << "phi_bin[" << i << "](" << iter.first << ", " << iter.second
60  << ") ";
61  i++;
62  }
63  os << endl;
64  return;
65 }
66 
67 pair<double, double>
69 {
70  if (ibin < 0 || ibin > get_etabins())
71  {
72  identify();
73  cout
74  << "RawTowerGeomContainer_Cylinderv1::get_etabounds - Asking for invalid bin in eta: "
75  << ibin << endl;
76  exit(1);
77  }
78  return eta_bound_map[ibin];
79 }
80 
81 pair<double, double>
83 {
84  if (ibin < 0 || ibin > get_phibins())
85  {
86  identify();
87  cout
88  << "RawTowerGeomContainer_Cylinderv1::get_phibounds - Asking for invalid bin in phi: "
89  << ibin << endl;
90  exit(1);
91  }
92  return phi_bound_map[ibin];
93 }
94 
96 {
97  int ibin = -1;
98  int i = 0;
99 
100  // switch to search for the closest bin
101  // since in a realistic calorimeter, there could be gaps
102  double min_deta = 10;
103 
104  for (const auto& iter : eta_bound_map)
105  {
106  const double mean_eta = 0.5 * (iter.first + iter.second);
107 
108  if (eta >= iter.first && eta < iter.second)
109  {
110  // found the bin that the hit belong
111  min_deta = 0;
112  ibin = i;
113  break;
114  }
115  else
116  {
117  const double deta = fabs(mean_eta - eta);
118  if (deta < min_deta)
119  {
120  min_deta = deta;
121  ibin = i;
122  } // keep searching
123  }
124 
125  i++;
126  }
127 
128  if (ibin < 0)
129  {
130  cout
131  << "RawTowerGeomContainer_Cylinderv1::get_etabin - ERROR - Asking for invalid bin in eta "
132  << eta << endl;
133  exit(1);
134  }
135 
136  return ibin;
137 }
138 
140 {
141  int ibin = -1;
142  int i = 0;
143 
144  // switch to search for the closest bin
145  // since in a realistic calorimeter, there could be gaps
146  double min_dphi = 10;
147 
148  for (const auto& iter : phi_bound_map)
149  {
150  const double mean_phi = 0.5 * (iter.first + iter.second);
151 
152  const double phi_fold = phi - round((phi - mean_phi) / 2. / M_PI) * 2 * M_PI;
153 
154  if (phi_fold >= iter.first && phi_fold < iter.second)
155  {
156  // found the bin that the hit belong
157  min_dphi = 0;
158  ibin = i;
159  break;
160  }
161  else
162  {
163  const double dphi = fabs(mean_phi - phi_fold);
164  if (dphi < min_dphi)
165  {
166  min_dphi = dphi;
167  ibin = i;
168  } // keep searching
169  }
170 
171  i++;
172  }
173 
174  if (ibin < 0)
175  {
176  cout
177  << "RawTowerGeomContainer_Cylinderv1::get_phibin - ERROR - Asking for invalid bin in phi "
178  << phi << endl;
179  exit(1);
180  }
181 
182  return ibin;
183 }
184 
185 double
187 {
188  if (ibin < 0 || ibin >= get_etabins())
189  {
190  cout
191  << "RawTowerGeomContainer_Cylinderv1::get_etacenter - Asking for invalid bin in eta: "
192  << ibin << endl;
193  cout << "minbin: 0, maxbin " << get_etabins() << endl;
194  exit(1);
195  }
196  return (eta_bound_map[ibin].first + eta_bound_map[ibin].second) / 2.;
197 }
198 
200  const std::pair<double, double>& bounds)
201 {
202  if (ibin < 0 || ibin >= get_etabins())
203  {
204  cout
205  << "RawTowerGeomContainer_Cylinderv1::set_bounds - Asking for invalid bin in eta: "
206  << ibin << endl;
207  cout << "minbin: 0, maxbin " << get_etabins() << endl;
208  exit(1);
209  }
210 
211  std::pair<double, double> b_reg(bounds);
212  if (b_reg.first > b_reg.second)
213  {
214  b_reg.second = bounds.first;
215  b_reg.first = bounds.second;
216  }
217 
218  eta_bound_map[ibin] = b_reg;
219 }
220 
221 double
223 {
224  if (ibin < 0 || ibin >= get_phibins())
225  {
226  cout
227  << "RawTowerGeomContainer_Cylinderv1::get_phicenter - Asking for invalid bin in phi: "
228  << ibin << endl;
229  cout << "minbin: 0, maxbin " << get_phibins() << endl;
230  exit(1);
231  }
232  return (phi_bound_map[ibin].first + phi_bound_map[ibin].second) / 2.;
233 }
234 
236  const std::pair<double, double>& bounds)
237 {
238  if (ibin < 0 || ibin >= get_phibins())
239  {
240  cout
241  << "RawTowerGeomContainer_Cylinderv1::set_bounds - Asking for invalid bin in phi: "
242  << ibin << endl;
243  cout << "minbin: 0, maxbin " << get_phibins() << endl;
244  exit(1);
245  }
246 
247  std::pair<double, double> b_reg(bounds);
248  if (b_reg.first > b_reg.second)
249  {
250  b_reg.second = bounds.first;
251  b_reg.first = bounds.second;
252  }
253 
254  phi_bound_map[ibin] = b_reg;
255 }