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