Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:19:53

0001 #include "RawTowerGeomContainer_Cylinderv1.h"
0002 
0003 #include <cassert>
0004 #include <cmath>
0005 #include <cstdlib>
0006 #include <iostream>
0007 
0008 RawTowerGeomContainer_Cylinderv1::RawTowerGeomContainer_Cylinderv1(RawTowerDefs::CalorimeterId caloid)
0009   : RawTowerGeomContainerv1(caloid)
0010 {
0011   return;
0012 }
0013 
0014 void RawTowerGeomContainer_Cylinderv1::Reset()
0015 {
0016   eta_bound_map.clear();
0017 
0018   phi_bound_map.clear();
0019 
0020   RawTowerGeomContainerv1::Reset();
0021 }
0022 
0023 void RawTowerGeomContainer_Cylinderv1::set_etabins(const int i)
0024 {
0025   assert(i > 0);
0026   bound_t invalid_bound(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
0027   eta_bound_map.resize(i, invalid_bound);
0028 }
0029 
0030 void RawTowerGeomContainer_Cylinderv1::set_phibins(const int i)
0031 {
0032   assert(i > 0);
0033   bound_t invalid_bound(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
0034   phi_bound_map.resize(i, invalid_bound);
0035 }
0036 
0037 void RawTowerGeomContainer_Cylinderv1::identify(std::ostream& os) const
0038 {
0039   os << "RawTowerGeomContainer_Cylinderv1: radius: " << radius
0040      << ", thickness: " << thickness << ", etabins: " << get_etabins()
0041      << ", phibins: " << get_phibins();
0042 
0043   int i = 0;
0044   for (const auto& iter : eta_bound_map)
0045   {
0046     os << "eta_bin[" << i << "](" << iter.first << ", " << iter.second
0047        << ")  ";
0048     i++;
0049   }
0050   os << std::endl;
0051   i = 0;
0052   for (const auto& iter : phi_bound_map)
0053   {
0054     os << "phi_bin[" << i << "](" << iter.first << ", " << iter.second
0055        << ")  ";
0056     i++;
0057   }
0058   os << std::endl;
0059   return;
0060 }
0061 
0062 std::pair<double, double>
0063 RawTowerGeomContainer_Cylinderv1::get_etabounds(const int ibin) const
0064 {
0065   if (ibin < 0 || ibin > get_etabins())
0066   {
0067     identify();
0068     std::cout
0069         << "RawTowerGeomContainer_Cylinderv1::get_etabounds - Asking for invalid bin in eta: "
0070         << ibin << std::endl;
0071     exit(1);
0072   }
0073   return eta_bound_map[ibin];
0074 }
0075 
0076 std::pair<double, double>
0077 RawTowerGeomContainer_Cylinderv1::get_phibounds(const int ibin) const
0078 {
0079   if (ibin < 0 || ibin > get_phibins())
0080   {
0081     identify();
0082     std::cout
0083         << "RawTowerGeomContainer_Cylinderv1::get_phibounds - Asking for invalid bin in phi: "
0084         << ibin << std::endl;
0085     exit(1);
0086   }
0087   return phi_bound_map[ibin];
0088 }
0089 
0090 int RawTowerGeomContainer_Cylinderv1::get_etabin(const double eta) const
0091 {
0092   int ibin = -1;
0093   int i = 0;
0094 
0095   // switch to search for the closest bin
0096   // since in a realistic calorimeter, there could be gaps
0097   double min_deta = 10;
0098 
0099   for (const auto& iter : eta_bound_map)
0100   {
0101     const double mean_eta = 0.5 * (iter.first + iter.second);
0102 
0103     if (eta >= iter.first && eta < iter.second)
0104     {
0105       // found the bin that the hit belong
0106       min_deta = 0;
0107       ibin = i;
0108       break;
0109     }
0110     const double deta = std::abs(mean_eta - eta);
0111     if (deta < min_deta)
0112     {
0113       min_deta = deta;
0114       ibin = i;
0115     }  // keep searching
0116 
0117     i++;
0118   }
0119 
0120   if (ibin < 0)
0121   {
0122     std::cout
0123         << "RawTowerGeomContainer_Cylinderv1::get_etabin - ERROR - Asking for invalid bin in eta "
0124         << eta << std::endl;
0125     exit(1);
0126   }
0127 
0128   return ibin;
0129 }
0130 
0131 int RawTowerGeomContainer_Cylinderv1::get_phibin(const double phi) const
0132 {
0133   int ibin = -1;
0134   int i = 0;
0135 
0136   // switch to search for the closest bin
0137   // since in a realistic calorimeter, there could be gaps
0138   double min_dphi = 10;
0139 
0140   for (const auto& iter : phi_bound_map)
0141   {
0142     const double mean_phi = 0.5 * (iter.first + iter.second);
0143 
0144     const double phi_fold = phi - round((phi - mean_phi) / 2. / M_PI) * 2 * M_PI;
0145 
0146     if (phi_fold >= iter.first && phi_fold < iter.second)
0147     {
0148       // found the bin that the hit belong
0149       min_dphi = 0;
0150       ibin = i;
0151       break;
0152     }
0153     const double dphi = std::abs(mean_phi - phi_fold);
0154     if (dphi < min_dphi)
0155     {
0156       min_dphi = dphi;
0157       ibin = i;
0158     }  // keep searching
0159 
0160     i++;
0161   }
0162 
0163   if (ibin < 0)
0164   {
0165     std::cout
0166         << "RawTowerGeomContainer_Cylinderv1::get_phibin - ERROR - Asking for invalid bin in phi "
0167         << phi << std::endl;
0168     exit(1);
0169   }
0170 
0171   return ibin;
0172 }
0173 
0174 double
0175 RawTowerGeomContainer_Cylinderv1::get_etacenter(const int ibin) const
0176 {
0177   if (ibin < 0 || ibin >= get_etabins())
0178   {
0179     std::cout
0180         << "RawTowerGeomContainer_Cylinderv1::get_etacenter - Asking for invalid bin in eta: "
0181         << ibin << std::endl;
0182     std::cout << "minbin: 0, maxbin " << get_etabins() << std::endl;
0183     exit(1);
0184   }
0185   return (eta_bound_map[ibin].first + eta_bound_map[ibin].second) / 2.;
0186 }
0187 
0188 void RawTowerGeomContainer_Cylinderv1::set_etabounds(const int ibin,
0189                                                      const std::pair<double, double>& bounds)
0190 {
0191   if (ibin < 0 || ibin >= get_etabins())
0192   {
0193     std::cout
0194         << "RawTowerGeomContainer_Cylinderv1::set_bounds - Asking for invalid bin in eta: "
0195         << ibin << std::endl;
0196     std::cout << "minbin: 0, maxbin " << get_etabins() << std::endl;
0197     exit(1);
0198   }
0199 
0200   std::pair<double, double> b_reg(bounds);
0201   if (b_reg.first > b_reg.second)
0202   {
0203     b_reg.second = bounds.first;
0204     b_reg.first = bounds.second;
0205   }
0206 
0207   eta_bound_map[ibin] = b_reg;
0208 }
0209 
0210 double
0211 RawTowerGeomContainer_Cylinderv1::get_phicenter(const int ibin) const
0212 {
0213   if (ibin < 0 || ibin >= get_phibins())
0214   {
0215     std::cout
0216         << "RawTowerGeomContainer_Cylinderv1::get_phicenter - Asking for invalid bin in phi: "
0217         << ibin << std::endl;
0218     std::cout << "minbin: 0, maxbin " << get_phibins() << std::endl;
0219     exit(1);
0220   }
0221   return (phi_bound_map[ibin].first + phi_bound_map[ibin].second) / 2.;
0222 }
0223 
0224 void RawTowerGeomContainer_Cylinderv1::set_phibounds(const int ibin,
0225                                                      const std::pair<double, double>& bounds)
0226 {
0227   if (ibin < 0 || ibin >= get_phibins())
0228   {
0229     std::cout
0230         << "RawTowerGeomContainer_Cylinderv1::set_bounds - Asking for invalid bin in phi: "
0231         << ibin << std::endl;
0232     std::cout << "minbin: 0, maxbin " << get_phibins() << std::endl;
0233     exit(1);
0234   }
0235 
0236   std::pair<double, double> b_reg(bounds);
0237   if (b_reg.first > b_reg.second)
0238   {
0239     b_reg.second = bounds.first;
0240     b_reg.first = bounds.second;
0241   }
0242 
0243   phi_bound_map[ibin] = b_reg;
0244 }