ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinAdjustmentVolume.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BinAdjustmentVolume.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 // BinAdjustment.hpp, Acts project
12 
13 #pragma once
14 
15 #include <stdexcept>
18 #include "Acts/Geometry/Volume.hpp"
19 
20 namespace Acts {
21 
29  const CylinderVolumeBounds& cBounds) {
30  // Default constructor
31  BinUtility uBinUtil;
32  // The parameters from the cylinder bounds
33  double minR = cBounds.get(CylinderVolumeBounds::eMinR);
34  double maxR = cBounds.get(CylinderVolumeBounds::eMaxR);
37  double minZ = -cBounds.get(CylinderVolumeBounds::eHalfLengthZ);
39  // Retrieve the binning data
40  const std::vector<BinningData>& bData = bu.binningData();
41  // Loop over the binning data and adjust the dimensions
42  for (auto& bd : bData) {
43  // The binning value
44  BinningValue bval = bd.binvalue;
45  // Throw exceptions is stuff doesn't make sense:
46  // - not the right binning value
47  // - not equidistant
48  if (bd.type == arbitrary) {
49  throw std::invalid_argument("Arbirary binning can not be adjusted.");
50  } else if (bval != binR and bval != binPhi and bval != binZ) {
51  throw std::invalid_argument("Cylinder volume binning must be: phi, r, z");
52  }
53  float min, max = 0.;
54  // Perform the value adjustment
55  if (bval == binPhi) {
56  min = minPhi;
57  max = maxPhi;
58  } else if (bval == binR) {
59  min = minR;
60  max = maxR;
61  } else if (bval == binZ) {
62  min = minZ;
63  max = maxZ;
64  }
65  // Create the updated BinningData
66  BinningData uBinData(bd.option, bval, bd.bins(), min, max);
67  uBinUtil += BinUtility(uBinData);
68  }
69  return uBinUtil;
70 }
71 
79  const CuboidVolumeBounds& cBounds) {
80  // Default constructor
81  BinUtility uBinUtil;
82  // The parameters from the cylinder bounds
83  double minX = -cBounds.get(CuboidVolumeBounds::eHalfLengthX);
84  double maxX = cBounds.get(CuboidVolumeBounds::eHalfLengthX);
85  double minY = -cBounds.get(CuboidVolumeBounds::eHalfLengthY);
86  double maxY = cBounds.get(CuboidVolumeBounds::eHalfLengthY);
87  double minZ = -cBounds.get(CuboidVolumeBounds::eHalfLengthZ);
88  double maxZ = cBounds.get(CuboidVolumeBounds::eHalfLengthZ);
89  // Retrieve the binning data
90  const std::vector<BinningData>& bData = bu.binningData();
91  // Loop over the binning data and adjust the dimensions
92  for (auto& bd : bData) {
93  // The binning value
94  BinningValue bval = bd.binvalue;
95  // Throw exceptions is stuff doesn't make sense:
96  // - not the right binning value
97  // - not equidistant
98  if (bd.type == arbitrary) {
99  throw std::invalid_argument("Arbirary binning can not be adjusted.");
100  } else if (bval != binX and bval != binY and bval != binZ) {
101  throw std::invalid_argument("Cylinder volume binning must be: x, y, z");
102  }
103  float min, max = 0.;
104  // Perform the value adjustment
105  if (bval == binX) {
106  min = minX;
107  max = maxX;
108  } else if (bval == binY) {
109  min = minY;
110  max = maxY;
111  } else if (bval == binZ) {
112  min = minZ;
113  max = maxZ;
114  }
115  // Create the updated BinningData
116  BinningData uBinData(bd.option, bval, bd.bins(), min, max);
117  uBinUtil += BinUtility(uBinData);
118  }
119  return uBinUtil;
120 }
121 
129  auto cyBounds =
130  dynamic_cast<const CylinderVolumeBounds*>(&(volume.volumeBounds()));
131  auto cuBounds =
132  dynamic_cast<const CuboidVolumeBounds*>(&(volume.volumeBounds()));
133 
134  if (cyBounds != nullptr) {
135  // Cylinder bounds
136  return adjustBinUtility(bu, *cyBounds);
137 
138  } else if (cuBounds != nullptr) {
139  // Cylinder bounds
140  return adjustBinUtility(bu, *cuBounds);
141  }
142 
143  throw std::invalid_argument(
144  "Bin adjustment not implemented for this volume yet!");
145 
146  return BinUtility();
147 }
148 
149 } // namespace Acts