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