EIC 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 
42 void RawTowerGeomContainer_Cylinderv1::identify(std::ostream& os) const
43 {
44  os << "RawTowerGeomContainer_Cylinderv1: radius: " << radius
45  << ", thickness: " << thickness << ", etabins: " << get_etabins()
46  << ", phibins: " << get_phibins();
47 
48  int i = 0;
49  for (bound_map_t::const_iterator iter = eta_bound_map.begin();
50  iter != eta_bound_map.end(); ++iter)
51  {
52  os << "eta_bin[" << i << "](" << iter->first << ", " << iter->second
53  << ") ";
54  i++;
55  }
56  os << endl;
57  i = 0;
58  for (bound_map_t::const_iterator iter = phi_bound_map.begin();
59  iter != phi_bound_map.end(); ++iter)
60  {
61  os << "phi_bin[" << i << "](" << iter->first << ", " << iter->second
62  << ") ";
63  i++;
64  }
65  os << endl;
66  return;
67 }
68 
69 pair<double, double>
71 {
72  if (ibin < 0 || ibin > get_etabins())
73  {
74  identify();
75  cout
76  << "RawTowerGeomContainer_Cylinderv1::get_etabounds - Asking for invalid bin in eta: "
77  << ibin << endl;
78  exit(1);
79  }
80  return eta_bound_map[ibin];
81 }
82 
83 pair<double, double>
85 {
86  if (ibin < 0 || ibin > get_phibins())
87  {
88  identify();
89  cout
90  << "RawTowerGeomContainer_Cylinderv1::get_phibounds - Asking for invalid bin in phi: "
91  << ibin << endl;
92  exit(1);
93  }
94  return phi_bound_map[ibin];
95 }
96 
98 {
99  int ibin = -1;
100  int i = 0;
101 
102  // switch to search for the closest bin
103  // since in a realistic calorimeter, there could be gaps
104  double min_deta = 10;
105 
106  for (bound_map_t::const_iterator iter = eta_bound_map.begin();
107  iter != eta_bound_map.end(); ++iter)
108  {
109  const double mean_eta = 0.5 * (iter->first + iter->second);
110 
111  if (eta >= iter->first && eta < iter->second)
112  {
113  // found the bin that the hit belong
114  min_deta = 0;
115  ibin = i;
116  break;
117  }
118  else
119  {
120  const double deta = fabs(mean_eta - eta);
121  if (deta < min_deta)
122  {
123  min_deta = deta;
124  ibin = i;
125  } // keep searching
126  }
127 
128  i++;
129  }
130 
131  if (ibin < 0)
132  {
133  cout
134  << "RawTowerGeomContainer_Cylinderv1::get_etabin - ERROR - Asking for invalid bin in eta "
135  << eta << endl;
136  exit(1);
137  }
138 
139  return ibin;
140 }
141 
143 {
144  int ibin = -1;
145  int i = 0;
146 
147  // switch to search for the closest bin
148  // since in a realistic calorimeter, there could be gaps
149  double min_dphi = 10;
150 
151  for (bound_map_t::const_iterator iter = phi_bound_map.begin();
152  iter != phi_bound_map.end(); ++iter)
153  {
154  const double mean_phi = 0.5 * (iter->first + iter->second);
155 
156  const double phi_fold = phi - round((phi - mean_phi) / 2. / M_PI) * 2 * M_PI;
157 
158  if (phi_fold >= iter->first && phi_fold < iter->second)
159  {
160  // found the bin that the hit belong
161  min_dphi = 0;
162  ibin = i;
163  break;
164  }
165  else
166  {
167  const double dphi = fabs(mean_phi - phi_fold);
168  if (dphi < min_dphi)
169  {
170  min_dphi = dphi;
171  ibin = i;
172  } // keep searching
173  }
174 
175  i++;
176  }
177 
178  if (ibin < 0)
179  {
180  cout
181  << "RawTowerGeomContainer_Cylinderv1::get_phibin - ERROR - Asking for invalid bin in phi "
182  << phi << endl;
183  exit(1);
184  }
185 
186  return ibin;
187 }
188 
189 double
191 {
192  if (ibin < 0 || ibin >= get_etabins())
193  {
194  cout
195  << "RawTowerGeomContainer_Cylinderv1::get_etacenter - Asking for invalid bin in eta: "
196  << ibin << endl;
197  cout << "minbin: 0, maxbin " << get_etabins() << endl;
198  exit(1);
199  }
200  return (eta_bound_map[ibin].first + eta_bound_map[ibin].second) / 2.;
201 }
202 
204  const std::pair<double, double>& bounds)
205 {
206  if (ibin < 0 || ibin >= get_etabins())
207  {
208  cout
209  << "RawTowerGeomContainer_Cylinderv1::set_bounds - Asking for invalid bin in eta: "
210  << ibin << endl;
211  cout << "minbin: 0, maxbin " << get_etabins() << endl;
212  exit(1);
213  }
214 
215  std::pair<double, double> b_reg(bounds);
216  if (b_reg.first > b_reg.second)
217  {
218  b_reg.second = bounds.first;
219  b_reg.first = bounds.second;
220  }
221 
222  eta_bound_map[ibin] = b_reg;
223 }
224 
225 double
227 {
228  if (ibin < 0 || ibin >= get_phibins())
229  {
230  cout
231  << "RawTowerGeomContainer_Cylinderv1::get_phicenter - Asking for invalid bin in phi: "
232  << ibin << endl;
233  cout << "minbin: 0, maxbin " << get_phibins() << endl;
234  exit(1);
235  }
236  return (phi_bound_map[ibin].first + phi_bound_map[ibin].second) / 2.;
237 }
238 
240  const std::pair<double, double>& bounds)
241 {
242  if (ibin < 0 || ibin >= get_phibins())
243  {
244  cout
245  << "RawTowerGeomContainer_Cylinderv1::set_bounds - Asking for invalid bin in phi: "
246  << ibin << endl;
247  cout << "minbin: 0, maxbin " << get_phibins() << endl;
248  exit(1);
249  }
250 
251  std::pair<double, double> b_reg(bounds);
252  if (b_reg.first > b_reg.second)
253  {
254  b_reg.second = bounds.first;
255  b_reg.first = bounds.second;
256  }
257 
258  phi_bound_map[ibin] = b_reg;
259 }