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 
18 #include "Acts/Geometry/Volume.hpp"
19 
22 
23 #include <stdexcept>
24 
25 namespace Acts {
26 
34  const CylinderVolumeBounds& cBounds,
35  const Transform3D& transform) {
36  // Default constructor
37  BinUtility uBinUtil(transform);
38  // The parameters from the cylinder bounds
39  double minR = cBounds.get(CylinderVolumeBounds::eMinR);
40  double maxR = cBounds.get(CylinderVolumeBounds::eMaxR);
43  double minZ = -cBounds.get(CylinderVolumeBounds::eHalfLengthZ);
44  double maxZ = cBounds.get(CylinderVolumeBounds::eHalfLengthZ);
45  // Retrieve the binning data
46  const std::vector<BinningData>& bData = bu.binningData();
47  // Loop over the binning data and adjust the dimensions
48  for (auto& bd : bData) {
49  // The binning value
50  BinningValue bval = bd.binvalue;
51  // Throw exceptions is stuff doesn't make sense:
52  // - not the right binning value
53  // - not equidistant
54  if (bd.type == arbitrary) {
55  throw std::invalid_argument("Arbirary binning can not be adjusted.");
56  } else if (bval != binR and bval != binPhi and bval != binZ) {
57  throw std::invalid_argument("Cylinder volume binning must be: phi, r, z");
58  }
59  float min = 0;
60  float max = 0;
61  // Perform the value adjustment
62  if (bval == binPhi) {
63  min = minPhi;
64  max = maxPhi;
65  } else if (bval == binR) {
66  min = minR;
67  max = maxR;
68  } else if (bval == binZ) {
69  min = minZ;
70  max = maxZ;
71  }
72  // Create the updated BinningData
73  BinningData uBinData(bd.option, bval, bd.bins(), min, max);
74  uBinUtil += BinUtility(uBinData);
75  }
76 
77  return uBinUtil;
78 }
79 
88  const CutoutCylinderVolumeBounds& cBounds,
89  const Transform3D& transform) {
90  // Default constructor
91  BinUtility uBinUtil(transform);
92  // The parameters from the cutout cylinder bounds
93  double minR = cBounds.get(CutoutCylinderVolumeBounds::eMinR);
94  double maxR = cBounds.get(CutoutCylinderVolumeBounds::eMaxR);
95  double minPhi = -M_PI;
96  double maxPhi = M_PI;
97  double minZ = -cBounds.get(CutoutCylinderVolumeBounds::eHalfLengthZ);
98  double maxZ = cBounds.get(CutoutCylinderVolumeBounds::eHalfLengthZ);
99  // Retrieve the binning data
100  const std::vector<BinningData>& bData = bu.binningData();
101  // Loop over the binning data and adjust the dimensions
102  for (auto& bd : bData) {
103  // The binning value
104  BinningValue bval = bd.binvalue;
105  // Throw exceptions is stuff doesn't make sense:
106  // - not the right binning value
107  // - not equidistant
108  if (bd.type == arbitrary) {
109  throw std::invalid_argument("Arbirary binning can not be adjusted.");
110  } else if (bval != binR and bval != binPhi and bval != binZ) {
111  throw std::invalid_argument(
112  "Cutout cylinder volume binning must be: phi, r, z");
113  }
114  float min = 0;
115  float max = 0;
116  // Perform the value adjustment
117  if (bval == binPhi) {
118  min = minPhi;
119  max = maxPhi;
120  } else if (bval == binR) {
121  min = minR;
122  max = maxR;
123  } else if (bval == binZ) {
124  min = minZ;
125  max = maxZ;
126  }
127  // Create the updated BinningData
128  BinningData uBinData(bd.option, bval, bd.bins(), min, max);
129  uBinUtil += BinUtility(uBinData);
130  }
131 
132  return uBinUtil;
133 }
134 
142  const CuboidVolumeBounds& cBounds,
143  const Transform3D& transform) {
144  // Default constructor
145  BinUtility uBinUtil(transform);
146  // The parameters from the cylinder bounds
147  double minX = -cBounds.get(CuboidVolumeBounds::eHalfLengthX);
148  double maxX = cBounds.get(CuboidVolumeBounds::eHalfLengthX);
149  double minY = -cBounds.get(CuboidVolumeBounds::eHalfLengthY);
150  double maxY = cBounds.get(CuboidVolumeBounds::eHalfLengthY);
151  double minZ = -cBounds.get(CuboidVolumeBounds::eHalfLengthZ);
152  double maxZ = cBounds.get(CuboidVolumeBounds::eHalfLengthZ);
153  // Retrieve the binning data
154  const std::vector<BinningData>& bData = bu.binningData();
155  // Loop over the binning data and adjust the dimensions
156  for (auto& bd : bData) {
157  // The binning value
158  BinningValue bval = bd.binvalue;
159  // Throw exceptions is stuff doesn't make sense:
160  // - not the right binning value
161  // - not equidistant
162  if (bd.type == arbitrary) {
163  throw std::invalid_argument("Arbirary binning can not be adjusted.");
164  } else if (bval != binX and bval != binY and bval != binZ) {
165  throw std::invalid_argument("Cylinder volume binning must be: x, y, z");
166  }
167  float min = 0;
168  float max = 0;
169  // Perform the value adjustment
170  if (bval == binX) {
171  min = minX;
172  max = maxX;
173  } else if (bval == binY) {
174  min = minY;
175  max = maxY;
176  } else if (bval == binZ) {
177  min = minZ;
178  max = maxZ;
179  }
180  // Create the updated BinningData
181  BinningData uBinData(bd.option, bval, bd.bins(), min, max);
182  uBinUtil += BinUtility(uBinData);
183  }
184  return uBinUtil;
185 }
186 
194  auto cyBounds =
195  dynamic_cast<const CylinderVolumeBounds*>(&(volume.volumeBounds()));
196  auto cutcylBounds =
197  dynamic_cast<const CutoutCylinderVolumeBounds*>(&(volume.volumeBounds()));
198  auto cuBounds =
199  dynamic_cast<const CuboidVolumeBounds*>(&(volume.volumeBounds()));
200 
201  if (cyBounds != nullptr) {
202  // Cylinder bounds
203  return adjustBinUtility(bu, *cyBounds, volume.transform());
204 
205  } else if (cutcylBounds != nullptr) {
206  // Cutout Cylinder bounds
207  return adjustBinUtility(bu, *cutcylBounds, volume.transform());
208 
209  } else if (cuBounds != nullptr) {
210  // Cuboid bounds
211  return adjustBinUtility(bu, *cuBounds, volume.transform());
212  }
213 
214  throw std::invalid_argument(
215  "Bin adjustment not implemented for this volume yet!");
216 
217  return BinUtility();
218 }
219 
220 } // namespace Acts