EIC 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 
19 
22 
23 #include <stdexcept>
24 
25 namespace Acts {
26 
34  const Transform3D& transform) {
35  // Default constructor
36  BinUtility uBinUtil(transform);
37 
38  // The parameters from the cylinder bounds
39  double minR = rBounds.get(RadialBounds::eMinR);
40  double maxR = rBounds.get(RadialBounds::eMaxR);
41  double minPhi = rBounds.get(RadialBounds::eAveragePhi) -
43  double maxPhi = rBounds.get(RadialBounds::eAveragePhi) +
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) {
57  throw std::invalid_argument("Disc binning must be: phi, r");
58  }
59  float min, max = 0.;
60  // Perform the value adjustment
61  if (bval == binPhi) {
62  min = minPhi;
63  max = maxPhi;
64  } else {
65  min = minR;
66  max = maxR;
67  }
68  // Create the updated BinningData
69  BinningData uBinData(bd.option, bval, bd.bins(), min, max);
70  uBinUtil += BinUtility(uBinData);
71  }
72  return uBinUtil;
73 }
74 
82  const Transform3D& transform) {
83  // Default constructor
84  BinUtility uBinUtil(transform);
85 
86  // The parameters from the cylinder bounds
87  double cR = cBounds.get(CylinderBounds::eR);
88  double cHz = cBounds.get(CylinderBounds::eHalfLengthZ);
89  double avgPhi = cBounds.get(CylinderBounds::eAveragePhi);
90  double halfPhi = cBounds.get(CylinderBounds::eHalfPhiSector);
91  double minPhi = avgPhi - halfPhi;
92  double maxPhi = avgPhi + halfPhi;
93 
94  // Retrieve the binning data
95  const std::vector<BinningData>& bData = bu.binningData();
96  // Loop over the binning data and adjust the dimensions
97  for (auto& bd : bData) {
98  // The binning value
99  BinningValue bval = bd.binvalue;
100  // Throw exceptions if stuff doesn't make sense:
101  // - not the right binning value
102  // - not equidistant
103  if (bd.type == arbitrary) {
104  throw std::invalid_argument("Arbitrary binning can not be adjusted.");
105  } else if (bval != binRPhi and bval != binPhi and bval != binZ) {
106  throw std::invalid_argument("Cylinder binning must be: rphi, phi, z");
107  }
108  float min, max = 0.;
109  // Perform the value adjustment
110  if (bval == binPhi) {
111  min = minPhi;
112  max = maxPhi;
113  } else if (bval == binRPhi) {
114  min = cR * minPhi;
115  max = cR * maxPhi;
116  } else {
117  min = -cHz;
118  max = cHz;
119  }
120  // Create the updated BinningData
121  BinningData uBinData(bd.option, bval, bd.bins(), min, max);
122  uBinUtil += BinUtility(uBinData);
123  }
124  return uBinUtil;
125 }
126 
134  // The surface type is a cylinder
135  if (surface.type() == Surface::Cylinder) {
136  // Cast to Cylinder bounds and return
137  auto cBounds = dynamic_cast<const CylinderBounds*>(&(surface.bounds()));
138  // Return specific adjustment
139  return adjustBinUtility(bu, *cBounds, surface.transform(GeometryContext()));
140 
141  } else if (surface.type() == Surface::Disc) {
142  // Cast to Cylinder bounds and return
143  auto rBounds = dynamic_cast<const RadialBounds*>(&(surface.bounds()));
144  // Return specific adjustment
145  return adjustBinUtility(bu, *rBounds, surface.transform(GeometryContext()));
146  }
147 
148  throw std::invalid_argument(
149  "Bin adjustment not implemented for this surface yet!");
150 
151  return BinUtility();
152 }
153 
154 } // namespace Acts