File indexing completed on 2025-08-06 08:18:54
0001 #include "PHG4BlockCellGeom.h"
0002 #include "PHG4CylinderCellDefs.h"
0003
0004 #include <cmath>
0005 #include <cstdlib>
0006
0007 void PHG4BlockCellGeom::set_zbins(const int i)
0008 {
0009 check_binning_method(PHG4CylinderCellDefs::sizebinning);
0010 _nzbins = i;
0011 }
0012
0013 void PHG4BlockCellGeom::set_zmin(const double z)
0014 {
0015 check_binning_method(PHG4CylinderCellDefs::sizebinning);
0016 _zmin = z;
0017 }
0018
0019 int PHG4BlockCellGeom::get_zbins() const
0020 {
0021 check_binning_method(PHG4CylinderCellDefs::sizebinning);
0022 return _nzbins;
0023 }
0024
0025 double
0026 PHG4BlockCellGeom::get_zmin() const
0027 {
0028 check_binning_method(PHG4CylinderCellDefs::sizebinning);
0029 return _zmin;
0030 }
0031
0032 double
0033 PHG4BlockCellGeom::get_zstep() const
0034 {
0035 check_binning_method(PHG4CylinderCellDefs::sizebinning);
0036 return _zstep;
0037 }
0038
0039 void PHG4BlockCellGeom::set_zstep(const double z)
0040 {
0041 check_binning_method(PHG4CylinderCellDefs::sizebinning);
0042 _zstep = z;
0043 }
0044
0045 int PHG4BlockCellGeom::get_xbins() const
0046 {
0047 check_binning_method_x("PHG4BlockCellGeom::get_xbins");
0048 return _nxbins;
0049 }
0050
0051 double
0052 PHG4BlockCellGeom::get_xstep() const
0053 {
0054 check_binning_method_x("PHG4BlockCellGeom::get_xstep");
0055 return _xstep;
0056 }
0057
0058 double
0059 PHG4BlockCellGeom::get_xmin() const
0060 {
0061 check_binning_method_x("PHG4BlockCellGeom::get_xmin");
0062 return _xmin;
0063 }
0064
0065 void PHG4BlockCellGeom::set_xbins(const int i)
0066 {
0067 check_binning_method_x("PHG4BlockCellGeom::set_xbins");
0068 _nxbins = i;
0069 }
0070
0071 void PHG4BlockCellGeom::set_xstep(const double r)
0072 {
0073 check_binning_method_x("PHG4BlockCellGeom::set_xstep");
0074 _xstep = r;
0075 }
0076
0077 void PHG4BlockCellGeom::set_xmin(const double r)
0078 {
0079 check_binning_method_x("PHG4BlockCellGeom::set_xmin");
0080 _xmin = r;
0081 }
0082
0083 int PHG4BlockCellGeom::get_etabins() const
0084 {
0085 check_binning_method_eta("PHG4BlockCellGeom::get_etabins");
0086 return _nzbins;
0087 }
0088
0089 double
0090 PHG4BlockCellGeom::get_etastep() const
0091 {
0092 check_binning_method_eta("PHG4BlockCellGeom::get_etastep");
0093 return _zstep;
0094 }
0095 double
0096 PHG4BlockCellGeom::get_etamin() const
0097 {
0098 check_binning_method_eta("PHG4BlockCellGeom::get_etamin");
0099 return _zmin;
0100 }
0101
0102 void PHG4BlockCellGeom::set_etamin(const double z)
0103 {
0104 check_binning_method_eta("PHG4BlockCellGeom::set_etamin");
0105 _zmin = z;
0106 }
0107
0108 void PHG4BlockCellGeom::set_etastep(const double z)
0109 {
0110 check_binning_method_eta("PHG4BlockCellGeom::set_etastep");
0111 _zstep = z;
0112 }
0113
0114 void PHG4BlockCellGeom::set_etabins(const int i)
0115 {
0116 check_binning_method_eta("PHG4BlockCellGeom::set_etabins");
0117 _nzbins = i;
0118 }
0119
0120 void PHG4BlockCellGeom::identify(std::ostream& os) const
0121 {
0122 os << "layer: " << _layer;
0123 switch (_binning)
0124 {
0125 case PHG4CylinderCellDefs::sizebinning:
0126 os << ", zbins: " << _nzbins
0127 << ", zmin: " << _zmin
0128 << ", zstepsize: " << _zstep;
0129 break;
0130
0131 case PHG4CylinderCellDefs::etaphibinning:
0132 case PHG4CylinderCellDefs::etaslatbinning:
0133 os << ", etabins: " << _nzbins
0134 << ", etamin: " << _zmin
0135 << ", etastepsize: " << _zstep;
0136 break;
0137
0138 default:
0139 os << "no valid binning method: " << _binning << std::endl;
0140 return;
0141 break;
0142 }
0143
0144 os << ", xmin: " << _xmin
0145 << ", xbins: " << _nxbins
0146 << ", xstep: " << _xstep
0147 << std::endl;
0148 return;
0149 }
0150
0151 std::pair<double, double>
0152 PHG4BlockCellGeom::get_zbounds(const int ibin) const
0153 {
0154 if (ibin < 0 || ibin > _nzbins)
0155 {
0156 std::cout << "Asking for invalid bin in z: " << ibin << std::endl;
0157 exit(1);
0158 }
0159 check_binning_method(PHG4CylinderCellDefs::sizebinning);
0160 double zlow = _zmin + ibin * _zstep;
0161 double zhigh = zlow + _zstep;
0162 return std::make_pair(zlow, zhigh);
0163 }
0164
0165 std::pair<double, double>
0166 PHG4BlockCellGeom::get_etabounds(const int ibin) const
0167 {
0168 if (ibin < 0 || ibin > _nzbins)
0169 {
0170 std::cout << "Asking for invalid bin in z: " << ibin << std::endl;
0171 exit(1);
0172 }
0173 check_binning_method_eta("PHG4BlockCellGeom::get_etabounds");
0174
0175 double zlow = _zmin + ibin * _zstep;
0176 double zhigh = zlow + _zstep;
0177 return std::make_pair(zlow, zhigh);
0178 }
0179
0180 std::pair<double, double>
0181 PHG4BlockCellGeom::get_xbounds(const int ibin) const
0182 {
0183 if (ibin < 0 || ibin > _nxbins)
0184 {
0185 std::cout << "Asking for invalid bin in x: " << ibin << std::endl;
0186 exit(1);
0187 }
0188
0189 double xlow = _xmin + ibin * _xstep;
0190 double xhigh = xlow + _xstep;
0191 return std::make_pair(xlow, xhigh);
0192 }
0193
0194 int PHG4BlockCellGeom::get_zbin(const double z) const
0195 {
0196 if (z < _zmin || z > (_zmin + _nzbins * _zstep))
0197 {
0198 std::cout << "Asking for bin for z outside of z range: " << z << std::endl;
0199 return -1;
0200 }
0201
0202 check_binning_method(PHG4CylinderCellDefs::sizebinning);
0203 return floor((z - _zmin) / _zstep);
0204 }
0205
0206 int PHG4BlockCellGeom::get_etabin(const double eta) const
0207 {
0208 if (eta < _zmin || eta > (_zmin + _nzbins * _zstep))
0209 {
0210 std::cout << "Asking for bin for eta outside of eta range: " << eta << std::endl;
0211 return -1;
0212 }
0213 check_binning_method_eta();
0214 return floor((eta - _zmin) / _zstep);
0215 }
0216
0217 int PHG4BlockCellGeom::get_xbin(const double x) const
0218 {
0219 double norm_x = x;
0220 if (x < _xmin || x > (_xmin + _nxbins * _xstep))
0221 {
0222 std::cout << "Asking for bin for x outside of x range: " << x << std::endl;
0223 return -1;
0224 }
0225 check_binning_method_x();
0226 return floor((norm_x - _xmin) / _xstep);
0227 }
0228
0229 double
0230 PHG4BlockCellGeom::get_zcenter(const int ibin) const
0231 {
0232 if (ibin < 0 || ibin > _nzbins)
0233 {
0234 std::cout << "Asking for invalid bin in z: " << ibin << std::endl;
0235 exit(1);
0236 }
0237 check_binning_method(PHG4CylinderCellDefs::sizebinning);
0238 return _zmin + (ibin + 0.5) * _zstep;
0239 }
0240
0241 double
0242 PHG4BlockCellGeom::get_etacenter(const int ibin) const
0243 {
0244 if (ibin < 0 || ibin > _nzbins)
0245 {
0246 std::cout << "Asking for invalid bin in eta: " << ibin << std::endl;
0247 std::cout << "minbin: 0, maxbin " << _nzbins << std::endl;
0248 exit(1);
0249 }
0250 check_binning_method_eta();
0251 return _zmin + (ibin + 0.5) * _zstep;
0252 }
0253
0254 double
0255 PHG4BlockCellGeom::get_xcenter(const int ibin) const
0256 {
0257 if (ibin < 0 || ibin > _nxbins)
0258 {
0259 std::cout << "Asking for invalid bin in x: " << ibin << std::endl;
0260 exit(1);
0261 }
0262
0263 check_binning_method_x();
0264 return (_xmin + (ibin + 0.5) * _xstep);
0265 }
0266
0267 std::string
0268 PHG4BlockCellGeom::methodname(const int i) const
0269 {
0270 switch (i)
0271 {
0272 case PHG4CylinderCellDefs::sizebinning:
0273 return "Bins in cm";
0274 break;
0275 case PHG4CylinderCellDefs::etaphibinning:
0276 return "Eta/Phi bins";
0277 break;
0278 case PHG4CylinderCellDefs::etaslatbinning:
0279 return "Eta/numslat bins";
0280 break;
0281 default:
0282 break;
0283 }
0284 return "Unknown";
0285 }
0286
0287 void PHG4BlockCellGeom::check_binning_method(const int i) const
0288 {
0289 if (_binning != i)
0290 {
0291 std::cout << "different binning method used " << methodname(_binning)
0292 << ", not : " << methodname(i)
0293 << std::endl;
0294 exit(1);
0295 }
0296 return;
0297 }
0298
0299 void PHG4BlockCellGeom::check_binning_method_eta(const std::string& src) const
0300 {
0301 if (_binning != PHG4CylinderCellDefs::etaphibinning &&
0302 _binning != PHG4CylinderCellDefs::etaslatbinning)
0303 {
0304 if (src.size())
0305 {
0306 std::cout << src << " : ";
0307 }
0308
0309 std::cout << "different binning method used " << methodname(_binning)
0310 << ", not : " << methodname(PHG4CylinderCellDefs::etaphibinning)
0311 << " or " << methodname(PHG4CylinderCellDefs::etaslatbinning)
0312 << std::endl;
0313 exit(1);
0314 }
0315 return;
0316 }
0317
0318 void PHG4BlockCellGeom::check_binning_method_x(const std::string& src) const
0319 {
0320 if (_binning != PHG4CylinderCellDefs::etaphibinning &&
0321 _binning != PHG4CylinderCellDefs::sizebinning &&
0322 _binning != PHG4CylinderCellDefs::etaslatbinning)
0323 {
0324 if (src.size())
0325 {
0326 std::cout << src << " : ";
0327 }
0328
0329 std::cout << "different binning method used " << methodname(_binning)
0330 << ", not : " << methodname(PHG4CylinderCellDefs::etaphibinning)
0331 << " or " << methodname(PHG4CylinderCellDefs::sizebinning)
0332 << std::endl;
0333 exit(1);
0334 }
0335 return;
0336 }