Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:16

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2019 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 ///////////////////////////////////////////////////////////////////
0010 // BinAdjustment.hpp, Acts project
0011 ///////////////////////////////////////////////////////////////////
0012 
0013 #pragma once
0014 
0015 #include "Acts/Definitions/Algebra.hpp"
0016 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0017 #include "Acts/Geometry/CutoutCylinderVolumeBounds.hpp"
0018 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0019 #include "Acts/Geometry/Volume.hpp"
0020 #include "Acts/Utilities/BinUtility.hpp"
0021 
0022 #include <stdexcept>
0023 
0024 namespace Acts {
0025 
0026 /// @brief adjust the BinUtility bu to the dimensions of cylinder volume bounds
0027 ///
0028 /// @param bu BinUtility at source
0029 /// @param cBounds the Cylinder volume bounds to adjust to
0030 /// @param transform Transform for the adjusted @c BinUtility
0031 ///
0032 /// @return new updated BinUtiltiy
0033 BinUtility adjustBinUtility(const BinUtility& bu,
0034                             const CylinderVolumeBounds& cBounds,
0035                             const Transform3& transform) {
0036   // Default constructor
0037   BinUtility uBinUtil(transform);
0038   // The parameters from the cylinder bounds
0039   double minR = cBounds.get(CylinderVolumeBounds::eMinR);
0040   double maxR = cBounds.get(CylinderVolumeBounds::eMaxR);
0041   double minPhi = -cBounds.get(CylinderVolumeBounds::eHalfPhiSector);
0042   double maxPhi = cBounds.get(CylinderVolumeBounds::eHalfPhiSector);
0043   double minZ = -cBounds.get(CylinderVolumeBounds::eHalfLengthZ);
0044   double maxZ = cBounds.get(CylinderVolumeBounds::eHalfLengthZ);
0045   // Retrieve the binning data
0046   const std::vector<BinningData>& bData = bu.binningData();
0047   // Loop over the binning data and adjust the dimensions
0048   for (auto& bd : bData) {
0049     // The binning value
0050     BinningValue bval = bd.binvalue;
0051     // Throw exceptions is stuff doesn't make sense:
0052     // - not the right binning value
0053     // - not equidistant
0054     if (bd.type == arbitrary) {
0055       throw std::invalid_argument("Arbitrary binning can not be adjusted.");
0056     } else if (bval != binR && bval != binPhi && bval != binZ) {
0057       throw std::invalid_argument("Cylinder volume binning must be: phi, r, z");
0058     }
0059     float min = 0;
0060     float max = 0;
0061     // Perform the value adjustment
0062     if (bval == binPhi) {
0063       min = minPhi;
0064       max = maxPhi;
0065     } else if (bval == binR) {
0066       min = minR;
0067       max = maxR;
0068     } else if (bval == binZ) {
0069       min = minZ;
0070       max = maxZ;
0071     }
0072     // Create the updated BinningData
0073     BinningData uBinData(bd.option, bval, bd.bins(), min, max);
0074     uBinUtil += BinUtility(uBinData);
0075   }
0076 
0077   return uBinUtil;
0078 }
0079 
0080 /// @brief adjust the BinUtility bu to the dimensions of cutout cylinder volume
0081 /// bounds
0082 ///
0083 /// @param bu BinUtility at source
0084 /// @param cBounds the Cutout Cylinder volume bounds to adjust to
0085 /// @param transform Transform for the adjusted @c BinUtility
0086 ///
0087 /// @return new updated BinUtiltiy
0088 BinUtility adjustBinUtility(const BinUtility& bu,
0089                             const CutoutCylinderVolumeBounds& cBounds,
0090                             const Transform3& transform) {
0091   // Default constructor
0092   BinUtility uBinUtil(transform);
0093   // The parameters from the cutout cylinder bounds
0094   double minR = cBounds.get(CutoutCylinderVolumeBounds::eMinR);
0095   double maxR = cBounds.get(CutoutCylinderVolumeBounds::eMaxR);
0096   double minPhi = -M_PI;
0097   double maxPhi = M_PI;
0098   double minZ = -cBounds.get(CutoutCylinderVolumeBounds::eHalfLengthZ);
0099   double maxZ = cBounds.get(CutoutCylinderVolumeBounds::eHalfLengthZ);
0100   // Retrieve the binning data
0101   const std::vector<BinningData>& bData = bu.binningData();
0102   // Loop over the binning data and adjust the dimensions
0103   for (auto& bd : bData) {
0104     // The binning value
0105     BinningValue bval = bd.binvalue;
0106     // Throw exceptions is stuff doesn't make sense:
0107     // - not the right binning value
0108     // - not equidistant
0109     if (bd.type == arbitrary) {
0110       throw std::invalid_argument("Arbitrary binning can not be adjusted.");
0111     } else if (bval != binR && bval != binPhi && bval != binZ) {
0112       throw std::invalid_argument(
0113           "Cutout cylinder volume binning must be: phi, r, z");
0114     }
0115     float min = 0;
0116     float max = 0;
0117     // Perform the value adjustment
0118     if (bval == binPhi) {
0119       min = minPhi;
0120       max = maxPhi;
0121     } else if (bval == binR) {
0122       min = minR;
0123       max = maxR;
0124     } else if (bval == binZ) {
0125       min = minZ;
0126       max = maxZ;
0127     }
0128     // Create the updated BinningData
0129     BinningData uBinData(bd.option, bval, bd.bins(), min, max);
0130     uBinUtil += BinUtility(uBinData);
0131   }
0132 
0133   return uBinUtil;
0134 }
0135 
0136 /// @brief adjust the BinUtility bu to the dimensions of cuboid volume bounds
0137 ///
0138 /// @param bu BinUtility at source
0139 /// @param cBounds the Cuboid volume bounds to adjust to
0140 /// @param transform Transform for the adjusted @c BinUtility
0141 ///
0142 /// @return new updated BinUtiltiy
0143 BinUtility adjustBinUtility(const BinUtility& bu,
0144                             const CuboidVolumeBounds& cBounds,
0145                             const Transform3& transform) {
0146   // Default constructor
0147   BinUtility uBinUtil(transform);
0148   // The parameters from the cylinder bounds
0149   double minX = -cBounds.get(CuboidVolumeBounds::eHalfLengthX);
0150   double maxX = cBounds.get(CuboidVolumeBounds::eHalfLengthX);
0151   double minY = -cBounds.get(CuboidVolumeBounds::eHalfLengthY);
0152   double maxY = cBounds.get(CuboidVolumeBounds::eHalfLengthY);
0153   double minZ = -cBounds.get(CuboidVolumeBounds::eHalfLengthZ);
0154   double maxZ = cBounds.get(CuboidVolumeBounds::eHalfLengthZ);
0155   // Retrieve the binning data
0156   const std::vector<BinningData>& bData = bu.binningData();
0157   // Loop over the binning data and adjust the dimensions
0158   for (auto& bd : bData) {
0159     // The binning value
0160     BinningValue bval = bd.binvalue;
0161     // Throw exceptions is stuff doesn't make sense:
0162     // - not the right binning value
0163     // - not equidistant
0164     if (bd.type == arbitrary) {
0165       throw std::invalid_argument("Arbitrary binning can not be adjusted.");
0166     } else if (bval != binX && bval != binY && bval != binZ) {
0167       throw std::invalid_argument("Cylinder volume binning must be: x, y, z");
0168     }
0169     float min = 0;
0170     float max = 0;
0171     // Perform the value adjustment
0172     if (bval == binX) {
0173       min = minX;
0174       max = maxX;
0175     } else if (bval == binY) {
0176       min = minY;
0177       max = maxY;
0178     } else if (bval == binZ) {
0179       min = minZ;
0180       max = maxZ;
0181     }
0182     // Create the updated BinningData
0183     BinningData uBinData(bd.option, bval, bd.bins(), min, max);
0184     uBinUtil += BinUtility(uBinData);
0185   }
0186   return uBinUtil;
0187 }
0188 
0189 /// @brief adjust the BinUtility bu to a volume
0190 ///
0191 /// @param bu BinUtility at source
0192 /// @param volume Volume to which the adjustment is being done
0193 ///
0194 /// @return new updated BinUtiltiy
0195 BinUtility adjustBinUtility(const BinUtility& bu, const Volume& volume) {
0196   auto cyBounds =
0197       dynamic_cast<const CylinderVolumeBounds*>(&(volume.volumeBounds()));
0198   auto cutcylBounds =
0199       dynamic_cast<const CutoutCylinderVolumeBounds*>(&(volume.volumeBounds()));
0200   auto cuBounds =
0201       dynamic_cast<const CuboidVolumeBounds*>(&(volume.volumeBounds()));
0202 
0203   if (cyBounds != nullptr) {
0204     // Cylinder bounds
0205     return adjustBinUtility(bu, *cyBounds, volume.transform());
0206 
0207   } else if (cutcylBounds != nullptr) {
0208     // Cutout Cylinder bounds
0209     return adjustBinUtility(bu, *cutcylBounds, volume.transform());
0210 
0211   } else if (cuBounds != nullptr) {
0212     // Cuboid bounds
0213     return adjustBinUtility(bu, *cuBounds, volume.transform());
0214   }
0215 
0216   throw std::invalid_argument(
0217       "Bin adjustment not implemented for this volume yet!");
0218 }
0219 
0220 }  // namespace Acts