Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinAdjustment.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BinAdjustment.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 
22 
23 #include <stdexcept>
24 
25 namespace Acts {
26 
35  const Transform3& transform) {
36  // Default constructor
37  BinUtility uBinUtil(transform);
38 
39  // The parameters from the cylinder bounds
40  double minR = rBounds.get(RadialBounds::eMinR);
41  double maxR = rBounds.get(RadialBounds::eMaxR);
42  double minPhi = rBounds.get(RadialBounds::eAveragePhi) -
44  double maxPhi = rBounds.get(RadialBounds::eAveragePhi) +
46  // Retrieve the binning data
47  const std::vector<BinningData>& bData = bu.binningData();
48  // Loop over the binning data and adjust the dimensions
49  for (auto& bd : bData) {
50  // The binning value
51  BinningValue bval = bd.binvalue;
52  // Throw exceptions is stuff doesn't make sense:
53  // - not the right binning value
54  // - not equidistant
55  if (bd.type == arbitrary) {
56  throw std::invalid_argument("Arbitrary binning can not be adjusted.");
57  } else if (bval != binR and bval != binPhi) {
58  throw std::invalid_argument("Disc binning must be: phi, r");
59  }
60  float min = 0., max = 0.;
61  // Perform the value adjustment
62  if (bval == binPhi) {
63  min = minPhi;
64  max = maxPhi;
65  } else {
66  min = minR;
67  max = maxR;
68  }
69  // Create the updated BinningData
70  BinningData uBinData(bd.option, bval, bd.bins(), min, max);
71  uBinUtil += BinUtility(uBinData);
72  }
73  return uBinUtil;
74 }
75 
84  const Transform3& transform) {
85  // Default constructor
86  BinUtility uBinUtil(transform);
87 
88  // The parameters from the cylinder bounds
89  double cR = cBounds.get(CylinderBounds::eR);
90  double cHz = cBounds.get(CylinderBounds::eHalfLengthZ);
91  double avgPhi = cBounds.get(CylinderBounds::eAveragePhi);
92  double halfPhi = cBounds.get(CylinderBounds::eHalfPhiSector);
93  double minPhi = avgPhi - halfPhi;
94  double maxPhi = avgPhi + halfPhi;
95 
96  // Retrieve the binning data
97  const std::vector<BinningData>& bData = bu.binningData();
98  // Loop over the binning data and adjust the dimensions
99  for (auto& bd : bData) {
100  // The binning value
101  BinningValue bval = bd.binvalue;
102  // Throw exceptions if stuff doesn't make sense:
103  // - not the right binning value
104  // - not equidistant
105  if (bd.type == arbitrary) {
106  throw std::invalid_argument("Arbitrary binning can not be adjusted.");
107  } else if (bval != binRPhi and bval != binPhi and bval != binZ) {
108  throw std::invalid_argument("Cylinder binning must be: rphi, phi, z");
109  }
110  float min = 0., max = 0.;
111  // Perform the value adjustment
112  if (bval == binPhi) {
113  min = minPhi;
114  max = maxPhi;
115  } else if (bval == binRPhi) {
116  min = cR * minPhi;
117  max = cR * maxPhi;
118  } else {
119  min = -cHz;
120  max = cHz;
121  }
122  // Create the updated BinningData
123  BinningData uBinData(bd.option, bval, bd.bins(), min, max);
124  uBinUtil += BinUtility(uBinData);
125  }
126  return uBinUtil;
127 }
128 
137  const RectangleBounds& pBounds,
138  const Transform3& transform) {
139  // Default constructor
140  BinUtility uBinUtil(transform);
141 
142  // The parameters from the cylinder bounds
143  double minX = pBounds.get(RectangleBounds::eMinX);
144  double minY = pBounds.get(RectangleBounds::eMinY);
145  double maxX = pBounds.get(RectangleBounds::eMaxX);
146  double maxY = pBounds.get(RectangleBounds::eMaxY);
147 
148  // Retrieve the binning data
149  const std::vector<BinningData>& bData = bu.binningData();
150  // Loop over the binning data and adjust the dimensions
151  for (auto& bd : bData) {
152  // The binning value
153  BinningValue bval = bd.binvalue;
154  // Throw exceptions if stuff doesn't make sense:
155  // - not the right binning value
156  // - not equidistant
157  if (bd.type == arbitrary) {
158  throw std::invalid_argument("Arbitrary binning can not be adjusted.");
159  } else if (bval != binX and bval != binY) {
160  throw std::invalid_argument("Rectangle binning must be: x, y. ");
161  }
162  float min = 0., max = 0.;
163  // Perform the value adjustment
164  if (bval == binX) {
165  min = minX;
166  max = maxX;
167  } else {
168  min = minY;
169  max = maxY;
170  }
171  // Create the updated BinningData
172  BinningData uBinData(bd.option, bval, bd.bins(), min, max);
173  uBinUtil += BinUtility(uBinData);
174  }
175 
176  return uBinUtil;
177 }
178 
187  const TrapezoidBounds& pBounds,
188  const Transform3& transform) {
189  // Default constructor
190  BinUtility uBinUtil(transform);
191 
192  // The parameters from the cylinder bounds
193 
194  double halfX = std::max(pBounds.get(Acts::TrapezoidBounds::eHalfLengthXnegY),
197 
198  // Retrieve the binning data
199  const std::vector<BinningData>& bData = bu.binningData();
200  // Loop over the binning data and adjust the dimensions
201  for (auto& bd : bData) {
202  // The binning value
203  BinningValue bval = bd.binvalue;
204  // Throw exceptions if stuff doesn't make sense:
205  // - not the right binning value
206  // - not equidistant
207  if (bd.type == arbitrary) {
208  throw std::invalid_argument("Arbitrary binning can not be adjusted.");
209  } else if (bval != binX and bval != binY) {
210  throw std::invalid_argument("Rectangle binning must be: x, y. ");
211  }
212  float min = 0., max = 0.;
213  // Perform the value adjustment
214  if (bval == binX) {
215  min = -1 * halfX;
216  max = halfX;
217  } else {
218  min = -1 * halfY;
219  max = halfY;
220  }
221  // Create the updated BinningData
222  BinningData uBinData(bd.option, bval, bd.bins(), min, max);
223  uBinUtil += BinUtility(uBinData);
224  }
225 
226  return uBinUtil;
227 }
228 
237  const GeometryContext& gctx) {
238  // The surface type is a cylinder
239  if (surface.type() == Surface::Cylinder) {
240  // Cast to Cylinder bounds and return
241  auto cBounds = dynamic_cast<const CylinderBounds*>(&(surface.bounds()));
242  // Return specific adjustment
243  return adjustBinUtility(bu, *cBounds, surface.transform(gctx));
244 
245  } else if (surface.type() == Surface::Disc) {
246  // Cast to Cylinder bounds and return
247  auto rBounds = dynamic_cast<const RadialBounds*>(&(surface.bounds()));
248  // Return specific adjustment
249  return adjustBinUtility(bu, *rBounds, surface.transform(gctx));
250  } else if (surface.type() == Surface::Plane) {
251  if (surface.bounds().type() == SurfaceBounds::eRectangle) {
252  // Cast to Plane bounds and return
253  auto pBounds = dynamic_cast<const RectangleBounds*>(&(surface.bounds()));
254  // Return specific adjustment
255  return adjustBinUtility(bu, *pBounds, surface.transform(gctx));
256  } else if (surface.bounds().type() == SurfaceBounds::eTrapezoid) {
257  // Cast to Plane bounds and return
258  auto pBounds = dynamic_cast<const TrapezoidBounds*>(&(surface.bounds()));
259  // Return specific adjustment
260  return adjustBinUtility(bu, *pBounds, surface.transform(gctx));
261  } else {
262  throw std::invalid_argument(
263  "Bin adjustment not implemented for this type of plane surface yet!");
264  }
265  }
266 
267  throw std::invalid_argument(
268  "Bin adjustment not implemented for this surface yet!");
269 
270  return BinUtility();
271 }
272 
273 } // namespace Acts